|
| 1 | +// clang-format off |
| 2 | + |
| 3 | +/* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. |
| 4 | + * |
| 5 | + * This program is free software; you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation; version 2 of the License. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License along |
| 15 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 16 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 | + */ |
| 18 | + |
| 19 | +#pragma once |
| 20 | +#include <string> |
| 21 | +#include <vector> |
| 22 | +#include "katran/lib/testing/tools/PacketAttributes.h" |
| 23 | +#include "katran/lib/testing/tools/PacketBuilder.h" |
| 24 | + |
| 25 | +namespace katran { |
| 26 | +namespace testing { |
| 27 | +/** |
| 28 | + * Test fixtures for CIDR_VIP feature. |
| 29 | + * |
| 30 | + * This feature enables prefix-based VIP matching using an LPM trie. When a |
| 31 | + * packet's destination IPv6 address does not match any exact VIP in vip_map, |
| 32 | + * the datapath falls back to vip_lpm_map for prefix-based matching. |
| 33 | + * |
| 34 | + * Setup: A /96 CIDR VIP is added at fc00:1::/96 with reals fc00::1 and fc00::2. |
| 35 | + * Packets to any address in fc00:1::0/96 (e.g., fc00:1::100, fc00:1::200) |
| 36 | + * should match the CIDR VIP and be load-balanced to a real. |
| 37 | + * |
| 38 | + * Test cases cover: |
| 39 | + * - IPv6 TCP packet matching CIDR VIP prefix (different IPs in /96 range) |
| 40 | + * - IPv6 UDP packet matching CIDR VIP prefix |
| 41 | + * - IPv6 packet NOT matching any prefix (XDP_PASS) |
| 42 | + * - IPv4 packet should not match CIDR VIP (IPv6 only) |
| 43 | + * |
| 44 | + * Note: These fixtures use GUE encapsulation. |
| 45 | + */ |
| 46 | +const std::vector<::katran::PacketAttributes> cidrVipTestFixtures = { |
| 47 | + // 1 |
| 48 | + // ipv6 TCP: dst fc00:1::100 matches CIDR VIP fc00:1::/96 (port=0 means |
| 49 | + // all ports). Routes to real fc00::1 via GUE encap. |
| 50 | + {.description = "ipv6 tcp: CIDR VIP match. CIDR_VIP is required", |
| 51 | + .expectedReturnValue = "XDP_TX", |
| 52 | + .inputPacketBuilder = katran::testing::PacketBuilder::newPacket() |
| 53 | + .Eth("0x1", "0x2") |
| 54 | + .IPv6("fc00:2::1", "fc00:1::100") |
| 55 | + .TCP(31337, 80, 0, 0, 8192, TH_ACK) |
| 56 | + .payload("katran test pkt"), |
| 57 | + .expectedOutputPacketBuilder = katran::testing::PacketBuilder::newPacket() |
| 58 | + .Eth("02:00:00:00:00:00", "00:00:de:ad:be:af") |
| 59 | + .IPv6("fc00:2307::1337", "fc00::1", 64, 0, 0) |
| 60 | + .UDP(31337, 9886) |
| 61 | + .IPv6("fc00:2::1", "fc00:1::100") |
| 62 | + .TCP(31337, 80, 0, 0, 8192, TH_ACK) |
| 63 | + .payload("katran test pkt") |
| 64 | + }, |
| 65 | + // 2 |
| 66 | + // ipv6 TCP: dst fc00:1::200 also matches CIDR VIP fc00:1::/96 (port=0 |
| 67 | + // means all ports). Different dest IP in same /96, should match same VIP. |
| 68 | + {.description = "ipv6 tcp: CIDR VIP match different IP in range. CIDR_VIP is required", |
| 69 | + .expectedReturnValue = "XDP_TX", |
| 70 | + .inputPacketBuilder = katran::testing::PacketBuilder::newPacket() |
| 71 | + .Eth("0x1", "0x2") |
| 72 | + .IPv6("fc00:2::1", "fc00:1::200") |
| 73 | + .TCP(31337, 443, 0, 0, 8192, TH_ACK) |
| 74 | + .payload("katran test pkt"), |
| 75 | + .expectedOutputPacketBuilder = katran::testing::PacketBuilder::newPacket() |
| 76 | + .Eth("02:00:00:00:00:00", "00:00:de:ad:be:af") |
| 77 | + .IPv6("fc00:2307::1337", "fc00::1", 64, 0, 0) |
| 78 | + .UDP(31337, 9886) |
| 79 | + .IPv6("fc00:2::1", "fc00:1::200") |
| 80 | + .TCP(31337, 443, 0, 0, 8192, TH_ACK) |
| 81 | + .payload("katran test pkt") |
| 82 | + }, |
| 83 | + // 3 |
| 84 | + // ipv6 TCP: dst fc00:1::400 with a different port (8080) matches |
| 85 | + // CIDR VIP fc00:1::/96 (port=0 means all ports). |
| 86 | + // Packet misses vip_map (exact port), misses vip_map (port=0), |
| 87 | + // then hits LPM trie. |
| 88 | + {.description = "ipv6 tcp: CIDR VIP match on different port. CIDR_VIP is required", |
| 89 | + .expectedReturnValue = "XDP_TX", |
| 90 | + .inputPacketBuilder = katran::testing::PacketBuilder::newPacket() |
| 91 | + .Eth("0x1", "0x2") |
| 92 | + .IPv6("fc00:2::1", "fc00:1::400") |
| 93 | + .TCP(31337, 8080, 0, 0, 8192, TH_ACK) |
| 94 | + .payload("katran test pkt"), |
| 95 | + .expectedOutputPacketBuilder = katran::testing::PacketBuilder::newPacket() |
| 96 | + .Eth("02:00:00:00:00:00", "00:00:de:ad:be:af") |
| 97 | + .IPv6("fc00:2307::1337", "fc00::1", 64, 0, 0) |
| 98 | + .UDP(31337, 9886) |
| 99 | + .IPv6("fc00:2::1", "fc00:1::400") |
| 100 | + .TCP(31337, 8080, 0, 0, 8192, TH_ACK) |
| 101 | + .payload("katran test pkt") |
| 102 | + }, |
| 103 | + // 4 |
| 104 | + // ipv6: dst fc00:3::1 does NOT match CIDR VIP fc00:1::/96 (port=0 means |
| 105 | + // all ports, but prefix doesn't match). Should be passed to kernel stack. |
| 106 | + {.description = "ipv6: CIDR VIP miss. CIDR_VIP is required", |
| 107 | + .expectedReturnValue = "XDP_PASS", |
| 108 | + .inputPacketBuilder = katran::testing::PacketBuilder::newPacket() |
| 109 | + .Eth("0x1", "0x2") |
| 110 | + .IPv6("fc00:2::1", "fc00:3::1") |
| 111 | + .TCP(31337, 80, 0, 0, 8192, TH_ACK) |
| 112 | + .payload("katran test pkt"), |
| 113 | + .expectedOutputPacketBuilder = katran::testing::PacketBuilder::newPacket() |
| 114 | + .Eth("0x1", "0x2") |
| 115 | + .IPv6("fc00:2::1", "fc00:3::1") |
| 116 | + .TCP(31337, 80, 0, 0, 8192, TH_ACK) |
| 117 | + .payload("katran test pkt") |
| 118 | + }, |
| 119 | +}; |
| 120 | + |
| 121 | +} // namespace testing |
| 122 | +} // namespace katran |
0 commit comments