Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 1 | /* |
| 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 Vavilapalli | 4db76e3 | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 16 | package org.onosproject.segmentrouting.grouphandler; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 17 | |
| 18 | import static com.google.common.base.Preconditions.checkNotNull; |
| 19 | import static org.slf4j.LoggerFactory.getLogger; |
| 20 | |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 21 | import java.net.URI; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 22 | import java.util.ArrayList; |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 23 | import java.util.Collections; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 24 | import java.util.HashMap; |
| 25 | import java.util.HashSet; |
| 26 | import java.util.List; |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 27 | import java.util.Random; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 28 | import java.util.Set; |
| 29 | |
| 30 | import org.onlab.packet.MacAddress; |
sangho | 32a5932 | 2015-02-17 12:07:41 -0800 | [diff] [blame] | 31 | import org.onlab.packet.MplsLabel; |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 32 | import org.onlab.util.KryoNamespace; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 33 | import org.onosproject.core.ApplicationId; |
| 34 | import org.onosproject.net.DeviceId; |
| 35 | import org.onosproject.net.Link; |
| 36 | import org.onosproject.net.PortNumber; |
| 37 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 38 | import org.onosproject.net.flow.TrafficTreatment; |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 39 | import org.onosproject.net.flowobjective.DefaultNextObjective; |
| 40 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
| 41 | import org.onosproject.net.flowobjective.NextObjective; |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 42 | import org.onosproject.net.group.DefaultGroupKey; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 43 | import org.onosproject.net.group.GroupKey; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 44 | import org.onosproject.net.link.LinkService; |
| 45 | import org.slf4j.Logger; |
| 46 | |
| 47 | /** |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 48 | * Default ECMP group handler creation module. This component creates a set of |
| 49 | * ECMP groups for every neighbor that this device is connected to based on |
| 50 | * whether the current device is an edge device or a transit device. |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 51 | */ |
| 52 | public class DefaultGroupHandler { |
| 53 | protected final Logger log = getLogger(getClass()); |
| 54 | |
| 55 | protected final DeviceId deviceId; |
| 56 | protected final ApplicationId appId; |
| 57 | protected final DeviceProperties deviceConfig; |
| 58 | protected final List<Integer> allSegmentIds; |
| 59 | protected final int nodeSegmentId; |
| 60 | protected final boolean isEdgeRouter; |
| 61 | protected final MacAddress nodeMacAddr; |
| 62 | protected LinkService linkService; |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 63 | protected FlowObjectiveService flowObjectiveService; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 64 | |
| 65 | protected HashMap<DeviceId, Set<PortNumber>> devicePortMap = |
| 66 | new HashMap<DeviceId, Set<PortNumber>>(); |
| 67 | protected HashMap<PortNumber, DeviceId> portDeviceMap = |
| 68 | new HashMap<PortNumber, DeviceId>(); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 69 | protected HashMap<GroupKey, Integer> deviceNextObjectiveIds = |
| 70 | new HashMap<GroupKey, Integer>(); |
| 71 | protected Random rand = new Random(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 72 | |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 73 | protected KryoNamespace.Builder kryo = new KryoNamespace.Builder() |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 74 | .register(URI.class).register(HashSet.class) |
| 75 | .register(DeviceId.class).register(PortNumber.class) |
| 76 | .register(NeighborSet.class).register(PolicyGroupIdentifier.class) |
| 77 | .register(PolicyGroupParams.class) |
| 78 | .register(GroupBucketIdentifier.class) |
| 79 | .register(GroupBucketIdentifier.BucketOutputType.class); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 80 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 81 | protected DefaultGroupHandler(DeviceId deviceId, ApplicationId appId, |
| 82 | DeviceProperties config, |
| 83 | LinkService linkService, |
| 84 | FlowObjectiveService flowObjService) { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 85 | this.deviceId = checkNotNull(deviceId); |
| 86 | this.appId = checkNotNull(appId); |
| 87 | this.deviceConfig = checkNotNull(config); |
| 88 | this.linkService = checkNotNull(linkService); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 89 | allSegmentIds = checkNotNull(config.getAllDeviceSegmentIds()); |
| 90 | nodeSegmentId = config.getSegmentId(deviceId); |
| 91 | isEdgeRouter = config.isEdgeDevice(deviceId); |
| 92 | nodeMacAddr = checkNotNull(config.getDeviceMac(deviceId)); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 93 | this.flowObjectiveService = flowObjService; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 94 | |
| 95 | populateNeighborMaps(); |
| 96 | } |
| 97 | |
| 98 | /** |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 99 | * Creates a group handler object based on the type of device. If device is |
| 100 | * of edge type it returns edge group handler, else it returns transit group |
| 101 | * handler. |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 102 | * |
| 103 | * @param deviceId device identifier |
| 104 | * @param appId application identifier |
| 105 | * @param config interface to retrieve the device properties |
| 106 | * @param linkService link service object |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 107 | * @param flowObjService flow objective service object |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 108 | * @return default group handler type |
| 109 | */ |
| 110 | public static DefaultGroupHandler createGroupHandler(DeviceId deviceId, |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 111 | ApplicationId appId, |
| 112 | DeviceProperties config, |
| 113 | LinkService linkService, |
| 114 | FlowObjectiveService flowObjService) { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 115 | if (config.isEdgeDevice(deviceId)) { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 116 | return new DefaultEdgeGroupHandler(deviceId, appId, config, |
| 117 | linkService, flowObjService); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 118 | } else { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 119 | return new DefaultTransitGroupHandler(deviceId, appId, config, |
| 120 | linkService, flowObjService); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 121 | } |
| 122 | } |
| 123 | |
| 124 | /** |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 125 | * Creates the auto created groups for this device based on the current |
| 126 | * snapshot of the topology. |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 127 | */ |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 128 | // Empty implementations to be overridden by derived classes |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 129 | public void createGroups() { |
| 130 | } |
| 131 | |
| 132 | /** |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 133 | * Performs group creation or update procedures when a new link is |
| 134 | * discovered on this device. |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 135 | * |
| 136 | * @param newLink new neighbor link |
| 137 | */ |
| 138 | public void linkUp(Link newLink) { |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 139 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 140 | if (newLink.type() != Link.Type.DIRECT) { |
| 141 | log.warn("linkUp: unknown link type"); |
| 142 | return; |
| 143 | } |
| 144 | |
| 145 | if (!newLink.src().deviceId().equals(deviceId)) { |
| 146 | log.warn("linkUp: deviceId{} doesn't match with link src{}", |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 147 | deviceId, newLink.src().deviceId()); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 148 | return; |
| 149 | } |
| 150 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 151 | log.debug("Device {} linkUp at local port {} to neighbor {}", deviceId, |
| 152 | newLink.src().port(), newLink.dst().deviceId()); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 153 | if (devicePortMap.get(newLink.dst().deviceId()) == null) { |
| 154 | // New Neighbor |
| 155 | newNeighbor(newLink); |
| 156 | } else { |
| 157 | // Old Neighbor |
| 158 | newPortToExistingNeighbor(newLink); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | /** |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 163 | * Performs group recovery procedures when a port goes down on this device. |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 164 | * |
| 165 | * @param port port number that has gone down |
| 166 | */ |
| 167 | public void portDown(PortNumber port) { |
| 168 | if (portDeviceMap.get(port) == null) { |
| 169 | log.warn("portDown: unknown port"); |
| 170 | return; |
| 171 | } |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 172 | log.debug("Device {} portDown {} to neighbor {}", deviceId, port, |
| 173 | portDeviceMap.get(port)); |
| 174 | Set<NeighborSet> nsSet = computeImpactedNeighborsetForPortEvent(portDeviceMap |
| 175 | .get(port), |
| 176 | devicePortMap |
| 177 | .keySet()); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 178 | for (NeighborSet ns : nsSet) { |
| 179 | // Create the bucket to be removed |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 180 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment |
| 181 | .builder(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 182 | tBuilder.setOutput(port) |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 183 | .setEthDst(deviceConfig.getDeviceMac(portDeviceMap |
| 184 | .get(port))).setEthSrc(nodeMacAddr); |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 185 | if (ns.getEdgeLabel() != NeighborSet.NO_EDGE_LABEL) { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 186 | tBuilder.pushMpls().setMpls(MplsLabel.mplsLabel(ns |
| 187 | .getEdgeLabel())); |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 188 | } |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 189 | /* |
| 190 | * GroupBucket removeBucket = DefaultGroupBucket. |
| 191 | * createSelectGroupBucket(tBuilder.build()); GroupBuckets |
| 192 | * removeBuckets = new GroupBuckets( Arrays.asList(removeBucket)); |
| 193 | * log.debug("portDown in device{}: " + |
| 194 | * "groupService.removeBucketsFromGroup " + "for neighborset{}", |
| 195 | * deviceId, ns); groupService.removeBucketsFromGroup(deviceId, |
| 196 | * getGroupKey(ns), removeBuckets, getGroupKey(ns), appId); |
| 197 | */ |
| 198 | //TODO: Use next objective API to update the previously created |
| 199 | //next objectives. |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | devicePortMap.get(portDeviceMap.get(port)).remove(port); |
| 203 | portDeviceMap.remove(port); |
| 204 | } |
| 205 | |
| 206 | /** |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 207 | * Returns the next objective associated with the neighborset. |
| 208 | * If there is no next objective for this neighborset, this API |
| 209 | * would create a next objective and return. |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 210 | * |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 211 | * @param ns neighborset |
| 212 | * @return int if found or -1 |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 213 | */ |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 214 | public int getNextObjectiveId(NeighborSet ns) { |
| 215 | Integer nextId = deviceNextObjectiveIds.get(getGroupKey(ns)); |
| 216 | if (nextId == null) { |
| 217 | createGroupsFromNeighborsets(Collections.singleton(ns)); |
| 218 | nextId = deviceNextObjectiveIds.get(getGroupKey(ns)); |
| 219 | if (nextId == null) { |
| 220 | log.warn("getNextObjectiveId: unable to create next objective"); |
| 221 | return -1; |
| 222 | } |
| 223 | } |
| 224 | return nextId.intValue(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 225 | } |
| 226 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 227 | // Empty implementation |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 228 | protected void newNeighbor(Link newLink) { |
| 229 | } |
| 230 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 231 | // Empty implementation |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 232 | protected void newPortToExistingNeighbor(Link newLink) { |
| 233 | } |
| 234 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 235 | // Empty implementation |
| 236 | protected Set<NeighborSet> |
| 237 | computeImpactedNeighborsetForPortEvent(DeviceId impactedNeighbor, |
| 238 | Set<DeviceId> updatedNeighbors) { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 239 | return null; |
| 240 | } |
| 241 | |
| 242 | private void populateNeighborMaps() { |
| 243 | Set<Link> outgoingLinks = linkService.getDeviceEgressLinks(deviceId); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 244 | for (Link link : outgoingLinks) { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 245 | if (link.type() != Link.Type.DIRECT) { |
| 246 | continue; |
| 247 | } |
| 248 | addNeighborAtPort(link.dst().deviceId(), link.src().port()); |
| 249 | } |
| 250 | } |
| 251 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 252 | protected void addNeighborAtPort(DeviceId neighborId, |
| 253 | PortNumber portToNeighbor) { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 254 | // Update DeviceToPort database |
| 255 | log.debug("Device {} addNeighborAtPort: neighbor {} at port {}", |
| 256 | deviceId, neighborId, portToNeighbor); |
| 257 | if (devicePortMap.get(neighborId) != null) { |
| 258 | devicePortMap.get(neighborId).add(portToNeighbor); |
| 259 | } else { |
| 260 | Set<PortNumber> ports = new HashSet<PortNumber>(); |
| 261 | ports.add(portToNeighbor); |
| 262 | devicePortMap.put(neighborId, ports); |
| 263 | } |
| 264 | |
| 265 | // Update portToDevice database |
| 266 | if (portDeviceMap.get(portToNeighbor) == null) { |
| 267 | portDeviceMap.put(portToNeighbor, neighborId); |
| 268 | } |
| 269 | } |
| 270 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 271 | protected Set<Set<DeviceId>> getPowerSetOfNeighbors(Set<DeviceId> neighbors) { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 272 | List<DeviceId> list = new ArrayList<DeviceId>(neighbors); |
| 273 | Set<Set<DeviceId>> sets = new HashSet<Set<DeviceId>>(); |
| 274 | // get the number of elements in the neighbors |
| 275 | int elements = list.size(); |
| 276 | // the number of members of a power set is 2^n |
| 277 | // including the empty set |
| 278 | int powerElements = (1 << elements); |
| 279 | |
| 280 | // run a binary counter for the number of power elements |
| 281 | // NOTE: Exclude empty set |
| 282 | for (long i = 1; i < powerElements; i++) { |
| 283 | Set<DeviceId> neighborSubSet = new HashSet<DeviceId>(); |
| 284 | for (int j = 0; j < elements; j++) { |
| 285 | if ((i >> j) % 2 == 1) { |
| 286 | neighborSubSet.add(list.get(j)); |
| 287 | } |
| 288 | } |
| 289 | sets.add(neighborSubSet); |
| 290 | } |
| 291 | return sets; |
| 292 | } |
| 293 | |
| 294 | private boolean isSegmentIdSameAsNodeSegmentId(DeviceId deviceId, int sId) { |
| 295 | return (deviceConfig.getSegmentId(deviceId) == sId); |
| 296 | } |
| 297 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 298 | protected List<Integer> getSegmentIdsTobePairedWithNeighborSet(Set<DeviceId> neighbors) { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 299 | |
| 300 | List<Integer> nsSegmentIds = new ArrayList<Integer>(); |
| 301 | |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 302 | // Always pair up with no edge label |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 303 | // If (neighbors.size() == 1) { |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 304 | nsSegmentIds.add(-1); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 305 | // } |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 306 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 307 | // Filter out SegmentIds matching with the |
| 308 | // nodes in the combo |
| 309 | for (Integer sId : allSegmentIds) { |
| 310 | if (sId.equals(nodeSegmentId)) { |
| 311 | continue; |
| 312 | } |
| 313 | boolean filterOut = false; |
| 314 | // Check if the edge label being set is of |
| 315 | // any node in the Neighbor set |
| 316 | for (DeviceId deviceId : neighbors) { |
| 317 | if (isSegmentIdSameAsNodeSegmentId(deviceId, sId)) { |
| 318 | filterOut = true; |
| 319 | break; |
| 320 | } |
| 321 | } |
| 322 | if (!filterOut) { |
| 323 | nsSegmentIds.add(sId); |
| 324 | } |
| 325 | } |
| 326 | return nsSegmentIds; |
| 327 | } |
| 328 | |
| 329 | protected void createGroupsFromNeighborsets(Set<NeighborSet> nsSet) { |
| 330 | for (NeighborSet ns : nsSet) { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 331 | int nextId = flowObjectiveService.allocateNextId(); |
| 332 | NextObjective.Builder nextObjBuilder = DefaultNextObjective |
| 333 | .builder().withId(nextId) |
| 334 | .withType(NextObjective.Type.HASHED).fromApp(appId); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 335 | for (DeviceId d : ns.getDeviceIds()) { |
| 336 | for (PortNumber sp : devicePortMap.get(d)) { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 337 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment |
| 338 | .builder(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 339 | tBuilder.setOutput(sp) |
| 340 | .setEthDst(deviceConfig.getDeviceMac(d)) |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 341 | .setEthSrc(nodeMacAddr); |
| 342 | if (ns.getEdgeLabel() != NeighborSet.NO_EDGE_LABEL) { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 343 | tBuilder.pushMpls().setMpls(MplsLabel.mplsLabel(ns |
| 344 | .getEdgeLabel())); |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 345 | } |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 346 | nextObjBuilder.addTreatment(tBuilder.build()); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 347 | } |
| 348 | } |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 349 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 350 | NextObjective nextObj = nextObjBuilder.add(); |
| 351 | flowObjectiveService.next(deviceId, nextObj); |
| 352 | deviceNextObjectiveIds.put(getGroupKey(ns), nextId); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 353 | } |
| 354 | } |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 355 | |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 356 | public GroupKey getGroupKey(Object obj) { |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 357 | return new DefaultGroupKey(kryo.build().serialize(obj)); |
| 358 | } |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 359 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 360 | } |