90-full-slip.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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", "[full-slip]") {
  37. MyStack stack;
  38. auto &echo_req = stack.get<0, 2>();
  39. char buff_raw[128];
  40. auto buff = Chunk(buff_raw, sizeof(buff_raw));
  41. echo_req.init(src, 64, 0x5DDE, 0x47);
  42. auto tx_result = echo_req.send(stack, buff, dst, payload);
  43. REQUIRE(tx_result);
  44. auto rx_result = stack.recv(tx_result.consumed(), nullptr);
  45. REQUIRE(rx_result);
  46. REQUIRE(!rx_result.demand());
  47. REQUIRE(rx_result.state() == &echo_req);
  48. auto p = echo_req.get_parsed();
  49. CHECK(p.payload == payload);
  50. }