Skip to content

Commit a198289

Browse files
authored
[orchagent, SRv6]: create seglist support to set sid list type (#2406)
* [orchagent, SRv6]: create seglist support to set sid list type If user doesn't set the sid list type, type will be ENCAPS_RED What I did create seglist support to set sid list type Why I did it could not set different sidlist type under local testing
1 parent 309df59 commit a198289

File tree

4 files changed

+56
-10
lines changed

4 files changed

+56
-10
lines changed

doc/swss-schema.md

+1
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ and reflects the LAG ports into the redis under: `LAG_TABLE:<team0>:port`
233233
key = ROUTE_TABLE:segment ; SRV6 segment name
234234
; field = value
235235
path = STRING ; Comma-separated list of IPV6 prefixes for a SRV6 segment
236+
type = STRING ; SRV6 segment list type like "insert", "encaps.red"; If not provided, default type will be "encaps.red"
236237

237238
---------------------------------------------
238239
### SRV6_MY_SID_TABLE

orchagent/srv6orch.cpp

+25-4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ const map<string, sai_my_sid_entry_endpoint_behavior_flavor_t> end_flavor_map =
5252
{"ua", SAI_MY_SID_ENTRY_ENDPOINT_BEHAVIOR_FLAVOR_PSP_AND_USD}
5353
};
5454

