Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [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 | */ |
| 16 | package org.onosproject.segmentrouting.grouphandler; |
| 17 | |
| 18 | import static com.google.common.base.Preconditions.checkNotNull; |
| 19 | import static org.slf4j.LoggerFactory.getLogger; |
| 20 | |
| 21 | import java.net.URI; |
| 22 | import java.util.ArrayList; |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 23 | import java.util.Collections; |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 24 | import java.util.HashMap; |
| 25 | import java.util.HashSet; |
| 26 | import java.util.List; |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 27 | import java.util.Random; |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 28 | import java.util.Set; |
| 29 | |
| 30 | import org.onlab.packet.MacAddress; |
| 31 | import org.onlab.packet.MplsLabel; |
| 32 | import org.onlab.util.KryoNamespace; |
| 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 | 6450548 | 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 | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 42 | import org.onosproject.net.group.DefaultGroupKey; |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 43 | import org.onosproject.net.group.GroupKey; |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 44 | import org.onosproject.net.link.LinkService; |
| 45 | import org.slf4j.Logger; |
| 46 | |
| 47 | /** |
Srikanth Vavilapalli | 6450548 | 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 | 37a461b | 2015-04-07 15:12:32 -0700 | [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 | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 63 | protected FlowObjectiveService flowObjectiveService; |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [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 | 6450548 | 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 | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 72 | |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 73 | protected KryoNamespace.Builder kryo = new KryoNamespace.Builder() |
Srikanth Vavilapalli | 6450548 | 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 | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 80 | |
Srikanth Vavilapalli | 6450548 | 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 | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 85 | this.deviceId = checkNotNull(deviceId); |
| 86 | this.appId = checkNotNull(appId); |
| 87 | this.deviceConfig = checkNotNull(config); |
| 88 | this.linkService = checkNotNull(linkService); |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [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 | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 93 | this.flowObjectiveService = flowObjService; |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 94 | |
| 95 | populateNeighborMaps(); |
| 96 | } |
| 97 | |
| 98 | /** |
Srikanth Vavilapalli | 6450548 | 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 | 37a461b | 2015-04-07 15:12:32 -0700 | [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 | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 107 | * @param flowObjService flow objective service object |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 108 | * @return default group handler type |
| 109 | */ |
| 110 | public static DefaultGroupHandler createGroupHandler(DeviceId deviceId, |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 111 | ApplicationId appId, |
| 112 | DeviceProperties config, |
| 113 | LinkService linkService, |
| 114 | FlowObjectiveService flowObjService) { |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 115 | if (config.isEdgeDevice(deviceId)) { |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 116 | return new DefaultEdgeGroupHandler(deviceId, appId, config, |
| 117 | linkService, flowObjService); |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 118 | } else { |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 119 | return new DefaultTransitGroupHandler(deviceId, appId, config, |
| 120 | linkService, flowObjService); |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 121 | } |
| 122 | } |
| 123 | |
| 124 | /** |
Srikanth Vavilapalli | 6450548 | 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 | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 127 | */ |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 128 | // Empty implementations to be overridden by derived classes |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 129 | public void createGroups() { |
| 130 | } |
| 131 | |
| 132 | /** |
Srikanth Vavilapalli | 6450548 | 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 | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 135 | * |
| 136 | * @param newLink new neighbor link |
| 137 | */ |
| 138 | public void linkUp(Link newLink) { |
| 139 | |
| 140 | if (newLink.type() != Link.Type.DIRECT) { |
| 141 | log.warn("linkUp: unknown link type"); |
| 142 | return; |
| 143 | } |
| 144 | |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 145 | if (!newLink.src().deviceId().equals(deviceId)) { |
| 146 | log.warn("linkUp: deviceId{} doesn't match with link src{}", |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 147 | deviceId, newLink.src().deviceId()); |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 148 | return; |
| 149 | } |
| 150 | |
Srikanth Vavilapalli | 6450548 | 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 | 37a461b | 2015-04-07 15:12:32 -0700 | [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 | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 163 | * Performs group recovery procedures when a port goes down on this device. |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [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 | 6450548 | 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 | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 178 | for (NeighborSet ns : nsSet) { |
| 179 | // Create the bucket to be removed |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 180 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment |
| 181 | .builder(); |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 182 | tBuilder.setOutput(port) |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 183 | .setEthDst(deviceConfig.getDeviceMac(portDeviceMap |
| 184 | .get(port))).setEthSrc(nodeMacAddr); |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 185 | if (ns.getEdgeLabel() != NeighborSet.NO_EDGE_LABEL) { |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 186 | tBuilder.pushMpls().setMpls(MplsLabel.mplsLabel(ns |
| 187 | .getEdgeLabel())); |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 188 | } |
sangho | 2165d22 | 2015-05-01 09:38:25 -0700 | [diff] [blame] | 189 | |
| 190 | Integer nextId = deviceNextObjectiveIds.get(getGroupKey(ns)); |
| 191 | if (nextId != null) { |
| 192 | NextObjective.Builder nextObjBuilder = DefaultNextObjective |
| 193 | .builder().withType(NextObjective.Type.SIMPLE).withId(nextId).fromApp(appId); |
| 194 | |
| 195 | nextObjBuilder.addTreatment(tBuilder.build()); |
| 196 | |
| 197 | NextObjective nextObjective = nextObjBuilder.remove(); |
| 198 | |
| 199 | flowObjectiveService.next(deviceId, nextObjective); |
| 200 | } |
| 201 | |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | devicePortMap.get(portDeviceMap.get(port)).remove(port); |
| 205 | portDeviceMap.remove(port); |
| 206 | } |
| 207 | |
| 208 | /** |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 209 | * Returns the next objective associated with the neighborset. |
| 210 | * If there is no next objective for this neighborset, this API |
| 211 | * would create a next objective and return. |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 212 | * |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 213 | * @param ns neighborset |
| 214 | * @return int if found or -1 |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 215 | */ |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 216 | public int getNextObjectiveId(NeighborSet ns) { |
| 217 | Integer nextId = deviceNextObjectiveIds.get(getGroupKey(ns)); |
| 218 | if (nextId == null) { |
| 219 | createGroupsFromNeighborsets(Collections.singleton(ns)); |
| 220 | nextId = deviceNextObjectiveIds.get(getGroupKey(ns)); |
| 221 | if (nextId == null) { |
| 222 | log.warn("getNextObjectiveId: unable to create next objective"); |
| 223 | return -1; |
| 224 | } |
| 225 | } |
| 226 | return nextId.intValue(); |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 229 | // Empty implementation |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 230 | protected void newNeighbor(Link newLink) { |
| 231 | } |
| 232 | |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 233 | // Empty implementation |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 234 | protected void newPortToExistingNeighbor(Link newLink) { |
| 235 | } |
| 236 | |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 237 | // Empty implementation |
| 238 | protected Set<NeighborSet> |
| 239 | computeImpactedNeighborsetForPortEvent(DeviceId impactedNeighbor, |
| 240 | Set<DeviceId> updatedNeighbors) { |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 241 | return null; |
| 242 | } |
| 243 | |
| 244 | private void populateNeighborMaps() { |
| 245 | Set<Link> outgoingLinks = linkService.getDeviceEgressLinks(deviceId); |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 246 | for (Link link : outgoingLinks) { |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 247 | if (link.type() != Link.Type.DIRECT) { |
| 248 | continue; |
| 249 | } |
| 250 | addNeighborAtPort(link.dst().deviceId(), link.src().port()); |
| 251 | } |
| 252 | } |
| 253 | |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 254 | protected void addNeighborAtPort(DeviceId neighborId, |
| 255 | PortNumber portToNeighbor) { |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 256 | // Update DeviceToPort database |
| 257 | log.debug("Device {} addNeighborAtPort: neighbor {} at port {}", |
| 258 | deviceId, neighborId, portToNeighbor); |
| 259 | if (devicePortMap.get(neighborId) != null) { |
| 260 | devicePortMap.get(neighborId).add(portToNeighbor); |
| 261 | } else { |
| 262 | Set<PortNumber> ports = new HashSet<PortNumber>(); |
| 263 | ports.add(portToNeighbor); |
| 264 | devicePortMap.put(neighborId, ports); |
| 265 | } |
| 266 | |
| 267 | // Update portToDevice database |
| 268 | if (portDeviceMap.get(portToNeighbor) == null) { |
| 269 | portDeviceMap.put(portToNeighbor, neighborId); |
| 270 | } |
| 271 | } |
| 272 | |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 273 | protected Set<Set<DeviceId>> getPowerSetOfNeighbors(Set<DeviceId> neighbors) { |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 274 | List<DeviceId> list = new ArrayList<DeviceId>(neighbors); |
| 275 | Set<Set<DeviceId>> sets = new HashSet<Set<DeviceId>>(); |
| 276 | // get the number of elements in the neighbors |
| 277 | int elements = list.size(); |
| 278 | // the number of members of a power set is 2^n |
| 279 | // including the empty set |
| 280 | int powerElements = (1 << elements); |
| 281 | |
| 282 | // run a binary counter for the number of power elements |
| 283 | // NOTE: Exclude empty set |
| 284 | for (long i = 1; i < powerElements; i++) { |
| 285 | Set<DeviceId> neighborSubSet = new HashSet<DeviceId>(); |
| 286 | for (int j = 0; j < elements; j++) { |
| 287 | if ((i >> j) % 2 == 1) { |
| 288 | neighborSubSet.add(list.get(j)); |
| 289 | } |
| 290 | } |
| 291 | sets.add(neighborSubSet); |
| 292 | } |
| 293 | return sets; |
| 294 | } |
| 295 | |
| 296 | private boolean isSegmentIdSameAsNodeSegmentId(DeviceId deviceId, int sId) { |
| 297 | return (deviceConfig.getSegmentId(deviceId) == sId); |
| 298 | } |
| 299 | |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 300 | protected List<Integer> getSegmentIdsTobePairedWithNeighborSet(Set<DeviceId> neighbors) { |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 301 | |
| 302 | List<Integer> nsSegmentIds = new ArrayList<Integer>(); |
| 303 | |
| 304 | // Always pair up with no edge label |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 305 | // If (neighbors.size() == 1) { |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 306 | nsSegmentIds.add(-1); |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 307 | // } |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 308 | |
| 309 | // Filter out SegmentIds matching with the |
| 310 | // nodes in the combo |
| 311 | for (Integer sId : allSegmentIds) { |
| 312 | if (sId.equals(nodeSegmentId)) { |
| 313 | continue; |
| 314 | } |
| 315 | boolean filterOut = false; |
| 316 | // Check if the edge label being set is of |
| 317 | // any node in the Neighbor set |
| 318 | for (DeviceId deviceId : neighbors) { |
| 319 | if (isSegmentIdSameAsNodeSegmentId(deviceId, sId)) { |
| 320 | filterOut = true; |
| 321 | break; |
| 322 | } |
| 323 | } |
| 324 | if (!filterOut) { |
| 325 | nsSegmentIds.add(sId); |
| 326 | } |
| 327 | } |
| 328 | return nsSegmentIds; |
| 329 | } |
| 330 | |
| 331 | protected void createGroupsFromNeighborsets(Set<NeighborSet> nsSet) { |
| 332 | for (NeighborSet ns : nsSet) { |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 333 | int nextId = flowObjectiveService.allocateNextId(); |
| 334 | NextObjective.Builder nextObjBuilder = DefaultNextObjective |
| 335 | .builder().withId(nextId) |
| 336 | .withType(NextObjective.Type.HASHED).fromApp(appId); |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 337 | for (DeviceId d : ns.getDeviceIds()) { |
sangho | 2165d22 | 2015-05-01 09:38:25 -0700 | [diff] [blame] | 338 | if (devicePortMap.get(d) == null) { |
| 339 | log.warn("Device {} is not in the port map yet", d); |
| 340 | return; |
| 341 | } |
| 342 | |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 343 | for (PortNumber sp : devicePortMap.get(d)) { |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 344 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment |
| 345 | .builder(); |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 346 | tBuilder.setOutput(sp) |
| 347 | .setEthDst(deviceConfig.getDeviceMac(d)) |
| 348 | .setEthSrc(nodeMacAddr); |
| 349 | if (ns.getEdgeLabel() != NeighborSet.NO_EDGE_LABEL) { |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 350 | tBuilder.pushMpls().setMpls(MplsLabel.mplsLabel(ns |
sangho | 2165d22 | 2015-05-01 09:38:25 -0700 | [diff] [blame] | 351 | .getEdgeLabel())); |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 352 | } |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 353 | nextObjBuilder.addTreatment(tBuilder.build()); |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 354 | } |
| 355 | } |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 356 | |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 357 | NextObjective nextObj = nextObjBuilder.add(); |
| 358 | flowObjectiveService.next(deviceId, nextObj); |
| 359 | deviceNextObjectiveIds.put(getGroupKey(ns), nextId); |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 360 | } |
| 361 | } |
| 362 | |
| 363 | public GroupKey getGroupKey(Object obj) { |
| 364 | return new DefaultGroupKey(kryo.build().serialize(obj)); |
| 365 | } |
| 366 | |
| 367 | } |