Skip to content

Commit d352d5a

Browse files
authored
Update default route status to state DB (#2009)
* Orchagent update of IPv4 and IPv6 default route status. If there is a valid default route, it shall be updated as state:ok. If there is no valid default route (with packet action drop), state db shall be updated as state:na - Schema ("ROUTE_TABLE|0.0.0.0/0")
1 parent 24a64d6 commit d352d5a

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

orchagent/routeorch.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ RouteOrch::RouteOrch(DBConnector *db, vector<table_name_with_pri_t> &tableNames,
8080

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

83+
m_stateDb = shared_ptr<DBConnector>(new DBConnector("STATE_DB", 0));
84+
m_stateDefaultRouteTb = unique_ptr<swss::Table>(new Table(m_stateDb.get(), STATE_ROUTE_TABLE_NAME));
85+
8386
IpPrefix default_ip_prefix("0.0.0.0/0");
87+
updateDefRouteState("0.0.0.0/0");
8488

8589
sai_route_entry_t unicast_route_entry;
8690
unicast_route_entry.vr_id = gVirtualRouterId;
@@ -106,6 +110,7 @@ RouteOrch::RouteOrch(DBConnector *db, vector<table_name_with_pri_t> &tableNames,
106110
SWSS_LOG_NOTICE("Create IPv4 default route with packet action drop");
107111

108112
IpPrefix v6_default_ip_prefix("::/0");
113+
updateDefRouteState("::/0");
109114

110115
copy(unicast_route_entry.destination, v6_default_ip_prefix);
111116
subnet(unicast_route_entry.destination, unicast_route_entry.destination);
@@ -231,6 +236,16 @@ void RouteOrch::delLinkLocalRouteToMe(sai_object_id_t vrf_id, IpPrefix linklocal
231236
SWSS_LOG_NOTICE("Deleted link local ipv6 route %s to cpu", linklocal_prefix.to_string().c_str());
232237
}
233238

239+
void RouteOrch::updateDefRouteState(string ip, bool add)
240+
{
241+
vector<FieldValueTuple> tuples;
242+
string state = add?"ok":"na";
243+
FieldValueTuple tuple("state", state);
244+
tuples.push_back(tuple);
245+
246+
m_stateDefaultRouteTb->set(ip, tuples);
247+
}
248+
234249
bool RouteOrch::hasNextHopGroup(const NextHopGroupKey& nexthops) const
235250
{
236251
return m_syncdNextHopGroups.find(nexthops) != m_syncdNextHopGroups.end();
@@ -2147,6 +2162,11 @@ bool RouteOrch::addRoutePost(const RouteBulkContext& ctx, const NextHopGroupKey
21472162
}
21482163
}
21492164

2165+
if (ipPrefix.isDefaultRoute())
2166+
{
2167+
updateDefRouteState(ipPrefix.to_string(), true);
2168+
}
2169+
21502170
m_syncdRoutes[vrf_id][ipPrefix] = RouteNhg(nextHops, ctx.nhg_index);
21512171

21522172
notifyNextHopChangeObservers(vrf_id, ipPrefix, nextHops, true);
@@ -2262,6 +2282,8 @@ bool RouteOrch::removeRoutePost(const RouteBulkContext& ctx)
22622282
}
22632283
}
22642284

2285+
updateDefRouteState(ipPrefix.to_string());
2286+
22652287
SWSS_LOG_INFO("Set route %s next hop ID to NULL", ipPrefix.to_string().c_str());
22662288
}
22672289
else

orchagent/routeorch.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ class RouteOrch : public Orch, public Subject
225225
unsigned int m_maxNextHopGroupCount;
226226
bool m_resync;
227227

228+
shared_ptr<DBConnector> m_stateDb;
229+
unique_ptr<swss::Table> m_stateDefaultRouteTb;
230+
228231
RouteTables m_syncdRoutes;
229232
LabelRouteTables m_syncdLabelRoutes;
230233
NextHopGroupTable m_syncdNextHopGroups;
@@ -251,6 +254,8 @@ class RouteOrch : public Orch, public Subject
251254
bool addLabelRoutePost(const LabelRouteBulkContext& ctx, const NextHopGroupKey &nextHops);
252255
bool removeLabelRoutePost(const LabelRouteBulkContext& ctx);
253256

257+
void updateDefRouteState(string ip, bool add=false);
258+
254259
void doTask(Consumer& consumer);
255260
void doLabelTask(Consumer& consumer);
256261

tests/test_route.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def setup_db(self, dvs):
1212
self.pdb = dvs.get_app_db()
1313
self.adb = dvs.get_asic_db()
1414
self.cdb = dvs.get_config_db()
15+
self.sdb = dvs.get_state_db()
1516

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

6364
wait_for_result(_access_function)
6465

