90-full-slip.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "limbo/errc.h"
  2. #include "limbo/icmp/echo_request.hpp"
  3. #include "limbo/icmp/echo_response.hpp"
  4. #include "limbo/icmp/state.hpp"
  5. #include "limbo/ip/state.hpp"
  6. #include "limbo/slip/state.hpp"
  7. #include "limbo/udp/connection.hpp"
  8. #include "limbo/udp/receiver.hpp"
  9. #include "limbo/udp/state.hpp"
  10. #include "limbo/stack.hpp"
  11. #include "test-utils.h"
  12. using namespace limbo;
  13. using SLIP = slip::State<void>;
  14. using IP = ip::State<SLIP>;
  15. using ICMP = icmp::State<IP>;
  16. using UDP = udp::State<IP>;
  17. using EchoReq = icmp::EchoRequest<ICMP>;
  18. using EchoRes = icmp::EchoResponse<ICMP>;
  19. using Receiver = udp::Receiver<UDP>;
  20. using Connection = udp::Connection<UDP>;
  21. using MyStack = Stack<Layer<Connection, Receiver, EchoReq, EchoRes>, /* app */
  22. Layer<UDP, ICMP>, /* transport */
  23. Layer<IP>, /* network */
  24. Layer<SLIP> /* link */
  25. >;
  26. auto src = make_address("169.254.1.1");
  27. auto dst = make_address("169.254.1.2");
  28. unsigned char payload_raw[] = {
  29. 0x8b, 0x15, 0x51, 0x63, 0x00, 0x00, 0x00, 0x00, 0x1a, 0x4c, 0x09, 0x00,
  30. 0x00, 0x00, 0x00, 0x00, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  31. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
  32. 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  33. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  34. };
  35. auto payload = Chunk(payload_raw, sizeof(payload_raw));
  36. TEST_CASE("send + receive", "[scenario]") {
  37. MyStack stack_1, stack_2;
  38. auto &echo_req_1 = stack_1.get<0, 2>();
  39. auto &echo_req_2 = stack_2.get<0, 2>();
  40. char buff_raw[128];
  41. auto buff = Chunk(buff_raw, sizeof(buff_raw));
  42. echo_req_1.init(src, 64, 0x5DDE, 0x47);
  43. echo_req_2.init(dst, 64, 0x5DDE, 0x47);
  44. auto tx_result = echo_req_1.send(stack_1, buff, dst, payload);
  45. REQUIRE(tx_result);
  46. auto rx_result = stack_2.recv(tx_result.consumed(), nullptr);
  47. REQUIRE(rx_result);
  48. REQUIRE(!rx_result.demand());
  49. REQUIRE(rx_result.state() == &echo_req_2);
  50. auto p = echo_req_2.get_parsed();
  51. CHECK(p.payload == payload);
  52. }