diff --git a/orchagent/intfsorch.cpp b/orchagent/intfsorch.cpp index a49b52ec4e..3d67767c6d 100644 --- a/orchagent/intfsorch.cpp +++ b/orchagent/intfsorch.cpp @@ -18,8 +18,8 @@ extern sai_router_interface_api_t* sai_router_intfs_api; extern sai_route_api_t* sai_route_api; extern sai_neighbor_api_t* sai_neighbor_api; -extern PortsOrch *gPortsOrch; extern sai_object_id_t gSwitchId; +extern PortsOrch *gPortsOrch; extern CrmOrch *gCrmOrch; extern BufferOrch *gBufferOrch; @@ -57,6 +57,27 @@ void IntfsOrch::decreaseRouterIntfsRefCount(const string &alias) alias.c_str(), m_syncdIntfses[alias].ref_count); } +bool IntfsOrch::setRouterIntfsMtu(Port &port) +{ + SWSS_LOG_ENTER(); + + sai_attribute_t attr; + attr.id = SAI_ROUTER_INTERFACE_ATTR_MTU; + attr.value.u32 = port.m_mtu; + + 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 %s MTU to %u, rv:%d", + port.m_alias.c_str(), port.m_mtu, status); + return false; + } + SWSS_LOG_NOTICE("Set router interface %s MTU to %u", + port.m_alias.c_str(), port.m_mtu); + return true; +} + void IntfsOrch::doTask(Consumer &consumer) { SWSS_LOG_ENTER(); @@ -159,7 +180,8 @@ void IntfsOrch::doTask(Consumer &consumer) addSubnetRoute(port, ip_prefix); addIp2MeRoute(ip_prefix); - if(port.m_type == Port::VLAN && ip_prefix.isV4()) + + if (port.m_type == Port::VLAN && ip_prefix.isV4()) { addDirectedBroadcast(port, ip_prefix.getBroadcastIp()); } diff --git a/orchagent/intfsorch.h b/orchagent/intfsorch.h index 0c08350d33..61df9dee59 100644 --- a/orchagent/intfsorch.h +++ b/orchagent/intfsorch.h @@ -31,6 +31,8 @@ class IntfsOrch : public Orch void increaseRouterIntfsRefCount(const string&); void decreaseRouterIntfsRefCount(const string&); + + bool setRouterIntfsMtu(Port &port); private: IntfsTable m_syncdIntfses; void doTask(Consumer &consumer); diff --git a/orchagent/orchdaemon.cpp b/orchagent/orchdaemon.cpp index 31fd7377ba..1df3d038eb 100644 --- a/orchagent/orchdaemon.cpp +++ b/orchagent/orchdaemon.cpp @@ -22,6 +22,7 @@ extern sai_object_id_t gSwitchId; */ PortsOrch *gPortsOrch; FdbOrch *gFdbOrch; +IntfsOrch *gIntfsOrch; NeighOrch *gNeighOrch; RouteOrch *gRouteOrch; AclOrch *gAclOrch; @@ -64,8 +65,8 @@ bool OrchDaemon::init() gCrmOrch = new CrmOrch(m_configDb, CFG_CRM_TABLE_NAME); gPortsOrch = new PortsOrch(m_applDb, ports_tables); gFdbOrch = new FdbOrch(m_applDb, APP_FDB_TABLE_NAME, gPortsOrch); - IntfsOrch *intfs_orch = new IntfsOrch(m_applDb, APP_INTF_TABLE_NAME); - gNeighOrch = new NeighOrch(m_applDb, APP_NEIGH_TABLE_NAME, intfs_orch); + gIntfsOrch = new IntfsOrch(m_applDb, APP_INTF_TABLE_NAME); + gNeighOrch = new NeighOrch(m_applDb, APP_NEIGH_TABLE_NAME, gIntfsOrch); gRouteOrch = new RouteOrch(m_applDb, APP_ROUTE_TABLE_NAME, gNeighOrch); CoppOrch *copp_orch = new CoppOrch(m_applDb, APP_COPP_TABLE_NAME); TunnelDecapOrch *tunnel_decap_orch = new TunnelDecapOrch(m_applDb, APP_TUNNEL_DECAP_TABLE_NAME); @@ -116,7 +117,7 @@ bool OrchDaemon::init() CFG_DTEL_EVENT_TABLE_NAME }; - m_orchList = { switch_orch, gCrmOrch, gBufferOrch, gPortsOrch, intfs_orch, gNeighOrch, gRouteOrch, copp_orch, tunnel_decap_orch, qos_orch, mirror_orch }; + m_orchList = { switch_orch, gCrmOrch, gBufferOrch, gPortsOrch, gIntfsOrch, gNeighOrch, gRouteOrch, copp_orch, tunnel_decap_orch, qos_orch, mirror_orch }; bool initialize_dtel = false; if (platform == BFN_PLATFORM_SUBSTRING || platform == VS_PLATFORM_SUBSTRING) diff --git a/orchagent/port.h b/orchagent/port.h index cd17d858a2..4f955dab51 100644 --- a/orchagent/port.h +++ b/orchagent/port.h @@ -11,7 +11,7 @@ extern "C" { #include #define DEFAULT_PORT_VLAN_ID 1 -#define DEFAULT_MTU 9100 +#define DEFAULT_MTU 9100 namespace swss { diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index 74c23723fc..1bb4c3a8a3 100644 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -1,4 +1,6 @@ #include "portsorch.h" +#include "intfsorch.h" +#include "bufferorch.h" #include "neighorch.h" #include @@ -18,7 +20,6 @@ #include "sai_serialize.h" #include "crmorch.h" #include "countercheckorch.h" -#include "bufferorch.h" #include "notifier.h" extern sai_switch_api_t *sai_switch_api; @@ -30,6 +31,7 @@ extern sai_hostif_api_t* sai_hostif_api; extern sai_acl_api_t* sai_acl_api; extern sai_queue_api_t *sai_queue_api; extern sai_object_id_t gSwitchId; +extern IntfsOrch *gIntfsOrch; extern NeighOrch *gNeighOrch; extern CrmOrch *gCrmOrch; extern BufferOrch *gBufferOrch; @@ -1529,6 +1531,10 @@ void PortsOrch::doPortTask(Consumer &consumer) p.m_mtu = mtu; m_portList[alias] = p; SWSS_LOG_NOTICE("Set port %s MTU to %u", alias.c_str(), mtu); + if (p.m_rif_id) + { + gIntfsOrch->setRouterIntfsMtu(p); + } } else { diff --git a/tests/test_interface.py b/tests/test_interface.py index b7ee4998c2..1e6b1ab7ab 100644 --- a/tests/test_interface.py +++ b/tests/test_interface.py @@ -32,7 +32,24 @@ def test_InterfaceAddIpv4Address(self, dvs): else: assert False - # check asic database + # check ASIC router interface database + tbl = swsscommon.Table(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" + if fv[0] == "SAI_ROUTER_INTERFACE_ATTR_MTU": + assert fv[1] == "1500" + + # check ASIC route database tbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY") for key in tbl.getKeys(): route = json.loads(key) @@ -43,12 +60,40 @@ def test_InterfaceAddIpv4Address(self, dvs): assert subnet_found and ip2me_found + def test_InterfaceChangeMtu(self, dvs): + pdb = swsscommon.DBConnector(0, dvs.redis_sock, 0) + adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) + cdb = swsscommon.DBConnector(4, dvs.redis_sock, 0) + + tbl = swsscommon.ProducerStateTable(pdb, "PORT_TABLE") + fvs = swsscommon.FieldValuePairs([("mtu", "8888")]) + tbl.set("Ethernet8", fvs) + + time.sleep(1) + + # check ASIC router interface database + tbl = swsscommon.Table(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" + if fv[0] == "SAI_ROUTER_INTERFACE_ATTR_MTU": + assert fv[1] == "8888" + def test_InterfaceRemoveIpv4Address(self, dvs): pdb = swsscommon.DBConnector(0, dvs.redis_sock, 0) adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) cdb = swsscommon.DBConnector(4, dvs.redis_sock, 0) - # assign IP to interface + # remove IP from interface tbl = swsscommon.Table(cdb, "INTERFACE") tbl._del("Ethernet8|10.0.0.4/31") time.sleep(1) @@ -58,7 +103,7 @@ def test_InterfaceRemoveIpv4Address(self, dvs): intf_entries = tbl.getKeys() assert len(intf_entries) == 0 - # check asic database + # check ASIC database tbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY") for key in tbl.getKeys(): route = json.loads(key)