55+
const map<string, sai_srv6_sidlist_type_t> sidlist_type_map =
56+
{
57+
{"insert", SAI_SRV6_SIDLIST_TYPE_INSERT},
58+
{"insert.red", SAI_SRV6_SIDLIST_TYPE_INSERT_RED},
59+
{"encaps", SAI_SRV6_SIDLIST_TYPE_ENCAPS},
60+
{"encaps.red", SAI_SRV6_SIDLIST_TYPE_ENCAPS_RED}
61+
};
62+
5563
void Srv6Orch::srv6TunnelUpdateNexthops(const string srv6_source, const NextHopKey nhkey, bool insert)
5664
{
5765
if (insert)
@@ -267,7 +275,7 @@ bool Srv6Orch::srv6Nexthops(const NextHopGroupKey &nhgKey, sai_object_id_t &next
267275
return true;
268276
}
269277

270-
bool Srv6Orch::createUpdateSidList(const string sid_name, const string sid_list)
278+
bool Srv6Orch::createUpdateSidList(const string sid_name, const string sid_list, const string sidlist_type)
271279
{
272280
SWSS_LOG_ENTER();
273281
bool exists = (sid_table_.find(sid_name) != sid_table_.end());
@@ -303,7 +311,16 @@ bool Srv6Orch::createUpdateSidList(const string sid_name, const string sid_list)
303311
attributes.push_back(attr);
304312

305313
attr.id = SAI_SRV6_SIDLIST_ATTR_TYPE;
306-
attr.value.s32 = SAI_SRV6_SIDLIST_TYPE_ENCAPS_RED;
314+
if (sidlist_type_map.find(sidlist_type) == sidlist_type_map.end())
315+
{
316+
SWSS_LOG_INFO("Use default sidlist type: ENCAPS_RED");
317+
attr.value.s32 = SAI_SRV6_SIDLIST_TYPE_ENCAPS_RED;
318+
}
319+
else
320+
{
321+
SWSS_LOG_INFO("sidlist type: %s", sidlist_type.c_str());
322+
attr.value.s32 = sidlist_type_map.at(sidlist_type);
323+
}
307324
attributes.push_back(attr);
308325
status = sai_srv6_api->create_srv6_sidlist(&segment_oid, gSwitchId, (uint32_t) attributes.size(), attributes.data());
309326
if (status != SAI_STATUS_SUCCESS)
@@ -365,18 +382,22 @@ void Srv6Orch::doTaskSidTable(const KeyOpFieldsValuesTuple & tuple)
365382
SWSS_LOG_ENTER();
366383
string sid_name = kfvKey(tuple);
367384
string op = kfvOp(tuple);
368-
string sid_list;
385+
string sid_list, sidlist_type;
369386

370387
for (auto i : kfvFieldsValues(tuple))
371388
{
372389
if (fvField(i) == "path")
373390
{
374391
sid_list = fvValue(i);
375392
}
393+
if (fvField(i) == "type")
394+
{
395+
sidlist_type = fvValue(i);
396+
}
376397
}
377398
if (op == SET_COMMAND)
378399
{
379-
if (!createUpdateSidList(sid_name, sid_list))
400+
if (!createUpdateSidList(sid_name, sid_list, sidlist_type))
380401
{
381402
SWSS_LOG_ERROR("Failed to process sid %s", sid_name.c_str());
382403
}

orchagent/srv6orch.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class Srv6Orch : public Orch
7676
void doTask(Consumer &consumer);
7777
void doTaskSidTable(const KeyOpFieldsValuesTuple &tuple);
7878
void doTaskMySidTable(const KeyOpFieldsValuesTuple &tuple);
79-
bool createUpdateSidList(const string seg_name, const string ips);
79+
bool createUpdateSidList(const string seg_name, const string ips, const string sidlist_type);
8080
bool deleteSidList(const string seg_name);
8181
bool createSrv6Tunnel(const string srv6_source);
8282
bool createSrv6Nexthop(const NextHopKey &nh);

tests/test_srv6.py

+29-5
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,14 @@ def setup_db(self, dvs):
121121
self.adb = dvs.get_asic_db()
122122
self.cdb = dvs.get_config_db()
123123

124-
def create_sidlist(self, segname, ips):
124+
def create_sidlist(self, segname, ips, type=None):
125125
table = "ASIC_STATE:SAI_OBJECT_TYPE_SRV6_SIDLIST"
126126
existed_entries = get_exist_entries(self.adb.db_connection, table)
127127

128-
fvs=swsscommon.FieldValuePairs([('path', ips)])
128+
if type is None:
129+
fvs=swsscommon.FieldValuePairs([('path', ips)])
130+
else:
131+
fvs=swsscommon.FieldValuePairs([('path', ips), ('type', type)])
129132
segtbl = swsscommon.ProducerStateTable(self.pdb.db_connection, "SRV6_SID_LIST_TABLE")
130133
segtbl.set(segname, fvs)
131134

@@ -239,9 +242,30 @@ def test_srv6(self, dvs, testlog):
239242

240243

241244
# create 2nd seg lists
242-
self.create_sidlist('seg2', 'baba:2002:10::,baba:2002:20::')
243-
# create 3rd seg lists
244-
self.create_sidlist('seg3', 'baba:2003:10::,baba:2003:20::')
245+
sidlist_id = self.create_sidlist('seg2', 'baba:2002:10::,baba:2002:20::', 'insert.red')
246+
247+
# check ASIC SAI_OBJECT_TYPE_SRV6_SIDLIST database
248+
tbl = swsscommon.Table(self.adb.db_connection, "ASIC_STATE:SAI_OBJECT_TYPE_SRV6_SIDLIST")
249+
(status, fvs) = tbl.get(sidlist_id)
250+
assert status == True
251+
for fv in fvs:
252+
if fv[0] == "SAI_SRV6_SIDLIST_ATTR_SEGMENT_LIST":
253+
assert fv[1] == "2:baba:2002:10::,baba:2002:20::"
254+
elif fv[0] == "SAI_SRV6_SIDLIST_ATTR_TYPE":
255+
assert fv[1] == "SAI_SRV6_SIDLIST_TYPE_INSERT_RED"
256+
257+
# create 3rd seg lists with unsupported or wrong naming of sid list type, for this case, it will use default type: ENCAPS_RED
258+
sidlist_id = self.create_sidlist('seg3', 'baba:2003:10::,baba:2003:20::', 'reduced')
259+
260+
# check ASIC SAI_OBJECT_TYPE_SRV6_SIDLIST database
261+
tbl = swsscommon.Table(self.adb.db_connection, "ASIC_STATE:SAI_OBJECT_TYPE_SRV6_SIDLIST")
262+
(status, fvs) = tbl.get(sidlist_id)
263+
assert status == True
264+
for fv in fvs:
265+
if fv[0] == "SAI_SRV6_SIDLIST_ATTR_SEGMENT_LIST":
266+
assert fv[1] == "2:baba:2003:10::,baba:2003:20::"
267+
elif fv[0] == "SAI_SRV6_SIDLIST_ATTR_TYPE":
268+
assert fv[1] == "SAI_SRV6_SIDLIST_TYPE_ENCAPS_RED"
245269

246270
# create 2nd v4 route with single sidlists
247271
self.create_srv6_route('20.20.20.21/32','seg2','1001:2000::1')

0 commit comments

Comments
 (0)