blob: 99fbf4cc3e785d48c5d0ccff59cdc73809b099f1 [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 Moroc6811a82021-10-12 11:29:41 +020019 from tests.USECASE.SegmentRouting.dependencies.up4 import UP4, \
20 N_FLOWS_PER_UE
Daniele Moro790cc102021-08-30 18:27:30 +020021 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import \
22 Testcaselib as run
Daniele Moro790cc102021-08-30 18:27:30 +020023 except ImportError as e:
24 main.log.error("Import not found. Exiting the test")
25 main.log.error(e)
26 main.cleanAndExit()
Daniele Moroc6811a82021-10-12 11:29:41 +020027 n_switches = int(main.params["TOPO"]["switchNum"])
Daniele Moro790cc102021-08-30 18:27:30 +020028
Daniele Moro790cc102021-08-30 18:27:30 +020029 run.initTest(main)
30 main.log.info(main.Cluster.numCtrls)
31 main.Cluster.setRunningNode(3)
32 run.installOnos(main, skipPackage=True, cliSleep=5)
33
Daniele Moro790cc102021-08-30 18:27:30 +020034 main.step("Start scapy and p4rt client")
Daniele Morobf53dec2021-09-13 18:11:56 +020035 # Use the first available ONOS instance CLI
36 onos_cli = main.Cluster.active(0).CLI
Daniele Moro9ba5cf02021-10-08 18:00:56 +020037 initial_flow_count = onos_cli.checkFlowCount()
Daniele Moro80889562021-09-08 10:09:26 +020038 up4 = UP4()
39 # Get the P4RT client connected to UP4 in the first available ONOS instance
40 up4.setup(main.Cluster.active(0).p4rtUp4)
Daniele Moro790cc102021-08-30 18:27:30 +020041
Daniele Moro93feb022021-10-04 16:26:23 +020042 main.step("Program and Verify PDRs and FARs via UP4")
Daniele Moro80889562021-09-08 10:09:26 +020043 up4.attachUes()
Daniele Morobf53dec2021-09-13 18:11:56 +020044 up4.verifyUp4Flow(onos_cli)
45
Daniele Moro9ba5cf02021-10-08 18:00:56 +020046 run.checkFlows(
47 main,
Daniele Moroc6811a82021-10-12 11:29:41 +020048 minFlowCount=initial_flow_count + (
49 len(up4.emulated_ues) * N_FLOWS_PER_UE * n_switches)
Daniele Moro9ba5cf02021-10-08 18:00:56 +020050 )
51
Daniele Moro80889562021-09-08 10:09:26 +020052 # ------- Test Upstream traffic (enb->pdn)
Daniele Moro790cc102021-08-30 18:27:30 +020053 main.step("Test upstream traffic")
Daniele Moro80889562021-09-08 10:09:26 +020054 up4.testUpstreamTraffic()
Daniele Moro790cc102021-08-30 18:27:30 +020055
Daniele Moro80889562021-09-08 10:09:26 +020056 # ------- Test Downstream traffic (pdn->enb)
Daniele Moro790cc102021-08-30 18:27:30 +020057 main.step("Test downstream traffic")
Daniele Moro80889562021-09-08 10:09:26 +020058 up4.testDownstreamTraffic()
Daniele Moro790cc102021-08-30 18:27:30 +020059
Daniele Moro93feb022021-10-04 16:26:23 +020060 main.step("Remove and Verify PDRs and FARs via UP4")
Daniele Moro80889562021-09-08 10:09:26 +020061 up4.detachUes()
Daniele Morobf53dec2021-09-13 18:11:56 +020062 up4.verifyNoUesFlow(onos_cli)
63
Daniele Moro9ba5cf02021-10-08 18:00:56 +020064 run.checkFlows(main, minFlowCount=initial_flow_count)
65
Daniele Moro790cc102021-08-30 18:27:30 +020066 main.step("Stop scapy and p4rt client")
Daniele Moro80889562021-09-08 10:09:26 +020067 up4.teardown()
Daniele Moroc99bf822021-10-11 23:21:15 +020068
69 run.saveOnosDiagsIfFailure(main)
Daniele Moro790cc102021-08-30 18:27:30 +020070 run.cleanup(main)
Daniele Morobf53dec2021-09-13 18:11:56 +020071
Daniele Moro9ba5cf02021-10-08 18:00:56 +020072 def CASE2(self, main):
Daniele Morobf53dec2021-09-13 18:11:56 +020073 main.case("BESS traffic routed")
74 """
75 Program PDRs and FARs for UEs managed via UP4
76 Verify PDRs and FARs
77 Verify Upstream Traffic: eNB -> Fabric -> BESS (encapped)
78 Verify Upstream Traffic: BESS -> Fabric -> PDN (not encapped)
79 Verify Downstream Traffic: PDN -> Fabric -> BESS (not encapped)
80 Verify Downstream Traffic: BESS -> Fabric -> eNB (encapped)
81 Remove PDRs and FARs for UEs managed via UP4
82 Verify removed PDRs and FARs
83 """
84 BESS_TEID = 300
85 BESS_UE_ADDR = "10.241.0.1"
86 GPDU_PORT = 2152
87 UE_PORT = 400
88 PDN_PORT = 800
89 try:
Daniele Moroc6811a82021-10-12 11:29:41 +020090 from tests.USECASE.SegmentRouting.dependencies.up4 import UP4, \
91 N_FLOWS_PER_UE
Daniele Morobf53dec2021-09-13 18:11:56 +020092 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import \
93 Testcaselib as run
94 except ImportError as e:
95 main.log.error("Import not found. Exiting the test")
96 main.log.error(e)
97 main.cleanAndExit()
Daniele Moroc6811a82021-10-12 11:29:41 +020098 n_switches = int(main.params["TOPO"]["switchNum"])
Daniele Morobf53dec2021-09-13 18:11:56 +020099
100 run.initTest(main)
101 main.log.info(main.Cluster.numCtrls)
102 main.Cluster.setRunningNode(3)
103 run.installOnos(main, skipPackage=True, cliSleep=5)
104
105 main.step("Start scapy and p4rt client + Scapy on BESS Host")
106 # Use the first available ONOS instance CLI
107 onos_cli = main.Cluster.active(0).CLI
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200108 initial_flow_count = onos_cli.checkFlowCount()
Daniele Morobf53dec2021-09-13 18:11:56 +0200109 up4 = UP4()
110 # Get the P4RT client connected to UP4 in the first available ONOS instance
111 up4.setup(main.Cluster.active(0).p4rtUp4)
112
113 # Setup the emulated BESS host and required parameters
114 bess_host = main.Compute2 # FIXME: Parametrize?
115 bess_interface = bess_host.interfaces[0]
116 bess_s1u_address = bess_interface["ips"][0]
117 bess_host.startScapy(ifaceName=bess_interface["name"], enableGtp=True)
118 enodeb_host = up4.enodeb_host
119 enodeb_interface = up4.enodeb_interface
120 pdn_host = up4.pdn_host
121 pdn_interface = up4.pdn_interface
122
Daniele Moro93feb022021-10-04 16:26:23 +0200123 main.step("Program and Verify PDRs and FARs for UEs via UP4")
Daniele Morobf53dec2021-09-13 18:11:56 +0200124 up4.attachUes()
Daniele Morobf53dec2021-09-13 18:11:56 +0200125 up4.verifyUp4Flow(onos_cli)
126
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200127 run.checkFlows(
128 main,
Daniele Moroc6811a82021-10-12 11:29:41 +0200129 minFlowCount=initial_flow_count + (
130 len(up4.emulated_ues) * N_FLOWS_PER_UE * n_switches)
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200131 )
132
Daniele Morobf53dec2021-09-13 18:11:56 +0200133 # ------------------- UPSTREAM -------------------
134 # ------- eNB -> fabric -> BESS (encapped)
135 main.step("Test upstream eNB -> fabric -> BESS")
136 # Start filter before sending packets, BESS should receive GTP encapped
137 # packets
138 pkt_filter_upstream = "ip and udp src port %d and udp dst port %d and src host %s and dst host %s" % (
139 GPDU_PORT, GPDU_PORT, up4.enb_address, bess_s1u_address)
140 main.log.info("Start listening on %s intf %s" % (
141 bess_host.name, bess_interface["name"]))
142 main.log.debug("BPF Filter BESS Upstream: \n %s" % pkt_filter_upstream)
143 bess_host.startFilter(ifaceName=bess_interface["name"],
144 sniffCount=1,
145 pktFilter=pkt_filter_upstream)
146 # Send GTP Packet
147 UP4.buildGtpPacket(enodeb_host,
148 src_ip_outer=up4.enb_address,
149 dst_ip_outer=bess_s1u_address,
150 src_ip_inner=BESS_UE_ADDR,
151 dst_ip_inner=pdn_interface["ips"][0],
152 src_udp_inner=UE_PORT,
153 dst_udp_inner=PDN_PORT,
154 teid=BESS_TEID)
155 enodeb_host.sendPacket()
156
157 packets = UP4.checkFilterAndGetPackets(bess_host)
158 # FIXME: with newer scapy TEID becomes teid (required for Scapy 2.4.5)
159 n_packets = packets.count("TEID=" + hex(BESS_TEID) + "L ")
160 tot_packets = packets.count('Ether')
161 utilities.assert_equal(expect=True,
162 actual=n_packets == 1 and tot_packets == 1,
163 onpass="BESS correctly received 1 GTP encapped packet",
164 onfail="ERROR: BESS received %d GTP encapped packets and filter captured %d packets" % (
165 n_packets, tot_packets))
166
167 # ------- BESS -> fabric -> PDN (not-encapped)
168 main.step("Test upstream BESS -> fabric -> PDN")
169 # Start filter before sending packets, PDN should receive non-GTP packet
170 pkt_filter_upstream = "ip and udp src port %d and udp dst port %d and src host %s and dst host %s" % (
171 UE_PORT, PDN_PORT, BESS_UE_ADDR, pdn_interface["ips"][0])
172 main.log.info("Start listening on %s intf %s" % (
173 pdn_host.name, pdn_interface["name"]))
174 main.log.debug("BPF Filter PDN Upstream: \n %s" % pkt_filter_upstream)
175 pdn_host.startFilter(ifaceName=pdn_interface["name"],
176 sniffCount=1,
177 pktFilter=pkt_filter_upstream)
178 # Send UDP Packet
179 UP4.buildUdpPacket(bess_host,
180 src_ip=BESS_UE_ADDR,
181 dst_ip=pdn_interface["ips"][0],
182 src_udp=UE_PORT,
183 dst_udp=PDN_PORT)
184 bess_host.sendPacket()
185
186 packets = UP4.checkFilterAndGetPackets(pdn_host)
187 tot_packets = packets.count('Ether')
188 utilities.assert_equal(expect=True,
189 actual=tot_packets == 1,
190 onpass="PDN correctly received 1 packet",
191 onfail="ERROR: PDN received %d packets" % (
192 tot_packets))
193 # ------------------------------------------------
194
195 # ------------------ DOWNSTREAM ------------------
196 # ------- PDN -> fabric -> BESS (not-encapped)
197 main.step("Test downstream PDN -> fabric -> BESS")
198 pkt_filter_downstream = "ip and udp src port %d and udp dst port %d and src host %s and dst host %s" % (
199 PDN_PORT, UE_PORT, pdn_interface["ips"][0], BESS_UE_ADDR)
200 main.log.info("Start listening on %s intf %s" % (
201 bess_host.name, bess_interface["name"]))
202 main.log.debug(
203 "BPF Filter BESS Downstream: \n %s" % pkt_filter_downstream)
204 bess_host.startFilter(ifaceName=bess_interface["name"],
205 sniffCount=1,
206 pktFilter=pkt_filter_downstream)
207 UP4.buildUdpPacket(pdn_host,
208 dst_eth=up4.router_mac,
209 src_ip=pdn_interface["ips"][0],
210 dst_ip=BESS_UE_ADDR,
211 src_udp=PDN_PORT,
212 dst_udp=UE_PORT)
213 pdn_host.sendPacket()
214
215 packets = UP4.checkFilterAndGetPackets(bess_host)
216
217 tot_packets = packets.count('Ether')
218 utilities.assert_equal(expect=True,
219 actual=tot_packets == 1,
220 onpass="BESS correctly received 1 packet",
221 onfail="ERROR: BESS received %d packets" % (
222 tot_packets))
223
224 # ------- BESS -> fabric -> eNB (encapped)
225 main.step("Test downstream BESS -> fabric -> eNB")
226 pkt_filter_downstream = "ip and udp src port %d and udp dst port %d and src host %s and dst host %s" % (
227 GPDU_PORT, GPDU_PORT, bess_s1u_address, up4.enb_address)
228 main.log.info("Start listening on %s intf %s" % (
229 enodeb_host.name, enodeb_interface["name"]))
230 main.log.debug(
231 "BPF Filter BESS Downstream: \n %s" % pkt_filter_downstream)
232 enodeb_host.startFilter(ifaceName=enodeb_interface["name"],
233 sniffCount=1,
234 pktFilter=pkt_filter_downstream)
235 # Build GTP packet from BESS host
236 UP4.buildGtpPacket(bess_host,
237 src_ip_outer=bess_s1u_address,
238 dst_ip_outer=up4.enb_address,
239 src_ip_inner=pdn_interface["ips"][0],
240 dst_ip_inner=BESS_UE_ADDR,
241 src_udp_inner=PDN_PORT,
242 dst_udp_inner=UE_PORT,
243 teid=BESS_TEID)
244 bess_host.sendPacket()
245
246 packets = UP4.checkFilterAndGetPackets(enodeb_host)
247
248 # FIXME: with newer scapy TEID becomes teid (required for Scapy 2.4.5)
249 n_packets = packets.count("TEID=" + hex(BESS_TEID) + "L ")
250 tot_packets = packets.count('Ether')
251 utilities.assert_equal(expect=True,
252 actual=n_packets == 1 and tot_packets == 1,
253 onpass="eNodeB correctly received 1 GTP encapped packet",
254 onfail="ERROR: eNodeb received %d GTP encapped packets and filter captured %d packets" % (
255 n_packets, tot_packets))
256 # ------------------------------------------------
257
Daniele Moro93feb022021-10-04 16:26:23 +0200258 main.step("Remove and Verify PDRs and FARs for UEs via UP4")
Daniele Morobf53dec2021-09-13 18:11:56 +0200259 up4.detachUes()
Daniele Morobf53dec2021-09-13 18:11:56 +0200260 up4.verifyNoUesFlow(onos_cli)
261
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200262 run.checkFlows(main, minFlowCount=initial_flow_count)
263
Daniele Morobf53dec2021-09-13 18:11:56 +0200264 main.step("Stop scapy and p4rt client")
265 up4.teardown()
266 bess_host.stopScapy()
Daniele Moroc99bf822021-10-11 23:21:15 +0200267
268 run.saveOnosDiagsIfFailure(main)
Daniele Morobf53dec2021-09-13 18:11:56 +0200269 run.cleanup(main)
Daniele Moro954e2282021-09-22 17:32:03 +0200270
271 def CASE3(self, main):
272 main.case("Verify UP4 from different ONOS instances")
273 """
274 Program PDRs and FARs via UP4 on first ONOS instance
275 Repeat for all ONOS Instances:
276 Verify PDRs and FARs via P4RT
277 Disconnect P4RT client
278 Verify and delete PDRs and FARs via UP4 on the third ONOS instance
279 Repeat for all ONOS Instance:
280 Verify removed PDRs and FARs via P4RT
281 Disconnect P4RT client
282 """
283 try:
Daniele Morofbfdfbd2021-10-18 22:47:51 +0200284 from tests.USECASE.SegmentRouting.dependencies.up4 import UP4, \
285 N_FLOWS_PER_UE
Daniele Moro954e2282021-09-22 17:32:03 +0200286 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import \
287 Testcaselib as run
288 except ImportError as e:
289 main.log.error("Import not found. Exiting the test")
290 main.log.error(e)
291 main.cleanAndExit()
Daniele Moroc6811a82021-10-12 11:29:41 +0200292 n_switches = int(main.params["TOPO"]["switchNum"])
Daniele Moro954e2282021-09-22 17:32:03 +0200293
294 run.initTest(main)
295 main.log.info(main.Cluster.numCtrls)
296 main.Cluster.setRunningNode(3)
297 run.installOnos(main, skipPackage=True, cliSleep=5)
298
299 onos_cli_0 = main.Cluster.active(0).CLI
300 onos_cli_1 = main.Cluster.active(1).CLI
301 onos_cli_2 = main.Cluster.active(2).CLI
302 up4_0 = UP4()
303 up4_1 = UP4()
304 up4_2 = UP4()
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200305 initial_flow_count = onos_cli_0.checkFlowCount()
Daniele Moro954e2282021-09-22 17:32:03 +0200306
Daniele Moro93feb022021-10-04 16:26:23 +0200307 main.step("Program and Verify PDRs and FARs via UP4 on ONOS 0")
Daniele Moro954e2282021-09-22 17:32:03 +0200308 up4_0.setup(main.Cluster.active(0).p4rtUp4, no_host=True)
309 up4_0.attachUes()
310 up4_0.verifyUp4Flow(onos_cli_0)
311 up4_0.teardown()
312
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200313 run.checkFlows(
314 main,
Daniele Moroc6811a82021-10-12 11:29:41 +0200315 minFlowCount=initial_flow_count + (
316 len(up4_0.emulated_ues) * N_FLOWS_PER_UE * n_switches)
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200317 )
318
Daniele Moro954e2282021-09-22 17:32:03 +0200319 main.step("Verify PDRs and FARs number via UP4 P4RT on ONOS 1")
320 up4_1.setup(main.Cluster.active(1).p4rtUp4, no_host=True)
321 utilities.assert_equal(
322 expect=True,
323 actual=up4_1.verifyUesFlowNumberP4rt(),
324 onpass="Correct number of PDRs and FARs",
325 onfail="Wrong number of PDRs and FARs"
326 )
327 up4_1.teardown()
328
329 main.step("Verify PDRs and FARs number via UP4 P4RT on ONOS 2")
330 up4_2.setup(main.Cluster.active(2).p4rtUp4, no_host=True)
331 utilities.assert_equal(
332 expect=True,
333 actual=up4_2.verifyUesFlowNumberP4rt(),
334 onpass="Correct number of PDRs and FARs",
335 onfail="Wrong number of PDRs and FARs"
336 )
337
338 main.step("Verify all ONOS instances have the same number of flows")
339 onos_0_flow_count = onos_cli_0.checkFlowCount()
340 onos_1_flow_count = onos_cli_1.checkFlowCount()
341 onos_2_flow_count = onos_cli_2.checkFlowCount()
342 utilities.assert_equal(
343 expect=True,
344 actual=onos_0_flow_count == onos_1_flow_count == onos_2_flow_count,
345 onpass="All ONOS instances have the same number of flows",
346 onfail="ONOS instances have different number of flows: (%d, %d, %d)" % (
347 onos_0_flow_count, onos_1_flow_count, onos_2_flow_count)
348 )
349
Daniele Moro93feb022021-10-04 16:26:23 +0200350 main.step("Remove and Verify PDRs and FARs via UP4 on ONOS 2")
Daniele Moro954e2282021-09-22 17:32:03 +0200351 up4_2.detachUes()
352 up4_2.verifyNoUesFlow(onos_cli_2)
353
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200354 run.checkFlows(main, minFlowCount=initial_flow_count)
355
Daniele Moro954e2282021-09-22 17:32:03 +0200356 main.step("Verify no PDRs and FARs via UP4 P4RT on ONOS 2")
357 utilities.assert_equal(
358 expect=True,
359 actual=up4_2.verifyNoUesFlowNumberP4rt(),
360 onpass="No PDRs and FARs",
361 onfail="Stale PDRs and FARs"
362 )
363 up4_2.teardown()
364
365 main.step("Verify no PDRs and FARs via UP4 P4RT on ONOS 1")
366 up4_1.setup(main.Cluster.active(1).p4rtUp4, no_host=True)
367 utilities.assert_equal(
368 expect=True,
369 actual=up4_1.verifyNoUesFlowNumberP4rt(),
370 onpass="No PDRs and FARs",
371 onfail="Stale PDRs and FARs"
372 )
373 up4_1.teardown()
374
375 main.step("Verify no PDRs and FARs via UP4 P4RT on ONOS 0")
376 up4_0.setup(main.Cluster.active(0).p4rtUp4, no_host=True)
377 utilities.assert_equal(
378 expect=True,
379 actual=up4_0.verifyNoUesFlowNumberP4rt(),
380 onpass="No PDRs and FARs",
381 onfail="Stale PDRs and FARs"
382 )
383 up4_0.teardown()
384
385 main.step("Verify all ONOS instances have the same number of flows")
386 onos_0_flow_count = onos_cli_0.checkFlowCount()
387 onos_1_flow_count = onos_cli_1.checkFlowCount()
388 onos_2_flow_count = onos_cli_2.checkFlowCount()
389 utilities.assert_equal(
390 expect=True,
391 actual=onos_0_flow_count == onos_1_flow_count == onos_2_flow_count,
392 onpass="All ONOS instances have the same number of flows",
393 onfail="ONOS instances have different number of flows: (%d, %d, %d)" % (
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200394 onos_0_flow_count, onos_1_flow_count, onos_2_flow_count)
Daniele Moro954e2282021-09-22 17:32:03 +0200395 )
Daniele Moroc99bf822021-10-11 23:21:15 +0200396
397 run.saveOnosDiagsIfFailure(main)
Daniele Moro954e2282021-09-22 17:32:03 +0200398 run.cleanup(main)
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200399
400 def CASE4(self, main):
401 main.case("Verify UP4 wipe-out after ONOS reboot")
402 """
403 Program PDRs/FARs
404 Kill ONOS POD
405 Verify PDRs/FARs from other ONOS instances
406 Remove PDRs/FARs
407 Wait/Verify ONOS is back
408 Verify no PDRs/FARs from rebooted instance
409 Re-program PDRs/FARs from rebooted instance
410 Verify all instances have same number of flows
411 Remove PDRs/FARs (cleanup)
412 """
413 try:
Daniele Moroc6811a82021-10-12 11:29:41 +0200414 from tests.USECASE.SegmentRouting.dependencies.up4 import UP4, \
415 N_FLOWS_PER_UE
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200416 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import \
417 Testcaselib as run
418 except ImportError as e:
419 main.log.error("Import not found. Exiting the test")
420 main.log.error(e)
421 main.cleanAndExit()
Daniele Moroc6811a82021-10-12 11:29:41 +0200422 n_switches = int(main.params["TOPO"]["switchNum"])
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200423
424 run.initTest(main)
425 main.log.info(main.Cluster.numCtrls)
426 main.Cluster.setRunningNode(3)
427 run.installOnos(main, skipPackage=True, cliSleep=5)
428
429 onos_cli_0 = main.Cluster.active(0).CLI
430 onos_cli_1 = main.Cluster.active(1).CLI
431 onos_cli_2 = main.Cluster.active(2).CLI
432 kubectl_0 = main.Cluster.active(0).k8s
433
434 up4_0 = UP4()
435 up4_1 = UP4()
436 up4_2 = UP4()
437
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200438 initial_flow_count = onos_cli_0.checkFlowCount()
439
Daniele Moro93feb022021-10-04 16:26:23 +0200440 main.step("Program and Verify PDRs and FARs via UP4 on ONOS 0")
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200441 up4_0.setup(main.Cluster.active(0).p4rtUp4, no_host=True)
442 up4_0.attachUes()
443 up4_0.verifyUp4Flow(onos_cli_0)
444 up4_0.teardown()
445
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200446 run.checkFlows(
447 main,
Daniele Moroc6811a82021-10-12 11:29:41 +0200448 minFlowCount=initial_flow_count + (
449 len(up4_0.emulated_ues) * N_FLOWS_PER_UE * n_switches)
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200450 )
451
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200452 onosPod = main.params["UP4_delete_pod"]
Daniele Moroc99bf822021-10-11 23:21:15 +0200453
454 # Save ONOS diags of the POD we are killing otherwise we lose ONOS logs
455 main.ONOSbench.onosDiagnosticsK8s(
456 [onosPod],
457 main.logdir,
458 "-CASE%d-%s_BeforeKill" % (main.CurrentTestCaseNumber, onosPod)
459 )
460
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200461 # Exit from previous port forwarding, because we need to restore
462 # port-forwarding after ONOS reboot.
463 kubectl_0.clearBuffer()
464 kubectl_0.exitFromProcess()
465 main.step("Kill " + onosPod)
466 utilities.assert_equal(
467 expect=main.TRUE,
468 actual=kubectl_0.kubectlDeletePod(
469 podName=onosPod,
470 kubeconfig=kubectl_0.kubeConfig,
471 namespace=main.params['kubernetes']['namespace']
472 ),
473 onpass="%s pod correctly deleted" % onosPod,
474 onfail="%s pod has not been deleted" % onosPod
475 )
476
477 main.step("Verify PDRs and FARs number via UP4 P4RT on ONOS 2")
478 up4_2.setup(main.Cluster.active(2).p4rtUp4, no_host=True)
479 utilities.assert_equal(
480 expect=True,
481 actual=up4_2.verifyUesFlowNumberP4rt(),
482 onpass="Correct number of PDRs and FARs",
483 onfail="Wrong number of PDRs and FARs"
484 )
485
Daniele Moro93feb022021-10-04 16:26:23 +0200486 main.step("Remove and Verify PDRs and FARs via UP4 on ONOS 2")
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200487 up4_2.detachUes()
488 up4_2.verifyNoUesFlow(onos_cli_2)
489
490 main.step("Verify no PDRs and FARs via UP4 P4RT on ONOS 2")
491 utilities.assert_equal(
492 expect=True,
493 actual=up4_2.verifyNoUesFlowNumberP4rt(),
494 onpass="No PDRs and FARs",
495 onfail="Stale PDRs and FARs"
496 )
497 up4_2.teardown()
498
Daniele Moroc6811a82021-10-12 11:29:41 +0200499 main.step(
500 "Verify all active ONOS instances have the same number of flows")
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200501 onos_1_flow_count = onos_cli_1.checkFlowCount()
502 onos_2_flow_count = onos_cli_2.checkFlowCount()
503 utilities.assert_equal(
504 expect=True,
505 actual=onos_1_flow_count == onos_2_flow_count,
506 onpass="All ONOS instances have the same number of flows",
507 onfail="ONOS instances have different number of flows: (%d, %d)" % (
508 onos_1_flow_count, onos_2_flow_count)
509 )
510
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200511 main.step("Verify ONOS 0 has restarted correctly")
512 onosStarted = utilities.retry(
513 f=kubectl_0.kubectlCheckPodReady,
514 retValue=main.FALSE,
515 kwargs={
516 "podName": onosPod,
517 "kubeconfig": kubectl_0.kubeConfig,
518 "namespace": main.params['kubernetes']['namespace']
519 },
520 sleep=10,
521 attempts=10
522 )
523 utilities.assert_equal(
524 expect=main.TRUE,
525 actual=onosStarted,
526 onpass="%s pod correctly restarted" % onosPod,
527 onfail="%s pod haven't restarted correctly" % onosPod
528 )
529
530 main.step("Verify ONOS cluster is in good shape")
531 # A bug in kubectl port forwarding doesn't terminate port-forwarding
532 # when the container changed, nor reconnect correctly to the restarted
533 # container.
534 # See: https://github.com/kubernetes/kubectl/issues/686
535 # Re-build the port-list for port forwarding
536 portList = "%s:%s " % (main.Cluster.active(0).CLI.karafPort, 8101)
537 portList += "%s:%s " % (main.Cluster.active(0).REST.port, 8181)
538 portList += "%s:%s " % (main.Cluster.active(0).p4rtUp4.p4rtPort,
539 main.ONOScell.up4Port)
540 kubectl_0.clearBuffer()
541 kubectl_0.kubectlPortForward(
542 onosPod,
543 portList,
544 kubectl_0.kubeConfig,
545 main.params['kubernetes']['namespace']
546 )
547 onos_cli_0.clearBuffer() # Trigger ONOS CLI reconnection
548 onosNodesStatus = utilities.retry(
549 f=main.Cluster.nodesCheck,
550 retValue=False,
551 sleep=5,
552 attempts=10
553 )
554 utilities.assert_equal(
555 expect=True,
556 actual=onosNodesStatus,
557 onpass="ONOS nodes status correct",
558 onfail="Wrong ONOS nodes status"
559 )
560
561 main.step("Verify no PDRs and FARs via UP4 P4RT on ONOS 0")
562 up4_0.setup(main.Cluster.active(0).p4rtUp4, no_host=True)
563 utilities.assert_equal(
564 expect=True,
565 actual=up4_0.verifyNoUesFlowNumberP4rt(),
566 onpass="No PDRs and FARs",
567 onfail="Stale PDRs and FARs"
568 )
569
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200570 run.checkFlows(main, minFlowCount=initial_flow_count)
571
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200572 main.step("Re-program PDRs and FARs via UP4 on ONOS 0 after restart")
573 up4_0.attachUes()
574 up4_0.verifyUp4Flow(onos_cli_0)
575 up4_0.teardown()
576
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200577 run.checkFlows(
578 main,
Daniele Moroc6811a82021-10-12 11:29:41 +0200579 minFlowCount=initial_flow_count + (
580 len(up4_0.emulated_ues) * N_FLOWS_PER_UE * n_switches)
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200581 )
582
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200583 main.step("Verify PDRs and FARs via UP4 on ONOS 1")
584 up4_1.setup(main.Cluster.active(1).p4rtUp4, no_host=True)
585 up4_1.verifyUp4Flow(onos_cli_1)
586
587 main.step("Verify all ONOS instances have the same number of flows")
588 onos_0_flow_count = onos_cli_0.checkFlowCount()
589 onos_1_flow_count = onos_cli_1.checkFlowCount()
590 onos_2_flow_count = onos_cli_2.checkFlowCount()
591 utilities.assert_equal(
592 expect=True,
593 actual=onos_0_flow_count == onos_1_flow_count == onos_2_flow_count,
594 onpass="All ONOS instances have the same number of flows",
595 onfail="ONOS instances have different number of flows: (%d, %d, %d)" % (
596 onos_0_flow_count, onos_1_flow_count, onos_2_flow_count)
597 )
598
599 main.step("Cleanup PDRs and FARs via UP4 on ONOS 1")
600 up4_1.detachUes()
Daniele Moro6dfbfef2021-09-28 22:44:19 +0200601 up4_1.verifyNoUesFlow(onos_cli_1)
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200602 up4_1.teardown()
603
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200604 run.checkFlows(main, minFlowCount=initial_flow_count)
605
Daniele Moroc99bf822021-10-11 23:21:15 +0200606 run.saveOnosDiagsIfFailure(main)
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200607 run.cleanup(main)