blob: d9e6b2cbbe9be8078d74499c4541f31019058ab2 [file] [log] [blame]
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -08001/*
2 * Copyright 2015 Open Networking Laboratory
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 */
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070016package org.onosproject.segmentrouting.grouphandler;
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080017
18import static com.google.common.base.Preconditions.checkNotNull;
19import static org.slf4j.LoggerFactory.getLogger;
20
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -070021import java.net.URI;
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080022import java.util.ArrayList;
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070023import java.util.Collections;
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080024import java.util.HashMap;
25import java.util.HashSet;
26import java.util.List;
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070027import java.util.Random;
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080028import java.util.Set;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -070029import java.util.stream.Collectors;
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080030
31import org.onlab.packet.MacAddress;
sangho32a59322015-02-17 12:07:41 -080032import org.onlab.packet.MplsLabel;
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -070033import org.onlab.util.KryoNamespace;
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080034import org.onosproject.core.ApplicationId;
35import org.onosproject.net.DeviceId;
36import org.onosproject.net.Link;
37import org.onosproject.net.PortNumber;
38import org.onosproject.net.flow.DefaultTrafficTreatment;
39import org.onosproject.net.flow.TrafficTreatment;
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070040import org.onosproject.net.flowobjective.DefaultNextObjective;
41import org.onosproject.net.flowobjective.FlowObjectiveService;
42import org.onosproject.net.flowobjective.NextObjective;
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -070043import org.onosproject.net.group.DefaultGroupKey;
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080044import org.onosproject.net.group.GroupKey;
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080045import org.onosproject.net.link.LinkService;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -070046import org.onosproject.store.service.EventuallyConsistentMap;
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080047import org.slf4j.Logger;
48
49/**
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070050 * Default ECMP group handler creation module. This component creates a set of
51 * ECMP groups for every neighbor that this device is connected to based on
52 * whether the current device is an edge device or a transit device.
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080053 */
54public class DefaultGroupHandler {
55 protected final Logger log = getLogger(getClass());
56
57 protected final DeviceId deviceId;
58 protected final ApplicationId appId;
59 protected final DeviceProperties deviceConfig;
60 protected final List<Integer> allSegmentIds;
61 protected final int nodeSegmentId;
62 protected final boolean isEdgeRouter;
63 protected final MacAddress nodeMacAddr;
64 protected LinkService linkService;
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070065 protected FlowObjectiveService flowObjectiveService;
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080066
67 protected HashMap<DeviceId, Set<PortNumber>> devicePortMap =
68 new HashMap<DeviceId, Set<PortNumber>>();
69 protected HashMap<PortNumber, DeviceId> portDeviceMap =
70 new HashMap<PortNumber, DeviceId>();
Srikanth Vavilapalli23181912015-05-04 09:48:09 -070071 //protected HashMap<NeighborSet, Integer> deviceNextObjectiveIds =
72 // new HashMap<NeighborSet, Integer>();
73 protected EventuallyConsistentMap<
74 NeighborSetNextObjectiveStoreKey, Integer> nsNextObjStore = null;
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070075 protected Random rand = new Random();
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080076
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -070077 protected KryoNamespace.Builder kryo = new KryoNamespace.Builder()
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070078 .register(URI.class).register(HashSet.class)
79 .register(DeviceId.class).register(PortNumber.class)
80 .register(NeighborSet.class).register(PolicyGroupIdentifier.class)
81 .register(PolicyGroupParams.class)
82 .register(GroupBucketIdentifier.class)
83 .register(GroupBucketIdentifier.BucketOutputType.class);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080084
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070085 protected DefaultGroupHandler(DeviceId deviceId, ApplicationId appId,
86 DeviceProperties config,
87 LinkService linkService,
Srikanth Vavilapalli23181912015-05-04 09:48:09 -070088 FlowObjectiveService flowObjService,
89 EventuallyConsistentMap<
90 NeighborSetNextObjectiveStoreKey,
91 Integer> nsNextObjStore) {
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080092 this.deviceId = checkNotNull(deviceId);
93 this.appId = checkNotNull(appId);
94 this.deviceConfig = checkNotNull(config);
95 this.linkService = checkNotNull(linkService);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080096 allSegmentIds = checkNotNull(config.getAllDeviceSegmentIds());
97 nodeSegmentId = config.getSegmentId(deviceId);
98 isEdgeRouter = config.isEdgeDevice(deviceId);
99 nodeMacAddr = checkNotNull(config.getDeviceMac(deviceId));
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700100 this.flowObjectiveService = flowObjService;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700101 this.nsNextObjStore = nsNextObjStore;
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800102
103 populateNeighborMaps();
104 }
105
106 /**
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700107 * Creates a group handler object based on the type of device. If device is
108 * of edge type it returns edge group handler, else it returns transit group
109 * handler.
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800110 *
111 * @param deviceId device identifier
112 * @param appId application identifier
113 * @param config interface to retrieve the device properties
114 * @param linkService link service object
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700115 * @param flowObjService flow objective service object
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800116 * @return default group handler type
117 */
118 public static DefaultGroupHandler createGroupHandler(DeviceId deviceId,
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700119 ApplicationId appId,
120 DeviceProperties config,
121 LinkService linkService,
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700122 FlowObjectiveService flowObjService,
123 EventuallyConsistentMap<
124 NeighborSetNextObjectiveStoreKey,
125 Integer> nsNextObjStore) {
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800126 if (config.isEdgeDevice(deviceId)) {
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700127 return new DefaultEdgeGroupHandler(deviceId, appId, config,
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700128 linkService,
129 flowObjService,
130 nsNextObjStore);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800131 } else {
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700132 return new DefaultTransitGroupHandler(deviceId, appId, config,
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700133 linkService,
134 flowObjService,
135 nsNextObjStore);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800136 }
137 }
138
139 /**
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700140 * Creates the auto created groups for this device based on the current
141 * snapshot of the topology.
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800142 */
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700143 // Empty implementations to be overridden by derived classes
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800144 public void createGroups() {
145 }
146
147 /**
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700148 * Performs group creation or update procedures when a new link is
149 * discovered on this device.
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800150 *
151 * @param newLink new neighbor link
152 */
153 public void linkUp(Link newLink) {
sanghob35a6192015-04-01 13:05:26 -0700154
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800155 if (newLink.type() != Link.Type.DIRECT) {
156 log.warn("linkUp: unknown link type");
157 return;
158 }
159
160 if (!newLink.src().deviceId().equals(deviceId)) {
161 log.warn("linkUp: deviceId{} doesn't match with link src{}",
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700162 deviceId, newLink.src().deviceId());
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800163 return;
164 }
165
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700166 log.debug("Device {} linkUp at local port {} to neighbor {}", deviceId,
167 newLink.src().port(), newLink.dst().deviceId());
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700168 addNeighborAtPort(newLink.dst().deviceId(),
169 newLink.src().port());
170 /*if (devicePortMap.get(newLink.dst().deviceId()) == null) {
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800171 // New Neighbor
172 newNeighbor(newLink);
173 } else {
174 // Old Neighbor
175 newPortToExistingNeighbor(newLink);
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700176 }*/
177 Set<NeighborSet> nsSet = nsNextObjStore.keySet()
178 .stream()
179 .filter((nsStoreEntry) -> (nsStoreEntry.deviceId().equals(deviceId)))
180 .map((nsStoreEntry) -> (nsStoreEntry.neighborSet()))
181 .filter((ns) -> (ns.getDeviceIds()
182 .contains(newLink.dst().deviceId())))
183 .collect(Collectors.toSet());
184 log.trace("linkUp: nsNextObjStore contents for device {}:",
185 deviceId,
186 nsSet);
187 for (NeighborSet ns : nsSet) {
188 // Create the new bucket to be updated
189 TrafficTreatment.Builder tBuilder =
190 DefaultTrafficTreatment.builder();
191 tBuilder.setOutput(newLink.src().port())
192 .setEthDst(deviceConfig.getDeviceMac(
193 newLink.dst().deviceId()))
194 .setEthSrc(nodeMacAddr);
195 if (ns.getEdgeLabel() != NeighborSet.NO_EDGE_LABEL) {
196 tBuilder.pushMpls()
197 .setMpls(MplsLabel.
198 mplsLabel(ns.getEdgeLabel()));
199 }
200
201 Integer nextId = nsNextObjStore.
202 get(new NeighborSetNextObjectiveStoreKey(deviceId, ns));
203 if (nextId != null) {
204 NextObjective.Builder nextObjBuilder = DefaultNextObjective
205 .builder().withId(nextId)
206 .withType(NextObjective.Type.HASHED).fromApp(appId);
207
208 nextObjBuilder.addTreatment(tBuilder.build());
209
210 log.debug("linkUp in device {}: Adding Bucket "
211 + "with Port {} to next object id {}",
212 deviceId,
213 newLink.src().port(),
214 nextId);
215 NextObjective nextObjective = nextObjBuilder.add();
216 flowObjectiveService.next(deviceId, nextObjective);
217 }
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800218 }
219 }
220
221 /**
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700222 * Performs group recovery procedures when a port goes down on this device.
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800223 *
224 * @param port port number that has gone down
225 */
226 public void portDown(PortNumber port) {
227 if (portDeviceMap.get(port) == null) {
228 log.warn("portDown: unknown port");
229 return;
230 }
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700231 log.debug("Device {} portDown {} to neighbor {}", deviceId, port,
232 portDeviceMap.get(port));
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700233 /*Set<NeighborSet> nsSet = computeImpactedNeighborsetForPortEvent(portDeviceMap
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700234 .get(port),
235 devicePortMap
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700236 .keySet());*/
237 Set<NeighborSet> nsSet = nsNextObjStore.keySet()
238 .stream()
239 .filter((nsStoreEntry) -> (nsStoreEntry.deviceId().equals(deviceId)))
240 .map((nsStoreEntry) -> (nsStoreEntry.neighborSet()))
241 .filter((ns) -> (ns.getDeviceIds()
242 .contains(portDeviceMap.get(port))))
243 .collect(Collectors.toSet());
244 log.trace("portDown: nsNextObjStore contents for device {}:",
245 deviceId,
246 nsSet);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800247 for (NeighborSet ns : nsSet) {
248 // Create the bucket to be removed
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700249 TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment
250 .builder();
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800251 tBuilder.setOutput(port)
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700252 .setEthDst(deviceConfig.getDeviceMac(portDeviceMap
253 .get(port))).setEthSrc(nodeMacAddr);
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -0700254 if (ns.getEdgeLabel() != NeighborSet.NO_EDGE_LABEL) {
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700255 tBuilder.pushMpls().setMpls(MplsLabel.mplsLabel(ns
256 .getEdgeLabel()));
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -0700257 }
sangho834e4b02015-05-01 09:38:25 -0700258
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700259 Integer nextId = nsNextObjStore.
260 get(new NeighborSetNextObjectiveStoreKey(deviceId, ns));
sangho834e4b02015-05-01 09:38:25 -0700261 if (nextId != null) {
262 NextObjective.Builder nextObjBuilder = DefaultNextObjective
263 .builder().withType(NextObjective.Type.SIMPLE).withId(nextId).fromApp(appId);
264
265 nextObjBuilder.addTreatment(tBuilder.build());
266
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700267 log.debug("portDown in device {}: Removing Bucket "
268 + "with Port {} to next object id {}",
269 deviceId,
270 port,
271 nextId);
sangho834e4b02015-05-01 09:38:25 -0700272 NextObjective nextObjective = nextObjBuilder.remove();
273
274 flowObjectiveService.next(deviceId, nextObjective);
275 }
276
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800277 }
278
279 devicePortMap.get(portDeviceMap.get(port)).remove(port);
280 portDeviceMap.remove(port);
281 }
282
283 /**
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700284 * Returns the next objective associated with the neighborset.
285 * If there is no next objective for this neighborset, this API
286 * would create a next objective and return.
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800287 *
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700288 * @param ns neighborset
289 * @return int if found or -1
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800290 */
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700291 public int getNextObjectiveId(NeighborSet ns) {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700292 Integer nextId = nsNextObjStore.
293 get(new NeighborSetNextObjectiveStoreKey(deviceId, ns));
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700294 if (nextId == null) {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700295 log.trace("getNextObjectiveId in device{}: Next objective id "
296 + "not found for {} and creating", deviceId, ns);
297 log.trace("getNextObjectiveId: nsNextObjStore contents for device {}: {}",
298 deviceId,
299 nsNextObjStore.entrySet()
300 .stream()
301 .filter((nsStoreEntry) ->
302 (nsStoreEntry.getKey().deviceId().equals(deviceId)))
303 .collect(Collectors.toList()));
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700304 createGroupsFromNeighborsets(Collections.singleton(ns));
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700305 nextId = nsNextObjStore.
306 get(new NeighborSetNextObjectiveStoreKey(deviceId, ns));
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700307 if (nextId == null) {
308 log.warn("getNextObjectiveId: unable to create next objective");
309 return -1;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700310 } else {
311 log.debug("getNextObjectiveId in device{}: Next objective id {} "
312 + "created for {}", deviceId, nextId.intValue(), ns);
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700313 }
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700314 } else {
315 log.trace("getNextObjectiveId in device{}: Next objective id {} "
316 + "found for {}", deviceId, nextId.intValue(), ns);
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700317 }
318 return nextId.intValue();
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800319 }
320
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700321 // Empty implementation
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800322 protected void newNeighbor(Link newLink) {
323 }
324
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700325 // Empty implementation
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800326 protected void newPortToExistingNeighbor(Link newLink) {
327 }
328
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700329 // Empty implementation
330 protected Set<NeighborSet>
331 computeImpactedNeighborsetForPortEvent(DeviceId impactedNeighbor,
332 Set<DeviceId> updatedNeighbors) {
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800333 return null;
334 }
335
336 private void populateNeighborMaps() {
337 Set<Link> outgoingLinks = linkService.getDeviceEgressLinks(deviceId);
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700338 for (Link link : outgoingLinks) {
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800339 if (link.type() != Link.Type.DIRECT) {
340 continue;
341 }
342 addNeighborAtPort(link.dst().deviceId(), link.src().port());
343 }
344 }
345
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700346 protected void addNeighborAtPort(DeviceId neighborId,
347 PortNumber portToNeighbor) {
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800348 // Update DeviceToPort database
349 log.debug("Device {} addNeighborAtPort: neighbor {} at port {}",
350 deviceId, neighborId, portToNeighbor);
351 if (devicePortMap.get(neighborId) != null) {
352 devicePortMap.get(neighborId).add(portToNeighbor);
353 } else {
354 Set<PortNumber> ports = new HashSet<PortNumber>();
355 ports.add(portToNeighbor);
356 devicePortMap.put(neighborId, ports);
357 }
358
359 // Update portToDevice database
360 if (portDeviceMap.get(portToNeighbor) == null) {
361 portDeviceMap.put(portToNeighbor, neighborId);
362 }
363 }
364
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700365 protected Set<Set<DeviceId>> getPowerSetOfNeighbors(Set<DeviceId> neighbors) {
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800366 List<DeviceId> list = new ArrayList<DeviceId>(neighbors);
367 Set<Set<DeviceId>> sets = new HashSet<Set<DeviceId>>();
368 // get the number of elements in the neighbors
369 int elements = list.size();
370 // the number of members of a power set is 2^n
371 // including the empty set
372 int powerElements = (1 << elements);
373
374 // run a binary counter for the number of power elements
375 // NOTE: Exclude empty set
376 for (long i = 1; i < powerElements; i++) {
377 Set<DeviceId> neighborSubSet = new HashSet<DeviceId>();
378 for (int j = 0; j < elements; j++) {
379 if ((i >> j) % 2 == 1) {
380 neighborSubSet.add(list.get(j));
381 }
382 }
383 sets.add(neighborSubSet);
384 }
385 return sets;
386 }
387
388 private boolean isSegmentIdSameAsNodeSegmentId(DeviceId deviceId, int sId) {
389 return (deviceConfig.getSegmentId(deviceId) == sId);
390 }
391
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700392 protected List<Integer> getSegmentIdsTobePairedWithNeighborSet(Set<DeviceId> neighbors) {
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800393
394 List<Integer> nsSegmentIds = new ArrayList<Integer>();
395
sanghob35a6192015-04-01 13:05:26 -0700396 // Always pair up with no edge label
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700397 // If (neighbors.size() == 1) {
sanghob35a6192015-04-01 13:05:26 -0700398 nsSegmentIds.add(-1);
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700399 // }
sanghob35a6192015-04-01 13:05:26 -0700400
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800401 // Filter out SegmentIds matching with the
402 // nodes in the combo
403 for (Integer sId : allSegmentIds) {
404 if (sId.equals(nodeSegmentId)) {
405 continue;
406 }
407 boolean filterOut = false;
408 // Check if the edge label being set is of
409 // any node in the Neighbor set
410 for (DeviceId deviceId : neighbors) {
411 if (isSegmentIdSameAsNodeSegmentId(deviceId, sId)) {
412 filterOut = true;
413 break;
414 }
415 }
416 if (!filterOut) {
417 nsSegmentIds.add(sId);
418 }
419 }
420 return nsSegmentIds;
421 }
422
423 protected void createGroupsFromNeighborsets(Set<NeighborSet> nsSet) {
424 for (NeighborSet ns : nsSet) {
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700425 int nextId = flowObjectiveService.allocateNextId();
426 NextObjective.Builder nextObjBuilder = DefaultNextObjective
427 .builder().withId(nextId)
428 .withType(NextObjective.Type.HASHED).fromApp(appId);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800429 for (DeviceId d : ns.getDeviceIds()) {
sangho834e4b02015-05-01 09:38:25 -0700430 if (devicePortMap.get(d) == null) {
431 log.warn("Device {} is not in the port map yet", d);
432 return;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700433 } else if (devicePortMap.get(d).size() == 0) {
434 log.warn("There are no ports for "
435 + "the Device {} in the port map yet", d);
436 return;
sangho834e4b02015-05-01 09:38:25 -0700437 }
438
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800439 for (PortNumber sp : devicePortMap.get(d)) {
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700440 TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment
441 .builder();
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800442 tBuilder.setOutput(sp)
443 .setEthDst(deviceConfig.getDeviceMac(d))
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -0700444 .setEthSrc(nodeMacAddr);
445 if (ns.getEdgeLabel() != NeighborSet.NO_EDGE_LABEL) {
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700446 tBuilder.pushMpls().setMpls(MplsLabel.mplsLabel(ns
sangho834e4b02015-05-01 09:38:25 -0700447 .getEdgeLabel()));
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -0700448 }
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700449 nextObjBuilder.addTreatment(tBuilder.build());
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800450 }
451 }
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800452
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700453 NextObjective nextObj = nextObjBuilder.add();
454 flowObjectiveService.next(deviceId, nextObj);
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700455 log.debug("createGroupsFromNeighborsets: Submited "
456 + "next objective {} in device {}",
457 nextId, deviceId);
458 nsNextObjStore.put(new NeighborSetNextObjectiveStoreKey(deviceId, ns),
459 nextId);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800460 }
461 }
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -0700462
sanghob35a6192015-04-01 13:05:26 -0700463 public GroupKey getGroupKey(Object obj) {
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -0700464 return new DefaultGroupKey(kryo.build().serialize(obj));
465 }
sanghob35a6192015-04-01 13:05:26 -0700466
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800467}