blob: 14b845fa3055d0a7b45b76b53672b0c8ec1d95cb [file] [log] [blame]
Daniele Moro790cc102021-08-30 18:27:30 +02001class UP4:
2
3 def __init__(self):
4 self.default = ''
5
6 # TODO: add test case that checks entries are being inserted and deleted from ONOS correclty
7 def CASE1(self, main):
Daniele Morobf53dec2021-09-13 18:11:56 +02008 main.case("Fabric UPF traffic terminated in the fabric")
Daniele Moro790cc102021-08-30 18:27:30 +02009 """
Daniele Morobf53dec2021-09-13 18:11:56 +020010 Program PDRs and FARs for UEs
11 Verify PDRs and FARs
Daniele Moro790cc102021-08-30 18:27:30 +020012 Generate traffic from UE to PDN
13 Verify traffic received from PDN
14 Generate traffic from PDN to UE
15 Verify traffic received from UE
Daniele Morobf53dec2021-09-13 18:11:56 +020016 Remove PDRs and FARs for UEs
17 Verify removed PDRs and FARs
Daniele Moro790cc102021-08-30 18:27:30 +020018 """
Daniele Moro790cc102021-08-30 18:27:30 +020019 try:
Daniele Moro80889562021-09-08 10:09:26 +020020 from tests.USECASE.SegmentRouting.dependencies.up4 import UP4
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()
27
Daniele Moro790cc102021-08-30 18:27:30 +020028 run.initTest(main)
29 main.log.info(main.Cluster.numCtrls)
30 main.Cluster.setRunningNode(3)
31 run.installOnos(main, skipPackage=True, cliSleep=5)
32
Daniele Moro790cc102021-08-30 18:27:30 +020033 main.step("Start scapy and p4rt client")
Daniele Morobf53dec2021-09-13 18:11:56 +020034 # Use the first available ONOS instance CLI
35 onos_cli = main.Cluster.active(0).CLI
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 Morobf53dec2021-09-13 18:11:56 +020040 main.step("Program PDRs and FARs via UP4")
Daniele Moro80889562021-09-08 10:09:26 +020041 up4.attachUes()
Daniele Moro790cc102021-08-30 18:27:30 +020042
Daniele Morobf53dec2021-09-13 18:11:56 +020043 main.step("Verify PDRs and FARs in ONOS")
44 up4.verifyUp4Flow(onos_cli)
45
Daniele Moro80889562021-09-08 10:09:26 +020046 # ------- Test Upstream traffic (enb->pdn)
Daniele Moro790cc102021-08-30 18:27:30 +020047 main.step("Test upstream traffic")
Daniele Moro80889562021-09-08 10:09:26 +020048 up4.testUpstreamTraffic()
Daniele Moro790cc102021-08-30 18:27:30 +020049
Daniele Moro80889562021-09-08 10:09:26 +020050 # ------- Test Downstream traffic (pdn->enb)
Daniele Moro790cc102021-08-30 18:27:30 +020051 main.step("Test downstream traffic")
Daniele Moro80889562021-09-08 10:09:26 +020052 up4.testDownstreamTraffic()
Daniele Moro790cc102021-08-30 18:27:30 +020053
Daniele Morobf53dec2021-09-13 18:11:56 +020054 main.step("Remove PDRs and FARs via UP4")
Daniele Moro80889562021-09-08 10:09:26 +020055 up4.detachUes()
Daniele Moro790cc102021-08-30 18:27:30 +020056
Daniele Morobf53dec2021-09-13 18:11:56 +020057 main.step("Verify removed PDRs and FARs from ONOS")
58 up4.verifyNoUesFlow(onos_cli)
59
Daniele Moro790cc102021-08-30 18:27:30 +020060 main.step("Stop scapy and p4rt client")
Daniele Moro80889562021-09-08 10:09:26 +020061 up4.teardown()
Daniele Moro790cc102021-08-30 18:27:30 +020062 run.cleanup(main)
Daniele Morobf53dec2021-09-13 18:11:56 +020063
64 def CASE2(self):
65 main.case("BESS traffic routed")
66 """
67 Program PDRs and FARs for UEs managed via UP4
68 Verify PDRs and FARs
69 Verify Upstream Traffic: eNB -> Fabric -> BESS (encapped)
70 Verify Upstream Traffic: BESS -> Fabric -> PDN (not encapped)
71 Verify Downstream Traffic: PDN -> Fabric -> BESS (not encapped)
72 Verify Downstream Traffic: BESS -> Fabric -> eNB (encapped)
73 Remove PDRs and FARs for UEs managed via UP4
74 Verify removed PDRs and FARs
75 """
76 BESS_TEID = 300
77 BESS_UE_ADDR = "10.241.0.1"
78 GPDU_PORT = 2152
79 UE_PORT = 400
80 PDN_PORT = 800
81 try:
82 from tests.USECASE.SegmentRouting.dependencies.up4 import UP4
83 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import \
84 Testcaselib as run
85 except ImportError as e:
86 main.log.error("Import not found. Exiting the test")
87 main.log.error(e)
88 main.cleanAndExit()
89
90 run.initTest(main)
91 main.log.info(main.Cluster.numCtrls)
92 main.Cluster.setRunningNode(3)
93 run.installOnos(main, skipPackage=True, cliSleep=5)
94
95 main.step("Start scapy and p4rt client + Scapy on BESS Host")
96 # Use the first available ONOS instance CLI
97 onos_cli = main.Cluster.active(0).CLI
98 up4 = UP4()
99 # Get the P4RT client connected to UP4 in the first available ONOS instance
100 up4.setup(main.Cluster.active(0).p4rtUp4)
101
102 # Setup the emulated BESS host and required parameters
103 bess_host = main.Compute2 # FIXME: Parametrize?
104 bess_interface = bess_host.interfaces[0]
105 bess_s1u_address = bess_interface["ips"][0]
106 bess_host.startScapy(ifaceName=bess_interface["name"], enableGtp=True)
107 enodeb_host = up4.enodeb_host
108 enodeb_interface = up4.enodeb_interface
109 pdn_host = up4.pdn_host
110 pdn_interface = up4.pdn_interface
111
112 main.step("Program PDRs and FARs for UEs via UP4")
113 up4.attachUes()
114
115 main.step("Verify PDRs and FARs in ONOS")
116 up4.verifyUp4Flow(onos_cli)
117
118 # ------------------- UPSTREAM -------------------
119 # ------- eNB -> fabric -> BESS (encapped)
120 main.step("Test upstream eNB -> fabric -> BESS")
121 # Start filter before sending packets, BESS should receive GTP encapped
122 # packets
123 pkt_filter_upstream = "ip and udp src port %d and udp dst port %d and src host %s and dst host %s" % (
124 GPDU_PORT, GPDU_PORT, up4.enb_address, bess_s1u_address)
125 main.log.info("Start listening on %s intf %s" % (
126 bess_host.name, bess_interface["name"]))
127 main.log.debug("BPF Filter BESS Upstream: \n %s" % pkt_filter_upstream)
128 bess_host.startFilter(ifaceName=bess_interface["name"],
129 sniffCount=1,
130 pktFilter=pkt_filter_upstream)
131 # Send GTP Packet
132 UP4.buildGtpPacket(enodeb_host,
133 src_ip_outer=up4.enb_address,
134 dst_ip_outer=bess_s1u_address,
135 src_ip_inner=BESS_UE_ADDR,
136 dst_ip_inner=pdn_interface["ips"][0],
137 src_udp_inner=UE_PORT,
138 dst_udp_inner=PDN_PORT,
139 teid=BESS_TEID)
140 enodeb_host.sendPacket()
141
142 packets = UP4.checkFilterAndGetPackets(bess_host)
143 # FIXME: with newer scapy TEID becomes teid (required for Scapy 2.4.5)
144 n_packets = packets.count("TEID=" + hex(BESS_TEID) + "L ")
145 tot_packets = packets.count('Ether')
146 utilities.assert_equal(expect=True,
147 actual=n_packets == 1 and tot_packets == 1,
148 onpass="BESS correctly received 1 GTP encapped packet",
149 onfail="ERROR: BESS received %d GTP encapped packets and filter captured %d packets" % (
150 n_packets, tot_packets))
151
152 # ------- BESS -> fabric -> PDN (not-encapped)
153 main.step("Test upstream BESS -> fabric -> PDN")
154 # Start filter before sending packets, PDN should receive non-GTP packet
155 pkt_filter_upstream = "ip and udp src port %d and udp dst port %d and src host %s and dst host %s" % (
156 UE_PORT, PDN_PORT, BESS_UE_ADDR, pdn_interface["ips"][0])
157 main.log.info("Start listening on %s intf %s" % (
158 pdn_host.name, pdn_interface["name"]))
159 main.log.debug("BPF Filter PDN Upstream: \n %s" % pkt_filter_upstream)
160 pdn_host.startFilter(ifaceName=pdn_interface["name"],
161 sniffCount=1,
162 pktFilter=pkt_filter_upstream)
163 # Send UDP Packet
164 UP4.buildUdpPacket(bess_host,
165 src_ip=BESS_UE_ADDR,
166 dst_ip=pdn_interface["ips"][0],
167 src_udp=UE_PORT,
168 dst_udp=PDN_PORT)
169 bess_host.sendPacket()
170
171 packets = UP4.checkFilterAndGetPackets(pdn_host)
172 tot_packets = packets.count('Ether')
173 utilities.assert_equal(expect=True,
174 actual=tot_packets == 1,
175 onpass="PDN correctly received 1 packet",
176 onfail="ERROR: PDN received %d packets" % (
177 tot_packets))
178 # ------------------------------------------------
179
180 # ------------------ DOWNSTREAM ------------------
181 # ------- PDN -> fabric -> BESS (not-encapped)
182 main.step("Test downstream PDN -> fabric -> BESS")
183 pkt_filter_downstream = "ip and udp src port %d and udp dst port %d and src host %s and dst host %s" % (
184 PDN_PORT, UE_PORT, pdn_interface["ips"][0], BESS_UE_ADDR)
185 main.log.info("Start listening on %s intf %s" % (
186 bess_host.name, bess_interface["name"]))
187 main.log.debug(
188 "BPF Filter BESS Downstream: \n %s" % pkt_filter_downstream)
189 bess_host.startFilter(ifaceName=bess_interface["name"],
190 sniffCount=1,
191 pktFilter=pkt_filter_downstream)
192 UP4.buildUdpPacket(pdn_host,
193 dst_eth=up4.router_mac,
194 src_ip=pdn_interface["ips"][0],
195 dst_ip=BESS_UE_ADDR,
196 src_udp=PDN_PORT,
197 dst_udp=UE_PORT)
198 pdn_host.sendPacket()
199
200 packets = UP4.checkFilterAndGetPackets(bess_host)
201
202 tot_packets = packets.count('Ether')
203 utilities.assert_equal(expect=True,
204 actual=tot_packets == 1,
205 onpass="BESS correctly received 1 packet",
206 onfail="ERROR: BESS received %d packets" % (
207 tot_packets))
208
209 # ------- BESS -> fabric -> eNB (encapped)
210 main.step("Test downstream BESS -> fabric -> eNB")
211 pkt_filter_downstream = "ip and udp src port %d and udp dst port %d and src host %s and dst host %s" % (
212 GPDU_PORT, GPDU_PORT, bess_s1u_address, up4.enb_address)
213 main.log.info("Start listening on %s intf %s" % (
214 enodeb_host.name, enodeb_interface["name"]))
215 main.log.debug(
216 "BPF Filter BESS Downstream: \n %s" % pkt_filter_downstream)
217 enodeb_host.startFilter(ifaceName=enodeb_interface["name"],
218 sniffCount=1,
219 pktFilter=pkt_filter_downstream)
220 # Build GTP packet from BESS host
221 UP4.buildGtpPacket(bess_host,
222 src_ip_outer=bess_s1u_address,
223 dst_ip_outer=up4.enb_address,
224 src_ip_inner=pdn_interface["ips"][0],
225 dst_ip_inner=BESS_UE_ADDR,
226 src_udp_inner=PDN_PORT,
227 dst_udp_inner=UE_PORT,
228 teid=BESS_TEID)
229 bess_host.sendPacket()
230
231 packets = UP4.checkFilterAndGetPackets(enodeb_host)
232
233 # FIXME: with newer scapy TEID becomes teid (required for Scapy 2.4.5)
234 n_packets = packets.count("TEID=" + hex(BESS_TEID) + "L ")
235 tot_packets = packets.count('Ether')
236 utilities.assert_equal(expect=True,
237 actual=n_packets == 1 and tot_packets == 1,
238 onpass="eNodeB correctly received 1 GTP encapped packet",
239 onfail="ERROR: eNodeb received %d GTP encapped packets and filter captured %d packets" % (
240 n_packets, tot_packets))
241 # ------------------------------------------------
242
243 main.step("Remove PDRs and FARs for UEs via UP4")
244 up4.detachUes()
245
246 main.step("Verify removed PDRs and FARs from ONOS")
247 up4.verifyNoUesFlow(onos_cli)
248
249 main.step("Stop scapy and p4rt client")
250 up4.teardown()
251 bess_host.stopScapy()
252 run.cleanup(main)