1- import pytest
21import json
3- import sys
42import time
53
64from swsscommon import swsscommon
1816 "7" : "7" ,
1917}
2018
19+ CFG_MPLS_TC_TO_TC_MAP_TABLE_NAME = "MPLS_TC_TO_TC_MAP"
20+ CFG_MPLS_TC_TO_TC_MAP_KEY = "AZURE_MPLS_TC"
21+ MPLS_TC_TO_TC_MAP = {
22+ "0" : "0" ,
23+ "1" : "4" ,
24+ "2" : "1" ,
25+ "3" : "3" ,
26+ "4" : "5" ,
27+ "5" : "2" ,
28+ "6" : "7" ,
29+ "7" : "6" ,
30+ }
31+
2132CFG_PORT_QOS_MAP_TABLE_NAME = "PORT_QOS_MAP"
22- CFG_PORT_QOS_MAP_FIELD = "dot1p_to_tc_map"
33+ CFG_PORT_QOS_DOT1P_MAP_FIELD = "dot1p_to_tc_map"
34+ CFG_PORT_QOS_MPLS_TC_MAP_FIELD = "mpls_tc_to_tc_map"
2335CFG_PORT_TABLE_NAME = "PORT"
2436
2537
@@ -39,7 +51,6 @@ def create_dot1p_profile(self):
3951 def find_dot1p_profile (self ):
4052 found = False
4153 dot1p_tc_map_raw = None
42- dot1p_tc_map_key = None
4354 tbl = swsscommon .Table (self .asic_db , "ASIC_STATE:SAI_OBJECT_TYPE_QOS_MAP" )
4455 keys = tbl .getKeys ()
4556 for key in keys :
@@ -50,7 +61,6 @@ def find_dot1p_profile(self):
5061 if fv [0 ] == "SAI_QOS_MAP_ATTR_MAP_TO_VALUE_LIST" :
5162 dot1p_tc_map_raw = fv [1 ]
5263 elif fv [0 ] == "SAI_QOS_MAP_ATTR_TYPE" and fv [1 ] == "SAI_QOS_MAP_TYPE_DOT1P_TO_TC" :
53- dot1p_tc_map_key = key
5464 found = True
5565
5666 if found :
@@ -63,7 +73,7 @@ def find_dot1p_profile(self):
6373
6474 def apply_dot1p_profile_on_all_ports (self ):
6575 tbl = swsscommon .Table (self .config_db , CFG_PORT_QOS_MAP_TABLE_NAME )
66- fvs = swsscommon .FieldValuePairs ([(CFG_PORT_QOS_MAP_FIELD , CFG_DOT1P_TO_TC_MAP_KEY )])
76+ fvs = swsscommon .FieldValuePairs ([(CFG_PORT_QOS_DOT1P_MAP_FIELD , CFG_DOT1P_TO_TC_MAP_KEY )])
6777 ports = swsscommon .Table (self .config_db , CFG_PORT_TABLE_NAME ).getKeys ()
6878 for port in ports :
6979 tbl .set (port , fvs )
@@ -74,7 +84,7 @@ def apply_dot1p_profile_on_all_ports(self):
7484 def test_dot1p_cfg (self , dvs ):
7585 self .connect_dbs (dvs )
7686 self .create_dot1p_profile ()
77- oid , dot1p_tc_map_raw = self .find_dot1p_profile ()
87+ _ , dot1p_tc_map_raw = self .find_dot1p_profile ()
7888
7989 dot1p_tc_map = json .loads (dot1p_tc_map_raw );
8090 for dot1p2tc in dot1p_tc_map ['list' ]:
@@ -86,7 +96,7 @@ def test_dot1p_cfg(self, dvs):
8696 def test_port_dot1p (self , dvs ):
8797 self .connect_dbs (dvs )
8898 self .create_dot1p_profile ()
89- oid , dot1p_tc_map_raw = self .find_dot1p_profile ()
99+ oid , _ = self .find_dot1p_profile ()
90100
91101 self .apply_dot1p_profile_on_all_ports ()
92102
@@ -106,6 +116,87 @@ def test_port_dot1p(self, dvs):
106116 assert port_cnt == cnt
107117
108118
119+ class TestMplsTc (object ):
120+ def connect_dbs (self , dvs ):
121+ self .asic_db = swsscommon .DBConnector (1 , dvs .redis_sock , 0 )
122+ self .config_db = swsscommon .DBConnector (4 , dvs .redis_sock , 0 )
123+
124+
125+ def create_mpls_tc_profile (self ):
126+ tbl = swsscommon .Table (self .config_db , CFG_MPLS_TC_TO_TC_MAP_TABLE_NAME )
127+ fvs = swsscommon .FieldValuePairs (list (MPLS_TC_TO_TC_MAP .items ()))
128+ tbl .set (CFG_MPLS_TC_TO_TC_MAP_KEY , fvs )
129+ time .sleep (1 )
130+
131+
132+ def find_mpls_tc_profile (self ):
133+ found = False
134+ mpls_tc_tc_map_raw = None
135+ tbl = swsscommon .Table (self .asic_db , "ASIC_STATE:SAI_OBJECT_TYPE_QOS_MAP" )
136+ keys = tbl .getKeys ()
137+ for key in keys :
138+ (status , fvs ) = tbl .get (key )
139+ assert status == True
140+
141+ for fv in fvs :
142+ if fv [0 ] == "SAI_QOS_MAP_ATTR_MAP_TO_VALUE_LIST" :
143+ mpls_tc_tc_map_raw = fv [1 ]
144+ elif fv [0 ] == "SAI_QOS_MAP_ATTR_TYPE" and fv [1 ] == "SAI_QOS_MAP_TYPE_MPLS_EXP_TO_TC" :
145+ found = True
146+
147+ if found :
148+ break
149+
150+ assert found == True
151+
152+ return (key , mpls_tc_tc_map_raw )
153+
154+
155+ def apply_mpls_tc_profile_on_all_ports (self ):
156+ tbl = swsscommon .Table (self .config_db , CFG_PORT_QOS_MAP_TABLE_NAME )
157+ fvs = swsscommon .FieldValuePairs ([(CFG_PORT_QOS_MPLS_TC_MAP_FIELD , CFG_MPLS_TC_TO_TC_MAP_KEY )])
158+ ports = swsscommon .Table (self .config_db , CFG_PORT_TABLE_NAME ).getKeys ()
159+ for port in ports :
160+ tbl .set (port , fvs )
161+
162+ time .sleep (1 )
163+
164+
165+ def test_mpls_tc_cfg (self , dvs ):
166+ self .connect_dbs (dvs )
167+ self .create_mpls_tc_profile ()
168+ _ , mpls_tc_tc_map_raw = self .find_mpls_tc_profile ()
169+
170+ mpls_tc_tc_map = json .loads (mpls_tc_tc_map_raw )
171+ for mplstc2tc in mpls_tc_tc_map ['list' ]:
172+ mpls_tc = str (mplstc2tc ['key' ]['mpls_exp' ])
173+ tc = str (mplstc2tc ['value' ]['tc' ])
174+ assert tc == MPLS_TC_TO_TC_MAP [mpls_tc ]
175+
176+
177+ def test_port_mpls_tc (self , dvs ):
178+ self .connect_dbs (dvs )
179+ self .create_mpls_tc_profile ()
180+ oid , _ = self .find_mpls_tc_profile ()
181+
182+ self .apply_mpls_tc_profile_on_all_ports ()
183+
184+ cnt = 0
185+ tbl = swsscommon .Table (self .asic_db , "ASIC_STATE:SAI_OBJECT_TYPE_PORT" )
186+ keys = tbl .getKeys ()
187+ for key in keys :
188+ (status , fvs ) = tbl .get (key )
189+ assert status == True
190+
191+ for fv in fvs :
192+ if fv [0 ] == "SAI_PORT_ATTR_QOS_MPLS_EXP_TO_TC_MAP" :
193+ cnt += 1
194+ assert fv [1 ] == oid
195+
196+ port_cnt = len (swsscommon .Table (self .config_db , CFG_PORT_TABLE_NAME ).getKeys ())
197+ assert port_cnt == cnt
198+
199+
109200# Add Dummy always-pass test at end as workaroud
110201# for issue when Flaky fail on final test it invokes module tear-down before retrying
111202def test_nonflaky_dummy ():
0 commit comments