blob: f7ba5bceffb260e9785b7dc37f4d23d60ca0fb5b [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 Chan45c19d72018-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 Chan45c19d72018-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 Chan45c19d72018-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 Chan45c19d72018-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 Chan1491b9b2018-11-27 21:33:33 +080069import java.util.Objects;
Charles Chana7903c82018-03-15 20:14:16 -070070import java.util.Random;
Charles Chan1491b9b2018-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 Chan45c19d72018-04-19 21:38:40 -070099 private static final int DEFAULT_OFFSET = 10; // ms
100 private static final int DEFAULT_BOUND = 40; // ms
Charles Chan1491b9b2018-11-27 21:33:33 +0800101 private static final int TIMEOUT_THRESH = 100; // ms
Charles Chan45c19d72018-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 Chan45c19d72018-04-19 21:38:40 -0700176 Thread.sleep(new Random().nextInt(bound) + offset);
Ray Milkey95c9e0f2018-05-30 14:16:37 -0700177 if (!actualObjs.contains(obj)) {
178 actualObjs.add(obj);
179 }
Charles Chana7903c82018-03-15 20:14:16 -0700180 obj.context().ifPresent(c -> c.onSuccess(obj));
181 } catch (Exception e) {
182 obj.context().ifPresent(c -> c.onError(obj, ObjectiveError.UNKNOWN));
183 }
184 }
185 };
186
187 @Before
188 public void setUp() {
189 mgr = new InOrderFlowObjectiveManager();
190 mgr.pipeliners.put(DEV1, pipeliner);
191 mgr.executorService = newFixedThreadPool(4, groupedThreads("foo", "bar"));
Charles Chan45c19d72018-04-19 21:38:40 -0700192 mgr.cfgService = createMock(ComponentConfigService.class);
193 mgr.deviceService = createMock(DeviceService.class);
194 mgr.driverService = createMock(DriverService.class);
Charles Chana7903c82018-03-15 20:14:16 -0700195 mgr.flowObjectiveStore = createMock(FlowObjectiveStore.class);
Charles Chan45c19d72018-04-19 21:38:40 -0700196 mgr.activate();
Charles Chana7903c82018-03-15 20:14:16 -0700197
Charles Chan45c19d72018-04-19 21:38:40 -0700198 reset(mgr.flowObjectiveStore);
Charles Chan45c19d72018-04-19 21:38:40 -0700199 offset = DEFAULT_OFFSET;
200 bound = DEFAULT_BOUND;
Charles Chana7903c82018-03-15 20:14:16 -0700201 actualObjs.clear();
202 }
203
204 @Test
Charles Chan45c19d72018-04-19 21:38:40 -0700205 public void filter() {
Charles Chana7903c82018-03-15 20:14:16 -0700206 expectFiltObjs.forEach(filtObj -> mgr.filter(DEV1, filtObj));
207
208 // Wait for the pipeline operation to complete
Charles Chan45c19d72018-04-19 21:38:40 -0700209 int expectedTime = (bound + offset) * 7;
Charles Chana7903c82018-03-15 20:14:16 -0700210 assertAfter(expectedTime, expectedTime * 5, () -> assertEquals(expectFiltObjs.size(), actualObjs.size()));
211
212 assertTrue(actualObjs.indexOf(FILT1) < actualObjs.indexOf(FILT2));
213 assertTrue(actualObjs.indexOf(FILT2) < actualObjs.indexOf(FILT3));
214 assertTrue(actualObjs.indexOf(FILT3) < actualObjs.indexOf(FILT5));
215 assertTrue(actualObjs.indexOf(FILT5) < actualObjs.indexOf(FILT7));
216 assertTrue(actualObjs.indexOf(FILT4) < actualObjs.indexOf(FILT6));
217 }
218
219 @Test
Charles Chan45c19d72018-04-19 21:38:40 -0700220 public void forward() {
Charles Chana7903c82018-03-15 20:14:16 -0700221 expect(mgr.flowObjectiveStore.getNextGroup(NID1)).andReturn(NGRP1).times(3);
222 expect(mgr.flowObjectiveStore.getNextGroup(NID2)).andReturn(NGRP2).times(3);
223 replay(mgr.flowObjectiveStore);
224
225 expectFwdObjs.forEach(fwdObj -> mgr.forward(DEV1, fwdObj));
226
227 // Wait for the pipeline operation to complete
Charles Chan45c19d72018-04-19 21:38:40 -0700228 int expectedTime = (bound + offset) * 6;
Charles Chana7903c82018-03-15 20:14:16 -0700229 assertAfter(expectedTime, expectedTime * 5, () -> assertEquals(expectFwdObjs.size(), actualObjs.size()));
230
231 assertTrue(actualObjs.indexOf(FWD1) < actualObjs.indexOf(FWD3));
232 assertTrue(actualObjs.indexOf(FWD3) < actualObjs.indexOf(FWD5));
233 assertTrue(actualObjs.indexOf(FWD2) < actualObjs.indexOf(FWD4));
234 assertTrue(actualObjs.indexOf(FWD4) < actualObjs.indexOf(FWD6));
235
236 verify(mgr.flowObjectiveStore);
237 }
238
239 @Test
Charles Chan45c19d72018-04-19 21:38:40 -0700240 public void forwardTimeout() {
Charles Chan1491b9b2018-11-27 21:33:33 +0800241 final AtomicInteger counter = new AtomicInteger(0);
242 ForwardingObjective fwdTimeout = buildFwdObjective(S1, NID2).add(new ObjectiveContext() {
243 @Override
244 public void onError(Objective objective, ObjectiveError error) {
245 if (Objects.equals(ObjectiveError.INSTALLATIONTIMEOUT, error)) {
246 counter.incrementAndGet();
247 }
248 }
249 });
250 List<ForwardingObjective> expectFwdObjsTimeout = Lists.newCopyOnWriteArrayList(
251 Lists.newArrayList(fwdTimeout, FWD1, FWD2));
252
253 // Reduce timeout so the unit test doesn't have to wait many seconds
254 InOrderFlowObjectiveManager.objTimeoutMs = TIMEOUT_THRESH;
255 setUp();
256
Ray Milkey95c9e0f2018-05-30 14:16:37 -0700257 expect(mgr.flowObjectiveStore.getNextGroup(NID1)).andReturn(NGRP1).times(2);
Charles Chan45c19d72018-04-19 21:38:40 -0700258 expect(mgr.flowObjectiveStore.getNextGroup(NID2)).andReturn(NGRP2).times(2);
259 replay(mgr.flowObjectiveStore);
260
261 // Force this objective to time out
Charles Chan1491b9b2018-11-27 21:33:33 +0800262 offset = InOrderFlowObjectiveManager.objTimeoutMs * 2;
Charles Chan45c19d72018-04-19 21:38:40 -0700263
264 expectFwdObjsTimeout.forEach(fwdObj -> mgr.forward(DEV1, fwdObj));
265
266 // Wait for the pipeline operation to complete
267 int expectedTime = (bound + offset) * 3;
268 assertAfter(expectedTime, expectedTime * 5, () -> assertEquals(expectFwdObjsTimeout.size(), actualObjs.size()));
269
Charles Chan1491b9b2018-11-27 21:33:33 +0800270 assertTrue(counter.get() != 0);
271 assertTrue(actualObjs.indexOf(fwdTimeout) < actualObjs.indexOf(FWD1));
Charles Chan45c19d72018-04-19 21:38:40 -0700272
273 verify(mgr.flowObjectiveStore);
274 }
275
276 @Test
277 public void forwardPending() {
Charles Chana7903c82018-03-15 20:14:16 -0700278 // Note: current logic will double check if the next obj need to be queued
279 // it does not check when resubmitting pending next back to the queue
280 expect(mgr.flowObjectiveStore.getNextGroup(NID1)).andReturn(null).times(2);
281 expect(mgr.flowObjectiveStore.getNextGroup(NID2)).andReturn(null).times(2);
282 expect(mgr.flowObjectiveStore.getNextGroup(NID1)).andReturn(NGRP1).times(3);
283 expect(mgr.flowObjectiveStore.getNextGroup(NID2)).andReturn(NGRP2).times(3);
284 replay(mgr.flowObjectiveStore);
285
286 expectFwdObjs.forEach(fwdObj -> mgr.forward(DEV1, fwdObj));
287
288 // Trigger the next objectives
289 mgr.next(DEV1, NEXT1);
290 mgr.next(DEV1, NEXT2);
291
292 // Wait for the pipeline operation to complete
Charles Chan45c19d72018-04-19 21:38:40 -0700293 int expectedTime = (bound + offset) * 8;
Charles Chana7903c82018-03-15 20:14:16 -0700294 assertAfter(expectedTime, expectedTime * 5, () -> assertEquals(expectFwdObjs.size() + 2, actualObjs.size()));
295
296 assertTrue(actualObjs.indexOf(NEXT1) < actualObjs.indexOf(FWD1));
297 assertTrue(actualObjs.indexOf(FWD1) < actualObjs.indexOf(FWD3));
298 assertTrue(actualObjs.indexOf(FWD3) < actualObjs.indexOf(FWD5));
299 assertTrue(actualObjs.indexOf(NEXT2) < actualObjs.indexOf(FWD2));
300 assertTrue(actualObjs.indexOf(FWD2) < actualObjs.indexOf(FWD4));
301 assertTrue(actualObjs.indexOf(FWD4) < actualObjs.indexOf(FWD6));
302
303 verify(mgr.flowObjectiveStore);
304 }
305
306 @Test
Charles Chan45c19d72018-04-19 21:38:40 -0700307 public void next() {
Charles Chana7903c82018-03-15 20:14:16 -0700308 // Note: ADD operation won't query this
309 expect(mgr.flowObjectiveStore.getNextGroup(NID1)).andReturn(NGRP1).times(3);
310 expect(mgr.flowObjectiveStore.getNextGroup(NID2)).andReturn(NGRP2).times(3);
311 replay(mgr.flowObjectiveStore);
312
313 expectNextObjs.forEach(nextObj -> mgr.next(DEV1, nextObj));
314
315 // Wait for the pipeline operation to complete
Charles Chan45c19d72018-04-19 21:38:40 -0700316 int expectedTime = (bound + offset) * 8;
Charles Chana7903c82018-03-15 20:14:16 -0700317 assertAfter(expectedTime, expectedTime * 5, () -> assertEquals(expectNextObjs.size(), actualObjs.size()));
318
319 assertTrue(actualObjs.indexOf(NEXT1) < actualObjs.indexOf(NEXT3));
320 assertTrue(actualObjs.indexOf(NEXT3) < actualObjs.indexOf(NEXT5));
321 assertTrue(actualObjs.indexOf(NEXT5) < actualObjs.indexOf(NEXT7));
322 assertTrue(actualObjs.indexOf(NEXT2) < actualObjs.indexOf(NEXT4));
323 assertTrue(actualObjs.indexOf(NEXT4) < actualObjs.indexOf(NEXT6));
324 assertTrue(actualObjs.indexOf(NEXT6) < actualObjs.indexOf(NEXT8));
325
326 verify(mgr.flowObjectiveStore);
327 }
328
329 // FIXME We currently do not handle the case when an app sends edit/remove of a next id before add.
330 // The edit/remove operation will be queued by pendingNext, and the add operation will be
331 // queued by the ordering queue forever due to the deadlock. This can be improved by making
332 // pendingForwards, pendingNexts and ordering queue caches.
333 @Test
334 @Ignore("Not supported")
Charles Chan45c19d72018-04-19 21:38:40 -0700335 public void nextPending() {
Charles Chana7903c82018-03-15 20:14:16 -0700336 // Note: current logic will double check if the next obj need to be queued
337 // it does not check when resubmitting pending next back to the queue
338 expect(mgr.flowObjectiveStore.getNextGroup(NID1)).andReturn(null).times(6);
339 expect(mgr.flowObjectiveStore.getNextGroup(NID2)).andReturn(null).times(6);
340 replay(mgr.flowObjectiveStore);
341
342 expectNextObjsPending.forEach(nextObj -> mgr.next(DEV1, nextObj));
343
344 // Wait for the pipeline operation to complete
Charles Chan45c19d72018-04-19 21:38:40 -0700345 int expectedTime = (bound + offset) * 8;
Charles Chana7903c82018-03-15 20:14:16 -0700346 assertAfter(expectedTime, expectedTime * 5, () -> assertEquals(expectNextObjs.size(), actualObjs.size()));
347
348 assertTrue(actualObjs.indexOf(NEXT1) < actualObjs.indexOf(NEXT5));
349 assertTrue(actualObjs.indexOf(NEXT5) < actualObjs.indexOf(NEXT3));
350 assertTrue(actualObjs.indexOf(NEXT3) < actualObjs.indexOf(NEXT7));
351 assertTrue(actualObjs.indexOf(NEXT2) < actualObjs.indexOf(NEXT6));
352 assertTrue(actualObjs.indexOf(NEXT6) < actualObjs.indexOf(NEXT4));
353 assertTrue(actualObjs.indexOf(NEXT4) < actualObjs.indexOf(NEXT8));
354
355 verify(mgr.flowObjectiveStore);
356 }
357
358 /**
359 * Creates filtering objective builder with a serial number encoded in MPLS label.
360 * The serial number is used to identify same objective that occurs multiple times.
361 *
362 * @param portnum Port number
363 * @param vlanId VLAN Id
364 * @param mac MAC address
365 * @param serial Serial number
366 * @return Filtering objective builder
367 */
368 private static FilteringObjective.Builder buildFilteringObjective(PortNumber portnum, VlanId vlanId,
369 MacAddress mac, int serial) {
370 FilteringObjective.Builder fob = DefaultFilteringObjective.builder();
371 fob.withKey(Criteria.matchInPort(portnum))
372 .addCondition(Criteria.matchEthDst(mac))
373 .addCondition(Criteria.matchVlanId(VlanId.NONE))
374 .addCondition(Criteria.matchMplsLabel(MplsLabel.mplsLabel(serial)))
375 .withPriority(PRIORITY);
376
377 TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
378 tBuilder.pushVlan().setVlanId(vlanId);
379 fob.withMeta(tBuilder.build());
380
381 fob.permit().fromApp(APP_ID);
382 return fob;
383 }
384
385 /**
386 * Creates next objective builder.
387 *
388 * @param nextId next ID
389 * @param vlanId VLAN ID
390 * @param ports Set of ports that is in the given VLAN ID
391 *
392 * @return Next objective builder
393 */
394 private static NextObjective.Builder buildNextObjective(int nextId, VlanId vlanId, Collection<PortNumber> ports) {
395 TrafficSelector metadata =
396 DefaultTrafficSelector.builder().matchVlanId(vlanId).build();
397
398 NextObjective.Builder nextObjBuilder = DefaultNextObjective
399 .builder().withId(nextId)
400 .withType(NextObjective.Type.BROADCAST).fromApp(APP_ID)
401 .withMeta(metadata);
402
403 ports.forEach(port -> {
404 TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
405 tBuilder.popVlan();
406 tBuilder.setOutput(port);
407 nextObjBuilder.addTreatment(tBuilder.build());
408 });
409
410 return nextObjBuilder;
411 }
412
413 /**
414 * Creates forwarding objective builder.
415 *
416 * @param selector Traffic selector
417 * @param nextId next ID
418 * @return Forwarding objective builder
419 */
420 private static ForwardingObjective.Builder buildFwdObjective(TrafficSelector selector, int nextId) {
421 return DefaultForwardingObjective.builder()
422 .makePermanent()
423 .withSelector(selector)
424 .nextStep(nextId)
425 .fromApp(APP_ID)
426 .withPriority(PRIORITY)
427 .withFlag(ForwardingObjective.Flag.SPECIFIC);
428 }
429}