Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 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 | |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 18 | |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 19 | import com.google.common.collect.Iterables; |
| 20 | import org.apache.commons.lang3.RandomUtils; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 21 | import org.onlab.packet.MacAddress; |
sangho | 32a5932 | 2015-02-17 12:07:41 -0800 | [diff] [blame] | 22 | import org.onlab.packet.MplsLabel; |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 23 | import org.onlab.packet.VlanId; |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 24 | import org.onlab.util.KryoNamespace; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 25 | import org.onosproject.core.ApplicationId; |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 26 | import org.onosproject.incubator.net.intf.Interface; |
| 27 | import org.onosproject.net.ConnectPoint; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 28 | import org.onosproject.net.DeviceId; |
| 29 | import org.onosproject.net.Link; |
| 30 | import org.onosproject.net.PortNumber; |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 31 | import org.onosproject.net.flow.DefaultTrafficSelector; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 32 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 33 | import org.onosproject.net.flow.TrafficSelector; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 34 | import org.onosproject.net.flow.TrafficTreatment; |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 35 | import org.onosproject.net.flowobjective.DefaultNextObjective; |
Charles Chan | 216e3c8 | 2016-04-23 14:48:16 -0700 | [diff] [blame] | 36 | import org.onosproject.net.flowobjective.DefaultObjectiveContext; |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 37 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
| 38 | import org.onosproject.net.flowobjective.NextObjective; |
Srikanth Vavilapalli | f3a8bc0 | 2015-05-22 13:47:31 -0700 | [diff] [blame] | 39 | import org.onosproject.net.flowobjective.ObjectiveContext; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 40 | import org.onosproject.net.link.LinkService; |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 41 | import org.onosproject.segmentrouting.SegmentRoutingManager; |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 42 | import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException; |
| 43 | import org.onosproject.segmentrouting.config.DeviceProperties; |
Charles Chan | d299036 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 44 | import org.onosproject.segmentrouting.storekey.NeighborSetNextObjectiveStoreKey; |
| 45 | import org.onosproject.segmentrouting.storekey.PortNextObjectiveStoreKey; |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 46 | import org.onosproject.segmentrouting.storekey.VlanNextObjectiveStoreKey; |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 47 | import org.onosproject.store.service.EventuallyConsistentMap; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 48 | import org.slf4j.Logger; |
| 49 | |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 50 | import java.net.URI; |
| 51 | import java.util.ArrayList; |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 52 | import java.util.Collection; |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 53 | import java.util.Collections; |
| 54 | import java.util.HashSet; |
| 55 | import java.util.List; |
| 56 | import java.util.Map; |
| 57 | import java.util.Set; |
| 58 | import java.util.concurrent.ConcurrentHashMap; |
| 59 | import java.util.stream.Collectors; |
| 60 | |
| 61 | import static com.google.common.base.Preconditions.checkNotNull; |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 62 | import static org.onosproject.segmentrouting.SegmentRoutingManager.INTERNAL_VLAN; |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 63 | import static org.slf4j.LoggerFactory.getLogger; |
| 64 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 65 | /** |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 66 | * Default ECMP group handler creation module. This component creates a set of |
| 67 | * ECMP groups for every neighbor that this device is connected to based on |
| 68 | * whether the current device is an edge device or a transit device. |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 69 | */ |
| 70 | public class DefaultGroupHandler { |
Srikanth Vavilapalli | f3a8bc0 | 2015-05-22 13:47:31 -0700 | [diff] [blame] | 71 | protected static final Logger log = getLogger(DefaultGroupHandler.class); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 72 | |
| 73 | protected final DeviceId deviceId; |
| 74 | protected final ApplicationId appId; |
| 75 | protected final DeviceProperties deviceConfig; |
| 76 | protected final List<Integer> allSegmentIds; |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 77 | protected int ipv4NodeSegmentId = -1; |
| 78 | protected int ipv6NodeSegmentId = -1; |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 79 | protected boolean isEdgeRouter = false; |
| 80 | protected MacAddress nodeMacAddr = null; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 81 | protected LinkService linkService; |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 82 | protected FlowObjectiveService flowObjectiveService; |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 83 | // local store for neighbor-device-ids and the set of ports on this device |
| 84 | // that connect to the same neighbor |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 85 | protected ConcurrentHashMap<DeviceId, Set<PortNumber>> devicePortMap = |
| 86 | new ConcurrentHashMap<>(); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 87 | // local store for ports on this device connected to neighbor-device-id |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 88 | protected ConcurrentHashMap<PortNumber, DeviceId> portDeviceMap = |
| 89 | new ConcurrentHashMap<>(); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 90 | // distributed store for (device+neighborset) mapped to next-id |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 91 | protected EventuallyConsistentMap<NeighborSetNextObjectiveStoreKey, Integer> |
| 92 | nsNextObjStore = null; |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 93 | // distributed store for (device+subnet-ip-prefix) mapped to next-id |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 94 | protected EventuallyConsistentMap<VlanNextObjectiveStoreKey, Integer> |
| 95 | vlanNextObjStore = null; |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 96 | // distributed store for (device+port+treatment) mapped to next-id |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 97 | protected EventuallyConsistentMap<PortNextObjectiveStoreKey, Integer> |
| 98 | portNextObjStore = null; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 99 | private SegmentRoutingManager srManager; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 100 | |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 101 | protected KryoNamespace.Builder kryo = new KryoNamespace.Builder() |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 102 | .register(URI.class).register(HashSet.class) |
| 103 | .register(DeviceId.class).register(PortNumber.class) |
| 104 | .register(NeighborSet.class).register(PolicyGroupIdentifier.class) |
| 105 | .register(PolicyGroupParams.class) |
| 106 | .register(GroupBucketIdentifier.class) |
| 107 | .register(GroupBucketIdentifier.BucketOutputType.class); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 108 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 109 | protected DefaultGroupHandler(DeviceId deviceId, ApplicationId appId, |
| 110 | DeviceProperties config, |
| 111 | LinkService linkService, |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 112 | FlowObjectiveService flowObjService, |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 113 | SegmentRoutingManager srManager) { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 114 | this.deviceId = checkNotNull(deviceId); |
| 115 | this.appId = checkNotNull(appId); |
| 116 | this.deviceConfig = checkNotNull(config); |
| 117 | this.linkService = checkNotNull(linkService); |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 118 | this.allSegmentIds = checkNotNull(config.getAllDeviceSegmentIds()); |
| 119 | try { |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 120 | this.ipv4NodeSegmentId = config.getIPv4SegmentId(deviceId); |
| 121 | this.ipv6NodeSegmentId = config.getIPv6SegmentId(deviceId); |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 122 | this.isEdgeRouter = config.isEdgeDevice(deviceId); |
| 123 | this.nodeMacAddr = checkNotNull(config.getDeviceMac(deviceId)); |
| 124 | } catch (DeviceConfigNotFoundException e) { |
| 125 | log.warn(e.getMessage() |
| 126 | + " Skipping value assignment in DefaultGroupHandler"); |
| 127 | } |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 128 | this.flowObjectiveService = flowObjService; |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 129 | this.nsNextObjStore = srManager.nsNextObjStore; |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 130 | this.vlanNextObjStore = srManager.vlanNextObjStore; |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 131 | this.portNextObjStore = srManager.portNextObjStore; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 132 | this.srManager = srManager; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 133 | |
| 134 | populateNeighborMaps(); |
| 135 | } |
| 136 | |
| 137 | /** |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 138 | * Creates a group handler object based on the type of device. If device is |
| 139 | * of edge type it returns edge group handler, else it returns transit group |
| 140 | * handler. |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 141 | * |
| 142 | * @param deviceId device identifier |
| 143 | * @param appId application identifier |
| 144 | * @param config interface to retrieve the device properties |
| 145 | * @param linkService link service object |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 146 | * @param flowObjService flow objective service object |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 147 | * @param srManager segment routing manager |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 148 | * @throws DeviceConfigNotFoundException if the device configuration is not found |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 149 | * @return default group handler type |
| 150 | */ |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 151 | public static DefaultGroupHandler createGroupHandler( |
| 152 | DeviceId deviceId, |
| 153 | ApplicationId appId, |
| 154 | DeviceProperties config, |
| 155 | LinkService linkService, |
| 156 | FlowObjectiveService flowObjService, |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 157 | SegmentRoutingManager srManager) |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 158 | throws DeviceConfigNotFoundException { |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 159 | // handle possible exception in the caller |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 160 | if (config.isEdgeDevice(deviceId)) { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 161 | return new DefaultEdgeGroupHandler(deviceId, appId, config, |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 162 | linkService, |
| 163 | flowObjService, |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 164 | srManager |
| 165 | ); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 166 | } else { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 167 | return new DefaultTransitGroupHandler(deviceId, appId, config, |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 168 | linkService, |
| 169 | flowObjService, |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 170 | srManager); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 171 | } |
| 172 | } |
| 173 | |
| 174 | /** |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 175 | * Creates the auto created groups for this device based on the current |
| 176 | * snapshot of the topology. |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 177 | */ |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 178 | // Empty implementations to be overridden by derived classes |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 179 | public void createGroups() { |
| 180 | } |
| 181 | |
| 182 | /** |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 183 | * Performs group creation or update procedures when a new link is |
| 184 | * discovered on this device. |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 185 | * |
| 186 | * @param newLink new neighbor link |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 187 | * @param isMaster true if local instance is the master |
| 188 | * |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 189 | */ |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 190 | public void linkUp(Link newLink, boolean isMaster) { |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 191 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 192 | if (newLink.type() != Link.Type.DIRECT) { |
| 193 | log.warn("linkUp: unknown link type"); |
| 194 | return; |
| 195 | } |
| 196 | |
| 197 | if (!newLink.src().deviceId().equals(deviceId)) { |
| 198 | log.warn("linkUp: deviceId{} doesn't match with link src{}", |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 199 | deviceId, newLink.src().deviceId()); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 200 | return; |
| 201 | } |
| 202 | |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 203 | log.info("* LinkUP: Device {} linkUp at local port {} to neighbor {}", deviceId, |
| 204 | newLink.src().port(), newLink.dst().deviceId()); |
Saurav Das | 59232cf | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 205 | // ensure local state is updated even if linkup is aborted later on |
| 206 | addNeighborAtPort(newLink.dst().deviceId(), |
| 207 | newLink.src().port()); |
| 208 | |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 209 | MacAddress dstMac; |
| 210 | try { |
| 211 | dstMac = deviceConfig.getDeviceMac(newLink.dst().deviceId()); |
| 212 | } catch (DeviceConfigNotFoundException e) { |
| 213 | log.warn(e.getMessage() + " Aborting linkUp."); |
| 214 | return; |
| 215 | } |
| 216 | |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 217 | /*if (devicePortMap.get(newLink.dst().deviceId()) == null) { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 218 | // New Neighbor |
| 219 | newNeighbor(newLink); |
| 220 | } else { |
| 221 | // Old Neighbor |
| 222 | newPortToExistingNeighbor(newLink); |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 223 | }*/ |
| 224 | Set<NeighborSet> nsSet = nsNextObjStore.keySet() |
| 225 | .stream() |
| 226 | .filter((nsStoreEntry) -> (nsStoreEntry.deviceId().equals(deviceId))) |
| 227 | .map((nsStoreEntry) -> (nsStoreEntry.neighborSet())) |
| 228 | .filter((ns) -> (ns.getDeviceIds() |
| 229 | .contains(newLink.dst().deviceId()))) |
| 230 | .collect(Collectors.toSet()); |
| 231 | log.trace("linkUp: nsNextObjStore contents for device {}:", |
sangho | 0b2b6d1 | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 232 | deviceId, |
| 233 | nsSet); |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 234 | for (NeighborSet ns : nsSet) { |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 235 | Integer nextId = nsNextObjStore. |
| 236 | get(new NeighborSetNextObjectiveStoreKey(deviceId, ns)); |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 237 | if (nextId != null && isMaster) { |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 238 | // Create the new bucket to be updated |
| 239 | TrafficTreatment.Builder tBuilder = |
| 240 | DefaultTrafficTreatment.builder(); |
| 241 | tBuilder.setOutput(newLink.src().port()) |
| 242 | .setEthDst(dstMac) |
| 243 | .setEthSrc(nodeMacAddr); |
| 244 | if (ns.getEdgeLabel() != NeighborSet.NO_EDGE_LABEL) { |
| 245 | tBuilder.pushMpls() |
| 246 | .copyTtlOut() |
| 247 | .setMpls(MplsLabel.mplsLabel(ns.getEdgeLabel())); |
| 248 | } |
| 249 | // setup metadata to pass to nextObjective - indicate the vlan on egress |
| 250 | // if needed by the switch pipeline. Since hashed next-hops are always to |
| 251 | // other neighboring routers, there is no subnet assigned on those ports. |
| 252 | TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder(); |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 253 | metabuilder.matchVlanId(INTERNAL_VLAN); |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 254 | |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 255 | NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder() |
| 256 | .withId(nextId) |
| 257 | .withType(NextObjective.Type.HASHED) |
| 258 | .addTreatment(tBuilder.build()) |
| 259 | .withMeta(metabuilder.build()) |
| 260 | .fromApp(appId); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 261 | log.info("**linkUp in device {}: Adding Bucket " |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 262 | + "with Port {} to next object id {}", |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 263 | deviceId, |
| 264 | newLink.src().port(), |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 265 | nextId); |
Charles Chan | 216e3c8 | 2016-04-23 14:48:16 -0700 | [diff] [blame] | 266 | |
| 267 | ObjectiveContext context = new DefaultObjectiveContext( |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 268 | (objective) -> log.debug("LinkUp addedTo NextObj {} on {}", |
Charles Chan | 216e3c8 | 2016-04-23 14:48:16 -0700 | [diff] [blame] | 269 | nextId, deviceId), |
| 270 | (objective, error) -> |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 271 | log.warn("LinkUp failed to addTo NextObj {} on {}: {}", |
Charles Chan | 216e3c8 | 2016-04-23 14:48:16 -0700 | [diff] [blame] | 272 | nextId, deviceId, error)); |
| 273 | NextObjective nextObjective = nextObjBuilder.addToExisting(context); |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 274 | flowObjectiveService.next(deviceId, nextObjective); |
| 275 | } else if (isMaster) { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 276 | log.warn("linkUp in device {}, but global store has no record " |
| 277 | + "for neighbor-set {}", deviceId, ns); |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 278 | } |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 279 | } |
| 280 | } |
| 281 | |
| 282 | /** |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 283 | * Performs hash group recovery procedures when a switch-to-switch |
| 284 | * port goes down on this device. |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 285 | * |
| 286 | * @param port port number that has gone down |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 287 | * @param isMaster true if local instance is the master |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 288 | */ |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 289 | public void portDown(PortNumber port, boolean isMaster) { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 290 | if (portDeviceMap.get(port) == null) { |
| 291 | log.warn("portDown: unknown port"); |
| 292 | return; |
| 293 | } |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 294 | |
| 295 | MacAddress dstMac; |
| 296 | try { |
| 297 | dstMac = deviceConfig.getDeviceMac(portDeviceMap.get(port)); |
| 298 | } catch (DeviceConfigNotFoundException e) { |
| 299 | log.warn(e.getMessage() + " Aborting portDown."); |
| 300 | return; |
| 301 | } |
| 302 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 303 | log.debug("Device {} portDown {} to neighbor {}", deviceId, port, |
| 304 | portDeviceMap.get(port)); |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 305 | /*Set<NeighborSet> nsSet = computeImpactedNeighborsetForPortEvent(portDeviceMap |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 306 | .get(port), |
| 307 | devicePortMap |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 308 | .keySet());*/ |
| 309 | Set<NeighborSet> nsSet = nsNextObjStore.keySet() |
| 310 | .stream() |
| 311 | .filter((nsStoreEntry) -> (nsStoreEntry.deviceId().equals(deviceId))) |
| 312 | .map((nsStoreEntry) -> (nsStoreEntry.neighborSet())) |
| 313 | .filter((ns) -> (ns.getDeviceIds() |
| 314 | .contains(portDeviceMap.get(port)))) |
| 315 | .collect(Collectors.toSet()); |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 316 | log.debug("portDown: nsNextObjStore contents for device {}:{}", |
| 317 | deviceId, nsSet); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 318 | for (NeighborSet ns : nsSet) { |
Saurav Das | 80980c7 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 319 | NeighborSetNextObjectiveStoreKey nsStoreKey = |
| 320 | new NeighborSetNextObjectiveStoreKey(deviceId, ns); |
| 321 | Integer nextId = nsNextObjStore.get(nsStoreKey); |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 322 | if (nextId != null && isMaster) { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 323 | log.info("**portDown in device {}: Removing Bucket " |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 324 | + "with Port {} to next object id {}", |
| 325 | deviceId, |
| 326 | port, |
| 327 | nextId); |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 328 | // Create the bucket to be removed |
| 329 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment |
| 330 | .builder(); |
| 331 | tBuilder.setOutput(port) |
| 332 | .setEthDst(dstMac) |
| 333 | .setEthSrc(nodeMacAddr); |
| 334 | if (ns.getEdgeLabel() != NeighborSet.NO_EDGE_LABEL) { |
| 335 | tBuilder.pushMpls() |
| 336 | .copyTtlOut() |
| 337 | .setMpls(MplsLabel.mplsLabel(ns.getEdgeLabel())); |
| 338 | } |
| 339 | NextObjective.Builder nextObjBuilder = DefaultNextObjective |
| 340 | .builder() |
| 341 | .withType(NextObjective.Type.HASHED) //same as original |
| 342 | .withId(nextId) |
| 343 | .fromApp(appId) |
| 344 | .addTreatment(tBuilder.build()); |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 345 | ObjectiveContext context = new DefaultObjectiveContext( |
| 346 | (objective) -> log.debug("portDown removedFrom NextObj {} on {}", |
| 347 | nextId, deviceId), |
| 348 | (objective, error) -> |
| 349 | log.warn("portDown failed to removeFrom NextObj {} on {}: {}", |
| 350 | nextId, deviceId, error)); |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 351 | NextObjective nextObjective = nextObjBuilder. |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 352 | removeFromExisting(context); |
sangho | 834e4b0 | 2015-05-01 09:38:25 -0700 | [diff] [blame] | 353 | |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 354 | flowObjectiveService.next(deviceId, nextObjective); |
sangho | 834e4b0 | 2015-05-01 09:38:25 -0700 | [diff] [blame] | 355 | } |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | devicePortMap.get(portDeviceMap.get(port)).remove(port); |
| 359 | portDeviceMap.remove(port); |
| 360 | } |
| 361 | |
| 362 | /** |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame^] | 363 | * Adds or removes a port that has been configured with a vlan to a broadcast group |
| 364 | * for bridging. Should only be called by the master instance for this device. |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 365 | * |
| 366 | * @param port the port on this device that needs to be added/removed to a bcast group |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame^] | 367 | * @param vlanId the vlan id corresponding to the broadcast domain/group |
| 368 | * @param popVlan indicates if packets should be sent out untagged or not out |
| 369 | * of the port. If true, indicates an access (untagged) or native vlan |
| 370 | * configuration. If false, indicates a trunk (tagged) vlan config. |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 371 | * @param portUp true if port is enabled, false if disabled |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 372 | */ |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame^] | 373 | public void processEdgePort(PortNumber port, VlanId vlanId, |
| 374 | boolean popVlan, boolean portUp) { |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 375 | //get the next id for the subnet and edit it. |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 376 | Integer nextId = getVlanNextObjectiveId(vlanId); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 377 | if (nextId == -1) { |
| 378 | if (portUp) { |
| 379 | log.debug("**Creating flooding group for first port enabled in" |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 380 | + " subnet {} on dev {} port {}", vlanId, deviceId, port); |
| 381 | createBcastGroupFromVlan(vlanId, Collections.singleton(port)); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 382 | } else { |
| 383 | log.warn("Could not find flooding group for subnet {} on dev:{} when" |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 384 | + " removing port:{}", vlanId, deviceId, port); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 385 | } |
| 386 | return; |
| 387 | } |
| 388 | |
| 389 | log.info("**port{} in device {}: {} Bucket with Port {} to" |
| 390 | + " next-id {}", (portUp) ? "UP" : "DOWN", deviceId, |
| 391 | (portUp) ? "Adding" : "Removing", |
| 392 | port, nextId); |
| 393 | // Create the bucket to be added or removed |
| 394 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame^] | 395 | if (popVlan) { |
| 396 | tBuilder.popVlan(); |
| 397 | } |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 398 | tBuilder.setOutput(port); |
| 399 | |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 400 | TrafficSelector metadata = |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame^] | 401 | DefaultTrafficSelector.builder().matchVlanId(vlanId).build(); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 402 | |
| 403 | NextObjective.Builder nextObjBuilder = DefaultNextObjective |
| 404 | .builder().withId(nextId) |
| 405 | .withType(NextObjective.Type.BROADCAST).fromApp(appId) |
| 406 | .addTreatment(tBuilder.build()) |
| 407 | .withMeta(metadata); |
| 408 | |
| 409 | ObjectiveContext context = new DefaultObjectiveContext( |
| 410 | (objective) -> log.debug("port {} successfully {} NextObj {} on {}", |
| 411 | port, (portUp) ? "addedTo" : "removedFrom", |
| 412 | nextId, deviceId), |
| 413 | (objective, error) -> |
| 414 | log.warn("port {} failed to {} NextObj {} on {}: {}", |
| 415 | port, (portUp) ? "addTo" : "removeFrom", |
| 416 | nextId, deviceId, error)); |
| 417 | |
| 418 | NextObjective nextObj = (portUp) ? nextObjBuilder.addToExisting(context) |
| 419 | : nextObjBuilder.removeFromExisting(context); |
| 420 | log.debug("edgePort processed: Submited next objective {} in device {}", |
| 421 | nextId, deviceId); |
| 422 | flowObjectiveService.next(deviceId, nextObj); |
| 423 | } |
| 424 | |
| 425 | /** |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 426 | * Returns the next objective of type hashed associated with the neighborset. |
| 427 | * If there is no next objective for this neighborset, this method |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 428 | * would create a next objective and return. Optionally metadata can be |
| 429 | * passed in for the creation of the next objective. |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 430 | * |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 431 | * @param ns neighborset |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 432 | * @param meta metadata passed into the creation of a Next Objective |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 433 | * @param isBos if Bos is set |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 434 | * @return int if found or -1 if there are errors in the creation of the |
| 435 | * neighbor set. |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 436 | */ |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 437 | public int getNextObjectiveId(NeighborSet ns, TrafficSelector meta, boolean isBos) { |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 438 | Integer nextId = nsNextObjStore. |
| 439 | get(new NeighborSetNextObjectiveStoreKey(deviceId, ns)); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 440 | if (nextId == null) { |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 441 | log.trace("getNextObjectiveId in device{}: Next objective id " |
| 442 | + "not found for {} and creating", deviceId, ns); |
| 443 | log.trace("getNextObjectiveId: nsNextObjStore contents for device {}: {}", |
| 444 | deviceId, |
| 445 | nsNextObjStore.entrySet() |
| 446 | .stream() |
| 447 | .filter((nsStoreEntry) -> |
| 448 | (nsStoreEntry.getKey().deviceId().equals(deviceId))) |
| 449 | .collect(Collectors.toList())); |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 450 | createGroupsFromNeighborsets(Collections.singleton(ns), meta, isBos); |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 451 | nextId = nsNextObjStore. |
| 452 | get(new NeighborSetNextObjectiveStoreKey(deviceId, ns)); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 453 | if (nextId == null) { |
| 454 | log.warn("getNextObjectiveId: unable to create next objective"); |
| 455 | return -1; |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 456 | } else { |
| 457 | log.debug("getNextObjectiveId in device{}: Next objective id {} " |
Sho SHIMIZU | af97343 | 2015-09-11 14:24:50 -0700 | [diff] [blame] | 458 | + "created for {}", deviceId, nextId, ns); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 459 | } |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 460 | } else { |
| 461 | log.trace("getNextObjectiveId in device{}: Next objective id {} " |
Sho SHIMIZU | af97343 | 2015-09-11 14:24:50 -0700 | [diff] [blame] | 462 | + "found for {}", deviceId, nextId, ns); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 463 | } |
Sho SHIMIZU | af97343 | 2015-09-11 14:24:50 -0700 | [diff] [blame] | 464 | return nextId; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 465 | } |
| 466 | |
sangho | 0b2b6d1 | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 467 | /** |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 468 | * Returns the next objective of type broadcast associated with the vlan, |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 469 | * or -1 if no such objective exists. Note that this method does NOT create |
| 470 | * the next objective as a side-effect. It is expected that is objective is |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 471 | * created at startup from network configuration. Typically this is used |
| 472 | * for L2 flooding within the subnet configured on the switch. |
Charles Chan | c42e84e | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 473 | * |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 474 | * @param vlanId vlan id |
Charles Chan | c42e84e | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 475 | * @return int if found or -1 |
| 476 | */ |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 477 | public int getVlanNextObjectiveId(VlanId vlanId) { |
| 478 | Integer nextId = vlanNextObjStore. |
| 479 | get(new VlanNextObjectiveStoreKey(deviceId, vlanId)); |
Charles Chan | 9f676b6 | 2015-10-29 14:58:10 -0700 | [diff] [blame] | 480 | |
| 481 | return (nextId != null) ? nextId : -1; |
Charles Chan | c42e84e | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | /** |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 485 | * Returns the next objective of type simple associated with the port on the |
| 486 | * device, given the treatment. Different treatments to the same port result |
| 487 | * in different next objectives. If no such objective exists, this method |
| 488 | * creates one and returns the id. Optionally metadata can be passed in for |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 489 | * the creation of the objective. Typically this is used for L2 and L3 forwarding |
| 490 | * to compute nodes and containers/VMs on the compute nodes directly attached |
| 491 | * to the switch. |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 492 | * |
| 493 | * @param portNum the port number for the simple next objective |
| 494 | * @param treatment the actions to apply on the packets (should include outport) |
| 495 | * @param meta optional metadata passed into the creation of the next objective |
| 496 | * @return int if found or created, -1 if there are errors during the |
| 497 | * creation of the next objective. |
| 498 | */ |
| 499 | public int getPortNextObjectiveId(PortNumber portNum, TrafficTreatment treatment, |
| 500 | TrafficSelector meta) { |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 501 | Integer nextId = portNextObjStore |
| 502 | .get(new PortNextObjectiveStoreKey(deviceId, portNum, treatment)); |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 503 | if (nextId == null) { |
| 504 | log.trace("getPortNextObjectiveId in device{}: Next objective id " |
| 505 | + "not found for {} and {} creating", deviceId, portNum); |
| 506 | createGroupFromPort(portNum, treatment, meta); |
| 507 | nextId = portNextObjStore.get( |
| 508 | new PortNextObjectiveStoreKey(deviceId, portNum, treatment)); |
| 509 | if (nextId == null) { |
| 510 | log.warn("getPortNextObjectiveId: unable to create next obj" |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 511 | + "for dev:{} port:{}", deviceId, portNum); |
| 512 | return -1; |
| 513 | } |
| 514 | } |
| 515 | return nextId; |
| 516 | } |
| 517 | |
| 518 | /** |
sangho | 0b2b6d1 | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 519 | * Checks if the next objective ID (group) for the neighbor set exists or not. |
| 520 | * |
| 521 | * @param ns neighbor set to check |
| 522 | * @return true if it exists, false otherwise |
| 523 | */ |
| 524 | public boolean hasNextObjectiveId(NeighborSet ns) { |
| 525 | Integer nextId = nsNextObjStore. |
| 526 | get(new NeighborSetNextObjectiveStoreKey(deviceId, ns)); |
| 527 | if (nextId == null) { |
| 528 | return false; |
| 529 | } |
| 530 | |
| 531 | return true; |
| 532 | } |
| 533 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 534 | // Empty implementation |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 535 | protected void newNeighbor(Link newLink) { |
| 536 | } |
| 537 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 538 | // Empty implementation |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 539 | protected void newPortToExistingNeighbor(Link newLink) { |
| 540 | } |
| 541 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 542 | // Empty implementation |
| 543 | protected Set<NeighborSet> |
| 544 | computeImpactedNeighborsetForPortEvent(DeviceId impactedNeighbor, |
| 545 | Set<DeviceId> updatedNeighbors) { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 546 | return null; |
| 547 | } |
| 548 | |
| 549 | private void populateNeighborMaps() { |
| 550 | Set<Link> outgoingLinks = linkService.getDeviceEgressLinks(deviceId); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 551 | for (Link link : outgoingLinks) { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 552 | if (link.type() != Link.Type.DIRECT) { |
| 553 | continue; |
| 554 | } |
| 555 | addNeighborAtPort(link.dst().deviceId(), link.src().port()); |
| 556 | } |
| 557 | } |
| 558 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 559 | protected void addNeighborAtPort(DeviceId neighborId, |
| 560 | PortNumber portToNeighbor) { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 561 | // Update DeviceToPort database |
| 562 | log.debug("Device {} addNeighborAtPort: neighbor {} at port {}", |
| 563 | deviceId, neighborId, portToNeighbor); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 564 | Set<PortNumber> ports = Collections |
| 565 | .newSetFromMap(new ConcurrentHashMap<PortNumber, Boolean>()); |
| 566 | ports.add(portToNeighbor); |
| 567 | Set<PortNumber> portnums = devicePortMap.putIfAbsent(neighborId, ports); |
| 568 | if (portnums != null) { |
| 569 | portnums.add(portToNeighbor); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | // Update portToDevice database |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 573 | DeviceId prev = portDeviceMap.putIfAbsent(portToNeighbor, neighborId); |
| 574 | if (prev != null) { |
| 575 | log.warn("Device: {} port: {} has neighbor: {}. NOT updating " |
| 576 | + "to neighbor: {}", deviceId, portToNeighbor, prev, neighborId); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 577 | } |
| 578 | } |
| 579 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 580 | protected Set<Set<DeviceId>> getPowerSetOfNeighbors(Set<DeviceId> neighbors) { |
Sho SHIMIZU | 6cfc02d | 2015-09-11 11:19:11 -0700 | [diff] [blame] | 581 | List<DeviceId> list = new ArrayList<>(neighbors); |
| 582 | Set<Set<DeviceId>> sets = new HashSet<>(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 583 | // get the number of elements in the neighbors |
| 584 | int elements = list.size(); |
| 585 | // the number of members of a power set is 2^n |
| 586 | // including the empty set |
| 587 | int powerElements = (1 << elements); |
| 588 | |
| 589 | // run a binary counter for the number of power elements |
| 590 | // NOTE: Exclude empty set |
| 591 | for (long i = 1; i < powerElements; i++) { |
Sho SHIMIZU | 6cfc02d | 2015-09-11 11:19:11 -0700 | [diff] [blame] | 592 | Set<DeviceId> neighborSubSet = new HashSet<>(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 593 | for (int j = 0; j < elements; j++) { |
| 594 | if ((i >> j) % 2 == 1) { |
| 595 | neighborSubSet.add(list.get(j)); |
| 596 | } |
| 597 | } |
| 598 | sets.add(neighborSubSet); |
| 599 | } |
| 600 | return sets; |
| 601 | } |
| 602 | |
| 603 | private boolean isSegmentIdSameAsNodeSegmentId(DeviceId deviceId, int sId) { |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 604 | int segmentId; |
| 605 | try { |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 606 | // IPv6 sid is not inserted. this part of the code is not used for now. |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 607 | segmentId = deviceConfig.getIPv4SegmentId(deviceId); |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 608 | } catch (DeviceConfigNotFoundException e) { |
| 609 | log.warn(e.getMessage() + " Aborting isSegmentIdSameAsNodeSegmentId."); |
| 610 | return false; |
| 611 | } |
| 612 | |
| 613 | return segmentId == sId; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 614 | } |
| 615 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 616 | protected List<Integer> getSegmentIdsTobePairedWithNeighborSet(Set<DeviceId> neighbors) { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 617 | |
Sho SHIMIZU | 6cfc02d | 2015-09-11 11:19:11 -0700 | [diff] [blame] | 618 | List<Integer> nsSegmentIds = new ArrayList<>(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 619 | |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 620 | // Always pair up with no edge label |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 621 | // If (neighbors.size() == 1) { |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 622 | nsSegmentIds.add(-1); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 623 | // } |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 624 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 625 | // Filter out SegmentIds matching with the |
| 626 | // nodes in the combo |
| 627 | for (Integer sId : allSegmentIds) { |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 628 | if (sId.equals(this.ipv4NodeSegmentId)) { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 629 | continue; |
| 630 | } |
| 631 | boolean filterOut = false; |
| 632 | // Check if the edge label being set is of |
| 633 | // any node in the Neighbor set |
| 634 | for (DeviceId deviceId : neighbors) { |
| 635 | if (isSegmentIdSameAsNodeSegmentId(deviceId, sId)) { |
| 636 | filterOut = true; |
| 637 | break; |
| 638 | } |
| 639 | } |
| 640 | if (!filterOut) { |
| 641 | nsSegmentIds.add(sId); |
| 642 | } |
| 643 | } |
| 644 | return nsSegmentIds; |
| 645 | } |
| 646 | |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 647 | /** |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 648 | * Creates hash groups from a set of NeighborSet given. |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 649 | * |
| 650 | * @param nsSet a set of NeighborSet |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 651 | * @param meta metadata passed into the creation of a Next Objective |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 652 | * @param isBos if BoS is set |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 653 | */ |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 654 | public void createGroupsFromNeighborsets(Set<NeighborSet> nsSet, |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 655 | TrafficSelector meta, |
| 656 | boolean isBos) { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 657 | for (NeighborSet ns : nsSet) { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 658 | int nextId = flowObjectiveService.allocateNextId(); |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 659 | NextObjective.Type type = NextObjective.Type.HASHED; |
| 660 | Set<DeviceId> neighbors = ns.getDeviceIds(); |
| 661 | // If Bos == False and MPLS-ECMP == false, we have |
| 662 | // to use simple group and we will pick a single neighbor. |
| 663 | if (!isBos && !srManager.getMplsEcmp()) { |
| 664 | type = NextObjective.Type.SIMPLE; |
| 665 | neighbors = Collections.singleton(ns.getFirstNeighbor()); |
| 666 | } |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 667 | NextObjective.Builder nextObjBuilder = DefaultNextObjective |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 668 | .builder() |
| 669 | .withId(nextId) |
| 670 | .withType(type) |
| 671 | .fromApp(appId); |
| 672 | // For each neighbor, we have to update the sent actions |
| 673 | for (DeviceId neighborId : neighbors) { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 674 | if (devicePortMap.get(neighborId) == null) { |
| 675 | log.warn("Neighbor {} is not in the port map yet for dev:{}", |
| 676 | neighborId, deviceId); |
sangho | 834e4b0 | 2015-05-01 09:38:25 -0700 | [diff] [blame] | 677 | return; |
Jon Hall | cbd1b39 | 2017-01-18 20:15:44 -0800 | [diff] [blame] | 678 | } else if (devicePortMap.get(neighborId).isEmpty()) { |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 679 | log.warn("There are no ports for " |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 680 | + "the Device {} in the port map yet", neighborId); |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 681 | return; |
sangho | 834e4b0 | 2015-05-01 09:38:25 -0700 | [diff] [blame] | 682 | } |
| 683 | |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 684 | MacAddress neighborMac; |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 685 | try { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 686 | neighborMac = deviceConfig.getDeviceMac(neighborId); |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 687 | } catch (DeviceConfigNotFoundException e) { |
| 688 | log.warn(e.getMessage() + " Aborting createGroupsFromNeighborsets."); |
| 689 | return; |
| 690 | } |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 691 | // For each port, we have to create a new treatment |
| 692 | Set<PortNumber> neighborPorts = devicePortMap.get(neighborId); |
| 693 | // In this case we are using a SIMPLE group. We randomly pick a port |
| 694 | if (!isBos && !srManager.getMplsEcmp()) { |
| 695 | int size = devicePortMap.get(neighborId).size(); |
| 696 | int index = RandomUtils.nextInt(0, size); |
| 697 | neighborPorts = Collections.singleton( |
| 698 | Iterables.get(devicePortMap.get(neighborId), index) |
| 699 | ); |
| 700 | } |
| 701 | for (PortNumber sp : neighborPorts) { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 702 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment |
| 703 | .builder(); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 704 | tBuilder.setEthDst(neighborMac) |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 705 | .setEthSrc(nodeMacAddr); |
| 706 | if (ns.getEdgeLabel() != NeighborSet.NO_EDGE_LABEL) { |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 707 | tBuilder.pushMpls() |
| 708 | .copyTtlOut() |
| 709 | .setMpls(MplsLabel.mplsLabel(ns.getEdgeLabel())); |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 710 | } |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 711 | tBuilder.setOutput(sp); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 712 | nextObjBuilder.addTreatment(tBuilder.build()); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 713 | } |
| 714 | } |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 715 | if (meta != null) { |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 716 | nextObjBuilder.withMeta(meta); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 717 | } |
Charles Chan | 216e3c8 | 2016-04-23 14:48:16 -0700 | [diff] [blame] | 718 | |
| 719 | ObjectiveContext context = new DefaultObjectiveContext( |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 720 | (objective) -> |
| 721 | log.debug("createGroupsFromNeighborsets installed NextObj {} on {}", |
Charles Chan | 216e3c8 | 2016-04-23 14:48:16 -0700 | [diff] [blame] | 722 | nextId, deviceId), |
| 723 | (objective, error) -> |
| 724 | log.warn("createGroupsFromNeighborsets failed to install NextObj {} on {}: {}", |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 725 | nextId, deviceId, error) |
| 726 | ); |
Charles Chan | 216e3c8 | 2016-04-23 14:48:16 -0700 | [diff] [blame] | 727 | NextObjective nextObj = nextObjBuilder.add(context); |
| 728 | log.debug("**createGroupsFromNeighborsets: Submited " |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 729 | + "next objective {} in device {}", |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 730 | nextId, deviceId); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 731 | flowObjectiveService.next(deviceId, nextObj); |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 732 | nsNextObjStore.put(new NeighborSetNextObjectiveStoreKey(deviceId, ns), |
| 733 | nextId); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 734 | } |
| 735 | } |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 736 | |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 737 | /** |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 738 | * Creates broadcast groups for all ports in the same subnet for |
| 739 | * all configured subnets. |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 740 | */ |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 741 | public void createGroupsFromVlanConfig() { |
| 742 | Set<Interface> interfaces = srManager.interfaceService.getInterfaces(); |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 743 | |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 744 | srManager.getVlanPortMap(deviceId).asMap().forEach((vlanId, ports) -> { |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 745 | createBcastGroupFromVlan(vlanId, ports); |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 746 | }); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 747 | } |
Charles Chan | 9f676b6 | 2015-10-29 14:58:10 -0700 | [diff] [blame] | 748 | |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 749 | /** |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 750 | * Creates a single broadcast group from a given vlan id and list of ports. |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 751 | * |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 752 | * @param vlanId vlan id |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 753 | * @param ports list of ports in the subnet |
| 754 | */ |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 755 | public void createBcastGroupFromVlan(VlanId vlanId, Collection<PortNumber> ports) { |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 756 | VlanNextObjectiveStoreKey key = new VlanNextObjectiveStoreKey(deviceId, vlanId); |
Charles Chan | 9f676b6 | 2015-10-29 14:58:10 -0700 | [diff] [blame] | 757 | |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 758 | if (vlanNextObjStore.containsKey(key)) { |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 759 | log.debug("Broadcast group for device {} and subnet {} exists", |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 760 | deviceId, vlanId); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 761 | return; |
| 762 | } |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 763 | |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 764 | TrafficSelector metadata = |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 765 | DefaultTrafficSelector.builder().matchVlanId(vlanId).build(); |
Charles Chan | c42e84e | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 766 | |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 767 | int nextId = flowObjectiveService.allocateNextId(); |
Charles Chan | c42e84e | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 768 | |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 769 | NextObjective.Builder nextObjBuilder = DefaultNextObjective |
| 770 | .builder().withId(nextId) |
| 771 | .withType(NextObjective.Type.BROADCAST).fromApp(appId) |
| 772 | .withMeta(metadata); |
Charles Chan | c42e84e | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 773 | |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 774 | ports.forEach(port -> { |
| 775 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 776 | if (toPopVlan(port, vlanId)) { |
| 777 | tBuilder.popVlan(); |
| 778 | } |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 779 | tBuilder.setOutput(port); |
| 780 | nextObjBuilder.addTreatment(tBuilder.build()); |
Charles Chan | c42e84e | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 781 | }); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 782 | |
| 783 | NextObjective nextObj = nextObjBuilder.add(); |
| 784 | flowObjectiveService.next(deviceId, nextObj); |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 785 | log.debug("createBcastGroupFromVlan: Submited next objective {} in device {}", |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 786 | nextId, deviceId); |
| 787 | |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 788 | vlanNextObjStore.put(key, nextId); |
Charles Chan | c42e84e | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 789 | } |
| 790 | |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 791 | /** |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 792 | * Determine if we should pop given vlan before sending packets to the given port. |
| 793 | * |
| 794 | * @param portNumber port number |
| 795 | * @param vlanId vlan id |
| 796 | * @return true if the vlan id is not contained in any vlanTagged config |
| 797 | */ |
| 798 | private boolean toPopVlan(PortNumber portNumber, VlanId vlanId) { |
| 799 | return srManager.interfaceService.getInterfacesByPort(new ConnectPoint(deviceId, portNumber)) |
| 800 | .stream().noneMatch(intf -> intf.vlanTagged().contains(vlanId)); |
| 801 | } |
| 802 | |
| 803 | /** |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 804 | * Create simple next objective for a single port. The treatments can include |
| 805 | * all outgoing actions that need to happen on the packet. |
| 806 | * |
| 807 | * @param portNum the outgoing port on the device |
| 808 | * @param treatment the actions to apply on the packets (should include outport) |
| 809 | * @param meta optional data to pass to the driver |
| 810 | */ |
| 811 | public void createGroupFromPort(PortNumber portNum, TrafficTreatment treatment, |
| 812 | TrafficSelector meta) { |
| 813 | int nextId = flowObjectiveService.allocateNextId(); |
| 814 | PortNextObjectiveStoreKey key = new PortNextObjectiveStoreKey( |
| 815 | deviceId, portNum, treatment); |
| 816 | |
| 817 | NextObjective.Builder nextObjBuilder = DefaultNextObjective |
| 818 | .builder().withId(nextId) |
| 819 | .withType(NextObjective.Type.SIMPLE) |
| 820 | .addTreatment(treatment) |
| 821 | .fromApp(appId) |
| 822 | .withMeta(meta); |
| 823 | |
| 824 | NextObjective nextObj = nextObjBuilder.add(); |
| 825 | flowObjectiveService.next(deviceId, nextObj); |
| 826 | log.debug("createGroupFromPort: Submited next objective {} in device {} " |
| 827 | + "for port {}", nextId, deviceId, portNum); |
| 828 | |
| 829 | portNextObjStore.put(key, nextId); |
| 830 | } |
| 831 | |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 832 | /** |
| 833 | * Removes groups for the next objective ID given. |
| 834 | * |
| 835 | * @param objectiveId next objective ID to remove |
| 836 | * @return true if succeeds, false otherwise |
| 837 | */ |
| 838 | public boolean removeGroup(int objectiveId) { |
| 839 | |
| 840 | if (nsNextObjStore.containsValue(objectiveId)) { |
| 841 | NextObjective.Builder nextObjBuilder = DefaultNextObjective |
| 842 | .builder().withId(objectiveId) |
| 843 | .withType(NextObjective.Type.HASHED).fromApp(appId); |
Charles Chan | 216e3c8 | 2016-04-23 14:48:16 -0700 | [diff] [blame] | 844 | ObjectiveContext context = new DefaultObjectiveContext( |
| 845 | (objective) -> log.debug("RemoveGroup removes NextObj {} on {}", |
| 846 | objectiveId, deviceId), |
| 847 | (objective, error) -> |
| 848 | log.warn("RemoveGroup failed to remove NextObj {} on {}: {}", |
| 849 | objectiveId, deviceId, error)); |
| 850 | NextObjective nextObjective = nextObjBuilder.remove(context); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 851 | log.info("**removeGroup: Submited " |
| 852 | + "next objective {} in device {}", |
| 853 | objectiveId, deviceId); |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 854 | flowObjectiveService.next(deviceId, nextObjective); |
| 855 | |
| 856 | for (Map.Entry<NeighborSetNextObjectiveStoreKey, Integer> entry: nsNextObjStore.entrySet()) { |
| 857 | if (entry.getValue().equals(objectiveId)) { |
| 858 | nsNextObjStore.remove(entry.getKey()); |
| 859 | break; |
| 860 | } |
| 861 | } |
sangho | 0b2b6d1 | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 862 | return true; |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | return false; |
| 866 | } |
Srikanth Vavilapalli | f3a8bc0 | 2015-05-22 13:47:31 -0700 | [diff] [blame] | 867 | |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 868 | /** |
| 869 | * Removes all groups from all next objective stores. |
| 870 | */ |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 871 | public void removeAllGroups() { |
| 872 | for (Map.Entry<NeighborSetNextObjectiveStoreKey, Integer> entry: |
| 873 | nsNextObjStore.entrySet()) { |
| 874 | removeGroup(entry.getValue()); |
| 875 | } |
| 876 | for (Map.Entry<PortNextObjectiveStoreKey, Integer> entry: |
| 877 | portNextObjStore.entrySet()) { |
| 878 | removeGroup(entry.getValue()); |
| 879 | } |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 880 | for (Map.Entry<VlanNextObjectiveStoreKey, Integer> entry: |
| 881 | vlanNextObjStore.entrySet()) { |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 882 | removeGroup(entry.getValue()); |
| 883 | } |
| 884 | // should probably clean local stores port-neighbor |
| 885 | } |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 886 | } |