blob: ef659fce12f8db8859bfee344e0a3da8690b8ecc [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
Daniele Morobf53dec2021-09-13 18:11:56 +020085 GPDU_PORT = 2152
86 UE_PORT = 400
87 PDN_PORT = 800
88 try:
Daniele Moroc6811a82021-10-12 11:29:41 +020089 from tests.USECASE.SegmentRouting.dependencies.up4 import UP4, \
90 N_FLOWS_PER_UE
Daniele Morobf53dec2021-09-13 18:11:56 +020091 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import \
92 Testcaselib as run
93 except ImportError as e:
94 main.log.error("Import not found. Exiting the test")
95 main.log.error(e)
96 main.cleanAndExit()
Daniele Moroc6811a82021-10-12 11:29:41 +020097 n_switches = int(main.params["TOPO"]["switchNum"])
Daniele Morobf53dec2021-09-13 18:11:56 +020098
99 run.initTest(main)
100 main.log.info(main.Cluster.numCtrls)
101 main.Cluster.setRunningNode(3)
102 run.installOnos(main, skipPackage=True, cliSleep=5)
103
104 main.step("Start scapy and p4rt client + Scapy on BESS Host")
105 # Use the first available ONOS instance CLI
106 onos_cli = main.Cluster.active(0).CLI
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200107 initial_flow_count = onos_cli.checkFlowCount()
Daniele Morobf53dec2021-09-13 18:11:56 +0200108 up4 = UP4()
109 # Get the P4RT client connected to UP4 in the first available ONOS instance
110 up4.setup(main.Cluster.active(0).p4rtUp4)
111
112 # Setup the emulated BESS host and required parameters
Daniele Moro522023c2021-10-15 17:30:33 +0200113 bess_host = getattr(main, main.params["BESS_UPF"]["bess_host"])
Daniele Morobf53dec2021-09-13 18:11:56 +0200114 bess_interface = bess_host.interfaces[0]
115 bess_s1u_address = bess_interface["ips"][0]
116 bess_host.startScapy(ifaceName=bess_interface["name"], enableGtp=True)
Daniele Moro522023c2021-10-15 17:30:33 +0200117 bess_ue_address = main.params["BESS_UPF"]["ue_address"]
118 enodeb_host = getattr(main, main.params["BESS_UPF"]["enodeb_host"])
119 enodeb_address = main.params["BESS_UPF"]["enb_address"]
120 enodeb_interface = enodeb_host.interfaces[0]["name"]
Daniele Morobf53dec2021-09-13 18:11:56 +0200121 pdn_host = up4.pdn_host
122 pdn_interface = up4.pdn_interface
123
Daniele Moro93feb022021-10-04 16:26:23 +0200124 main.step("Program and Verify PDRs and FARs for UEs via UP4")
Daniele Morobf53dec2021-09-13 18:11:56 +0200125 up4.attachUes()
Daniele Morobf53dec2021-09-13 18:11:56 +0200126 up4.verifyUp4Flow(onos_cli)
127
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200128 run.checkFlows(
129 main,
Daniele Moroc6811a82021-10-12 11:29:41 +0200130 minFlowCount=initial_flow_count + (
131 len(up4.emulated_ues) * N_FLOWS_PER_UE * n_switches)
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200132 )
133
Daniele Morobf53dec2021-09-13 18:11:56 +0200134 # ------------------- UPSTREAM -------------------
135 # ------- eNB -> fabric -> BESS (encapped)
136 main.step("Test upstream eNB -> fabric -> BESS")
137 # Start filter before sending packets, BESS should receive GTP encapped
138 # packets
139 pkt_filter_upstream = "ip and udp src port %d and udp dst port %d and src host %s and dst host %s" % (
Daniele Moro522023c2021-10-15 17:30:33 +0200140 GPDU_PORT, GPDU_PORT, enodeb_address, bess_s1u_address)
Daniele Morobf53dec2021-09-13 18:11:56 +0200141 main.log.info("Start listening on %s intf %s" % (
142 bess_host.name, bess_interface["name"]))
143 main.log.debug("BPF Filter BESS Upstream: \n %s" % pkt_filter_upstream)
144 bess_host.startFilter(ifaceName=bess_interface["name"],
145 sniffCount=1,
146 pktFilter=pkt_filter_upstream)
147 # Send GTP Packet
148 UP4.buildGtpPacket(enodeb_host,
Daniele Moro522023c2021-10-15 17:30:33 +0200149 src_ip_outer=enodeb_address,
Daniele Morobf53dec2021-09-13 18:11:56 +0200150 dst_ip_outer=bess_s1u_address,
Daniele Moro522023c2021-10-15 17:30:33 +0200151 src_ip_inner=bess_ue_address,
Daniele Morobf53dec2021-09-13 18:11:56 +0200152 dst_ip_inner=pdn_interface["ips"][0],
153 src_udp_inner=UE_PORT,
154 dst_udp_inner=PDN_PORT,
155 teid=BESS_TEID)
156 enodeb_host.sendPacket()
157
158 packets = UP4.checkFilterAndGetPackets(bess_host)
159 # FIXME: with newer scapy TEID becomes teid (required for Scapy 2.4.5)
160 n_packets = packets.count("TEID=" + hex(BESS_TEID) + "L ")
161 tot_packets = packets.count('Ether')
162 utilities.assert_equal(expect=True,
163 actual=n_packets == 1 and tot_packets == 1,
164 onpass="BESS correctly received 1 GTP encapped packet",
165 onfail="ERROR: BESS received %d GTP encapped packets and filter captured %d packets" % (
166 n_packets, tot_packets))
167
168 # ------- BESS -> fabric -> PDN (not-encapped)
169 main.step("Test upstream BESS -> fabric -> PDN")
170 # Start filter before sending packets, PDN should receive non-GTP packet
171 pkt_filter_upstream = "ip and udp src port %d and udp dst port %d and src host %s and dst host %s" % (
Daniele Moro522023c2021-10-15 17:30:33 +0200172 UE_PORT, PDN_PORT, bess_ue_address, pdn_interface["ips"][0])
Daniele Morobf53dec2021-09-13 18:11:56 +0200173 main.log.info("Start listening on %s intf %s" % (
174 pdn_host.name, pdn_interface["name"]))
175 main.log.debug("BPF Filter PDN Upstream: \n %s" % pkt_filter_upstream)
176 pdn_host.startFilter(ifaceName=pdn_interface["name"],
177 sniffCount=1,
178 pktFilter=pkt_filter_upstream)
179 # Send UDP Packet
180 UP4.buildUdpPacket(bess_host,
Daniele Moro522023c2021-10-15 17:30:33 +0200181 src_ip=bess_ue_address,
Daniele Morobf53dec2021-09-13 18:11:56 +0200182 dst_ip=pdn_interface["ips"][0],
183 src_udp=UE_PORT,
184 dst_udp=PDN_PORT)
185 bess_host.sendPacket()
186
187 packets = UP4.checkFilterAndGetPackets(pdn_host)
188 tot_packets = packets.count('Ether')
189 utilities.assert_equal(expect=True,
190 actual=tot_packets == 1,
191 onpass="PDN correctly received 1 packet",
192 onfail="ERROR: PDN received %d packets" % (
193 tot_packets))
194 # ------------------------------------------------
195
196 # ------------------ DOWNSTREAM ------------------
197 # ------- PDN -> fabric -> BESS (not-encapped)
198 main.step("Test downstream PDN -> fabric -> BESS")
199 pkt_filter_downstream = "ip and udp src port %d and udp dst port %d and src host %s and dst host %s" % (
Daniele Moro522023c2021-10-15 17:30:33 +0200200 PDN_PORT, UE_PORT, pdn_interface["ips"][0], bess_ue_address)
Daniele Morobf53dec2021-09-13 18:11:56 +0200201 main.log.info("Start listening on %s intf %s" % (
202 bess_host.name, bess_interface["name"]))
203 main.log.debug(
204 "BPF Filter BESS Downstream: \n %s" % pkt_filter_downstream)
205 bess_host.startFilter(ifaceName=bess_interface["name"],
206 sniffCount=1,
207 pktFilter=pkt_filter_downstream)
208 UP4.buildUdpPacket(pdn_host,
209 dst_eth=up4.router_mac,
210 src_ip=pdn_interface["ips"][0],
Daniele Moro522023c2021-10-15 17:30:33 +0200211 dst_ip=bess_ue_address,
Daniele Morobf53dec2021-09-13 18:11:56 +0200212 src_udp=PDN_PORT,
213 dst_udp=UE_PORT)
214 pdn_host.sendPacket()
215
216 packets = UP4.checkFilterAndGetPackets(bess_host)
217
218 tot_packets = packets.count('Ether')
219 utilities.assert_equal(expect=True,
220 actual=tot_packets == 1,
221 onpass="BESS correctly received 1 packet",
222 onfail="ERROR: BESS received %d packets" % (
223 tot_packets))
224
225 # ------- BESS -> fabric -> eNB (encapped)
226 main.step("Test downstream BESS -> fabric -> eNB")
227 pkt_filter_downstream = "ip and udp src port %d and udp dst port %d and src host %s and dst host %s" % (
Daniele Moro522023c2021-10-15 17:30:33 +0200228 GPDU_PORT, GPDU_PORT, bess_s1u_address, enodeb_address)
Daniele Morobf53dec2021-09-13 18:11:56 +0200229 main.log.info("Start listening on %s intf %s" % (
Daniele Moro522023c2021-10-15 17:30:33 +0200230 enodeb_host.name, enodeb_interface))
Daniele Morobf53dec2021-09-13 18:11:56 +0200231 main.log.debug(
232 "BPF Filter BESS Downstream: \n %s" % pkt_filter_downstream)
Daniele Moro522023c2021-10-15 17:30:33 +0200233 enodeb_host.startFilter(ifaceName=enodeb_interface,
Daniele Morobf53dec2021-09-13 18:11:56 +0200234 sniffCount=1,
235 pktFilter=pkt_filter_downstream)
236 # Build GTP packet from BESS host
237 UP4.buildGtpPacket(bess_host,
238 src_ip_outer=bess_s1u_address,
Daniele Moro522023c2021-10-15 17:30:33 +0200239 dst_ip_outer=enodeb_address,
Daniele Morobf53dec2021-09-13 18:11:56 +0200240 src_ip_inner=pdn_interface["ips"][0],
Daniele Moro522023c2021-10-15 17:30:33 +0200241 dst_ip_inner=bess_ue_address,
Daniele Morobf53dec2021-09-13 18:11:56 +0200242 src_udp_inner=PDN_PORT,
243 dst_udp_inner=UE_PORT,
244 teid=BESS_TEID)
245 bess_host.sendPacket()
246
247 packets = UP4.checkFilterAndGetPackets(enodeb_host)
248
249 # FIXME: with newer scapy TEID becomes teid (required for Scapy 2.4.5)
250 n_packets = packets.count("TEID=" + hex(BESS_TEID) + "L ")
251 tot_packets = packets.count('Ether')
252 utilities.assert_equal(expect=True,
253 actual=n_packets == 1 and tot_packets == 1,
254 onpass="eNodeB correctly received 1 GTP encapped packet",
255 onfail="ERROR: eNodeb received %d GTP encapped packets and filter captured %d packets" % (
256 n_packets, tot_packets))
257 # ------------------------------------------------
258
Daniele Moro93feb022021-10-04 16:26:23 +0200259 main.step("Remove and Verify PDRs and FARs for UEs via UP4")
Daniele Morobf53dec2021-09-13 18:11:56 +0200260 up4.detachUes()
Daniele Morobf53dec2021-09-13 18:11:56 +0200261 up4.verifyNoUesFlow(onos_cli)
262
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200263 run.checkFlows(main, minFlowCount=initial_flow_count)
264
Daniele Morobf53dec2021-09-13 18:11:56 +0200265 main.step("Stop scapy and p4rt client")
266 up4.teardown()
267 bess_host.stopScapy()
Daniele Moroc99bf822021-10-11 23:21:15 +0200268
269 run.saveOnosDiagsIfFailure(main)
Daniele Morobf53dec2021-09-13 18:11:56 +0200270 run.cleanup(main)
Daniele Moro954e2282021-09-22 17:32:03 +0200271
272 def CASE3(self, main):
273 main.case("Verify UP4 from different ONOS instances")
274 """
275 Program PDRs and FARs via UP4 on first ONOS instance
276 Repeat for all ONOS Instances:
277 Verify PDRs and FARs via P4RT
278 Disconnect P4RT client
279 Verify and delete PDRs and FARs via UP4 on the third ONOS instance
280 Repeat for all ONOS Instance:
281 Verify removed PDRs and FARs via P4RT
282 Disconnect P4RT client
283 """
284 try:
Daniele Morofbfdfbd2021-10-18 22:47:51 +0200285 from tests.USECASE.SegmentRouting.dependencies.up4 import UP4, \
286 N_FLOWS_PER_UE
Daniele Moro954e2282021-09-22 17:32:03 +0200287 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import \
288 Testcaselib as run
289 except ImportError as e:
290 main.log.error("Import not found. Exiting the test")
291 main.log.error(e)
292 main.cleanAndExit()
Daniele Moroc6811a82021-10-12 11:29:41 +0200293 n_switches = int(main.params["TOPO"]["switchNum"])
Daniele Moro954e2282021-09-22 17:32:03 +0200294
295 run.initTest(main)
296 main.log.info(main.Cluster.numCtrls)
297 main.Cluster.setRunningNode(3)
298 run.installOnos(main, skipPackage=True, cliSleep=5)
299
300 onos_cli_0 = main.Cluster.active(0).CLI
301 onos_cli_1 = main.Cluster.active(1).CLI
302 onos_cli_2 = main.Cluster.active(2).CLI
303 up4_0 = UP4()
304 up4_1 = UP4()
305 up4_2 = UP4()
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200306 initial_flow_count = onos_cli_0.checkFlowCount()
Daniele Moro954e2282021-09-22 17:32:03 +0200307
Daniele Moro93feb022021-10-04 16:26:23 +0200308 main.step("Program and Verify PDRs and FARs via UP4 on ONOS 0")
Daniele Moro954e2282021-09-22 17:32:03 +0200309 up4_0.setup(main.Cluster.active(0).p4rtUp4, no_host=True)
310 up4_0.attachUes()
311 up4_0.verifyUp4Flow(onos_cli_0)
312 up4_0.teardown()
313
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200314 run.checkFlows(
315 main,
Daniele Moroc6811a82021-10-12 11:29:41 +0200316 minFlowCount=initial_flow_count + (
317 len(up4_0.emulated_ues) * N_FLOWS_PER_UE * n_switches)
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200318 )
319
Daniele Moro954e2282021-09-22 17:32:03 +0200320 main.step("Verify PDRs and FARs number via UP4 P4RT on ONOS 1")
321 up4_1.setup(main.Cluster.active(1).p4rtUp4, no_host=True)
322 utilities.assert_equal(
323 expect=True,
324 actual=up4_1.verifyUesFlowNumberP4rt(),
325 onpass="Correct number of PDRs and FARs",
326 onfail="Wrong number of PDRs and FARs"
327 )
328 up4_1.teardown()
329
330 main.step("Verify PDRs and FARs number via UP4 P4RT on ONOS 2")
331 up4_2.setup(main.Cluster.active(2).p4rtUp4, no_host=True)
332 utilities.assert_equal(
333 expect=True,
334 actual=up4_2.verifyUesFlowNumberP4rt(),
335 onpass="Correct number of PDRs and FARs",
336 onfail="Wrong number of PDRs and FARs"
337 )
338
339 main.step("Verify all ONOS instances have the same number of flows")
340 onos_0_flow_count = onos_cli_0.checkFlowCount()
341 onos_1_flow_count = onos_cli_1.checkFlowCount()
342 onos_2_flow_count = onos_cli_2.checkFlowCount()
343 utilities.assert_equal(
344 expect=True,
345 actual=onos_0_flow_count == onos_1_flow_count == onos_2_flow_count,
346 onpass="All ONOS instances have the same number of flows",
347 onfail="ONOS instances have different number of flows: (%d, %d, %d)" % (
348 onos_0_flow_count, onos_1_flow_count, onos_2_flow_count)
349 )
350
Daniele Moro93feb022021-10-04 16:26:23 +0200351 main.step("Remove and Verify PDRs and FARs via UP4 on ONOS 2")
Daniele Moro954e2282021-09-22 17:32:03 +0200352 up4_2.detachUes()
353 up4_2.verifyNoUesFlow(onos_cli_2)
354
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200355 run.checkFlows(main, minFlowCount=initial_flow_count)
356
Daniele Moro954e2282021-09-22 17:32:03 +0200357 main.step("Verify no PDRs and FARs via UP4 P4RT on ONOS 2")
358 utilities.assert_equal(
359 expect=True,
360 actual=up4_2.verifyNoUesFlowNumberP4rt(),
361 onpass="No PDRs and FARs",
362 onfail="Stale PDRs and FARs"
363 )
364 up4_2.teardown()
365
366 main.step("Verify no PDRs and FARs via UP4 P4RT on ONOS 1")
367 up4_1.setup(main.Cluster.active(1).p4rtUp4, no_host=True)
368 utilities.assert_equal(
369 expect=True,
370 actual=up4_1.verifyNoUesFlowNumberP4rt(),
371 onpass="No PDRs and FARs",
372 onfail="Stale PDRs and FARs"
373 )
374 up4_1.teardown()
375
376 main.step("Verify no PDRs and FARs via UP4 P4RT on ONOS 0")
377 up4_0.setup(main.Cluster.active(0).p4rtUp4, no_host=True)
378 utilities.assert_equal(
379 expect=True,
380 actual=up4_0.verifyNoUesFlowNumberP4rt(),
381 onpass="No PDRs and FARs",
382 onfail="Stale PDRs and FARs"
383 )
384 up4_0.teardown()
385
386 main.step("Verify all ONOS instances have the same number of flows")
387 onos_0_flow_count = onos_cli_0.checkFlowCount()
388 onos_1_flow_count = onos_cli_1.checkFlowCount()
389 onos_2_flow_count = onos_cli_2.checkFlowCount()
390 utilities.assert_equal(
391 expect=True,
392 actual=onos_0_flow_count == onos_1_flow_count == onos_2_flow_count,
393 onpass="All ONOS instances have the same number of flows",
394 onfail="ONOS instances have different number of flows: (%d, %d, %d)" % (
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200395 onos_0_flow_count, onos_1_flow_count, onos_2_flow_count)
Daniele Moro954e2282021-09-22 17:32:03 +0200396 )
Daniele Moroc99bf822021-10-11 23:21:15 +0200397
398 run.saveOnosDiagsIfFailure(main)
Daniele Moro954e2282021-09-22 17:32:03 +0200399 run.cleanup(main)
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200400
401 def CASE4(self, main):
402 main.case("Verify UP4 wipe-out after ONOS reboot")
403 """
404 Program PDRs/FARs
405 Kill ONOS POD
406 Verify PDRs/FARs from other ONOS instances
407 Remove PDRs/FARs
408 Wait/Verify ONOS is back
409 Verify no PDRs/FARs from rebooted instance
410 Re-program PDRs/FARs from rebooted instance
411 Verify all instances have same number of flows
412 Remove PDRs/FARs (cleanup)
413 """
414 try:
Daniele Moroc6811a82021-10-12 11:29:41 +0200415 from tests.USECASE.SegmentRouting.dependencies.up4 import UP4, \
416 N_FLOWS_PER_UE
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200417 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import \
418 Testcaselib as run
419 except ImportError as e:
420 main.log.error("Import not found. Exiting the test")
421 main.log.error(e)
422 main.cleanAndExit()
Daniele Moroc6811a82021-10-12 11:29:41 +0200423 n_switches = int(main.params["TOPO"]["switchNum"])
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200424
425 run.initTest(main)
426 main.log.info(main.Cluster.numCtrls)
427 main.Cluster.setRunningNode(3)
428 run.installOnos(main, skipPackage=True, cliSleep=5)
429
430 onos_cli_0 = main.Cluster.active(0).CLI
431 onos_cli_1 = main.Cluster.active(1).CLI
432 onos_cli_2 = main.Cluster.active(2).CLI
433 kubectl_0 = main.Cluster.active(0).k8s
434
435 up4_0 = UP4()
436 up4_1 = UP4()
437 up4_2 = UP4()
438
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200439 initial_flow_count = onos_cli_0.checkFlowCount()
440
Daniele Moro93feb022021-10-04 16:26:23 +0200441 main.step("Program and Verify PDRs and FARs via UP4 on ONOS 0")
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200442 up4_0.setup(main.Cluster.active(0).p4rtUp4, no_host=True)
443 up4_0.attachUes()
444 up4_0.verifyUp4Flow(onos_cli_0)
445 up4_0.teardown()
446
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200447 run.checkFlows(
448 main,
Daniele Moroc6811a82021-10-12 11:29:41 +0200449 minFlowCount=initial_flow_count + (
450 len(up4_0.emulated_ues) * N_FLOWS_PER_UE * n_switches)
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200451 )
452
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200453 onosPod = main.params["UP4_delete_pod"]
Daniele Moroc99bf822021-10-11 23:21:15 +0200454
455 # Save ONOS diags of the POD we are killing otherwise we lose ONOS logs
456 main.ONOSbench.onosDiagnosticsK8s(
457 [onosPod],
458 main.logdir,
459 "-CASE%d-%s_BeforeKill" % (main.CurrentTestCaseNumber, onosPod)
460 )
461
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200462 # Exit from previous port forwarding, because we need to restore
463 # port-forwarding after ONOS reboot.
464 kubectl_0.clearBuffer()
465 kubectl_0.exitFromProcess()
466 main.step("Kill " + onosPod)
467 utilities.assert_equal(
468 expect=main.TRUE,
469 actual=kubectl_0.kubectlDeletePod(
470 podName=onosPod,
471 kubeconfig=kubectl_0.kubeConfig,
472 namespace=main.params['kubernetes']['namespace']
473 ),
474 onpass="%s pod correctly deleted" % onosPod,
475 onfail="%s pod has not been deleted" % onosPod
476 )
477
478 main.step("Verify PDRs and FARs number via UP4 P4RT on ONOS 2")
479 up4_2.setup(main.Cluster.active(2).p4rtUp4, no_host=True)
480 utilities.assert_equal(
481 expect=True,
482 actual=up4_2.verifyUesFlowNumberP4rt(),
483 onpass="Correct number of PDRs and FARs",
484 onfail="Wrong number of PDRs and FARs"
485 )
486
Daniele Moro93feb022021-10-04 16:26:23 +0200487 main.step("Remove and Verify PDRs and FARs via UP4 on ONOS 2")
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200488 up4_2.detachUes()
489 up4_2.verifyNoUesFlow(onos_cli_2)
490
491 main.step("Verify no PDRs and FARs via UP4 P4RT on ONOS 2")
492 utilities.assert_equal(
493 expect=True,
494 actual=up4_2.verifyNoUesFlowNumberP4rt(),
495 onpass="No PDRs and FARs",
496 onfail="Stale PDRs and FARs"
497 )
498 up4_2.teardown()
499
Daniele Moroc6811a82021-10-12 11:29:41 +0200500 main.step(
501 "Verify all active ONOS instances have the same number of flows")
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200502 onos_1_flow_count = onos_cli_1.checkFlowCount()
503 onos_2_flow_count = onos_cli_2.checkFlowCount()
504 utilities.assert_equal(
505 expect=True,
506 actual=onos_1_flow_count == onos_2_flow_count,
507 onpass="All ONOS instances have the same number of flows",
508 onfail="ONOS instances have different number of flows: (%d, %d)" % (
509 onos_1_flow_count, onos_2_flow_count)
510 )
511
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200512 main.step("Verify ONOS 0 has restarted correctly")
513 onosStarted = utilities.retry(
514 f=kubectl_0.kubectlCheckPodReady,
515 retValue=main.FALSE,
516 kwargs={
517 "podName": onosPod,
518 "kubeconfig": kubectl_0.kubeConfig,
519 "namespace": main.params['kubernetes']['namespace']
520 },
521 sleep=10,
522 attempts=10
523 )
524 utilities.assert_equal(
525 expect=main.TRUE,
526 actual=onosStarted,
527 onpass="%s pod correctly restarted" % onosPod,
528 onfail="%s pod haven't restarted correctly" % onosPod
529 )
530
531 main.step("Verify ONOS cluster is in good shape")
532 # A bug in kubectl port forwarding doesn't terminate port-forwarding
533 # when the container changed, nor reconnect correctly to the restarted
534 # container.
535 # See: https://github.com/kubernetes/kubectl/issues/686
536 # Re-build the port-list for port forwarding
537 portList = "%s:%s " % (main.Cluster.active(0).CLI.karafPort, 8101)
538 portList += "%s:%s " % (main.Cluster.active(0).REST.port, 8181)
539 portList += "%s:%s " % (main.Cluster.active(0).p4rtUp4.p4rtPort,
540 main.ONOScell.up4Port)
541 kubectl_0.clearBuffer()
542 kubectl_0.kubectlPortForward(
543 onosPod,
544 portList,
545 kubectl_0.kubeConfig,
546 main.params['kubernetes']['namespace']
547 )
548 onos_cli_0.clearBuffer() # Trigger ONOS CLI reconnection
549 onosNodesStatus = utilities.retry(
550 f=main.Cluster.nodesCheck,
551 retValue=False,
552 sleep=5,
553 attempts=10
554 )
555 utilities.assert_equal(
556 expect=True,
557 actual=onosNodesStatus,
558 onpass="ONOS nodes status correct",
559 onfail="Wrong ONOS nodes status"
560 )
561
562 main.step("Verify no PDRs and FARs via UP4 P4RT on ONOS 0")
563 up4_0.setup(main.Cluster.active(0).p4rtUp4, no_host=True)
564 utilities.assert_equal(
565 expect=True,
566 actual=up4_0.verifyNoUesFlowNumberP4rt(),
567 onpass="No PDRs and FARs",
568 onfail="Stale PDRs and FARs"
569 )
570
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200571 run.checkFlows(main, minFlowCount=initial_flow_count)
572
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200573 main.step("Re-program PDRs and FARs via UP4 on ONOS 0 after restart")
574 up4_0.attachUes()
575 up4_0.verifyUp4Flow(onos_cli_0)
576 up4_0.teardown()
577
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200578 run.checkFlows(
579 main,
Daniele Moroc6811a82021-10-12 11:29:41 +0200580 minFlowCount=initial_flow_count + (
581 len(up4_0.emulated_ues) * N_FLOWS_PER_UE * n_switches)
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200582 )
583
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200584 main.step("Verify PDRs and FARs via UP4 on ONOS 1")
585 up4_1.setup(main.Cluster.active(1).p4rtUp4, no_host=True)
586 up4_1.verifyUp4Flow(onos_cli_1)
587
588 main.step("Verify all ONOS instances have the same number of flows")
589 onos_0_flow_count = onos_cli_0.checkFlowCount()
590 onos_1_flow_count = onos_cli_1.checkFlowCount()
591 onos_2_flow_count = onos_cli_2.checkFlowCount()
592 utilities.assert_equal(
593 expect=True,
594 actual=onos_0_flow_count == onos_1_flow_count == onos_2_flow_count,
595 onpass="All ONOS instances have the same number of flows",
596 onfail="ONOS instances have different number of flows: (%d, %d, %d)" % (
597 onos_0_flow_count, onos_1_flow_count, onos_2_flow_count)
598 )
599
600 main.step("Cleanup PDRs and FARs via UP4 on ONOS 1")
601 up4_1.detachUes()
Daniele Moro6dfbfef2021-09-28 22:44:19 +0200602 up4_1.verifyNoUesFlow(onos_cli_1)
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200603 up4_1.teardown()
604
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200605 run.checkFlows(main, minFlowCount=initial_flow_count)
606
Daniele Moroc99bf822021-10-11 23:21:15 +0200607 run.saveOnosDiagsIfFailure(main)
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200608 run.cleanup(main)
Daniele Moro522023c2021-10-15 17:30:33 +0200609
610 def CASE5(self, main):
611 main.case("UP4 Data Plane Failure Test")
612 """
613 Program PDRs/FARs
614 Kill one switch
615 Verify that traffic from eNodebs that are connected to that switch fails
616 Verify that traffic from other eNodeBs is being forwarded
617 Wait for the switch to be up again
618 Check flows
619 Remove PDRs/FARs (cleanup)
620 """
621 try:
622 from tests.USECASE.SegmentRouting.dependencies.up4 import UP4, \
623 N_FLOWS_PER_UE
624 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import \
625 Testcaselib as run
626 from tests.USECASE.SegmentRouting.SRStaging.dependencies.SRStagingTest import \
627 SRStagingTest
628 import time
629 import itertools
630 except ImportError as e:
631 main.log.error("Import not found. Exiting the test")
632 main.log.error(e)
633 main.cleanAndExit()
634 n_switches = int(main.params["TOPO"]["switchNum"])
635 switch_to_kill = main.params["UP4"]["switch_to_kill"]
636
637 run.initTest(main)
638 main.log.info(main.Cluster.numCtrls)
639 main.Cluster.setRunningNode(3)
640 run.installOnos(main, skipPackage=True, cliSleep=5)
641
642 onos_cli = main.Cluster.active(0).CLI
643
644 up4 = UP4()
645
646 initial_flow_count = onos_cli.checkFlowCount()
647
648 main.step("Program and Verify PDRs and FARs via UP4")
649 up4.setup(main.Cluster.active(0).p4rtUp4)
650 up4.attachUes()
651 up4.verifyUp4Flow(onos_cli)
652
653 run.checkFlows(
654 main,
655 minFlowCount=initial_flow_count+(len(up4.emulated_ues)*4*n_switches)
656 )
657
658 main.step("Kill switch")
659 switch_component = getattr(main, switch_to_kill)
660 switch_component.handle.sendline("sudo reboot")
661
662 sleepTime = 20
663 main.log.info("Sleeping %s seconds for Fabric to react" % sleepTime)
664 time.sleep(sleepTime)
665
666 available = utilities.retry(SRStagingTest.switchIsConnected,
667 True,
668 args=[switch_component],
669 attempts=300,
670 getRetryingTime=True)
671 main.log.info("Switch %s is available in ONOS? %s" % (
672 switch_to_kill, available))
673 utilities.assert_equal(
674 expect=False,
675 actual=available,
676 onpass="Switch was rebooted (ONL reboot) successfully",
677 onfail="Switch was not rebooted (ONL reboot) successfully"
678 )
679
680 enodebs_fail = main.params["UP4"]["enodebs_fail"].split(",")
681 enodebs_no_fail = list(set(up4.enodebs.keys()) - set(enodebs_fail))
682
683 # ------- Test Upstream traffic (enbs->pdn)
684 main.step("Test upstream traffic FAIL")
685 up4.testUpstreamTraffic(enb_names=enodebs_fail, shouldFail=True)
686 main.step("Test upstream traffic NO FAIL")
687 up4.testUpstreamTraffic(enb_names=enodebs_no_fail, shouldFail=False)
688
689 # ------- Test Downstream traffic (pdn->enbs)
690 main.step("Test downstream traffic FAIL")
691 up4.testDownstreamTraffic(enb_names=enodebs_fail, shouldFail=True)
692 main.step("Test downstream traffic NO FAIL")
693 up4.testDownstreamTraffic(enb_names=enodebs_no_fail, shouldFail=False)
694
695 # Reconnect to the switch
696 connect = utilities.retry(switch_component.connect,
697 main.FALSE,
698 attempts=30,
699 getRetryingTime=True)
700 main.log.info("Connected to the switch %s? %s" % (
701 switch_to_kill, connect))
702 # Wait switch to be back in ONOS
703 available = utilities.retry(SRStagingTest.switchIsConnected,
704 False,
705 args=[switch_component],
706 attempts=300,
707 getRetryingTime=True)
708 main.log.info("Switch %s is available in ONOS? %s" % (
709 switch_to_kill, available))
710 utilities.assert_equal(
711 expect=True,
712 actual=available and connect == main.TRUE,
713 onpass="Switch is back available in ONOS",
714 onfail="Switch is not available in ONOS, may influence subsequent tests!"
715 )
716
717 main.step("Test upstream traffic AFTER switch reboot")
718 up4.testUpstreamTraffic()
719
720 main.step("Cleanup PDRs and FARs via UP4")
721 up4.detachUes()
722 up4.verifyNoUesFlow(onos_cli)
723 up4.teardown()
724
725 run.checkFlows(main, minFlowCount=initial_flow_count)
726
727 # Teardown
728 run.cleanup(main)