From 4dcd0b987225bac637b8292e89888f0d8c1796e5 Mon Sep 17 00:00:00 2001 From: abhinav-nexthop Date: Tue, 13 Oct 2026 19:49:50 +0530 Subject: [PATCH 1/4] Add integration tests for IpInIpTunnel.dstIpMask and srcIpMask --- .../integration_test/TunnelIpInIpTest.cpp | 163 ++++++++++++++++++ 1 file changed, 163 insertions(+) diff --git a/fboss/cli/fboss2/test/integration_test/TunnelIpInIpTest.cpp b/fboss/cli/fboss2/test/integration_test/TunnelIpInIpTest.cpp index 9768d88871c..3bd0fd10189 100644 --- a/fboss/cli/fboss2/test/integration_test/TunnelIpInIpTest.cpp +++ b/fboss/cli/fboss2/test/integration_test/TunnelIpInIpTest.cpp @@ -17,6 +17,8 @@ * - FBOSS agent must be running with a valid configuration */ +#include +#include #include #include #include @@ -90,6 +92,131 @@ class TunnelIpInIpTest : public Fboss2IntegrationTest { createdTunnels_.emplace_back(id, direction); } + // Shared body of the destination/source mask tests. Creates a `direction` + // ("encap" or "decap") tunnel whose `attr` ("destination" or "source") + // carries `mask /64`, then checks where the agent put the mask, and removes + // the tunnel and the underlay VLAN it created. + // + // The CLI stores the prefix length as an IPv6 mask address in dstIpMask or + // srcIpMask. For encap the agent copies both fields straight into switch + // state; for decap it swaps them, because config dstIp is the termination + // match and is kept as srcIp in switch state. The other mask must stay unset + // in both places, so a mask written to the wrong field fails the test. + void checkTunnelMask(const std::string& direction, const std::string& attr) { + const bool encap = direction == "encap"; + const bool onDst = attr == "destination"; + const std::string cfgMask = onDst ? "dstIpMask" : "srcIpMask"; + const std::string cfgOther = onDst ? "srcIpMask" : "dstIpMask"; + // Decap swaps directions in switch state. + const bool stateOnDst = encap == onDst; + const std::string stateMask = stateOnDst ? "dstIpMask" : "srcIpMask"; + const std::string stateOther = stateOnDst ? "srcIpMask" : "dstIpMask"; + const std::string stateIp = stateOnDst ? "dstIp" : "srcIp"; + const std::string mask = "ffff:ffff:ffff:ffff::"; // /64 + + int intfId = ensureUnderlayIntfId(); + const std::string dstIp = findIpv6OnIntf(intfId); + const std::string srcIp = "2001:db8:cafe::5"; + const std::string tunnelId = fmt::format( + "integration-test-{}-{}mask", direction, onDst ? "dst" : "src"); + const std::string& maskedIp = onDst ? dstIp : srcIp; + + // Drop the tunnel, then the underlay VLAN and its interface that + // ensureUnderlayIntfId created. Armed as a guard so a failed check still + // leaves the DUT as found; runs explicitly in Step 3. + auto cleanup = [&]() { + try { + if (runCli({"delete", "tunnel", "ip-in-ip", direction, tunnelId}) + .exitCode == 0) { + commitConfig(); + } + auto config = getRunningConfig(); + for (const auto& intf : config["sw"]["interfaces"]) { + const auto* id = intf.get_ptr("intfID"); + const auto* vlan = intf.get_ptr("vlanID"); + if (id != nullptr && vlan != nullptr && id->asInt() == intfId) { + deleteVlanIfPresent(static_cast(vlan->asInt())); + } + } + EXPECT_FALSE(findTunnelInRunningConfig(tunnelId).has_value()) + << "Tunnel '" << tunnelId << "' still present after delete"; + auto after = getRunningConfig(); + for (const auto& intf : after["sw"]["interfaces"]) { + const auto* id = intf.get_ptr("intfID"); + EXPECT_TRUE(id == nullptr || id->asInt() != intfId) + << "underlay interface " << intfId << " left behind"; + } + } catch (const std::exception& e) { + ADD_FAILURE() << "cleanup failed: " << e.what(); + } + }; + auto cleanupGuard = folly::makeGuard(cleanup); + + std::vector cmd{ + "config", + "tunnel", + "ip-in-ip", + direction, + tunnelId, + "destination", + dstIp}; + if (onDst) { + cmd.insert(cmd.end(), {"mask", "64"}); + } + if (encap || !onDst) { + cmd.insert(cmd.end(), {"source", srcIp}); + } + if (!onDst) { + cmd.insert(cmd.end(), {"mask", "64"}); + } + if (!encap) { + // ttl-mode pipe: see DeleteDecapTunnel. + cmd.insert(cmd.end(), {"ttl-mode", "pipe"}); + } + cmd.insert(cmd.end(), {"underlay-intf-id", std::to_string(intfId)}); + + XLOG(INFO) << "[Step 1] Creating " << direction << " tunnel " << tunnelId + << " with " << attr << " mask /64..."; + auto result = runCli(cmd); + ASSERT_EQ(result.exitCode, 0) << "Create failed: " << result.stderr; + commitConfig(); + trackTunnel(tunnelId, direction); + + XLOG(INFO) << "[Step 2] Verifying the mask in running config and state..."; + auto tunnel = waitForTunnelInRunningConfig(tunnelId, /*shouldExist=*/true); + ASSERT_TRUE(tunnel.has_value()) + << "Tunnel '" << tunnelId << "' not found in running config"; + ASSERT_TRUE(tunnel->count(cfgMask)) + << cfgMask << " missing from running config"; + EXPECT_EQ((*tunnel)[cfgMask].asString(), mask); + EXPECT_FALSE(tunnel->count(cfgOther)) + << cfgOther << " set without being configured"; + + // ipTunnelMaps: SwitchIdList -> tunnel id -> IpTunnelFields. + auto tunnelMaps = getSwitchState("ipTunnelMaps"); + int found = 0; + for (const auto& [switchIds, tunnels] : tunnelMaps.items()) { + const auto* state = tunnels.get_ptr(tunnelId); + if (state == nullptr) { + continue; + } + ++found; + EXPECT_EQ((*state)[stateIp].asString(), maskedIp); + const auto* stateMaskVal = state->get_ptr(stateMask); + ASSERT_NE(stateMaskVal, nullptr) + << stateMask << " missing from " << direction << " switch state"; + EXPECT_EQ(stateMaskVal->asString(), mask); + EXPECT_EQ(state->get_ptr(stateOther), nullptr) + << direction << " " << attr << " mask landed in switch state " + << stateOther; + } + EXPECT_GT(found, 0) << "tunnel '" << tunnelId << "' not in switch state"; + + XLOG(INFO) << "[Step 3] Deleting tunnel and underlay VLAN..."; + cleanupGuard.dismiss(); + cleanup(); + } + private: // (tunnelId, direction) pairs to clean up in TearDown. std::vector> createdTunnels_; @@ -151,6 +278,24 @@ TEST_F(TunnelIpInIpTest, CreateDecapTunnelAndVerifyRunningConfig) { static_cast(cfg::TunnelTerminationType::P2MP)); } +// --------------------------------------------------------------------------- +// Positive: 'destination mask ' on a DECAP tunnel lands in the +// switch state's srcIpMask (decap swaps directions). +// --------------------------------------------------------------------------- + +TEST_F(TunnelIpInIpTest, DecapDestinationMask) { + checkTunnelMask("decap", "destination"); +} + +// --------------------------------------------------------------------------- +// Positive: 'source mask ' on a DECAP tunnel lands in the switch +// state's dstIpMask (decap swaps directions). +// --------------------------------------------------------------------------- + +TEST_F(TunnelIpInIpTest, DecapSourceMask) { + checkTunnelMask("decap", "source"); +} + // --------------------------------------------------------------------------- // Positive: create an ENCAP tunnel and verify tunnelType == IP_IN_IP_ENCAP in // the agent's running config. @@ -193,6 +338,24 @@ TEST_F(TunnelIpInIpTest, CreateEncapTunnelAndVerifyRunningConfig) { static_cast(TunnelType::IP_IN_IP_ENCAP)); } +// --------------------------------------------------------------------------- +// Positive: 'destination mask ' on an ENCAP tunnel lands in the +// switch state's dstIpMask. +// --------------------------------------------------------------------------- + +TEST_F(TunnelIpInIpTest, EncapDestinationMask) { + checkTunnelMask("encap", "destination"); +} + +// --------------------------------------------------------------------------- +// Positive: 'source mask ' on an ENCAP tunnel lands in the switch +// state's srcIpMask. +// --------------------------------------------------------------------------- + +TEST_F(TunnelIpInIpTest, EncapSourceMask) { + checkTunnelMask("encap", "source"); +} + // --------------------------------------------------------------------------- // Positive: create then delete a decap tunnel; verify it disappears from the // running config. From 22733d1f1d1ab0598bb90f6201935b61510a925c Mon Sep 17 00:00:00 2001 From: abhinav-nexthop Date: Tue, 13 Oct 2026 20:02:12 +0530 Subject: [PATCH 2/4] Add integration tests for IpInIpTunnel.dscpMode and ecnMode --- .../integration_test/TunnelIpInIpTest.cpp | 196 ++++++++++++++++++ 1 file changed, 196 insertions(+) diff --git a/fboss/cli/fboss2/test/integration_test/TunnelIpInIpTest.cpp b/fboss/cli/fboss2/test/integration_test/TunnelIpInIpTest.cpp index 3bd0fd10189..72aaffd128b 100644 --- a/fboss/cli/fboss2/test/integration_test/TunnelIpInIpTest.cpp +++ b/fboss/cli/fboss2/test/integration_test/TunnelIpInIpTest.cpp @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include #include #include @@ -50,6 +52,163 @@ class TunnelIpInIpTest : public Fboss2IntegrationTest { Fboss2IntegrationTest::TearDown(); } + // Shared body of the dscp-mode and ecn-mode tests. Creates a `direction` + // ("encap" or "decap") tunnel with `attr` ("dscp-mode" or "ecn-mode") set to + // pipe (the agent defaults to uniform), checks the mode in the running + // config, the switch state and the SAI tunnel object, then removes the + // tunnel and the underlay VLAN it created. + // + // What SaiTunnelManager programs differs per mode and direction: + // - dscp-mode goes to the direction's own attribute (EncapDscpMode or + // DecapDscpMode, PIPE_MODEL = 1); the other direction stays uniform (0). + // - decap ecn-mode goes to DecapEcnMode (pipe -> COPY_FROM_OUTER = 1). + // - encap ecn-mode is not programmed at all: the IP-in-IP SAI tunnel has no + // encap ECN attribute, so only DecapEcnMode is checked to stay STANDARD + // (0). + void checkTunnelMode(const std::string& direction, const std::string& attr) { + const bool encap = direction == "encap"; + const bool dscp = attr == "dscp-mode"; + const std::string cfgField = dscp ? "dscpMode" : "ecnMode"; + const int pipe = static_cast(cfg::TunnelMode::PIPE); + // Substrings of the new tunnel's 'show hw-object IPTUNNEL' line; an empty + // one is not checked. + std::string saiSet; + std::string saiUnset; + if (dscp) { + saiSet = encap ? "EncapDscpMode: 1" : "DecapDscpMode: 1"; + saiUnset = encap ? "DecapDscpMode: 0" : "EncapDscpMode: 0"; + } else if (encap) { + saiUnset = "DecapEcnMode: 0"; + } else { + saiSet = "DecapEcnMode: 1"; + } + + // The SAI tunnel objects currently programmed, one line each. + // The JSON output maps each host to that hw agent's text dump. + auto saiTunnels = [this]() { + std::set lines; + auto dump = runCliJson({"show", "hw-object", "IPTUNNEL"}); + for (const auto& [host, text] : dump.items()) { + std::istringstream out(text.asString()); + std::string line; + while (std::getline(out, line)) { + if (line.find("TunnelSaiId(") != std::string::npos) { + lines.insert(line); + } + } + } + return lines; + }; + + int intfId = ensureUnderlayIntfId(); + const std::string dstIp = findIpv6OnIntf(intfId); + const std::string tunnelId = + fmt::format("integration-test-{}-{}", direction, dscp ? "dscp" : "ecn"); + std::vector cmd{ + "config", + "tunnel", + "ip-in-ip", + direction, + tunnelId, + "destination", + dstIp, + attr, + "pipe"}; + if (encap) { + cmd.insert(cmd.end(), {"source", "2001:db8:cafe::6"}); + } else { + // ttl-mode pipe: see DeleteDecapTunnel. + cmd.insert(cmd.end(), {"ttl-mode", "pipe"}); + } + cmd.insert(cmd.end(), {"underlay-intf-id", std::to_string(intfId)}); + + // Deletes the tunnel and the underlay VLAN. Armed as a guard so a failed + // check still leaves the DUT as found; runs explicitly in Step 3. + auto cleanup = [&]() { + try { + if (runCli({"delete", "tunnel", "ip-in-ip", direction, tunnelId}) + .exitCode == 0) { + commitConfig(); + } + auto config = getRunningConfig(); + for (const auto& intf : config["sw"]["interfaces"]) { + const auto* id = intf.get_ptr("intfID"); + const auto* vlan = intf.get_ptr("vlanID"); + if (id != nullptr && vlan != nullptr && id->asInt() == intfId) { + deleteVlanIfPresent(static_cast(vlan->asInt())); + } + } + } catch (const std::exception& e) { + ADD_FAILURE() << "cleanup failed: " << e.what(); + } + }; + auto cleanupGuard = folly::makeGuard(cleanup); + + const auto saiBefore = saiTunnels(); + XLOG(INFO) << "[Step 1] Creating " << direction << " tunnel " << tunnelId + << " with " << attr << " pipe..."; + auto result = runCli(cmd); + ASSERT_EQ(result.exitCode, 0) << "Create failed: " << result.stderr; + commitConfig(); + trackTunnel(tunnelId, direction); + + XLOG(INFO) << "[Step 2] Verifying " << attr + << " in config, state and SAI..."; + auto tunnel = waitForTunnelInRunningConfig(tunnelId, /*shouldExist=*/true); + ASSERT_TRUE(tunnel.has_value()) + << "Tunnel '" << tunnelId << "' not found in running config"; + ASSERT_TRUE(tunnel->count(cfgField)) + << cfgField << " missing from running config"; + EXPECT_EQ((*tunnel)[cfgField].asInt(), pipe); + + // ipTunnelMaps: SwitchIdList -> tunnel id -> IpTunnelFields. + auto tunnelMaps = getSwitchState("ipTunnelMaps"); + int found = 0; + for (const auto& [switchIds, tunnels] : tunnelMaps.items()) { + const auto* state = tunnels.get_ptr(tunnelId); + if (state == nullptr) { + continue; + } + ++found; + const auto* mode = state->get_ptr(cfgField); + ASSERT_NE(mode, nullptr) << cfgField << " missing from switch state"; + EXPECT_EQ(mode->asInt(), pipe); + } + EXPECT_GT(found, 0) << "tunnel '" << tunnelId << "' not in switch state"; + + std::vector added; + for (const auto& line : saiTunnels()) { + if (!saiBefore.count(line)) { + added.push_back(line); + } + } + ASSERT_EQ(added.size(), 1) << "expected one new SAI tunnel object"; + XLOG(INFO) << "New SAI tunnel: " << added[0]; + if (!saiSet.empty()) { + EXPECT_NE(added[0].find(saiSet), std::string::npos) + << "SAI tunnel lacks '" << saiSet << "'"; + } + if (!saiUnset.empty()) { + EXPECT_NE(added[0].find(saiUnset), std::string::npos) + << "SAI tunnel lacks '" << saiUnset << "'"; + } + + // Leave the DUT as found: drop the tunnel, then the underlay VLAN and its + // interface that ensureUnderlayIntfId created. + XLOG(INFO) << "[Step 3] Deleting tunnel and underlay VLAN..."; + cleanupGuard.dismiss(); + cleanup(); + EXPECT_FALSE(findTunnelInRunningConfig(tunnelId).has_value()) + << "Tunnel '" << tunnelId << "' still present after delete"; + EXPECT_EQ(saiTunnels(), saiBefore) << "SAI tunnel left after delete"; + auto after = getRunningConfig(); + for (const auto& intf : after["sw"]["interfaces"]) { + const auto* id = intf.get_ptr("intfID"); + EXPECT_TRUE(id == nullptr || id->asInt() != intfId) + << "underlay interface " << intfId << " left behind"; + } + } + // Return the tunnel object with the given id from the agent's running config, // or std::nullopt if absent. std::optional findTunnelInRunningConfig( @@ -391,6 +550,24 @@ TEST_F(TunnelIpInIpTest, DeleteDecapTunnel) { << "Tunnel '" << tunnelId << "' still present after delete"; } +// --------------------------------------------------------------------------- +// Positive: 'dscp-mode pipe' on a DECAP tunnel is programmed as the SAI +// tunnel's DecapDscpMode. +// --------------------------------------------------------------------------- + +TEST_F(TunnelIpInIpTest, DecapDscpMode) { + checkTunnelMode("decap", "dscp-mode"); +} + +// --------------------------------------------------------------------------- +// Positive: 'ecn-mode pipe' on a DECAP tunnel is programmed as the SAI +// tunnel's DecapEcnMode (COPY_FROM_OUTER). +// --------------------------------------------------------------------------- + +TEST_F(TunnelIpInIpTest, DecapEcnMode) { + checkTunnelMode("decap", "ecn-mode"); +} + // --------------------------------------------------------------------------- // Positive: reset an optional attr (ttl-mode) on a decap tunnel and confirm it // is gone from the running config while destination survives. @@ -446,6 +623,25 @@ TEST_F(TunnelIpInIpTest, ResetOptionalAttrOnDecapTunnel) { EXPECT_EQ((*tunnel)["dstIp"].asString(), dstIp); } +// --------------------------------------------------------------------------- +// Positive: 'dscp-mode pipe' on an ENCAP tunnel is programmed as the SAI +// tunnel's EncapDscpMode. +// --------------------------------------------------------------------------- + +TEST_F(TunnelIpInIpTest, EncapDscpMode) { + checkTunnelMode("encap", "dscp-mode"); +} + +// --------------------------------------------------------------------------- +// Positive: 'ecn-mode pipe' on an ENCAP tunnel reaches the running config and +// switch state. The IP-in-IP SAI tunnel has no encap ECN attribute, so the +// hardware check is only that it does not leak into DecapEcnMode. +// --------------------------------------------------------------------------- + +TEST_F(TunnelIpInIpTest, EncapEcnMode) { + checkTunnelMode("encap", "ecn-mode"); +} + // --------------------------------------------------------------------------- // Negative: termination-type is decap-only — the encap command must reject it. // --------------------------------------------------------------------------- From 38a1926e7774b00a6a65a06d29f9e3bb45283d9a Mon Sep 17 00:00:00 2001 From: abhinav-nexthop Date: Mon, 19 Oct 2026 13:53:00 +0530 Subject: [PATCH 3/4] Add integration test for IpInIpTunnel.tunnelTermType --- .../integration_test/TunnelIpInIpTest.cpp | 205 ++++++++++++++---- 1 file changed, 160 insertions(+), 45 deletions(-) diff --git a/fboss/cli/fboss2/test/integration_test/TunnelIpInIpTest.cpp b/fboss/cli/fboss2/test/integration_test/TunnelIpInIpTest.cpp index 72aaffd128b..3f821b5fde9 100644 --- a/fboss/cli/fboss2/test/integration_test/TunnelIpInIpTest.cpp +++ b/fboss/cli/fboss2/test/integration_test/TunnelIpInIpTest.cpp @@ -83,23 +83,6 @@ class TunnelIpInIpTest : public Fboss2IntegrationTest { saiSet = "DecapEcnMode: 1"; } - // The SAI tunnel objects currently programmed, one line each. - // The JSON output maps each host to that hw agent's text dump. - auto saiTunnels = [this]() { - std::set lines; - auto dump = runCliJson({"show", "hw-object", "IPTUNNEL"}); - for (const auto& [host, text] : dump.items()) { - std::istringstream out(text.asString()); - std::string line; - while (std::getline(out, line)) { - if (line.find("TunnelSaiId(") != std::string::npos) { - lines.insert(line); - } - } - } - return lines; - }; - int intfId = ensureUnderlayIntfId(); const std::string dstIp = findIpv6OnIntf(intfId); const std::string tunnelId = @@ -122,29 +105,14 @@ class TunnelIpInIpTest : public Fboss2IntegrationTest { } cmd.insert(cmd.end(), {"underlay-intf-id", std::to_string(intfId)}); - // Deletes the tunnel and the underlay VLAN. Armed as a guard so a failed - // check still leaves the DUT as found; runs explicitly in Step 3. + // Armed as a guard so a failed check still leaves the DUT as found; runs + // explicitly in Step 3. auto cleanup = [&]() { - try { - if (runCli({"delete", "tunnel", "ip-in-ip", direction, tunnelId}) - .exitCode == 0) { - commitConfig(); - } - auto config = getRunningConfig(); - for (const auto& intf : config["sw"]["interfaces"]) { - const auto* id = intf.get_ptr("intfID"); - const auto* vlan = intf.get_ptr("vlanID"); - if (id != nullptr && vlan != nullptr && id->asInt() == intfId) { - deleteVlanIfPresent(static_cast(vlan->asInt())); - } - } - } catch (const std::exception& e) { - ADD_FAILURE() << "cleanup failed: " << e.what(); - } + deleteTunnelAndUnderlay(direction, tunnelId, intfId); }; auto cleanupGuard = folly::makeGuard(cleanup); - const auto saiBefore = saiTunnels(); + const auto saiBefore = saiTunnelObjects("TunnelSaiId("); XLOG(INFO) << "[Step 1] Creating " << direction << " tunnel " << tunnelId << " with " << attr << " pipe..."; auto result = runCli(cmd); @@ -177,7 +145,7 @@ class TunnelIpInIpTest : public Fboss2IntegrationTest { EXPECT_GT(found, 0) << "tunnel '" << tunnelId << "' not in switch state"; std::vector added; - for (const auto& line : saiTunnels()) { + for (const auto& line : saiTunnelObjects("TunnelSaiId(")) { if (!saiBefore.count(line)) { added.push_back(line); } @@ -198,14 +166,59 @@ class TunnelIpInIpTest : public Fboss2IntegrationTest { XLOG(INFO) << "[Step 3] Deleting tunnel and underlay VLAN..."; cleanupGuard.dismiss(); cleanup(); - EXPECT_FALSE(findTunnelInRunningConfig(tunnelId).has_value()) - << "Tunnel '" << tunnelId << "' still present after delete"; - EXPECT_EQ(saiTunnels(), saiBefore) << "SAI tunnel left after delete"; - auto after = getRunningConfig(); - for (const auto& intf : after["sw"]["interfaces"]) { - const auto* id = intf.get_ptr("intfID"); - EXPECT_TRUE(id == nullptr || id->asInt() != intfId) - << "underlay interface " << intfId << " left behind"; + EXPECT_EQ(saiTunnelObjects("TunnelSaiId("), saiBefore) + << "SAI tunnel left after delete"; + } + + // The SAI tunnel objects whose 'show hw-object IPTUNNEL' line contains + // `prefix` ("TunnelSaiId(" for tunnels, "TunnelTermSaiId(" for tunnel + // terminations), one line per object. The JSON output maps each host to + // that hw agent's text dump. + std::set saiTunnelObjects(const std::string& prefix) { + std::set lines; + auto dump = runCliJson({"show", "hw-object", "IPTUNNEL"}); + for (const auto& [host, text] : dump.items()) { + std::istringstream out(text.asString()); + std::string line; + while (std::getline(out, line)) { + if (line.find(prefix) != std::string::npos) { + lines.insert(line); + } + } + } + return lines; + } + + // Deletes the tunnel, then the underlay VLAN and its interface that + // ensureUnderlayIntfId created for `intfId`, and checks both are gone. Safe + // to call when either is already absent, so tests also arm it as a guard. + void deleteTunnelAndUnderlay( + const std::string& direction, + const std::string& tunnelId, + int intfId) { + try { + if (runCli({"delete", "tunnel", "ip-in-ip", direction, tunnelId}) + .exitCode == 0) { + commitConfig(); + } + auto config = getRunningConfig(); + for (const auto& intf : config["sw"]["interfaces"]) { + const auto* id = intf.get_ptr("intfID"); + const auto* vlan = intf.get_ptr("vlanID"); + if (id != nullptr && vlan != nullptr && id->asInt() == intfId) { + deleteVlanIfPresent(static_cast(vlan->asInt())); + } + } + EXPECT_FALSE(findTunnelInRunningConfig(tunnelId).has_value()) + << "Tunnel '" << tunnelId << "' still present after delete"; + auto after = getRunningConfig(); + for (const auto& intf : after["sw"]["interfaces"]) { + const auto* id = intf.get_ptr("intfID"); + EXPECT_TRUE(id == nullptr || id->asInt() != intfId) + << "underlay interface " << intfId << " left behind"; + } + } catch (const std::exception& e) { + ADD_FAILURE() << "cleanup failed: " << e.what(); } } @@ -568,6 +581,108 @@ TEST_F(TunnelIpInIpTest, DecapEcnMode) { checkTunnelMode("decap", "ecn-mode"); } +// --------------------------------------------------------------------------- +// Positive: 'termination-type p2p' on a DECAP tunnel (the agent defaults to +// p2mp) is programmed as a P2P SAI tunnel term, which also matches on the +// outer source address; a P2MP term has no source. +// --------------------------------------------------------------------------- + +TEST_F(TunnelIpInIpTest, DecapTerminationType) { + // Fake SAI only implements P2MP tunnel terms and rejects a P2P one with + // ATTR_NOT_SUPPORTED, which aborts the hw agent (fboss-sim runs fake SAI). + const auto config = getRunningConfig(); + for (const auto& info : + config["sw"]["switchSettings"]["switchIdToSwitchInfo"].values()) { + switch (static_cast(info["asicType"].asInt())) { + case cfg::AsicType::ASIC_TYPE_FAKE: + case cfg::AsicType::ASIC_TYPE_FAKE_NO_WARMBOOT: + GTEST_SKIP() << "fake SAI does not support P2P tunnel terms"; + default: + break; + } + } + + int intfId = ensureUnderlayIntfId(); + const std::string dstIp = findIpv6OnIntf(intfId); + const std::string srcIp = "2001:db8:cafe::7"; + const std::string tunnelId = "integration-test-decap-p2p"; + const int p2p = static_cast(cfg::TunnelTerminationType::P2P); + + // Armed as a guard so a failed check still leaves the DUT as found; runs + // explicitly in Step 3. + auto cleanup = [&]() { deleteTunnelAndUnderlay("decap", tunnelId, intfId); }; + auto cleanupGuard = folly::makeGuard(cleanup); + const auto termsBefore = saiTunnelObjects("TunnelTermSaiId("); + + // ttl-mode pipe: see DeleteDecapTunnel. + XLOG(INFO) << "[Step 1] Creating decap tunnel " << tunnelId + << " with termination-type p2p..."; + auto result = runCli( + {"config", + "tunnel", + "ip-in-ip", + "decap", + tunnelId, + "destination", + dstIp, + "source", + srcIp, + "termination-type", + "p2p", + "ttl-mode", + "pipe", + "underlay-intf-id", + std::to_string(intfId)}); + ASSERT_EQ(result.exitCode, 0) << "Create failed: " << result.stderr; + commitConfig(); + trackTunnel(tunnelId, "decap"); + + XLOG(INFO) << "[Step 2] Verifying termination-type in config, state, SAI..."; + auto tunnel = waitForTunnelInRunningConfig(tunnelId, /*shouldExist=*/true); + ASSERT_TRUE(tunnel.has_value()) + << "Tunnel '" << tunnelId << "' not found in running config"; + ASSERT_TRUE(tunnel->count("tunnelTermType")) + << "tunnelTermType missing from running config"; + EXPECT_EQ((*tunnel)["tunnelTermType"].asInt(), p2p); + + // ipTunnelMaps: SwitchIdList -> tunnel id -> IpTunnelFields. + auto tunnelMaps = getSwitchState("ipTunnelMaps"); + int found = 0; + for (const auto& [switchIds, tunnels] : tunnelMaps.items()) { + const auto* state = tunnels.get_ptr(tunnelId); + if (state == nullptr) { + continue; + } + ++found; + const auto* termType = state->get_ptr("tunnelTermType"); + ASSERT_NE(termType, nullptr) << "tunnelTermType missing from switch state"; + EXPECT_EQ(termType->asInt(), p2p); + } + EXPECT_GT(found, 0) << "tunnel '" << tunnelId << "' not in switch state"; + + // SAI_TUNNEL_TERM_TABLE_ENTRY_TYPE_P2P = 0 (P2MP = 1, and has no SrcIp). + std::vector added; + for (const auto& line : saiTunnelObjects("TunnelTermSaiId(")) { + if (!termsBefore.count(line)) { + added.push_back(line); + } + } + ASSERT_EQ(added.size(), 1) << "expected one new SAI tunnel term"; + XLOG(INFO) << "New SAI tunnel term: " << added[0]; + EXPECT_NE(added[0].find("(Type: 0,"), std::string::npos) + << "SAI tunnel term is not P2P"; + EXPECT_NE(added[0].find(fmt::format("DstIp: {},", dstIp)), std::string::npos) + << "SAI tunnel term does not match the destination"; + EXPECT_NE(added[0].find(fmt::format("SrcIp: {},", srcIp)), std::string::npos) + << "SAI tunnel term does not match the outer source"; + + XLOG(INFO) << "[Step 3] Deleting tunnel and underlay VLAN..."; + cleanupGuard.dismiss(); + cleanup(); + EXPECT_EQ(saiTunnelObjects("TunnelTermSaiId("), termsBefore) + << "SAI tunnel term left after delete"; +} + // --------------------------------------------------------------------------- // Positive: reset an optional attr (ttl-mode) on a decap tunnel and confirm it // is gone from the running config while destination survives. From ed1f7ee2aef3f34c16e47be5b01ece0840838f77 Mon Sep 17 00:00:00 2001 From: abhinav-nexthop Date: Fri, 30 Oct 2026 02:03:10 +0530 Subject: [PATCH 4/4] Delete the underlay VLAN in TunnelIpInIpTest tests that commit a tunnel --- .../integration_test/TunnelIpInIpTest.cpp | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/fboss/cli/fboss2/test/integration_test/TunnelIpInIpTest.cpp b/fboss/cli/fboss2/test/integration_test/TunnelIpInIpTest.cpp index 3f821b5fde9..2e8661f72a0 100644 --- a/fboss/cli/fboss2/test/integration_test/TunnelIpInIpTest.cpp +++ b/fboss/cli/fboss2/test/integration_test/TunnelIpInIpTest.cpp @@ -404,6 +404,12 @@ TEST_F(TunnelIpInIpTest, CreateDecapTunnelAndVerifyRunningConfig) { const std::string dstIp = findIpv6OnIntf(intfId); const std::string srcIp = "2001:db8:cafe::1"; const std::string tunnelId = "integration-test-decap"; + // Drop the tunnel, then the underlay VLAN and its interface that + // ensureUnderlayIntfId created. Runs even when an assertion below fails, so + // the VLAN never outlives the test. + SCOPE_EXIT { + deleteTunnelAndUnderlay("decap", tunnelId, intfId); + }; XLOG(INFO) << "[Step 1] Creating decap tunnel " << tunnelId << " (underlayIntf=" << intfId << " dst=" << dstIp << ")..."; @@ -478,6 +484,12 @@ TEST_F(TunnelIpInIpTest, CreateEncapTunnelAndVerifyRunningConfig) { const std::string dstIp = findIpv6OnIntf(intfId); const std::string srcIp = "2001:db8:cafe::2"; const std::string tunnelId = "integration-test-encap"; + // Drop the tunnel, then the underlay VLAN and its interface that + // ensureUnderlayIntfId created. Runs even when an assertion below fails, so + // the VLAN never outlives the test. + SCOPE_EXIT { + deleteTunnelAndUnderlay("encap", tunnelId, intfId); + }; XLOG(INFO) << "[Step 1] Creating encap tunnel " << tunnelId << "..."; auto result = runCli( @@ -537,6 +549,12 @@ TEST_F(TunnelIpInIpTest, DeleteDecapTunnel) { int intfId = ensureUnderlayIntfId(); const std::string dstIp = findIpv6OnIntf(intfId); const std::string tunnelId = "integration-test-decap-delete"; + // The test deletes the tunnel; this drops the underlay VLAN and its + // interface that ensureUnderlayIntfId created, and the tunnel too if the + // test fails before deleting it. + SCOPE_EXIT { + deleteTunnelAndUnderlay("decap", tunnelId, intfId); + }; auto result = runCli( {"config", @@ -692,6 +710,12 @@ TEST_F(TunnelIpInIpTest, ResetOptionalAttrOnDecapTunnel) { int intfId = ensureUnderlayIntfId(); const std::string dstIp = findIpv6OnIntf(intfId); const std::string tunnelId = "integration-test-decap-reset"; + // Drop the tunnel, then the underlay VLAN and its interface that + // ensureUnderlayIntfId created. Runs even when an assertion below fails, so + // the VLAN never outlives the test. + SCOPE_EXIT { + deleteTunnelAndUnderlay("decap", tunnelId, intfId); + }; auto result = runCli( {"config", @@ -821,6 +845,12 @@ TEST_F(TunnelIpInIpTest, DeleteWrongDirectionRejected) { int intfId = ensureUnderlayIntfId(); const std::string dstIp = findIpv6OnIntf(intfId); const std::string tunnelId = "integration-test-encap-wrongdir"; + // Drop the tunnel, then the underlay VLAN and its interface that + // ensureUnderlayIntfId created. Runs even when an assertion below fails, so + // the VLAN never outlives the test, and after the discardSession() below. + SCOPE_EXIT { + deleteTunnelAndUnderlay("encap", tunnelId, intfId); + }; auto result = runCli( {"config",