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