|
1 | | -// @nolint |
| 1 | +// clang-format off |
2 | 2 |
|
3 | 3 | /* Copyright (C) 2018-present, Facebook, Inc. |
4 | 4 | * |
|
17 | 17 | */ |
18 | 18 |
|
19 | 19 | #pragma once |
20 | | -#include <bpf/bpf.h> |
21 | | -#include <katran/lib/testing/tools/PacketAttributes.h> |
22 | | -#include <string> |
23 | | -#include <utility> |
24 | 20 | #include <vector> |
| 21 | +#include "katran/lib/testing/tools/PacketAttributes.h" |
| 22 | +#include "katran/lib/testing/tools/PacketBuilder.h" |
| 23 | + |
| 24 | +extern "C" { |
| 25 | +#include <netinet/tcp.h> |
| 26 | +} |
25 | 27 |
|
26 | | -namespace katran { |
27 | | -namespace testing { |
28 | 28 | /** |
29 | | - * Input packets has been generated with scapy. |
| 29 | + * Test fixtures for VIP decapsulation statistics functionality. |
| 30 | + * |
| 31 | + * Each test case is generated using PacketBuilder and contains: |
| 32 | + * - inputPacketBuilder: PacketBuilder object for input packet |
| 33 | + * - expectedOutputPacketBuilder: PacketBuilder object for expected output packet |
| 34 | + * - description: Test case description |
| 35 | + * - expectedReturnValue: Expected BPF program return code (XDP_TX, XDP_DROP, XDP_PASS) |
30 | 36 | * |
31 | | - * Format of the input data: <string, string>; 1st string is a base64 encoded |
32 | | - * packet. 2nd string is test's description |
| 37 | + * PacketBuilder Usage: |
| 38 | + * PacketBuilder::newPacket() |
| 39 | + * .Eth("01:00:00:00:00:00", "02:00:00:00:00:00") |
| 40 | + * .IPv4("192.168.1.1", "10.200.1.1") |
| 41 | + * .UDP(31337, 80) |
| 42 | + * .payload("katran test pkt") |
33 | 43 | * |
34 | | - * Format of the output data: <string, string>; 1st string is a base64 encoded |
35 | | - * packet which we are expecting to see after bpf program's run. |
36 | | - * 2nd string = bpf's program return code. |
| 44 | + * For GUE encapsulation: |
| 45 | + * PacketBuilder::newPacket() |
| 46 | + * .Eth("01:00:00:00:00:00", "02:00:00:00:00:00") |
| 47 | + * .IPv6("100::64", "fc00:1::1") // outer IPv6 - to VIP |
| 48 | + * .UDP(31337, 9886) // outer UDP (GUE) |
| 49 | + * .IPv4("192.168.1.1", "10.200.1.1") // inner IPv4 - client to VIP |
| 50 | + * .UDP(31337, 80) // inner UDP |
| 51 | + * .payload("katran test pkt") |
37 | 52 | * |
38 | | - * to create pcap w/ scapy: |
39 | | - * 1) create packets |
40 | | - * 2) pckts = [ <created packets from above> ] |
41 | | - * 3) wrpcap(<path_to_file>, pckts) |
| 53 | + * Requirements: |
| 54 | + * - INLINE_DECAP_GUE feature must be enabled for decap tests |
| 55 | + * - Tests cover scenarios where GUE packets hit configured VIPs |
| 56 | + * - VIP decap stats counters should be incremented for successful decaps |
42 | 57 | */ |
43 | 58 |
|
44 | | -const std::vector<PacketAttributes> DecapTestFixtures = { |
45 | | - // gue ip6 in ip6 inline decap. out dst is host primary addr fc00:2307::1337 |
46 | | - {// Ether(src="0x1", dst="0x2")/IPv6(src="100::64",dst="fc00:2307::1337")/UDP(sport=31337,dport=9886)/IPv6(src="fc00:2307:1::2", dst="fc00:1::1")/TCP(sport=31337,dport=80,flags="A")/"katran test pkt" |
47 | | - .inputPacket = |
48 | | - "AgAAAAAAAQAAAAAAht1gAAAAAFMRQAEAAAAAAAAAAAAAAAAAAGT8ACMHAAAAAAAAAAAAABM3emkmngBTxGNgAAAAACMGQPwAIwcAAQAAAAAAAAAAAAL8AAABAAAAAAAAAAAAAAABemkAUAAAAAAAAAAAUBAgANpIAABrYXRyYW4gdGVzdCBwa3Q=", |
49 | | - .description = "gue ip6ip6 inline decap. INLINE_DECAP_GUE is required", |
50 | | - .expectedReturnValue = "XDP_PASS", |
51 | | - .expectedOutputPacket = |
52 | | - "AgAAAAAAAQAAAAAAht1gAAAAACMGP/wAIwcAAQAAAAAAAAAAAAL8AAABAAAAAAAAAAAAAAABemkAUAAAAAAAAAAAUBAgANpIAABrYXRyYW4gdGVzdCBwa3Q="}, |
53 | | - // gue ip4 in ip6 inline decap. out dst is host primary addr fc00:2307::1337 |
54 | | - {// Ether(src="0x1", dst="0x2")/IPv6(src="100::64",dst="fc00:2307::1337")/UDP(sport=31337,dport=9886)/IP(src="192.168.1.3", dst="10.200.1.1")/UDP(sport=31337,dport=80)/"katran test pkt" |
55 | | - .inputPacket = |
56 | | - "AgAAAAAAAQAAAAAAht1gAAAAADMRQAEAAAAAAAAAAAAAAAAAAGT8ACMHAAAAAAAAAAAAABM3emkmngAz+HpFAAArAAEAAEARrU3AqAEDCsgBAXppAFAAF5fca2F0cmFuIHRlc3QgcGt0", |
57 | | - .description = "gue ip4 in ip6 inline decap. INLINE_DECAP_GUE is required", |
58 | | - .expectedReturnValue = "XDP_PASS", |
59 | | - // Ether(src="0x1", dst="0x2")/IP(src="192.168.1.3",dst="10.200.1.1")/UDP(sport=31337, dport=80)/"katran test pkt" |
60 | | - .expectedOutputPacket = |
61 | | - "AgAAAAAAAQAAAAAACABFAAArAAEAAD8Rrk3AqAEDCsgBAXppAFAAF5fca2F0cmFuIHRlc3QgcGt0"}, |
62 | | - // ip6 packet for vip - this should not get decaped, so won't be added to decap vip stats |
63 | | - {// Ether(src="0x1", dst="0x2")/IPv6(src="100::64",dst="fc00:1::1")/TCP(sport=31337, dport=80,flags="A")/"katran test pkt" |
64 | | - .inputPacket = |
65 | | - "AgAAAAAAAQAAAAAAht1gAAAAACMGQAEAAAAAAAAAAAAAAAAAAGT8AAABAAAAAAAAAAAAAAABemkAUAAAAAAAAAAAUBAgAPfvAABrYXRyYW4gdGVzdCBwa3Q=", |
66 | | - .description = "vip traffic", |
67 | | - .expectedReturnValue = "XDP_TX", |
68 | | - // Ether(dst="00:00:de:ad:be:af",src="02:00:00:00:00:00")/IPv6(src="fc00:2307::1337",dst="fc00::2")/UDP(sport=31337, dport=9886)/IPv6(src="100::64",dst="fc00:1::1")/TCP(sport=31337, dport=80,flags="A")/"katran test pkt" |
69 | | - .expectedOutputPacket = |
70 | | - "AADerb6vAgAAAAAAht1gAAAAAFMRQPwAIwcAAAAAAAAAAAAAEzf8AAAAAAAAAAAAAAAAAAACemkmngBTycRgAAAAACMGQAEAAAAAAAAAAAAAAAAAAGT8AAABAAAAAAAAAAAAAAABemkAUAAAAAAAAAAAUBAgAPfvAABrYXRyYW4gdGVzdCBwa3Q="}, |
| 59 | +namespace katran { |
| 60 | +namespace testing { |
71 | 61 |
|
| 62 | +const std::vector<PacketAttributes> DecapTestFixtures = { |
| 63 | + //1 |
| 64 | + { |
| 65 | + .description = "GUE IPv6-in-IPv6 decap for IPv6 VIP fc00:1::1 port 80", |
| 66 | + .expectedReturnValue = "XDP_PASS", |
| 67 | + .inputPacketBuilder = katran::testing::PacketBuilder::newPacket() |
| 68 | + .Eth("0x1", "0x2") |
| 69 | + .IPv6("100::64", "fc00:2307::1337") // outer IPv6 - destination is Katran source for inline decap |
| 70 | + .UDP(31337, 9886) // GUE encapsulation port 9886 |
| 71 | + .IPv6("fc00:2307:1::2", "fc00:1::1") // inner IPv6 - from client to VIP |
| 72 | + .TCP(31337, 80, 0, 0, 8192, TH_ACK) |
| 73 | + .payload("katran test pkt"), |
| 74 | + .expectedOutputPacketBuilder = katran::testing::PacketBuilder::newPacket() |
| 75 | + .Eth("0x1", "0x2") |
| 76 | + .IPv6("fc00:2307:1::2", "fc00:1::1", 63) // inner packet after decap, hop limit decremented |
| 77 | + .TCP(31337, 80, 0, 0, 8192, TH_ACK) // inner TCP |
| 78 | + .payload("katran test pkt") |
| 79 | + }, |
| 80 | + //2 |
| 81 | + { |
| 82 | + .description = "GUE IPv4-in-IPv6 decap for IPv4 VIP 10.200.1.1 port 80", |
| 83 | + .expectedReturnValue = "XDP_PASS", |
| 84 | + .inputPacketBuilder = katran::testing::PacketBuilder::newPacket() |
| 85 | + .Eth("0x1", "0x2") |
| 86 | + .IPv6("100::64", "fc00:2307::1337") // outer IPv6 - destination is Katran source for inline decap |
| 87 | + .UDP(31337, 9886) // GUE encapsulation port 9886 |
| 88 | + .IPv4("192.168.1.3", "10.200.1.1") // inner IPv4 - from client to VIP |
| 89 | + .UDP(31337, 80) |
| 90 | + .payload("katran test pkt"), |
| 91 | + .expectedOutputPacketBuilder = katran::testing::PacketBuilder::newPacket() |
| 92 | + .Eth("0x1", "0x2") |
| 93 | + .IPv4("192.168.1.3", "10.200.1.1", 63, 0, 1) // inner packet after decap, TTL decremented, ID=1 |
| 94 | + .UDP(31337, 80) // inner UDP |
| 95 | + .payload("katran test pkt") |
| 96 | + }, |
| 97 | + //3 |
| 98 | + { |
| 99 | + .description = "Regular IPv6 VIP traffic (not decap) to fc00:1::1", |
| 100 | + .expectedReturnValue = "XDP_TX", |
| 101 | + .inputPacketBuilder = katran::testing::PacketBuilder::newPacket() |
| 102 | + .Eth("0x1", "0x2") |
| 103 | + .IPv6("100::64", "fc00:1::1") |
| 104 | + .TCP(31337, 80, 0, 0, 8192, TH_ACK) |
| 105 | + .payload("katran test pkt"), |
| 106 | + .expectedOutputPacketBuilder = katran::testing::PacketBuilder::newPacket() |
| 107 | + .Eth("02:00:00:00:00:00", "00:00:de:ad:be:af") |
| 108 | + .IPv6("fc00:2307::1337", "fc00::2") // encapsulated to IPv6 backend |
| 109 | + .UDP(31337, 9886) |
| 110 | + .IPv6("100::64", "fc00:1::1") |
| 111 | + .TCP(31337, 80, 0, 0, 8192, TH_ACK) |
| 112 | + .payload("katran test pkt") |
| 113 | + } |
72 | 114 | }; |
73 | 115 |
|
74 | 116 | } // namespace testing |
|
0 commit comments