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