Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 1 | class 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 Moro | bf53dec | 2021-09-13 18:11:56 +0200 | [diff] [blame^] | 8 | main.case("Fabric UPF traffic terminated in the fabric") |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 9 | """ |
Daniele Moro | bf53dec | 2021-09-13 18:11:56 +0200 | [diff] [blame^] | 10 | Program PDRs and FARs for UEs |
| 11 | Verify PDRs and FARs |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 12 | 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 Moro | bf53dec | 2021-09-13 18:11:56 +0200 | [diff] [blame^] | 16 | Remove PDRs and FARs for UEs |
| 17 | Verify removed PDRs and FARs |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 18 | """ |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 19 | try: |
Daniele Moro | 8088956 | 2021-09-08 10:09:26 +0200 | [diff] [blame] | 20 | from tests.USECASE.SegmentRouting.dependencies.up4 import UP4 |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 21 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import \ |
| 22 | Testcaselib as run |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 23 | except ImportError as e: |
| 24 | main.log.error("Import not found. Exiting the test") |
| 25 | main.log.error(e) |
| 26 | main.cleanAndExit() |
| 27 | |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 28 | 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 Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 33 | main.step("Start scapy and p4rt client") |
Daniele Moro | bf53dec | 2021-09-13 18:11:56 +0200 | [diff] [blame^] | 34 | # Use the first available ONOS instance CLI |
| 35 | onos_cli = main.Cluster.active(0).CLI |
Daniele Moro | 8088956 | 2021-09-08 10:09:26 +0200 | [diff] [blame] | 36 | 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 Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 39 | |
Daniele Moro | bf53dec | 2021-09-13 18:11:56 +0200 | [diff] [blame^] | 40 | main.step("Program PDRs and FARs via UP4") |
Daniele Moro | 8088956 | 2021-09-08 10:09:26 +0200 | [diff] [blame] | 41 | up4.attachUes() |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 42 | |
Daniele Moro | bf53dec | 2021-09-13 18:11:56 +0200 | [diff] [blame^] | 43 | main.step("Verify PDRs and FARs in ONOS") |
| 44 | up4.verifyUp4Flow(onos_cli) |
| 45 | |
Daniele Moro | 8088956 | 2021-09-08 10:09:26 +0200 | [diff] [blame] | 46 | # ------- Test Upstream traffic (enb->pdn) |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 47 | main.step("Test upstream traffic") |
Daniele Moro | 8088956 | 2021-09-08 10:09:26 +0200 | [diff] [blame] | 48 | up4.testUpstreamTraffic() |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 49 | |
Daniele Moro | 8088956 | 2021-09-08 10:09:26 +0200 | [diff] [blame] | 50 | # ------- Test Downstream traffic (pdn->enb) |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 51 | main.step("Test downstream traffic") |
Daniele Moro | 8088956 | 2021-09-08 10:09:26 +0200 | [diff] [blame] | 52 | up4.testDownstreamTraffic() |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 53 | |
Daniele Moro | bf53dec | 2021-09-13 18:11:56 +0200 | [diff] [blame^] | 54 | main.step("Remove PDRs and FARs via UP4") |
Daniele Moro | 8088956 | 2021-09-08 10:09:26 +0200 | [diff] [blame] | 55 | up4.detachUes() |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 56 | |
Daniele Moro | bf53dec | 2021-09-13 18:11:56 +0200 | [diff] [blame^] | 57 | main.step("Verify removed PDRs and FARs from ONOS") |
| 58 | up4.verifyNoUesFlow(onos_cli) |
| 59 | |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 60 | main.step("Stop scapy and p4rt client") |
Daniele Moro | 8088956 | 2021-09-08 10:09:26 +0200 | [diff] [blame] | 61 | up4.teardown() |
Daniele Moro | 790cc10 | 2021-08-30 18:27:30 +0200 | [diff] [blame] | 62 | run.cleanup(main) |
Daniele Moro | bf53dec | 2021-09-13 18:11:56 +0200 | [diff] [blame^] | 63 | |
| 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) |