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)" % ( |
Daniele Moro | e1d05eb | 2021-09-23 19:52:30 +0200 | [diff] [blame^] | 365 | onos_0_flow_count, onos_1_flow_count, onos_2_flow_count) |
Daniele Moro | 954e228 | 2021-09-22 17:32:03 +0200 | [diff] [blame] | 366 | ) |
| 367 | run.cleanup(main) |
Daniele Moro | e1d05eb | 2021-09-23 19:52:30 +0200 | [diff] [blame^] | 368 | |
| 369 | def CASE4(self, main): |
| 370 | main.case("Verify UP4 wipe-out after ONOS reboot") |
| 371 | """ |
| 372 | Program PDRs/FARs |
| 373 | Kill ONOS POD |
| 374 | Verify PDRs/FARs from other ONOS instances |
| 375 | Remove PDRs/FARs |
| 376 | Wait/Verify ONOS is back |
| 377 | Verify no PDRs/FARs from rebooted instance |
| 378 | Re-program PDRs/FARs from rebooted instance |
| 379 | Verify all instances have same number of flows |
| 380 | Remove PDRs/FARs (cleanup) |
| 381 | """ |
| 382 | try: |
| 383 | from tests.USECASE.SegmentRouting.dependencies.up4 import UP4 |
| 384 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import \ |
| 385 | Testcaselib as run |
| 386 | except ImportError as e: |
| 387 | main.log.error("Import not found. Exiting the test") |
| 388 | main.log.error(e) |
| 389 | main.cleanAndExit() |
| 390 | |
| 391 | run.initTest(main) |
| 392 | main.log.info(main.Cluster.numCtrls) |
| 393 | main.Cluster.setRunningNode(3) |
| 394 | run.installOnos(main, skipPackage=True, cliSleep=5) |
| 395 | |
| 396 | onos_cli_0 = main.Cluster.active(0).CLI |
| 397 | onos_cli_1 = main.Cluster.active(1).CLI |
| 398 | onos_cli_2 = main.Cluster.active(2).CLI |
| 399 | kubectl_0 = main.Cluster.active(0).k8s |
| 400 | |
| 401 | up4_0 = UP4() |
| 402 | up4_1 = UP4() |
| 403 | up4_2 = UP4() |
| 404 | |
| 405 | main.step("Program PDRs and FARs via UP4 on ONOS 0") |
| 406 | up4_0.setup(main.Cluster.active(0).p4rtUp4, no_host=True) |
| 407 | up4_0.attachUes() |
| 408 | up4_0.verifyUp4Flow(onos_cli_0) |
| 409 | up4_0.teardown() |
| 410 | |
| 411 | onosPod = main.params["UP4_delete_pod"] |
| 412 | # Exit from previous port forwarding, because we need to restore |
| 413 | # port-forwarding after ONOS reboot. |
| 414 | kubectl_0.clearBuffer() |
| 415 | kubectl_0.exitFromProcess() |
| 416 | main.step("Kill " + onosPod) |
| 417 | utilities.assert_equal( |
| 418 | expect=main.TRUE, |
| 419 | actual=kubectl_0.kubectlDeletePod( |
| 420 | podName=onosPod, |
| 421 | kubeconfig=kubectl_0.kubeConfig, |
| 422 | namespace=main.params['kubernetes']['namespace'] |
| 423 | ), |
| 424 | onpass="%s pod correctly deleted" % onosPod, |
| 425 | onfail="%s pod has not been deleted" % onosPod |
| 426 | ) |
| 427 | |
| 428 | main.step("Verify PDRs and FARs number via UP4 P4RT on ONOS 2") |
| 429 | up4_2.setup(main.Cluster.active(2).p4rtUp4, no_host=True) |
| 430 | utilities.assert_equal( |
| 431 | expect=True, |
| 432 | actual=up4_2.verifyUesFlowNumberP4rt(), |
| 433 | onpass="Correct number of PDRs and FARs", |
| 434 | onfail="Wrong number of PDRs and FARs" |
| 435 | ) |
| 436 | |
| 437 | main.step("Remove PDRs and FARs via UP4 on ONOS 2") |
| 438 | up4_2.detachUes() |
| 439 | up4_2.verifyNoUesFlow(onos_cli_2) |
| 440 | |
| 441 | main.step("Verify no PDRs and FARs via UP4 P4RT on ONOS 2") |
| 442 | utilities.assert_equal( |
| 443 | expect=True, |
| 444 | actual=up4_2.verifyNoUesFlowNumberP4rt(), |
| 445 | onpass="No PDRs and FARs", |
| 446 | onfail="Stale PDRs and FARs" |
| 447 | ) |
| 448 | up4_2.teardown() |
| 449 | |
| 450 | main.step("Verify ONOS 0 has restarted correctly") |
| 451 | onosStarted = utilities.retry( |
| 452 | f=kubectl_0.kubectlCheckPodReady, |
| 453 | retValue=main.FALSE, |
| 454 | kwargs={ |
| 455 | "podName": onosPod, |
| 456 | "kubeconfig": kubectl_0.kubeConfig, |
| 457 | "namespace": main.params['kubernetes']['namespace'] |
| 458 | }, |
| 459 | sleep=10, |
| 460 | attempts=10 |
| 461 | ) |
| 462 | utilities.assert_equal( |
| 463 | expect=main.TRUE, |
| 464 | actual=onosStarted, |
| 465 | onpass="%s pod correctly restarted" % onosPod, |
| 466 | onfail="%s pod haven't restarted correctly" % onosPod |
| 467 | ) |
| 468 | |
| 469 | main.step("Verify ONOS cluster is in good shape") |
| 470 | # A bug in kubectl port forwarding doesn't terminate port-forwarding |
| 471 | # when the container changed, nor reconnect correctly to the restarted |
| 472 | # container. |
| 473 | # See: https://github.com/kubernetes/kubectl/issues/686 |
| 474 | # Re-build the port-list for port forwarding |
| 475 | portList = "%s:%s " % (main.Cluster.active(0).CLI.karafPort, 8101) |
| 476 | portList += "%s:%s " % (main.Cluster.active(0).REST.port, 8181) |
| 477 | portList += "%s:%s " % (main.Cluster.active(0).p4rtUp4.p4rtPort, |
| 478 | main.ONOScell.up4Port) |
| 479 | kubectl_0.clearBuffer() |
| 480 | kubectl_0.kubectlPortForward( |
| 481 | onosPod, |
| 482 | portList, |
| 483 | kubectl_0.kubeConfig, |
| 484 | main.params['kubernetes']['namespace'] |
| 485 | ) |
| 486 | onos_cli_0.clearBuffer() # Trigger ONOS CLI reconnection |
| 487 | onosNodesStatus = utilities.retry( |
| 488 | f=main.Cluster.nodesCheck, |
| 489 | retValue=False, |
| 490 | sleep=5, |
| 491 | attempts=10 |
| 492 | ) |
| 493 | utilities.assert_equal( |
| 494 | expect=True, |
| 495 | actual=onosNodesStatus, |
| 496 | onpass="ONOS nodes status correct", |
| 497 | onfail="Wrong ONOS nodes status" |
| 498 | ) |
| 499 | |
| 500 | main.step("Verify no PDRs and FARs via UP4 P4RT on ONOS 0") |
| 501 | up4_0.setup(main.Cluster.active(0).p4rtUp4, no_host=True) |
| 502 | utilities.assert_equal( |
| 503 | expect=True, |
| 504 | actual=up4_0.verifyNoUesFlowNumberP4rt(), |
| 505 | onpass="No PDRs and FARs", |
| 506 | onfail="Stale PDRs and FARs" |
| 507 | ) |
| 508 | |
| 509 | main.step("Re-program PDRs and FARs via UP4 on ONOS 0 after restart") |
| 510 | up4_0.attachUes() |
| 511 | up4_0.verifyUp4Flow(onos_cli_0) |
| 512 | up4_0.teardown() |
| 513 | |
| 514 | main.step("Verify PDRs and FARs via UP4 on ONOS 1") |
| 515 | up4_1.setup(main.Cluster.active(1).p4rtUp4, no_host=True) |
| 516 | up4_1.verifyUp4Flow(onos_cli_1) |
| 517 | |
| 518 | main.step("Verify all ONOS instances have the same number of flows") |
| 519 | onos_0_flow_count = onos_cli_0.checkFlowCount() |
| 520 | onos_1_flow_count = onos_cli_1.checkFlowCount() |
| 521 | onos_2_flow_count = onos_cli_2.checkFlowCount() |
| 522 | utilities.assert_equal( |
| 523 | expect=True, |
| 524 | actual=onos_0_flow_count == onos_1_flow_count == onos_2_flow_count, |
| 525 | onpass="All ONOS instances have the same number of flows", |
| 526 | onfail="ONOS instances have different number of flows: (%d, %d, %d)" % ( |
| 527 | onos_0_flow_count, onos_1_flow_count, onos_2_flow_count) |
| 528 | ) |
| 529 | |
| 530 | main.step("Cleanup PDRs and FARs via UP4 on ONOS 1") |
| 531 | up4_1.detachUes() |
| 532 | up4_1.verifyNoUesFlow(onos_cli_2) |
| 533 | up4_1.teardown() |
| 534 | |
| 535 | run.cleanup(main) |