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 | a804a40 | 2021-10-08 18:00:56 +0200 | [diff] [blame] | 35 | initial_flow_count = onos_cli.checkFlowCount() |
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 | 93feb02 | 2021-10-04 16:26:23 +0200 | [diff] [blame] | 40 | main.step("Program and Verify PDRs and FARs via UP4") |
Daniele Moro | 8088956 | 2021-09-08 10:09:26 +0200 | [diff] [blame] | 41 | up4.attachUes() |
Daniele Moro | bf53dec | 2021-09-13 18:11:56 +0200 | [diff] [blame] | 42 | up4.verifyUp4Flow(onos_cli) |
| 43 | |
Daniele Moro | a804a40 | 2021-10-08 18:00:56 +0200 | [diff] [blame] | 44 | run.checkFlows(main, minFlowCount=initial_flow_count+(up4.emulated_ues*2)) |
| 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 | 93feb02 | 2021-10-04 16:26:23 +0200 | [diff] [blame] | 54 | main.step("Remove and Verify PDRs and FARs via UP4") |
Daniele Moro | 8088956 | 2021-09-08 10:09:26 +0200 | [diff] [blame] | 55 | up4.detachUes() |
Daniele Moro | bf53dec | 2021-09-13 18:11:56 +0200 | [diff] [blame] | 56 | up4.verifyNoUesFlow(onos_cli) |
| 57 | |
Daniele Moro | a804a40 | 2021-10-08 18:00:56 +0200 | [diff] [blame] | 58 | run.checkFlows(main, minFlowCount=initial_flow_count) |
| 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 | |
Daniele Moro | a804a40 | 2021-10-08 18:00:56 +0200 | [diff] [blame] | 64 | def CASE2(self, main): |
Daniele Moro | bf53dec | 2021-09-13 18:11:56 +0200 | [diff] [blame] | 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 |
Daniele Moro | a804a40 | 2021-10-08 18:00:56 +0200 | [diff] [blame] | 98 | initial_flow_count = onos_cli.checkFlowCount() |
Daniele Moro | bf53dec | 2021-09-13 18:11:56 +0200 | [diff] [blame] | 99 | up4 = UP4() |
| 100 | # Get the P4RT client connected to UP4 in the first available ONOS instance |
| 101 | up4.setup(main.Cluster.active(0).p4rtUp4) |
| 102 | |
| 103 | # Setup the emulated BESS host and required parameters |
| 104 | bess_host = main.Compute2 # FIXME: Parametrize? |
| 105 | bess_interface = bess_host.interfaces[0] |
| 106 | bess_s1u_address = bess_interface["ips"][0] |
| 107 | bess_host.startScapy(ifaceName=bess_interface["name"], enableGtp=True) |
| 108 | enodeb_host = up4.enodeb_host |
| 109 | enodeb_interface = up4.enodeb_interface |
| 110 | pdn_host = up4.pdn_host |
| 111 | pdn_interface = up4.pdn_interface |
| 112 | |
Daniele Moro | 93feb02 | 2021-10-04 16:26:23 +0200 | [diff] [blame] | 113 | main.step("Program and Verify PDRs and FARs for UEs via UP4") |
Daniele Moro | bf53dec | 2021-09-13 18:11:56 +0200 | [diff] [blame] | 114 | up4.attachUes() |
Daniele Moro | bf53dec | 2021-09-13 18:11:56 +0200 | [diff] [blame] | 115 | up4.verifyUp4Flow(onos_cli) |
| 116 | |
Daniele Moro | a804a40 | 2021-10-08 18:00:56 +0200 | [diff] [blame] | 117 | run.checkFlows(main, minFlowCount=initial_flow_count+(up4.emulated_ues*2)) |
| 118 | |
Daniele Moro | bf53dec | 2021-09-13 18:11:56 +0200 | [diff] [blame] | 119 | # ------------------- UPSTREAM ------------------- |
| 120 | # ------- eNB -> fabric -> BESS (encapped) |
| 121 | main.step("Test upstream eNB -> fabric -> BESS") |
| 122 | # Start filter before sending packets, BESS should receive GTP encapped |
| 123 | # packets |
| 124 | pkt_filter_upstream = "ip and udp src port %d and udp dst port %d and src host %s and dst host %s" % ( |
| 125 | GPDU_PORT, GPDU_PORT, up4.enb_address, bess_s1u_address) |
| 126 | main.log.info("Start listening on %s intf %s" % ( |
| 127 | bess_host.name, bess_interface["name"])) |
| 128 | main.log.debug("BPF Filter BESS Upstream: \n %s" % pkt_filter_upstream) |
| 129 | bess_host.startFilter(ifaceName=bess_interface["name"], |
| 130 | sniffCount=1, |
| 131 | pktFilter=pkt_filter_upstream) |
| 132 | # Send GTP Packet |
| 133 | UP4.buildGtpPacket(enodeb_host, |
| 134 | src_ip_outer=up4.enb_address, |
| 135 | dst_ip_outer=bess_s1u_address, |
| 136 | src_ip_inner=BESS_UE_ADDR, |
| 137 | dst_ip_inner=pdn_interface["ips"][0], |
| 138 | src_udp_inner=UE_PORT, |
| 139 | dst_udp_inner=PDN_PORT, |
| 140 | teid=BESS_TEID) |
| 141 | enodeb_host.sendPacket() |
| 142 | |
| 143 | packets = UP4.checkFilterAndGetPackets(bess_host) |
| 144 | # FIXME: with newer scapy TEID becomes teid (required for Scapy 2.4.5) |
| 145 | n_packets = packets.count("TEID=" + hex(BESS_TEID) + "L ") |
| 146 | tot_packets = packets.count('Ether') |
| 147 | utilities.assert_equal(expect=True, |
| 148 | actual=n_packets == 1 and tot_packets == 1, |
| 149 | onpass="BESS correctly received 1 GTP encapped packet", |
| 150 | onfail="ERROR: BESS received %d GTP encapped packets and filter captured %d packets" % ( |
| 151 | n_packets, tot_packets)) |
| 152 | |
| 153 | # ------- BESS -> fabric -> PDN (not-encapped) |
| 154 | main.step("Test upstream BESS -> fabric -> PDN") |
| 155 | # Start filter before sending packets, PDN should receive non-GTP packet |
| 156 | pkt_filter_upstream = "ip and udp src port %d and udp dst port %d and src host %s and dst host %s" % ( |
| 157 | UE_PORT, PDN_PORT, BESS_UE_ADDR, pdn_interface["ips"][0]) |
| 158 | main.log.info("Start listening on %s intf %s" % ( |
| 159 | pdn_host.name, pdn_interface["name"])) |
| 160 | main.log.debug("BPF Filter PDN Upstream: \n %s" % pkt_filter_upstream) |
| 161 | pdn_host.startFilter(ifaceName=pdn_interface["name"], |
| 162 | sniffCount=1, |
| 163 | pktFilter=pkt_filter_upstream) |
| 164 | # Send UDP Packet |
| 165 | UP4.buildUdpPacket(bess_host, |
| 166 | src_ip=BESS_UE_ADDR, |
| 167 | dst_ip=pdn_interface["ips"][0], |
| 168 | src_udp=UE_PORT, |
| 169 | dst_udp=PDN_PORT) |
| 170 | bess_host.sendPacket() |
| 171 | |
| 172 | packets = UP4.checkFilterAndGetPackets(pdn_host) |
| 173 | tot_packets = packets.count('Ether') |
| 174 | utilities.assert_equal(expect=True, |
| 175 | actual=tot_packets == 1, |
| 176 | onpass="PDN correctly received 1 packet", |
| 177 | onfail="ERROR: PDN received %d packets" % ( |
| 178 | tot_packets)) |
| 179 | # ------------------------------------------------ |
| 180 | |
| 181 | # ------------------ DOWNSTREAM ------------------ |
| 182 | # ------- PDN -> fabric -> BESS (not-encapped) |
| 183 | main.step("Test downstream PDN -> fabric -> BESS") |
| 184 | pkt_filter_downstream = "ip and udp src port %d and udp dst port %d and src host %s and dst host %s" % ( |
| 185 | PDN_PORT, UE_PORT, pdn_interface["ips"][0], BESS_UE_ADDR) |
| 186 | main.log.info("Start listening on %s intf %s" % ( |
| 187 | bess_host.name, bess_interface["name"])) |
| 188 | main.log.debug( |
| 189 | "BPF Filter BESS Downstream: \n %s" % pkt_filter_downstream) |
| 190 | bess_host.startFilter(ifaceName=bess_interface["name"], |
| 191 | sniffCount=1, |
| 192 | pktFilter=pkt_filter_downstream) |
| 193 | UP4.buildUdpPacket(pdn_host, |
| 194 | dst_eth=up4.router_mac, |
| 195 | src_ip=pdn_interface["ips"][0], |
| 196 | dst_ip=BESS_UE_ADDR, |
| 197 | src_udp=PDN_PORT, |
| 198 | dst_udp=UE_PORT) |
| 199 | pdn_host.sendPacket() |
| 200 | |
| 201 | packets = UP4.checkFilterAndGetPackets(bess_host) |
| 202 | |
| 203 | tot_packets = packets.count('Ether') |
| 204 | utilities.assert_equal(expect=True, |
| 205 | actual=tot_packets == 1, |
| 206 | onpass="BESS correctly received 1 packet", |
| 207 | onfail="ERROR: BESS received %d packets" % ( |
| 208 | tot_packets)) |
| 209 | |
| 210 | # ------- BESS -> fabric -> eNB (encapped) |
| 211 | main.step("Test downstream BESS -> fabric -> eNB") |
| 212 | pkt_filter_downstream = "ip and udp src port %d and udp dst port %d and src host %s and dst host %s" % ( |
| 213 | GPDU_PORT, GPDU_PORT, bess_s1u_address, up4.enb_address) |
| 214 | main.log.info("Start listening on %s intf %s" % ( |
| 215 | enodeb_host.name, enodeb_interface["name"])) |
| 216 | main.log.debug( |
| 217 | "BPF Filter BESS Downstream: \n %s" % pkt_filter_downstream) |
| 218 | enodeb_host.startFilter(ifaceName=enodeb_interface["name"], |
| 219 | sniffCount=1, |
| 220 | pktFilter=pkt_filter_downstream) |
| 221 | # Build GTP packet from BESS host |
| 222 | UP4.buildGtpPacket(bess_host, |
| 223 | src_ip_outer=bess_s1u_address, |
| 224 | dst_ip_outer=up4.enb_address, |
| 225 | src_ip_inner=pdn_interface["ips"][0], |
| 226 | dst_ip_inner=BESS_UE_ADDR, |
| 227 | src_udp_inner=PDN_PORT, |
| 228 | dst_udp_inner=UE_PORT, |
| 229 | teid=BESS_TEID) |
| 230 | bess_host.sendPacket() |
| 231 | |
| 232 | packets = UP4.checkFilterAndGetPackets(enodeb_host) |
| 233 | |
| 234 | # FIXME: with newer scapy TEID becomes teid (required for Scapy 2.4.5) |
| 235 | n_packets = packets.count("TEID=" + hex(BESS_TEID) + "L ") |
| 236 | tot_packets = packets.count('Ether') |
| 237 | utilities.assert_equal(expect=True, |
| 238 | actual=n_packets == 1 and tot_packets == 1, |
| 239 | onpass="eNodeB correctly received 1 GTP encapped packet", |
| 240 | onfail="ERROR: eNodeb received %d GTP encapped packets and filter captured %d packets" % ( |
| 241 | n_packets, tot_packets)) |
| 242 | # ------------------------------------------------ |
| 243 | |
Daniele Moro | 93feb02 | 2021-10-04 16:26:23 +0200 | [diff] [blame] | 244 | main.step("Remove and Verify PDRs and FARs for UEs via UP4") |
Daniele Moro | bf53dec | 2021-09-13 18:11:56 +0200 | [diff] [blame] | 245 | up4.detachUes() |
Daniele Moro | bf53dec | 2021-09-13 18:11:56 +0200 | [diff] [blame] | 246 | up4.verifyNoUesFlow(onos_cli) |
| 247 | |
Daniele Moro | a804a40 | 2021-10-08 18:00:56 +0200 | [diff] [blame] | 248 | run.checkFlows(main, minFlowCount=initial_flow_count) |
| 249 | |
Daniele Moro | bf53dec | 2021-09-13 18:11:56 +0200 | [diff] [blame] | 250 | main.step("Stop scapy and p4rt client") |
| 251 | up4.teardown() |
| 252 | bess_host.stopScapy() |
| 253 | run.cleanup(main) |
Daniele Moro | 954e228 | 2021-09-22 17:32:03 +0200 | [diff] [blame] | 254 | |
| 255 | def CASE3(self, main): |
| 256 | main.case("Verify UP4 from different ONOS instances") |
| 257 | """ |
| 258 | Program PDRs and FARs via UP4 on first ONOS instance |
| 259 | Repeat for all ONOS Instances: |
| 260 | Verify PDRs and FARs via P4RT |
| 261 | Disconnect P4RT client |
| 262 | Verify and delete PDRs and FARs via UP4 on the third ONOS instance |
| 263 | Repeat for all ONOS Instance: |
| 264 | Verify removed PDRs and FARs via P4RT |
| 265 | Disconnect P4RT client |
| 266 | """ |
| 267 | try: |
| 268 | from tests.USECASE.SegmentRouting.dependencies.up4 import UP4 |
| 269 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import \ |
| 270 | Testcaselib as run |
| 271 | except ImportError as e: |
| 272 | main.log.error("Import not found. Exiting the test") |
| 273 | main.log.error(e) |
| 274 | main.cleanAndExit() |
| 275 | |
| 276 | run.initTest(main) |
| 277 | main.log.info(main.Cluster.numCtrls) |
| 278 | main.Cluster.setRunningNode(3) |
| 279 | run.installOnos(main, skipPackage=True, cliSleep=5) |
| 280 | |
| 281 | onos_cli_0 = main.Cluster.active(0).CLI |
| 282 | onos_cli_1 = main.Cluster.active(1).CLI |
| 283 | onos_cli_2 = main.Cluster.active(2).CLI |
| 284 | up4_0 = UP4() |
| 285 | up4_1 = UP4() |
| 286 | up4_2 = UP4() |
Daniele Moro | a804a40 | 2021-10-08 18:00:56 +0200 | [diff] [blame] | 287 | initial_flow_count = onos_cli_0.checkFlowCount() |
Daniele Moro | 954e228 | 2021-09-22 17:32:03 +0200 | [diff] [blame] | 288 | |
Daniele Moro | 93feb02 | 2021-10-04 16:26:23 +0200 | [diff] [blame] | 289 | main.step("Program and Verify PDRs and FARs via UP4 on ONOS 0") |
Daniele Moro | 954e228 | 2021-09-22 17:32:03 +0200 | [diff] [blame] | 290 | up4_0.setup(main.Cluster.active(0).p4rtUp4, no_host=True) |
| 291 | up4_0.attachUes() |
| 292 | up4_0.verifyUp4Flow(onos_cli_0) |
| 293 | up4_0.teardown() |
| 294 | |
Daniele Moro | a804a40 | 2021-10-08 18:00:56 +0200 | [diff] [blame] | 295 | run.checkFlows(main, minFlowCount=initial_flow_count+(up4_0.emulated_ues*2)) |
| 296 | |
Daniele Moro | 954e228 | 2021-09-22 17:32:03 +0200 | [diff] [blame] | 297 | main.step("Verify PDRs and FARs number via UP4 P4RT on ONOS 1") |
| 298 | up4_1.setup(main.Cluster.active(1).p4rtUp4, no_host=True) |
| 299 | utilities.assert_equal( |
| 300 | expect=True, |
| 301 | actual=up4_1.verifyUesFlowNumberP4rt(), |
| 302 | onpass="Correct number of PDRs and FARs", |
| 303 | onfail="Wrong number of PDRs and FARs" |
| 304 | ) |
| 305 | up4_1.teardown() |
| 306 | |
| 307 | main.step("Verify PDRs and FARs number via UP4 P4RT on ONOS 2") |
| 308 | up4_2.setup(main.Cluster.active(2).p4rtUp4, no_host=True) |
| 309 | utilities.assert_equal( |
| 310 | expect=True, |
| 311 | actual=up4_2.verifyUesFlowNumberP4rt(), |
| 312 | onpass="Correct number of PDRs and FARs", |
| 313 | onfail="Wrong number of PDRs and FARs" |
| 314 | ) |
| 315 | |
| 316 | main.step("Verify all ONOS instances have the same number of flows") |
| 317 | onos_0_flow_count = onos_cli_0.checkFlowCount() |
| 318 | onos_1_flow_count = onos_cli_1.checkFlowCount() |
| 319 | onos_2_flow_count = onos_cli_2.checkFlowCount() |
| 320 | utilities.assert_equal( |
| 321 | expect=True, |
| 322 | actual=onos_0_flow_count == onos_1_flow_count == onos_2_flow_count, |
| 323 | onpass="All ONOS instances have the same number of flows", |
| 324 | onfail="ONOS instances have different number of flows: (%d, %d, %d)" % ( |
| 325 | onos_0_flow_count, onos_1_flow_count, onos_2_flow_count) |
| 326 | ) |
| 327 | |
Daniele Moro | 93feb02 | 2021-10-04 16:26:23 +0200 | [diff] [blame] | 328 | main.step("Remove and Verify PDRs and FARs via UP4 on ONOS 2") |
Daniele Moro | 954e228 | 2021-09-22 17:32:03 +0200 | [diff] [blame] | 329 | up4_2.detachUes() |
| 330 | up4_2.verifyNoUesFlow(onos_cli_2) |
| 331 | |
Daniele Moro | a804a40 | 2021-10-08 18:00:56 +0200 | [diff] [blame] | 332 | run.checkFlows(main, minFlowCount=initial_flow_count) |
| 333 | |
Daniele Moro | 954e228 | 2021-09-22 17:32:03 +0200 | [diff] [blame] | 334 | main.step("Verify no PDRs and FARs via UP4 P4RT on ONOS 2") |
| 335 | utilities.assert_equal( |
| 336 | expect=True, |
| 337 | actual=up4_2.verifyNoUesFlowNumberP4rt(), |
| 338 | onpass="No PDRs and FARs", |
| 339 | onfail="Stale PDRs and FARs" |
| 340 | ) |
| 341 | up4_2.teardown() |
| 342 | |
| 343 | main.step("Verify no PDRs and FARs via UP4 P4RT on ONOS 1") |
| 344 | up4_1.setup(main.Cluster.active(1).p4rtUp4, no_host=True) |
| 345 | utilities.assert_equal( |
| 346 | expect=True, |
| 347 | actual=up4_1.verifyNoUesFlowNumberP4rt(), |
| 348 | onpass="No PDRs and FARs", |
| 349 | onfail="Stale PDRs and FARs" |
| 350 | ) |
| 351 | up4_1.teardown() |
| 352 | |
| 353 | main.step("Verify no PDRs and FARs via UP4 P4RT on ONOS 0") |
| 354 | up4_0.setup(main.Cluster.active(0).p4rtUp4, no_host=True) |
| 355 | utilities.assert_equal( |
| 356 | expect=True, |
| 357 | actual=up4_0.verifyNoUesFlowNumberP4rt(), |
| 358 | onpass="No PDRs and FARs", |
| 359 | onfail="Stale PDRs and FARs" |
| 360 | ) |
| 361 | up4_0.teardown() |
| 362 | |
| 363 | main.step("Verify all ONOS instances have the same number of flows") |
| 364 | onos_0_flow_count = onos_cli_0.checkFlowCount() |
| 365 | onos_1_flow_count = onos_cli_1.checkFlowCount() |
| 366 | onos_2_flow_count = onos_cli_2.checkFlowCount() |
| 367 | utilities.assert_equal( |
| 368 | expect=True, |
| 369 | actual=onos_0_flow_count == onos_1_flow_count == onos_2_flow_count, |
| 370 | onpass="All ONOS instances have the same number of flows", |
| 371 | onfail="ONOS instances have different number of flows: (%d, %d, %d)" % ( |
Daniele Moro | e1d05eb | 2021-09-23 19:52:30 +0200 | [diff] [blame] | 372 | onos_0_flow_count, onos_1_flow_count, onos_2_flow_count) |
Daniele Moro | 954e228 | 2021-09-22 17:32:03 +0200 | [diff] [blame] | 373 | ) |
| 374 | run.cleanup(main) |
Daniele Moro | e1d05eb | 2021-09-23 19:52:30 +0200 | [diff] [blame] | 375 | |
| 376 | def CASE4(self, main): |
| 377 | main.case("Verify UP4 wipe-out after ONOS reboot") |
| 378 | """ |
| 379 | Program PDRs/FARs |
| 380 | Kill ONOS POD |
| 381 | Verify PDRs/FARs from other ONOS instances |
| 382 | Remove PDRs/FARs |
| 383 | Wait/Verify ONOS is back |
| 384 | Verify no PDRs/FARs from rebooted instance |
| 385 | Re-program PDRs/FARs from rebooted instance |
| 386 | Verify all instances have same number of flows |
| 387 | Remove PDRs/FARs (cleanup) |
| 388 | """ |
| 389 | try: |
| 390 | from tests.USECASE.SegmentRouting.dependencies.up4 import UP4 |
| 391 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import \ |
| 392 | Testcaselib as run |
| 393 | except ImportError as e: |
| 394 | main.log.error("Import not found. Exiting the test") |
| 395 | main.log.error(e) |
| 396 | main.cleanAndExit() |
| 397 | |
| 398 | run.initTest(main) |
| 399 | main.log.info(main.Cluster.numCtrls) |
| 400 | main.Cluster.setRunningNode(3) |
| 401 | run.installOnos(main, skipPackage=True, cliSleep=5) |
| 402 | |
| 403 | onos_cli_0 = main.Cluster.active(0).CLI |
| 404 | onos_cli_1 = main.Cluster.active(1).CLI |
| 405 | onos_cli_2 = main.Cluster.active(2).CLI |
| 406 | kubectl_0 = main.Cluster.active(0).k8s |
| 407 | |
| 408 | up4_0 = UP4() |
| 409 | up4_1 = UP4() |
| 410 | up4_2 = UP4() |
| 411 | |
Daniele Moro | a804a40 | 2021-10-08 18:00:56 +0200 | [diff] [blame] | 412 | initial_flow_count = onos_cli_0.checkFlowCount() |
| 413 | |
Daniele Moro | 93feb02 | 2021-10-04 16:26:23 +0200 | [diff] [blame] | 414 | main.step("Program and Verify PDRs and FARs via UP4 on ONOS 0") |
Daniele Moro | e1d05eb | 2021-09-23 19:52:30 +0200 | [diff] [blame] | 415 | up4_0.setup(main.Cluster.active(0).p4rtUp4, no_host=True) |
| 416 | up4_0.attachUes() |
| 417 | up4_0.verifyUp4Flow(onos_cli_0) |
| 418 | up4_0.teardown() |
| 419 | |
Daniele Moro | a804a40 | 2021-10-08 18:00:56 +0200 | [diff] [blame] | 420 | run.checkFlows(main, minFlowCount=initial_flow_count+(up4_0.emulated_ues*2)) |
| 421 | |
Daniele Moro | e1d05eb | 2021-09-23 19:52:30 +0200 | [diff] [blame] | 422 | onosPod = main.params["UP4_delete_pod"] |
| 423 | # Exit from previous port forwarding, because we need to restore |
| 424 | # port-forwarding after ONOS reboot. |
| 425 | kubectl_0.clearBuffer() |
| 426 | kubectl_0.exitFromProcess() |
| 427 | main.step("Kill " + onosPod) |
| 428 | utilities.assert_equal( |
| 429 | expect=main.TRUE, |
| 430 | actual=kubectl_0.kubectlDeletePod( |
| 431 | podName=onosPod, |
| 432 | kubeconfig=kubectl_0.kubeConfig, |
| 433 | namespace=main.params['kubernetes']['namespace'] |
| 434 | ), |
| 435 | onpass="%s pod correctly deleted" % onosPod, |
| 436 | onfail="%s pod has not been deleted" % onosPod |
| 437 | ) |
| 438 | |
| 439 | main.step("Verify PDRs and FARs number via UP4 P4RT on ONOS 2") |
| 440 | up4_2.setup(main.Cluster.active(2).p4rtUp4, no_host=True) |
| 441 | utilities.assert_equal( |
| 442 | expect=True, |
| 443 | actual=up4_2.verifyUesFlowNumberP4rt(), |
| 444 | onpass="Correct number of PDRs and FARs", |
| 445 | onfail="Wrong number of PDRs and FARs" |
| 446 | ) |
| 447 | |
Daniele Moro | 93feb02 | 2021-10-04 16:26:23 +0200 | [diff] [blame] | 448 | main.step("Remove and Verify PDRs and FARs via UP4 on ONOS 2") |
Daniele Moro | e1d05eb | 2021-09-23 19:52:30 +0200 | [diff] [blame] | 449 | up4_2.detachUes() |
| 450 | up4_2.verifyNoUesFlow(onos_cli_2) |
| 451 | |
Daniele Moro | a804a40 | 2021-10-08 18:00:56 +0200 | [diff] [blame] | 452 | run.checkFlows(main, minFlowCount=initial_flow_count) |
| 453 | |
Daniele Moro | e1d05eb | 2021-09-23 19:52:30 +0200 | [diff] [blame] | 454 | main.step("Verify no PDRs and FARs via UP4 P4RT on ONOS 2") |
| 455 | utilities.assert_equal( |
| 456 | expect=True, |
| 457 | actual=up4_2.verifyNoUesFlowNumberP4rt(), |
| 458 | onpass="No PDRs and FARs", |
| 459 | onfail="Stale PDRs and FARs" |
| 460 | ) |
| 461 | up4_2.teardown() |
| 462 | |
| 463 | main.step("Verify ONOS 0 has restarted correctly") |
| 464 | onosStarted = utilities.retry( |
| 465 | f=kubectl_0.kubectlCheckPodReady, |
| 466 | retValue=main.FALSE, |
| 467 | kwargs={ |
| 468 | "podName": onosPod, |
| 469 | "kubeconfig": kubectl_0.kubeConfig, |
| 470 | "namespace": main.params['kubernetes']['namespace'] |
| 471 | }, |
| 472 | sleep=10, |
| 473 | attempts=10 |
| 474 | ) |
| 475 | utilities.assert_equal( |
| 476 | expect=main.TRUE, |
| 477 | actual=onosStarted, |
| 478 | onpass="%s pod correctly restarted" % onosPod, |
| 479 | onfail="%s pod haven't restarted correctly" % onosPod |
| 480 | ) |
| 481 | |
| 482 | main.step("Verify ONOS cluster is in good shape") |
| 483 | # A bug in kubectl port forwarding doesn't terminate port-forwarding |
| 484 | # when the container changed, nor reconnect correctly to the restarted |
| 485 | # container. |
| 486 | # See: https://github.com/kubernetes/kubectl/issues/686 |
| 487 | # Re-build the port-list for port forwarding |
| 488 | portList = "%s:%s " % (main.Cluster.active(0).CLI.karafPort, 8101) |
| 489 | portList += "%s:%s " % (main.Cluster.active(0).REST.port, 8181) |
| 490 | portList += "%s:%s " % (main.Cluster.active(0).p4rtUp4.p4rtPort, |
| 491 | main.ONOScell.up4Port) |
| 492 | kubectl_0.clearBuffer() |
| 493 | kubectl_0.kubectlPortForward( |
| 494 | onosPod, |
| 495 | portList, |
| 496 | kubectl_0.kubeConfig, |
| 497 | main.params['kubernetes']['namespace'] |
| 498 | ) |
| 499 | onos_cli_0.clearBuffer() # Trigger ONOS CLI reconnection |
| 500 | onosNodesStatus = utilities.retry( |
| 501 | f=main.Cluster.nodesCheck, |
| 502 | retValue=False, |
| 503 | sleep=5, |
| 504 | attempts=10 |
| 505 | ) |
| 506 | utilities.assert_equal( |
| 507 | expect=True, |
| 508 | actual=onosNodesStatus, |
| 509 | onpass="ONOS nodes status correct", |
| 510 | onfail="Wrong ONOS nodes status" |
| 511 | ) |
| 512 | |
| 513 | main.step("Verify no PDRs and FARs via UP4 P4RT on ONOS 0") |
| 514 | up4_0.setup(main.Cluster.active(0).p4rtUp4, no_host=True) |
| 515 | utilities.assert_equal( |
| 516 | expect=True, |
| 517 | actual=up4_0.verifyNoUesFlowNumberP4rt(), |
| 518 | onpass="No PDRs and FARs", |
| 519 | onfail="Stale PDRs and FARs" |
| 520 | ) |
| 521 | |
| 522 | main.step("Re-program PDRs and FARs via UP4 on ONOS 0 after restart") |
| 523 | up4_0.attachUes() |
| 524 | up4_0.verifyUp4Flow(onos_cli_0) |
| 525 | up4_0.teardown() |
| 526 | |
Daniele Moro | a804a40 | 2021-10-08 18:00:56 +0200 | [diff] [blame] | 527 | run.checkFlows(main, minFlowCount=initial_flow_count+(up4_0.emulated_ues*2)) |
| 528 | |
Daniele Moro | e1d05eb | 2021-09-23 19:52:30 +0200 | [diff] [blame] | 529 | main.step("Verify PDRs and FARs via UP4 on ONOS 1") |
| 530 | up4_1.setup(main.Cluster.active(1).p4rtUp4, no_host=True) |
| 531 | up4_1.verifyUp4Flow(onos_cli_1) |
| 532 | |
| 533 | main.step("Verify all ONOS instances have the same number of flows") |
| 534 | onos_0_flow_count = onos_cli_0.checkFlowCount() |
| 535 | onos_1_flow_count = onos_cli_1.checkFlowCount() |
| 536 | onos_2_flow_count = onos_cli_2.checkFlowCount() |
| 537 | utilities.assert_equal( |
| 538 | expect=True, |
| 539 | actual=onos_0_flow_count == onos_1_flow_count == onos_2_flow_count, |
| 540 | onpass="All ONOS instances have the same number of flows", |
| 541 | onfail="ONOS instances have different number of flows: (%d, %d, %d)" % ( |
| 542 | onos_0_flow_count, onos_1_flow_count, onos_2_flow_count) |
| 543 | ) |
| 544 | |
| 545 | main.step("Cleanup PDRs and FARs via UP4 on ONOS 1") |
| 546 | up4_1.detachUes() |
Daniele Moro | 6dfbfef | 2021-09-28 22:44:19 +0200 | [diff] [blame] | 547 | up4_1.verifyNoUesFlow(onos_cli_1) |
Daniele Moro | e1d05eb | 2021-09-23 19:52:30 +0200 | [diff] [blame] | 548 | up4_1.teardown() |
| 549 | |
Daniele Moro | a804a40 | 2021-10-08 18:00:56 +0200 | [diff] [blame] | 550 | run.checkFlows(main, minFlowCount=initial_flow_count) |
| 551 | |
Daniele Moro | e1d05eb | 2021-09-23 19:52:30 +0200 | [diff] [blame] | 552 | run.cleanup(main) |