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; |
| 24 | import org.onlab.packet.VlanId; |
| 25 | import org.onosproject.core.DefaultApplicationId; |
| 26 | import org.onosproject.core.GroupId; |
| 27 | import org.onosproject.net.ConnectPoint; |
| 28 | import org.onosproject.net.DefaultHost; |
| 29 | import org.onosproject.net.DeviceId; |
| 30 | import org.onosproject.net.Host; |
| 31 | import org.onosproject.net.HostId; |
| 32 | import org.onosproject.net.HostLocation; |
| 33 | import org.onosproject.net.PortNumber; |
| 34 | import org.onosproject.net.flow.DefaultFlowEntry; |
| 35 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 36 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 37 | import org.onosproject.net.flow.FlowEntry; |
| 38 | import org.onosproject.net.flow.FlowRule; |
| 39 | import org.onosproject.net.flow.TrafficSelector; |
| 40 | import org.onosproject.net.flow.TrafficTreatment; |
| 41 | import org.onosproject.net.group.DefaultGroup; |
| 42 | import org.onosproject.net.group.DefaultGroupBucket; |
| 43 | import org.onosproject.net.group.Group; |
| 44 | import org.onosproject.net.group.GroupBucket; |
| 45 | import org.onosproject.net.group.GroupBuckets; |
| 46 | import org.onosproject.net.provider.ProviderId; |
| 47 | |
| 48 | /** |
| 49 | * Helper class for objects related to the Troubleshoot Manager Test. |
| 50 | */ |
| 51 | final class T3TestObjects { |
| 52 | |
| 53 | private static final String HOST_ONE_MAC = "00:00:00:00:00:01"; |
| 54 | private static final String HOST_TWO_MAC = "00:00:00:00:00:02"; |
| 55 | private static final String HOST_ONE_VLAN = "None"; |
| 56 | private static final String HOST_TWO_VLAN = "None"; |
| 57 | private static final String HOST_ONE = HOST_ONE_MAC + "/" + HOST_ONE_VLAN; |
| 58 | private static final String HOST_TWO = HOST_TWO_MAC + "/" + HOST_TWO_VLAN; |
| 59 | |
| 60 | //Single Flow Test |
| 61 | static final DeviceId SINGLE_FLOW_DEVICE = DeviceId.deviceId("SingleFlowDevice"); |
| 62 | private static final TrafficSelector SINGLE_FLOW_SELECTOR = DefaultTrafficSelector.builder() |
| 63 | .matchInPort(PortNumber.portNumber(1)) |
| 64 | .matchIPSrc(IpPrefix.valueOf("127.0.0.1/32")) |
| 65 | .matchIPDst(IpPrefix.valueOf("127.0.0.2/32")) |
| 66 | .build(); |
| 67 | |
| 68 | private static final TrafficTreatment OUTPUT_FLOW_TREATMENT = DefaultTrafficTreatment.builder() |
| 69 | .setOutput(PortNumber.portNumber(2)).build(); |
| 70 | private static final FlowRule SINGLE_FLOW = DefaultFlowEntry.builder().forDevice(SINGLE_FLOW_DEVICE) |
| 71 | .forTable(0) |
| 72 | .withPriority(100) |
| 73 | .withSelector(SINGLE_FLOW_SELECTOR) |
| 74 | .withTreatment(OUTPUT_FLOW_TREATMENT) |
| 75 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 76 | .makePermanent() |
| 77 | .build(); |
| 78 | static final FlowEntry SINGLE_FLOW_ENTRY = new DefaultFlowEntry(SINGLE_FLOW); |
| 79 | |
| 80 | static final ConnectPoint SINGLE_FLOW_IN_CP = ConnectPoint.deviceConnectPoint(SINGLE_FLOW_DEVICE + "/" + 1); |
| 81 | |
| 82 | static final ConnectPoint SINGLE_FLOW_OUT_CP = ConnectPoint.deviceConnectPoint(SINGLE_FLOW_DEVICE + "/" + 2); |
| 83 | |
| 84 | //Dual Flow Test |
| 85 | static final DeviceId DUAL_FLOW_DEVICE = DeviceId.deviceId("DualFlowDevice"); |
| 86 | private static final TrafficTreatment TRANSITION_FLOW_TREATMENT = DefaultTrafficTreatment.builder() |
| 87 | .setVlanId(VlanId.vlanId((short) 100)) |
| 88 | .transition(10) |
| 89 | .build(); |
| 90 | private static final TrafficSelector VLAN_FLOW_SELECTOR = DefaultTrafficSelector.builder() |
| 91 | .matchVlanId(VlanId.vlanId((short) 100)) |
| 92 | .build(); |
| 93 | private static final FlowRule FIRST_FLOW = DefaultFlowEntry.builder().forDevice(DUAL_FLOW_DEVICE) |
| 94 | .forTable(0) |
| 95 | .withPriority(100) |
| 96 | .withSelector(SINGLE_FLOW_SELECTOR) |
| 97 | .withTreatment(TRANSITION_FLOW_TREATMENT) |
| 98 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 99 | .makePermanent() |
| 100 | .build(); |
| 101 | static final FlowEntry FIRST_FLOW_ENTRY = new DefaultFlowEntry(FIRST_FLOW); |
| 102 | private static final FlowRule SECOND_FLOW = DefaultFlowEntry.builder().forDevice(DUAL_FLOW_DEVICE) |
| 103 | .forTable(10) |
| 104 | .withPriority(100) |
| 105 | .withSelector(VLAN_FLOW_SELECTOR) |
| 106 | .withTreatment(OUTPUT_FLOW_TREATMENT) |
| 107 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 108 | .makePermanent() |
| 109 | .build(); |
| 110 | static final FlowEntry SECOND_FLOW_ENTRY = new DefaultFlowEntry(SECOND_FLOW); |
| 111 | |
| 112 | static final ConnectPoint DUAL_FLOW_IN_CP = ConnectPoint.deviceConnectPoint(DUAL_FLOW_DEVICE + "/" + 1); |
| 113 | |
| 114 | static final ConnectPoint DUAL_FLOW_OUT_CP = ConnectPoint.deviceConnectPoint(DUAL_FLOW_DEVICE + "/" + 2); |
| 115 | |
| 116 | //Flow and Group Test |
| 117 | static final DeviceId GROUP_FLOW_DEVICE = DeviceId.deviceId("GroupFlowDevice"); |
| 118 | |
| 119 | private static final GroupId GROUP_ID = GroupId.valueOf(1); |
| 120 | |
| 121 | private static final TrafficTreatment GROUP_FLOW_TREATMENT = DefaultTrafficTreatment.builder() |
| 122 | .group(GROUP_ID) |
| 123 | .build(); |
| 124 | private static final FlowRule GROUP_FLOW = DefaultFlowEntry.builder().forDevice(GROUP_FLOW_DEVICE) |
| 125 | .forTable(0) |
| 126 | .withPriority(100) |
| 127 | .withSelector(SINGLE_FLOW_SELECTOR) |
| 128 | .withTreatment(GROUP_FLOW_TREATMENT) |
| 129 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 130 | .makePermanent() |
| 131 | .build(); |
| 132 | static final FlowEntry GROUP_FLOW_ENTRY = new DefaultFlowEntry(GROUP_FLOW); |
| 133 | |
| 134 | private static final GroupBucket BUCKET = DefaultGroupBucket.createSelectGroupBucket(OUTPUT_FLOW_TREATMENT); |
| 135 | |
| 136 | private static final GroupBuckets BUCKETS = new GroupBuckets(ImmutableList.of(BUCKET)); |
| 137 | |
| 138 | static final Group GROUP = new DefaultGroup(GROUP_ID, GROUP_FLOW_DEVICE, Group.Type.SELECT, BUCKETS); |
| 139 | |
| 140 | static final ConnectPoint GROUP_FLOW_IN_CP = ConnectPoint.deviceConnectPoint(GROUP_FLOW_DEVICE + "/" + 1); |
| 141 | |
| 142 | static final ConnectPoint GROUP_FLOW_OUT_CP = ConnectPoint.deviceConnectPoint(GROUP_FLOW_DEVICE + "/" + 2); |
| 143 | |
| 144 | //topology |
| 145 | |
| 146 | static final DeviceId TOPO_FLOW_DEVICE = DeviceId.deviceId("SingleFlowDevice1"); |
| 147 | |
| 148 | static final DeviceId TOPO_FLOW_2_DEVICE = DeviceId.deviceId("SingleFlowDevice2"); |
| 149 | |
| 150 | static final DeviceId TOPO_FLOW_3_DEVICE = DeviceId.deviceId("SingleFlowDevice3"); |
| 151 | |
| 152 | private static final TrafficSelector TOPO_FLOW_SELECTOR = DefaultTrafficSelector.builder() |
| 153 | .matchInPort(PortNumber.portNumber(1)) |
| 154 | .matchIPSrc(IpPrefix.valueOf("127.0.0.1/32")) |
| 155 | .matchIPDst(IpPrefix.valueOf("127.0.0.3/32")) |
| 156 | .build(); |
| 157 | |
| 158 | private static final FlowRule TOPO_SINGLE_FLOW = DefaultFlowEntry.builder().forDevice(TOPO_FLOW_DEVICE) |
| 159 | .forTable(0) |
| 160 | .withPriority(100) |
| 161 | .withSelector(TOPO_FLOW_SELECTOR) |
| 162 | .withTreatment(OUTPUT_FLOW_TREATMENT) |
| 163 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 164 | .makePermanent() |
| 165 | .build(); |
| 166 | |
| 167 | static final FlowEntry TOPO_SINGLE_FLOW_ENTRY = new DefaultFlowEntry(TOPO_SINGLE_FLOW); |
| 168 | |
| 169 | static final ConnectPoint TOPO_FLOW_1_IN_CP = ConnectPoint.deviceConnectPoint(TOPO_FLOW_DEVICE + "/" + 1); |
| 170 | |
| 171 | static final ConnectPoint TOPO_FLOW_1_OUT_CP = ConnectPoint.deviceConnectPoint(TOPO_FLOW_DEVICE + "/" + 2); |
| 172 | |
| 173 | static final ConnectPoint TOPO_FLOW_2_IN_CP = ConnectPoint.deviceConnectPoint(TOPO_FLOW_2_DEVICE + "/" + 1); |
| 174 | |
| 175 | static final ConnectPoint TOPO_FLOW_2_OUT_CP = ConnectPoint.deviceConnectPoint(TOPO_FLOW_2_DEVICE + "/" + 2); |
| 176 | |
| 177 | static final ConnectPoint TOPO_FLOW_3_IN_CP = ConnectPoint.deviceConnectPoint(TOPO_FLOW_3_DEVICE + "/" + 1); |
| 178 | |
| 179 | static final ConnectPoint TOPO_FLOW_3_OUT_CP = ConnectPoint.deviceConnectPoint(TOPO_FLOW_3_DEVICE + "/" + 2); |
| 180 | |
| 181 | |
| 182 | //Topology with Groups |
| 183 | |
| 184 | static final DeviceId TOPO_GROUP_FLOW_DEVICE = DeviceId.deviceId("TopoGroupFlowDevice"); |
| 185 | |
| 186 | private static final TrafficSelector TOPO_SECOND_INPUT_FLOW_SELECTOR = DefaultTrafficSelector.builder() |
| 187 | .matchInPort(PortNumber.portNumber(3)) |
| 188 | .matchIPSrc(IpPrefix.valueOf("127.0.0.1/32")) |
| 189 | .matchIPDst(IpPrefix.valueOf("127.0.0.3/32")) |
| 190 | .build(); |
| 191 | |
| 192 | private static final FlowRule TOPO_SECOND_INPUT_FLOW = DefaultFlowEntry.builder().forDevice(TOPO_FLOW_3_DEVICE) |
| 193 | .forTable(0) |
| 194 | .withPriority(100) |
| 195 | .withSelector(TOPO_SECOND_INPUT_FLOW_SELECTOR) |
| 196 | .withTreatment(OUTPUT_FLOW_TREATMENT) |
| 197 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 198 | .makePermanent() |
| 199 | .build(); |
| 200 | |
| 201 | private static final TrafficTreatment OUTPUT_2_FLOW_TREATMENT = DefaultTrafficTreatment.builder() |
| 202 | .setOutput(PortNumber.portNumber(3)).build(); |
| 203 | |
| 204 | |
| 205 | private static final GroupId TOPO_GROUP_ID = GroupId.valueOf(1); |
| 206 | |
| 207 | private static final TrafficTreatment TOPO_GROUP_FLOW_TREATMENT = DefaultTrafficTreatment.builder() |
| 208 | .group(TOPO_GROUP_ID) |
| 209 | .build(); |
| 210 | private static final FlowRule TOPO_GROUP_FLOW = DefaultFlowEntry.builder().forDevice(TOPO_GROUP_FLOW_DEVICE) |
| 211 | .forTable(0) |
| 212 | .withPriority(100) |
| 213 | .withSelector(TOPO_FLOW_SELECTOR) |
| 214 | .withTreatment(TOPO_GROUP_FLOW_TREATMENT) |
| 215 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 216 | .makePermanent() |
| 217 | .build(); |
| 218 | static final FlowEntry TOPO_GROUP_FLOW_ENTRY = new DefaultFlowEntry(TOPO_GROUP_FLOW); |
| 219 | |
| 220 | private static final GroupBucket BUCKET_2 = DefaultGroupBucket.createSelectGroupBucket(OUTPUT_2_FLOW_TREATMENT); |
| 221 | |
| 222 | private static final GroupBuckets BUCKETS_MULTIPLE = new GroupBuckets(ImmutableList.of(BUCKET, BUCKET_2)); |
| 223 | |
| 224 | static final Group TOPO_GROUP = new DefaultGroup(TOPO_GROUP_ID, TOPO_GROUP_FLOW_DEVICE, Group.Type.SELECT, BUCKETS_MULTIPLE); |
| 225 | |
| 226 | static final FlowEntry TOPO_SECOND_INPUT_FLOW_ENTRY = new DefaultFlowEntry(TOPO_SECOND_INPUT_FLOW); |
| 227 | |
| 228 | static final DeviceId TOPO_FLOW_4_DEVICE = DeviceId.deviceId("SingleFlowDevice4"); |
| 229 | |
| 230 | static final ConnectPoint TOPO_FLOW_IN_CP = ConnectPoint.deviceConnectPoint(TOPO_GROUP_FLOW_DEVICE + "/" + 1); |
| 231 | |
| 232 | static final ConnectPoint TOPO_FLOW_OUT_CP_1 = ConnectPoint.deviceConnectPoint(TOPO_GROUP_FLOW_DEVICE + "/" + 2); |
| 233 | |
| 234 | protected static final ConnectPoint TOPO_FLOW_OUT_CP_2 = ConnectPoint.deviceConnectPoint(TOPO_GROUP_FLOW_DEVICE + "/" + 3); |
| 235 | |
| 236 | static final ConnectPoint TOPO_FLOW_4_IN_CP = ConnectPoint.deviceConnectPoint(TOPO_FLOW_4_DEVICE + "/" + 1); |
| 237 | |
| 238 | static final ConnectPoint TOPO_FLOW_3_IN_2_CP = ConnectPoint.deviceConnectPoint(TOPO_FLOW_3_DEVICE + "/" + 3); |
| 239 | |
| 240 | static final ConnectPoint TOPO_FLOW_4_OUT_CP = ConnectPoint.deviceConnectPoint(TOPO_FLOW_4_DEVICE + "/" + 2); |
| 241 | |
| 242 | |
| 243 | //hardware |
| 244 | |
| 245 | static final DeviceId HARDWARE_DEVICE = DeviceId.deviceId("HardwareDevice"); |
| 246 | |
| 247 | static final ConnectPoint HARDWARE_DEVICE_IN_CP = ConnectPoint.deviceConnectPoint(HARDWARE_DEVICE + "/" + 1); |
| 248 | |
| 249 | static final ConnectPoint HARDWARE_DEVICE_OUT_CP = ConnectPoint.deviceConnectPoint(HARDWARE_DEVICE + "/" + 2); |
| 250 | |
| 251 | private static final TrafficSelector HARDWARE_FLOW_SELECTOR = DefaultTrafficSelector.builder() |
| 252 | .matchInPort(PortNumber.portNumber(1)) |
| 253 | .matchIPSrc(IpPrefix.valueOf("127.0.0.1/32")) |
| 254 | .matchIPDst(IpPrefix.valueOf("127.0.0.2/32")) |
| 255 | .build(); |
| 256 | |
| 257 | private static final TrafficTreatment HW_TRANSITION_FLOW_TREATMENT = DefaultTrafficTreatment.builder() |
| 258 | .pushMpls() |
| 259 | .transition(27) |
| 260 | .build(); |
| 261 | |
| 262 | private static final FlowRule HARDWARE_FLOW = DefaultFlowEntry.builder().forDevice(TOPO_FLOW_3_DEVICE) |
| 263 | .forTable(0) |
| 264 | .withPriority(100) |
| 265 | .withSelector(HARDWARE_FLOW_SELECTOR) |
| 266 | .withTreatment(HW_TRANSITION_FLOW_TREATMENT) |
| 267 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 268 | .makePermanent() |
| 269 | .build(); |
| 270 | |
| 271 | static final FlowEntry HARDWARE_FLOW_ENTRY = new DefaultFlowEntry(HARDWARE_FLOW); |
| 272 | |
| 273 | private static final TrafficSelector HARDWARE_ETH_FLOW_SELECTOR = DefaultTrafficSelector.builder() |
| 274 | .matchInPort(PortNumber.portNumber(1)) |
| 275 | .matchIPSrc(IpPrefix.valueOf("127.0.0.1/32")) |
| 276 | .matchIPDst(IpPrefix.valueOf("127.0.0.2/32")) |
| 277 | .matchEthType(EthType.EtherType.IPV4.ethType().toShort()) |
| 278 | .build(); |
| 279 | |
| 280 | private static final FlowRule HARDWARE_ETH_FLOW = DefaultFlowEntry.builder().forDevice(TOPO_FLOW_3_DEVICE) |
| 281 | .forTable(30) |
| 282 | .withPriority(100) |
| 283 | .withSelector(HARDWARE_ETH_FLOW_SELECTOR) |
| 284 | .withTreatment(OUTPUT_FLOW_TREATMENT) |
| 285 | .fromApp(new DefaultApplicationId(0, "TestApp")) |
| 286 | .makePermanent() |
| 287 | .build(); |
| 288 | |
| 289 | static final FlowEntry HARDWARE_ETH_FLOW_ENTRY = new DefaultFlowEntry(HARDWARE_ETH_FLOW); |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | //helper elements |
| 295 | |
| 296 | static final Host H1 = new DefaultHost(ProviderId.NONE, HostId.hostId(HOST_ONE), MacAddress.valueOf(100), |
| 297 | VlanId.NONE, new HostLocation(SINGLE_FLOW_DEVICE, PortNumber.portNumber(2), 0), |
| 298 | ImmutableSet.of(IpAddress.valueOf("127.0.0.2"))); |
| 299 | |
| 300 | static final Host H2 = new DefaultHost(ProviderId.NONE, HostId.hostId(HOST_TWO), MacAddress.valueOf(100), |
| 301 | VlanId.NONE, new HostLocation(TOPO_FLOW_3_DEVICE, PortNumber.portNumber(2), 0), |
| 302 | ImmutableSet.of(IpAddress.valueOf("127.0.0.3"))); |
| 303 | |
| 304 | static final TrafficSelector PACKET_OK = DefaultTrafficSelector.builder() |
| 305 | .matchInPort(PortNumber.portNumber(1)) |
| 306 | .matchIPSrc(IpPrefix.valueOf("127.0.0.1/32")) |
| 307 | .matchIPDst(IpPrefix.valueOf("127.0.0.2/32")) |
| 308 | .build(); |
| 309 | |
| 310 | static final TrafficSelector PACKET_OK_TOPO = DefaultTrafficSelector.builder() |
| 311 | .matchInPort(PortNumber.portNumber(1)) |
| 312 | .matchIPSrc(IpPrefix.valueOf("127.0.0.1/32")) |
| 313 | .matchIPDst(IpPrefix.valueOf("127.0.0.3/32")) |
| 314 | .build(); |
| 315 | |
| 316 | static final TrafficSelector PACKET_FAIL = DefaultTrafficSelector.builder() |
| 317 | .matchInPort(PortNumber.portNumber(1)) |
| 318 | .matchIPSrc(IpPrefix.valueOf("127.0.0.1/32")) |
| 319 | .matchIPDst(IpPrefix.valueOf("127.0.0.99/32")) |
| 320 | .build(); |
| 321 | } |