Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.t3.impl; |
| 17 | |
| 18 | import com.google.common.collect.ImmutableList; |
| 19 | import com.google.common.collect.ImmutableSet; |
| 20 | import org.onlab.packet.EthType; |
| 21 | import org.onlab.packet.IpAddress; |
| 22 | import org.onlab.packet.IpPrefix; |
| 23 | import org.onlab.packet.MacAddress; |
Andrea Campanella | 09ca07a | 2018-01-25 16:44:04 +0100 | [diff] [blame] | 24 | import org.onlab.packet.MplsLabel; |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 25 | import org.onlab.packet.VlanId; |
| 26 | import org.onosproject.core.DefaultApplicationId; |
| 27 | import org.onosproject.core.GroupId; |
| 28 | import org.onosproject.net.ConnectPoint; |
| 29 | import org.onosproject.net.DefaultHost; |
| 30 | import org.onosproject.net.DeviceId; |
| 31 | import org.onosproject.net.Host; |
| 32 | import org.onosproject.net.HostId; |
| 33 | import org.onosproject.net.HostLocation; |
| 34 | import org.onosproject.net.PortNumber; |
| 35 | import org.onosproject.net.flow.DefaultFlowEntry; |
| 36 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 37 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 38 | import org.onosproject.net.flow.FlowEntry; |
| 39 | import org.onosproject.net.flow.FlowRule; |
| 40 | import org.onosproject.net.flow.TrafficSelector; |
| 41 | import org.onosproject.net.flow.TrafficTreatment; |
| 42 | import org.onosproject.net.group.DefaultGroup; |
| 43 | import org.onosproject.net.group.DefaultGroupBucket; |
| 44 | import org.onosproject.net.group.Group; |
| 45 | import org.onosproject.net.group.GroupBucket; |
| 46 | import org.onosproject.net.group.GroupBuckets; |
| 47 | import org.onosproject.net.provider.ProviderId; |
| 48 | |
| 49 | /** |
| 50 | * Helper class for objects related to the Troubleshoot Manager Test. |
| 51 | */ |
| 52 | final class T3TestObjects { |
| 53 | |
Andrea Campanella | 7c8e791 | 2018-01-23 12:46:04 +0100 | [diff] [blame] | 54 | private T3TestObjects() { |
Andrea Campanella | 2bc55dd | 2018-01-18 16:54:34 +0100 | [diff] [blame] | 55 | //banning construction |
| 56 | } |
| 57 | |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 58 | private static final String HOST_ONE_MAC = "00:00:00:00:00:01"; |
| 59 | private static final String HOST_TWO_MAC = "00:00:00:00:00:02"; |
| 60 | private static final String HOST_ONE_VLAN = "None"; |
| 61 | private static final String HOST_TWO_VLAN = "None"; |
| 62 | private static final String HOST_ONE = HOST_ONE_MAC + "/" + HOST_ONE_VLAN; |
| 63 | private static final String HOST_TWO = HOST_TWO_MAC + "/" + HOST_TWO_VLAN; |
| 64 | |
Andrea Campanella | 37d1062 | 2018-01-18 17:11:42 +0100 | [diff] [blame] | 65 | //offline device |
| 66 | static final DeviceId OFFLINE_DEVICE = DeviceId.deviceId("offlineDevice"); |
| 67 | |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 68 | //Single Flow Test |
| 69 | static final DeviceId SINGLE_FLOW_DEVICE = DeviceId.deviceId("SingleFlowDevice"); |
| 70 | private static final TrafficSelector SINGLE_FLOW_SELECTOR = DefaultTrafficSelector.builder() |
| 71 | .matchInPort(PortNumber.portNumber(1)) |
| 72 | .matchIPSrc(IpPrefix.valueOf("127.0.0.1/32")) |
| 73 | .matchIPDst(IpPrefix.valueOf("127.0.0.2/32")) |
| 74 | .build(); |
| 75 | |
| 76 | private static final TrafficTreatment OUTPUT_FLOW_TREATMENT = DefaultTrafficTreatment.builder() |
| 77 | .setOutput(PortNumber.portNumber(2)).build(); |
| 78 | private static final FlowRule SINGLE_FLOW = DefaultFlowEntry.builder().forDevice(SINGLE_FLOW_DEVICE) |
| 79 | .forTable(0) |
| 80 | .withPriority(100) |
| 81 | .withSelector(SINGLE_FLOW_SELECTOR) |
| 82 | .withTreatment(OUTPUT_FLOW_TREATMENT) |
| 83 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 84 | .makePermanent() |
| 85 | .build(); |
| 86 | static final FlowEntry SINGLE_FLOW_ENTRY = new DefaultFlowEntry(SINGLE_FLOW); |
| 87 | |
| 88 | static final ConnectPoint SINGLE_FLOW_IN_CP = ConnectPoint.deviceConnectPoint(SINGLE_FLOW_DEVICE + "/" + 1); |
| 89 | |
| 90 | static final ConnectPoint SINGLE_FLOW_OUT_CP = ConnectPoint.deviceConnectPoint(SINGLE_FLOW_DEVICE + "/" + 2); |
| 91 | |
Andrea Campanella | bb9d3fb | 2018-01-22 15:10:30 +0100 | [diff] [blame] | 92 | //same output as input |
| 93 | static final DeviceId SAME_OUTPUT_FLOW_DEVICE = DeviceId.deviceId("sameOutputDevice"); |
| 94 | |
| 95 | private static final TrafficTreatment SAME_OUTPUT_FLOW_TREATMENT = DefaultTrafficTreatment.builder() |
| 96 | .setOutput(PortNumber.portNumber(1)).build(); |
| 97 | private static final FlowRule SAME_OUTPUT_FLOW = DefaultFlowEntry.builder().forDevice(SAME_OUTPUT_FLOW_DEVICE) |
| 98 | .forTable(0) |
| 99 | .withPriority(100) |
| 100 | .withSelector(SINGLE_FLOW_SELECTOR) |
| 101 | .withTreatment(SAME_OUTPUT_FLOW_TREATMENT) |
| 102 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 103 | .makePermanent() |
| 104 | .build(); |
| 105 | static final FlowEntry SAME_OUTPUT_FLOW_ENTRY = new DefaultFlowEntry(SAME_OUTPUT_FLOW); |
| 106 | |
| 107 | static final ConnectPoint SAME_OUTPUT_FLOW_CP = ConnectPoint.deviceConnectPoint(SAME_OUTPUT_FLOW_DEVICE + "/" + 1); |
| 108 | |
Andrea Campanella | 7c8e791 | 2018-01-23 12:46:04 +0100 | [diff] [blame] | 109 | //ARP |
| 110 | static final DeviceId ARP_FLOW_DEVICE = DeviceId.deviceId("ArpDevice"); |
| 111 | |
| 112 | private static final TrafficSelector ARP_FLOW_SELECTOR = DefaultTrafficSelector.builder() |
| 113 | .matchInPort(PortNumber.portNumber(1)) |
| 114 | .matchEthType(EthType.EtherType.ARP.ethType().toShort()) |
| 115 | .build(); |
| 116 | |
| 117 | private static final TrafficTreatment ARP_FLOW_TREATMENT = DefaultTrafficTreatment.builder() |
| 118 | .setOutput(PortNumber.CONTROLLER).build(); |
| 119 | private static final FlowRule ARP_FLOW = DefaultFlowEntry.builder().forDevice(ARP_FLOW_DEVICE) |
| 120 | .forTable(0) |
| 121 | .withPriority(100) |
| 122 | .withSelector(ARP_FLOW_SELECTOR) |
| 123 | .withTreatment(ARP_FLOW_TREATMENT) |
| 124 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 125 | .makePermanent() |
| 126 | .build(); |
| 127 | static final FlowEntry ARP_FLOW_ENTRY = new DefaultFlowEntry(ARP_FLOW); |
| 128 | |
| 129 | static final ConnectPoint ARP_FLOW_CP = ConnectPoint.deviceConnectPoint(ARP_FLOW_DEVICE + "/" + 1); |
| 130 | |
Andrea Campanella | bb9d3fb | 2018-01-22 15:10:30 +0100 | [diff] [blame] | 131 | |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 132 | //Dual Flow Test |
| 133 | static final DeviceId DUAL_FLOW_DEVICE = DeviceId.deviceId("DualFlowDevice"); |
| 134 | private static final TrafficTreatment TRANSITION_FLOW_TREATMENT = DefaultTrafficTreatment.builder() |
| 135 | .setVlanId(VlanId.vlanId((short) 100)) |
| 136 | .transition(10) |
| 137 | .build(); |
| 138 | private static final TrafficSelector VLAN_FLOW_SELECTOR = DefaultTrafficSelector.builder() |
| 139 | .matchVlanId(VlanId.vlanId((short) 100)) |
| 140 | .build(); |
| 141 | private static final FlowRule FIRST_FLOW = DefaultFlowEntry.builder().forDevice(DUAL_FLOW_DEVICE) |
| 142 | .forTable(0) |
| 143 | .withPriority(100) |
| 144 | .withSelector(SINGLE_FLOW_SELECTOR) |
| 145 | .withTreatment(TRANSITION_FLOW_TREATMENT) |
| 146 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 147 | .makePermanent() |
| 148 | .build(); |
| 149 | static final FlowEntry FIRST_FLOW_ENTRY = new DefaultFlowEntry(FIRST_FLOW); |
| 150 | private static final FlowRule SECOND_FLOW = DefaultFlowEntry.builder().forDevice(DUAL_FLOW_DEVICE) |
| 151 | .forTable(10) |
| 152 | .withPriority(100) |
| 153 | .withSelector(VLAN_FLOW_SELECTOR) |
| 154 | .withTreatment(OUTPUT_FLOW_TREATMENT) |
| 155 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 156 | .makePermanent() |
| 157 | .build(); |
| 158 | static final FlowEntry SECOND_FLOW_ENTRY = new DefaultFlowEntry(SECOND_FLOW); |
| 159 | |
| 160 | static final ConnectPoint DUAL_FLOW_IN_CP = ConnectPoint.deviceConnectPoint(DUAL_FLOW_DEVICE + "/" + 1); |
| 161 | |
| 162 | static final ConnectPoint DUAL_FLOW_OUT_CP = ConnectPoint.deviceConnectPoint(DUAL_FLOW_DEVICE + "/" + 2); |
| 163 | |
| 164 | //Flow and Group Test |
| 165 | static final DeviceId GROUP_FLOW_DEVICE = DeviceId.deviceId("GroupFlowDevice"); |
| 166 | |
| 167 | private static final GroupId GROUP_ID = GroupId.valueOf(1); |
| 168 | |
| 169 | private static final TrafficTreatment GROUP_FLOW_TREATMENT = DefaultTrafficTreatment.builder() |
Andrea Campanella | 09ca07a | 2018-01-25 16:44:04 +0100 | [diff] [blame] | 170 | .pushMpls() |
| 171 | .setMpls(MplsLabel.mplsLabel(100)) |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 172 | .group(GROUP_ID) |
| 173 | .build(); |
| 174 | private static final FlowRule GROUP_FLOW = DefaultFlowEntry.builder().forDevice(GROUP_FLOW_DEVICE) |
| 175 | .forTable(0) |
| 176 | .withPriority(100) |
| 177 | .withSelector(SINGLE_FLOW_SELECTOR) |
| 178 | .withTreatment(GROUP_FLOW_TREATMENT) |
| 179 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 180 | .makePermanent() |
| 181 | .build(); |
| 182 | static final FlowEntry GROUP_FLOW_ENTRY = new DefaultFlowEntry(GROUP_FLOW); |
| 183 | |
Andrea Campanella | 09ca07a | 2018-01-25 16:44:04 +0100 | [diff] [blame] | 184 | private static final TrafficTreatment OUTPUT_GROUP_TREATMENT = DefaultTrafficTreatment.builder() |
| 185 | .popMpls(EthType.EtherType.IPV4.ethType()) |
| 186 | .setOutput(PortNumber.portNumber(2)).build(); |
| 187 | |
| 188 | private static final GroupBucket BUCKET = DefaultGroupBucket.createSelectGroupBucket(OUTPUT_GROUP_TREATMENT); |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 189 | |
| 190 | private static final GroupBuckets BUCKETS = new GroupBuckets(ImmutableList.of(BUCKET)); |
| 191 | |
| 192 | static final Group GROUP = new DefaultGroup(GROUP_ID, GROUP_FLOW_DEVICE, Group.Type.SELECT, BUCKETS); |
| 193 | |
| 194 | static final ConnectPoint GROUP_FLOW_IN_CP = ConnectPoint.deviceConnectPoint(GROUP_FLOW_DEVICE + "/" + 1); |
| 195 | |
| 196 | static final ConnectPoint GROUP_FLOW_OUT_CP = ConnectPoint.deviceConnectPoint(GROUP_FLOW_DEVICE + "/" + 2); |
| 197 | |
| 198 | //topology |
| 199 | |
| 200 | static final DeviceId TOPO_FLOW_DEVICE = DeviceId.deviceId("SingleFlowDevice1"); |
| 201 | |
| 202 | static final DeviceId TOPO_FLOW_2_DEVICE = DeviceId.deviceId("SingleFlowDevice2"); |
| 203 | |
| 204 | static final DeviceId TOPO_FLOW_3_DEVICE = DeviceId.deviceId("SingleFlowDevice3"); |
| 205 | |
| 206 | private static final TrafficSelector TOPO_FLOW_SELECTOR = DefaultTrafficSelector.builder() |
| 207 | .matchInPort(PortNumber.portNumber(1)) |
| 208 | .matchIPSrc(IpPrefix.valueOf("127.0.0.1/32")) |
| 209 | .matchIPDst(IpPrefix.valueOf("127.0.0.3/32")) |
| 210 | .build(); |
| 211 | |
| 212 | private static final FlowRule TOPO_SINGLE_FLOW = DefaultFlowEntry.builder().forDevice(TOPO_FLOW_DEVICE) |
| 213 | .forTable(0) |
| 214 | .withPriority(100) |
| 215 | .withSelector(TOPO_FLOW_SELECTOR) |
| 216 | .withTreatment(OUTPUT_FLOW_TREATMENT) |
| 217 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 218 | .makePermanent() |
| 219 | .build(); |
| 220 | |
| 221 | static final FlowEntry TOPO_SINGLE_FLOW_ENTRY = new DefaultFlowEntry(TOPO_SINGLE_FLOW); |
| 222 | |
| 223 | static final ConnectPoint TOPO_FLOW_1_IN_CP = ConnectPoint.deviceConnectPoint(TOPO_FLOW_DEVICE + "/" + 1); |
| 224 | |
| 225 | static final ConnectPoint TOPO_FLOW_1_OUT_CP = ConnectPoint.deviceConnectPoint(TOPO_FLOW_DEVICE + "/" + 2); |
| 226 | |
| 227 | static final ConnectPoint TOPO_FLOW_2_IN_CP = ConnectPoint.deviceConnectPoint(TOPO_FLOW_2_DEVICE + "/" + 1); |
| 228 | |
| 229 | static final ConnectPoint TOPO_FLOW_2_OUT_CP = ConnectPoint.deviceConnectPoint(TOPO_FLOW_2_DEVICE + "/" + 2); |
| 230 | |
| 231 | static final ConnectPoint TOPO_FLOW_3_IN_CP = ConnectPoint.deviceConnectPoint(TOPO_FLOW_3_DEVICE + "/" + 1); |
| 232 | |
| 233 | static final ConnectPoint TOPO_FLOW_3_OUT_CP = ConnectPoint.deviceConnectPoint(TOPO_FLOW_3_DEVICE + "/" + 2); |
| 234 | |
| 235 | |
| 236 | //Topology with Groups |
| 237 | |
| 238 | static final DeviceId TOPO_GROUP_FLOW_DEVICE = DeviceId.deviceId("TopoGroupFlowDevice"); |
| 239 | |
| 240 | private static final TrafficSelector TOPO_SECOND_INPUT_FLOW_SELECTOR = DefaultTrafficSelector.builder() |
| 241 | .matchInPort(PortNumber.portNumber(3)) |
| 242 | .matchIPSrc(IpPrefix.valueOf("127.0.0.1/32")) |
| 243 | .matchIPDst(IpPrefix.valueOf("127.0.0.3/32")) |
| 244 | .build(); |
| 245 | |
| 246 | private static final FlowRule TOPO_SECOND_INPUT_FLOW = DefaultFlowEntry.builder().forDevice(TOPO_FLOW_3_DEVICE) |
| 247 | .forTable(0) |
| 248 | .withPriority(100) |
| 249 | .withSelector(TOPO_SECOND_INPUT_FLOW_SELECTOR) |
| 250 | .withTreatment(OUTPUT_FLOW_TREATMENT) |
| 251 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 252 | .makePermanent() |
| 253 | .build(); |
| 254 | |
| 255 | private static final TrafficTreatment OUTPUT_2_FLOW_TREATMENT = DefaultTrafficTreatment.builder() |
| 256 | .setOutput(PortNumber.portNumber(3)).build(); |
| 257 | |
| 258 | |
| 259 | private static final GroupId TOPO_GROUP_ID = GroupId.valueOf(1); |
| 260 | |
| 261 | private static final TrafficTreatment TOPO_GROUP_FLOW_TREATMENT = DefaultTrafficTreatment.builder() |
| 262 | .group(TOPO_GROUP_ID) |
| 263 | .build(); |
| 264 | private static final FlowRule TOPO_GROUP_FLOW = DefaultFlowEntry.builder().forDevice(TOPO_GROUP_FLOW_DEVICE) |
| 265 | .forTable(0) |
| 266 | .withPriority(100) |
| 267 | .withSelector(TOPO_FLOW_SELECTOR) |
| 268 | .withTreatment(TOPO_GROUP_FLOW_TREATMENT) |
| 269 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 270 | .makePermanent() |
| 271 | .build(); |
| 272 | static final FlowEntry TOPO_GROUP_FLOW_ENTRY = new DefaultFlowEntry(TOPO_GROUP_FLOW); |
| 273 | |
| 274 | private static final GroupBucket BUCKET_2 = DefaultGroupBucket.createSelectGroupBucket(OUTPUT_2_FLOW_TREATMENT); |
| 275 | |
| 276 | private static final GroupBuckets BUCKETS_MULTIPLE = new GroupBuckets(ImmutableList.of(BUCKET, BUCKET_2)); |
| 277 | |
Andrea Campanella | 2bc55dd | 2018-01-18 16:54:34 +0100 | [diff] [blame] | 278 | static final Group TOPO_GROUP = new DefaultGroup(TOPO_GROUP_ID, TOPO_GROUP_FLOW_DEVICE, |
| 279 | Group.Type.SELECT, BUCKETS_MULTIPLE); |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 280 | |
| 281 | static final FlowEntry TOPO_SECOND_INPUT_FLOW_ENTRY = new DefaultFlowEntry(TOPO_SECOND_INPUT_FLOW); |
| 282 | |
| 283 | static final DeviceId TOPO_FLOW_4_DEVICE = DeviceId.deviceId("SingleFlowDevice4"); |
| 284 | |
| 285 | static final ConnectPoint TOPO_FLOW_IN_CP = ConnectPoint.deviceConnectPoint(TOPO_GROUP_FLOW_DEVICE + "/" + 1); |
| 286 | |
| 287 | static final ConnectPoint TOPO_FLOW_OUT_CP_1 = ConnectPoint.deviceConnectPoint(TOPO_GROUP_FLOW_DEVICE + "/" + 2); |
| 288 | |
Andrea Campanella | 2bc55dd | 2018-01-18 16:54:34 +0100 | [diff] [blame] | 289 | protected static final ConnectPoint TOPO_FLOW_OUT_CP_2 = |
| 290 | ConnectPoint.deviceConnectPoint(TOPO_GROUP_FLOW_DEVICE + "/" + 3); |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 291 | |
| 292 | static final ConnectPoint TOPO_FLOW_4_IN_CP = ConnectPoint.deviceConnectPoint(TOPO_FLOW_4_DEVICE + "/" + 1); |
| 293 | |
| 294 | static final ConnectPoint TOPO_FLOW_3_IN_2_CP = ConnectPoint.deviceConnectPoint(TOPO_FLOW_3_DEVICE + "/" + 3); |
| 295 | |
| 296 | static final ConnectPoint TOPO_FLOW_4_OUT_CP = ConnectPoint.deviceConnectPoint(TOPO_FLOW_4_DEVICE + "/" + 2); |
| 297 | |
| 298 | |
| 299 | //hardware |
| 300 | |
| 301 | static final DeviceId HARDWARE_DEVICE = DeviceId.deviceId("HardwareDevice"); |
| 302 | |
| 303 | static final ConnectPoint HARDWARE_DEVICE_IN_CP = ConnectPoint.deviceConnectPoint(HARDWARE_DEVICE + "/" + 1); |
| 304 | |
| 305 | static final ConnectPoint HARDWARE_DEVICE_OUT_CP = ConnectPoint.deviceConnectPoint(HARDWARE_DEVICE + "/" + 2); |
| 306 | |
| 307 | private static final TrafficSelector HARDWARE_FLOW_SELECTOR = DefaultTrafficSelector.builder() |
| 308 | .matchInPort(PortNumber.portNumber(1)) |
| 309 | .matchIPSrc(IpPrefix.valueOf("127.0.0.1/32")) |
| 310 | .matchIPDst(IpPrefix.valueOf("127.0.0.2/32")) |
| 311 | .build(); |
| 312 | |
| 313 | private static final TrafficTreatment HW_TRANSITION_FLOW_TREATMENT = DefaultTrafficTreatment.builder() |
| 314 | .pushMpls() |
| 315 | .transition(27) |
| 316 | .build(); |
| 317 | |
| 318 | private static final FlowRule HARDWARE_FLOW = DefaultFlowEntry.builder().forDevice(TOPO_FLOW_3_DEVICE) |
| 319 | .forTable(0) |
| 320 | .withPriority(100) |
| 321 | .withSelector(HARDWARE_FLOW_SELECTOR) |
| 322 | .withTreatment(HW_TRANSITION_FLOW_TREATMENT) |
| 323 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 324 | .makePermanent() |
| 325 | .build(); |
| 326 | |
| 327 | static final FlowEntry HARDWARE_FLOW_ENTRY = new DefaultFlowEntry(HARDWARE_FLOW); |
| 328 | |
| 329 | private static final TrafficSelector HARDWARE_ETH_FLOW_SELECTOR = DefaultTrafficSelector.builder() |
| 330 | .matchInPort(PortNumber.portNumber(1)) |
| 331 | .matchIPSrc(IpPrefix.valueOf("127.0.0.1/32")) |
| 332 | .matchIPDst(IpPrefix.valueOf("127.0.0.2/32")) |
| 333 | .matchEthType(EthType.EtherType.IPV4.ethType().toShort()) |
| 334 | .build(); |
| 335 | |
| 336 | private static final FlowRule HARDWARE_ETH_FLOW = DefaultFlowEntry.builder().forDevice(TOPO_FLOW_3_DEVICE) |
| 337 | .forTable(30) |
| 338 | .withPriority(100) |
| 339 | .withSelector(HARDWARE_ETH_FLOW_SELECTOR) |
| 340 | .withTreatment(OUTPUT_FLOW_TREATMENT) |
| 341 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 342 | .makePermanent() |
| 343 | .build(); |
| 344 | |
| 345 | static final FlowEntry HARDWARE_ETH_FLOW_ENTRY = new DefaultFlowEntry(HARDWARE_ETH_FLOW); |
| 346 | |
Andrea Campanella | 97f9d4c | 2018-02-06 18:58:40 +0100 | [diff] [blame] | 347 | //HW Double Rule on 10 |
| 348 | |
| 349 | static final DeviceId HARDWARE_DEVICE_10 = DeviceId.deviceId("HardwareDevice10"); |
| 350 | |
| 351 | static final ConnectPoint HARDWARE_DEVICE_10_IN_CP = ConnectPoint.deviceConnectPoint(HARDWARE_DEVICE_10 + "/" + 1); |
| 352 | |
| 353 | static final ConnectPoint HARDWARE_DEVICE_10_OUT_CP = ConnectPoint.deviceConnectPoint(HARDWARE_DEVICE_10 + "/" + 2); |
| 354 | |
| 355 | private static final TrafficSelector HARDWARE_10_FLOW_SELECTOR = DefaultTrafficSelector.builder() |
| 356 | .matchInPort(PortNumber.portNumber(1)) |
| 357 | .matchIPSrc(IpPrefix.valueOf("127.0.0.1/32")) |
| 358 | .matchIPDst(IpPrefix.valueOf("127.0.0.2/32")) |
| 359 | .matchVlanId(VlanId.NONE) |
| 360 | .build(); |
| 361 | |
| 362 | private static final TrafficTreatment HARDWARE_10_TRANSITION_FLOW_TREATMENT = DefaultTrafficTreatment.builder() |
| 363 | .setVlanId(VlanId.vlanId("10")) |
| 364 | .transition(20) |
| 365 | .build(); |
| 366 | |
| 367 | private static final FlowRule HARDWARE_DEVICE_10_FLOW = DefaultFlowEntry.builder().forDevice(HARDWARE_DEVICE_10) |
| 368 | .forTable(10) |
| 369 | .withPriority(100) |
| 370 | .withSelector(HARDWARE_10_FLOW_SELECTOR) |
| 371 | .withTreatment(HARDWARE_10_TRANSITION_FLOW_TREATMENT) |
| 372 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 373 | .makePermanent() |
| 374 | .build(); |
| 375 | |
| 376 | static final FlowEntry HARDWARE_10_FLOW_ENTRY = new DefaultFlowEntry(HARDWARE_DEVICE_10_FLOW); |
| 377 | |
| 378 | private static final TrafficSelector HARDWARE_10_SECOND_SELECTOR = DefaultTrafficSelector.builder() |
| 379 | .matchInPort(PortNumber.portNumber(1)) |
| 380 | .matchVlanId(VlanId.vlanId("10")) |
| 381 | .matchIPSrc(IpPrefix.valueOf("127.0.0.1/32")) |
| 382 | .matchIPDst(IpPrefix.valueOf("127.0.0.2/32")) |
| 383 | .matchEthType(EthType.EtherType.IPV4.ethType().toShort()) |
| 384 | .build(); |
| 385 | |
| 386 | private static final FlowRule HARDWARE_10_SECOND_FLOW = DefaultFlowEntry.builder().forDevice(HARDWARE_DEVICE_10) |
| 387 | .forTable(10) |
| 388 | .withPriority(100) |
| 389 | .withSelector(HARDWARE_10_SECOND_SELECTOR) |
| 390 | .withTreatment(HARDWARE_10_TRANSITION_FLOW_TREATMENT) |
| 391 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 392 | .makePermanent() |
| 393 | .build(); |
| 394 | |
| 395 | static final FlowEntry HARDWARE_10_SECOND_FLOW_ENTRY = new DefaultFlowEntry(HARDWARE_10_SECOND_FLOW); |
| 396 | |
| 397 | private static final FlowRule HARDWARE_10_OUTPUT_FLOW = DefaultFlowEntry.builder().forDevice(HARDWARE_DEVICE_10) |
| 398 | .forTable(20) |
| 399 | .withPriority(100) |
| 400 | .withSelector(SINGLE_FLOW_SELECTOR) |
| 401 | .withTreatment(OUTPUT_FLOW_TREATMENT) |
| 402 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 403 | .makePermanent() |
| 404 | .build(); |
| 405 | |
| 406 | static final FlowEntry HARDWARE_10_OUTPUT_FLOW_ENTRY = new DefaultFlowEntry(HARDWARE_10_OUTPUT_FLOW); |
| 407 | |
Andrea Campanella | e04aac9 | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 408 | //Dual Links |
| 409 | // - (1) Device 1 (2-3) - (1-4) Device 2 (2-3) - (1-2) Device 3 (3) - |
| 410 | static final DeviceId DUAL_LINK_1 = DeviceId.deviceId("DualLink1"); |
| 411 | static final DeviceId DUAL_LINK_2 = DeviceId.deviceId("DualLink2"); |
| 412 | static final DeviceId DUAL_LINK_3 = DeviceId.deviceId("DualLink3"); |
| 413 | |
| 414 | static final ConnectPoint DUAL_LINK_1_CP_1_IN = ConnectPoint.deviceConnectPoint(DUAL_LINK_1 + "/" + 1); |
| 415 | static final ConnectPoint DUAL_LINK_1_CP_2_OUT = ConnectPoint.deviceConnectPoint(DUAL_LINK_1 + "/" + 2); |
| 416 | static final ConnectPoint DUAL_LINK_1_CP_3_OUT = ConnectPoint.deviceConnectPoint(DUAL_LINK_1 + "/" + 3); |
| 417 | static final ConnectPoint DUAL_LINK_2_CP_1_IN = ConnectPoint.deviceConnectPoint(DUAL_LINK_2 + "/" + 1); |
| 418 | static final ConnectPoint DUAL_LINK_2_CP_4_IN = ConnectPoint.deviceConnectPoint(DUAL_LINK_2 + "/" + 4); |
| 419 | static final ConnectPoint DUAL_LINK_2_CP_2_OUT = ConnectPoint.deviceConnectPoint(DUAL_LINK_2 + "/" + 2); |
| 420 | static final ConnectPoint DUAL_LINK_2_CP_3_OUT = ConnectPoint.deviceConnectPoint(DUAL_LINK_2 + "/" + 3); |
| 421 | static final ConnectPoint DUAL_LINK_3_CP_1_IN = ConnectPoint.deviceConnectPoint(DUAL_LINK_3 + "/" + 1); |
| 422 | static final ConnectPoint DUAL_LINK_3_CP_2_IN = ConnectPoint.deviceConnectPoint(DUAL_LINK_3 + "/" + 2); |
| 423 | static final ConnectPoint DUAL_LINK_3_CP_3_OUT = ConnectPoint.deviceConnectPoint(DUAL_LINK_3 + "/" + 3); |
| 424 | |
| 425 | //match on port 1 and point to group for device 1 and 2 |
| 426 | private static final TrafficTreatment DUAL_LINK_1_GROUP_FLOW_TREATMENT = DefaultTrafficTreatment.builder() |
| 427 | .pushMpls() |
| 428 | .setMpls(MplsLabel.mplsLabel(100)) |
| 429 | .group(GROUP_ID) |
| 430 | .build(); |
| 431 | private static final FlowRule DUAL_LINK_1_GROUP_FLOW = DefaultFlowEntry.builder().forDevice(DUAL_LINK_1) |
| 432 | .forTable(0) |
| 433 | .withPriority(100) |
| 434 | .withSelector(SINGLE_FLOW_SELECTOR) |
| 435 | .withTreatment(DUAL_LINK_1_GROUP_FLOW_TREATMENT) |
| 436 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 437 | .makePermanent() |
| 438 | .build(); |
| 439 | static final FlowEntry DUAL_LINK_1_GROUP_FLOW_ENTRY = new DefaultFlowEntry(DUAL_LINK_1_GROUP_FLOW); |
| 440 | |
| 441 | //Match on port 4 and point to group for device 2 |
| 442 | private static final TrafficSelector DUAL_LINK_2_FLOW_SELECTOR = DefaultTrafficSelector.builder() |
| 443 | .matchInPort(PortNumber.portNumber(4)) |
| 444 | .matchIPSrc(IpPrefix.valueOf("127.0.0.1/32")) |
| 445 | .matchIPDst(IpPrefix.valueOf("127.0.0.2/32")) |
| 446 | .build(); |
| 447 | |
| 448 | private static final FlowRule DUAL_LINK_2_GROUP_FLOW = DefaultFlowEntry.builder().forDevice(DUAL_LINK_2) |
| 449 | .forTable(0) |
| 450 | .withPriority(100) |
| 451 | .withSelector(DUAL_LINK_2_FLOW_SELECTOR) |
| 452 | .withTreatment(DUAL_LINK_1_GROUP_FLOW_TREATMENT) |
| 453 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 454 | .makePermanent() |
| 455 | .build(); |
| 456 | static final FlowEntry DUAL_LINK_2_GROUP_FLOW_ENTRY = new DefaultFlowEntry(DUAL_LINK_2_GROUP_FLOW); |
| 457 | |
| 458 | //Flows for device 3 to ouput on port 3 |
| 459 | private static final TrafficTreatment DUAL_LINK_1_OUTPUT_TREATMENT = DefaultTrafficTreatment.builder() |
| 460 | .popMpls(EthType.EtherType.IPV4.ethType()) |
| 461 | .setOutput(PortNumber.portNumber(3)).build(); |
| 462 | |
| 463 | private static final TrafficSelector DUAL_LINK_3_FLOW_SELECTOR_1 = DefaultTrafficSelector.builder() |
| 464 | .matchInPort(PortNumber.portNumber(1)) |
| 465 | .matchIPSrc(IpPrefix.valueOf("127.0.0.1/32")) |
| 466 | .matchIPDst(IpPrefix.valueOf("127.0.0.2/32")) |
| 467 | .build(); |
| 468 | private static final FlowRule DUAL_LINK_3_FLOW_1 = DefaultFlowEntry.builder().forDevice(DUAL_LINK_3) |
| 469 | .forTable(0) |
| 470 | .withPriority(100) |
| 471 | .withSelector(DUAL_LINK_3_FLOW_SELECTOR_1) |
| 472 | .withTreatment(DUAL_LINK_1_OUTPUT_TREATMENT) |
| 473 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 474 | .makePermanent() |
| 475 | .build(); |
| 476 | |
| 477 | static final FlowEntry DUAL_LINK_3_FLOW_ENTRY = new DefaultFlowEntry(DUAL_LINK_3_FLOW_1); |
| 478 | |
| 479 | private static final TrafficSelector DUAL_LINK_3_FLOW_SELECTOR_2 = DefaultTrafficSelector.builder() |
| 480 | .matchInPort(PortNumber.portNumber(2)) |
| 481 | .matchIPSrc(IpPrefix.valueOf("127.0.0.1/32")) |
| 482 | .matchIPDst(IpPrefix.valueOf("127.0.0.2/32")) |
| 483 | .build(); |
| 484 | private static final FlowRule DUAL_LINK_3_FLOW_2 = DefaultFlowEntry.builder().forDevice(DUAL_LINK_3) |
| 485 | .forTable(0) |
| 486 | .withPriority(100) |
| 487 | .withSelector(DUAL_LINK_3_FLOW_SELECTOR_2) |
| 488 | .withTreatment(DUAL_LINK_1_OUTPUT_TREATMENT) |
| 489 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 490 | .makePermanent() |
| 491 | .build(); |
| 492 | |
| 493 | static final FlowEntry DUAL_LINK_3_FLOW_ENTRY_2 = new DefaultFlowEntry(DUAL_LINK_3_FLOW_2); |
| 494 | |
| 495 | //Group with two buckets to output on port 2 and 3 of device 1 and 2 |
| 496 | |
| 497 | private static final GroupBucket BUCKET_2_DUAL = |
| 498 | DefaultGroupBucket.createSelectGroupBucket(DUAL_LINK_1_OUTPUT_TREATMENT); |
| 499 | |
| 500 | private static final GroupBuckets BUCKETS_DUAL = new GroupBuckets(ImmutableList.of(BUCKET, BUCKET_2_DUAL)); |
| 501 | |
| 502 | static final Group DUAL_LINK_GROUP = new DefaultGroup(GROUP_ID, DUAL_LINK_1, Group.Type.SELECT, BUCKETS_DUAL); |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 503 | |
Andrea Campanella | d5bb2ef | 2018-01-31 16:43:23 +0100 | [diff] [blame] | 504 | //Clear Deferred |
| 505 | static final DeviceId DEFERRED_1 = DeviceId.deviceId("Deferred"); |
| 506 | |
| 507 | static final ConnectPoint DEFERRED_CP_1_IN = ConnectPoint.deviceConnectPoint(DEFERRED_1 + "/" + 1); |
| 508 | static final ConnectPoint DEFERRED_CP_2_OUT = ConnectPoint.deviceConnectPoint(DEFERRED_1 + "/" + 2); |
| 509 | |
| 510 | //match on port 1 and apply deferred actions |
| 511 | private static final TrafficTreatment DEFERRED_1_FLOW_TREATMENT = DefaultTrafficTreatment.builder() |
| 512 | .transition(10) |
| 513 | .deferred() |
| 514 | .pushMpls() |
| 515 | .setMpls(MplsLabel.mplsLabel(100)) |
| 516 | .build(); |
| 517 | private static final FlowRule DEFERRED_FLOW = DefaultFlowEntry.builder().forDevice(DEFERRED_1) |
| 518 | .forTable(0) |
| 519 | .withPriority(100) |
| 520 | .withSelector(SINGLE_FLOW_SELECTOR) |
| 521 | .withTreatment(DEFERRED_1_FLOW_TREATMENT) |
| 522 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 523 | .makePermanent() |
| 524 | .build(); |
| 525 | static final FlowEntry DEFERRED_FLOW_ENTRY = new DefaultFlowEntry(DEFERRED_FLOW); |
| 526 | |
| 527 | //match on port 1, clear deferred actions and output |
| 528 | private static final TrafficTreatment DEFERRED_CLEAR_1_FLOW_TREATMENT = DefaultTrafficTreatment.builder() |
| 529 | .wipeDeferred() |
| 530 | .setOutput(PortNumber.portNumber(2)) |
| 531 | .build(); |
| 532 | private static final FlowRule DEFERRED_CLEAR_FLOW = DefaultFlowEntry.builder().forDevice(DEFERRED_1) |
| 533 | .forTable(10) |
| 534 | .withPriority(100) |
| 535 | .withSelector(SINGLE_FLOW_SELECTOR) |
| 536 | .withTreatment(DEFERRED_CLEAR_1_FLOW_TREATMENT) |
| 537 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 538 | .makePermanent() |
| 539 | .build(); |
| 540 | static final FlowEntry DEFERRED_CLEAR_FLOW_ENTRY = new DefaultFlowEntry(DEFERRED_CLEAR_FLOW); |
| 541 | |
Andrea Campanella | 6f2d674 | 2018-02-07 12:00:12 +0100 | [diff] [blame^] | 542 | //LLDP |
| 543 | |
| 544 | static final DeviceId LLDP_FLOW_DEVICE = DeviceId.deviceId("LldpDevice"); |
| 545 | |
| 546 | private static final TrafficSelector LLDP_FLOW_SELECTOR = DefaultTrafficSelector.builder() |
| 547 | .matchInPort(PortNumber.portNumber(1)) |
| 548 | .matchEthType(EthType.EtherType.LLDP.ethType().toShort()) |
| 549 | .build(); |
| 550 | |
| 551 | private static final TrafficTreatment LLDP_FLOW_TREATMENT = DefaultTrafficTreatment.builder() |
| 552 | .setOutput(PortNumber.CONTROLLER).build(); |
| 553 | private static final FlowRule LLDP_FLOW = DefaultFlowEntry.builder().forDevice(LLDP_FLOW_DEVICE) |
| 554 | .forTable(0) |
| 555 | .withPriority(100) |
| 556 | .withSelector(LLDP_FLOW_SELECTOR) |
| 557 | .withTreatment(LLDP_FLOW_TREATMENT) |
| 558 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 559 | .makePermanent() |
| 560 | .build(); |
| 561 | static final FlowEntry LLDP_FLOW_ENTRY = new DefaultFlowEntry(LLDP_FLOW); |
| 562 | |
| 563 | static final ConnectPoint LLDP_FLOW_CP = ConnectPoint.deviceConnectPoint(LLDP_FLOW_DEVICE + "/" + 1); |
| 564 | |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 565 | //helper elements |
| 566 | |
Andrea Campanella | 7c8e791 | 2018-01-23 12:46:04 +0100 | [diff] [blame] | 567 | static final String MASTER_1 = "Master1"; |
| 568 | |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 569 | static final Host H1 = new DefaultHost(ProviderId.NONE, HostId.hostId(HOST_ONE), MacAddress.valueOf(100), |
| 570 | VlanId.NONE, new HostLocation(SINGLE_FLOW_DEVICE, PortNumber.portNumber(2), 0), |
| 571 | ImmutableSet.of(IpAddress.valueOf("127.0.0.2"))); |
| 572 | |
| 573 | static final Host H2 = new DefaultHost(ProviderId.NONE, HostId.hostId(HOST_TWO), MacAddress.valueOf(100), |
| 574 | VlanId.NONE, new HostLocation(TOPO_FLOW_3_DEVICE, PortNumber.portNumber(2), 0), |
| 575 | ImmutableSet.of(IpAddress.valueOf("127.0.0.3"))); |
| 576 | |
| 577 | static final TrafficSelector PACKET_OK = DefaultTrafficSelector.builder() |
| 578 | .matchInPort(PortNumber.portNumber(1)) |
Andrea Campanella | 2bc55dd | 2018-01-18 16:54:34 +0100 | [diff] [blame] | 579 | .matchEthType(EthType.EtherType.IPV4.ethType().toShort()) |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 580 | .matchIPSrc(IpPrefix.valueOf("127.0.0.1/32")) |
| 581 | .matchIPDst(IpPrefix.valueOf("127.0.0.2/32")) |
Andrea Campanella | 97f9d4c | 2018-02-06 18:58:40 +0100 | [diff] [blame] | 582 | .matchVlanId(VlanId.NONE) |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 583 | .build(); |
| 584 | |
| 585 | static final TrafficSelector PACKET_OK_TOPO = DefaultTrafficSelector.builder() |
| 586 | .matchInPort(PortNumber.portNumber(1)) |
| 587 | .matchIPSrc(IpPrefix.valueOf("127.0.0.1/32")) |
| 588 | .matchIPDst(IpPrefix.valueOf("127.0.0.3/32")) |
| 589 | .build(); |
| 590 | |
Andrea Campanella | 7c8e791 | 2018-01-23 12:46:04 +0100 | [diff] [blame] | 591 | static final TrafficSelector PACKET_ARP = DefaultTrafficSelector.builder() |
| 592 | .matchInPort(PortNumber.portNumber(1)) |
| 593 | .matchIPDst(IpPrefix.valueOf("255.255.255.255/32")) |
| 594 | .matchEthType(EthType.EtherType.ARP.ethType().toShort()) |
| 595 | .build(); |
| 596 | |
Andrea Campanella | 6f2d674 | 2018-02-07 12:00:12 +0100 | [diff] [blame^] | 597 | static final TrafficSelector PACKET_LLDP = DefaultTrafficSelector.builder() |
| 598 | .matchInPort(PortNumber.portNumber(1)) |
| 599 | .matchEthType(EthType.EtherType.LLDP.ethType().toShort()) |
| 600 | .build(); |
| 601 | |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 602 | static final TrafficSelector PACKET_FAIL = DefaultTrafficSelector.builder() |
| 603 | .matchInPort(PortNumber.portNumber(1)) |
| 604 | .matchIPSrc(IpPrefix.valueOf("127.0.0.1/32")) |
| 605 | .matchIPDst(IpPrefix.valueOf("127.0.0.99/32")) |
| 606 | .build(); |
| 607 | } |