-
Notifications
You must be signed in to change notification settings - Fork 525
/
test_fdb_warm.py
281 lines (239 loc) · 11.1 KB
/
test_fdb_warm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
from swsscommon import swsscommon
import os
import sys
import time
import json
from distutils.version import StrictVersion
def create_entry(tbl, key, pairs):
fvs = swsscommon.FieldValuePairs(pairs)
tbl.set(key, fvs)
# FIXME: better to wait until DB create them
time.sleep(1)
def create_entry_tbl(db, table, key, pairs):
tbl = swsscommon.Table(db, table)
create_entry(tbl, key, pairs)
def create_entry_pst(db, table, key, pairs):
tbl = swsscommon.ProducerStateTable(db, table)
create_entry(tbl, key, pairs)
def how_many_entries_exist(db, table):
tbl = swsscommon.Table(db, table)
return len(tbl.getKeys())
def test_fdb_notifications(dvs, testlog):
dvs.setup_db()
dvs.runcmd("sonic-clear fdb all")
dvs.runcmd("crm config polling interval 1")
dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '1000')
time.sleep(2)
counter_before = dvs.getCrmCounterValue('STATS', 'crm_stats_fdb_entry_used')
# create vlan; create vlan member
dvs.create_vlan("6")
dvs.create_vlan_member("6", "Ethernet64")
dvs.create_vlan_member("6", "Ethernet68")
# Put Ethernet72 and Ethernet76 into vlan 7 in untagged mode, they will have pvid of 7
# and into vlan8 in tagged mode
dvs.create_vlan("7")
dvs.create_vlan_member("7", "Ethernet72")
dvs.create_vlan_member("7", "Ethernet76")
dvs.create_vlan("8")
dvs.create_vlan_member_tagged("8", "Ethernet72")
dvs.create_vlan_member_tagged("8", "Ethernet76")
# Get mapping between interface name and its bridge port_id
time.sleep(2)
iface_2_bridge_port_id = dvs.get_map_iface_bridge_port_id(dvs.adb)
# check FDB learning mode
ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT',
iface_2_bridge_port_id["Ethernet64"],
[("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")])
assert ok, str(extra)
ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT',
iface_2_bridge_port_id["Ethernet68"],
[("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")])
assert ok, str(extra)
ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT',
iface_2_bridge_port_id["Ethernet72"],
[("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")])
assert ok, str(extra)
ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT',
iface_2_bridge_port_id["Ethernet76"],
[("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")])
assert ok, str(extra)
# check fdb aging attr
ok, extra = dvs.all_table_entry_has_no(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_SWITCH',
".*",
["SAI_SWITCH_ATTR_FDB_AGING_TIME"])
# bring up vlan and member
dvs.set_interface_status("Vlan6", "up")
dvs.add_ip_address("Vlan6", "6.6.6.1/24")
dvs.add_ip_address("Vlan8", "8.8.8.1/24")
dvs.set_interface_status("Ethernet64", "up")
dvs.set_interface_status("Ethernet68", "up")
dvs.set_interface_status("Ethernet72", "up")
dvs.set_interface_status("Ethernet76", "up")
dvs.servers[16].runcmd("ifconfig eth0 6.6.6.6/24 up")
dvs.servers[16].runcmd("ip route add default via 6.6.6.1")
dvs.servers[17].runcmd("ifconfig eth0 6.6.6.7/24 up")
dvs.servers[17].runcmd("ip route add default via 6.6.6.1")
dvs.servers[18].runcmd("vconfig add eth0 8")
dvs.servers[18].runcmd("ifconfig eth0.8 8.8.8.6/24 up")
dvs.servers[18].runcmd("ip route add default via 8.8.8.1")
dvs.servers[19].runcmd("vconfig add eth0 8")
dvs.servers[19].runcmd("ifconfig eth0.8 8.8.8.7/24 up")
dvs.servers[19].runcmd("ip route add default via 8.8.8.1")
# get neighbor and arp entry
time.sleep(2)
rc = dvs.servers[16].runcmd("ping -c 1 6.6.6.7")
assert rc == 0
rc = dvs.servers[17].runcmd("ping -c 1 6.6.6.6")
assert rc == 0
# get neighbor and arp entry
time.sleep(2)
rc = dvs.servers[18].runcmd("ping -c 1 8.8.8.7")
assert rc == 0
rc = dvs.servers[19].runcmd("ping -c 1 8.8.8.6")
assert rc == 0
# check that the FDB entries were inserted into ASIC DB
ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY",
[],
[("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"),
("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet64"]),
]
)
assert ok, str(extra)
ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY",
[],
[("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"),
("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet68"]),
]
)
assert ok, str(extra)
ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY",
[],
[("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"),
("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet72"]),
]
)
assert ok, str(extra)
ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY",
[],
[("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"),
("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet76"]),
]
)
assert ok, str(extra)
time.sleep(2)
counter_inserted = dvs.getCrmCounterValue('STATS', 'crm_stats_fdb_entry_used')
assert counter_inserted - counter_before == 4
# check that the FDB entries were inserted into State DB
ok, extra = dvs.is_table_entry_exists(dvs.sdb, "FDB_TABLE",
"Vlan6:.*",
[("port", "Ethernet64"),
("type", "dynamic"),
]
)
assert ok, str(extra)
ok, extra = dvs.is_table_entry_exists(dvs.sdb, "FDB_TABLE",
"Vlan6:*",
[("port", "Ethernet68"),
("type", "dynamic"),
]
)
assert ok, str(extra)
# check that the FDB entries were inserted into State DB, Vlan8 while not Vlan7(untagged) in the key
ok, extra = dvs.is_table_entry_exists(dvs.sdb, "FDB_TABLE",
"Vlan8:.*",
[("port", "Ethernet72"),
("type", "dynamic"),
]
)
assert ok, str(extra)
ok, extra = dvs.is_table_entry_exists(dvs.sdb, "FDB_TABLE",
"Vlan8:*",
[("port", "Ethernet76"),
("type", "dynamic"),
]
)
assert ok, str(extra)
# enable warm restart
(exitcode, result) = dvs.runcmd("config warm_restart enable swss")
assert exitcode == 0
# freeze orchagent for warm restart
(exitcode, result) = dvs.runcmd("/usr/bin/orchagent_restart_check")
assert result == "RESTARTCHECK succeeded\n"
time.sleep(2)
try:
# restart orchagent
dvs.stop_swss()
# check FDB learning mode
ok, extra = dvs.all_table_entry_has(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT',
".*",
[("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_DISABLE")])
assert ok, str(extra)
# check FDB aging time
ok, extra = dvs.all_table_entry_has(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_SWITCH',
".*",
[("SAI_SWITCH_ATTR_FDB_AGING_TIME", "0")])
assert ok, str(extra)
dvs.start_swss()
time.sleep(2)
# Get mapping between interface name and its bridge port_id
# Note: they are changed
iface_2_bridge_port_id = dvs.get_map_iface_bridge_port_id(dvs.adb)
# check that the FDB entries were inserted into ASIC DB
ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY",
[],
[("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"),
("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet64"]),
]
)
assert ok, str(extra)
ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY",
[],
[("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"),
("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet68"]),
]
)
assert ok, str(extra)
# check that the FDB entries were inserted into ASIC DB
ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY",
[],
[("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"),
("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet72"]),
]
)
assert ok, str(extra)
ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY",
[],
[("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"),
("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet76"]),
]
)
assert ok, str(extra)
# check FDB learning mode
ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT',
iface_2_bridge_port_id["Ethernet64"],
[("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")])
assert ok, str(extra)
ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT',
iface_2_bridge_port_id["Ethernet68"],
[("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")])
assert ok, str(extra)
ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT',
iface_2_bridge_port_id["Ethernet72"],
[("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")])
assert ok, str(extra)
ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT',
iface_2_bridge_port_id["Ethernet76"],
[("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")])
assert ok, str(extra)
time.sleep(2)
counter_restarted = dvs.getCrmCounterValue('STATS', 'crm_stats_fdb_entry_used')
assert counter_inserted == counter_restarted
# check fdb aging attr
ok, extra = dvs.all_table_entry_has_no(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_SWITCH',
".*",
["SAI_SWITCH_ATTR_FDB_AGING_TIME"])
finally:
# disable warm restart
dvs.runcmd("config warm_restart disable swss")
# slow down crm polling
dvs.runcmd("crm config polling interval 10000")