Skip to content

Commit

Permalink
[intfsorch]: Add setRouterIntfsMtu function
Browse files Browse the repository at this point in the history
This function allows the propagation of MTU from port MTU to router
interface MTU if the router interface is created based on this port.

Once the port MTU gets changes, the router interface MTU will also
get changed.

Update the VS unit test test_InterfaceChangeMtu case. It will check
the data flow from application database to ASIC database.

Signed-off-by: Shu0T1an ChenG <[email protected]>
  • Loading branch information
Shu0T1an ChenG committed Aug 14, 2018
1 parent c9ed2c4 commit 5a50673
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 10 deletions.
26 changes: 24 additions & 2 deletions orchagent/intfsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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());
}
Expand Down
2 changes: 2 additions & 0 deletions orchagent/intfsorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions orchagent/orchdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extern sai_object_id_t gSwitchId;
*/
PortsOrch *gPortsOrch;
FdbOrch *gFdbOrch;
IntfsOrch *gIntfsOrch;
NeighOrch *gNeighOrch;
RouteOrch *gRouteOrch;
AclOrch *gAclOrch;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion orchagent/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extern "C" {
#include <map>

#define DEFAULT_PORT_VLAN_ID 1
#define DEFAULT_MTU 9100
#define DEFAULT_MTU 9100

namespace swss {

Expand Down
8 changes: 7 additions & 1 deletion orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "portsorch.h"
#include "intfsorch.h"
#include "bufferorch.h"
#include "neighorch.h"

#include <cassert>
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down
51 changes: 48 additions & 3 deletions tests/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 5a50673

Please sign in to comment.