blob: 15cee5ffae96f67f9b5d775e12afe989c7afc73c [file] [log] [blame]
Andrea Campanella01e886e2017-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;
Andrea Campanella09ca07a2018-01-25 16:44:04 +010024import org.onlab.packet.MplsLabel;
Andrea Campanella01e886e2017-12-15 15:27:31 +010025import org.onlab.packet.VlanId;
26import org.onosproject.core.DefaultApplicationId;
27import org.onosproject.core.GroupId;
28import org.onosproject.net.ConnectPoint;
29import org.onosproject.net.DefaultHost;
30import org.onosproject.net.DeviceId;
31import org.onosproject.net.Host;
32import org.onosproject.net.HostId;
33import org.onosproject.net.HostLocation;
34import org.onosproject.net.PortNumber;
35import org.onosproject.net.flow.DefaultFlowEntry;
36import org.onosproject.net.flow.DefaultTrafficSelector;
37import org.onosproject.net.flow.DefaultTrafficTreatment;
38import org.onosproject.net.flow.FlowEntry;
39import org.onosproject.net.flow.FlowRule;
40import org.onosproject.net.flow.TrafficSelector;
41import org.onosproject.net.flow.TrafficTreatment;
42import org.onosproject.net.group.DefaultGroup;
43import org.onosproject.net.group.DefaultGroupBucket;
44import org.onosproject.net.group.Group;
45import org.onosproject.net.group.GroupBucket;
46import org.onosproject.net.group.GroupBuckets;
47import org.onosproject.net.provider.ProviderId;
48
49/**
50 * Helper class for objects related to the Troubleshoot Manager Test.
51 */
52final class T3TestObjects {
53
Andrea Campanella2bc55dd2018-01-18 16:54:34 +010054 private T3TestObjects(){
55 //banning construction
56 }
57
Andrea Campanella01e886e2017-12-15 15:27:31 +010058 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 Campanella37d10622018-01-18 17:11:42 +010065 //offline device
66 static final DeviceId OFFLINE_DEVICE = DeviceId.deviceId("offlineDevice");
67
Andrea Campanella01e886e2017-12-15 15:27:31 +010068 //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 Campanellabb9d3fb2018-01-22 15:10:30 +010092 //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
109
Andrea Campanella01e886e2017-12-15 15:27:31 +0100110 //Dual Flow Test
111 static final DeviceId DUAL_FLOW_DEVICE = DeviceId.deviceId("DualFlowDevice");
112 private static final TrafficTreatment TRANSITION_FLOW_TREATMENT = DefaultTrafficTreatment.builder()
113 .setVlanId(VlanId.vlanId((short) 100))
114 .transition(10)
115 .build();
116 private static final TrafficSelector VLAN_FLOW_SELECTOR = DefaultTrafficSelector.builder()
117 .matchVlanId(VlanId.vlanId((short) 100))
118 .build();
119 private static final FlowRule FIRST_FLOW = DefaultFlowEntry.builder().forDevice(DUAL_FLOW_DEVICE)
120 .forTable(0)
121 .withPriority(100)
122 .withSelector(SINGLE_FLOW_SELECTOR)
123 .withTreatment(TRANSITION_FLOW_TREATMENT)
124 .fromApp(new DefaultApplicationId(0, "TestApp"))
125 .makePermanent()
126 .build();
127 static final FlowEntry FIRST_FLOW_ENTRY = new DefaultFlowEntry(FIRST_FLOW);
128 private static final FlowRule SECOND_FLOW = DefaultFlowEntry.builder().forDevice(DUAL_FLOW_DEVICE)
129 .forTable(10)
130 .withPriority(100)
131 .withSelector(VLAN_FLOW_SELECTOR)
132 .withTreatment(OUTPUT_FLOW_TREATMENT)
133 .fromApp(new DefaultApplicationId(0, "TestApp"))
134 .makePermanent()
135 .build();
136 static final FlowEntry SECOND_FLOW_ENTRY = new DefaultFlowEntry(SECOND_FLOW);
137
138 static final ConnectPoint DUAL_FLOW_IN_CP = ConnectPoint.deviceConnectPoint(DUAL_FLOW_DEVICE + "/" + 1);
139
140 static final ConnectPoint DUAL_FLOW_OUT_CP = ConnectPoint.deviceConnectPoint(DUAL_FLOW_DEVICE + "/" + 2);
141
142 //Flow and Group Test
143 static final DeviceId GROUP_FLOW_DEVICE = DeviceId.deviceId("GroupFlowDevice");
144
145 private static final GroupId GROUP_ID = GroupId.valueOf(1);
146
147 private static final TrafficTreatment GROUP_FLOW_TREATMENT = DefaultTrafficTreatment.builder()
Andrea Campanella09ca07a2018-01-25 16:44:04 +0100148 .pushMpls()
149 .setMpls(MplsLabel.mplsLabel(100))
Andrea Campanella01e886e2017-12-15 15:27:31 +0100150 .group(GROUP_ID)
151 .build();
152 private static final FlowRule GROUP_FLOW = DefaultFlowEntry.builder().forDevice(GROUP_FLOW_DEVICE)
153 .forTable(0)
154 .withPriority(100)
155 .withSelector(SINGLE_FLOW_SELECTOR)
156 .withTreatment(GROUP_FLOW_TREATMENT)
157 .fromApp(new DefaultApplicationId(0, "TestApp"))
158 .makePermanent()
159 .build();
160 static final FlowEntry GROUP_FLOW_ENTRY = new DefaultFlowEntry(GROUP_FLOW);
161
Andrea Campanella09ca07a2018-01-25 16:44:04 +0100162 private static final TrafficTreatment OUTPUT_GROUP_TREATMENT = DefaultTrafficTreatment.builder()
163 .popMpls(EthType.EtherType.IPV4.ethType())
164 .setOutput(PortNumber.portNumber(2)).build();
165
166 private static final GroupBucket BUCKET = DefaultGroupBucket.createSelectGroupBucket(OUTPUT_GROUP_TREATMENT);
Andrea Campanella01e886e2017-12-15 15:27:31 +0100167
168 private static final GroupBuckets BUCKETS = new GroupBuckets(ImmutableList.of(BUCKET));
169
170 static final Group GROUP = new DefaultGroup(GROUP_ID, GROUP_FLOW_DEVICE, Group.Type.SELECT, BUCKETS);
171
172 static final ConnectPoint GROUP_FLOW_IN_CP = ConnectPoint.deviceConnectPoint(GROUP_FLOW_DEVICE + "/" + 1);
173
174 static final ConnectPoint GROUP_FLOW_OUT_CP = ConnectPoint.deviceConnectPoint(GROUP_FLOW_DEVICE + "/" + 2);
175
176 //topology
177
178 static final DeviceId TOPO_FLOW_DEVICE = DeviceId.deviceId("SingleFlowDevice1");
179
180 static final DeviceId TOPO_FLOW_2_DEVICE = DeviceId.deviceId("SingleFlowDevice2");
181
182 static final DeviceId TOPO_FLOW_3_DEVICE = DeviceId.deviceId("SingleFlowDevice3");
183
184 private static final TrafficSelector TOPO_FLOW_SELECTOR = DefaultTrafficSelector.builder()
185 .matchInPort(PortNumber.portNumber(1))
186 .matchIPSrc(IpPrefix.valueOf("127.0.0.1/32"))
187 .matchIPDst(IpPrefix.valueOf("127.0.0.3/32"))
188 .build();
189
190 private static final FlowRule TOPO_SINGLE_FLOW = DefaultFlowEntry.builder().forDevice(TOPO_FLOW_DEVICE)
191 .forTable(0)
192 .withPriority(100)
193 .withSelector(TOPO_FLOW_SELECTOR)
194 .withTreatment(OUTPUT_FLOW_TREATMENT)
195 .fromApp(new DefaultApplicationId(0, "TestApp"))
196 .makePermanent()
197 .build();
198
199 static final FlowEntry TOPO_SINGLE_FLOW_ENTRY = new DefaultFlowEntry(TOPO_SINGLE_FLOW);
200
201 static final ConnectPoint TOPO_FLOW_1_IN_CP = ConnectPoint.deviceConnectPoint(TOPO_FLOW_DEVICE + "/" + 1);
202
203 static final ConnectPoint TOPO_FLOW_1_OUT_CP = ConnectPoint.deviceConnectPoint(TOPO_FLOW_DEVICE + "/" + 2);
204
205 static final ConnectPoint TOPO_FLOW_2_IN_CP = ConnectPoint.deviceConnectPoint(TOPO_FLOW_2_DEVICE + "/" + 1);
206
207 static final ConnectPoint TOPO_FLOW_2_OUT_CP = ConnectPoint.deviceConnectPoint(TOPO_FLOW_2_DEVICE + "/" + 2);
208
209 static final ConnectPoint TOPO_FLOW_3_IN_CP = ConnectPoint.deviceConnectPoint(TOPO_FLOW_3_DEVICE + "/" + 1);
210
211 static final ConnectPoint TOPO_FLOW_3_OUT_CP = ConnectPoint.deviceConnectPoint(TOPO_FLOW_3_DEVICE + "/" + 2);
212
213
214 //Topology with Groups
215
216 static final DeviceId TOPO_GROUP_FLOW_DEVICE = DeviceId.deviceId("TopoGroupFlowDevice");
217
218 private static final TrafficSelector TOPO_SECOND_INPUT_FLOW_SELECTOR = DefaultTrafficSelector.builder()
219 .matchInPort(PortNumber.portNumber(3))
220 .matchIPSrc(IpPrefix.valueOf("127.0.0.1/32"))
221 .matchIPDst(IpPrefix.valueOf("127.0.0.3/32"))
222 .build();
223
224 private static final FlowRule TOPO_SECOND_INPUT_FLOW = DefaultFlowEntry.builder().forDevice(TOPO_FLOW_3_DEVICE)
225 .forTable(0)
226 .withPriority(100)
227 .withSelector(TOPO_SECOND_INPUT_FLOW_SELECTOR)
228 .withTreatment(OUTPUT_FLOW_TREATMENT)
229 .fromApp(new DefaultApplicationId(0, "TestApp"))
230 .makePermanent()
231 .build();
232
233 private static final TrafficTreatment OUTPUT_2_FLOW_TREATMENT = DefaultTrafficTreatment.builder()
234 .setOutput(PortNumber.portNumber(3)).build();
235
236
237 private static final GroupId TOPO_GROUP_ID = GroupId.valueOf(1);
238
239 private static final TrafficTreatment TOPO_GROUP_FLOW_TREATMENT = DefaultTrafficTreatment.builder()
240 .group(TOPO_GROUP_ID)
241 .build();
242 private static final FlowRule TOPO_GROUP_FLOW = DefaultFlowEntry.builder().forDevice(TOPO_GROUP_FLOW_DEVICE)
243 .forTable(0)
244 .withPriority(100)
245 .withSelector(TOPO_FLOW_SELECTOR)
246 .withTreatment(TOPO_GROUP_FLOW_TREATMENT)
247 .fromApp(new DefaultApplicationId(0, "TestApp"))
248 .makePermanent()
249 .build();
250 static final FlowEntry TOPO_GROUP_FLOW_ENTRY = new DefaultFlowEntry(TOPO_GROUP_FLOW);
251
252 private static final GroupBucket BUCKET_2 = DefaultGroupBucket.createSelectGroupBucket(OUTPUT_2_FLOW_TREATMENT);
253
254 private static final GroupBuckets BUCKETS_MULTIPLE = new GroupBuckets(ImmutableList.of(BUCKET, BUCKET_2));
255
Andrea Campanella2bc55dd2018-01-18 16:54:34 +0100256 static final Group TOPO_GROUP = new DefaultGroup(TOPO_GROUP_ID, TOPO_GROUP_FLOW_DEVICE,
257 Group.Type.SELECT, BUCKETS_MULTIPLE);
Andrea Campanella01e886e2017-12-15 15:27:31 +0100258
259 static final FlowEntry TOPO_SECOND_INPUT_FLOW_ENTRY = new DefaultFlowEntry(TOPO_SECOND_INPUT_FLOW);
260
261 static final DeviceId TOPO_FLOW_4_DEVICE = DeviceId.deviceId("SingleFlowDevice4");
262
263 static final ConnectPoint TOPO_FLOW_IN_CP = ConnectPoint.deviceConnectPoint(TOPO_GROUP_FLOW_DEVICE + "/" + 1);
264
265 static final ConnectPoint TOPO_FLOW_OUT_CP_1 = ConnectPoint.deviceConnectPoint(TOPO_GROUP_FLOW_DEVICE + "/" + 2);
266
Andrea Campanella2bc55dd2018-01-18 16:54:34 +0100267 protected static final ConnectPoint TOPO_FLOW_OUT_CP_2 =
268 ConnectPoint.deviceConnectPoint(TOPO_GROUP_FLOW_DEVICE + "/" + 3);
Andrea Campanella01e886e2017-12-15 15:27:31 +0100269
270 static final ConnectPoint TOPO_FLOW_4_IN_CP = ConnectPoint.deviceConnectPoint(TOPO_FLOW_4_DEVICE + "/" + 1);
271
272 static final ConnectPoint TOPO_FLOW_3_IN_2_CP = ConnectPoint.deviceConnectPoint(TOPO_FLOW_3_DEVICE + "/" + 3);
273
274 static final ConnectPoint TOPO_FLOW_4_OUT_CP = ConnectPoint.deviceConnectPoint(TOPO_FLOW_4_DEVICE + "/" + 2);
275
276
277 //hardware
278
279 static final DeviceId HARDWARE_DEVICE = DeviceId.deviceId("HardwareDevice");
280
281 static final ConnectPoint HARDWARE_DEVICE_IN_CP = ConnectPoint.deviceConnectPoint(HARDWARE_DEVICE + "/" + 1);
282
283 static final ConnectPoint HARDWARE_DEVICE_OUT_CP = ConnectPoint.deviceConnectPoint(HARDWARE_DEVICE + "/" + 2);
284
285 private static final TrafficSelector HARDWARE_FLOW_SELECTOR = DefaultTrafficSelector.builder()
286 .matchInPort(PortNumber.portNumber(1))
287 .matchIPSrc(IpPrefix.valueOf("127.0.0.1/32"))
288 .matchIPDst(IpPrefix.valueOf("127.0.0.2/32"))
289 .build();
290
291 private static final TrafficTreatment HW_TRANSITION_FLOW_TREATMENT = DefaultTrafficTreatment.builder()
292 .pushMpls()
293 .transition(27)
294 .build();
295
296 private static final FlowRule HARDWARE_FLOW = DefaultFlowEntry.builder().forDevice(TOPO_FLOW_3_DEVICE)
297 .forTable(0)
298 .withPriority(100)
299 .withSelector(HARDWARE_FLOW_SELECTOR)
300 .withTreatment(HW_TRANSITION_FLOW_TREATMENT)
301 .fromApp(new DefaultApplicationId(0, "TestApp"))
302 .makePermanent()
303 .build();
304
305 static final FlowEntry HARDWARE_FLOW_ENTRY = new DefaultFlowEntry(HARDWARE_FLOW);
306
307 private static final TrafficSelector HARDWARE_ETH_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 .matchEthType(EthType.EtherType.IPV4.ethType().toShort())
312 .build();
313
314 private static final FlowRule HARDWARE_ETH_FLOW = DefaultFlowEntry.builder().forDevice(TOPO_FLOW_3_DEVICE)
315 .forTable(30)
316 .withPriority(100)
317 .withSelector(HARDWARE_ETH_FLOW_SELECTOR)
318 .withTreatment(OUTPUT_FLOW_TREATMENT)
319 .fromApp(new DefaultApplicationId(0, "TestApp"))
320 .makePermanent()
321 .build();
322
323 static final FlowEntry HARDWARE_ETH_FLOW_ENTRY = new DefaultFlowEntry(HARDWARE_ETH_FLOW);
324
325
326
327
328 //helper elements
329
330 static final Host H1 = new DefaultHost(ProviderId.NONE, HostId.hostId(HOST_ONE), MacAddress.valueOf(100),
331 VlanId.NONE, new HostLocation(SINGLE_FLOW_DEVICE, PortNumber.portNumber(2), 0),
332 ImmutableSet.of(IpAddress.valueOf("127.0.0.2")));
333
334 static final Host H2 = new DefaultHost(ProviderId.NONE, HostId.hostId(HOST_TWO), MacAddress.valueOf(100),
335 VlanId.NONE, new HostLocation(TOPO_FLOW_3_DEVICE, PortNumber.portNumber(2), 0),
336 ImmutableSet.of(IpAddress.valueOf("127.0.0.3")));
337
338 static final TrafficSelector PACKET_OK = DefaultTrafficSelector.builder()
339 .matchInPort(PortNumber.portNumber(1))
Andrea Campanella2bc55dd2018-01-18 16:54:34 +0100340 .matchEthType(EthType.EtherType.IPV4.ethType().toShort())
Andrea Campanella01e886e2017-12-15 15:27:31 +0100341 .matchIPSrc(IpPrefix.valueOf("127.0.0.1/32"))
342 .matchIPDst(IpPrefix.valueOf("127.0.0.2/32"))
343 .build();
344
345 static final TrafficSelector PACKET_OK_TOPO = DefaultTrafficSelector.builder()
346 .matchInPort(PortNumber.portNumber(1))
347 .matchIPSrc(IpPrefix.valueOf("127.0.0.1/32"))
348 .matchIPDst(IpPrefix.valueOf("127.0.0.3/32"))
349 .build();
350
351 static final TrafficSelector PACKET_FAIL = DefaultTrafficSelector.builder()
352 .matchInPort(PortNumber.portNumber(1))
353 .matchIPSrc(IpPrefix.valueOf("127.0.0.1/32"))
354 .matchIPDst(IpPrefix.valueOf("127.0.0.99/32"))
355 .build();
356}