Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update default route status to state DB #2009

Merged
merged 7 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions orchagent/muxorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ MuxCable::MuxCable(string name, IpPrefix& srv_ip4, IpPrefix& srv_ip6, IpAddress
state_machine_handlers_.insert(handler_pair(MUX_STATE_STANDBY_ACTIVE, &MuxCable::stateActive));
state_machine_handlers_.insert(handler_pair(MUX_STATE_INIT_STANDBY, &MuxCable::stateStandby));
state_machine_handlers_.insert(handler_pair(MUX_STATE_ACTIVE_STANDBY, &MuxCable::stateStandby));

/* Set initial state to "standby" */
stateStandby();
prsunny marked this conversation as resolved.
Show resolved Hide resolved
}

bool MuxCable::stateInitActive()
Expand Down
23 changes: 23 additions & 0 deletions orchagent/routeorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ RouteOrch::RouteOrch(DBConnector *db, vector<table_name_with_pri_t> &tableNames,

SWSS_LOG_NOTICE("Maximum number of ECMP groups supported is %d", m_maxNextHopGroupCount);

m_stateDb = shared_ptr<DBConnector>(new DBConnector("STATE_DB", 0));
m_stateDefaultRouteTb = unique_ptr<swss::Table>(new Table(m_stateDb.get(), STATE_DEFAULT_ROUTE_TABLE_NAME));


IpPrefix default_ip_prefix("0.0.0.0/0");
updateDefRouteState("0.0.0.0/0");

sai_route_entry_t unicast_route_entry;
unicast_route_entry.vr_id = gVirtualRouterId;
Expand All @@ -103,6 +108,7 @@ RouteOrch::RouteOrch(DBConnector *db, vector<table_name_with_pri_t> &tableNames,
SWSS_LOG_NOTICE("Create IPv4 default route with packet action drop");

IpPrefix v6_default_ip_prefix("::/0");
updateDefRouteState("::/0");

copy(unicast_route_entry.destination, v6_default_ip_prefix);
subnet(unicast_route_entry.destination, unicast_route_entry.destination);
Expand Down Expand Up @@ -228,6 +234,16 @@ void RouteOrch::delLinkLocalRouteToMe(sai_object_id_t vrf_id, IpPrefix linklocal
SWSS_LOG_NOTICE("Deleted link local ipv6 route %s to cpu", linklocal_prefix.to_string().c_str());
}

void RouteOrch::updateDefRouteState(string ip, bool add)
{
vector<FieldValueTuple> tuples;
string state = add?"ok":"na";
FieldValueTuple tuple("state", state);
tuples.push_back(tuple);

m_stateDefaultRouteTb->set(ip, tuples);
}

bool RouteOrch::hasNextHopGroup(const NextHopGroupKey& nexthops) const
{
return m_syncdNextHopGroups.find(nexthops) != m_syncdNextHopGroups.end();
Expand Down Expand Up @@ -2048,6 +2064,11 @@ bool RouteOrch::addRoutePost(const RouteBulkContext& ctx, const NextHopGroupKey
}
}

if (ipPrefix.isDefaultRoute())
{
updateDefRouteState(ipPrefix.to_string(), true);
}

m_syncdRoutes[vrf_id][ipPrefix] = RouteNhg(nextHops, ctx.nhg_index);

notifyNextHopChangeObservers(vrf_id, ipPrefix, nextHops, true);
Expand Down Expand Up @@ -2163,6 +2184,8 @@ bool RouteOrch::removeRoutePost(const RouteBulkContext& ctx)
}
}

updateDefRouteState(ipPrefix.to_string());

SWSS_LOG_INFO("Set route %s next hop ID to NULL", ipPrefix.to_string().c_str());
}
else
Expand Down
5 changes: 5 additions & 0 deletions orchagent/routeorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ class RouteOrch : public Orch, public Subject
unsigned int getNhgCount() { return m_nextHopGroupCount; }
unsigned int getMaxNhgCount() { return m_maxNextHopGroupCount; }

void updateDefRouteState(string ip, bool add=false);
prsunny marked this conversation as resolved.
Show resolved Hide resolved

