blob: 191b8de308e252fd1d74aa6ddd531626ef8b16b5 [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
Daniele Moro5d88e2a2021-11-12 17:47:55 +0100419 from tests.USECASE.SegmentRouting.SRStaging.dependencies.SRStagingTest import \
420 SRStagingTest
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200421 except ImportError as e:
422 main.log.error("Import not found. Exiting the test")
423 main.log.error(e)
424 main.cleanAndExit()
Daniele Moroc6811a82021-10-12 11:29:41 +0200425 n_switches = int(main.params["TOPO"]["switchNum"])
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200426
427 run.initTest(main)
428 main.log.info(main.Cluster.numCtrls)
429 main.Cluster.setRunningNode(3)
430 run.installOnos(main, skipPackage=True, cliSleep=5)
431
432 onos_cli_0 = main.Cluster.active(0).CLI
433 onos_cli_1 = main.Cluster.active(1).CLI
434 onos_cli_2 = main.Cluster.active(2).CLI
Daniele Moro5d88e2a2021-11-12 17:47:55 +0100435 ctrl_0 = main.Cluster.active(0)
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200436
437 up4_0 = UP4()
438 up4_1 = UP4()
439 up4_2 = UP4()
440
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200441 initial_flow_count = onos_cli_0.checkFlowCount()
442
Daniele Moro93feb022021-10-04 16:26:23 +0200443 main.step("Program and Verify PDRs and FARs via UP4 on ONOS 0")
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200444 up4_0.setup(main.Cluster.active(0).p4rtUp4, no_host=True)
445 up4_0.attachUes()
446 up4_0.verifyUp4Flow(onos_cli_0)
447 up4_0.teardown()
448
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200449 run.checkFlows(
450 main,
Daniele Moroc6811a82021-10-12 11:29:41 +0200451 minFlowCount=initial_flow_count + (
452 len(up4_0.emulated_ues) * N_FLOWS_PER_UE * n_switches)
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200453 )
454
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200455 onosPod = main.params["UP4_delete_pod"]
Daniele Moroc99bf822021-10-11 23:21:15 +0200456
457 # Save ONOS diags of the POD we are killing otherwise we lose ONOS logs
458 main.ONOSbench.onosDiagnosticsK8s(
459 [onosPod],
460 main.logdir,
461 "-CASE%d-%s_BeforeKill" % (main.CurrentTestCaseNumber, onosPod)
462 )
463
Daniele Moro5d88e2a2021-11-12 17:47:55 +0100464 onosK8sNode = SRStagingTest.onosDown(main, ctrl_0, preventRestart=True)
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200465
466 main.step("Verify PDRs and FARs number via UP4 P4RT on ONOS 2")
467 up4_2.setup(main.Cluster.active(2).p4rtUp4, no_host=True)
468 utilities.assert_equal(
469 expect=True,
470 actual=up4_2.verifyUesFlowNumberP4rt(),
471 onpass="Correct number of PDRs and FARs",
472 onfail="Wrong number of PDRs and FARs"
473 )
474
Daniele Moro93feb022021-10-04 16:26:23 +0200475 main.step("Remove and Verify PDRs and FARs via UP4 on ONOS 2")
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200476 up4_2.detachUes()
477 up4_2.verifyNoUesFlow(onos_cli_2)
478
479 main.step("Verify no PDRs and FARs via UP4 P4RT on ONOS 2")
480 utilities.assert_equal(
481 expect=True,
482 actual=up4_2.verifyNoUesFlowNumberP4rt(),
483 onpass="No PDRs and FARs",
484 onfail="Stale PDRs and FARs"
485 )
486 up4_2.teardown()
487
Daniele Moroc6811a82021-10-12 11:29:41 +0200488 main.step(
489 "Verify all active ONOS instances have the same number of flows")
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200490 onos_1_flow_count = onos_cli_1.checkFlowCount()
491 onos_2_flow_count = onos_cli_2.checkFlowCount()
492 utilities.assert_equal(
493 expect=True,
494 actual=onos_1_flow_count == onos_2_flow_count,
495 onpass="All ONOS instances have the same number of flows",
496 onfail="ONOS instances have different number of flows: (%d, %d)" % (
497 onos_1_flow_count, onos_2_flow_count)
498 )
499
Daniele Moro5d88e2a2021-11-12 17:47:55 +0100500 SRStagingTest.onosUp(main, onosK8sNode, ctrl_0)
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200501
502 main.step("Verify ONOS cluster is in good shape")
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200503 onosNodesStatus = utilities.retry(
504 f=main.Cluster.nodesCheck,
505 retValue=False,
506 sleep=5,
507 attempts=10
508 )
509 utilities.assert_equal(
510 expect=True,
511 actual=onosNodesStatus,
512 onpass="ONOS nodes status correct",
513 onfail="Wrong ONOS nodes status"
514 )
515
516 main.step("Verify no PDRs and FARs via UP4 P4RT on ONOS 0")
517 up4_0.setup(main.Cluster.active(0).p4rtUp4, no_host=True)
518 utilities.assert_equal(
519 expect=True,
520 actual=up4_0.verifyNoUesFlowNumberP4rt(),
521 onpass="No PDRs and FARs",
522 onfail="Stale PDRs and FARs"
523 )
524
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200525 run.checkFlows(main, minFlowCount=initial_flow_count)
526
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200527 main.step("Re-program PDRs and FARs via UP4 on ONOS 0 after restart")
528 up4_0.attachUes()
529 up4_0.verifyUp4Flow(onos_cli_0)
530 up4_0.teardown()
531
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200532 run.checkFlows(
533 main,
Daniele Moroc6811a82021-10-12 11:29:41 +0200534 minFlowCount=initial_flow_count + (
535 len(up4_0.emulated_ues) * N_FLOWS_PER_UE * n_switches)
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200536 )
537
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200538 main.step("Verify PDRs and FARs via UP4 on ONOS 1")
539 up4_1.setup(main.Cluster.active(1).p4rtUp4, no_host=True)
540 up4_1.verifyUp4Flow(onos_cli_1)
541
542 main.step("Verify all ONOS instances have the same number of flows")
543 onos_0_flow_count = onos_cli_0.checkFlowCount()
544 onos_1_flow_count = onos_cli_1.checkFlowCount()
545 onos_2_flow_count = onos_cli_2.checkFlowCount()
546 utilities.assert_equal(
547 expect=True,
548 actual=onos_0_flow_count == onos_1_flow_count == onos_2_flow_count,
549 onpass="All ONOS instances have the same number of flows",
550 onfail="ONOS instances have different number of flows: (%d, %d, %d)" % (
551 onos_0_flow_count, onos_1_flow_count, onos_2_flow_count)
552 )
553
554 main.step("Cleanup PDRs and FARs via UP4 on ONOS 1")
555 up4_1.detachUes()
Daniele Moro6dfbfef2021-09-28 22:44:19 +0200556 up4_1.verifyNoUesFlow(onos_cli_1)
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200557 up4_1.teardown()
558
Daniele Moro9ba5cf02021-10-08 18:00:56 +0200559 run.checkFlows(main, minFlowCount=initial_flow_count)
560
Daniele Moroc99bf822021-10-11 23:21:15 +0200561 run.saveOnosDiagsIfFailure(main)
Daniele Moroe1d05eb2021-09-23 19:52:30 +0200562 run.cleanup(main)
Daniele Moro522023c2021-10-15 17:30:33 +0200563
564 def CASE5(self, main):
565 main.case("UP4 Data Plane Failure Test")
566 """
567 Program PDRs/FARs
568 Kill one switch
Daniele Moro80271cb2021-11-11 20:08:51 +0100569 Set label on switch K8S node to prevent K8S to redeploy stratum
Daniele Moro522023c2021-10-15 17:30:33 +0200570 Verify that traffic from eNodebs that are connected to that switch fails
571 Verify that traffic from other eNodeBs is being forwarded
572 Wait for the switch to be up again
573 Check flows
574 Remove PDRs/FARs (cleanup)
575 """
576 try:
577 from tests.USECASE.SegmentRouting.dependencies.up4 import UP4, \
578 N_FLOWS_PER_UE
579 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import \
580 Testcaselib as run
581 from tests.USECASE.SegmentRouting.SRStaging.dependencies.SRStagingTest import \
582 SRStagingTest
583 import time
584 import itertools
585 except ImportError as e:
586 main.log.error("Import not found. Exiting the test")
587 main.log.error(e)
588 main.cleanAndExit()
589 n_switches = int(main.params["TOPO"]["switchNum"])
Daniele Moro80271cb2021-11-11 20:08:51 +0100590 switch_to_kill = main.params["UP4"]["UP4_dataplane_fail"]["switch_to_kill"]
591 k8s_switch_node = main.params["UP4"]["UP4_dataplane_fail"]["k8s_switch_node"]
592 k8s_label = main.params["UP4"]["UP4_dataplane_fail"]["k8s_label"]
593 k8s_label_value_test = main.params["UP4"]["UP4_dataplane_fail"]["k8s_label_value_test"]
594 k8s_label_value_normal = main.params["UP4"]["UP4_dataplane_fail"]["k8s_label_value_normal"]
Daniele Moro522023c2021-10-15 17:30:33 +0200595
596 run.initTest(main)
597 main.log.info(main.Cluster.numCtrls)
598 main.Cluster.setRunningNode(3)
599 run.installOnos(main, skipPackage=True, cliSleep=5)
600
601 onos_cli = main.Cluster.active(0).CLI
Daniele Moro80271cb2021-11-11 20:08:51 +0100602 kubectl = main.Cluster.active(0).Bench
603 kubeconfig = main.Cluster.active(0).k8s.kubeConfig
604 namespace = main.params['kubernetes']['namespace']
Daniele Moro522023c2021-10-15 17:30:33 +0200605
606 up4 = UP4()
607
608 initial_flow_count = onos_cli.checkFlowCount()
609
610 main.step("Program and Verify PDRs and FARs via UP4")
611 up4.setup(main.Cluster.active(0).p4rtUp4)
612 up4.attachUes()
613 up4.verifyUp4Flow(onos_cli)
614
615 run.checkFlows(
616 main,
617 minFlowCount=initial_flow_count+(len(up4.emulated_ues)*4*n_switches)
618 )
619
Daniele Moro80271cb2021-11-11 20:08:51 +0100620 main.step("Set label to switch k8s node and kill switch")
621 # K8s node name correspond to the switch name in lowercase
Daniele Moro522023c2021-10-15 17:30:33 +0200622 utilities.assert_equal(
Daniele Moro80271cb2021-11-11 20:08:51 +0100623 expect=main.TRUE,
624 actual=kubectl.kubectlSetLabel(
625 nodeName=k8s_switch_node,
626 label=k8s_label,
627 value=k8s_label_value_test,
628 kubeconfig=kubeconfig,
629 namespace=namespace,
630 ),
631 onpass="Label has been set correctly on node %s" % k8s_switch_node,
632 onfail="Label has not been set on node %s" % k8s_switch_node
Daniele Moro522023c2021-10-15 17:30:33 +0200633 )
Daniele Moro80271cb2021-11-11 20:08:51 +0100634 try:
635 def checkNumberStratumPods(n_value):
636 pods = kubectl.kubectlGetPodNames(
637 kubeconfig=kubeconfig,
638 namespace=namespace,
639 name="stratum"
640 )
641 main.log.info("PODS: " + str(pods))
642 return n_value == len(pods) if pods is not main.FALSE else False
643 # Execute the following in try/except/finally to be sure to restore the
644 # k8s label even in case of unhandled exception.
Daniele Moro522023c2021-10-15 17:30:33 +0200645
Daniele Moro80271cb2021-11-11 20:08:51 +0100646 # Wait for stratum pod to be removed from the switch
647 removed = utilities.retry(checkNumberStratumPods,
648 False,
649 args=[n_switches-1],
650 attempts=50
651 )
652 main.log.info("Stratum has been removed from the switch? %s" % removed)
Daniele Moro522023c2021-10-15 17:30:33 +0200653
Daniele Moro80271cb2021-11-11 20:08:51 +0100654 switch_component = getattr(main, switch_to_kill)
655 switch_component.handle.sendline("sudo reboot")
Daniele Moro522023c2021-10-15 17:30:33 +0200656
Daniele Moro80271cb2021-11-11 20:08:51 +0100657 sleepTime = 20
658 main.log.info("Sleeping %s seconds for Fabric to react" % sleepTime)
659 time.sleep(sleepTime)
Daniele Moro522023c2021-10-15 17:30:33 +0200660
Daniele Moro80271cb2021-11-11 20:08:51 +0100661 available = utilities.retry(SRStagingTest.switchIsConnected,
662 True,
663 args=[switch_component],
664 attempts=300,
665 getRetryingTime=True)
666 main.log.info("Switch %s is available in ONOS? %s" % (
667 switch_to_kill, available))
668 utilities.assert_equal(
669 expect=True,
670 actual=not available and removed,
671 onpass="Switch was rebooted (ONL reboot) successfully and stratum" +
672 " removed from switch k8s node",
673 onfail="Switch was not rebooted (ONL reboot) successfully or stratum " +
674 "not removed from switch k8s node"
675 )
676
677 enodebs_fail = main.params["UP4"]["UP4_dataplane_fail"]["enodebs_fail"].split(",")
678 enodebs_no_fail = list(set(up4.enodebs.keys()) - set(enodebs_fail))
679
680 # ------- Test Upstream traffic (enbs->pdn)
681 main.step("Test upstream traffic FAIL")
682 up4.testUpstreamTraffic(enb_names=enodebs_fail, shouldFail=True)
683 main.step("Test upstream traffic NO FAIL")
684 up4.testUpstreamTraffic(enb_names=enodebs_no_fail, shouldFail=False)
685
686 # ------- Test Downstream traffic (pdn->enbs)
687 main.step("Test downstream traffic FAIL")
688 up4.testDownstreamTraffic(enb_names=enodebs_fail, shouldFail=True)
689 main.step("Test downstream traffic NO FAIL")
690 up4.testDownstreamTraffic(enb_names=enodebs_no_fail, shouldFail=False)
691 except Exception as e:
692 main.log.error("Unhandled exception!")
693 main.log.error(e)
694 finally:
695 utilities.assert_equal(
696 expect=main.TRUE,
697 actual=kubectl.kubectlSetLabel(
698 nodeName=k8s_switch_node,
699 label=k8s_label,
700 value=k8s_label_value_normal,
701 kubeconfig=kubeconfig,
702 namespace=namespace,
703 ),
704 onpass="Label has been set correctly on node %s" % k8s_switch_node,
705 onfail="Label has not been set on node %s" % k8s_switch_node
706 )
707 # Reconnect to the switch
708 connect = utilities.retry(switch_component.connect,
709 main.FALSE,
710 attempts=30,
711 getRetryingTime=True)
712 main.log.info("Connected to the switch %s? %s" % (
713 switch_to_kill, connect))
714
715 # Wait for stratum pod to be re-deployed on the switch
716 deployed = utilities.retry(checkNumberStratumPods,
717 False,
718 args=[n_switches],
719 attempts=50
720 )
721 main.log.info("Stratum has been redeployed on the switch? %s" % deployed)
722
723 # Wait switch to be back in ONOS
724 available = utilities.retry(SRStagingTest.switchIsConnected,
725 False,
726 args=[switch_component],
727 attempts=300,
728 getRetryingTime=True)
729 main.log.info("Switch %s is available in ONOS? %s" % (
730 switch_to_kill, available))
731 utilities.assert_equal(
732 expect=True,
733 actual=available and connect == main.TRUE and deployed,
734 onpass="Switch is back available in ONOS and stratum has been redeployed",
735 onfail="Switch is not available in ONOS, may influence subsequent tests!"
736 )
Daniele Moro522023c2021-10-15 17:30:33 +0200737
738 main.step("Test upstream traffic AFTER switch reboot")
739 up4.testUpstreamTraffic()
740
741 main.step("Cleanup PDRs and FARs via UP4")
742 up4.detachUes()
743 up4.verifyNoUesFlow(onos_cli)
744 up4.teardown()
745
746 run.checkFlows(main, minFlowCount=initial_flow_count)
747
748 # Teardown
749 run.cleanup(main)
Daniele Moro80271cb2021-11-11 20:08:51 +0100750