blob: 456a6b5e97c5689c32433d10d5ccf533de3142ae [file] [log] [blame]
Daniele Moro790cc102021-08-30 18:27:30 +02001class UP4:
2
3 def __init__(self):
4 self.default = ''
5
Daniele Moro790cc102021-08-30 18:27:30 +02006 def CASE1(self, main):
Daniele Morobf53dec2021-09-13 18:11:56 +02007 main.case("Fabric UPF traffic terminated in the fabric")
Daniele Moro790cc102021-08-30 18:27:30 +02008 """
Daniele Morobf53dec2021-09-13 18:11:56 +02009 Program PDRs and FARs for UEs
10 Verify PDRs and FARs
Daniele Moro790cc102021-08-30 18:27:30 +020011 Generate traffic from UE to PDN
12 Verify traffic received from PDN
13 Generate traffic from PDN to UE
14 Verify traffic received from UE
Daniele Morobf53dec2021-09-13 18:11:56 +020015 Remove PDRs and FARs for UEs
16 Verify removed PDRs and FARs
Daniele Moro790cc102021-08-30 18:27:30 +020017 """
Daniele Moro790cc102021-08-30 18:27:30 +020018 try:
Daniele Moro80889562021-09-08 10:09:26 +020019 from tests.USECASE.SegmentRouting.dependencies.up4 import UP4
Daniele Moro790cc102021-08-30 18:27:30 +020020 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import \
21 Testcaselib as run
Daniele Moro790cc102021-08-30 18:27:30 +020022 except ImportError as e:
23 main.log.error("Import not found. Exiting the test")
24 main.log.error(e)
25 main.cleanAndExit()
26
Daniele Moro790cc102021-08-30 18:27:30 +020027 run.initTest(main)
28 main.log.info(main.Cluster.numCtrls)
29 main.Cluster.setRunningNode(3)
30 run.installOnos(main, skipPackage=True, cliSleep=5)
31
Daniele Moro790cc102021-08-30 18:27:30 +020032 main.step("Start scapy and p4rt client")
Daniele Morobf53dec2021-09-13 18:11:56 +020033 # Use the first available ONOS instance CLI
34 onos_cli = main.Cluster.active(0).CLI
Daniele Moro9ba5cf02021-10-08 18:00:56 +020035 initial_flow_count = onos_cli.checkFlowCount()
Daniele Moro80889562021-09-08 10:09:26 +020036 up4 = UP4()
37 # Get the P4RT client connected to UP4 in the first available ONOS instance
38 up4.setup(main.Cluster.active(0).p4rtUp4)
Daniele Moro790cc102021-08-30 18:27:30 +020039
Daniele Moro93feb022021-10-04 16:26:23 +020040 main.step("Program and Verify PDRs and FARs via UP4")
Daniele Moro80889562021-09-08 10:09:26 +020041 up4.attachUes()
Daniele Morobf53dec2021-09-13 18:11:56 +020042 up4.verifyUp4Flow(onos_cli)
43
Daniele Moro9ba5cf02021-10-08 18:00:56 +020044 run.checkFlows(
45 main,
46 minFlowCount=initial_flow_count+(len(up4.emulated_ues)*2)
47 )
48
Daniele Moro80889562021-09-08 10:09:26 +020049 # ------- Test Upstream traffic (enb->pdn)
Daniele Moro790cc102021-08-30 18:27:30 +020050 main.step("Test upstream traffic")
Daniele Moro80889562021-09-08 10:09:26 +020051 up4.testUpstreamTraffic()
Daniele Moro790cc102021-08-30 18:27:30 +020052
Daniele Moro80889562021-09-08 10:09:26 +020053 # ------- Test Downstream traffic (pdn->enb)
Daniele Moro790cc102021-08-30 18:27:30 +020054 main.step("Test downstream traffic")
Daniele Moro80889562021-09-08 10:09:26 +020055 up4.testDownstreamTraffic()
Daniele Moro790cc102021-08-30 18:27:30 +020056
Daniele Moro93feb022021-10-04 16:26:23 +020057 main.step("Remove and Verify PDRs and FARs via UP4")
Daniele Moro80889562021-09-08 10:09:26 +020058 up4.detachUes()
Daniele Morobf53dec2021-09-13 18:11:56 +020059 up4.verifyNoUesFlow(onos_cli)
60
Daniele Moro9ba5cf02021-10-08 18:00:56 +020061 run.checkFlows(main, minFlowCount=initial_flow_count)
62
Daniele Moro790cc102021-08-30 18:27:30 +020063 main.step("Stop scapy and p4rt client")
Daniele Moro80889562021-09-08 10:09:26 +020064 up4.teardown()
Daniele Moroc99bf822021-10-11 23:21:15 +020065
66 run.saveOnosDiagsIfFailure(main)
Daniele Moro790cc102021-08-30 18:27:30 +020067 run.cleanup(main)
Daniele Morobf53dec2021-09-13 18:11:56 +020068
Daniele Moro9ba5cf02021-10-08 18:00:56 +020069 def CASE2(self, main):
Daniele Morobf53dec2021-09-13 18:11:56 +020070 main.case("BESS traffic routed")
71 """
72 Program PDRs and FARs for UEs managed via UP4
73 Verify PDRs and FARs
74 Verify Upstream Traffic: eNB -> Fabric -> BESS (encapped)
75 Verify Upstream Traffic: BESS -> Fabric -> PDN (not encapped)
76 Verify Downstream Traffic: PDN -> Fabric -> BESS (not encapped)
77 Verify Downstream Traffic: BESS -> Fabric -> eNB (encapped)
78 Remove PDRs and FARs for UEs managed via UP4
79 Verify removed PDRs and FARs
80 """
81 BESS_TEID = 300
82 BESS_UE_ADDR = "10.241.0.1"
83 GPDU_PORT = 2152
84 UE_PORT = 400
85 PDN_PORT = 800
86 try:
87 from tests.USECASE.SegmentRouting.dependencies.up4 import UP4
88 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import \
89 Testcaselib as run
90 except ImportError as e:
91 main.log.error("Import not found. Exiting the test")
92 main.log.error(e)
93 main.cleanAndExit()
94
95 run.initTest(main)
96 main.log.info(main.Cluster.numCtrls)
97 main.Cluster.setRunningNode(3)
98 run.installOnos(main, skipPackage=True, cliSleep=5)
99
100 main.step("Start scapy and p4rt client + Scapy on BESS Host")
101 # Use the first available ONOS instance CLI
102 onos_cli = main.Cluster.active(0).CLI
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200103 initial_flow_count = onos_cli.checkFlowCount()
Daniele Morobf53dec2021-09-13 18:11:56 +0200104 up4 = UP4()
105 # Get the P4RT client connected to UP4 in the first available ONOS instance
106 up4.setup(main.Cluster.active(0).p4rtUp4)
107
108 # Setup the emulated BESS host and required parameters
109 bess_host = main.Compute2 # FIXME: Parametrize?
110 bess_interface = bess_host.interfaces[0]
111 bess_s1u_address = bess_interface["ips"][0]
112 bess_host.startScapy(ifaceName=bess_interface["name"], enableGtp=True)
113 enodeb_host = up4.enodeb_host
114 enodeb_interface = up4.enodeb_interface
115 pdn_host = up4.pdn_host
116 pdn_interface = up4.pdn_interface
117
Daniele Moro93feb022021-10-04 16:26:23 +0200118 main.step("Program and Verify PDRs and FARs for UEs via UP4")
Daniele Morobf53dec2021-09-13 18:11:56 +0200119 up4.attachUes()
Daniele Morobf53dec2021-09-13 18:11:56 +0200120 up4.verifyUp4Flow(onos_cli)
121
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200122 run.checkFlows(
123 main,
124 minFlowCount=initial_flow_count+(len(up4.emulated_ues)*2)
125 )
126
Daniele Morobf53dec2021-09-13 18:11:56 +0200127 # ------------------- UPSTREAM -------------------
128 # ------- eNB -> fabric -> BESS (encapped)
129 main.step("Test upstream eNB -> fabric -> BESS")
130 # Start filter before sending packets, BESS should receive GTP encapped
131 # packets
132 pkt_filter_upstream = "ip and udp src port %d and udp dst port %d and src host %s and dst host %s" % (
133 GPDU_PORT, GPDU_PORT, up4.enb_address, bess_s1u_address)
134 main.log.info("Start listening on %s intf %s" % (
135 bess_host.name, bess_interface["name"]))
136 main.log.debug("BPF Filter BESS Upstream: \n %s" % pkt_filter_upstream)
137 bess_host.startFilter(ifaceName=bess_interface["name"],
138 sniffCount=1,
139 pktFilter=pkt_filter_upstream)
140 # Send GTP Packet
141 UP4.buildGtpPacket(enodeb_host,
142 src_ip_outer=up4.enb_address,
143 dst_ip_outer=bess_s1u_address,
144 src_ip_inner=BESS_UE_ADDR,
145 dst_ip_inner=pdn_interface["ips"][0],
146 src_udp_inner=UE_PORT,
147 dst_udp_inner=PDN_PORT,
148 teid=BESS_TEID)
149 enodeb_host.sendPacket()
150
151 packets = UP4.checkFilterAndGetPackets(bess_host)
152 # FIXME: with newer scapy TEID becomes teid (required for Scapy 2.4.5)
153 n_packets = packets.count("TEID=" + hex(BESS_TEID) + "L ")
154 tot_packets = packets.count('Ether')
155 utilities.assert_equal(expect=True,
156 actual=n_packets == 1 and tot_packets == 1,
157 onpass="BESS correctly received 1 GTP encapped packet",
158 onfail="ERROR: BESS received %d GTP encapped packets and filter captured %d packets" % (
159 n_packets, tot_packets))
160
161 # ------- BESS -> fabric -> PDN (not-encapped)
162 main.step("Test upstream BESS -> fabric -> PDN")
163 # Start filter before sending packets, PDN should receive non-GTP packet
164 pkt_filter_upstream = "ip and udp src port %d and udp dst port %d and src host %s and dst host %s" % (
165 UE_PORT, PDN_PORT, BESS_UE_ADDR, pdn_interface["ips"][0])
166 main.log.info("Start listening on %s intf %s" % (
167 pdn_host.name, pdn_interface["name"]))
168 main.log.debug("BPF Filter PDN Upstream: \n %s" % pkt_filter_upstream)
169 pdn_host.startFilter(ifaceName=pdn_interface["name"],
170 sniffCount=1,
171 pktFilter=pkt_filter_upstream)
172 # Send UDP Packet
173 UP4.buildUdpPacket(bess_host,
174 src_ip=BESS_UE_ADDR,
175 dst_ip=pdn_interface["ips"][0],
176 src_udp=UE_PORT,
177 dst_udp=PDN_PORT)
178 bess_host.sendPacket()
179
180 packets = UP4.checkFilterAndGetPackets(pdn_host)
181 tot_packets = packets.count('Ether')
182 utilities.assert_equal(expect=True,
183 actual=tot_packets == 1,
184 onpass="PDN correctly received 1 packet",
185 onfail="ERROR: PDN received %d packets" % (
186 tot_packets))
187 # ------------------------------------------------
188
189 # ------------------ DOWNSTREAM ------------------
190 # ------- PDN -> fabric -> BESS (not-encapped)
191 main.step("Test downstream PDN -> fabric -> BESS")
192 pkt_filter_downstream = "ip and udp src port %d and udp dst port %d and src host %s and dst host %s" % (
193 PDN_PORT, UE_PORT, pdn_interface["ips"][0], BESS_UE_ADDR)
194 main.log.info("Start listening on %s intf %s" % (
195 bess_host.name, bess_interface["name"]))
196 main.log.debug(
197 "BPF Filter BESS Downstream: \n %s" % pkt_filter_downstream)
198 bess_host.startFilter(ifaceName=bess_interface["name"],
199 sniffCount=1,
200 pktFilter=pkt_filter_downstream)
201 UP4.buildUdpPacket(pdn_host,
202 dst_eth=up4.router_mac,
203 src_ip=pdn_interface["ips"][0],
204 dst_ip=BESS_UE_ADDR,
205 src_udp=PDN_PORT,
206 dst_udp=UE_PORT)
207 pdn_host.sendPacket()
208
209 packets = UP4.checkFilterAndGetPackets(bess_host)
210
211 tot_packets = packets.count('Ether')
212 utilities.assert_equal(expect=True,
213 actual=tot_packets == 1,
214 onpass="BESS correctly received 1 packet",
215 onfail="ERROR: BESS received %d packets" % (
216 tot_packets))
217
218 # ------- BESS -> fabric -> eNB (encapped)
219 main.step("Test downstream BESS -> fabric -> eNB")
220 pkt_filter_downstream = "ip and udp src port %d and udp dst port %d and src host %s and dst host %s" % (
221 GPDU_PORT, GPDU_PORT, bess_s1u_address, up4.enb_address)
222 main.log.info("Start listening on %s intf %s" % (
223 enodeb_host.name, enodeb_interface["name"]))
224 main.log.debug(
225 "BPF Filter BESS Downstream: \n %s" % pkt_filter_downstream)
226 enodeb_host.startFilter(ifaceName=enodeb_interface["name"],
227 sniffCount=1,
228 pktFilter=pkt_filter_downstream)
229 # Build GTP packet from BESS host
230 UP4.buildGtpPacket(bess_host,
231 src_ip_outer=bess_s1u_address,
232 dst_ip_outer=up4.enb_address,
233 src_ip_inner=pdn_interface["ips"][0],
234 dst_ip_inner=BESS_UE_ADDR,
235 src_udp_inner=PDN_PORT,
236 dst_udp_inner=UE_PORT,
237 teid=BESS_TEID)
238 bess_host.sendPacket()
239
240 packets = UP4.checkFilterAndGetPackets(enodeb_host)
241
242 # FIXME: with newer scapy TEID becomes teid (required for Scapy 2.4.5)
243 n_packets = packets.count("TEID=" + hex(BESS_TEID) + "L ")
244 tot_packets = packets.count('Ether')
245 utilities.assert_equal(expect=True,
246 actual=n_packets == 1 and tot_packets == 1,
247 onpass="eNodeB correctly received 1 GTP encapped packet",
248 onfail="ERROR: eNodeb received %d GTP encapped packets and filter captured %d packets" % (
249 n_packets, tot_packets))
250 # ------------------------------------------------
251
Daniele Moro93feb022021-10-04 16:26:23 +0200252 main.step("Remove and Verify PDRs and FARs for UEs via UP4")
Daniele Morobf53dec2021-09-13 18:11:56 +0200253 up4.detachUes()
Daniele Morobf53dec2021-09-13 18:11:56 +0200254 up4.verifyNoUesFlow(onos_cli)
255
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200256 run.checkFlows(main, minFlowCount=initial_flow_count)
257
Daniele Morobf53dec2021-09-13 18:11:56 +0200258 main.step("Stop scapy and p4rt client")
259 up4.teardown()
260 bess_host.stopScapy()
Daniele Moroc99bf822021-10-11 23:21:15 +0200261
262 run.saveOnosDiagsIfFailure(main)
Daniele Morobf53dec2021-09-13 18:11:56 +0200263 run.cleanup(main)
Daniele Moro954e2282021-09-22 17:32:03 +0200264
265 def CASE3(self, main):
266 main.case("Verify UP4 from different ONOS instances")
267 """
268 Program PDRs and FARs via UP4 on first ONOS instance
269 Repeat for all ONOS Instances:
270 Verify PDRs and FARs via P4RT
271 Disconnect P4RT client
272 Verify and delete PDRs and FARs via UP4 on the third ONOS instance
273 Repeat for all ONOS Instance:
274 Verify removed PDRs and FARs via P4RT
275 Disconnect P4RT client
276 """
277 try:
278 from tests.USECASE.SegmentRouting.dependencies.up4 import UP4
279 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import \
280 Testcaselib as run
281 except ImportError as e:
282 main.log.error("Import not found. Exiting the test")
283 main.log.error(e)
284 main.cleanAndExit()
285
286 run.initTest(main)
287 main.log.info(main.Cluster.numCtrls)
288 main.Cluster.setRunningNode(3)
289 run.installOnos(main, skipPackage=True, cliSleep=5)
290
291 onos_cli_0 = main.Cluster.active(0).CLI
292 onos_cli_1 = main.Cluster.active(1).CLI
293 onos_cli_2 = main.Cluster.active(2).CLI
294 up4_0 = UP4()
295 up4_1 = UP4()
296 up4_2 = UP4()
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200297 initial_flow_count = onos_cli_0.checkFlowCount()
Daniele Moro954e2282021-09-22 17:32:03 +0200298
Daniele Moro93feb022021-10-04 16:26:23 +0200299 main.step("Program and Verify PDRs and FARs via UP4 on ONOS 0")
Daniele Moro954e2282021-09-22 17:32:03 +0200300 up4_0.setup(main.Cluster.active(0).p4rtUp4, no_host=True)
301 up4_0.attachUes()
302 up4_0.verifyUp4Flow(onos_cli_0)
303 up4_0.teardown()
304
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200305 run.checkFlows(
306 main,
307 minFlowCount=initial_flow_count+(len(up4_0.emulated_ues)*2)
308 )
309
Daniele Moro954e2282021-09-22 17:32:03 +0200310 main.step("Verify PDRs and FARs number via UP4 P4RT on ONOS 1")
311 up4_1.setup(main.Cluster.active(1).p4rtUp4, no_host=True)
312 utilities.assert_equal(
313 expect=True,
314 actual=up4_1.verifyUesFlowNumberP4rt(),
315 onpass="Correct number of PDRs and FARs",
316 onfail="Wrong number of PDRs and FARs"
317 )
318 up4_1.teardown()
319
320 main.step("Verify PDRs and FARs number via UP4 P4RT on ONOS 2")
321 up4_2.setup(main.Cluster.active(2).p4rtUp4, no_host=True)
322 utilities.assert_equal(
323 expect=True,
324 actual=up4_2.verifyUesFlowNumberP4rt(),
325 onpass="Correct number of PDRs and FARs",
326 onfail="Wrong number of PDRs and FARs"
327 )
328
329 main.step("Verify all ONOS instances have the same number of flows")
330 onos_0_flow_count = onos_cli_0.checkFlowCount()
331 onos_1_flow_count = onos_cli_1.checkFlowCount()
332 onos_2_flow_count = onos_cli_2.checkFlowCount()
333 utilities.assert_equal(
334 expect=True,
335 actual=onos_0_flow_count == onos_1_flow_count == onos_2_flow_count,
336 onpass="All ONOS instances have the same number of flows",
337 onfail="ONOS instances have different number of flows: (%d, %d, %d)" % (
338 onos_0_flow_count, onos_1_flow_count, onos_2_flow_count)
339 )
340
Daniele Moro93feb022021-10-04 16:26:23 +0200341 main.step("Remove and Verify PDRs and FARs via UP4 on ONOS 2")
Daniele Moro954e2282021-09-22 17:32:03 +0200342 up4_2.detachUes()
343 up4_2.verifyNoUesFlow(onos_cli_2)
344
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200345 run.checkFlows(main, minFlowCount=initial_flow_count)
346
Daniele Moro954e2282021-09-22 17:32:03 +0200347 main.step("Verify no PDRs and FARs via UP4 P4RT on ONOS 2")
348 utilities.assert_equal(
349 expect=True,
350 actual=up4_2.verifyNoUesFlowNumberP4rt(),
351 onpass="No PDRs and FARs",
352 onfail="Stale PDRs and FARs"
353 )
354 up4_2.teardown()
355
356 main.step("Verify no PDRs and FARs via UP4 P4RT on ONOS 1")
357 up4_1.setup(main.Cluster.active(1).p4rtUp4, no_host=True)
358 utilities.assert_equal(
359 expect=True,
360 actual=up4_1.verifyNoUesFlowNumberP4rt(),
361 onpass="No PDRs and FARs",
362 onfail="Stale PDRs and FARs"
363 )
364 up4_1.teardown()
365
366 main.step("Verify no PDRs and FARs via UP4 P4RT on ONOS 0")
367 up4_0.setup(main.Cluster.active(0).p4rtUp4, no_host=True)
368 utilities.assert_equal(
369 expect=True,
370 actual=up4_0.verifyNoUesFlowNumberP4rt(),
371 onpass="No PDRs and FARs",
372 onfail="Stale PDRs and FARs"
373 )
374 up4_0.teardown()
375
376 main.step("Verify all ONOS instances have the same number of flows")
377 onos_0_flow_count = onos_cli_0.checkFlowCount()
378 onos_1_flow_count = onos_cli_1.checkFlowCount()
379 onos_2_flow_count = onos_cli_2.checkFlowCount()
380 utilities.assert_equal(
381 expect=True,
382 actual=onos_0_flow_count == onos_1_flow_count == onos_2_flow_count,
383 onpass="All ONOS instances have the same number of flows",
384 onfail="ONOS instances have different number of flows: (%d, %d, %d)" % (
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200385 onos_0_flow_count, onos_1_flow_count, onos_2_flow_count)
Daniele Moro954e2282021-09-22 17:32:03 +0200386 )
Daniele Moroc99bf822021-10-11 23:21:15 +0200387
388 run.saveOnosDiagsIfFailure(main)
Daniele Moro954e2282021-09-22 17:32:03 +0200389 run.cleanup(main)
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200390
391 def CASE4(self, main):
392 main.case("Verify UP4 wipe-out after ONOS reboot")
393 """
394 Program PDRs/FARs
395 Kill ONOS POD
396 Verify PDRs/FARs from other ONOS instances
397 Remove PDRs/FARs
398 Wait/Verify ONOS is back
399 Verify no PDRs/FARs from rebooted instance
400 Re-program PDRs/FARs from rebooted instance
401 Verify all instances have same number of flows
402 Remove PDRs/FARs (cleanup)
403 """
404 try:
405 from tests.USECASE.SegmentRouting.dependencies.up4 import UP4
406 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import \
407 Testcaselib as run
408 except ImportError as e:
409 main.log.error("Import not found. Exiting the test")
410 main.log.error(e)
411 main.cleanAndExit()
412
413 run.initTest(main)
414 main.log.info(main.Cluster.numCtrls)
415 main.Cluster.setRunningNode(3)
416 run.installOnos(main, skipPackage=True, cliSleep=5)
417
418 onos_cli_0 = main.Cluster.active(0).CLI
419 onos_cli_1 = main.Cluster.active(1).CLI
420 onos_cli_2 = main.Cluster.active(2).CLI
421 kubectl_0 = main.Cluster.active(0).k8s
422
423 up4_0 = UP4()
424 up4_1 = UP4()
425 up4_2 = UP4()
426
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200427 initial_flow_count = onos_cli_0.checkFlowCount()
428
Daniele Moro93feb022021-10-04 16:26:23 +0200429 main.step("Program and Verify PDRs and FARs via UP4 on ONOS 0")
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200430 up4_0.setup(main.Cluster.active(0).p4rtUp4, no_host=True)
431 up4_0.attachUes()
432 up4_0.verifyUp4Flow(onos_cli_0)
433 up4_0.teardown()
434
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200435 run.checkFlows(
436 main,
437 minFlowCount=initial_flow_count+(len(up4_0.emulated_ues)*2)
438 )
439
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200440 onosPod = main.params["UP4_delete_pod"]
Daniele Moroc99bf822021-10-11 23:21:15 +0200441
442 # Save ONOS diags of the POD we are killing otherwise we lose ONOS logs
443 main.ONOSbench.onosDiagnosticsK8s(
444 [onosPod],
445 main.logdir,
446 "-CASE%d-%s_BeforeKill" % (main.CurrentTestCaseNumber, onosPod)
447 )
448
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200449 # Exit from previous port forwarding, because we need to restore
450 # port-forwarding after ONOS reboot.
451 kubectl_0.clearBuffer()
452 kubectl_0.exitFromProcess()
453 main.step("Kill " + onosPod)
454 utilities.assert_equal(
455 expect=main.TRUE,
456 actual=kubectl_0.kubectlDeletePod(
457 podName=onosPod,
458 kubeconfig=kubectl_0.kubeConfig,
459 namespace=main.params['kubernetes']['namespace']
460 ),
461 onpass="%s pod correctly deleted" % onosPod,
462 onfail="%s pod has not been deleted" % onosPod
463 )
464
465 main.step("Verify PDRs and FARs number via UP4 P4RT on ONOS 2")
466 up4_2.setup(main.Cluster.active(2).p4rtUp4, no_host=True)
467 utilities.assert_equal(
468 expect=True,
469 actual=up4_2.verifyUesFlowNumberP4rt(),
470 onpass="Correct number of PDRs and FARs",
471 onfail="Wrong number of PDRs and FARs"
472 )
473
Daniele Moro93feb022021-10-04 16:26:23 +0200474 main.step("Remove and Verify PDRs and FARs via UP4 on ONOS 2")
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200475 up4_2.detachUes()
476 up4_2.verifyNoUesFlow(onos_cli_2)
477
478 main.step("Verify no PDRs and FARs via UP4 P4RT on ONOS 2")
479 utilities.assert_equal(
480 expect=True,
481 actual=up4_2.verifyNoUesFlowNumberP4rt(),
482 onpass="No PDRs and FARs",
483 onfail="Stale PDRs and FARs"
484 )
485 up4_2.teardown()
486
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200487 main.step("Verify all active ONOS instances have the same number of flows")
488 onos_1_flow_count = onos_cli_1.checkFlowCount()
489 onos_2_flow_count = onos_cli_2.checkFlowCount()
490 utilities.assert_equal(
491 expect=True,
492 actual=onos_1_flow_count == onos_2_flow_count,
493 onpass="All ONOS instances have the same number of flows",
494 onfail="ONOS instances have different number of flows: (%d, %d)" % (
495 onos_1_flow_count, onos_2_flow_count)
496 )
497
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200498 main.step("Verify ONOS 0 has restarted correctly")
499 onosStarted = utilities.retry(
500 f=kubectl_0.kubectlCheckPodReady,
501 retValue=main.FALSE,
502 kwargs={
503 "podName": onosPod,
504 "kubeconfig": kubectl_0.kubeConfig,
505 "namespace": main.params['kubernetes']['namespace']
506 },
507 sleep=10,
508 attempts=10
509 )
510 utilities.assert_equal(
511 expect=main.TRUE,
512 actual=onosStarted,
513 onpass="%s pod correctly restarted" % onosPod,
514 onfail="%s pod haven't restarted correctly" % onosPod
515 )
516
517 main.step("Verify ONOS cluster is in good shape")
518 # A bug in kubectl port forwarding doesn't terminate port-forwarding
519 # when the container changed, nor reconnect correctly to the restarted
520 # container.
521 # See: https://github.com/kubernetes/kubectl/issues/686
522 # Re-build the port-list for port forwarding
523 portList = "%s:%s " % (main.Cluster.active(0).CLI.karafPort, 8101)
524 portList += "%s:%s " % (main.Cluster.active(0).REST.port, 8181)
525 portList += "%s:%s " % (main.Cluster.active(0).p4rtUp4.p4rtPort,
526 main.ONOScell.up4Port)
527 kubectl_0.clearBuffer()
528 kubectl_0.kubectlPortForward(
529 onosPod,
530 portList,
531 kubectl_0.kubeConfig,
532 main.params['kubernetes']['namespace']
533 )
534 onos_cli_0.clearBuffer() # Trigger ONOS CLI reconnection
535 onosNodesStatus = utilities.retry(
536 f=main.Cluster.nodesCheck,
537 retValue=False,
538 sleep=5,
539 attempts=10
540 )
541 utilities.assert_equal(
542 expect=True,
543 actual=onosNodesStatus,
544 onpass="ONOS nodes status correct",
545 onfail="Wrong ONOS nodes status"
546 )
547
548 main.step("Verify no PDRs and FARs via UP4 P4RT on ONOS 0")
549 up4_0.setup(main.Cluster.active(0).p4rtUp4, no_host=True)
550 utilities.assert_equal(
551 expect=True,
552 actual=up4_0.verifyNoUesFlowNumberP4rt(),
553 onpass="No PDRs and FARs",
554 onfail="Stale PDRs and FARs"
555 )
556
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200557 run.checkFlows(main, minFlowCount=initial_flow_count)
558
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200559 main.step("Re-program PDRs and FARs via UP4 on ONOS 0 after restart")
560 up4_0.attachUes()
561 up4_0.verifyUp4Flow(onos_cli_0)
562 up4_0.teardown()
563
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200564 run.checkFlows(
565 main,
566 minFlowCount=initial_flow_count+(len(up4_0.emulated_ues)*2)
567 )
568
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200569 main.step("Verify PDRs and FARs via UP4 on ONOS 1")
570 up4_1.setup(main.Cluster.active(1).p4rtUp4, no_host=True)
571 up4_1.verifyUp4Flow(onos_cli_1)
572
573 main.step("Verify all ONOS instances have the same number of flows")
574 onos_0_flow_count = onos_cli_0.checkFlowCount()
575 onos_1_flow_count = onos_cli_1.checkFlowCount()
576 onos_2_flow_count = onos_cli_2.checkFlowCount()
577 utilities.assert_equal(
578 expect=True,
579 actual=onos_0_flow_count == onos_1_flow_count == onos_2_flow_count,
580 onpass="All ONOS instances have the same number of flows",
581 onfail="ONOS instances have different number of flows: (%d, %d, %d)" % (
582 onos_0_flow_count, onos_1_flow_count, onos_2_flow_count)
583 )
584
585 main.step("Cleanup PDRs and FARs via UP4 on ONOS 1")
586 up4_1.detachUes()
Daniele Moro6dfbfef2021-09-28 22:44:19 +0200587 up4_1.verifyNoUesFlow(onos_cli_1)
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200588 up4_1.teardown()
589
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200590 run.checkFlows(main, minFlowCount=initial_flow_count)
591
Daniele Moroc99bf822021-10-11 23:21:15 +0200592 run.saveOnosDiagsIfFailure(main)
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200593 run.cleanup(main)