private:
SwitchOrch *m_switchOrch;
NeighOrch *m_neighOrch;
Expand All @@ -217,6 +219,9 @@ class RouteOrch : public Orch, public Subject
unsigned int m_maxNextHopGroupCount;
bool m_resync;

shared_ptr<DBConnector> m_stateDb;
unique_ptr<swss::Table> m_stateDefaultRouteTb;

RouteTables m_syncdRoutes;
LabelRouteTables m_syncdLabelRoutes;
NextHopGroupTable m_syncdNextHopGroups;
Expand Down
36 changes: 36 additions & 0 deletions tests/test_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def setup_db(self, dvs):
self.pdb = dvs.get_app_db()
self.adb = dvs.get_asic_db()
self.cdb = dvs.get_config_db()
self.sdb = dvs.get_state_db()

def set_admin_status(self, interface, status):
self.cdb.update_entry("PORT", interface, {"admin_status": status})
Expand Down Expand Up @@ -62,6 +63,23 @@ def _access_function():

wait_for_result(_access_function)

def check_route_state(self, prefix, value):
found = False

route_entries = self.sdb.get_keys("ROUTE_TABLE")
for key in route_entries:
if key != prefix:
continue
found = True
fvs = self.sdb.get_entry("ROUTE_TABLE", key)

assert fvs != {}

for f,v in fvs.items():
if f == "state":
assert v == value
assert found

def get_asic_db_key(self, destination):
route_entries = self.adb.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY")
for route_entry in route_entries:
Expand Down Expand Up @@ -123,6 +141,9 @@ def test_RouteAddRemoveIpv4Route(self, dvs, testlog):
self.create_l3_intf("Ethernet0", "")
self.create_l3_intf("Ethernet4", "")

# check STATE route database, initial state shall be "na"
self.check_route_state("0.0.0.0/0", "na")

# set ip address
self.add_ip_address("Ethernet0", "10.0.0.0/31")
self.add_ip_address("Ethernet4", "10.0.0.2/31")
Expand Down Expand Up @@ -150,6 +171,9 @@ def test_RouteAddRemoveIpv4Route(self, dvs, testlog):
# check ASIC route database
self.check_route_entries(["2.2.2.0/24"])

# check STATE route database
self.check_route_state("0.0.0.0/0", "ok")

# remove route entry
dvs.runcmd("vtysh -c \"configure terminal\" -c \"no ip route 2.2.2.0/24 10.0.0.1\"")

Expand All @@ -170,6 +194,9 @@ def test_RouteAddRemoveIpv4Route(self, dvs, testlog):
self.set_admin_status("Ethernet0", "down")
self.set_admin_status("Ethernet4", "down")

# check STATE route database, state set to "na" after deleting the default route
self.check_route_state("0.0.0.0/0", "na")

# remove ip address and default route
dvs.servers[0].runcmd("ip route del default dev eth0")
dvs.servers[0].runcmd("ip address del 10.0.0.1/31 dev eth0")
Expand All @@ -184,6 +211,9 @@ def test_RouteAddRemoveIpv6Route(self, dvs, testlog):
self.create_l3_intf("Ethernet0", "")
self.create_l3_intf("Ethernet4", "")

# check STATE route database, initial state shall be "na"
self.check_route_state("::/0", "na")

# bring up interface
self.set_admin_status("Ethernet0", "up")
self.set_admin_status("Ethernet4", "up")
Expand Down Expand Up @@ -213,6 +243,9 @@ def test_RouteAddRemoveIpv6Route(self, dvs, testlog):
# check ASIC route database
self.check_route_entries(["3000::/64"])

# check STATE route database
self.check_route_state("::/0", "ok")

# remove route entry
dvs.runcmd("vtysh -c \"configure terminal\" -c \"no ipv6 route 3000::0/64 2000::2\"")

Expand All @@ -233,6 +266,9 @@ def test_RouteAddRemoveIpv6Route(self, dvs, testlog):
self.set_admin_status("Ethernet0", "down")
self.set_admin_status("Ethernet4", "down")

# check STATE route database, state set to "na" after deleting the default route
self.check_route_state("::/0", "na")

# remove ip address and default route
dvs.servers[0].runcmd("ip -6 route del default dev eth0")
dvs.servers[0].runcmd("ip -6 address del 2000::2/64 dev eth0")
Expand Down