blob: 94096b5d5c8f163482355be7bb1b955fb337b354 [file] [log] [blame]
Charles Chana7903c82018-03-15 20:14:16 -07001/*
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
17package org.onosproject.net.flowobjective.impl;
18
19import com.google.common.collect.Lists;
20import com.google.common.collect.Sets;
21import org.junit.Before;
22import org.junit.Ignore;
23import org.junit.Test;
24import org.onlab.packet.Ethernet;
25import org.onlab.packet.IpPrefix;
26import org.onlab.packet.MacAddress;
27import org.onlab.packet.MplsLabel;
28import org.onlab.packet.VlanId;
Charles Chan63152d42018-04-19 21:38:40 -070029import org.onosproject.cfg.ComponentConfigService;
Charles Chana7903c82018-03-15 20:14:16 -070030import org.onosproject.core.ApplicationId;
31import org.onosproject.core.DefaultApplicationId;
32import org.onosproject.net.DeviceId;
33import org.onosproject.net.PortNumber;
34import org.onosproject.net.behaviour.NextGroup;
35import org.onosproject.net.behaviour.Pipeliner;
36import org.onosproject.net.behaviour.PipelinerAdapter;
Charles Chan63152d42018-04-19 21:38:40 -070037import org.onosproject.net.device.DeviceService;
38import org.onosproject.net.driver.DriverService;
Charles Chana7903c82018-03-15 20:14:16 -070039import org.onosproject.net.flow.DefaultTrafficSelector;
40import org.onosproject.net.flow.DefaultTrafficTreatment;
41import org.onosproject.net.flow.TrafficSelector;
42import org.onosproject.net.flow.TrafficTreatment;
43import org.onosproject.net.flow.criteria.Criteria;
44import org.onosproject.net.flowobjective.DefaultFilteringObjective;
45import org.onosproject.net.flowobjective.DefaultForwardingObjective;
46import org.onosproject.net.flowobjective.DefaultNextObjective;
47import org.onosproject.net.flowobjective.FilteringObjective;
48import org.onosproject.net.flowobjective.FlowObjectiveStore;
49import org.onosproject.net.flowobjective.ForwardingObjective;
50import org.onosproject.net.flowobjective.NextObjective;
51import org.onosproject.net.flowobjective.Objective;
Charles Chan63152d42018-04-19 21:38:40 -070052import org.onosproject.net.flowobjective.ObjectiveContext;
Charles Chana7903c82018-03-15 20:14:16 -070053import org.onosproject.net.flowobjective.ObjectiveError;
54import org.onosproject.net.flowobjective.ObjectiveEvent;
55
56import static java.util.concurrent.Executors.newFixedThreadPool;
57import static org.easymock.EasyMock.createMock;
58import static org.easymock.EasyMock.expect;
59import static org.easymock.EasyMock.replay;
Charles Chan63152d42018-04-19 21:38:40 -070060import static org.easymock.EasyMock.reset;
Charles Chana7903c82018-03-15 20:14:16 -070061import static org.easymock.EasyMock.verify;
62import static org.junit.Assert.assertTrue;
63import static org.junit.Assert.assertEquals;
64import static org.onlab.junit.TestTools.assertAfter;
65import static org.onlab.util.Tools.groupedThreads;
66
67import java.util.Collection;
68import java.util.List;
Charles Chan16ec41d2018-11-27 21:33:33 +080069import java.util.Objects;
Charles Chana7903c82018-03-15 20:14:16 -070070import java.util.Random;
Charles Chan16ec41d2018-11-27 21:33:33 +080071import java.util.concurrent.atomic.AtomicInteger;
Charles Chana7903c82018-03-15 20:14:16 -070072
73public class InOrderFlowObjectiveManagerTest {
74 private InOrderFlowObjectiveManager mgr;
75
76 private static final int PRIORITY = 1000;
77 private static final ApplicationId APP_ID = new DefaultApplicationId(1, "org.onosproject.test");
78 private static final DeviceId DEV1 = DeviceId.deviceId("of:1");
79 private static final PortNumber P1 = PortNumber.portNumber(1);
80 private static final PortNumber P2 = PortNumber.portNumber(2);
81 private static final PortNumber P3 = PortNumber.portNumber(3);
82 private static final PortNumber P4 = PortNumber.portNumber(4);
83 private static final MacAddress M1 = MacAddress.valueOf("00:00:00:00:00:01");
84 private static final MacAddress M2 = MacAddress.valueOf("00:00:00:00:00:02");
85 private static final MacAddress M3 = MacAddress.valueOf("00:00:00:00:00:03");
86 private static final VlanId V1 = VlanId.vlanId((short) 10);
87 private static final VlanId V2 = VlanId.vlanId((short) 20);
88 private static final VlanId V3 = VlanId.vlanId((short) 30);
89 private static final TrafficSelector S1 = DefaultTrafficSelector.builder()
90 .matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IpPrefix.valueOf("10.0.0.1/32")).build();
91 private static final TrafficSelector S2 = DefaultTrafficSelector.builder()
92 .matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IpPrefix.valueOf("10.0.0.2/32")).build();
93 private static final int NID1 = 1;
94 private static final int NID2 = 2;
95 private static final NextGroup NGRP1 = () -> new byte[] {0x00, 0x01};
96 private static final NextGroup NGRP2 = () -> new byte[] {0x02, 0x03};
97
98 // Delay flow objectives OFFSET + rand(0, BOUND) millis
Charles Chan63152d42018-04-19 21:38:40 -070099 private static final int DEFAULT_OFFSET = 10; // ms
100 private static final int DEFAULT_BOUND = 40; // ms
Charles Chan16ec41d2018-11-27 21:33:33 +0800101 private static final int TIMEOUT_THRESH = 100; // ms
Charles Chan63152d42018-04-19 21:38:40 -0700102 private static int offset = DEFAULT_OFFSET;
103 private static int bound = DEFAULT_BOUND;
Charles Chana7903c82018-03-15 20:14:16 -0700104
105 private static final FilteringObjective FILT1 = buildFilteringObjective(P2, V3, M3, 1).add();
106 private static final FilteringObjective FILT2 = buildFilteringObjective(P2, V2, M2, 2).add();
107 private static final FilteringObjective FILT3 = buildFilteringObjective(P2, V3, M3, 3).remove();
108 private static final FilteringObjective FILT4 = buildFilteringObjective(P1, V1, M1, 4).add();
109 private static final FilteringObjective FILT5 = buildFilteringObjective(P2, V2, M2, 5).remove();
110 private static final FilteringObjective FILT6 = buildFilteringObjective(P1, V1, M1, 6).remove();
111 private static final FilteringObjective FILT7 = buildFilteringObjective(P2, V3, M3, 7).add();
112 private List<FilteringObjective> expectFiltObjs = Lists.newCopyOnWriteArrayList(
113 Lists.newArrayList(FILT1, FILT2, FILT3, FILT4, FILT5, FILT6, FILT7));
114
115 private static final NextObjective NEXT1 = buildNextObjective(NID1, V1, Sets.newHashSet(P1)).add();
116 private static final NextObjective NEXT2 = buildNextObjective(NID2, V2, Sets.newHashSet(P3)).add();
117 private static final NextObjective NEXT3 = buildNextObjective(NID1, V1, Sets.newHashSet(P1, P2)).addToExisting();
118 private static final NextObjective NEXT4 = buildNextObjective(NID2, V2, Sets.newHashSet(P3, P4)).addToExisting();
119 private static final NextObjective NEXT5 = buildNextObjective(NID1, V1, Sets.newHashSet(P1)).removeFromExisting();
120 private static final NextObjective NEXT6 = buildNextObjective(NID2, V2, Sets.newHashSet(P3)).removeFromExisting();
121 private static final NextObjective NEXT7 = buildNextObjective(NID1, V1, Sets.newHashSet()).remove();
122 private static final NextObjective NEXT8 = buildNextObjective(NID2, V2, Sets.newHashSet()).remove();
123 private List<NextObjective> expectNextObjs = Lists.newCopyOnWriteArrayList(
124 Lists.newArrayList(NEXT1, NEXT2, NEXT3, NEXT4, NEXT5, NEXT6, NEXT7, NEXT8));
125 private List<NextObjective> expectNextObjsPending = Lists.newCopyOnWriteArrayList(
126 Lists.newArrayList(NEXT5, NEXT6, NEXT1, NEXT2, NEXT3, NEXT4, NEXT7, NEXT8));
127
128 private static final ForwardingObjective FWD1 = buildFwdObjective(S1, NID1).add();
129 private static final ForwardingObjective FWD2 = buildFwdObjective(S2, NID2).add();
130 private static final ForwardingObjective FWD3 = buildFwdObjective(S1, NID2).add();
131 private static final ForwardingObjective FWD4 = buildFwdObjective(S2, NID1).add();
132 private static final ForwardingObjective FWD5 = buildFwdObjective(S1, NID2).remove();
133 private static final ForwardingObjective FWD6 = buildFwdObjective(S2, NID1).remove();
134 private List<ForwardingObjective> expectFwdObjs = Lists.newCopyOnWriteArrayList(
135 Lists.newArrayList(FWD1, FWD2, FWD3, FWD4, FWD5, FWD6));
136
137 private List<Objective> actualObjs = Lists.newCopyOnWriteArrayList();
138
139 private Pipeliner pipeliner = new PipelinerAdapter() {
140 @Override
141 public void filter(FilteringObjective filterObjective) {
142 recordObjective(filterObjective);
143 }
144
145 @Override
146 public void forward(ForwardingObjective forwardObjective) {
147 recordObjective(forwardObjective);
148 }
149
150 @Override
151 public void next(NextObjective nextObjective) {
152 recordObjective(nextObjective);
153
154 // Notify delegate when the next obj is completed
155 ObjectiveEvent.Type type;
156 if (nextObjective.op() == Objective.Operation.ADD ||
157 nextObjective.op() == Objective.Operation.ADD_TO_EXISTING) {
158 type = ObjectiveEvent.Type.ADD;
159 } else if (nextObjective.op() == Objective.Operation.REMOVE ||
160 nextObjective.op() == Objective.Operation.REMOVE_FROM_EXISTING) {
161 type = ObjectiveEvent.Type.REMOVE;
162 } else {
163 return;
164 }
165 mgr.delegate.notify(new ObjectiveEvent(type, nextObjective.id()));
166 }
167
168 /**
169 * Record the objectives.
170 * The random delay is introduced in order to mimic pipeline and flow operation behavior.
171 *
172 * @param obj Flow objective
173 */
174 private void recordObjective(Objective obj) {
175 try {
Charles Chan63152d42018-04-19 21:38:40 -0700176 Thread.sleep(new Random().nextInt(bound) + offset);
Charles Chana7903c82018-03-15 20:14:16 -0700177 actualObjs.add(obj);
178 obj.context().ifPresent(c -> c.onSuccess(obj));
179 } catch (Exception e) {
180 obj.context().ifPresent(c -> c.onError(obj, ObjectiveError.UNKNOWN));
181 }
182 }
183 };
184
185 @Before
186 public void setUp() {
187 mgr = new InOrderFlowObjectiveManager();
188 mgr.pipeliners.put(DEV1, pipeliner);
189 mgr.executorService = newFixedThreadPool(4, groupedThreads("foo", "bar"));
Charles Chan63152d42018-04-19 21:38:40 -0700190 mgr.cfgService = createMock(ComponentConfigService.class);
191 mgr.deviceService = createMock(DeviceService.class);
192 mgr.driverService = createMock(DriverService.class);
Charles Chana7903c82018-03-15 20:14:16 -0700193 mgr.flowObjectiveStore = createMock(FlowObjectiveStore.class);
Charles Chan63152d42018-04-19 21:38:40 -0700194 mgr.activate();
Charles Chana7903c82018-03-15 20:14:16 -0700195
Charles Chan63152d42018-04-19 21:38:40 -0700196 reset(mgr.flowObjectiveStore);
Charles Chan63152d42018-04-19 21:38:40 -0700197 offset = DEFAULT_OFFSET;
198 bound = DEFAULT_BOUND;
Charles Chana7903c82018-03-15 20:14:16 -0700199 actualObjs.clear();
200 }
201
202 @Test
Charles Chan63152d42018-04-19 21:38:40 -0700203 public void filter() {
Charles Chana7903c82018-03-15 20:14:16 -0700204 expectFiltObjs.forEach(filtObj -> mgr.filter(DEV1, filtObj));
205
206 // Wait for the pipeline operation to complete
Charles Chan63152d42018-04-19 21:38:40 -0700207 int expectedTime = (bound + offset) * 7;
Charles Chana7903c82018-03-15 20:14:16 -0700208 assertAfter(expectedTime, expectedTime * 5, () -> assertEquals(expectFiltObjs.size(), actualObjs.size()));
209
210 assertTrue(actualObjs.indexOf(FILT1) < actualObjs.indexOf(FILT2));
211 assertTrue(actualObjs.indexOf(FILT2) < actualObjs.indexOf(FILT3));
212 assertTrue(actualObjs.indexOf(FILT3) < actualObjs.indexOf(FILT5));
213 assertTrue(actualObjs.indexOf(FILT5) < actualObjs.indexOf(FILT7));
214 assertTrue(actualObjs.indexOf(FILT4) < actualObjs.indexOf(FILT6));
215 }
216
217 @Test
Charles Chan63152d42018-04-19 21:38:40 -0700218 public void forward() {
Charles Chana7903c82018-03-15 20:14:16 -0700219 expect(mgr.flowObjectiveStore.getNextGroup(NID1)).andReturn(NGRP1).times(3);
220 expect(mgr.flowObjectiveStore.getNextGroup(NID2)).andReturn(NGRP2).times(3);
221 replay(mgr.flowObjectiveStore);
222
223 expectFwdObjs.forEach(fwdObj -> mgr.forward(DEV1, fwdObj));
224
225 // Wait for the pipeline operation to complete
Charles Chan63152d42018-04-19 21:38:40 -0700226 int expectedTime = (bound + offset) * 6;
Charles Chana7903c82018-03-15 20:14:16 -0700227 assertAfter(expectedTime, expectedTime * 5, () -> assertEquals(expectFwdObjs.size(), actualObjs.size()));
228
229 assertTrue(actualObjs.indexOf(FWD1) < actualObjs.indexOf(FWD3));
230 assertTrue(actualObjs.indexOf(FWD3) < actualObjs.indexOf(FWD5));
231 assertTrue(actualObjs.indexOf(FWD2) < actualObjs.indexOf(FWD4));
232 assertTrue(actualObjs.indexOf(FWD4) < actualObjs.indexOf(FWD6));
233
234 verify(mgr.flowObjectiveStore);
235 }
236
237 @Test
Charles Chan63152d42018-04-19 21:38:40 -0700238 public void forwardTimeout() {
Charles Chan16ec41d2018-11-27 21:33:33 +0800239 final AtomicInteger counter = new AtomicInteger(0);
240 ForwardingObjective fwdTimeout = buildFwdObjective(S1, NID2).add(new ObjectiveContext() {
241 @Override
242 public void onError(Objective objective, ObjectiveError error) {
243 if (Objects.equals(ObjectiveError.INSTALLATIONTIMEOUT, error)) {
244 counter.incrementAndGet();
245 }
246 }
247 });
248 List<ForwardingObjective> expectFwdObjsTimeout = Lists.newCopyOnWriteArrayList(
249 Lists.newArrayList(fwdTimeout, FWD1, FWD2));
250
251 // Reduce timeout so the unit test doesn't have to wait many seconds
252 InOrderFlowObjectiveManager.objTimeoutMs = TIMEOUT_THRESH;
253 setUp();
254
Charles Chan63152d42018-04-19 21:38:40 -0700255 expect(mgr.flowObjectiveStore.getNextGroup(NID1)).andReturn(NGRP1).times(1);
256 expect(mgr.flowObjectiveStore.getNextGroup(NID2)).andReturn(NGRP2).times(2);
257 replay(mgr.flowObjectiveStore);
258
259 // Force this objective to time out
Charles Chan16ec41d2018-11-27 21:33:33 +0800260 offset = InOrderFlowObjectiveManager.objTimeoutMs * 2;
Charles Chan63152d42018-04-19 21:38:40 -0700261
262 expectFwdObjsTimeout.forEach(fwdObj -> mgr.forward(DEV1, fwdObj));
263
264 // Wait for the pipeline operation to complete
265 int expectedTime = (bound + offset) * 3;
266 assertAfter(expectedTime, expectedTime * 5, () -> assertEquals(expectFwdObjsTimeout.size(), actualObjs.size()));
267
Charles Chan16ec41d2018-11-27 21:33:33 +0800268 assertTrue(counter.get() != 0);
269 assertTrue(actualObjs.indexOf(fwdTimeout) < actualObjs.indexOf(FWD1));
Charles Chan63152d42018-04-19 21:38:40 -0700270
271 verify(mgr.flowObjectiveStore);
272 }
273
274 @Test
275 public void forwardPending() {
Charles Chana7903c82018-03-15 20:14:16 -0700276 // Note: current logic will double check if the next obj need to be queued
277 // it does not check when resubmitting pending next back to the queue
278 expect(mgr.flowObjectiveStore.getNextGroup(NID1)).andReturn(null).times(2);
279 expect(mgr.flowObjectiveStore.getNextGroup(NID2)).andReturn(null).times(2);
280 expect(mgr.flowObjectiveStore.getNextGroup(NID1)).andReturn(NGRP1).times(3);
281 expect(mgr.flowObjectiveStore.getNextGroup(NID2)).andReturn(NGRP2).times(3);
282 replay(mgr.flowObjectiveStore);
283
284 expectFwdObjs.forEach(fwdObj -> mgr.forward(DEV1, fwdObj));
285
286 // Trigger the next objectives
287 mgr.next(DEV1, NEXT1);
288 mgr.next(DEV1, NEXT2);
289
290 // Wait for the pipeline operation to complete
Charles Chan63152d42018-04-19 21:38:40 -0700291 int expectedTime = (bound + offset) * 8;
Charles Chana7903c82018-03-15 20:14:16 -0700292 assertAfter(expectedTime, expectedTime * 5, () -> assertEquals(expectFwdObjs.size() + 2, actualObjs.size()));
293
294 assertTrue(actualObjs.indexOf(NEXT1) < actualObjs.indexOf(FWD1));
295 assertTrue(actualObjs.indexOf(FWD1) < actualObjs.indexOf(FWD3));
296 assertTrue(actualObjs.indexOf(FWD3) < actualObjs.indexOf(FWD5));
297 assertTrue(actualObjs.indexOf(NEXT2) < actualObjs.indexOf(FWD2));
298 assertTrue(actualObjs.indexOf(FWD2) < actualObjs.indexOf(FWD4));
299 assertTrue(actualObjs.indexOf(FWD4) < actualObjs.indexOf(FWD6));
300
301 verify(mgr.flowObjectiveStore);
302 }
303
304 @Test
Charles Chan63152d42018-04-19 21:38:40 -0700305 public void next() {
Charles Chana7903c82018-03-15 20:14:16 -0700306 // Note: ADD operation won't query this
307 expect(mgr.flowObjectiveStore.getNextGroup(NID1)).andReturn(NGRP1).times(3);
308 expect(mgr.flowObjectiveStore.getNextGroup(NID2)).andReturn(NGRP2).times(3);
309 replay(mgr.flowObjectiveStore);
310
311 expectNextObjs.forEach(nextObj -> mgr.next(DEV1, nextObj));
312
313 // Wait for the pipeline operation to complete
Charles Chan63152d42018-04-19 21:38:40 -0700314 int expectedTime = (bound + offset) * 8;
Charles Chana7903c82018-03-15 20:14:16 -0700315 assertAfter(expectedTime, expectedTime * 5, () -> assertEquals(expectNextObjs.size(), actualObjs.size()));
316
317 assertTrue(actualObjs.indexOf(NEXT1) < actualObjs.indexOf(NEXT3));
318 assertTrue(actualObjs.indexOf(NEXT3) < actualObjs.indexOf(NEXT5));
319 assertTrue(actualObjs.indexOf(NEXT5) < actualObjs.indexOf(NEXT7));
320 assertTrue(actualObjs.indexOf(NEXT2) < actualObjs.indexOf(NEXT4));
321 assertTrue(actualObjs.indexOf(NEXT4) < actualObjs.indexOf(NEXT6));
322 assertTrue(actualObjs.indexOf(NEXT6) < actualObjs.indexOf(NEXT8));
323
324 verify(mgr.flowObjectiveStore);
325 }
326
327 // FIXME We currently do not handle the case when an app sends edit/remove of a next id before add.
328 // The edit/remove operation will be queued by pendingNext, and the add operation will be
329 // queued by the ordering queue forever due to the deadlock. This can be improved by making
330 // pendingForwards, pendingNexts and ordering queue caches.
331 @Test
332 @Ignore("Not supported")
Charles Chan63152d42018-04-19 21:38:40 -0700333 public void nextPending() {
Charles Chana7903c82018-03-15 20:14:16 -0700334 // Note: current logic will double check if the next obj need to be queued
335 // it does not check when resubmitting pending next back to the queue
336 expect(mgr.flowObjectiveStore.getNextGroup(NID1)).andReturn(null).times(6);
337 expect(mgr.flowObjectiveStore.getNextGroup(NID2)).andReturn(null).times(6);
338 replay(mgr.flowObjectiveStore);
339
340 expectNextObjsPending.forEach(nextObj -> mgr.next(DEV1, nextObj));
341
342 // Wait for the pipeline operation to complete
Charles Chan63152d42018-04-19 21:38:40 -0700343 int expectedTime = (bound + offset) * 8;
Charles Chana7903c82018-03-15 20:14:16 -0700344 assertAfter(expectedTime, expectedTime * 5, () -> assertEquals(expectNextObjs.size(), actualObjs.size()));
345
346 assertTrue(actualObjs.indexOf(NEXT1) < actualObjs.indexOf(NEXT5));
347 assertTrue(actualObjs.indexOf(NEXT5) < actualObjs.indexOf(NEXT3));
348 assertTrue(actualObjs.indexOf(NEXT3) < actualObjs.indexOf(NEXT7));
349 assertTrue(actualObjs.indexOf(NEXT2) < actualObjs.indexOf(NEXT6));
350 assertTrue(actualObjs.indexOf(NEXT6) < actualObjs.indexOf(NEXT4));
351 assertTrue(actualObjs.indexOf(NEXT4) < actualObjs.indexOf(NEXT8));
352
353 verify(mgr.flowObjectiveStore);
354 }
355
356 /**
357 * Creates filtering objective builder with a serial number encoded in MPLS label.
358 * The serial number is used to identify same objective that occurs multiple times.
359 *
360 * @param portnum Port number
361 * @param vlanId VLAN Id
362 * @param mac MAC address
363 * @param serial Serial number
364 * @return Filtering objective builder
365 */
366 private static FilteringObjective.Builder buildFilteringObjective(PortNumber portnum, VlanId vlanId,
367 MacAddress mac, int serial) {
368 FilteringObjective.Builder fob = DefaultFilteringObjective.builder();
369 fob.withKey(Criteria.matchInPort(portnum))
370 .addCondition(Criteria.matchEthDst(mac))
371 .addCondition(Criteria.matchVlanId(VlanId.NONE))
372 .addCondition(Criteria.matchMplsLabel(MplsLabel.mplsLabel(serial)))
373 .withPriority(PRIORITY);
374
375 TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
376 tBuilder.pushVlan().setVlanId(vlanId);
377 fob.withMeta(tBuilder.build());
378
379 fob.permit().fromApp(APP_ID);
380 return fob;
381 }
382
383 /**
384 * Creates next objective builder.
385 *
386 * @param nextId next ID
387 * @param vlanId VLAN ID
388 * @param ports Set of ports that is in the given VLAN ID
389 *
390 * @return Next objective builder
391 */
392 private static NextObjective.Builder buildNextObjective(int nextId, VlanId vlanId, Collection<PortNumber> ports) {
393 TrafficSelector metadata =
394 DefaultTrafficSelector.builder().matchVlanId(vlanId).build();
395
396 NextObjective.Builder nextObjBuilder = DefaultNextObjective
397 .builder().withId(nextId)
398 .withType(NextObjective.Type.BROADCAST).fromApp(APP_ID)
399 .withMeta(metadata);
400
401 ports.forEach(port -> {
402 TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
403 tBuilder.popVlan();
404 tBuilder.setOutput(port);
405 nextObjBuilder.addTreatment(tBuilder.build());
406 });
407
408 return nextObjBuilder;
409 }
410
411 /**
412 * Creates forwarding objective builder.
413 *
414 * @param selector Traffic selector
415 * @param nextId next ID
416 * @return Forwarding objective builder
417 */
418 private static ForwardingObjective.Builder buildFwdObjective(TrafficSelector selector, int nextId) {
419 return DefaultForwardingObjective.builder()
420 .makePermanent()
421 .withSelector(selector)
422 .nextStep(nextId)
423 .fromApp(APP_ID)
424 .withPriority(PRIORITY)
425 .withFlag(ForwardingObjective.Flag.SPECIFIC);
426 }
427}