Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 1 | class UP4: |
| 2 | |
| 3 | def __init__(self): |
| 4 | self.default = '' |
| 5 | |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 6 | def CASE1(self, main): |
Daniele Moro | bf53dec | 2021-09-13 18:11:56 +0200 | [diff] [blame] | 7 | main.case("Fabric UPF traffic terminated in the fabric") |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 8 | """ |
Daniele Moro | bf53dec | 2021-09-13 18:11:56 +0200 | [diff] [blame] | 9 | Program PDRs and FARs for UEs |
| 10 | Verify PDRs and FARs |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 11 | 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 Moro | bf53dec | 2021-09-13 18:11:56 +0200 | [diff] [blame] | 15 | Remove PDRs and FARs for UEs |
| 16 | Verify removed PDRs and FARs |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 17 | """ |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 18 | try: |
Daniele Moro | 8088956 | 2021-09-08 10:09:26 +0200 | [diff] [blame] | 19 | from tests.USECASE.SegmentRouting.dependencies.up4 import UP4 |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 20 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import \ |
| 21 | Testcaselib as run |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 22 | except ImportError as e: |
| 23 | main.log.error("Import not found. Exiting the test") |
| 24 | main.log.error(e) |
| 25 | main.cleanAndExit() |
| 26 | |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 27 | run.initTest(main) |
| 28 | main.log.info(main.Cluster.numCtrls) |
| 29 | main.Cluster.setRunningNode(3) |
| 30 | run.installOnos(main, skipPackage=True, cliSleep=5) |
| 31 | |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 32 | main.step("Start scapy and p4rt client") |
Daniele Moro | bf53dec | 2021-09-13 18:11:56 +0200 | [diff] [blame] | 33 | # Use the first available ONOS instance CLI |
| 34 | onos_cli = main.Cluster.active(0).CLI |
Daniele Moro | 8088956 | 2021-09-08 10:09:26 +0200 | [diff] [blame] | 35 | up4 = UP4() |
| 36 | # Get the P4RT client connected to UP4 in the first available ONOS instance |
| 37 | up4.setup(main.Cluster.active(0).p4rtUp4) |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 38 | |
Daniele Moro | bf53dec | 2021-09-13 18:11:56 +0200 | [diff] [blame] | 39 | main.step("Program PDRs and FARs via UP4") |
Daniele Moro | 8088956 | 2021-09-08 10:09:26 +0200 | [diff] [blame] | 40 | up4.attachUes() |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 41 | |
Daniele Moro | bf53dec | 2021-09-13 18:11:56 +0200 | [diff] [blame] | 42 | main.step("Verify PDRs and FARs in ONOS") |
| 43 | up4.verifyUp4Flow(onos_cli) |
| 44 | |
Daniele Moro | 8088956 | 2021-09-08 10:09:26 +0200 | [diff] [blame] | 45 | # ------- Test Upstream traffic (enb->pdn) |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 46 | main.step("Test upstream traffic") |
Daniele Moro | 8088956 | 2021-09-08 10:09:26 +0200 | [diff] [blame] | 47 | up4.testUpstreamTraffic() |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 48 | |
Daniele Moro | 8088956 | 2021-09-08 10:09:26 +0200 | [diff] [blame] | 49 | # ------- Test Downstream traffic (pdn->enb) |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 50 | main.step("Test downstream traffic") |
Daniele Moro | 8088956 | 2021-09-08 10:09:26 +0200 | [diff] [blame] | 51 | up4.testDownstreamTraffic() |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 52 | |
Daniele Moro | bf53dec | 2021-09-13 18:11:56 +0200 | [diff] [blame] | 53 | main.step("Remove PDRs and FARs via UP4") |
Daniele Moro | 8088956 | 2021-09-08 10:09:26 +0200 | [diff] [blame] | 54 | up4.detachUes() |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 55 | |
Daniele Moro | bf53dec | 2021-09-13 18:11:56 +0200 | [diff] [blame] | 56 | main.step("Verify removed PDRs and FARs from ONOS") |
| 57 | up4.verifyNoUesFlow(onos_cli) |
| 58 | |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 59 | main.step("Stop scapy and p4rt client") |
Daniele Moro | 8088956 | 2021-09-08 10:09:26 +0200 | [diff] [blame] | 60 | up4.teardown() |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 61 | run.cleanup(main) |
Daniele Moro | bf53dec | 2021-09-13 18:11:56 +0200 | [diff] [blame] | 62 | |
| 63 | def CASE2(self): |
| 64 | main.case("BESS traffic routed") |
| 65 | """ |
| 66 | Program PDRs and FARs for UEs managed via UP4 |
| 67 | Verify PDRs and FARs |
| 68 | Verify Upstream Traffic: eNB -> Fabric -> BESS (encapped) |
| 69 | Verify Upstream Traffic: BESS -> Fabric -> PDN (not encapped) |
| 70 | Verify Downstream Traffic: PDN -> Fabric -> BESS (not encapped) |
| 71 | Verify Downstream Traffic: BESS -> Fabric -> eNB (encapped) |
| 72 | Remove PDRs and FARs for UEs managed via UP4 |
| 73 | Verify removed PDRs and FARs |
| 74 | """ |
| 75 | BESS_TEID = 300 |
| 76 | BESS_UE_ADDR = "10.241.0.1" |
| 77 | GPDU_PORT = 2152 |
| 78 | UE_PORT = 400 |
| 79 | PDN_PORT = 800 |
| 80 | try: |
| 81 | from tests.USECASE.SegmentRouting.dependencies.up4 import UP4 |
| 82 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import \ |
| 83 | Testcaselib as run |
| 84 | except ImportError as e: |
| 85 | main.log.error("Import not found. Exiting the test") |
| 86 | main.log.error(e) |
| 87 | main.cleanAndExit() |
| 88 | |
| 89 | run.initTest(main) |
| 90 | main.log.info(main.Cluster.numCtrls) |
| 91 | main.Cluster.setRunningNode(3) |
| 92 | run.installOnos(main, skipPackage=True, cliSleep=5) |
| 93 | |
| 94 | main.step("Start scapy and p4rt client + Scapy on BESS Host") |
| 95 | # Use the first available ONOS instance CLI |
| 96 | onos_cli = main.Cluster.active(0).CLI |
| 97 | up4 = UP4() |
| 98 | # Get the P4RT client connected to UP4 in the first available ONOS instance |
| 99 | up4.setup(main.Cluster.active(0).p4rtUp4) |
| 100 | |
| 101 | # Setup the emulated BESS host and required parameters |
| 102 | bess_host = main.Compute2 # FIXME: Parametrize? |
| 103 | bess_interface = bess_host.interfaces[0] |
| 104 | bess_s1u_address = bess_interface["ips"][0] |
| 105 | bess_host.startScapy(ifaceName=bess_interface["name"], enableGtp=True) |
| 106 | enodeb_host = up4.enodeb_host |
| 107 | enodeb_interface = up4.enodeb_interface |
| 108 | pdn_host = up4.pdn_host |
| 109 | pdn_interface = up4.pdn_interface |
| 110 | |
| 111 | main.step("Program PDRs and FARs for UEs via UP4") |
| 112 | up4.attachUes() |
| 113 | |
| 114 | main.step("Verify PDRs and FARs in ONOS") |
| 115 | up4.verifyUp4Flow(onos_cli) |
| 116 | |
| 117 | # ------------------- UPSTREAM ------------------- |
| 118 | # ------- eNB -> fabric -> BESS (encapped) |
| 119 | main.step("Test upstream eNB -> fabric -> BESS") |
| 120 | # Start filter before sending packets, BESS should receive GTP encapped |
| 121 | # packets |
| 122 | pkt_filter_upstream = "ip and udp src port %d and udp dst port %d and src host %s and dst host %s" % ( |
| 123 | GPDU_PORT, GPDU_PORT, up4.enb_address, bess_s1u_address) |
| 124 | main.log.info("Start listening on %s intf %s" % ( |
| 125 | bess_host.name, bess_interface["name"])) |
| 126 | main.log.debug("BPF Filter BESS Upstream: \n %s" % pkt_filter_upstream) |
| 127 | bess_host.startFilter(ifaceName=bess_interface["name"], |
| 128 | sniffCount=1, |
| 129 | pktFilter=pkt_filter_upstream) |
| 130 | # Send GTP Packet |
| 131 | UP4.buildGtpPacket(enodeb_host, |
| 132 | src_ip_outer=up4.enb_address, |
| 133 | dst_ip_outer=bess_s1u_address, |
| 134 | src_ip_inner=BESS_UE_ADDR, |
| 135 | dst_ip_inner=pdn_interface["ips"][0], |
| 136 | src_udp_inner=UE_PORT, |
| 137 | dst_udp_inner=PDN_PORT, |
| 138 | teid=BESS_TEID) |
| 139 | enodeb_host.sendPacket() |
| 140 | |
| 141 | packets = UP4.checkFilterAndGetPackets(bess_host) |
| 142 | # FIXME: with newer scapy TEID becomes teid (required for Scapy 2.4.5) |
| 143 | n_packets = packets.count("TEID=" + hex(BESS_TEID) + "L ") |
| 144 | tot_packets = packets.count('Ether') |
| 145 | utilities.assert_equal(expect=True, |
| 146 | actual=n_packets == 1 and tot_packets == 1, |
| 147 | onpass="BESS correctly received 1 GTP encapped packet", |
| 148 | onfail="ERROR: BESS received %d GTP encapped packets and filter captured %d packets" % ( |
| 149 | n_packets, tot_packets)) |
| 150 | |
| 151 | # ------- BESS -> fabric -> PDN (not-encapped) |
| 152 | main.step("Test upstream BESS -> fabric -> PDN") |
| 153 | # Start filter before sending packets, PDN should receive non-GTP packet |
| 154 | pkt_filter_upstream = "ip and udp src port %d and udp dst port %d and src host %s and dst host %s" % ( |
| 155 | UE_PORT, PDN_PORT, BESS_UE_ADDR, pdn_interface["ips"][0]) |
| 156 | main.log.info("Start listening on %s intf %s" % ( |
| 157 | pdn_host.name, pdn_interface["name"])) |
| 158 | main.log.debug("BPF Filter PDN Upstream: \n %s" % pkt_filter_upstream) |
| 159 | pdn_host.startFilter(ifaceName=pdn_interface["name"], |
| 160 | sniffCount=1, |
| 161 | pktFilter=pkt_filter_upstream) |
| 162 | # Send UDP Packet |
| 163 | UP4.buildUdpPacket(bess_host, |
| 164 | src_ip=BESS_UE_ADDR, |
| 165 | dst_ip=pdn_interface["ips"][0], |
| 166 | src_udp=UE_PORT, |
| 167 | dst_udp=PDN_PORT) |
| 168 | bess_host.sendPacket() |
| 169 | |
| 170 | packets = UP4.checkFilterAndGetPackets(pdn_host) |
| 171 | tot_packets = packets.count('Ether') |
| 172 | utilities.assert_equal(expect=True, |
| 173 | actual=tot_packets == 1, |
| 174 | onpass="PDN correctly received 1 packet", |
| 175 | onfail="ERROR: PDN received %d packets" % ( |
| 176 | tot_packets)) |
| 177 | # ------------------------------------------------ |
| 178 | |
| 179 | # ------------------ DOWNSTREAM ------------------ |
| 180 | # ------- PDN -> fabric -> BESS (not-encapped) |
| 181 | main.step("Test downstream PDN -> fabric -> BESS") |
| 182 | pkt_filter_downstream = "ip and udp src port %d and udp dst port %d and src host %s and dst host %s" % ( |
| 183 | PDN_PORT, UE_PORT, pdn_interface["ips"][0], BESS_UE_ADDR) |
| 184 | main.log.info("Start listening on %s intf %s" % ( |
| 185 | bess_host.name, bess_interface["name"])) |
| 186 | main.log.debug( |
| 187 | "BPF Filter BESS Downstream: \n %s" % pkt_filter_downstream) |
| 188 | bess_host.startFilter(ifaceName=bess_interface["name"], |
| 189 | sniffCount=1, |
| 190 | pktFilter=pkt_filter_downstream) |
| 191 | UP4.buildUdpPacket(pdn_host, |
| 192 | dst_eth=up4.router_mac, |
| 193 | src_ip=pdn_interface["ips"][0], |
| 194 | dst_ip=BESS_UE_ADDR, |
| 195 | src_udp=PDN_PORT, |
| 196 | dst_udp=UE_PORT) |
| 197 | pdn_host.sendPacket() |
| 198 | |
| 199 | packets = UP4.checkFilterAndGetPackets(bess_host) |
| 200 | |
| 201 | tot_packets = packets.count('Ether') |
| 202 | utilities.assert_equal(expect=True, |
| 203 | actual=tot_packets == 1, |
| 204 | onpass="BESS correctly received 1 packet", |
| 205 | onfail="ERROR: BESS received %d packets" % ( |
| 206 | tot_packets)) |
| 207 | |
| 208 | # ------- BESS -> fabric -> eNB (encapped) |
| 209 | main.step("Test downstream BESS -> fabric -> eNB") |
| 210 | pkt_filter_downstream = "ip and udp src port %d and udp dst port %d and src host %s and dst host %s" % ( |
| 211 | GPDU_PORT, GPDU_PORT, bess_s1u_address, up4.enb_address) |
| 212 | main.log.info("Start listening on %s intf %s" % ( |
| 213 | enodeb_host.name, enodeb_interface["name"])) |
| 214 | main.log.debug( |
| 215 | "BPF Filter BESS Downstream: \n %s" % pkt_filter_downstream) |
| 216 | enodeb_host.startFilter(ifaceName=enodeb_interface["name"], |
| 217 | sniffCount=1, |
| 218 | pktFilter=pkt_filter_downstream) |
| 219 | # Build GTP packet from BESS host |
| 220 | UP4.buildGtpPacket(bess_host, |
| 221 | src_ip_outer=bess_s1u_address, |
| 222 | dst_ip_outer=up4.enb_address, |
| 223 | src_ip_inner=pdn_interface["ips"][0], |
| 224 | dst_ip_inner=BESS_UE_ADDR, |
| 225 | src_udp_inner=PDN_PORT, |
| 226 | dst_udp_inner=UE_PORT, |
| 227 | teid=BESS_TEID) |
| 228 | bess_host.sendPacket() |
| 229 | |
| 230 | packets = UP4.checkFilterAndGetPackets(enodeb_host) |
| 231 | |
| 232 | # FIXME: with newer scapy TEID becomes teid (required for Scapy 2.4.5) |
| 233 | n_packets = packets.count("TEID=" + hex(BESS_TEID) + "L ") |
| 234 | tot_packets = packets.count('Ether') |
| 235 | utilities.assert_equal(expect=True, |
| 236 | actual=n_packets == 1 and tot_packets == 1, |
| 237 | onpass="eNodeB correctly received 1 GTP encapped packet", |
| 238 | onfail="ERROR: eNodeb received %d GTP encapped packets and filter captured %d packets" % ( |
| 239 | n_packets, tot_packets)) |
| 240 | # ------------------------------------------------ |
| 241 | |
| 242 | main.step("Remove PDRs and FARs for UEs via UP4") |
| 243 | up4.detachUes() |
| 244 | |
| 245 | main.step("Verify removed PDRs and FARs from ONOS") |
| 246 | up4.verifyNoUesFlow(onos_cli) |
| 247 | |
| 248 | main.step("Stop scapy and p4rt client") |
| 249 | up4.teardown() |
| 250 | bess_host.stopScapy() |
| 251 | run.cleanup(main) |
Daniele Moro | 954e228 | 2021-09-22 17:32:03 +0200 | [diff] [blame] | 252 | |
| 253 | def CASE3(self, main): |
| 254 | main.case("Verify UP4 from different ONOS instances") |
| 255 | """ |
| 256 | Program PDRs and FARs via UP4 on first ONOS instance |
| 257 | Repeat for all ONOS Instances: |
| 258 | Verify PDRs and FARs via P4RT |
| 259 | Disconnect P4RT client |
| 260 | Verify and delete PDRs and FARs via UP4 on the third ONOS instance |
| 261 | Repeat for all ONOS Instance: |
| 262 | Verify removed PDRs and FARs via P4RT |
| 263 | Disconnect P4RT client |
| 264 | """ |
| 265 | try: |
| 266 | from tests.USECASE.SegmentRouting.dependencies.up4 import UP4 |
| 267 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import \ |
| 268 | Testcaselib as run |
| 269 | except ImportError as e: |
| 270 | main.log.error("Import not found. Exiting the test") |
| 271 | main.log.error(e) |
| 272 | main.cleanAndExit() |
| 273 | |
| 274 | run.initTest(main) |
| 275 | main.log.info(main.Cluster.numCtrls) |
| 276 | main.Cluster.setRunningNode(3) |
| 277 | run.installOnos(main, skipPackage=True, cliSleep=5) |
| 278 | |
| 279 | onos_cli_0 = main.Cluster.active(0).CLI |
| 280 | onos_cli_1 = main.Cluster.active(1).CLI |
| 281 | onos_cli_2 = main.Cluster.active(2).CLI |
| 282 | up4_0 = UP4() |
| 283 | up4_1 = UP4() |
| 284 | up4_2 = UP4() |
| 285 | |
| 286 | main.step("Program PDRs and FARs via UP4 on ONOS 0") |
| 287 | up4_0.setup(main.Cluster.active(0).p4rtUp4, no_host=True) |
| 288 | up4_0.attachUes() |
| 289 | up4_0.verifyUp4Flow(onos_cli_0) |
| 290 | up4_0.teardown() |
| 291 | |
| 292 | main.step("Verify PDRs and FARs number via UP4 P4RT on ONOS 1") |
| 293 | up4_1.setup(main.Cluster.active(1).p4rtUp4, no_host=True) |
| 294 | utilities.assert_equal( |
| 295 | expect=True, |
| 296 | actual=up4_1.verifyUesFlowNumberP4rt(), |
| 297 | onpass="Correct number of PDRs and FARs", |
| 298 | onfail="Wrong number of PDRs and FARs" |
| 299 | ) |
| 300 | up4_1.teardown() |
| 301 | |
| 302 | main.step("Verify PDRs and FARs number via UP4 P4RT on ONOS 2") |
| 303 | up4_2.setup(main.Cluster.active(2).p4rtUp4, no_host=True) |
| 304 | utilities.assert_equal( |
| 305 | expect=True, |
| 306 | actual=up4_2.verifyUesFlowNumberP4rt(), |
| 307 | onpass="Correct number of PDRs and FARs", |
| 308 | onfail="Wrong number of PDRs and FARs" |
| 309 | ) |
| 310 | |
| 311 | main.step("Verify all ONOS instances have the same number of flows") |
| 312 | onos_0_flow_count = onos_cli_0.checkFlowCount() |
| 313 | onos_1_flow_count = onos_cli_1.checkFlowCount() |
| 314 | onos_2_flow_count = onos_cli_2.checkFlowCount() |
| 315 | utilities.assert_equal( |
| 316 | expect=True, |
| 317 | actual=onos_0_flow_count == onos_1_flow_count == onos_2_flow_count, |
| 318 | onpass="All ONOS instances have the same number of flows", |
| 319 | onfail="ONOS instances have different number of flows: (%d, %d, %d)" % ( |
| 320 | onos_0_flow_count, onos_1_flow_count, onos_2_flow_count) |
| 321 | ) |
| 322 | |
| 323 | main.step("Remove PDRs and FARs via UP4 on ONOS 2") |
| 324 | up4_2.detachUes() |
| 325 | up4_2.verifyNoUesFlow(onos_cli_2) |
| 326 | |
| 327 | main.step("Verify no PDRs and FARs via UP4 P4RT on ONOS 2") |
| 328 | utilities.assert_equal( |
| 329 | expect=True, |
| 330 | actual=up4_2.verifyNoUesFlowNumberP4rt(), |
| 331 | onpass="No PDRs and FARs", |
| 332 | onfail="Stale PDRs and FARs" |
| 333 | ) |
| 334 | up4_2.teardown() |
| 335 | |
| 336 | main.step("Verify no PDRs and FARs via UP4 P4RT on ONOS 1") |
| 337 | up4_1.setup(main.Cluster.active(1).p4rtUp4, no_host=True) |
| 338 | utilities.assert_equal( |
| 339 | expect=True, |
| 340 | actual=up4_1.verifyNoUesFlowNumberP4rt(), |
| 341 | onpass="No PDRs and FARs", |
| 342 | onfail="Stale PDRs and FARs" |
| 343 | ) |
| 344 | up4_1.teardown() |
| 345 | |
| 346 | main.step("Verify no PDRs and FARs via UP4 P4RT on ONOS 0") |
| 347 | up4_0.setup(main.Cluster.active(0).p4rtUp4, no_host=True) |
| 348 | utilities.assert_equal( |
| 349 | expect=True, |
| 350 | actual=up4_0.verifyNoUesFlowNumberP4rt(), |
| 351 | onpass="No PDRs and FARs", |
| 352 | onfail="Stale PDRs and FARs" |
| 353 | ) |
| 354 | up4_0.teardown() |
| 355 | |
| 356 | main.step("Verify all ONOS instances have the same number of flows") |
| 357 | onos_0_flow_count = onos_cli_0.checkFlowCount() |
| 358 | onos_1_flow_count = onos_cli_1.checkFlowCount() |
| 359 | onos_2_flow_count = onos_cli_2.checkFlowCount() |
| 360 | utilities.assert_equal( |
| 361 | expect=True, |
| 362 | actual=onos_0_flow_count == onos_1_flow_count == onos_2_flow_count, |
| 363 | onpass="All ONOS instances have the same number of flows", |
| 364 | onfail="ONOS instances have different number of flows: (%d, %d, %d)" % ( |
| 365 | onos_0_flow_count, onos_1_flow_count, onos_2_flow_count) |
| 366 | ) |
| 367 | run.cleanup(main) |