From c6e54cabdff56a9c5b7c42ea462b6bf91aac890c Mon Sep 17 00:00:00 2001 From: mramezani95 Date: Mon, 18 Nov 2024 12:56:47 -0800 Subject: [PATCH] [mirror] erspan ipv6 underlay (see PR #1817) (#3317) * Applied changes from PR #1817 Why I did it Unlock erspan capability on td3 and beyond that supports erspan ipv6 encap. What I did Extend test_MirrorAddSetRemove, test_MirrorToVlanAddRemove, test_MirrorToLagAddRemove, test_MirrorDestMoveVlan, test_MirrorDestMoveLag to vs test erspan ipv6 encap On td3 --- orchagent/mirrororch.cpp | 28 +++-- tests/test_mirror.py | 248 ++++++++++++++++++++++++++------------- 2 files changed, 179 insertions(+), 97 deletions(-) diff --git a/orchagent/mirrororch.cpp b/orchagent/mirrororch.cpp index d2981330e42..b05f1c3288b 100644 --- a/orchagent/mirrororch.cpp +++ b/orchagent/mirrororch.cpp @@ -34,7 +34,8 @@ #define MIRROR_SESSION_DEFAULT_VLAN_PRI 0 #define MIRROR_SESSION_DEFAULT_VLAN_CFI 0 -#define MIRROR_SESSION_DEFAULT_IP_HDR_VER 4 +#define MIRROR_SESSION_IP_HDR_VER_4 4 +#define MIRROR_SESSION_IP_HDR_VER_6 6 #define MIRROR_SESSION_DSCP_SHIFT 2 #define MIRROR_SESSION_DSCP_MIN 0 #define MIRROR_SESSION_DSCP_MAX 63 @@ -380,6 +381,9 @@ task_process_status MirrorOrch::createEntry(const string& key, const vector 0 return { fv[0]: fv[1] for fv in fvs } + def mirror_session_entry_exists(self, name): + tbl = swsscommon.Table(self.sdb, "MIRROR_SESSION_TABLE") + (status, _) = tbl.get(name) + return status + def check_syslog(self, dvs, marker, log, expected_cnt): (ec, out) = dvs.runcmd(['sh', '-c', "awk \'/%s/,ENDFILE {print;}\' /var/log/syslog | grep \'%s\' | wc -l" % (marker, log)]) assert out.strip() == str(expected_cnt) - def test_MirrorAddRemove(self, dvs, testlog): + def test_MirrorInvalidEntry(self, dvs): + """ + This test ensures that an invalid mirror session entry is not created. + Here, "invalid" means an entry in which src IP is IPv4 while dst IP is IPv6 + (or vice versa). + """ + self.setup_db(dvs) + session = "TEST_SESSION" + self.create_mirror_session(session, "1.1.1.1", "fc00::2:2:2:2", "0x6558", "8", "100", "0") + assert self.mirror_session_entry_exists(session) == False + + def _test_MirrorAddRemove(self, dvs, testlog, v6_encap=False): """ This test covers the basic mirror session creation and removal operations Operation flow: @@ -119,34 +135,37 @@ def test_MirrorAddRemove(self, dvs, testlog): The session becomes inactive again till the end 4. Remove miror session """ - self.setup_db(dvs) - session = "TEST_SESSION" + src_ip = "1.1.1.1" if v6_encap == False else "fc00::1:1:1:1" + dst_ip = "2.2.2.2" if v6_encap == False else "fc00::2:2:2:2" + intf_addr = "10.0.0.0/31" if v6_encap == False else "fc00::/126" + nhop_ip = "10.0.0.1" if v6_encap == False else "fc00::1" marker = dvs.add_log_marker() # create mirror session - self.create_mirror_session(session, "1.1.1.1", "2.2.2.2", "0x6558", "8", "100", "0") + self.create_mirror_session(session, src_ip, dst_ip, "0x6558", "8", "100", "0") assert self.get_mirror_session_state(session)["status"] == "inactive" - self.check_syslog(dvs, marker, "Attached next hop observer .* for destination IP 2.2.2.2", 1) + assert self.get_mirror_session_state(session)["next_hop_ip"] == ("0.0.0.0@" if v6_encap == False else "::@") + self.check_syslog(dvs, marker, "Attached next hop observer .* for destination IP {}".format(dst_ip), 1) # bring up Ethernet16 self.set_interface_status(dvs, "Ethernet16", "up") assert self.get_mirror_session_state(session)["status"] == "inactive" # add IP address to Ethernet16 - self.add_ip_address("Ethernet16", "10.0.0.0/31") + self.add_ip_address("Ethernet16", intf_addr) assert self.get_mirror_session_state(session)["status"] == "inactive" # add neighbor to Ethernet16 - self.add_neighbor("Ethernet16", "10.0.0.1", "02:04:06:08:10:12") + self.add_neighbor("Ethernet16", nhop_ip, "02:04:06:08:10:12") assert self.get_mirror_session_state(session)["status"] == "inactive" - # add route to mirror destination via 10.0.0.1 - self.add_route(dvs, "2.2.2.2", "10.0.0.1") + # add route to mirror destination via next hop ip + self.add_route(dvs, dst_ip, nhop_ip) assert self.get_mirror_session_state(session)["status"] == "active" assert self.get_mirror_session_state(session)["monitor_port"] == "Ethernet16" assert self.get_mirror_session_state(session)["dst_mac"] == "02:04:06:08:10:12" - assert self.get_mirror_session_state(session)["route_prefix"] == "2.2.2.2/32" + assert self.get_mirror_session_state(session)["route_prefix"] == "{}/{}".format(dst_ip, 32 if v6_encap == False else 128) # check asic database tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_MIRROR_SESSION") @@ -164,15 +183,15 @@ def test_MirrorAddRemove(self, dvs, testlog): elif fv[0] == "SAI_MIRROR_SESSION_ATTR_ERSPAN_ENCAPSULATION_TYPE": assert fv[1] == "SAI_ERSPAN_ENCAPSULATION_TYPE_MIRROR_L3_GRE_TUNNEL" elif fv[0] == "SAI_MIRROR_SESSION_ATTR_IPHDR_VERSION": - assert fv[1] == "4" + assert fv[1] == "4" if v6_encap == False else "6" elif fv[0] == "SAI_MIRROR_SESSION_ATTR_TOS": assert fv[1] == "32" elif fv[0] == "SAI_MIRROR_SESSION_ATTR_TTL": assert fv[1] == "100" elif fv[0] == "SAI_MIRROR_SESSION_ATTR_SRC_IP_ADDRESS": - assert fv[1] == "1.1.1.1" + assert fv[1] == src_ip elif fv[0] == "SAI_MIRROR_SESSION_ATTR_DST_IP_ADDRESS": - assert fv[1] == "2.2.2.2" + assert fv[1] == dst_ip elif fv[0] == "SAI_MIRROR_SESSION_ATTR_SRC_MAC_ADDRESS": assert fv[1] == dvs.runcmd("bash -c \"ip link show eth0 | grep ether | awk '{print $2}'\"")[1].strip().upper() elif fv[0] == "SAI_MIRROR_SESSION_ATTR_DST_MAC_ADDRESS": @@ -183,15 +202,15 @@ def test_MirrorAddRemove(self, dvs, testlog): assert False # remove route - self.remove_route(dvs, "2.2.2.2") + self.remove_route(dvs, dst_ip) assert self.get_mirror_session_state(session)["status"] == "inactive" # remove neighbor - self.remove_neighbor("Ethernet16", "10.0.0.1") + self.remove_neighbor("Ethernet16", nhop_ip) assert self.get_mirror_session_state(session)["status"] == "inactive" # remove IP address - self.remove_ip_address("Ethernet16", "10.0.0.0/31") + self.remove_ip_address("Ethernet16", intf_addr) assert self.get_mirror_session_state(session)["status"] == "inactive" # bring down Ethernet16 @@ -201,7 +220,13 @@ def test_MirrorAddRemove(self, dvs, testlog): marker = dvs.add_log_marker() # remove mirror session self.remove_mirror_session(session) - self.check_syslog(dvs, marker, "Detached next hop observer for destination IP 2.2.2.2", 1) + self.check_syslog(dvs, marker, "Detached next hop observer for destination IP {}".format(dst_ip), 1) + + def test_MirrorAddRemove(self, dvs, testlog): + self.setup_db(dvs) + + self._test_MirrorAddRemove(dvs, testlog) + self._test_MirrorAddRemove(dvs, testlog, v6_encap=True) def create_vlan(self, dvs, vlan): #dvs.runcmd("ip link del Bridge") @@ -239,11 +264,7 @@ def remove_fdb(self, vlan, mac): tbl._del("Vlan" + vlan + ":" + mac) time.sleep(1) - - # Ignore testcase in Debian Jessie - # TODO: Remove this skip if Jessie support is no longer needed - @pytest.mark.skipif(StrictVersion(distro.linux_distribution()[1]) <= StrictVersion('8.9'), reason="Debian 8.9 or before has no support") - def test_MirrorToVlanAddRemove(self, dvs, testlog): + def _test_MirrorToVlanAddRemove(self, dvs, testlog, v6_encap=False): """ This test covers basic mirror session creation and removal operation with destination port sits in a VLAN @@ -254,15 +275,18 @@ def test_MirrorToVlanAddRemove(self, dvs, testlog): 3. Remove FDB; remove neighbor; remove IP; remove VLAN 4. Remove mirror session """ - self.setup_db(dvs) - session = "TEST_SESSION" + src_ip = "5.5.5.5" if v6_encap == False else "fc00::5:5:5:5" + # dst ip in directly connected vlan subnet + dst_ip = "6.6.6.6" if v6_encap == False else "fc00::6:6:6:6" + intf_addr = "6.6.6.0/24" if v6_encap == False else "fc00::6:6:6:0/112" marker = dvs.add_log_marker() # create mirror session - self.create_mirror_session(session, "5.5.5.5", "6.6.6.6", "0x6558", "8", "100", "0") + self.create_mirror_session(session, src_ip, dst_ip, "0x6558", "8", "100", "0") assert self.get_mirror_session_state(session)["status"] == "inactive" - self.check_syslog(dvs, marker, "Attached next hop observer .* for destination IP 6.6.6.6", 1) + assert self.get_mirror_session_state(session)["next_hop_ip"] == ("0.0.0.0@" if v6_encap == False else "::@") + self.check_syslog(dvs, marker, "Attached next hop observer .* for destination IP {}".format(dst_ip), 1) # create vlan; create vlan member self.create_vlan(dvs, "6") @@ -273,11 +297,11 @@ def test_MirrorToVlanAddRemove(self, dvs, testlog): self.set_interface_status(dvs, "Ethernet4", "up") # add ip address to vlan 6 - self.add_ip_address("Vlan6", "6.6.6.0/24") + self.add_ip_address("Vlan6", intf_addr) assert self.get_mirror_session_state(session)["status"] == "inactive" # create neighbor to vlan 6 - self.add_neighbor("Vlan6", "6.6.6.6", "66:66:66:66:66:66") + self.add_neighbor("Vlan6", dst_ip, "66:66:66:66:66:66") assert self.get_mirror_session_state(session)["status"] == "inactive" # create fdb entry to ethernet4 @@ -300,15 +324,15 @@ def test_MirrorToVlanAddRemove(self, dvs, testlog): elif fv[0] == "SAI_MIRROR_SESSION_ATTR_ERSPAN_ENCAPSULATION_TYPE": assert fv[1] == "SAI_ERSPAN_ENCAPSULATION_TYPE_MIRROR_L3_GRE_TUNNEL" elif fv[0] == "SAI_MIRROR_SESSION_ATTR_IPHDR_VERSION": - assert fv[1] == "4" + assert fv[1] == "4" if v6_encap == False else "6" elif fv[0] == "SAI_MIRROR_SESSION_ATTR_TOS": assert fv[1] == "32" elif fv[0] == "SAI_MIRROR_SESSION_ATTR_TTL": assert fv[1] == "100" elif fv[0] == "SAI_MIRROR_SESSION_ATTR_SRC_IP_ADDRESS": - assert fv[1] == "5.5.5.5" + assert fv[1] == src_ip elif fv[0] == "SAI_MIRROR_SESSION_ATTR_DST_IP_ADDRESS": - assert fv[1] == "6.6.6.6" + assert fv[1] == dst_ip elif fv[0] == "SAI_MIRROR_SESSION_ATTR_SRC_MAC_ADDRESS": assert fv[1] == dvs.runcmd("bash -c \"ip link show eth0 | grep ether | awk '{print $2}'\"")[1].strip().upper() elif fv[0] == "SAI_MIRROR_SESSION_ATTR_DST_MAC_ADDRESS": @@ -333,11 +357,11 @@ def test_MirrorToVlanAddRemove(self, dvs, testlog): assert self.get_mirror_session_state(session)["status"] == "inactive" # remove neighbor - self.remove_neighbor("Vlan6", "6.6.6.6") + self.remove_neighbor("Vlan6", dst_ip) assert self.get_mirror_session_state(session)["status"] == "inactive" # remove ip address - self.remove_ip_address("Vlan6", "6.6.6.0/24") + self.remove_ip_address("Vlan6", intf_addr) assert self.get_mirror_session_state(session)["status"] == "inactive" # bring down vlan and member @@ -351,7 +375,16 @@ def test_MirrorToVlanAddRemove(self, dvs, testlog): marker = dvs.add_log_marker() # remove mirror session self.remove_mirror_session(session) - self.check_syslog(dvs, marker, "Detached next hop observer for destination IP 6.6.6.6", 1) + self.check_syslog(dvs, marker, "Detached next hop observer for destination IP {}".format(dst_ip), 1) + + # Ignore testcase in Debian Jessie + # TODO: Remove this skip if Jessie support is no longer needed + @pytest.mark.skipif(StrictVersion(distro.linux_distribution()[1]) <= StrictVersion('8.9'), reason="Debian 8.9 or before has no support") + def test_MirrorToVlanAddRemove(self, dvs, testlog): + self.setup_db(dvs) + + self._test_MirrorToVlanAddRemove(dvs, testlog) + self._test_MirrorToVlanAddRemove(dvs, testlog, v6_encap=True) def create_port_channel(self, dvs, channel): tbl = swsscommon.ProducerStateTable(self.pdb, "LAG_TABLE") @@ -382,8 +415,7 @@ def remove_port_channel_member(self, channel, interface): tbl._del("PortChannel" + channel + ":" + interface) time.sleep(1) - - def test_MirrorToLagAddRemove(self, dvs, testlog): + def _test_MirrorToLagAddRemove(self, dvs, testlog, v6_encap=False): """ This test covers basic mirror session creation and removal operations with destination port sits in a LAG @@ -395,15 +427,18 @@ def test_MirrorToLagAddRemove(self, dvs, testlog): 4. Remove mirror session """ - self.setup_db(dvs) - session = "TEST_SESSION" + src_ip = "10.10.10.10" if v6_encap == False else "fc00::10:10:10:10" + dst_ip = "11.11.11.11" if v6_encap == False else "fc00::11:11:11:11" + # dst ip in directly connected subnet + intf_addr = "11.11.11.0/24" if v6_encap == False else "fc00::11:11:11:0/112" marker = dvs.add_log_marker() # create mirror session - self.create_mirror_session(session, "10.10.10.10", "11.11.11.11", "0x6558", "8", "100", "0") + self.create_mirror_session(session, src_ip, dst_ip, "0x6558", "8", "100", "0") assert self.get_mirror_session_state(session)["status"] == "inactive" - self.check_syslog(dvs, marker, "Attached next hop observer .* for destination IP 11.11.11.11", 1) + assert self.get_mirror_session_state(session)["next_hop_ip"] == ("0.0.0.0@" if v6_encap == False else "::@") + self.check_syslog(dvs, marker, "Attached next hop observer .* for destination IP {}".format(dst_ip), 1) # create port channel; create port channel member self.create_port_channel(dvs, "008") @@ -414,11 +449,11 @@ def test_MirrorToLagAddRemove(self, dvs, testlog): self.set_interface_status(dvs, "Ethernet88", "up") # add ip address to port channel 008 - self.add_ip_address("PortChannel008", "11.11.11.0/24") + self.add_ip_address("PortChannel008", intf_addr) assert self.get_mirror_session_state(session)["status"] == "inactive" # create neighbor to port channel 008 - self.add_neighbor("PortChannel008", "11.11.11.11", "88:88:88:88:88:88") + self.add_neighbor("PortChannel008", dst_ip, "88:88:88:88:88:88") assert self.get_mirror_session_state(session)["status"] == "active" # check asic database @@ -432,13 +467,15 @@ def test_MirrorToLagAddRemove(self, dvs, testlog): assert dvs.asicdb.portoidmap[fv[1]] == "Ethernet88" elif fv[0] == "SAI_MIRROR_SESSION_ATTR_DST_MAC_ADDRESS": assert fv[1] == "88:88:88:88:88:88" + elif fv[0] == "SAI_MIRROR_SESSION_ATTR_IPHDR_VERSION": + assert fv[1] == "4" if v6_encap == False else "6" # remove neighbor - self.remove_neighbor("PortChannel008", "11.11.11.11") + self.remove_neighbor("PortChannel008", dst_ip) assert self.get_mirror_session_state(session)["status"] == "inactive" # remove ip address - self.remove_ip_address("PortChannel008", "11.11.11.0/24") + self.remove_ip_address("PortChannel008", intf_addr) assert self.get_mirror_session_state(session)["status"] == "inactive" # bring down port channel and port channel member @@ -452,13 +489,15 @@ def test_MirrorToLagAddRemove(self, dvs, testlog): marker = dvs.add_log_marker() # remove mirror session self.remove_mirror_session(session) - self.check_syslog(dvs, marker, "Detached next hop observer for destination IP 11.11.11.11", 1) + self.check_syslog(dvs, marker, "Detached next hop observer for destination IP {}".format(dst_ip), 1) + def test_MirrorToLagAddRemove(self, dvs, testlog): + self.setup_db(dvs) - # Ignore testcase in Debian Jessie - # TODO: Remove this skip if Jessie support is no longer needed - @pytest.mark.skipif(StrictVersion(distro.linux_distribution()[1]) <= StrictVersion('8.9'), reason="Debian 8.9 or before has no support") - def test_MirrorDestMoveVlan(self, dvs, testlog): + self._test_MirrorToLagAddRemove(dvs, testlog) + self._test_MirrorToLagAddRemove(dvs, testlog, v6_encap=True) + + def _test_MirrorDestMoveVlan(self, dvs, testlog, v6_encap=False): """ This test tests mirror session destination move from non-VLAN to VLAN and back to non-VLAN port @@ -471,19 +510,25 @@ def test_MirrorDestMoveVlan(self, dvs, testlog): 7. Disable non-VLAN monitor port 8. Remove mirror session """ - self.setup_db(dvs) - session = "TEST_SESSION" + src_ip = "7.7.7.7" if v6_encap == False else "fc00::7:7:7:7" + dst_ip = "8.8.8.8" if v6_encap == False else "fc00::8:8:8:8" + port_intf_addr = "80.0.0.0/31" if v6_encap == False else "fc00::80:0:0:0/126" + port_nhop_ip = "80.0.0.1" if v6_encap == False else "fc00::80:0:0:1" + port_ip_prefix = "8.8.0.0/16" if v6_encap == False else "fc00::8:8:0:0/96" + # dst ip moves to directly connected vlan subnet + vlan_intf_addr = "8.8.8.0/24" if v6_encap == False else "fc00::8:8:8:0/112" # create mirror session - self.create_mirror_session(session, "7.7.7.7", "8.8.8.8", "0x6558", "8", "100", "0") + self.create_mirror_session(session, src_ip, dst_ip, "0x6558", "8", "100", "0") assert self.get_mirror_session_state(session)["status"] == "inactive" + assert self.get_mirror_session_state(session)["next_hop_ip"] == ("0.0.0.0@" if v6_encap == False else "::@") # bring up port; add ip; add neighbor; add route self.set_interface_status(dvs, "Ethernet32", "up") - self.add_ip_address("Ethernet32", "80.0.0.0/31") - self.add_neighbor("Ethernet32", "80.0.0.1", "02:04:06:08:10:12") - self.add_route(dvs, "8.8.0.0/16", "80.0.0.1") + self.add_ip_address("Ethernet32", port_intf_addr) + self.add_neighbor("Ethernet32", port_nhop_ip, "02:04:06:08:10:12") + self.add_route(dvs, port_ip_prefix, port_nhop_ip) assert self.get_mirror_session_state(session)["status"] == "active" # check monitor port @@ -496,6 +541,8 @@ def test_MirrorDestMoveVlan(self, dvs, testlog): assert dvs.asicdb.portoidmap[fv[1]] == "Ethernet32" elif fv[0] == "SAI_MIRROR_SESSION_ATTR_VLAN_HEADER_VALID": assert fv[1] == "false" + elif fv[0] == "SAI_MIRROR_SESSION_ATTR_IPHDR_VERSION": + assert fv[1] == "4" if v6_encap == False else "6" # mirror session move round 1 # create vlan; create vlan member; bring up vlan and member @@ -506,11 +553,13 @@ def test_MirrorDestMoveVlan(self, dvs, testlog): assert self.get_mirror_session_state(session)["status"] == "active" # add ip address to vlan 9 - self.add_ip_address("Vlan9", "8.8.8.0/24") + self.add_ip_address("Vlan9", vlan_intf_addr) + time.sleep(2) + # inactive due to no neighbor mac or fdb entry assert self.get_mirror_session_state(session)["status"] == "inactive" # create neighbor to vlan 9 - self.add_neighbor("Vlan9", "8.8.8.8", "88:88:88:88:88:88") + self.add_neighbor("Vlan9", dst_ip, "88:88:88:88:88:88") assert self.get_mirror_session_state(session)["status"] == "inactive" # create fdb entry to ethernet48 @@ -535,6 +584,8 @@ def test_MirrorDestMoveVlan(self, dvs, testlog): assert fv[1] == "0" elif fv[0] == "SAI_MIRROR_SESSION_ATTR_VLAN_CFI": assert fv[1] == "0" + elif fv[0] == "SAI_MIRROR_SESSION_ATTR_IPHDR_VERSION": + assert fv[1] == "4" if v6_encap == False else "6" # mirror session move round 2 # remove fdb entry @@ -542,11 +593,11 @@ def test_MirrorDestMoveVlan(self, dvs, testlog): assert self.get_mirror_session_state(session)["status"] == "inactive" # remove neighbor - self.remove_neighbor("Vlan9", "8.8.8.8") + self.remove_neighbor("Vlan9", dst_ip) assert self.get_mirror_session_state(session)["status"] == "inactive" # remove ip address - self.remove_ip_address("Vlan9", "8.8.8.0/24") + self.remove_ip_address("Vlan9", vlan_intf_addr) assert self.get_mirror_session_state(session)["status"] == "active" # check monitor port @@ -559,6 +610,8 @@ def test_MirrorDestMoveVlan(self, dvs, testlog): assert dvs.asicdb.portoidmap[fv[1]] == "Ethernet32" elif fv[0] == "SAI_MIRROR_SESSION_ATTR_VLAN_HEADER_VALID": assert fv[1] == "false" + elif fv[0] == "SAI_MIRROR_SESSION_ATTR_IPHDR_VERSION": + assert fv[1] == "4" if v6_encap == False else "6" # bring down vlan and member; remove vlan member; remove vlan self.set_interface_status(dvs, "Ethernet48", "down") @@ -567,16 +620,24 @@ def test_MirrorDestMoveVlan(self, dvs, testlog): self.remove_vlan("9") # remove route; remove neighbor; remove ip; bring down port - self.remove_route(dvs, "8.8.8.0/24") - self.remove_neighbor("Ethernet32", "80.0.0.1") - self.remove_ip_address("Ethernet32", "80.0.0.0/31") + self.remove_route(dvs, vlan_intf_addr) + self.remove_neighbor("Ethernet32", port_nhop_ip) + self.remove_ip_address("Ethernet32", port_intf_addr) self.set_interface_status(dvs, "Ethernet32", "down") # remove mirror session self.remove_mirror_session(session) + # Ignore testcase in Debian Jessie + # TODO: Remove this skip if Jessie support is no longer needed + @pytest.mark.skipif(StrictVersion(distro.linux_distribution()[1]) <= StrictVersion('8.9'), reason="Debian 8.9 or before has no support") + def test_MirrorDestMoveVlan(self, dvs, testlog): + self.setup_db(dvs) + + self._test_MirrorDestMoveVlan(dvs, testlog) + self._test_MirrorDestMoveVlan(dvs, testlog, v6_encap=True) - def test_MirrorDestMoveLag(self, dvs, testlog): + def _test_MirrorDestMoveLag(self, dvs, testlog, v6_encap=False): """ This test tests mirror session destination move from non-LAG to LAG and back to non-LAG port @@ -589,19 +650,26 @@ def test_MirrorDestMoveLag(self, dvs, testlog): 7. Disable non-LAG monitor port 8. Remove mirror session """ - self.setup_db(dvs) - session = "TEST_SESSION" + src_ip = "12.12.12.12" if v6_encap == False else "fc00::12:12:12:12" + dst_ip = "13.13.13.13" if v6_encap == False else "fc00::13:13:13:13" + port_intf_addr = "100.0.0.0/31" if v6_encap == False else "fc00::100:0:0:0/126" + port_nhop_ip = "100.0.0.1" if v6_encap == False else "fc00::100:0:0:1" + port_ip_prefix = "13.13.0.0/16" if v6_encap == False else "fc00::13:13:0:0/96" + lag_intf_addr = "200.0.0.0/31" if v6_encap == False else "fc00::200:0:0:0/126" + lag_nhop_ip = "200.0.0.1" if v6_encap == False else "fc00::200:0:0:1" + lag_ip_prefix = "13.13.13.0/24" if v6_encap == False else "fc00::13:13:13:0/112" # create mirror session - self.create_mirror_session(session, "12.12.12.12", "13.13.13.13", "0x6558", "8", "100", "0") + self.create_mirror_session(session, src_ip, dst_ip, "0x6558", "8", "100", "0") assert self.get_mirror_session_state(session)["status"] == "inactive" + assert self.get_mirror_session_state(session)["next_hop_ip"] == ("0.0.0.0@" if v6_encap == False else "::@") # bring up port; add ip; add neighbor; add route self.set_interface_status(dvs, "Ethernet64", "up") - self.add_ip_address("Ethernet64", "100.0.0.0/31") - self.add_neighbor("Ethernet64", "100.0.0.1", "02:04:06:08:10:12") - self.add_route(dvs, "13.13.0.0/16", "100.0.0.1") + self.add_ip_address("Ethernet64", port_intf_addr) + self.add_neighbor("Ethernet64", port_nhop_ip, "02:04:06:08:10:12") + self.add_route(dvs, port_ip_prefix, port_nhop_ip) assert self.get_mirror_session_state(session)["status"] == "active" # check monitor port @@ -612,8 +680,10 @@ def test_MirrorDestMoveLag(self, dvs, testlog): for fv in fvs: if fv[0] == "SAI_MIRROR_SESSION_ATTR_MONITOR_PORT": assert dvs.asicdb.portoidmap[fv[1]] == "Ethernet64" - if fv[0] == "SAI_MIRROR_SESSION_ATTR_DST_MAC_ADDRESS": + elif fv[0] == "SAI_MIRROR_SESSION_ATTR_DST_MAC_ADDRESS": assert fv[1] == "02:04:06:08:10:12" + elif fv[0] == "SAI_MIRROR_SESSION_ATTR_IPHDR_VERSION": + assert fv[1] == "4" if v6_encap == False else "6" # mirror session move round 1 # create port channel; create port channel member; bring up @@ -623,12 +693,12 @@ def test_MirrorDestMoveLag(self, dvs, testlog): self.set_interface_status(dvs, "Ethernet32", "up") # add ip address to port channel 080; create neighbor to port channel 080 - self.add_ip_address("PortChannel080", "200.0.0.0/31") - self.add_neighbor("PortChannel080", "200.0.0.1", "12:10:08:06:04:02") + self.add_ip_address("PortChannel080", lag_intf_addr) + self.add_neighbor("PortChannel080", lag_nhop_ip, "12:10:08:06:04:02") assert self.get_mirror_session_state(session)["status"] == "active" # add route - self.add_route(dvs, "13.13.13.0/24", "200.0.0.1") + self.add_route(dvs, lag_ip_prefix, lag_nhop_ip) assert self.get_mirror_session_state(session)["status"] == "active" # check monitor port @@ -639,8 +709,10 @@ def test_MirrorDestMoveLag(self, dvs, testlog): for fv in fvs: if fv[0] == "SAI_MIRROR_SESSION_ATTR_MONITOR_PORT": assert dvs.asicdb.portoidmap[fv[1]] == "Ethernet32" - if fv[0] == "SAI_MIRROR_SESSION_ATTR_DST_MAC_ADDRESS": + elif fv[0] == "SAI_MIRROR_SESSION_ATTR_DST_MAC_ADDRESS": assert fv[1] == "12:10:08:06:04:02" + elif fv[0] == "SAI_MIRROR_SESSION_ATTR_IPHDR_VERSION": + assert fv[1] == "4" if v6_encap == False else "6" # mirror session move round 2 # remove port channel member @@ -660,15 +732,16 @@ def test_MirrorDestMoveLag(self, dvs, testlog): for fv in fvs: if fv[0] == "SAI_MIRROR_SESSION_ATTR_MONITOR_PORT": assert dvs.asicdb.portoidmap[fv[1]] == "Ethernet32" - if fv[0] == "SAI_MIRROR_SESSION_ATTR_DST_MAC_ADDRESS": + elif fv[0] == "SAI_MIRROR_SESSION_ATTR_DST_MAC_ADDRESS": assert fv[1] == "12:10:08:06:04:02" + elif fv[0] == "SAI_MIRROR_SESSION_ATTR_IPHDR_VERSION": + assert fv[1] == "4" if v6_encap == False else "6" # mirror session move round 4 # remove route - self.remove_route(dvs, "13.13.13.0/24") + self.remove_route(dvs, lag_ip_prefix) assert self.get_mirror_session_state(session)["status"] == "active" - port_oid = "" # check monitor port tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_MIRROR_SESSION") assert len(tbl.getKeys()) == 1 @@ -677,12 +750,14 @@ def test_MirrorDestMoveLag(self, dvs, testlog): for fv in fvs: if fv[0] == "SAI_MIRROR_SESSION_ATTR_MONITOR_PORT": assert dvs.asicdb.portoidmap[fv[1]] == "Ethernet64" - if fv[0] == "SAI_MIRROR_SESSION_ATTR_DST_MAC_ADDRESS": + elif fv[0] == "SAI_MIRROR_SESSION_ATTR_DST_MAC_ADDRESS": assert fv[1] == "02:04:06:08:10:12" + elif fv[0] == "SAI_MIRROR_SESSION_ATTR_IPHDR_VERSION": + assert fv[1] == "4" if v6_encap == False else "6" # remove neighbor; remove ip address to port channel 080 - self.remove_neighbor("PortChannel080", "200.0.0.1") - self.remove_ip_address("PortChannel080", "200.0.0.0/31") + self.remove_neighbor("PortChannel080", lag_nhop_ip) + self.remove_ip_address("PortChannel080", lag_intf_addr) # bring down; remove port channel member; remove port channel self.set_interface_status(dvs, "Ethernet32", "down") @@ -692,15 +767,20 @@ def test_MirrorDestMoveLag(self, dvs, testlog): assert self.get_mirror_session_state(session)["status"] == "active" # remove route; remove neighbor; remove ip; bring down port - self.remove_route(dvs, "13.13.0.0/16") - self.remove_neighbor("Ethernet64", "100.0.0.1") - self.remove_ip_address("Ethernet64", "100.0.0.0/31") + self.remove_route(dvs, port_ip_prefix) + self.remove_neighbor("Ethernet64", port_nhop_ip) + self.remove_ip_address("Ethernet64", port_intf_addr) self.set_interface_status(dvs, "Ethernet64", "down") assert self.get_mirror_session_state(session)["status"] == "inactive" # remove mirror session self.remove_mirror_session(session) + def test_MirrorDestMoveLag(self, dvs, testlog): + self.setup_db(dvs) + + self._test_MirrorDestMoveLag(dvs, testlog) + self._test_MirrorDestMoveLag(dvs, testlog, v6_encap=True) def create_acl_table(self, table, interfaces): tbl = swsscommon.Table(self.cdb, "ACL_TABLE")