From 7796b108dcce469cd536e3d92fbd8a42b2e124cd Mon Sep 17 00:00:00 2001 From: "shine.chen" Date: Mon, 11 Mar 2019 00:00:40 -0700 Subject: [PATCH 01/17] [intfsorch]: add support to change rif mac-address Signed-off-by: shine.chen --- orchagent/intfsorch.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/orchagent/intfsorch.cpp b/orchagent/intfsorch.cpp index 4421caae8c..bff3423098 100644 --- a/orchagent/intfsorch.cpp +++ b/orchagent/intfsorch.cpp @@ -181,6 +181,10 @@ void IntfsOrch::doTask(Consumer &consumer) while (it != consumer.m_toSync.end()) { KeyOpFieldsValuesTuple t = it->second; + MacAddress mac; + int mac_attr_set; + + mac_attr_set = 0; vector keys = tokenize(kfvKey(t), ':'); string alias(keys[0]); @@ -208,6 +212,12 @@ void IntfsOrch::doTask(Consumer &consumer) { vnet_name = value; } + else if (field == "mac_addr") + { + mac_attr_set = 1; + + mac = MacAddress(value); + } } if (alias == "eth0" || alias == "docker0") @@ -299,6 +309,31 @@ void IntfsOrch::doTask(Consumer &consumer) } } + if (mac_attr_set == 1) + { + auto it_intfs = m_syncdIntfses.find(alias); + if (it_intfs != m_syncdIntfses.end()) + { + /* Get mac information and update mac of the interface*/ + sai_attribute_t attr; + + attr.id = SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS; + memcpy(attr.value.mac, mac.getMac(), sizeof(sai_mac_t)); + + sai_status_t status = sai_router_intfs_api->set_router_interface_attribute(port.m_rif_id, &attr); + if (status != SAI_STATUS_SUCCESS) + { + SWSS_LOG_ERROR("Failed to set router interface mac %s for port %s, rv:%d", + mac.to_string().c_str(), port.m_alias.c_str(), status); + } + else + { + SWSS_LOG_NOTICE("Set router interface mac %s for port %s success", + mac.to_string().c_str(), port.m_alias.c_str()); + } + } + } + it = consumer.m_toSync.erase(it); } else if (op == DEL_COMMAND) From af68d1056d31b06d06db16937e28cafba7ebe9de Mon Sep 17 00:00:00 2001 From: "leo.li" Date: Sun, 2 Jun 2019 08:01:59 -0700 Subject: [PATCH 02/17] add the corresponding vs-test Signed-off-by: leo.li --- tests/test_intf_mac.py | 248 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 248 insertions(+) create mode 100644 tests/test_intf_mac.py diff --git a/tests/test_intf_mac.py b/tests/test_intf_mac.py new file mode 100644 index 0000000000..95d367a067 --- /dev/null +++ b/tests/test_intf_mac.py @@ -0,0 +1,248 @@ +from swsscommon import swsscommon + +import time +import json + +class TestRouterInterfaceMac(object): + def setup_db(self, dvs): + self.pdb = swsscommon.DBConnector(0, dvs.redis_sock, 0) + self.adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) + self.cdb = swsscommon.DBConnector(4, dvs.redis_sock, 0) + + def add_ip_address(self, interface, ip): + tbl = swsscommon.Table(self.cdb, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL", "NULL")]) + tbl.set(interface + "|" + ip, fvs) + time.sleep(2) # IPv6 netlink message needs longer time + + def remove_ip_address(self, interface, ip): + tbl = swsscommon.Table(self.cdb, "INTERFACE") + tbl._del(interface + "|" + ip); + time.sleep(1) + + def set_mac(self, interface, mac, ip): + tbl = swsscommon.Table(self.cdb, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("mac_addr", mac)]) + tbl.set(interface + "|" + ip, fvs) + time.sleep(2) + + def test_InterfaceSetMac(self, dvs, testlog): + self.setup_db(dvs) + + # assign IP to interface + self.add_ip_address("Ethernet8", "10.0.0.4/31") + + # check application database + tbl = swsscommon.Table(self.pdb, "INTF_TABLE:Ethernet8") + intf_entries = tbl.getKeys() + assert len(intf_entries) == 1 + assert intf_entries[0] == "10.0.0.4/31" + + (status, fvs) = tbl.get(tbl.getKeys()[0]) + assert status == True + assert len(fvs) == 2 + for fv in fvs: + if fv[0] == "scope": + assert fv[1] == "global" + elif fv[0] == "family": + assert fv[1] == "IPv4" + else: + assert False + + # check ASIC router interface database + tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE") + intf_entries = tbl.getKeys() + # one loopback router interface one port based router interface + #assert len(intf_entries) == 2 + + for key in intf_entries: + (status, fvs) = tbl.get(key) + assert status == True + # a port based router interface has five field/value tuples + if len(fvs) == 5: + for fv in fvs: + if fv[0] == "SAI_ROUTER_INTERFACE_ATTR_TYPE": + assert fv[1] == "SAI_ROUTER_INTERFACE_TYPE_PORT" + # the default MTU without any configuration is 9100 + if fv[0] == "SAI_ROUTER_INTERFACE_ATTR_MTU": + assert fv[1] == "9100" + + # set MAC to interface + self.set_mac("Ethernet8", "6C:EC:5A:11:22:33", "10.0.0.4/31") + + # check application database + tbl = swsscommon.Table(self.pdb, "INTF_TABLE:Ethernet8") + (status, fvs) = tbl.get(tbl.getKeys()[0]) + assert status == True + assert len(fvs) == 3 + for fv in fvs: + if fv[0] == "scope": + assert fv[1] == "global" + elif fv[0] == "family": + assert fv[1] == "IPv4" + elif fv[0] == "mac_addr": + assert fv[1] == "6c:ec:5a:11:22:33" + else: + assert False + + # check ASIC router interface database + tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE") + intf_entries = tbl.getKeys() + # one loopback router interface one port based router interface + #assert len(intf_entries) == 2 + + for key in intf_entries: + (status, fvs) = tbl.get(key) + assert status == True + # a port based router interface has five field/value tuples + if len(fvs) == 5: + for fv in fvs: + # check the MAC + if fv[0] == "SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS": + assert fv[1] == "6C:EC:5A:11:22:33" + + # remove IP from interface + self.remove_ip_address("Ethernet8", "10.0.0.4/31") + + # check application database + tbl = swsscommon.Table(self.pdb, "INTF_TABLE:Ethernet8") + intf_entries = tbl.getKeys() + assert len(intf_entries) == 0 + +class TestLagRouterInterfaceMac(object): + def setup_db(self, dvs): + self.pdb = swsscommon.DBConnector(0, dvs.redis_sock, 0) + self.adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) + self.cdb = swsscommon.DBConnector(4, dvs.redis_sock, 0) + + def create_port_channel(self, dvs, alias): + tbl = swsscommon.Table(self.cdb, "PORTCHANNEL") + fvs = swsscommon.FieldValuePairs([("admin_status", "up"), + ("mtu", "9100")]) + tbl.set(alias, fvs) + time.sleep(1) + + def remove_port_channel(self, dvs, alias): + tbl = swsscommon.Table(self.cdb, "PORTCHANNEL") + tbl._del(alias) + time.sleep(1) + + def add_port_channel_members(self, dvs, lag, members): + tbl = swsscommon.Table(self.cdb, "PORTCHANNEL_MEMBER") + fvs = swsscommon.FieldValuePairs([("NULL", "NULL")]) + for member in members: + tbl.set(lag + "|" + member, fvs) + time.sleep(1) + + def remove_port_channel_members(self, dvs, lag, members): + tbl = swsscommon.Table(self.cdb, "PORTCHANNEL_MEMBER") + for member in members: + tbl._del(lag + "|" + member) + time.sleep(1) + + def add_ip_address(self, interface, ip): + tbl = swsscommon.Table(self.cdb, "PORTCHANNEL_INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL", "NULL")]) + tbl.set(interface + "|" + ip, fvs) + time.sleep(1) + + def remove_ip_address(self, interface, ip): + tbl = swsscommon.Table(self.cdb, "PORTCHANNEL_INTERFACE") + tbl._del(interface + "|" + ip); + time.sleep(1) + + def set_mac(self, interface, mac, ip): + tbl = swsscommon.Table(self.cdb, "PORTCHANNEL_INTERFACE") + fvs = swsscommon.FieldValuePairs([("mac_addr", mac)]) + tbl.set(interface + "|" + ip, fvs) + time.sleep(2) + + def test_InterfaceSetMac(self, dvs, testlog): + self.setup_db(dvs) + + # create port channel + self.create_port_channel(dvs, "PortChannel001") + + # assign IP to interface + self.add_ip_address("PortChannel001", "30.0.0.4/31") + + # check application database + tbl = swsscommon.Table(self.pdb, "INTF_TABLE:PortChannel001") + intf_entries = tbl.getKeys() + assert len(intf_entries) == 1 + assert intf_entries[0] == "30.0.0.4/31" + + (status, fvs) = tbl.get(tbl.getKeys()[0]) + assert status == True + assert len(fvs) == 2 + for fv in fvs: + if fv[0] == "scope": + assert fv[1] == "global" + elif fv[0] == "family": + assert fv[1] == "IPv4" + else: + assert False + + # check ASIC router interface database + tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE") + intf_entries = tbl.getKeys() + # one loopback router interface one port based router interface + #assert len(intf_entries) == 2 + + for key in intf_entries: + (status, fvs) = tbl.get(key) + assert status == True + # a port based router interface has five field/value tuples + if len(fvs) == 5: + for fv in fvs: + if fv[0] == "SAI_ROUTER_INTERFACE_ATTR_TYPE": + assert fv[1] == "SAI_ROUTER_INTERFACE_TYPE_PORT" + # the default MTU without any configuration is 9100 + if fv[0] == "SAI_ROUTER_INTERFACE_ATTR_MTU": + assert fv[1] == "9100" + + # set MAC to interface + self.set_mac("PortChannel001", "6C:EC:5A:11:22:33", "30.0.0.4/31") + + # check application database + tbl = swsscommon.Table(self.pdb, "INTF_TABLE:PortChannel001") + (status, fvs) = tbl.get(tbl.getKeys()[0]) + assert status == True + assert len(fvs) == 3 + for fv in fvs: + if fv[0] == "scope": + assert fv[1] == "global" + elif fv[0] == "family": + assert fv[1] == "IPv4" + elif fv[0] == "mac_addr": + assert fv[1] == "6c:ec:5a:11:22:33" + else: + assert False + + # check ASIC router interface database + tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE") + intf_entries = tbl.getKeys() + # one loopback router interface one port based router interface + #assert len(intf_entries) == 2 + + for key in intf_entries: + (status, fvs) = tbl.get(key) + assert status == True + # a port based router interface has five field/value tuples + if len(fvs) == 5: + for fv in fvs: + # check the MAC + if fv[0] == "SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS": + assert fv[1] == "6C:EC:5A:11:22:33" + + # remove IP from interface + self.remove_ip_address("PortChannel001", "30.0.0.4/31") + + # check application database + tbl = swsscommon.Table(self.pdb, "INTF_TABLE:PortChannel001") + intf_entries = tbl.getKeys() + assert len(intf_entries) == 0 + + # remove port channel + self.remove_port_channel(dvs, "PortChannel001") + From 2da2d4a62d18cd7e2de5efeadbb9d7e2af3a4cd4 Mon Sep 17 00:00:00 2001 From: "leo.li" Date: Wed, 12 Jun 2019 04:37:26 -0700 Subject: [PATCH 03/17] [vstest] update the corresponding vstest for pr#814 Signed-off-by: leo.li --- tests/test_intf_mac.py | 240 +++++++++++++++++++++-------------------- 1 file changed, 125 insertions(+), 115 deletions(-) diff --git a/tests/test_intf_mac.py b/tests/test_intf_mac.py index 95d367a067..2c2b4b4805 100644 --- a/tests/test_intf_mac.py +++ b/tests/test_intf_mac.py @@ -5,9 +5,10 @@ class TestRouterInterfaceMac(object): def setup_db(self, dvs): - self.pdb = swsscommon.DBConnector(0, dvs.redis_sock, 0) - self.adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) - self.cdb = swsscommon.DBConnector(4, dvs.redis_sock, 0) + self.pdb = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + self.adb = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + self.cdb = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + self.cntdb = swsscommon.DBConnector(swsscommon.COUNTERS_DB, dvs.redis_sock, 0) def add_ip_address(self, interface, ip): tbl = swsscommon.Table(self.cdb, "INTERFACE") @@ -25,87 +26,87 @@ def set_mac(self, interface, mac, ip): fvs = swsscommon.FieldValuePairs([("mac_addr", mac)]) tbl.set(interface + "|" + ip, fvs) time.sleep(2) - + + def get_port_oid(self, interface): + tbl = swsscommon.Table(self.cntdb, "COUNTERS_PORT_NAME_MAP") + fvs = tbl.get('')[1] + for fv in fvs: + if fv[0] == interface: + return fv[1] + return None + + def find_mac(self, interface, mac): + port_oid = self.get_port_oid(interface) + assert port_oid is not None + + tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE") + intf_entries = tbl.getKeys() + for key in intf_entries: + (status, fvs) = tbl.get(key) + assert status == True + values = dict(fvs) + if "SAI_ROUTER_INTERFACE_TYPE_PORT" != values["SAI_ROUTER_INTERFACE_ATTR_TYPE"]: + continue + if port_oid == values["SAI_ROUTER_INTERFACE_ATTR_PORT_ID"] and mac == values["SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS"]: + return True + return False + def test_InterfaceSetMac(self, dvs, testlog): self.setup_db(dvs) # assign IP to interface self.add_ip_address("Ethernet8", "10.0.0.4/31") + # set MAC to interface + self.set_mac("Ethernet8", "6C:EC:5A:11:22:33", "10.0.0.4/31") + # check application database tbl = swsscommon.Table(self.pdb, "INTF_TABLE:Ethernet8") - intf_entries = tbl.getKeys() - assert len(intf_entries) == 1 - assert intf_entries[0] == "10.0.0.4/31" - (status, fvs) = tbl.get(tbl.getKeys()[0]) assert status == True - assert len(fvs) == 2 - for fv in fvs: - if fv[0] == "scope": - assert fv[1] == "global" - elif fv[0] == "family": - assert fv[1] == "IPv4" - else: - assert False + values = dict(fvs) + assert values["mac_addr"] == "6c:ec:5a:11:22:33" # check ASIC router interface database - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE") + src_mac_addr_found = self.find_mac("Ethernet8", "6C:EC:5A:11:22:33") + assert src_mac_addr_found == True + + # remove IP from interface + self.remove_ip_address("Ethernet8", "10.0.0.4/31") + + # check application database + tbl = swsscommon.Table(self.pdb, "INTF_TABLE:Ethernet8") intf_entries = tbl.getKeys() - # one loopback router interface one port based router interface - #assert len(intf_entries) == 2 + assert len(intf_entries) == 0 - for key in intf_entries: - (status, fvs) = tbl.get(key) - assert status == True - # a port based router interface has five field/value tuples - if len(fvs) == 5: - for fv in fvs: - if fv[0] == "SAI_ROUTER_INTERFACE_ATTR_TYPE": - assert fv[1] == "SAI_ROUTER_INTERFACE_TYPE_PORT" - # the default MTU without any configuration is 9100 - if fv[0] == "SAI_ROUTER_INTERFACE_ATTR_MTU": - assert fv[1] == "9100" + def test_InterfaceChangeMac(self, dvs, testlog): + self.setup_db(dvs) + + # assign IP to interface + self.add_ip_address("Ethernet12", "12.0.0.4/31") # set MAC to interface - self.set_mac("Ethernet8", "6C:EC:5A:11:22:33", "10.0.0.4/31") + self.set_mac("Ethernet12", "6C:EC:5A:22:33:44", "12.0.0.4/31") + + # change interface MAC + self.set_mac("Ethernet12", "6C:EC:5A:33:44:55", "12.0.0.4/31") # check application database - tbl = swsscommon.Table(self.pdb, "INTF_TABLE:Ethernet8") + tbl = swsscommon.Table(self.pdb, "INTF_TABLE:Ethernet12") (status, fvs) = tbl.get(tbl.getKeys()[0]) assert status == True - assert len(fvs) == 3 - for fv in fvs: - if fv[0] == "scope": - assert fv[1] == "global" - elif fv[0] == "family": - assert fv[1] == "IPv4" - elif fv[0] == "mac_addr": - assert fv[1] == "6c:ec:5a:11:22:33" - else: - assert False + values = dict(fvs) + assert values["mac_addr"] == "6c:ec:5a:33:44:55" # check ASIC router interface database - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE") - intf_entries = tbl.getKeys() - # one loopback router interface one port based router interface - #assert len(intf_entries) == 2 + src_mac_addr_found = self.find_mac("Ethernet12", "6C:EC:5A:33:44:55") + assert src_mac_addr_found == True - for key in intf_entries: - (status, fvs) = tbl.get(key) - assert status == True - # a port based router interface has five field/value tuples - if len(fvs) == 5: - for fv in fvs: - # check the MAC - if fv[0] == "SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS": - assert fv[1] == "6C:EC:5A:11:22:33" - # remove IP from interface - self.remove_ip_address("Ethernet8", "10.0.0.4/31") + self.remove_ip_address("Ethernet12", "12.0.0.4/31") # check application database - tbl = swsscommon.Table(self.pdb, "INTF_TABLE:Ethernet8") + tbl = swsscommon.Table(self.pdb, "INTF_TABLE:Ethernet12") intf_entries = tbl.getKeys() assert len(intf_entries) == 0 @@ -156,7 +157,21 @@ def set_mac(self, interface, mac, ip): fvs = swsscommon.FieldValuePairs([("mac_addr", mac)]) tbl.set(interface + "|" + ip, fvs) time.sleep(2) - + + def find_mac(self, lag_oid, mac): + tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE") + intf_entries = tbl.getKeys() + + for key in intf_entries: + (status, fvs) = tbl.get(key) + assert status == True + values = dict(fvs) + if "SAI_ROUTER_INTERFACE_TYPE_PORT" != values["SAI_ROUTER_INTERFACE_ATTR_TYPE"]: + continue + if lag_oid == values["SAI_ROUTER_INTERFACE_ATTR_PORT_ID"] and mac == values["SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS"]: + return True + return False + def test_InterfaceSetMac(self, dvs, testlog): self.setup_db(dvs) @@ -166,83 +181,78 @@ def test_InterfaceSetMac(self, dvs, testlog): # assign IP to interface self.add_ip_address("PortChannel001", "30.0.0.4/31") + # set MAC to interface + self.set_mac("PortChannel001", "6C:EC:5A:11:22:33", "30.0.0.4/31") + # check application database tbl = swsscommon.Table(self.pdb, "INTF_TABLE:PortChannel001") - intf_entries = tbl.getKeys() - assert len(intf_entries) == 1 - assert intf_entries[0] == "30.0.0.4/31" - (status, fvs) = tbl.get(tbl.getKeys()[0]) assert status == True - assert len(fvs) == 2 - for fv in fvs: - if fv[0] == "scope": - assert fv[1] == "global" - elif fv[0] == "family": - assert fv[1] == "IPv4" - else: - assert False + values = dict(fvs) + assert values["mac_addr"] == "6c:ec:5a:11:22:33" + + # get PortChannel oid; When sonic-swss pr885 is complete, you can get oid directly from COUNTERS_LAG_NAME_MAP, which would be better. + lag_tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_LAG") + lag_entries = lag_tbl.getKeys() + # At this point there should be only one lag in the system, which is PortChannel001. + assert len(lag_entries) == 1 + lag_oid = lag_entries[0] # check ASIC router interface database - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE") + src_mac_addr_found = self.find_mac(lag_oid, "6C:EC:5A:11:22:33") + assert src_mac_addr_found == True + + # remove IP from interface + self.remove_ip_address("PortChannel001", "30.0.0.4/31") + + # check application database + tbl = swsscommon.Table(self.pdb, "INTF_TABLE:PortChannel001") intf_entries = tbl.getKeys() - # one loopback router interface one port based router interface - #assert len(intf_entries) == 2 + assert len(intf_entries) == 0 - for key in intf_entries: - (status, fvs) = tbl.get(key) - assert status == True - # a port based router interface has five field/value tuples - if len(fvs) == 5: - for fv in fvs: - if fv[0] == "SAI_ROUTER_INTERFACE_ATTR_TYPE": - assert fv[1] == "SAI_ROUTER_INTERFACE_TYPE_PORT" - # the default MTU without any configuration is 9100 - if fv[0] == "SAI_ROUTER_INTERFACE_ATTR_MTU": - assert fv[1] == "9100" + # remove port channel + self.remove_port_channel(dvs, "PortChannel001") + + def test_InterfaceChangeMac(self, dvs, testlog): + self.setup_db(dvs) + + # create port channel + self.create_port_channel(dvs, "PortChannel002") + + # assign IP to interface + self.add_ip_address("PortChannel002", "32.0.0.4/31") # set MAC to interface - self.set_mac("PortChannel001", "6C:EC:5A:11:22:33", "30.0.0.4/31") + self.set_mac("PortChannel002", "6C:EC:5A:22:33:44", "32.0.0.4/31") + + # change interface MAC + self.set_mac("PortChannel002", "6C:EC:5A:33:44:55", "32.0.0.4/31") # check application database - tbl = swsscommon.Table(self.pdb, "INTF_TABLE:PortChannel001") + tbl = swsscommon.Table(self.pdb, "INTF_TABLE:PortChannel002") (status, fvs) = tbl.get(tbl.getKeys()[0]) assert status == True - assert len(fvs) == 3 - for fv in fvs: - if fv[0] == "scope": - assert fv[1] == "global" - elif fv[0] == "family": - assert fv[1] == "IPv4" - elif fv[0] == "mac_addr": - assert fv[1] == "6c:ec:5a:11:22:33" - else: - assert False + values = dict(fvs) + assert values["mac_addr"] == "6c:ec:5a:33:44:55" + + # get PortChannel oid; When sonic-swss pr885 is complete, you can get oid directly from COUNTERS_LAG_NAME_MAP, which would be better. + lag_tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_LAG") + lag_entries = lag_tbl.getKeys() + # At this point there should be only one lag in the system, which is PortChannel002. + assert len(lag_entries) == 1 + lag_oid = lag_entries[0] # check ASIC router interface database - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE") - intf_entries = tbl.getKeys() - # one loopback router interface one port based router interface - #assert len(intf_entries) == 2 + src_mac_addr_found = self.find_mac(lag_oid, "6C:EC:5A:33:44:55") + assert src_mac_addr_found == True - for key in intf_entries: - (status, fvs) = tbl.get(key) - assert status == True - # a port based router interface has five field/value tuples - if len(fvs) == 5: - for fv in fvs: - # check the MAC - if fv[0] == "SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS": - assert fv[1] == "6C:EC:5A:11:22:33" - # remove IP from interface - self.remove_ip_address("PortChannel001", "30.0.0.4/31") + self.remove_ip_address("PortChannel002", "32.0.0.4/31") # check application database - tbl = swsscommon.Table(self.pdb, "INTF_TABLE:PortChannel001") + tbl = swsscommon.Table(self.pdb, "INTF_TABLE:PortChannel002") intf_entries = tbl.getKeys() assert len(intf_entries) == 0 # remove port channel - self.remove_port_channel(dvs, "PortChannel001") - + self.remove_port_channel(dvs, "PortChannel002") \ No newline at end of file From 115f9aa8f8fde53954350035be674350d6f64949 Mon Sep 17 00:00:00 2001 From: "shine.chen" Date: Mon, 17 Jun 2019 19:51:28 -0700 Subject: [PATCH 04/17] refine code according to prsunny/stcheng review Signed-off-by: shine.chen --- cfgmgr/intfmgr.cpp | 31 +++++++++++++++++++++++++++++++ orchagent/intfsorch.cpp | 7 +------ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/cfgmgr/intfmgr.cpp b/cfgmgr/intfmgr.cpp index 8993c7684e..28998e2d80 100644 --- a/cfgmgr/intfmgr.cpp +++ b/cfgmgr/intfmgr.cpp @@ -184,6 +184,28 @@ bool IntfMgr::doIntfAddrTask(const vector& keys, bool is_lo = !alias.compare(0, strlen(LOOPBACK_PREFIX), LOOPBACK_PREFIX); string appKey = (is_lo ? "lo" : keys[0]) + ":" + keys[1]; + MacAddress mac; + bool invalid_mac = false; + + for (auto idx : data) + { + const auto &field = fvField(idx); + const auto &value = fvValue(idx); + if (field == "mac_addr") + { + try + { + mac = MacAddress(value); + } + catch (const std::invalid_argument& e) + { + SWSS_LOG_ERROR("Invalid Mac addr '%s' for '%s'", value.c_str(), alias.c_str()); + invalid_mac = true; + break; + } + } + } + if (op == SET_COMMAND) { /* @@ -207,6 +229,15 @@ bool IntfMgr::doIntfAddrTask(const vector& keys, FieldValueTuple s("scope", "global"); fvVector.push_back(s); fvVector.push_back(f); + /*Set the mac of interface*/ + if(mac) + { + if (invalid_mac == false) + { + FieldValueTuple mac_attr("mac_addr",mac.to_string().c_str()); + fvVector.push_back(mac_attr); + } + } m_appIntfTableProducer.set(appKey, fvVector); m_stateIntfTable.hset(keys[0] + state_db_key_delimiter + keys[1], "state", "ok"); diff --git a/orchagent/intfsorch.cpp b/orchagent/intfsorch.cpp index bff3423098..61869d736c 100644 --- a/orchagent/intfsorch.cpp +++ b/orchagent/intfsorch.cpp @@ -182,9 +182,6 @@ void IntfsOrch::doTask(Consumer &consumer) { KeyOpFieldsValuesTuple t = it->second; MacAddress mac; - int mac_attr_set; - - mac_attr_set = 0; vector keys = tokenize(kfvKey(t), ':'); string alias(keys[0]); @@ -214,8 +211,6 @@ void IntfsOrch::doTask(Consumer &consumer) } else if (field == "mac_addr") { - mac_attr_set = 1; - mac = MacAddress(value); } } @@ -309,7 +304,7 @@ void IntfsOrch::doTask(Consumer &consumer) } } - if (mac_attr_set == 1) + if (mac) { auto it_intfs = m_syncdIntfses.find(alias); if (it_intfs != m_syncdIntfses.end()) From 065c10fd0fe8591e4923eb7cb57f38c6be044afd Mon Sep 17 00:00:00 2001 From: "shine.chen" Date: Mon, 8 Jul 2019 01:06:03 -0700 Subject: [PATCH 05/17] fix bool value condition judgement Signed-off-by: shine.chen --- cfgmgr/intfmgr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cfgmgr/intfmgr.cpp b/cfgmgr/intfmgr.cpp index 28998e2d80..623319824e 100644 --- a/cfgmgr/intfmgr.cpp +++ b/cfgmgr/intfmgr.cpp @@ -232,7 +232,7 @@ bool IntfMgr::doIntfAddrTask(const vector& keys, /*Set the mac of interface*/ if(mac) { - if (invalid_mac == false) + if (!invalid_mac) { FieldValueTuple mac_attr("mac_addr",mac.to_string().c_str()); fvVector.push_back(mac_attr); From dfcae9b5c1fb149ef160bbd8b145127910c0ffe7 Mon Sep 17 00:00:00 2001 From: "leo.li" Date: Mon, 8 Jul 2019 19:42:46 -0700 Subject: [PATCH 06/17] [vstest] update the corresponding vstest for pr#814 Signed-off-by: leo.li --- tests/test_intf_mac.py | 134 ++++++++++++++--------------------------- 1 file changed, 46 insertions(+), 88 deletions(-) diff --git a/tests/test_intf_mac.py b/tests/test_intf_mac.py index 2c2b4b4805..d1706fbf80 100644 --- a/tests/test_intf_mac.py +++ b/tests/test_intf_mac.py @@ -4,42 +4,16 @@ import json class TestRouterInterfaceMac(object): - def setup_db(self, dvs): - self.pdb = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) - self.adb = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) - self.cdb = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - self.cntdb = swsscommon.DBConnector(swsscommon.COUNTERS_DB, dvs.redis_sock, 0) - - def add_ip_address(self, interface, ip): - tbl = swsscommon.Table(self.cdb, "INTERFACE") - fvs = swsscommon.FieldValuePairs([("NULL", "NULL")]) - tbl.set(interface + "|" + ip, fvs) - time.sleep(2) # IPv6 netlink message needs longer time - - def remove_ip_address(self, interface, ip): - tbl = swsscommon.Table(self.cdb, "INTERFACE") - tbl._del(interface + "|" + ip); - time.sleep(1) - - def set_mac(self, interface, mac, ip): - tbl = swsscommon.Table(self.cdb, "INTERFACE") + def set_mac(self, dvs, interface, mac, ip): + tbl = swsscommon.Table(dvs.cdb, "INTERFACE") fvs = swsscommon.FieldValuePairs([("mac_addr", mac)]) tbl.set(interface + "|" + ip, fvs) time.sleep(2) - def get_port_oid(self, interface): - tbl = swsscommon.Table(self.cntdb, "COUNTERS_PORT_NAME_MAP") - fvs = tbl.get('')[1] - for fv in fvs: - if fv[0] == interface: - return fv[1] - return None - - def find_mac(self, interface, mac): - port_oid = self.get_port_oid(interface) - assert port_oid is not None + def find_mac(self, dvs, interface, mac): + port_oid = dvs.asicdb.portnamemap[interface] - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE") + tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE") intf_entries = tbl.getKeys() for key in intf_entries: (status, fvs) = tbl.get(key) @@ -52,114 +26,98 @@ def find_mac(self, interface, mac): return False def test_InterfaceSetMac(self, dvs, testlog): - self.setup_db(dvs) + dvs.setup_db() # assign IP to interface - self.add_ip_address("Ethernet8", "10.0.0.4/31") + dvs.add_ip_address("Ethernet8", "10.0.0.4/31") # set MAC to interface - self.set_mac("Ethernet8", "6C:EC:5A:11:22:33", "10.0.0.4/31") + self.set_mac(dvs, "Ethernet8", "6C:EC:5A:11:22:33", "10.0.0.4/31") # check application database - tbl = swsscommon.Table(self.pdb, "INTF_TABLE:Ethernet8") + tbl = swsscommon.Table(dvs.pdb, "INTF_TABLE:Ethernet8") (status, fvs) = tbl.get(tbl.getKeys()[0]) assert status == True values = dict(fvs) assert values["mac_addr"] == "6c:ec:5a:11:22:33" # check ASIC router interface database - src_mac_addr_found = self.find_mac("Ethernet8", "6C:EC:5A:11:22:33") + src_mac_addr_found = self.find_mac(dvs, "Ethernet8", "6C:EC:5A:11:22:33") assert src_mac_addr_found == True # remove IP from interface - self.remove_ip_address("Ethernet8", "10.0.0.4/31") + dvs.remove_ip_address("Ethernet8", "10.0.0.4/31") # check application database - tbl = swsscommon.Table(self.pdb, "INTF_TABLE:Ethernet8") + tbl = swsscommon.Table(dvs.pdb, "INTF_TABLE:Ethernet8") intf_entries = tbl.getKeys() assert len(intf_entries) == 0 def test_InterfaceChangeMac(self, dvs, testlog): - self.setup_db(dvs) + dvs.setup_db() # assign IP to interface - self.add_ip_address("Ethernet12", "12.0.0.4/31") + dvs.add_ip_address("Ethernet12", "12.0.0.4/31") # set MAC to interface - self.set_mac("Ethernet12", "6C:EC:5A:22:33:44", "12.0.0.4/31") + self.set_mac(dvs, "Ethernet12", "6C:EC:5A:22:33:44", "12.0.0.4/31") # change interface MAC - self.set_mac("Ethernet12", "6C:EC:5A:33:44:55", "12.0.0.4/31") + self.set_mac(dvs, "Ethernet12", "6C:EC:5A:33:44:55", "12.0.0.4/31") # check application database - tbl = swsscommon.Table(self.pdb, "INTF_TABLE:Ethernet12") + tbl = swsscommon.Table(dvs.pdb, "INTF_TABLE:Ethernet12") (status, fvs) = tbl.get(tbl.getKeys()[0]) assert status == True values = dict(fvs) assert values["mac_addr"] == "6c:ec:5a:33:44:55" # check ASIC router interface database - src_mac_addr_found = self.find_mac("Ethernet12", "6C:EC:5A:33:44:55") + src_mac_addr_found = self.find_mac(dvs, "Ethernet12", "6C:EC:5A:33:44:55") assert src_mac_addr_found == True # remove IP from interface - self.remove_ip_address("Ethernet12", "12.0.0.4/31") + dvs.remove_ip_address("Ethernet12", "12.0.0.4/31") # check application database - tbl = swsscommon.Table(self.pdb, "INTF_TABLE:Ethernet12") + tbl = swsscommon.Table(dvs.pdb, "INTF_TABLE:Ethernet12") intf_entries = tbl.getKeys() assert len(intf_entries) == 0 class TestLagRouterInterfaceMac(object): - def setup_db(self, dvs): - self.pdb = swsscommon.DBConnector(0, dvs.redis_sock, 0) - self.adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) - self.cdb = swsscommon.DBConnector(4, dvs.redis_sock, 0) - def create_port_channel(self, dvs, alias): - tbl = swsscommon.Table(self.cdb, "PORTCHANNEL") + tbl = swsscommon.Table(dvs.cdb, "PORTCHANNEL") fvs = swsscommon.FieldValuePairs([("admin_status", "up"), ("mtu", "9100")]) tbl.set(alias, fvs) time.sleep(1) def remove_port_channel(self, dvs, alias): - tbl = swsscommon.Table(self.cdb, "PORTCHANNEL") + tbl = swsscommon.Table(dvs.cdb, "PORTCHANNEL") tbl._del(alias) time.sleep(1) def add_port_channel_members(self, dvs, lag, members): - tbl = swsscommon.Table(self.cdb, "PORTCHANNEL_MEMBER") + tbl = swsscommon.Table(dvs.cdb, "PORTCHANNEL_MEMBER") fvs = swsscommon.FieldValuePairs([("NULL", "NULL")]) for member in members: tbl.set(lag + "|" + member, fvs) time.sleep(1) def remove_port_channel_members(self, dvs, lag, members): - tbl = swsscommon.Table(self.cdb, "PORTCHANNEL_MEMBER") + tbl = swsscommon.Table(dvs.cdb, "PORTCHANNEL_MEMBER") for member in members: tbl._del(lag + "|" + member) time.sleep(1) - def add_ip_address(self, interface, ip): - tbl = swsscommon.Table(self.cdb, "PORTCHANNEL_INTERFACE") - fvs = swsscommon.FieldValuePairs([("NULL", "NULL")]) - tbl.set(interface + "|" + ip, fvs) - time.sleep(1) - - def remove_ip_address(self, interface, ip): - tbl = swsscommon.Table(self.cdb, "PORTCHANNEL_INTERFACE") - tbl._del(interface + "|" + ip); - time.sleep(1) - - def set_mac(self, interface, mac, ip): - tbl = swsscommon.Table(self.cdb, "PORTCHANNEL_INTERFACE") + def set_mac(self, dvs, interface, mac, ip): + tbl = swsscommon.Table(dvs.cdb, "PORTCHANNEL_INTERFACE") fvs = swsscommon.FieldValuePairs([("mac_addr", mac)]) tbl.set(interface + "|" + ip, fvs) time.sleep(2) - def find_mac(self, lag_oid, mac): - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE") + def find_mac(self, dvs, lag_oid, mac): + tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE") intf_entries = tbl.getKeys() for key in intf_entries: @@ -173,40 +131,40 @@ def find_mac(self, lag_oid, mac): return False def test_InterfaceSetMac(self, dvs, testlog): - self.setup_db(dvs) + dvs.setup_db() # create port channel self.create_port_channel(dvs, "PortChannel001") # assign IP to interface - self.add_ip_address("PortChannel001", "30.0.0.4/31") + dvs.add_ip_address("PortChannel001", "30.0.0.4/31") # set MAC to interface - self.set_mac("PortChannel001", "6C:EC:5A:11:22:33", "30.0.0.4/31") + self.set_mac(dvs, "PortChannel001", "6C:EC:5A:11:22:33", "30.0.0.4/31") # check application database - tbl = swsscommon.Table(self.pdb, "INTF_TABLE:PortChannel001") + tbl = swsscommon.Table(dvs.pdb, "INTF_TABLE:PortChannel001") (status, fvs) = tbl.get(tbl.getKeys()[0]) assert status == True values = dict(fvs) assert values["mac_addr"] == "6c:ec:5a:11:22:33" # get PortChannel oid; When sonic-swss pr885 is complete, you can get oid directly from COUNTERS_LAG_NAME_MAP, which would be better. - lag_tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_LAG") + lag_tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_LAG") lag_entries = lag_tbl.getKeys() # At this point there should be only one lag in the system, which is PortChannel001. assert len(lag_entries) == 1 lag_oid = lag_entries[0] # check ASIC router interface database - src_mac_addr_found = self.find_mac(lag_oid, "6C:EC:5A:11:22:33") + src_mac_addr_found = self.find_mac(dvs, lag_oid, "6C:EC:5A:11:22:33") assert src_mac_addr_found == True # remove IP from interface - self.remove_ip_address("PortChannel001", "30.0.0.4/31") + dvs.remove_ip_address("PortChannel001", "30.0.0.4/31") # check application database - tbl = swsscommon.Table(self.pdb, "INTF_TABLE:PortChannel001") + tbl = swsscommon.Table(dvs.pdb, "INTF_TABLE:PortChannel001") intf_entries = tbl.getKeys() assert len(intf_entries) == 0 @@ -214,45 +172,45 @@ def test_InterfaceSetMac(self, dvs, testlog): self.remove_port_channel(dvs, "PortChannel001") def test_InterfaceChangeMac(self, dvs, testlog): - self.setup_db(dvs) + dvs.setup_db() # create port channel self.create_port_channel(dvs, "PortChannel002") # assign IP to interface - self.add_ip_address("PortChannel002", "32.0.0.4/31") + dvs.add_ip_address("PortChannel002", "32.0.0.4/31") # set MAC to interface - self.set_mac("PortChannel002", "6C:EC:5A:22:33:44", "32.0.0.4/31") + self.set_mac(dvs, "PortChannel002", "6C:EC:5A:22:33:44", "32.0.0.4/31") # change interface MAC - self.set_mac("PortChannel002", "6C:EC:5A:33:44:55", "32.0.0.4/31") + self.set_mac(dvs, "PortChannel002", "6C:EC:5A:33:44:55", "32.0.0.4/31") # check application database - tbl = swsscommon.Table(self.pdb, "INTF_TABLE:PortChannel002") + tbl = swsscommon.Table(dvs.pdb, "INTF_TABLE:PortChannel002") (status, fvs) = tbl.get(tbl.getKeys()[0]) assert status == True values = dict(fvs) assert values["mac_addr"] == "6c:ec:5a:33:44:55" # get PortChannel oid; When sonic-swss pr885 is complete, you can get oid directly from COUNTERS_LAG_NAME_MAP, which would be better. - lag_tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_LAG") + lag_tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_LAG") lag_entries = lag_tbl.getKeys() # At this point there should be only one lag in the system, which is PortChannel002. assert len(lag_entries) == 1 lag_oid = lag_entries[0] # check ASIC router interface database - src_mac_addr_found = self.find_mac(lag_oid, "6C:EC:5A:33:44:55") + src_mac_addr_found = self.find_mac(dvs, lag_oid, "6C:EC:5A:33:44:55") assert src_mac_addr_found == True # remove IP from interface - self.remove_ip_address("PortChannel002", "32.0.0.4/31") + dvs.remove_ip_address("PortChannel002", "32.0.0.4/31") # check application database - tbl = swsscommon.Table(self.pdb, "INTF_TABLE:PortChannel002") + tbl = swsscommon.Table(dvs.pdb, "INTF_TABLE:PortChannel002") intf_entries = tbl.getKeys() assert len(intf_entries) == 0 # remove port channel - self.remove_port_channel(dvs, "PortChannel002") \ No newline at end of file + self.remove_port_channel(dvs, "PortChannel002") From 4b26a956165b824b8cfcb0fa25dcfdc28cd36cc7 Mon Sep 17 00:00:00 2001 From: "shine.chen" Date: Tue, 9 Jul 2019 23:52:50 -0700 Subject: [PATCH 07/17] move mac-address change code to intfGeneralTask Signed-off-by: shine.chen --- cfgmgr/intfmgr.cpp | 55 ++++++++++++++++++++-------------------------- cfgmgr/intfmgr.h | 1 + 2 files changed, 25 insertions(+), 31 deletions(-) diff --git a/cfgmgr/intfmgr.cpp b/cfgmgr/intfmgr.cpp index d61834a049..d5707dd8c3 100644 --- a/cfgmgr/intfmgr.cpp +++ b/cfgmgr/intfmgr.cpp @@ -50,6 +50,20 @@ void IntfMgr::setIntfIp(const string &alias, const string &opCmd, } } +void IntfMgr::setIntfMac(const string &alias, const string mac_str) +{ + stringstream cmd; + string res; + + cmd << IP_CMD << " link set " << alias << " address " << mac_str; + + int ret = swss::exec(cmd.str(), res); + if (ret) + { + SWSS_LOG_ERROR("Command '%s' failed with rc %d", cmd.str().c_str(), ret); + } +} + void IntfMgr::setIntfVrf(const string &alias, const string vrfName) { stringstream cmd; @@ -116,6 +130,7 @@ bool IntfMgr::doIntfGeneralTask(const vector& keys, string alias(keys[0]); string vrf_name = ""; bool is_lo = !alias.compare(0, strlen(LOOPBACK_PREFIX), LOOPBACK_PREFIX); + string mac = ""; for (auto idx : data) { @@ -125,6 +140,10 @@ bool IntfMgr::doIntfGeneralTask(const vector& keys, { vrf_name = value; } + else if (field == "mac_addr") + { + mac = value; + } } if (op == SET_COMMAND) @@ -148,6 +167,11 @@ bool IntfMgr::doIntfGeneralTask(const vector& keys, { setIntfVrf(alias, vrf_name); } + /*Set the mac of interface*/ + if(!mac.empty()) + { + setIntfMac(alias, mac); + } m_appIntfTableProducer.set(alias, data); } else @@ -187,28 +211,6 @@ bool IntfMgr::doIntfAddrTask(const vector& keys, bool is_lo = !alias.compare(0, strlen(LOOPBACK_PREFIX), LOOPBACK_PREFIX); string appKey = (is_lo ? "lo" : keys[0]) + ":" + keys[1]; - MacAddress mac; - bool invalid_mac = false; - - for (auto idx : data) - { - const auto &field = fvField(idx); - const auto &value = fvValue(idx); - if (field == "mac_addr") - { - try - { - mac = MacAddress(value); - } - catch (const std::invalid_argument& e) - { - SWSS_LOG_ERROR("Invalid Mac addr '%s' for '%s'", value.c_str(), alias.c_str()); - invalid_mac = true; - break; - } - } - } - if (op == SET_COMMAND) { /* @@ -232,15 +234,6 @@ bool IntfMgr::doIntfAddrTask(const vector& keys, FieldValueTuple s("scope", "global"); fvVector.push_back(s); fvVector.push_back(f); - /*Set the mac of interface*/ - if(mac) - { - if (!invalid_mac) - { - FieldValueTuple mac_attr("mac_addr",mac.to_string().c_str()); - fvVector.push_back(mac_attr); - } - } m_appIntfTableProducer.set(appKey, fvVector); m_stateIntfTable.hset(keys[0] + state_db_key_delimiter + keys[1], "state", "ok"); diff --git a/cfgmgr/intfmgr.h b/cfgmgr/intfmgr.h index d10b5d8b4c..d4dfafaa8f 100644 --- a/cfgmgr/intfmgr.h +++ b/cfgmgr/intfmgr.h @@ -22,6 +22,7 @@ class IntfMgr : public Orch Table m_statePortTable, m_stateLagTable, m_stateVlanTable, m_stateVrfTable, m_stateIntfTable; void setIntfIp(const string &alias, const string &opCmd, const string &ipPrefixStr, const bool ipv4 = true); + void setIntfMac(const string &alias, const string mac_str); void setIntfVrf(const string &alias, const string vrfName); bool doIntfGeneralTask(const vector& keys, const vector& data, const string& op); bool doIntfAddrTask(const vector& keys, const vector& data, const string& op); From d34689dc0f92dbd5c82626403c5ec4b82088469f Mon Sep 17 00:00:00 2001 From: "shine.chen" Date: Wed, 10 Jul 2019 00:54:17 -0700 Subject: [PATCH 08/17] remove unnecessary condition statement Signed-off-by: shine.chen --- orchagent/intfsorch.cpp | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/orchagent/intfsorch.cpp b/orchagent/intfsorch.cpp index bd518f4245..ce83a1a521 100644 --- a/orchagent/intfsorch.cpp +++ b/orchagent/intfsorch.cpp @@ -404,26 +404,21 @@ void IntfsOrch::doTask(Consumer &consumer) if (mac) { - auto it_intfs = m_syncdIntfses.find(alias); - if (it_intfs != m_syncdIntfses.end()) - { /* Get mac information and update mac of the interface*/ - sai_attribute_t attr; - - attr.id = SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS; - memcpy(attr.value.mac, mac.getMac(), sizeof(sai_mac_t)); + sai_attribute_t attr; + attr.id = SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS; + memcpy(attr.value.mac, mac.getMac(), sizeof(sai_mac_t)); - sai_status_t status = sai_router_intfs_api->set_router_interface_attribute(port.m_rif_id, &attr); - if (status != SAI_STATUS_SUCCESS) - { - SWSS_LOG_ERROR("Failed to set router interface mac %s for port %s, rv:%d", - mac.to_string().c_str(), port.m_alias.c_str(), status); - } - else - { - SWSS_LOG_NOTICE("Set router interface mac %s for port %s success", - mac.to_string().c_str(), port.m_alias.c_str()); - } + sai_status_t status = sai_router_intfs_api->set_router_interface_attribute(port.m_rif_id, &attr); + if (status != SAI_STATUS_SUCCESS) + { + SWSS_LOG_ERROR("Failed to set router interface mac %s for port %s, rv:%d", + mac.to_string().c_str(), port.m_alias.c_str(), status); + } + else + { + SWSS_LOG_NOTICE("Set router interface mac %s for port %s success", + mac.to_string().c_str(), port.m_alias.c_str()); } } From 53063a014561d776172ac2997302e50d0d065bcd Mon Sep 17 00:00:00 2001 From: "leo.li" Date: Wed, 10 Jul 2019 03:37:26 -0700 Subject: [PATCH 09/17] [vstest] update the corresponding vstest for pr#814 Signed-off-by: leo.li --- tests/test_intf_mac.py | 82 +++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 40 deletions(-) diff --git a/tests/test_intf_mac.py b/tests/test_intf_mac.py index d1706fbf80..5ed381d693 100644 --- a/tests/test_intf_mac.py +++ b/tests/test_intf_mac.py @@ -4,11 +4,16 @@ import json class TestRouterInterfaceMac(object): - def set_mac(self, dvs, interface, mac, ip): + def set_mac(self, dvs, interface, mac): tbl = swsscommon.Table(dvs.cdb, "INTERFACE") fvs = swsscommon.FieldValuePairs([("mac_addr", mac)]) - tbl.set(interface + "|" + ip, fvs) - time.sleep(2) + tbl.set(interface, fvs) + time.sleep(1) + + def remove_mac(self, dvs, interface): + tbl = swsscommon.Table(dvs.cdb, "INTERFACE") + tbl.hdel(interface, "mac_addr") + time.sleep(1) def find_mac(self, dvs, interface, mac): port_oid = dvs.asicdb.portnamemap[interface] @@ -32,14 +37,14 @@ def test_InterfaceSetMac(self, dvs, testlog): dvs.add_ip_address("Ethernet8", "10.0.0.4/31") # set MAC to interface - self.set_mac(dvs, "Ethernet8", "6C:EC:5A:11:22:33", "10.0.0.4/31") + self.set_mac(dvs, "Ethernet8", "6C:EC:5A:11:22:33") # check application database - tbl = swsscommon.Table(dvs.pdb, "INTF_TABLE:Ethernet8") - (status, fvs) = tbl.get(tbl.getKeys()[0]) + tbl = swsscommon.Table(dvs.pdb, "INTF_TABLE") + (status, fvs) = tbl.get("Ethernet8") assert status == True values = dict(fvs) - assert values["mac_addr"] == "6c:ec:5a:11:22:33" + assert values["mac_addr"] == "6C:EC:5A:11:22:33" # check ASIC router interface database src_mac_addr_found = self.find_mac(dvs, "Ethernet8", "6C:EC:5A:11:22:33") @@ -48,10 +53,8 @@ def test_InterfaceSetMac(self, dvs, testlog): # remove IP from interface dvs.remove_ip_address("Ethernet8", "10.0.0.4/31") - # check application database - tbl = swsscommon.Table(dvs.pdb, "INTF_TABLE:Ethernet8") - intf_entries = tbl.getKeys() - assert len(intf_entries) == 0 + # remove MAC from interface + self.remove_mac(dvs, "Ethernet8") def test_InterfaceChangeMac(self, dvs, testlog): dvs.setup_db() @@ -60,17 +63,17 @@ def test_InterfaceChangeMac(self, dvs, testlog): dvs.add_ip_address("Ethernet12", "12.0.0.4/31") # set MAC to interface - self.set_mac(dvs, "Ethernet12", "6C:EC:5A:22:33:44", "12.0.0.4/31") + self.set_mac(dvs, "Ethernet12", "6C:EC:5A:22:33:44") # change interface MAC - self.set_mac(dvs, "Ethernet12", "6C:EC:5A:33:44:55", "12.0.0.4/31") + self.set_mac(dvs, "Ethernet12", "6C:EC:5A:33:44:55") # check application database - tbl = swsscommon.Table(dvs.pdb, "INTF_TABLE:Ethernet12") - (status, fvs) = tbl.get(tbl.getKeys()[0]) + tbl = swsscommon.Table(dvs.pdb, "INTF_TABLE") + (status, fvs) = tbl.get("Ethernet12") assert status == True values = dict(fvs) - assert values["mac_addr"] == "6c:ec:5a:33:44:55" + assert values["mac_addr"] == "6C:EC:5A:33:44:55" # check ASIC router interface database src_mac_addr_found = self.find_mac(dvs, "Ethernet12", "6C:EC:5A:33:44:55") @@ -79,10 +82,8 @@ def test_InterfaceChangeMac(self, dvs, testlog): # remove IP from interface dvs.remove_ip_address("Ethernet12", "12.0.0.4/31") - # check application database - tbl = swsscommon.Table(dvs.pdb, "INTF_TABLE:Ethernet12") - intf_entries = tbl.getKeys() - assert len(intf_entries) == 0 + # remove MAC from interface + self.remove_mac(dvs, "Ethernet12") class TestLagRouterInterfaceMac(object): def create_port_channel(self, dvs, alias): @@ -110,11 +111,16 @@ def remove_port_channel_members(self, dvs, lag, members): tbl._del(lag + "|" + member) time.sleep(1) - def set_mac(self, dvs, interface, mac, ip): + def set_mac(self, dvs, interface, mac): tbl = swsscommon.Table(dvs.cdb, "PORTCHANNEL_INTERFACE") fvs = swsscommon.FieldValuePairs([("mac_addr", mac)]) - tbl.set(interface + "|" + ip, fvs) - time.sleep(2) + tbl.set(interface, fvs) + time.sleep(1) + + def remove_mac(self, dvs, interface): + tbl = swsscommon.Table(dvs.cdb, "PORTCHANNEL_INTERFACE") + tbl.hdel(interface, "mac_addr") + time.sleep(1) def find_mac(self, dvs, lag_oid, mac): tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE") @@ -140,14 +146,14 @@ def test_InterfaceSetMac(self, dvs, testlog): dvs.add_ip_address("PortChannel001", "30.0.0.4/31") # set MAC to interface - self.set_mac(dvs, "PortChannel001", "6C:EC:5A:11:22:33", "30.0.0.4/31") + self.set_mac(dvs, "PortChannel001", "6C:EC:5A:11:22:33") # check application database - tbl = swsscommon.Table(dvs.pdb, "INTF_TABLE:PortChannel001") - (status, fvs) = tbl.get(tbl.getKeys()[0]) + tbl = swsscommon.Table(dvs.pdb, "INTF_TABLE") + (status, fvs) = tbl.get("PortChannel001") assert status == True values = dict(fvs) - assert values["mac_addr"] == "6c:ec:5a:11:22:33" + assert values["mac_addr"] == "6C:EC:5A:11:22:33" # get PortChannel oid; When sonic-swss pr885 is complete, you can get oid directly from COUNTERS_LAG_NAME_MAP, which would be better. lag_tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_LAG") @@ -163,10 +169,8 @@ def test_InterfaceSetMac(self, dvs, testlog): # remove IP from interface dvs.remove_ip_address("PortChannel001", "30.0.0.4/31") - # check application database - tbl = swsscommon.Table(dvs.pdb, "INTF_TABLE:PortChannel001") - intf_entries = tbl.getKeys() - assert len(intf_entries) == 0 + # remove MAC from interface + self.remove_mac(dvs, "PortChannel001") # remove port channel self.remove_port_channel(dvs, "PortChannel001") @@ -181,17 +185,17 @@ def test_InterfaceChangeMac(self, dvs, testlog): dvs.add_ip_address("PortChannel002", "32.0.0.4/31") # set MAC to interface - self.set_mac(dvs, "PortChannel002", "6C:EC:5A:22:33:44", "32.0.0.4/31") + self.set_mac(dvs, "PortChannel002", "6C:EC:5A:22:33:44") # change interface MAC - self.set_mac(dvs, "PortChannel002", "6C:EC:5A:33:44:55", "32.0.0.4/31") + self.set_mac(dvs, "PortChannel002", "6C:EC:5A:33:44:55") # check application database - tbl = swsscommon.Table(dvs.pdb, "INTF_TABLE:PortChannel002") - (status, fvs) = tbl.get(tbl.getKeys()[0]) + tbl = swsscommon.Table(dvs.pdb, "INTF_TABLE") + (status, fvs) = tbl.get("PortChannel002") assert status == True values = dict(fvs) - assert values["mac_addr"] == "6c:ec:5a:33:44:55" + assert values["mac_addr"] == "6C:EC:5A:33:44:55" # get PortChannel oid; When sonic-swss pr885 is complete, you can get oid directly from COUNTERS_LAG_NAME_MAP, which would be better. lag_tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_LAG") @@ -207,10 +211,8 @@ def test_InterfaceChangeMac(self, dvs, testlog): # remove IP from interface dvs.remove_ip_address("PortChannel002", "32.0.0.4/31") - # check application database - tbl = swsscommon.Table(dvs.pdb, "INTF_TABLE:PortChannel002") - intf_entries = tbl.getKeys() - assert len(intf_entries) == 0 + # remove MAC from interface + self.remove_mac(dvs, "PortChannel002") # remove port channel self.remove_port_channel(dvs, "PortChannel002") From 39a5b31c4d6d40aa7d218bfc9f41954bd696f102 Mon Sep 17 00:00:00 2001 From: shine4chen <37530989+shine4chen@users.noreply.github.com> Date: Thu, 11 Jul 2019 14:32:02 +0800 Subject: [PATCH 10/17] minor format adjustment in intfmgr.cpp --- cfgmgr/intfmgr.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cfgmgr/intfmgr.cpp b/cfgmgr/intfmgr.cpp index d5707dd8c3..7a5e7d7525 100644 --- a/cfgmgr/intfmgr.cpp +++ b/cfgmgr/intfmgr.cpp @@ -140,7 +140,7 @@ bool IntfMgr::doIntfGeneralTask(const vector& keys, { vrf_name = value; } - else if (field == "mac_addr") + else if (field == "mac_addr") { mac = value; } @@ -168,7 +168,7 @@ bool IntfMgr::doIntfGeneralTask(const vector& keys, setIntfVrf(alias, vrf_name); } /*Set the mac of interface*/ - if(!mac.empty()) + if (!mac.empty()) { setIntfMac(alias, mac); } From b80f60c16f744b5f9f043e5a190535d6964960d2 Mon Sep 17 00:00:00 2001 From: "leo.li" Date: Wed, 14 Aug 2019 21:43:39 -0700 Subject: [PATCH 11/17] [vstest] update the corresponding vstest for pr#814 Signed-off-by: leo.li --- tests/test_intf_mac.py | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/tests/test_intf_mac.py b/tests/test_intf_mac.py index 5ed381d693..2536103edd 100644 --- a/tests/test_intf_mac.py +++ b/tests/test_intf_mac.py @@ -4,6 +4,19 @@ import json class TestRouterInterfaceMac(object): + def add_ip_address(self, dvs, interface, ip): + tbl = swsscommon.Table(dvs.cdb, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL", "NULL")]) + tbl.set(interface, fvs) + tbl.set(interface + "|" + ip, fvs) + time.sleep(1) + + def remove_ip_address(self, dvs, interface, ip): + tbl = swsscommon.Table(dvs.cdb, "INTERFACE") + tbl._del(interface + "|" + ip); + tbl.hdel(interface, "NULL") + time.sleep(1) + def set_mac(self, dvs, interface, mac): tbl = swsscommon.Table(dvs.cdb, "INTERFACE") fvs = swsscommon.FieldValuePairs([("mac_addr", mac)]) @@ -34,7 +47,7 @@ def test_InterfaceSetMac(self, dvs, testlog): dvs.setup_db() # assign IP to interface - dvs.add_ip_address("Ethernet8", "10.0.0.4/31") + self.add_ip_address(dvs, "Ethernet8", "10.0.0.4/31") # set MAC to interface self.set_mac(dvs, "Ethernet8", "6C:EC:5A:11:22:33") @@ -51,7 +64,7 @@ def test_InterfaceSetMac(self, dvs, testlog): assert src_mac_addr_found == True # remove IP from interface - dvs.remove_ip_address("Ethernet8", "10.0.0.4/31") + self.remove_ip_address(dvs, "Ethernet8", "10.0.0.4/31") # remove MAC from interface self.remove_mac(dvs, "Ethernet8") @@ -60,7 +73,7 @@ def test_InterfaceChangeMac(self, dvs, testlog): dvs.setup_db() # assign IP to interface - dvs.add_ip_address("Ethernet12", "12.0.0.4/31") + self.add_ip_address(dvs, "Ethernet12", "12.0.0.4/31") # set MAC to interface self.set_mac(dvs, "Ethernet12", "6C:EC:5A:22:33:44") @@ -80,7 +93,7 @@ def test_InterfaceChangeMac(self, dvs, testlog): assert src_mac_addr_found == True # remove IP from interface - dvs.remove_ip_address("Ethernet12", "12.0.0.4/31") + self.remove_ip_address(dvs, "Ethernet12", "12.0.0.4/31") # remove MAC from interface self.remove_mac(dvs, "Ethernet12") @@ -111,6 +124,19 @@ def remove_port_channel_members(self, dvs, lag, members): tbl._del(lag + "|" + member) time.sleep(1) + def add_ip_address(self, dvs, interface, ip): + tbl = swsscommon.Table(dvs.cdb, "PORTCHANNEL_INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL", "NULL")]) + tbl.set(interface, fvs) + tbl.set(interface + "|" + ip, fvs) + time.sleep(1) + + def remove_ip_address(self, dvs, interface, ip): + tbl = swsscommon.Table(dvs.cdb, "PORTCHANNEL_INTERFACE") + tbl._del(interface + "|" + ip); + tbl.hdel(interface, "NULL") + time.sleep(1) + def set_mac(self, dvs, interface, mac): tbl = swsscommon.Table(dvs.cdb, "PORTCHANNEL_INTERFACE") fvs = swsscommon.FieldValuePairs([("mac_addr", mac)]) @@ -143,7 +169,7 @@ def test_InterfaceSetMac(self, dvs, testlog): self.create_port_channel(dvs, "PortChannel001") # assign IP to interface - dvs.add_ip_address("PortChannel001", "30.0.0.4/31") + self.add_ip_address(dvs, "PortChannel001", "30.0.0.4/31") # set MAC to interface self.set_mac(dvs, "PortChannel001", "6C:EC:5A:11:22:33") @@ -167,7 +193,7 @@ def test_InterfaceSetMac(self, dvs, testlog): assert src_mac_addr_found == True # remove IP from interface - dvs.remove_ip_address("PortChannel001", "30.0.0.4/31") + self.remove_ip_address(dvs, "PortChannel001", "30.0.0.4/31") # remove MAC from interface self.remove_mac(dvs, "PortChannel001") @@ -182,7 +208,7 @@ def test_InterfaceChangeMac(self, dvs, testlog): self.create_port_channel(dvs, "PortChannel002") # assign IP to interface - dvs.add_ip_address("PortChannel002", "32.0.0.4/31") + self.add_ip_address(dvs, "PortChannel002", "32.0.0.4/31") # set MAC to interface self.set_mac(dvs, "PortChannel002", "6C:EC:5A:22:33:44") @@ -209,7 +235,7 @@ def test_InterfaceChangeMac(self, dvs, testlog): assert src_mac_addr_found == True # remove IP from interface - dvs.remove_ip_address("PortChannel002", "32.0.0.4/31") + self.remove_ip_address(dvs, "PortChannel002", "32.0.0.4/31") # remove MAC from interface self.remove_mac(dvs, "PortChannel002") From 165964a1380aef55a3c83eacfec5d714926eddc0 Mon Sep 17 00:00:00 2001 From: "shine.chen" Date: Mon, 9 Sep 2019 02:28:35 -0700 Subject: [PATCH 12/17] fix the issue that intf mac can't be recovered correctly after warm-reboot Signed-off-by: shine.chen --- orchagent/intfsorch.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/orchagent/intfsorch.cpp b/orchagent/intfsorch.cpp index 4ff9fb4969..28cb1789ca 100644 --- a/orchagent/intfsorch.cpp +++ b/orchagent/intfsorch.cpp @@ -410,16 +410,25 @@ void IntfsOrch::doTask(Consumer &consumer) attr.id = SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS; memcpy(attr.value.mac, mac.getMac(), sizeof(sai_mac_t)); - sai_status_t status = sai_router_intfs_api->set_router_interface_attribute(port.m_rif_id, &attr); - if (status != SAI_STATUS_SUCCESS) + /*port.m_rif_id is set in setIntf(), need get port again*/ + if (gPortsOrch->getPort(alias, port)) { - SWSS_LOG_ERROR("Failed to set router interface mac %s for port %s, rv:%d", - mac.to_string().c_str(), port.m_alias.c_str(), status); + sai_status_t status = sai_router_intfs_api->set_router_interface_attribute(port.m_rif_id, &attr); + if (status != SAI_STATUS_SUCCESS) + { + SWSS_LOG_ERROR("Failed to set router interface mac %s for port %s, rv:%d", + mac.to_string().c_str(), port.m_alias.c_str(), status); + } + else + { + SWSS_LOG_NOTICE("Set router interface mac %s for port %s success", + mac.to_string().c_str(), port.m_alias.c_str()); + } } else { - SWSS_LOG_NOTICE("Set router interface mac %s for port %s success", - mac.to_string().c_str(), port.m_alias.c_str()); + SWSS_LOG_ERROR("Failed to set router interface mac %s for port %s, getPort fail", + mac.to_string().c_str(), alias.c_str()); } } From f577cc7652db396d72dbd97946631c584cabac6b Mon Sep 17 00:00:00 2001 From: shine4chen <37530989+shine4chen@users.noreply.github.com> Date: Sat, 16 Nov 2019 10:03:22 +0800 Subject: [PATCH 13/17] reformat intmgr.h --- cfgmgr/intfmgr.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cfgmgr/intfmgr.h b/cfgmgr/intfmgr.h index 80e8d8e5d9..77d9bbf696 100644 --- a/cfgmgr/intfmgr.h +++ b/cfgmgr/intfmgr.h @@ -26,14 +26,16 @@ class IntfMgr : public Orch void setIntfIp(const std::string &alias, const std::string &opCmd, const IpPrefix &ipPrefix); void setIntfVrf(const std::string &alias, const std::string &vrfName); void setIntfMac(const std::string &alias, const std::string &macAddr); + bool doIntfGeneralTask(const std::vector& keys, std::vector data, const std::string& op); - bool doIntfAddrTask(const std::vector& keys, const std::vector& data, const std::string& op); void doTask(Consumer &consumer); + bool isIntfStateOk(const std::string &alias); bool isIntfCreated(const std::string &alias); bool isIntfChangeVrf(const std::string &alias, const std::string &vrfName); int getIntfIpCount(const std::string &alias); + void addLoopbackIntf(const std::string &alias); void delLoopbackIntf(const std::string &alias); From b190f4dcaaa7ac8277331333cc5f5d30fd9037a8 Mon Sep 17 00:00:00 2001 From: shine4chen <37530989+shine4chen@users.noreply.github.com> Date: Sat, 16 Nov 2019 10:05:39 +0800 Subject: [PATCH 14/17] Update intfmgr.cpp --- cfgmgr/intfmgr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cfgmgr/intfmgr.cpp b/cfgmgr/intfmgr.cpp index 9b48c279af..414a6bf88e 100644 --- a/cfgmgr/intfmgr.cpp +++ b/cfgmgr/intfmgr.cpp @@ -60,7 +60,7 @@ void IntfMgr::setIntfIp(const string &alias, const string &opCmd, } } -void IntfMgr::setIntfMac(const string &alias, const string mac_str) +void IntfMgr::setIntfMac(const string &alias, const string &mac_str) { stringstream cmd; string res; From 405f41333dd05a8da5a89d1c940f4c9ea6875f3f Mon Sep 17 00:00:00 2001 From: shine4chen <37530989+shine4chen@users.noreply.github.com> Date: Sat, 30 Nov 2019 19:40:32 +0800 Subject: [PATCH 15/17] set {mac:""} to app-db if not existed in cfg-db --- cfgmgr/intfmgr.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cfgmgr/intfmgr.cpp b/cfgmgr/intfmgr.cpp index 414a6bf88e..fae732deae 100644 --- a/cfgmgr/intfmgr.cpp +++ b/cfgmgr/intfmgr.cpp @@ -401,7 +401,6 @@ bool IntfMgr::doIntfGeneralTask(const vector& keys, } bool is_lo = !alias.compare(0, strlen(LOOPBACK_PREFIX), LOOPBACK_PREFIX); string mac = ""; - string vrf_name = ""; string mtu = ""; string adminStatus = ""; @@ -460,7 +459,12 @@ bool IntfMgr::doIntfGeneralTask(const vector& keys, { setIntfMac(alias, mac); } - + else + { + FieldValueTuple fvTuple("mac", mac); + data.push_back(fvTuple); + } + if (!subIntfAlias.empty()) { if (m_subIntfList.find(subIntfAlias) == m_subIntfList.end()) From 5484fe08dd3d9d9bee5a6f59318cf2b7511a41bb Mon Sep 17 00:00:00 2001 From: shine4chen <37530989+shine4chen@users.noreply.github.com> Date: Sat, 30 Nov 2019 19:46:51 +0800 Subject: [PATCH 16/17] move mac variable definition down --- orchagent/intfsorch.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/orchagent/intfsorch.cpp b/orchagent/intfsorch.cpp index 1a7a0d9d3e..cfec4936a2 100644 --- a/orchagent/intfsorch.cpp +++ b/orchagent/intfsorch.cpp @@ -382,8 +382,6 @@ void IntfsOrch::doTask(Consumer &consumer) while (it != consumer.m_toSync.end()) { KeyOpFieldsValuesTuple t = it->second; - MacAddress mac; - vector keys = tokenize(kfvKey(t), ':'); string alias(keys[0]); @@ -406,6 +404,7 @@ void IntfsOrch::doTask(Consumer &consumer) const vector& data = kfvFieldsValues(t); string vrf_name = "", vnet_name = ""; + MacAddress mac; uint32_t mtu; bool adminUp; for (auto idx : data) From eff6af9806935c579decc30be2ac87bdd3d7e290 Mon Sep 17 00:00:00 2001 From: "shine.chen" Date: Sat, 30 Nov 2019 23:26:46 +0800 Subject: [PATCH 17/17] add some sleep on test case Signed-off-by: shine.chen --- cfgmgr/intfmgr.cpp | 3 ++- orchagent/intfsorch.cpp | 10 +++++++++- tests/test_intf_mac.py | 18 ++++++++++++++---- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/cfgmgr/intfmgr.cpp b/cfgmgr/intfmgr.cpp index fae732deae..ce1cba1eb4 100644 --- a/cfgmgr/intfmgr.cpp +++ b/cfgmgr/intfmgr.cpp @@ -7,6 +7,7 @@ #include "intfmgr.h" #include "exec.h" #include "shellcmd.h" +#include "macaddress.h" using namespace std; using namespace swss; @@ -461,7 +462,7 @@ bool IntfMgr::doIntfGeneralTask(const vector& keys, } else { - FieldValueTuple fvTuple("mac", mac); + FieldValueTuple fvTuple("mac_addr", MacAddress().to_string()); data.push_back(fvTuple); } diff --git a/orchagent/intfsorch.cpp b/orchagent/intfsorch.cpp index 130e299b94..bfcd8d40f9 100644 --- a/orchagent/intfsorch.cpp +++ b/orchagent/intfsorch.cpp @@ -421,7 +421,15 @@ void IntfsOrch::doTask(Consumer &consumer) } else if (field == "mac_addr") { - mac = MacAddress(value); + try + { + mac = MacAddress(value); + } + catch (const std::invalid_argument &e) + { + SWSS_LOG_ERROR("Invalid mac argument %s to %s()", value.c_str(), e.what()); + continue; + } } else if (field == "mtu") { diff --git a/tests/test_intf_mac.py b/tests/test_intf_mac.py index 2536103edd..d205cbee59 100644 --- a/tests/test_intf_mac.py +++ b/tests/test_intf_mac.py @@ -6,15 +6,16 @@ class TestRouterInterfaceMac(object): def add_ip_address(self, dvs, interface, ip): tbl = swsscommon.Table(dvs.cdb, "INTERFACE") - fvs = swsscommon.FieldValuePairs([("NULL", "NULL")]) + fvs = swsscommon.FieldValuePairs([("mac_addr", "00:00:00:00:00:00")]) tbl.set(interface, fvs) + fvs = swsscommon.FieldValuePairs([("NULL", "NULL")]) tbl.set(interface + "|" + ip, fvs) time.sleep(1) def remove_ip_address(self, dvs, interface, ip): tbl = swsscommon.Table(dvs.cdb, "INTERFACE") tbl._del(interface + "|" + ip); - tbl.hdel(interface, "NULL") + tbl.hdel(interface, "mac_addr") time.sleep(1) def set_mac(self, dvs, interface, mac): @@ -59,6 +60,8 @@ def test_InterfaceSetMac(self, dvs, testlog): values = dict(fvs) assert values["mac_addr"] == "6C:EC:5A:11:22:33" + time.sleep(3) + # check ASIC router interface database src_mac_addr_found = self.find_mac(dvs, "Ethernet8", "6C:EC:5A:11:22:33") assert src_mac_addr_found == True @@ -87,6 +90,8 @@ def test_InterfaceChangeMac(self, dvs, testlog): assert status == True values = dict(fvs) assert values["mac_addr"] == "6C:EC:5A:33:44:55" + + time.sleep(3) # check ASIC router interface database src_mac_addr_found = self.find_mac(dvs, "Ethernet12", "6C:EC:5A:33:44:55") @@ -126,15 +131,16 @@ def remove_port_channel_members(self, dvs, lag, members): def add_ip_address(self, dvs, interface, ip): tbl = swsscommon.Table(dvs.cdb, "PORTCHANNEL_INTERFACE") - fvs = swsscommon.FieldValuePairs([("NULL", "NULL")]) + fvs = swsscommon.FieldValuePairs([("mac_addr", "00:00:00:00:00:00")]) tbl.set(interface, fvs) + fvs = swsscommon.FieldValuePairs([("NULL", "NULL")]) tbl.set(interface + "|" + ip, fvs) time.sleep(1) def remove_ip_address(self, dvs, interface, ip): tbl = swsscommon.Table(dvs.cdb, "PORTCHANNEL_INTERFACE") tbl._del(interface + "|" + ip); - tbl.hdel(interface, "NULL") + tbl.hdel(interface, "mac_addr") time.sleep(1) def set_mac(self, dvs, interface, mac): @@ -188,6 +194,8 @@ def test_InterfaceSetMac(self, dvs, testlog): assert len(lag_entries) == 1 lag_oid = lag_entries[0] + time.sleep(3) + # check ASIC router interface database src_mac_addr_found = self.find_mac(dvs, lag_oid, "6C:EC:5A:11:22:33") assert src_mac_addr_found == True @@ -229,6 +237,8 @@ def test_InterfaceChangeMac(self, dvs, testlog): # At this point there should be only one lag in the system, which is PortChannel002. assert len(lag_entries) == 1 lag_oid = lag_entries[0] + + time.sleep(3) # check ASIC router interface database src_mac_addr_found = self.find_mac(dvs, lag_oid, "6C:EC:5A:33:44:55")