66+
def check_route_state(self, prefix, value):
67+
found = False
68+
69+
route_entries = self.sdb.get_keys("ROUTE_TABLE")
70+
for key in route_entries:
71+
if key != prefix:
72+
continue
73+
found = True
74+
fvs = self.sdb.get_entry("ROUTE_TABLE", key)
75+
76+
assert fvs != {}
77+
78+
for f,v in fvs.items():
79+
if f == "state":
80+
assert v == value
81+
assert found
82+
6583
def get_asic_db_key(self, destination):
6684
route_entries = self.adb.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY")
6785
for route_entry in route_entries:
@@ -123,6 +141,9 @@ def test_RouteAddRemoveIpv4Route(self, dvs, testlog):
123141
self.create_l3_intf("Ethernet0", "")
124142
self.create_l3_intf("Ethernet4", "")
125143

144+
# check STATE route database, initial state shall be "na"
145+
self.check_route_state("0.0.0.0/0", "na")
146+
126147
# set ip address
127148
self.add_ip_address("Ethernet0", "10.0.0.0/31")
128149
self.add_ip_address("Ethernet4", "10.0.0.2/31")
@@ -144,15 +165,25 @@ def test_RouteAddRemoveIpv4Route(self, dvs, testlog):
144165
# add route entry
145166
dvs.runcmd("vtysh -c \"configure terminal\" -c \"ip route 2.2.2.0/24 10.0.0.1\"")
146167

168+
# add default route entry
169+
fieldValues = {"nexthop": "10.0.0.1", "ifname": "Ethernet0"}
170+
self.create_route_entry("0.0.0.0/0", fieldValues)
171+
147172
# check application database
148173
self.pdb.wait_for_entry("ROUTE_TABLE", "2.2.2.0/24")
149174

150175
# check ASIC route database
151176
self.check_route_entries(["2.2.2.0/24"])
152177

178+
# check STATE route database
179+
self.check_route_state("0.0.0.0/0", "ok")
180+
153181
# remove route entry
154182
dvs.runcmd("vtysh -c \"configure terminal\" -c \"no ip route 2.2.2.0/24 10.0.0.1\"")
155183

184+
# remove default route entry
185+
self.remove_route_entry("0.0.0.0/0")
186+
156187
# check application database
157188
self.pdb.wait_for_deleted_entry("ROUTE_TABLE", "2.2.2.0/24")
158189

@@ -170,6 +201,9 @@ def test_RouteAddRemoveIpv4Route(self, dvs, testlog):
170201
self.set_admin_status("Ethernet0", "down")
171202
self.set_admin_status("Ethernet4", "down")
172203

204+
# check STATE route database, state set to "na" after deleting the default route
205+
self.check_route_state("0.0.0.0/0", "na")
206+
173207
# remove ip address and default route
174208
dvs.servers[0].runcmd("ip route del default dev eth0")
175209
dvs.servers[0].runcmd("ip address del 10.0.0.1/31 dev eth0")
@@ -184,6 +218,9 @@ def test_RouteAddRemoveIpv6Route(self, dvs, testlog):
184218
self.create_l3_intf("Ethernet0", "")
185219
self.create_l3_intf("Ethernet4", "")
186220

221+
# check STATE route database, initial state shall be "na"
222+
self.check_route_state("::/0", "na")
223+
187224
# bring up interface
188225
self.set_admin_status("Ethernet0", "up")
189226
self.set_admin_status("Ethernet4", "up")
@@ -207,15 +244,25 @@ def test_RouteAddRemoveIpv6Route(self, dvs, testlog):
207244
# add route entry
208245
dvs.runcmd("vtysh -c \"configure terminal\" -c \"ipv6 route 3000::0/64 2000::2\"")
209246

247+
# add default route entry
248+
fieldValues = {"nexthop": "2000::2", "ifname": "Ethernet0"}
249+
self.create_route_entry("::/0", fieldValues)
250+
210251
# check application database
211252
self.pdb.wait_for_entry("ROUTE_TABLE", "3000::/64")
212253

213254
# check ASIC route database
214255
self.check_route_entries(["3000::/64"])
215256

257+
# check STATE route database
258+
self.check_route_state("::/0", "ok")
259+
216260
# remove route entry
217261
dvs.runcmd("vtysh -c \"configure terminal\" -c \"no ipv6 route 3000::0/64 2000::2\"")
218262

263+
# remove default route entry
264+
self.remove_route_entry("::/0")
265+
219266
# check application database
220267
self.pdb.wait_for_deleted_entry("ROUTE_TABLE", "3000::/64")
221268

@@ -233,6 +280,9 @@ def test_RouteAddRemoveIpv6Route(self, dvs, testlog):
233280
self.set_admin_status("Ethernet0", "down")
234281
self.set_admin_status("Ethernet4", "down")
235282

283+
# check STATE route database, state set to "na" after deleting the default route
284+
self.check_route_state("::/0", "na")
285+
236286
# remove ip address and default route
237287
dvs.servers[0].runcmd("ip -6 route del default dev eth0")
238288
dvs.servers[0].runcmd("ip -6 address del 2000::2/64 dev eth0")

0 commit comments

Comments
 (0)