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