Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
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 | |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableMap; |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 19 | import com.google.common.collect.Iterables; |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 20 | import com.google.common.collect.Lists; |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 21 | import com.google.common.collect.Sets; |
| 22 | |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 23 | import org.apache.commons.lang3.RandomUtils; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 24 | import org.onlab.packet.MacAddress; |
sangho | 32a5932 | 2015-02-17 12:07:41 -0800 | [diff] [blame] | 25 | import org.onlab.packet.MplsLabel; |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 26 | import org.onlab.packet.VlanId; |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 27 | import org.onlab.util.KryoNamespace; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 28 | import org.onosproject.core.ApplicationId; |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 29 | import org.onosproject.net.ConnectPoint; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 30 | import org.onosproject.net.DeviceId; |
| 31 | import org.onosproject.net.Link; |
| 32 | import org.onosproject.net.PortNumber; |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 33 | import org.onosproject.net.flow.DefaultTrafficSelector; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 34 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 35 | import org.onosproject.net.flow.TrafficSelector; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 36 | import org.onosproject.net.flow.TrafficTreatment; |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 37 | import org.onosproject.net.flowobjective.DefaultNextObjective; |
Charles Chan | 216e3c8 | 2016-04-23 14:48:16 -0700 | [diff] [blame] | 38 | import org.onosproject.net.flowobjective.DefaultObjectiveContext; |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 39 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
| 40 | import org.onosproject.net.flowobjective.NextObjective; |
Srikanth Vavilapalli | f3a8bc0 | 2015-05-22 13:47:31 -0700 | [diff] [blame] | 41 | import org.onosproject.net.flowobjective.ObjectiveContext; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 42 | import org.onosproject.net.link.LinkService; |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 43 | import org.onosproject.segmentrouting.DefaultRoutingHandler; |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 44 | import org.onosproject.segmentrouting.SegmentRoutingManager; |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 45 | import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException; |
| 46 | import org.onosproject.segmentrouting.config.DeviceProperties; |
Ruchi Sahota | ef0761c | 2019-01-28 01:08:18 +0000 | [diff] [blame^] | 47 | import org.onosproject.segmentrouting.config.DeviceConfiguration; |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 48 | import org.onosproject.segmentrouting.storekey.DestinationSetNextObjectiveStoreKey; |
Charles Chan | d299036 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 49 | import org.onosproject.segmentrouting.storekey.PortNextObjectiveStoreKey; |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 50 | import org.onosproject.segmentrouting.storekey.VlanNextObjectiveStoreKey; |
Ruchi Sahota | ef0761c | 2019-01-28 01:08:18 +0000 | [diff] [blame^] | 51 | import org.onosproject.segmentrouting.storekey.MacVlanNextObjectiveStoreKey; |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 52 | import org.onosproject.store.service.EventuallyConsistentMap; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 53 | import org.slf4j.Logger; |
| 54 | |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 55 | import java.net.URI; |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 56 | import java.util.Collection; |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 57 | import java.util.Collections; |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 58 | import java.util.HashMap; |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 59 | import java.util.HashSet; |
| 60 | import java.util.List; |
| 61 | import java.util.Map; |
| 62 | import java.util.Set; |
| 63 | import java.util.concurrent.ConcurrentHashMap; |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 64 | import java.util.concurrent.ScheduledExecutorService; |
| 65 | import java.util.concurrent.TimeUnit; |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 66 | import java.util.stream.Collectors; |
| 67 | |
| 68 | import static com.google.common.base.Preconditions.checkNotNull; |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 69 | import static java.util.concurrent.Executors.newScheduledThreadPool; |
| 70 | import static org.onlab.util.Tools.groupedThreads; |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 71 | import static org.slf4j.LoggerFactory.getLogger; |
| 72 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 73 | /** |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 74 | * Default ECMP group handler creation module. This component creates a set of |
| 75 | * ECMP groups for every neighbor that this device is connected to based on |
| 76 | * whether the current device is an edge device or a transit device. |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 77 | */ |
| 78 | public class DefaultGroupHandler { |
Ray Milkey | 9c9cde4 | 2018-01-12 14:22:06 -0800 | [diff] [blame] | 79 | private static final Logger log = getLogger(DefaultGroupHandler.class); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 80 | |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 81 | private static final long VERIFY_INTERVAL = 30; // secs |
| 82 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 83 | protected final DeviceId deviceId; |
| 84 | protected final ApplicationId appId; |
| 85 | protected final DeviceProperties deviceConfig; |
| 86 | protected final List<Integer> allSegmentIds; |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 87 | protected int ipv4NodeSegmentId = -1; |
| 88 | protected int ipv6NodeSegmentId = -1; |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 89 | protected boolean isEdgeRouter = false; |
| 90 | protected MacAddress nodeMacAddr = null; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 91 | protected LinkService linkService; |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 92 | protected FlowObjectiveService flowObjectiveService; |
Ruchi Sahota | ef0761c | 2019-01-28 01:08:18 +0000 | [diff] [blame^] | 93 | private DeviceConfiguration config; |
| 94 | |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 95 | /** |
| 96 | * local store for neighbor-device-ids and the set of ports on this device |
| 97 | * that connect to the same neighbor. |
| 98 | */ |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 99 | protected ConcurrentHashMap<DeviceId, Set<PortNumber>> devicePortMap = |
| 100 | new ConcurrentHashMap<>(); |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 101 | /** |
| 102 | * local store for ports on this device connected to neighbor-device-id. |
| 103 | */ |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 104 | protected ConcurrentHashMap<PortNumber, DeviceId> portDeviceMap = |
| 105 | new ConcurrentHashMap<>(); |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 106 | |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 107 | // distributed store for (device+destination-set) mapped to next-id and neighbors |
| 108 | protected EventuallyConsistentMap<DestinationSetNextObjectiveStoreKey, NextNeighbors> |
| 109 | dsNextObjStore = null; |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 110 | // distributed store for (device+subnet-ip-prefix) mapped to next-id |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 111 | protected EventuallyConsistentMap<VlanNextObjectiveStoreKey, Integer> |
| 112 | vlanNextObjStore = null; |
Ruchi Sahota | ef0761c | 2019-01-28 01:08:18 +0000 | [diff] [blame^] | 113 | // distributed store for (device+mac+vlan+treatment) mapped to next-id |
| 114 | protected EventuallyConsistentMap<MacVlanNextObjectiveStoreKey, Integer> |
| 115 | macVlanNextObjStore = null; |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 116 | // distributed store for (device+port+treatment) mapped to next-id |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 117 | protected EventuallyConsistentMap<PortNextObjectiveStoreKey, Integer> |
| 118 | portNextObjStore = null; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 119 | private SegmentRoutingManager srManager; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 120 | |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 121 | private ScheduledExecutorService executorService |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 122 | = newScheduledThreadPool(1, groupedThreads("bktCorrector", "bktC-%d", log)); |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 123 | |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 124 | protected KryoNamespace.Builder kryo = new KryoNamespace.Builder() |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 125 | .register(URI.class).register(HashSet.class) |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 126 | .register(DeviceId.class).register(PortNumber.class) |
| 127 | .register(DestinationSet.class).register(PolicyGroupIdentifier.class) |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 128 | .register(PolicyGroupParams.class) |
| 129 | .register(GroupBucketIdentifier.class) |
| 130 | .register(GroupBucketIdentifier.BucketOutputType.class); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 131 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 132 | protected DefaultGroupHandler(DeviceId deviceId, ApplicationId appId, |
| 133 | DeviceProperties config, |
| 134 | LinkService linkService, |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 135 | FlowObjectiveService flowObjService, |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 136 | SegmentRoutingManager srManager) { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 137 | this.deviceId = checkNotNull(deviceId); |
| 138 | this.appId = checkNotNull(appId); |
| 139 | this.deviceConfig = checkNotNull(config); |
| 140 | this.linkService = checkNotNull(linkService); |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 141 | this.allSegmentIds = checkNotNull(config.getAllDeviceSegmentIds()); |
| 142 | try { |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 143 | this.ipv4NodeSegmentId = config.getIPv4SegmentId(deviceId); |
| 144 | this.ipv6NodeSegmentId = config.getIPv6SegmentId(deviceId); |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 145 | this.isEdgeRouter = config.isEdgeDevice(deviceId); |
| 146 | this.nodeMacAddr = checkNotNull(config.getDeviceMac(deviceId)); |
| 147 | } catch (DeviceConfigNotFoundException e) { |
| 148 | log.warn(e.getMessage() |
| 149 | + " Skipping value assignment in DefaultGroupHandler"); |
| 150 | } |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 151 | this.flowObjectiveService = flowObjService; |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 152 | this.dsNextObjStore = srManager.dsNextObjStore(); |
Ray Milkey | e4afdb5 | 2017-04-05 09:42:04 -0700 | [diff] [blame] | 153 | this.vlanNextObjStore = srManager.vlanNextObjStore(); |
| 154 | this.portNextObjStore = srManager.portNextObjStore(); |
Ruchi Sahota | ef0761c | 2019-01-28 01:08:18 +0000 | [diff] [blame^] | 155 | this.macVlanNextObjStore = srManager.macVlanNextObjStore(); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 156 | this.srManager = srManager; |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 157 | executorService.scheduleWithFixedDelay(new BucketCorrector(), 10, |
| 158 | VERIFY_INTERVAL, |
| 159 | TimeUnit.SECONDS); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 160 | populateNeighborMaps(); |
| 161 | } |
| 162 | |
| 163 | /** |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 164 | * Gracefully shuts down a groupHandler. Typically called when the handler is |
| 165 | * no longer needed. |
| 166 | */ |
| 167 | public void shutdown() { |
| 168 | executorService.shutdown(); |
| 169 | } |
| 170 | |
| 171 | /** |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 172 | * Creates a group handler object. |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 173 | * |
| 174 | * @param deviceId device identifier |
| 175 | * @param appId application identifier |
| 176 | * @param config interface to retrieve the device properties |
| 177 | * @param linkService link service object |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 178 | * @param flowObjService flow objective service object |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 179 | * @param srManager segment routing manager |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 180 | * @throws DeviceConfigNotFoundException if the device configuration is not found |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 181 | * @return default group handler type |
| 182 | */ |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 183 | public static DefaultGroupHandler createGroupHandler( |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 184 | DeviceId deviceId, |
| 185 | ApplicationId appId, |
| 186 | DeviceProperties config, |
| 187 | LinkService linkService, |
| 188 | FlowObjectiveService flowObjService, |
| 189 | SegmentRoutingManager srManager) |
| 190 | throws DeviceConfigNotFoundException { |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 191 | return new DefaultGroupHandler(deviceId, appId, config, |
| 192 | linkService, |
| 193 | flowObjService, |
| 194 | srManager); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | /** |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 198 | * Updates local stores for link-src-device/port to neighbor (link-dst) for |
| 199 | * link that has come up. |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 200 | * |
| 201 | * @param link the infrastructure link |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 202 | */ |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 203 | public void portUpForLink(Link link) { |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 204 | if (!link.src().deviceId().equals(deviceId)) { |
| 205 | log.warn("linkUp: deviceId{} doesn't match with link src {}", |
| 206 | deviceId, link.src().deviceId()); |
| 207 | return; |
| 208 | } |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 209 | |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 210 | log.info("* portUpForLink: Device {} linkUp at local port {} to " |
| 211 | + "neighbor {}", deviceId, link.src().port(), link.dst().deviceId()); |
| 212 | // ensure local state is updated even if linkup is aborted later on |
| 213 | addNeighborAtPort(link.dst().deviceId(), |
| 214 | link.src().port()); |
| 215 | } |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 216 | |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 217 | /** |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 218 | * Updates local stores for link-src-device/port to neighbor (link-dst) for |
| 219 | * link that has gone down. |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 220 | * |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 221 | * @param link the infrastructure link |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 222 | */ |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 223 | public void portDownForLink(Link link) { |
| 224 | PortNumber port = link.src().port(); |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 225 | if (portDeviceMap.get(port) == null) { |
| 226 | log.warn("portDown: unknown port"); |
| 227 | return; |
| 228 | } |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 229 | |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 230 | log.debug("Device {} portDown {} to neighbor {}", deviceId, port, |
| 231 | portDeviceMap.get(port)); |
| 232 | devicePortMap.get(portDeviceMap.get(port)).remove(port); |
| 233 | portDeviceMap.remove(port); |
| 234 | } |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 235 | |
| 236 | /** |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 237 | * Cleans up local stores for removed neighbor device. |
| 238 | * |
| 239 | * @param neighborId the device identifier for the neighbor device |
| 240 | */ |
| 241 | public void cleanUpForNeighborDown(DeviceId neighborId) { |
| 242 | Set<PortNumber> ports = devicePortMap.remove(neighborId); |
| 243 | if (ports != null) { |
| 244 | ports.forEach(p -> portDeviceMap.remove(p)); |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | /** |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 249 | * Checks all groups in the src-device of link for neighbor sets that include |
| 250 | * the dst-device of link, and edits the hash groups according to link up |
| 251 | * or down. Should only be called by the master instance of the src-switch |
| 252 | * of link. Typically used when there are no route-path changes due to the |
| 253 | * link up or down, as the ECMPspg does not change. |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 254 | * |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 255 | * @param link the infrastructure link that has gone down or come up |
| 256 | * @param linkDown true if link has gone down |
| 257 | * @param firstTime true if link has come up for the first time i.e a link |
| 258 | * not seen-before |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 259 | */ |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 260 | public void retryHash(Link link, boolean linkDown, boolean firstTime) { |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 261 | MacAddress neighborMac; |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 262 | try { |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 263 | neighborMac = deviceConfig.getDeviceMac(link.dst().deviceId()); |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 264 | } catch (DeviceConfigNotFoundException e) { |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 265 | log.warn(e.getMessage() + " Aborting retryHash."); |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 266 | return; |
| 267 | } |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 268 | // find all the destinationSets related to link |
| 269 | Set<DestinationSetNextObjectiveStoreKey> dsKeySet = dsNextObjStore.entrySet() |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 270 | .stream() |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 271 | .filter(entry -> entry.getKey().deviceId().equals(deviceId)) |
Pier Luigi | 63edd93 | 2018-01-14 21:56:11 +0100 | [diff] [blame] | 272 | // Filter out PW transit groups or include them if MPLS ECMP is supported |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 273 | .filter(entry -> !entry.getKey().destinationSet().notBos() || |
| 274 | (entry.getKey().destinationSet().notBos() && srManager.getMplsEcmp())) |
| 275 | // Filter out simple SWAP groups or include them if MPLS ECMP is supported |
| 276 | .filter(entry -> !entry.getKey().destinationSet().swap() || |
| 277 | (entry.getKey().destinationSet().swap() && srManager.getMplsEcmp())) |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 278 | .filter(entry -> entry.getValue().containsNextHop(link.dst().deviceId())) |
| 279 | .map(entry -> entry.getKey()) |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 280 | .collect(Collectors.toSet()); |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 281 | |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 282 | log.debug("retryHash: dsNextObjStore contents for linkSrc {} -> linkDst {}: {}", |
| 283 | deviceId, link.dst().deviceId(), dsKeySet); |
| 284 | |
| 285 | for (DestinationSetNextObjectiveStoreKey dsKey : dsKeySet) { |
| 286 | NextNeighbors nextHops = dsNextObjStore.get(dsKey); |
| 287 | if (nextHops == null) { |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 288 | log.warn("retryHash in device {}, but global store has no record " |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 289 | + "for dsKey:{}", deviceId, dsKey); |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 290 | continue; |
| 291 | } |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 292 | int nextId = nextHops.nextId(); |
| 293 | Set<DeviceId> dstSet = nextHops.getDstForNextHop(link.dst().deviceId()); |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 294 | if (!linkDown) { |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 295 | List<PortLabel> pl = Lists.newArrayList(); |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 296 | if (firstTime) { |
| 297 | // some links may have come up before the next-objective was created |
| 298 | // we take this opportunity to ensure other ports to same next-hop-dst |
| 299 | // are part of the hash group (see CORD-1180). Duplicate additions |
| 300 | // to the same hash group are avoided by the driver. |
| 301 | for (PortNumber p : devicePortMap.get(link.dst().deviceId())) { |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 302 | dstSet.forEach(dst -> { |
| 303 | int edgeLabel = dsKey.destinationSet().getEdgeLabel(dst); |
Charles Chan | e0260e1 | 2018-08-22 17:56:47 -0700 | [diff] [blame] | 304 | pl.add(new PortLabel(p, edgeLabel, popVlanInHashGroup(dsKey.destinationSet()))); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 305 | }); |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 306 | } |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 307 | addToHashedNextObjective(pl, neighborMac, nextId); |
| 308 | } else { |
| 309 | // handle only the port that came up |
| 310 | dstSet.forEach(dst -> { |
| 311 | int edgeLabel = dsKey.destinationSet().getEdgeLabel(dst); |
Charles Chan | e0260e1 | 2018-08-22 17:56:47 -0700 | [diff] [blame] | 312 | pl.add(new PortLabel(link.src().port(), edgeLabel, popVlanInHashGroup(dsKey.destinationSet()))); |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 313 | }); |
| 314 | addToHashedNextObjective(pl, neighborMac, nextId); |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 315 | } |
| 316 | } else { |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 317 | // linkdown |
| 318 | List<PortLabel> pl = Lists.newArrayList(); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 319 | dstSet.forEach(dst -> { |
| 320 | int edgeLabel = dsKey.destinationSet().getEdgeLabel(dst); |
Charles Chan | e0260e1 | 2018-08-22 17:56:47 -0700 | [diff] [blame] | 321 | pl.add(new PortLabel(link.src().port(), edgeLabel, popVlanInHashGroup(dsKey.destinationSet()))); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 322 | }); |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 323 | removeFromHashedNextObjective(pl, neighborMac, nextId); |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 324 | } |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 325 | } |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 326 | } |
| 327 | |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 328 | /** |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 329 | * Utility class for associating output ports and the corresponding MPLS |
| 330 | * labels to push. In dual-homing, there are different labels to push |
| 331 | * corresponding to the destination switches in an edge-pair. If both |
| 332 | * destinations are reachable via the same spine, then the output-port to |
| 333 | * the spine will be associated with two labels i.e. there will be two |
| 334 | * PortLabel objects for the same port but with different labels. |
| 335 | */ |
| 336 | private class PortLabel { |
| 337 | PortNumber port; |
| 338 | int edgeLabel; |
Charles Chan | e0260e1 | 2018-08-22 17:56:47 -0700 | [diff] [blame] | 339 | boolean popVlan; |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 340 | |
Charles Chan | e0260e1 | 2018-08-22 17:56:47 -0700 | [diff] [blame] | 341 | PortLabel(PortNumber port, int edgeLabel, boolean popVlan) { |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 342 | this.port = port; |
| 343 | this.edgeLabel = edgeLabel; |
Charles Chan | e0260e1 | 2018-08-22 17:56:47 -0700 | [diff] [blame] | 344 | this.popVlan = popVlan; |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | @Override |
| 348 | public String toString() { |
Charles Chan | e0260e1 | 2018-08-22 17:56:47 -0700 | [diff] [blame] | 349 | return port.toString() + "/" + String.valueOf(edgeLabel) + (popVlan ? "/popVlan" : ""); |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 350 | } |
| 351 | } |
| 352 | |
| 353 | /** |
| 354 | * Makes a call to the FlowObjective service to add buckets to |
| 355 | * a hashed group. User must ensure that all the ports & labels are meant |
| 356 | * same neighbor (ie. dstMac). |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 357 | * |
Pier Luigi | 63edd93 | 2018-01-14 21:56:11 +0100 | [diff] [blame] | 358 | * @param portLabels a collection of port & label combinations to add |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 359 | * to the hash group identified by the nextId |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 360 | * @param dstMac destination mac address of next-hop |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 361 | * @param nextId id for next-objective to which buckets will be added |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 362 | * |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 363 | */ |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 364 | private void addToHashedNextObjective(Collection<PortLabel> portLabels, |
| 365 | MacAddress dstMac, Integer nextId) { |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 366 | // setup metadata to pass to nextObjective - indicate the vlan on egress |
| 367 | // if needed by the switch pipeline. Since hashed next-hops are always to |
| 368 | // other neighboring routers, there is no subnet assigned on those ports. |
| 369 | TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder(); |
Saurav Das | 09c2c4d | 2018-08-13 15:34:26 -0700 | [diff] [blame] | 370 | metabuilder.matchVlanId(srManager.getDefaultInternalVlan()); |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 371 | NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder() |
| 372 | .withId(nextId) |
| 373 | .withType(NextObjective.Type.HASHED) |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 374 | .withMeta(metabuilder.build()) |
| 375 | .fromApp(appId); |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 376 | // Create the new buckets to be updated |
| 377 | portLabels.forEach(pl -> { |
| 378 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 379 | tBuilder.setOutput(pl.port) |
| 380 | .setEthDst(dstMac) |
| 381 | .setEthSrc(nodeMacAddr); |
Charles Chan | e0260e1 | 2018-08-22 17:56:47 -0700 | [diff] [blame] | 382 | if (pl.popVlan) { |
| 383 | tBuilder.popVlan(); |
| 384 | } |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 385 | if (pl.edgeLabel != DestinationSet.NO_EDGE_LABEL) { |
| 386 | tBuilder.pushMpls() |
| 387 | .copyTtlOut() |
| 388 | .setMpls(MplsLabel.mplsLabel(pl.edgeLabel)); |
| 389 | } |
| 390 | nextObjBuilder.addTreatment(tBuilder.build()); |
| 391 | }); |
| 392 | |
| 393 | log.debug("addToHash in device {}: Adding Bucket with port/label {} " |
| 394 | + "to nextId {}", deviceId, portLabels, nextId); |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 395 | |
| 396 | ObjectiveContext context = new DefaultObjectiveContext( |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 397 | (objective) -> log.debug("addToHash port/label {} addedTo " |
| 398 | + "NextObj {} on {}", portLabels, nextId, deviceId), |
Charles Chan | 55b806f | 2018-08-23 14:30:33 -0700 | [diff] [blame] | 399 | (objective, error) -> { |
| 400 | log.warn("addToHash failed to add port/label {} to NextObj {} on {}: {}", |
| 401 | portLabels, nextId, deviceId, error); |
| 402 | srManager.invalidateNextObj(objective.id()); |
| 403 | }); |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 404 | NextObjective nextObjective = nextObjBuilder.addToExisting(context); |
| 405 | flowObjectiveService.next(deviceId, nextObjective); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | /** |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 409 | * Makes a call to the FlowObjective service to remove buckets from |
| 410 | * a hash group. User must ensure that all the ports & labels are meant |
| 411 | * same neighbor (ie. dstMac). |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 412 | * |
Pier Luigi | 63edd93 | 2018-01-14 21:56:11 +0100 | [diff] [blame] | 413 | * @param portLabels a collection of port & label combinations to remove |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 414 | * from the hash group identified by the nextId |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 415 | * @param dstMac destination mac address of next-hop |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 416 | * @param nextId id for next-objective from which buckets will be removed |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 417 | */ |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 418 | private void removeFromHashedNextObjective(Collection<PortLabel> portLabels, |
| 419 | MacAddress dstMac, Integer nextId) { |
Charles Chan | 67ef255 | 2018-08-30 19:49:23 -0700 | [diff] [blame] | 420 | TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder(); |
| 421 | metabuilder.matchVlanId(srManager.getDefaultInternalVlan()); |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 422 | NextObjective.Builder nextObjBuilder = DefaultNextObjective |
| 423 | .builder() |
| 424 | .withType(NextObjective.Type.HASHED) //same as original |
Charles Chan | 67ef255 | 2018-08-30 19:49:23 -0700 | [diff] [blame] | 425 | .withMeta(metabuilder.build()) |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 426 | .withId(nextId) |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 427 | .fromApp(appId); |
| 428 | // Create the buckets to be removed |
| 429 | portLabels.forEach(pl -> { |
| 430 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 431 | tBuilder.setOutput(pl.port) |
| 432 | .setEthDst(dstMac) |
| 433 | .setEthSrc(nodeMacAddr); |
Charles Chan | e0260e1 | 2018-08-22 17:56:47 -0700 | [diff] [blame] | 434 | if (pl.popVlan) { |
| 435 | tBuilder.popVlan(); |
| 436 | } |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 437 | if (pl.edgeLabel != DestinationSet.NO_EDGE_LABEL) { |
| 438 | tBuilder.pushMpls() |
| 439 | .copyTtlOut() |
| 440 | .setMpls(MplsLabel.mplsLabel(pl.edgeLabel)); |
| 441 | } |
| 442 | nextObjBuilder.addTreatment(tBuilder.build()); |
| 443 | }); |
| 444 | log.debug("removeFromHash in device {}: Removing Bucket with port/label" |
| 445 | + " {} from nextId {}", deviceId, portLabels, nextId); |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 446 | |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 447 | ObjectiveContext context = new DefaultObjectiveContext( |
| 448 | (objective) -> log.debug("port/label {} removedFrom NextObj" |
| 449 | + " {} on {}", portLabels, nextId, deviceId), |
Charles Chan | 55b806f | 2018-08-23 14:30:33 -0700 | [diff] [blame] | 450 | (objective, error) -> { |
| 451 | log.warn("port/label {} failed to removeFrom NextObj {} on {}: {}", |
| 452 | portLabels, nextId, deviceId, error); |
| 453 | srManager.invalidateNextObj(objective.id()); |
| 454 | }); |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 455 | NextObjective nextObjective = nextObjBuilder.removeFromExisting(context); |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 456 | flowObjectiveService.next(deviceId, nextObjective); |
| 457 | } |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 458 | |
| 459 | /** |
| 460 | * Checks all the hash-groups in the target-switch meant for the destination |
| 461 | * switch, and either adds or removes buckets to make the neighbor-set |
| 462 | * match the given next-hops. Typically called by the master instance of the |
| 463 | * destination switch, which may be different from the master instance of the |
| 464 | * target switch where hash-group changes are made. |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 465 | * |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 466 | * @param targetSw the switch in which the hash groups will be edited |
| 467 | * @param nextHops the current next hops for the target switch to reach |
| 468 | * the dest sw |
| 469 | * @param destSw the destination switch |
| 470 | * @param revoke true if hash groups need to remove buckets from the |
| 471 | * the groups to match the current next hops |
| 472 | * @return true if calls are made to edit buckets, or if no edits are required |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 473 | */ |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 474 | public boolean fixHashGroups(DeviceId targetSw, Set<DeviceId> nextHops, |
| 475 | DeviceId destSw, boolean revoke) { |
| 476 | // temporary storage of keys to be updated |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 477 | Map<DestinationSetNextObjectiveStoreKey, Set<DeviceId>> tempStore = |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 478 | new HashMap<>(); |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 479 | boolean foundNextObjective = false, success = true; |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 480 | |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 481 | // retrieve hash-groups meant for destSw, which have destinationSets |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 482 | // with different neighbors than the given next-hops |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 483 | for (DestinationSetNextObjectiveStoreKey dskey : dsNextObjStore.keySet()) { |
| 484 | if (!dskey.deviceId().equals(targetSw) || |
| 485 | !dskey.destinationSet().getDestinationSwitches().contains(destSw)) { |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 486 | continue; |
| 487 | } |
| 488 | foundNextObjective = true; |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 489 | NextNeighbors nhops = dsNextObjStore.get(dskey); |
| 490 | Set<DeviceId> currNeighbors = nhops.nextHops(destSw); |
| 491 | int edgeLabel = dskey.destinationSet().getEdgeLabel(destSw); |
| 492 | Integer nextId = nhops.nextId(); |
Saurav Das | e0d4c87 | 2018-03-05 14:37:16 -0800 | [diff] [blame] | 493 | if (currNeighbors == null || nextHops == null) { |
| 494 | log.warn("fixing hash groups but found currNeighbors:{} or nextHops:{}" |
| 495 | + " in targetSw:{} for dstSw:{}", currNeighbors, |
| 496 | nextHops, targetSw, destSw); |
| 497 | success &= false; |
| 498 | continue; |
| 499 | } |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 500 | |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 501 | // some store elements may not be hashed next-objectives - ignore them |
| 502 | if (isSimpleNextObjective(dskey)) { |
| 503 | log.debug("Ignoring {} of SIMPLE nextObj for targetSw:{}" |
| 504 | + " -> dstSw:{} with current nextHops:{} to new" |
| 505 | + " nextHops: {} in nextId:{}", |
| 506 | (revoke) ? "removal" : "addition", targetSw, destSw, |
| 507 | currNeighbors, nextHops, nextId); |
Saurav Das | e0d4c87 | 2018-03-05 14:37:16 -0800 | [diff] [blame] | 508 | if ((revoke && !nextHops.isEmpty()) |
| 509 | || (!revoke && !nextHops.equals(currNeighbors))) { |
Saurav Das | 137f27f | 2018-06-11 17:02:31 -0700 | [diff] [blame] | 510 | log.debug("Simple next objective cannot be edited to " |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 511 | + "move from {} to {}", currNeighbors, nextHops); |
| 512 | } |
| 513 | continue; |
| 514 | } |
| 515 | |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 516 | Set<DeviceId> diff; |
| 517 | if (revoke) { |
| 518 | diff = Sets.difference(currNeighbors, nextHops); |
| 519 | log.debug("targetSw:{} -> dstSw:{} in nextId:{} has current next " |
| 520 | + "hops:{} ..removing {}", targetSw, destSw, nextId, |
| 521 | currNeighbors, diff); |
| 522 | } else { |
| 523 | diff = Sets.difference(nextHops, currNeighbors); |
| 524 | log.debug("targetSw:{} -> dstSw:{} in nextId:{} has current next " |
| 525 | + "hops:{} ..adding {}", targetSw, destSw, nextId, |
| 526 | currNeighbors, diff); |
| 527 | } |
Charles Chan | e0260e1 | 2018-08-22 17:56:47 -0700 | [diff] [blame] | 528 | boolean suc = updateAllPortsToNextHop(diff, edgeLabel, nextId, popVlanInHashGroup(dskey.destinationSet()), |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 529 | revoke); |
| 530 | if (suc) { |
| 531 | // to update neighbor set with changes made |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 532 | if (revoke) { |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 533 | tempStore.put(dskey, Sets.difference(currNeighbors, diff)); |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 534 | } else { |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 535 | tempStore.put(dskey, Sets.union(currNeighbors, diff)); |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 536 | } |
sangho | 834e4b0 | 2015-05-01 09:38:25 -0700 | [diff] [blame] | 537 | } |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 538 | success &= suc; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 539 | } |
| 540 | |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 541 | if (!foundNextObjective) { |
| 542 | log.debug("Cannot find any nextObjectives for route targetSw:{} " |
| 543 | + "-> dstSw:{}", targetSw, destSw); |
| 544 | return true; // nothing to do, return true so ECMPspg is updated |
| 545 | } |
| 546 | |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 547 | // update the dsNextObjectiveStore with new destinationSet to nextId mappings |
| 548 | for (DestinationSetNextObjectiveStoreKey key : tempStore.keySet()) { |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 549 | NextNeighbors currentNextHops = dsNextObjStore.get(key); |
| 550 | if (currentNextHops == null) { |
| 551 | log.warn("fixHashGroups could not update global store in " |
| 552 | + "device {} .. missing nextNeighbors for key {}", |
| 553 | deviceId, key); |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 554 | continue; |
| 555 | } |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 556 | Set<DeviceId> newNeighbors = new HashSet<>(); |
| 557 | newNeighbors.addAll(tempStore.get(key)); |
| 558 | Map<DeviceId, Set<DeviceId>> oldDstNextHops = |
| 559 | ImmutableMap.copyOf(currentNextHops.dstNextHops()); |
| 560 | currentNextHops.dstNextHops().put(destSw, newNeighbors); //local change |
| 561 | log.debug("Updating nsNextObjStore target:{} -> dst:{} in key:{} nextId:{}", |
| 562 | targetSw, destSw, key, currentNextHops.nextId()); |
| 563 | log.debug("Old dstNextHops: {}", oldDstNextHops); |
| 564 | log.debug("New dstNextHops: {}", currentNextHops.dstNextHops()); |
| 565 | // update global store |
| 566 | dsNextObjStore.put(key, |
| 567 | new NextNeighbors(currentNextHops.dstNextHops(), |
| 568 | currentNextHops.nextId())); |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 569 | } |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 570 | |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 571 | // even if one fails and others succeed, return false so ECMPspg not updated |
| 572 | return success; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 573 | } |
| 574 | |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 575 | /** |
| 576 | * Updates the DestinationSetNextObjectiveStore with any per-destination nexthops |
| 577 | * that are not already in the store for the given DestinationSet. Note that |
| 578 | * this method does not remove existing next hops for the destinations in the |
| 579 | * DestinationSet. |
| 580 | * |
| 581 | * @param ds the DestinationSet for which the next hops need to be updated |
| 582 | * @param newDstNextHops a map of per-destination next hops to update the |
| 583 | * destinationSet with |
| 584 | * @return true if successful in updating all next hops |
| 585 | */ |
| 586 | private boolean updateNextHops(DestinationSet ds, |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 587 | Map<DeviceId, Set<DeviceId>> newDstNextHops) { |
| 588 | DestinationSetNextObjectiveStoreKey key = |
| 589 | new DestinationSetNextObjectiveStoreKey(deviceId, ds); |
| 590 | NextNeighbors currNext = dsNextObjStore.get(key); |
| 591 | Map<DeviceId, Set<DeviceId>> currDstNextHops = currNext.dstNextHops(); |
| 592 | |
| 593 | // add newDstNextHops to currDstNextHops for each dst |
| 594 | boolean success = true; |
| 595 | for (DeviceId dstSw : ds.getDestinationSwitches()) { |
| 596 | Set<DeviceId> currNhops = currDstNextHops.get(dstSw); |
| 597 | Set<DeviceId> newNhops = newDstNextHops.get(dstSw); |
| 598 | currNhops = (currNhops == null) ? Sets.newHashSet() : currNhops; |
| 599 | newNhops = (newNhops == null) ? Sets.newHashSet() : newNhops; |
| 600 | int edgeLabel = ds.getEdgeLabel(dstSw); |
| 601 | int nextId = currNext.nextId(); |
| 602 | |
| 603 | // new next hops should be added |
| 604 | boolean suc = updateAllPortsToNextHop(Sets.difference(newNhops, currNhops), |
Charles Chan | e0260e1 | 2018-08-22 17:56:47 -0700 | [diff] [blame] | 605 | edgeLabel, nextId, popVlanInHashGroup(key.destinationSet()), false); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 606 | if (suc) { |
| 607 | currNhops.addAll(newNhops); |
| 608 | currDstNextHops.put(dstSw, currNhops); // this is only a local change |
| 609 | } |
| 610 | success &= suc; |
| 611 | } |
| 612 | |
| 613 | if (success) { |
| 614 | // update global store |
| 615 | dsNextObjStore.put(key, new NextNeighbors(currDstNextHops, |
| 616 | currNext.nextId())); |
| 617 | log.debug("Updated device:{} ds:{} new next-hops: {}", deviceId, ds, |
| 618 | dsNextObjStore.get(key)); |
| 619 | } |
| 620 | return success; |
| 621 | } |
| 622 | |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 623 | /** |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 624 | * Adds or removes buckets for all ports to a set of neighbor devices. Caller |
| 625 | * needs to ensure that the given neighbors are all next hops towards the |
| 626 | * same destination (represented by the given edgeLabel). |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 627 | * |
| 628 | * @param neighbors set of neighbor device ids |
| 629 | * @param edgeLabel MPLS label to use in buckets |
| 630 | * @param nextId the nextObjective to change |
Charles Chan | e0260e1 | 2018-08-22 17:56:47 -0700 | [diff] [blame] | 631 | * @param popVlan this hash group bucket shuold includes a popVlan action |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 632 | * @param revoke true if buckets need to be removed, false if they need to |
| 633 | * be added |
| 634 | * @return true if successful in adding or removing buckets for all ports |
| 635 | * to the neighbors |
| 636 | */ |
| 637 | private boolean updateAllPortsToNextHop(Set<DeviceId> neighbors, int edgeLabel, |
Charles Chan | e0260e1 | 2018-08-22 17:56:47 -0700 | [diff] [blame] | 638 | int nextId, boolean popVlan, boolean revoke) { |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 639 | for (DeviceId neighbor : neighbors) { |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 640 | MacAddress neighborMac; |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 641 | try { |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 642 | neighborMac = deviceConfig.getDeviceMac(neighbor); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 643 | } catch (DeviceConfigNotFoundException e) { |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 644 | log.warn(e.getMessage() + " Aborting updateAllPortsToNextHop" |
| 645 | + " for nextId:" + nextId); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 646 | return false; |
| 647 | } |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 648 | Collection<PortNumber> portsToNeighbor = devicePortMap.get(neighbor); |
| 649 | if (portsToNeighbor == null || portsToNeighbor.isEmpty()) { |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 650 | log.warn("No ports found in dev:{} for neighbor:{} .. cannot " |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 651 | + "updateAllPortsToNextHop for nextId: {}", |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 652 | deviceId, neighbor, nextId); |
| 653 | return false; |
| 654 | } |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 655 | List<PortLabel> pl = Lists.newArrayList(); |
Charles Chan | e0260e1 | 2018-08-22 17:56:47 -0700 | [diff] [blame] | 656 | portsToNeighbor.forEach(p -> pl.add(new PortLabel(p, edgeLabel, popVlan))); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 657 | if (revoke) { |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 658 | log.debug("updateAllPortsToNextHops in device {}: Removing Bucket(s) " |
| 659 | + "with Port/Label:{} to next object id {}", |
| 660 | deviceId, pl, nextId); |
| 661 | removeFromHashedNextObjective(pl, neighborMac, nextId); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 662 | } else { |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 663 | log.debug("fixHashGroup in device {}: Adding Bucket(s) " |
| 664 | + "with Port/Label: {} to next object id {}", |
| 665 | deviceId, pl, nextId); |
| 666 | addToHashedNextObjective(pl, neighborMac, nextId); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 667 | } |
| 668 | } |
| 669 | return true; |
| 670 | } |
| 671 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 672 | /** |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 673 | * Returns true if the destination set is meant for swap or multi-labeled |
| 674 | * packet transport, and MPLS ECMP is not supported. |
| 675 | * |
| 676 | * @param dskey the key representing the destination set |
| 677 | * @return true if destination set is meant for simple next objectives |
| 678 | */ |
| 679 | boolean isSimpleNextObjective(DestinationSetNextObjectiveStoreKey dskey) { |
| 680 | return (dskey.destinationSet().notBos() || dskey.destinationSet().swap()) |
| 681 | && !srManager.getMplsEcmp(); |
| 682 | } |
| 683 | |
| 684 | /** |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 685 | * Adds or removes a port that has been configured with a vlan to a broadcast group |
| 686 | * 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] | 687 | * |
| 688 | * @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] | 689 | * @param vlanId the vlan id corresponding to the broadcast domain/group |
| 690 | * @param popVlan indicates if packets should be sent out untagged or not out |
| 691 | * of the port. If true, indicates an access (untagged) or native vlan |
| 692 | * configuration. If false, indicates a trunk (tagged) vlan config. |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 693 | * @param portUp true if port is enabled, false if disabled |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 694 | */ |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 695 | public void processEdgePort(PortNumber port, VlanId vlanId, |
| 696 | boolean popVlan, boolean portUp) { |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 697 | //get the next id for the subnet and edit it. |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 698 | Integer nextId = getVlanNextObjectiveId(vlanId); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 699 | if (nextId == -1) { |
| 700 | if (portUp) { |
| 701 | log.debug("**Creating flooding group for first port enabled in" |
Saurav Das | f14d9ef | 2017-12-05 15:00:23 -0800 | [diff] [blame] | 702 | + " vlan {} on dev {} port {}", vlanId, deviceId, port); |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 703 | createBcastGroupFromVlan(vlanId, Collections.singleton(port)); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 704 | } else { |
| 705 | log.warn("Could not find flooding group for subnet {} on dev:{} when" |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 706 | + " removing port:{}", vlanId, deviceId, port); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 707 | } |
| 708 | return; |
| 709 | } |
| 710 | |
| 711 | log.info("**port{} in device {}: {} Bucket with Port {} to" |
| 712 | + " next-id {}", (portUp) ? "UP" : "DOWN", deviceId, |
| 713 | (portUp) ? "Adding" : "Removing", |
| 714 | port, nextId); |
| 715 | // Create the bucket to be added or removed |
| 716 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 717 | if (popVlan) { |
| 718 | tBuilder.popVlan(); |
| 719 | } |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 720 | tBuilder.setOutput(port); |
| 721 | |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 722 | TrafficSelector metadata = |
Saurav Das | b0ae6ee | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 723 | DefaultTrafficSelector.builder().matchVlanId(vlanId).build(); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 724 | |
| 725 | NextObjective.Builder nextObjBuilder = DefaultNextObjective |
| 726 | .builder().withId(nextId) |
| 727 | .withType(NextObjective.Type.BROADCAST).fromApp(appId) |
| 728 | .addTreatment(tBuilder.build()) |
| 729 | .withMeta(metadata); |
| 730 | |
| 731 | ObjectiveContext context = new DefaultObjectiveContext( |
| 732 | (objective) -> log.debug("port {} successfully {} NextObj {} on {}", |
| 733 | port, (portUp) ? "addedTo" : "removedFrom", |
| 734 | nextId, deviceId), |
Charles Chan | 55b806f | 2018-08-23 14:30:33 -0700 | [diff] [blame] | 735 | (objective, error) -> { |
| 736 | log.warn("port {} failed to {} NextObj {} on {}: {}", |
| 737 | port, (portUp) ? "addTo" : "removeFrom", nextId, deviceId, error); |
| 738 | srManager.invalidateNextObj(objective.id()); |
| 739 | }); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 740 | |
| 741 | NextObjective nextObj = (portUp) ? nextObjBuilder.addToExisting(context) |
| 742 | : nextObjBuilder.removeFromExisting(context); |
| 743 | log.debug("edgePort processed: Submited next objective {} in device {}", |
| 744 | nextId, deviceId); |
| 745 | flowObjectiveService.next(deviceId, nextObj); |
| 746 | } |
| 747 | |
| 748 | /** |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 749 | * Returns the next objective of type hashed (or simple) associated with the |
| 750 | * destination set. In addition, updates the existing next-objective if new |
| 751 | * route-paths found have resulted in the addition of new next-hops to a |
| 752 | * particular destination. If there is no existing next objective for this |
| 753 | * destination set, this method would create a next objective and return the |
| 754 | * nextId. Optionally metadata can be passed in for the creation of the next |
| 755 | * objective. If the parameter simple is true then a simple next objective |
| 756 | * is created instead of a hashed one. |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 757 | * |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 758 | * @param ds destination set |
| 759 | * @param nextHops a map of per destination next hops |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 760 | * @param meta metadata passed into the creation of a Next Objective |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 761 | * @param simple if true, a simple next objective will be created instead of |
| 762 | * a hashed next objective |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 763 | * @return int if found or -1 if there are errors in the creation of the |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 764 | * neighbor set. |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 765 | */ |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 766 | public int getNextObjectiveId(DestinationSet ds, |
| 767 | Map<DeviceId, Set<DeviceId>> nextHops, |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 768 | TrafficSelector meta, boolean simple) { |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 769 | NextNeighbors next = dsNextObjStore. |
| 770 | get(new DestinationSetNextObjectiveStoreKey(deviceId, ds)); |
| 771 | if (next == null) { |
| 772 | log.debug("getNextObjectiveId in device{}: Next objective id " |
| 773 | + "not found for {} ... creating", deviceId, ds); |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 774 | log.trace("getNextObjectiveId: nsNextObjStore contents for device {}: {}", |
| 775 | deviceId, |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 776 | dsNextObjStore.entrySet() |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 777 | .stream() |
| 778 | .filter((nsStoreEntry) -> |
| 779 | (nsStoreEntry.getKey().deviceId().equals(deviceId))) |
| 780 | .collect(Collectors.toList())); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 781 | |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 782 | createGroupFromDestinationSet(ds, nextHops, meta, simple); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 783 | next = dsNextObjStore. |
| 784 | get(new DestinationSetNextObjectiveStoreKey(deviceId, ds)); |
| 785 | if (next == null) { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 786 | log.warn("getNextObjectiveId: unable to create next objective"); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 787 | // failure in creating group |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 788 | return -1; |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 789 | } else { |
| 790 | log.debug("getNextObjectiveId in device{}: Next objective id {} " |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 791 | + "created for {}", deviceId, next.nextId(), ds); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 792 | } |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 793 | } else { |
| 794 | log.trace("getNextObjectiveId in device{}: Next objective id {} " |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 795 | + "found for {}", deviceId, next.nextId(), ds); |
| 796 | // should fix hash groups too if next-hops have changed |
| 797 | if (!next.dstNextHops().equals(nextHops)) { |
| 798 | log.debug("Nexthops have changed for dev:{} nextId:{} ..updating", |
| 799 | deviceId, next.nextId()); |
| 800 | if (!updateNextHops(ds, nextHops)) { |
| 801 | // failure in updating group |
| 802 | return -1; |
| 803 | } |
| 804 | } |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 805 | } |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 806 | return next.nextId(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 807 | } |
| 808 | |
sangho | 0b2b6d1 | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 809 | /** |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 810 | * Returns the next objective of type broadcast associated with the vlan, |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 811 | * or -1 if no such objective exists. Note that this method does NOT create |
| 812 | * 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] | 813 | * created at startup from network configuration. Typically this is used |
| 814 | * for L2 flooding within the subnet configured on the switch. |
Charles Chan | c42e84e | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 815 | * |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 816 | * @param vlanId vlan id |
Charles Chan | c42e84e | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 817 | * @return int if found or -1 |
| 818 | */ |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 819 | public int getVlanNextObjectiveId(VlanId vlanId) { |
| 820 | Integer nextId = vlanNextObjStore. |
| 821 | get(new VlanNextObjectiveStoreKey(deviceId, vlanId)); |
Charles Chan | 9f676b6 | 2015-10-29 14:58:10 -0700 | [diff] [blame] | 822 | |
| 823 | return (nextId != null) ? nextId : -1; |
Charles Chan | c42e84e | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | /** |
Ruchi Sahota | ef0761c | 2019-01-28 01:08:18 +0000 | [diff] [blame^] | 827 | * Returns the next objective of type simple associated with the mac/vlan on the |
| 828 | * device, given the treatment. Different treatments to the same mac/vlan result |
| 829 | * in different next objectives. If no such objective exists, this method |
| 830 | * creates one (if requested) and returns the id. Optionally metadata can be passed in for |
| 831 | * the creation of the objective. Typically this is used for L2 and L3 forwarding |
| 832 | * to compute nodes and containers/VMs on the compute nodes directly attached |
| 833 | * to the switch. |
| 834 | * |
| 835 | * @param macAddr the mac addr for the simple next objective |
| 836 | * @param vlanId the vlan for the simple next objective |
| 837 | * @param treatment the actions to apply on the packets (should include outport) |
| 838 | * @param meta optional metadata passed into the creation of the next objective |
| 839 | * @param createIfMissing true if a next object should be created if not found |
| 840 | * @return int if found or created, -1 if there are errors during the |
| 841 | * creation of the next objective. |
| 842 | */ |
| 843 | public int getMacVlanNextObjectiveId(MacAddress macAddr, VlanId vlanId, TrafficTreatment treatment, |
| 844 | TrafficSelector meta, boolean createIfMissing) { |
| 845 | |
| 846 | Integer nextId = macVlanNextObjStore |
| 847 | .get(new MacVlanNextObjectiveStoreKey(deviceId, macAddr, vlanId)); |
| 848 | |
| 849 | if (nextId != null) { |
| 850 | return nextId; |
| 851 | } |
| 852 | |
| 853 | log.debug("getMacVlanNextObjectiveId in device {}: Next objective id " |
| 854 | + "not found for host : {}/{} .. {}", deviceId, macAddr, vlanId, |
| 855 | (createIfMissing) ? "creating" : "aborting"); |
| 856 | |
| 857 | if (!createIfMissing) { |
| 858 | return -1; |
| 859 | } |
| 860 | |
| 861 | /* create missing next objective */ |
| 862 | nextId = createGroupFromMacVlan(macAddr, vlanId, treatment, meta); |
| 863 | if (nextId == null) { |
| 864 | log.warn("getMacVlanNextObjectiveId: unable to create next obj" |
| 865 | + "for dev:{} host:{}/{}", deviceId, macAddr, vlanId); |
| 866 | return -1; |
| 867 | } |
| 868 | return nextId; |
| 869 | } |
| 870 | |
| 871 | |
| 872 | /** |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 873 | * Returns the next objective of type simple associated with the port on the |
| 874 | * device, given the treatment. Different treatments to the same port result |
| 875 | * in different next objectives. If no such objective exists, this method |
Saurav Das | 961beb2 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 876 | * creates one (if requested) and returns the id. Optionally metadata can be passed in for |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 877 | * the creation of the objective. Typically this is used for L2 and L3 forwarding |
| 878 | * to compute nodes and containers/VMs on the compute nodes directly attached |
| 879 | * to the switch. |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 880 | * |
| 881 | * @param portNum the port number for the simple next objective |
| 882 | * @param treatment the actions to apply on the packets (should include outport) |
| 883 | * @param meta optional metadata passed into the creation of the next objective |
Saurav Das | 961beb2 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 884 | * @param createIfMissing true if a next object should be created if not found |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 885 | * @return int if found or created, -1 if there are errors during the |
| 886 | * creation of the next objective. |
| 887 | */ |
| 888 | public int getPortNextObjectiveId(PortNumber portNum, TrafficTreatment treatment, |
Saurav Das | 961beb2 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 889 | TrafficSelector meta, boolean createIfMissing) { |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 890 | Integer nextId = portNextObjStore |
Saurav Das | 76ae681 | 2017-03-15 15:15:14 -0700 | [diff] [blame] | 891 | .get(new PortNextObjectiveStoreKey(deviceId, portNum, treatment, meta)); |
Saurav Das | 961beb2 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 892 | if (nextId != null) { |
| 893 | return nextId; |
| 894 | } |
| 895 | log.debug("getPortNextObjectiveId in device {}: Next objective id " |
| 896 | + "not found for port: {} .. {}", deviceId, portNum, |
| 897 | (createIfMissing) ? "creating" : "aborting"); |
| 898 | if (!createIfMissing) { |
| 899 | return -1; |
| 900 | } |
| 901 | // create missing next objective |
| 902 | createGroupFromPort(portNum, treatment, meta); |
| 903 | nextId = portNextObjStore.get(new PortNextObjectiveStoreKey(deviceId, portNum, |
| 904 | treatment, meta)); |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 905 | if (nextId == null) { |
Saurav Das | 961beb2 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 906 | log.warn("getPortNextObjectiveId: unable to create next obj" |
| 907 | + "for dev:{} port:{}", deviceId, portNum); |
| 908 | return -1; |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 909 | } |
| 910 | return nextId; |
| 911 | } |
| 912 | |
| 913 | /** |
sangho | 0b2b6d1 | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 914 | * Checks if the next objective ID (group) for the neighbor set exists or not. |
| 915 | * |
| 916 | * @param ns neighbor set to check |
| 917 | * @return true if it exists, false otherwise |
| 918 | */ |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 919 | public boolean hasNextObjectiveId(DestinationSet ns) { |
| 920 | NextNeighbors nextHops = dsNextObjStore. |
| 921 | get(new DestinationSetNextObjectiveStoreKey(deviceId, ns)); |
| 922 | if (nextHops == null) { |
sangho | 0b2b6d1 | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 923 | return false; |
| 924 | } |
| 925 | |
| 926 | return true; |
| 927 | } |
| 928 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 929 | private void populateNeighborMaps() { |
| 930 | Set<Link> outgoingLinks = linkService.getDeviceEgressLinks(deviceId); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 931 | for (Link link : outgoingLinks) { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 932 | if (link.type() != Link.Type.DIRECT) { |
| 933 | continue; |
| 934 | } |
| 935 | addNeighborAtPort(link.dst().deviceId(), link.src().port()); |
| 936 | } |
| 937 | } |
| 938 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 939 | protected void addNeighborAtPort(DeviceId neighborId, |
| 940 | PortNumber portToNeighbor) { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 941 | // Update DeviceToPort database |
| 942 | log.debug("Device {} addNeighborAtPort: neighbor {} at port {}", |
| 943 | deviceId, neighborId, portToNeighbor); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 944 | Set<PortNumber> ports = Collections |
| 945 | .newSetFromMap(new ConcurrentHashMap<PortNumber, Boolean>()); |
| 946 | ports.add(portToNeighbor); |
| 947 | Set<PortNumber> portnums = devicePortMap.putIfAbsent(neighborId, ports); |
| 948 | if (portnums != null) { |
| 949 | portnums.add(portToNeighbor); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | // Update portToDevice database |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 953 | // should always update as neighbor could have changed on this port |
| 954 | DeviceId prev = portDeviceMap.put(portToNeighbor, neighborId); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 955 | if (prev != null) { |
Saurav Das | 5a35604 | 2018-04-06 20:16:01 -0700 | [diff] [blame] | 956 | log.warn("Device/port: {}/{} previous neighbor: {}, current neighbor: {} ", |
Saurav Das | c88d466 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 957 | deviceId, portToNeighbor, prev, neighborId); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 958 | } |
| 959 | } |
| 960 | |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 961 | /** |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 962 | * Creates a NextObjective for a hash group in this device from a given |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 963 | * DestinationSet. If the parameter simple is true, a simple next objective |
| 964 | * is created instead. |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 965 | * |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 966 | * @param ds the DestinationSet |
| 967 | * @param neighbors a map for each destination and its next-hops |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 968 | * @param meta metadata passed into the creation of a Next Objective |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 969 | * @param simple if true, a simple next objective will be created instead of |
| 970 | * a hashed next objective |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 971 | */ |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 972 | public void createGroupFromDestinationSet(DestinationSet ds, |
| 973 | Map<DeviceId, Set<DeviceId>> neighbors, |
| 974 | TrafficSelector meta, |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 975 | boolean simple) { |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 976 | int nextId = flowObjectiveService.allocateNextId(); |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 977 | NextObjective.Type type = (simple) ? NextObjective.Type.SIMPLE |
| 978 | : NextObjective.Type.HASHED; |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 979 | if (neighbors == null || neighbors.isEmpty()) { |
| 980 | log.warn("createGroupsFromDestinationSet: needs at least one neighbor" |
| 981 | + "to create group in dev:{} for ds: {} with next-hops {}", |
| 982 | deviceId, ds, neighbors); |
| 983 | return; |
| 984 | } |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 985 | |
| 986 | NextObjective.Builder nextObjBuilder = DefaultNextObjective |
| 987 | .builder() |
| 988 | .withId(nextId) |
| 989 | .withType(type) |
| 990 | .fromApp(appId); |
| 991 | if (meta != null) { |
| 992 | nextObjBuilder.withMeta(meta); |
| 993 | } |
| 994 | |
| 995 | // create treatment buckets for each neighbor for each dst Device |
| 996 | // except in the special case where we only want to pick a single |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 997 | // neighbor/port for a simple nextObj |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 998 | boolean foundSingleNeighbor = false; |
| 999 | boolean treatmentAdded = false; |
| 1000 | Map<DeviceId, Set<DeviceId>> dstNextHops = new ConcurrentHashMap<>(); |
| 1001 | for (DeviceId dst : ds.getDestinationSwitches()) { |
| 1002 | Set<DeviceId> nextHops = neighbors.get(dst); |
| 1003 | if (nextHops == null || nextHops.isEmpty()) { |
| 1004 | continue; |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 1005 | } |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1006 | |
| 1007 | if (foundSingleNeighbor) { |
| 1008 | break; |
| 1009 | } |
| 1010 | |
| 1011 | for (DeviceId neighborId : nextHops) { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1012 | if (devicePortMap.get(neighborId) == null) { |
| 1013 | log.warn("Neighbor {} is not in the port map yet for dev:{}", |
| 1014 | neighborId, deviceId); |
sangho | 834e4b0 | 2015-05-01 09:38:25 -0700 | [diff] [blame] | 1015 | return; |
Jon Hall | cbd1b39 | 2017-01-18 20:15:44 -0800 | [diff] [blame] | 1016 | } else if (devicePortMap.get(neighborId).isEmpty()) { |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 1017 | log.warn("There are no ports for " |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1018 | + "the Device {} in the port map yet", neighborId); |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 1019 | return; |
sangho | 834e4b0 | 2015-05-01 09:38:25 -0700 | [diff] [blame] | 1020 | } |
| 1021 | |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1022 | MacAddress neighborMac; |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 1023 | try { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1024 | neighborMac = deviceConfig.getDeviceMac(neighborId); |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 1025 | } catch (DeviceConfigNotFoundException e) { |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1026 | log.warn(e.getMessage() + " Aborting createGroupsFromDestinationset."); |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 1027 | return; |
| 1028 | } |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1029 | // For each port to the neighbor, we create a new treatment |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 1030 | Set<PortNumber> neighborPorts = devicePortMap.get(neighborId); |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 1031 | // In this case we need a SIMPLE nextObj. We randomly pick a port |
| 1032 | if (simple) { |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 1033 | int size = devicePortMap.get(neighborId).size(); |
| 1034 | int index = RandomUtils.nextInt(0, size); |
| 1035 | neighborPorts = Collections.singleton( |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1036 | Iterables.get(devicePortMap.get(neighborId), |
| 1037 | index)); |
| 1038 | foundSingleNeighbor = true; |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 1039 | } |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1040 | |
Pier Ventre | 917127a | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 1041 | for (PortNumber sp : neighborPorts) { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 1042 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment |
| 1043 | .builder(); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1044 | tBuilder.setEthDst(neighborMac).setEthSrc(nodeMacAddr); |
| 1045 | int edgeLabel = ds.getEdgeLabel(dst); |
| 1046 | if (edgeLabel != DestinationSet.NO_EDGE_LABEL) { |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 1047 | if (simple) { |
| 1048 | // swap label case |
| 1049 | tBuilder.setMpls(MplsLabel.mplsLabel(edgeLabel)); |
| 1050 | } else { |
| 1051 | // ecmp with label push case |
| 1052 | tBuilder.pushMpls().copyTtlOut() |
| 1053 | .setMpls(MplsLabel.mplsLabel(edgeLabel)); |
| 1054 | } |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 1055 | } |
Charles Chan | 69b7ae6 | 2018-08-12 15:19:01 -0700 | [diff] [blame] | 1056 | |
| 1057 | // Set VLAN ID for PW transport. Otherwise pop vlan |
Charles Chan | e0260e1 | 2018-08-22 17:56:47 -0700 | [diff] [blame] | 1058 | if (!popVlanInHashGroup(ds)) { |
Saurav Das | 09c2c4d | 2018-08-13 15:34:26 -0700 | [diff] [blame] | 1059 | tBuilder.setVlanId(srManager.getPwTransportVlan()); |
Charles Chan | 69b7ae6 | 2018-08-12 15:19:01 -0700 | [diff] [blame] | 1060 | } else { |
| 1061 | tBuilder.popVlan(); |
Andreas Pantelopoulos | 192284c | 2018-05-01 14:56:05 -0700 | [diff] [blame] | 1062 | } |
Charles Chan | 69b7ae6 | 2018-08-12 15:19:01 -0700 | [diff] [blame] | 1063 | |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1064 | tBuilder.setOutput(sp); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 1065 | nextObjBuilder.addTreatment(tBuilder.build()); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1066 | treatmentAdded = true; |
| 1067 | //update store |
| 1068 | Set<DeviceId> existingNeighbors = dstNextHops.get(dst); |
| 1069 | if (existingNeighbors == null) { |
| 1070 | existingNeighbors = new HashSet<>(); |
| 1071 | } |
| 1072 | existingNeighbors.add(neighborId); |
| 1073 | dstNextHops.put(dst, existingNeighbors); |
| 1074 | log.debug("creating treatment for port/label {}/{} in next:{}", |
| 1075 | sp, edgeLabel, nextId); |
| 1076 | } |
| 1077 | |
| 1078 | if (foundSingleNeighbor) { |
| 1079 | break; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 1080 | } |
| 1081 | } |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 1082 | } |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1083 | |
| 1084 | if (!treatmentAdded) { |
| 1085 | log.warn("Could not createGroup from DestinationSet {} without any" |
| 1086 | + "next hops {}", ds, neighbors); |
| 1087 | return; |
| 1088 | } |
| 1089 | ObjectiveContext context = new DefaultObjectiveContext( |
| 1090 | (objective) -> |
| 1091 | log.debug("createGroupsFromDestinationSet installed " |
| 1092 | + "NextObj {} on {}", nextId, deviceId), |
Charles Chan | 55b806f | 2018-08-23 14:30:33 -0700 | [diff] [blame] | 1093 | (objective, error) -> { |
| 1094 | log.warn("createGroupsFromDestinationSet failed to install NextObj {} on {}: {}", |
| 1095 | nextId, deviceId, error); |
| 1096 | srManager.invalidateNextObj(objective.id()); |
| 1097 | }); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1098 | NextObjective nextObj = nextObjBuilder.add(context); |
| 1099 | log.debug(".. createGroupsFromDestinationSet: Submitted " |
| 1100 | + "next objective {} in device {}", nextId, deviceId); |
| 1101 | flowObjectiveService.next(deviceId, nextObj); |
| 1102 | //update store |
| 1103 | dsNextObjStore.put(new DestinationSetNextObjectiveStoreKey(deviceId, ds), |
| 1104 | new NextNeighbors(dstNextHops, nextId)); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 1105 | } |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 1106 | |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1107 | /** |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1108 | * Creates broadcast groups for all ports in the same subnet for |
| 1109 | * all configured subnets. |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1110 | */ |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1111 | public void createGroupsFromVlanConfig() { |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 1112 | srManager.getVlanPortMap(deviceId).asMap().forEach((vlanId, ports) -> { |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1113 | createBcastGroupFromVlan(vlanId, ports); |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 1114 | }); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1115 | } |
Charles Chan | 9f676b6 | 2015-10-29 14:58:10 -0700 | [diff] [blame] | 1116 | |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1117 | /** |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1118 | * 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] | 1119 | * |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1120 | * @param vlanId vlan id |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1121 | * @param ports list of ports in the subnet |
| 1122 | */ |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 1123 | public void createBcastGroupFromVlan(VlanId vlanId, Collection<PortNumber> ports) { |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1124 | VlanNextObjectiveStoreKey key = new VlanNextObjectiveStoreKey(deviceId, vlanId); |
Charles Chan | 9f676b6 | 2015-10-29 14:58:10 -0700 | [diff] [blame] | 1125 | |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1126 | if (vlanNextObjStore.containsKey(key)) { |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1127 | log.debug("Broadcast group for device {} and subnet {} exists", |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1128 | deviceId, vlanId); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1129 | return; |
| 1130 | } |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1131 | |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1132 | TrafficSelector metadata = |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1133 | DefaultTrafficSelector.builder().matchVlanId(vlanId).build(); |
Charles Chan | c42e84e | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 1134 | |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1135 | int nextId = flowObjectiveService.allocateNextId(); |
Charles Chan | c42e84e | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 1136 | |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1137 | NextObjective.Builder nextObjBuilder = DefaultNextObjective |
| 1138 | .builder().withId(nextId) |
| 1139 | .withType(NextObjective.Type.BROADCAST).fromApp(appId) |
| 1140 | .withMeta(metadata); |
Charles Chan | c42e84e | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 1141 | |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1142 | ports.forEach(port -> { |
| 1143 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 1144 | if (toPopVlan(port, vlanId)) { |
| 1145 | tBuilder.popVlan(); |
| 1146 | } |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1147 | tBuilder.setOutput(port); |
| 1148 | nextObjBuilder.addTreatment(tBuilder.build()); |
Charles Chan | c42e84e | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 1149 | }); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1150 | |
Saurav Das | 961beb2 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 1151 | ObjectiveContext context = new DefaultObjectiveContext( |
| 1152 | (objective) -> |
| 1153 | log.debug("createBroadcastGroupFromVlan installed " |
| 1154 | + "NextObj {} on {}", nextId, deviceId), |
Charles Chan | 55b806f | 2018-08-23 14:30:33 -0700 | [diff] [blame] | 1155 | (objective, error) -> { |
| 1156 | log.warn("createBroadcastGroupFromVlan failed to install NextObj {} on {}: {}", |
| 1157 | nextId, deviceId, error); |
| 1158 | srManager.invalidateNextObj(objective.id()); |
| 1159 | }); |
Saurav Das | 961beb2 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 1160 | NextObjective nextObj = nextObjBuilder.add(context); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1161 | flowObjectiveService.next(deviceId, nextObj); |
Saurav Das | f14d9ef | 2017-12-05 15:00:23 -0800 | [diff] [blame] | 1162 | log.debug("createBcastGroupFromVlan: Submitted next objective {} " |
| 1163 | + "for vlan: {} in device {}", nextId, vlanId, deviceId); |
Saurav Das | 1a129a0 | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1164 | |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1165 | vlanNextObjStore.put(key, nextId); |
Charles Chan | c42e84e | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 1166 | } |
| 1167 | |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 1168 | /** |
Jonghwan Hyun | 42fe105 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 1169 | * Removes a single broadcast group from a given vlan id. |
| 1170 | * The group should be empty. |
| 1171 | * @param deviceId device Id to remove the group |
| 1172 | * @param portNum port number related to the group |
| 1173 | * @param vlanId vlan id of the broadcast group to remove |
| 1174 | * @param popVlan true if the TrafficTreatment involves pop vlan tag action |
| 1175 | */ |
| 1176 | public void removeBcastGroupFromVlan(DeviceId deviceId, PortNumber portNum, |
| 1177 | VlanId vlanId, boolean popVlan) { |
| 1178 | VlanNextObjectiveStoreKey key = new VlanNextObjectiveStoreKey(deviceId, vlanId); |
| 1179 | |
| 1180 | if (!vlanNextObjStore.containsKey(key)) { |
| 1181 | log.debug("Broadcast group for device {} and subnet {} does not exist", |
| 1182 | deviceId, vlanId); |
| 1183 | return; |
| 1184 | } |
| 1185 | |
| 1186 | TrafficSelector metadata = |
| 1187 | DefaultTrafficSelector.builder().matchVlanId(vlanId).build(); |
| 1188 | |
| 1189 | int nextId = vlanNextObjStore.get(key); |
| 1190 | |
| 1191 | NextObjective.Builder nextObjBuilder = DefaultNextObjective |
| 1192 | .builder().withId(nextId) |
| 1193 | .withType(NextObjective.Type.BROADCAST).fromApp(appId) |
| 1194 | .withMeta(metadata); |
| 1195 | |
| 1196 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 1197 | if (popVlan) { |
| 1198 | tBuilder.popVlan(); |
| 1199 | } |
| 1200 | tBuilder.setOutput(portNum); |
| 1201 | nextObjBuilder.addTreatment(tBuilder.build()); |
| 1202 | |
| 1203 | ObjectiveContext context = new DefaultObjectiveContext( |
| 1204 | (objective) -> |
| 1205 | log.debug("removeBroadcastGroupFromVlan removed " |
| 1206 | + "NextObj {} on {}", nextId, deviceId), |
Charles Chan | 55b806f | 2018-08-23 14:30:33 -0700 | [diff] [blame] | 1207 | (objective, error) -> { |
| 1208 | log.warn("removeBroadcastGroupFromVlan failed to remove NextObj {} on {}: {}", |
| 1209 | nextId, deviceId, error); |
| 1210 | srManager.invalidateNextObj(objective.id()); |
| 1211 | }); |
Jonghwan Hyun | 42fe105 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 1212 | NextObjective nextObj = nextObjBuilder.remove(context); |
| 1213 | flowObjectiveService.next(deviceId, nextObj); |
| 1214 | log.debug("removeBcastGroupFromVlan: Submited next objective {} in device {}", |
| 1215 | nextId, deviceId); |
| 1216 | |
| 1217 | vlanNextObjStore.remove(key, nextId); |
| 1218 | } |
| 1219 | |
| 1220 | /** |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 1221 | * Determine if we should pop given vlan before sending packets to the given port. |
| 1222 | * |
| 1223 | * @param portNumber port number |
| 1224 | * @param vlanId vlan id |
| 1225 | * @return true if the vlan id is not contained in any vlanTagged config |
| 1226 | */ |
| 1227 | private boolean toPopVlan(PortNumber portNumber, VlanId vlanId) { |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1228 | return srManager.interfaceService |
| 1229 | .getInterfacesByPort(new ConnectPoint(deviceId, portNumber)) |
Charles Chan | 7ffd81f | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 1230 | .stream().noneMatch(intf -> intf.vlanTagged().contains(vlanId)); |
| 1231 | } |
| 1232 | |
| 1233 | /** |
Ruchi Sahota | ef0761c | 2019-01-28 01:08:18 +0000 | [diff] [blame^] | 1234 | * Create simple next objective for an indirect host mac/vlan. The treatments can include |
| 1235 | * all outgoing actions that need to happen on the packet. |
| 1236 | * |
| 1237 | * @param macAddr the mac address of the host |
| 1238 | * @param vlanId the vlan of the host |
| 1239 | * @param treatment the actions to apply on the packets (should include outport) |
| 1240 | * @param meta optional data to pass to the driver |
| 1241 | * @return next objective ID |
| 1242 | */ |
| 1243 | public int createGroupFromMacVlan(MacAddress macAddr, VlanId vlanId, TrafficTreatment treatment, |
| 1244 | TrafficSelector meta) { |
| 1245 | int nextId = flowObjectiveService.allocateNextId(); |
| 1246 | MacVlanNextObjectiveStoreKey key = new MacVlanNextObjectiveStoreKey(deviceId, macAddr, vlanId); |
| 1247 | |
| 1248 | NextObjective.Builder nextObjBuilder = DefaultNextObjective |
| 1249 | .builder().withId(nextId) |
| 1250 | .withType(NextObjective.Type.SIMPLE) |
| 1251 | .addTreatment(treatment) |
| 1252 | .fromApp(appId) |
| 1253 | .withMeta(meta); |
| 1254 | |
| 1255 | ObjectiveContext context = new DefaultObjectiveContext( |
| 1256 | (objective) -> |
| 1257 | log.debug("createGroupFromMacVlan installed " |
| 1258 | + "NextObj {} on {}", nextId, deviceId), |
| 1259 | (objective, error) -> { |
| 1260 | log.warn("createGroupFromMacVlan failed to install NextObj {} on {}: {}", nextId, deviceId, error); |
| 1261 | srManager.invalidateNextObj(objective.id()); |
| 1262 | }); |
| 1263 | NextObjective nextObj = nextObjBuilder.add(context); |
| 1264 | flowObjectiveService.next(deviceId, nextObj); |
| 1265 | log.debug("createGroupFromMacVlan: Submited next objective {} in device {} " |
| 1266 | + "for host {}/{}", nextId, deviceId, macAddr, vlanId); |
| 1267 | |
| 1268 | macVlanNextObjStore.put(key, nextId); |
| 1269 | return nextId; |
| 1270 | } |
| 1271 | |
| 1272 | /** |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1273 | * Create simple next objective for a single port. The treatments can include |
| 1274 | * all outgoing actions that need to happen on the packet. |
| 1275 | * |
| 1276 | * @param portNum the outgoing port on the device |
| 1277 | * @param treatment the actions to apply on the packets (should include outport) |
| 1278 | * @param meta optional data to pass to the driver |
| 1279 | */ |
| 1280 | public void createGroupFromPort(PortNumber portNum, TrafficTreatment treatment, |
| 1281 | TrafficSelector meta) { |
| 1282 | int nextId = flowObjectiveService.allocateNextId(); |
| 1283 | PortNextObjectiveStoreKey key = new PortNextObjectiveStoreKey( |
Saurav Das | 76ae681 | 2017-03-15 15:15:14 -0700 | [diff] [blame] | 1284 | deviceId, portNum, treatment, meta); |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1285 | |
| 1286 | NextObjective.Builder nextObjBuilder = DefaultNextObjective |
| 1287 | .builder().withId(nextId) |
| 1288 | .withType(NextObjective.Type.SIMPLE) |
| 1289 | .addTreatment(treatment) |
| 1290 | .fromApp(appId) |
| 1291 | .withMeta(meta); |
| 1292 | |
Saurav Das | 961beb2 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 1293 | ObjectiveContext context = new DefaultObjectiveContext( |
| 1294 | (objective) -> |
| 1295 | log.debug("createGroupFromPort installed " |
| 1296 | + "NextObj {} on {}", nextId, deviceId), |
Charles Chan | 55b806f | 2018-08-23 14:30:33 -0700 | [diff] [blame] | 1297 | (objective, error) -> { |
| 1298 | log.warn("createGroupFromPort failed to install NextObj {} on {}: {}", nextId, deviceId, error); |
| 1299 | srManager.invalidateNextObj(objective.id()); |
| 1300 | }); |
Saurav Das | 961beb2 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 1301 | NextObjective nextObj = nextObjBuilder.add(context); |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1302 | flowObjectiveService.next(deviceId, nextObj); |
| 1303 | log.debug("createGroupFromPort: Submited next objective {} in device {} " |
| 1304 | + "for port {}", nextId, deviceId, portNum); |
| 1305 | |
| 1306 | portNextObjStore.put(key, nextId); |
| 1307 | } |
| 1308 | |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 1309 | /** |
Jonghwan Hyun | 42fe105 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 1310 | * Removes simple next objective for a single port. |
| 1311 | * |
| 1312 | * @param deviceId device id that has the port to deal with |
| 1313 | * @param portNum the outgoing port on the device |
| 1314 | * @param vlanId vlan id associated with the port |
| 1315 | * @param popVlan true if POP_VLAN action is applied on the packets, false otherwise |
| 1316 | */ |
| 1317 | public void removePortNextObjective(DeviceId deviceId, PortNumber portNum, VlanId vlanId, boolean popVlan) { |
| 1318 | TrafficSelector.Builder mbuilder = DefaultTrafficSelector.builder(); |
| 1319 | mbuilder.matchVlanId(vlanId); |
| 1320 | |
| 1321 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
| 1322 | tbuilder.immediate().setOutput(portNum); |
| 1323 | if (popVlan) { |
| 1324 | tbuilder.immediate().popVlan(); |
| 1325 | } |
| 1326 | |
| 1327 | int portNextObjId = srManager.getPortNextObjectiveId(deviceId, portNum, |
| 1328 | tbuilder.build(), mbuilder.build(), false); |
| 1329 | |
| 1330 | PortNextObjectiveStoreKey key = new PortNextObjectiveStoreKey( |
| 1331 | deviceId, portNum, tbuilder.build(), mbuilder.build()); |
| 1332 | if (portNextObjId != -1 && portNextObjStore.containsKey(key)) { |
| 1333 | NextObjective.Builder nextObjBuilder = DefaultNextObjective |
| 1334 | .builder().withId(portNextObjId) |
| 1335 | .withType(NextObjective.Type.SIMPLE).fromApp(appId); |
| 1336 | ObjectiveContext context = new DefaultObjectiveContext( |
| 1337 | (objective) -> log.debug("removePortNextObjective removes NextObj {} on {}", |
| 1338 | portNextObjId, deviceId), |
Charles Chan | 55b806f | 2018-08-23 14:30:33 -0700 | [diff] [blame] | 1339 | (objective, error) -> { |
| 1340 | log.warn("removePortNextObjective failed to remove NextObj {} on {}: {}", |
| 1341 | portNextObjId, deviceId, error); |
| 1342 | srManager.invalidateNextObj(objective.id()); |
| 1343 | }); |
Jonghwan Hyun | 42fe105 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 1344 | NextObjective nextObjective = nextObjBuilder.remove(context); |
| 1345 | log.info("**removePortNextObjective: Submitted " |
| 1346 | + "next objective {} in device {}", |
| 1347 | portNextObjId, deviceId); |
| 1348 | flowObjectiveService.next(deviceId, nextObjective); |
| 1349 | |
| 1350 | portNextObjStore.remove(key); |
| 1351 | } |
| 1352 | } |
Ruchi Sahota | ef0761c | 2019-01-28 01:08:18 +0000 | [diff] [blame^] | 1353 | |
Jonghwan Hyun | 42fe105 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 1354 | /** |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 1355 | * Removes groups for the next objective ID given. |
| 1356 | * |
| 1357 | * @param objectiveId next objective ID to remove |
| 1358 | * @return true if succeeds, false otherwise |
| 1359 | */ |
| 1360 | public boolean removeGroup(int objectiveId) { |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1361 | for (Map.Entry<DestinationSetNextObjectiveStoreKey, NextNeighbors> e : |
| 1362 | dsNextObjStore.entrySet()) { |
| 1363 | if (e.getValue().nextId() != objectiveId) { |
| 1364 | continue; |
| 1365 | } |
Pier Luigi | 63edd93 | 2018-01-14 21:56:11 +0100 | [diff] [blame] | 1366 | // Right now it is just used in TunnelHandler |
| 1367 | // remember in future that PW transit groups could |
| 1368 | // be Indirect groups |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 1369 | NextObjective.Builder nextObjBuilder = DefaultNextObjective |
| 1370 | .builder().withId(objectiveId) |
| 1371 | .withType(NextObjective.Type.HASHED).fromApp(appId); |
Charles Chan | 216e3c8 | 2016-04-23 14:48:16 -0700 | [diff] [blame] | 1372 | ObjectiveContext context = new DefaultObjectiveContext( |
| 1373 | (objective) -> log.debug("RemoveGroup removes NextObj {} on {}", |
| 1374 | objectiveId, deviceId), |
Charles Chan | 55b806f | 2018-08-23 14:30:33 -0700 | [diff] [blame] | 1375 | (objective, error) -> { |
| 1376 | log.warn("RemoveGroup failed to remove NextObj {} on {}: {}", objectiveId, deviceId, error); |
| 1377 | srManager.invalidateNextObj(objective.id()); |
| 1378 | }); |
Charles Chan | 216e3c8 | 2016-04-23 14:48:16 -0700 | [diff] [blame] | 1379 | NextObjective nextObjective = nextObjBuilder.remove(context); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1380 | log.info("**removeGroup: Submited " |
| 1381 | + "next objective {} in device {}", |
| 1382 | objectiveId, deviceId); |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 1383 | flowObjectiveService.next(deviceId, nextObjective); |
| 1384 | |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1385 | dsNextObjStore.remove(e.getKey()); |
sangho | 0b2b6d1 | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 1386 | return true; |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | return false; |
| 1390 | } |
Jonghwan Hyun | 42fe105 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 1391 | /** |
| 1392 | * Remove simple next objective for a single port. The treatments can include |
| 1393 | * all outgoing actions that need to happen on the packet. |
| 1394 | * |
| 1395 | * @param portNum the outgoing port on the device |
| 1396 | * @param treatment the actions applied on the packets (should include outport) |
| 1397 | * @param meta optional data to pass to the driver |
| 1398 | */ |
| 1399 | public void removeGroupFromPort(PortNumber portNum, TrafficTreatment treatment, |
| 1400 | TrafficSelector meta) { |
| 1401 | PortNextObjectiveStoreKey key = new PortNextObjectiveStoreKey( |
| 1402 | deviceId, portNum, treatment, meta); |
| 1403 | Integer nextId = portNextObjStore.get(key); |
| 1404 | |
| 1405 | NextObjective.Builder nextObjBuilder = DefaultNextObjective |
| 1406 | .builder().withId(nextId) |
| 1407 | .withType(NextObjective.Type.SIMPLE) |
| 1408 | .addTreatment(treatment) |
| 1409 | .fromApp(appId) |
| 1410 | .withMeta(meta); |
| 1411 | |
| 1412 | ObjectiveContext context = new DefaultObjectiveContext( |
| 1413 | (objective) -> |
| 1414 | log.info("removeGroupFromPort installed " |
| 1415 | + "NextObj {} on {}", nextId, deviceId), |
Charles Chan | 55b806f | 2018-08-23 14:30:33 -0700 | [diff] [blame] | 1416 | (objective, error) -> { |
| 1417 | log.warn("removeGroupFromPort failed to install NextObj {} on {}: {}", nextId, deviceId, error); |
| 1418 | srManager.invalidateNextObj(objective.id()); |
| 1419 | } |
Jonghwan Hyun | 42fe105 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 1420 | ); |
| 1421 | NextObjective nextObj = nextObjBuilder.remove(context); |
| 1422 | flowObjectiveService.next(deviceId, nextObj); |
| 1423 | log.info("removeGroupFromPort: Submitted next objective {} in device {} " |
| 1424 | + "for port {}", nextId, deviceId, portNum); |
| 1425 | |
| 1426 | portNextObjStore.remove(key); |
| 1427 | } |
Srikanth Vavilapalli | f3a8bc0 | 2015-05-22 13:47:31 -0700 | [diff] [blame] | 1428 | |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 1429 | /** |
| 1430 | * Removes all groups from all next objective stores. |
| 1431 | */ |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1432 | /*public void removeAllGroups() { |
| 1433 | for (Map.Entry<NeighborSetNextObjectiveStoreKey, NextNeighbors> entry: |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 1434 | nsNextObjStore.entrySet()) { |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1435 | removeGroup(entry.getValue().nextId()); |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 1436 | } |
| 1437 | for (Map.Entry<PortNextObjectiveStoreKey, Integer> entry: |
| 1438 | portNextObjStore.entrySet()) { |
| 1439 | removeGroup(entry.getValue()); |
| 1440 | } |
Charles Chan | 59cc16d | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1441 | for (Map.Entry<VlanNextObjectiveStoreKey, Integer> entry: |
| 1442 | vlanNextObjStore.entrySet()) { |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 1443 | removeGroup(entry.getValue()); |
| 1444 | } |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1445 | }*/ //XXX revisit |
| 1446 | |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 1447 | /** |
| 1448 | * Triggers a one time bucket verification operation on all hash groups |
| 1449 | * on this device. |
| 1450 | */ |
| 1451 | public void triggerBucketCorrector() { |
| 1452 | BucketCorrector bc = new BucketCorrector(); |
| 1453 | bc.run(); |
| 1454 | } |
| 1455 | |
Jonghwan Hyun | f810a7a | 2018-02-12 16:43:45 +0900 | [diff] [blame] | 1456 | /** |
| 1457 | * Modifies L2IG bucket when the interface configuration is updated, especially |
| 1458 | * when the interface has same VLAN ID but the VLAN type is changed (e.g., from |
| 1459 | * vlan-tagged [10] to vlan-untagged 10), which requires changes on |
| 1460 | * TrafficTreatment in turn. |
| 1461 | * |
| 1462 | * @param portNumber the port on this device that needs to be updated |
| 1463 | * @param vlanId the vlan id corresponding to this port |
| 1464 | * @param pushVlan indicates if packets should be sent out untagged or not out |
| 1465 | * from the port. If true, updated TrafficTreatment involves |
| 1466 | * pop vlan tag action. If false, updated TrafficTreatment |
| 1467 | * does not involve pop vlan tag action. |
| 1468 | */ |
| 1469 | public void updateL2InterfaceGroupBucket(PortNumber portNumber, VlanId vlanId, boolean pushVlan) { |
| 1470 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 1471 | if (pushVlan) { |
| 1472 | tBuilder.popVlan(); |
| 1473 | } |
| 1474 | tBuilder.setOutput(portNumber); |
| 1475 | |
| 1476 | TrafficSelector metadata = |
| 1477 | DefaultTrafficSelector.builder().matchVlanId(vlanId).build(); |
| 1478 | |
| 1479 | int nextId = getVlanNextObjectiveId(vlanId); |
| 1480 | |
| 1481 | NextObjective.Builder nextObjBuilder = DefaultNextObjective |
| 1482 | .builder().withId(nextId) |
| 1483 | .withType(NextObjective.Type.SIMPLE).fromApp(appId) |
| 1484 | .addTreatment(tBuilder.build()) |
| 1485 | .withMeta(metadata); |
| 1486 | |
| 1487 | ObjectiveContext context = new DefaultObjectiveContext( |
| 1488 | (objective) -> log.debug("port {} successfully updated NextObj {} on {}", |
| 1489 | portNumber, nextId, deviceId), |
Charles Chan | 55b806f | 2018-08-23 14:30:33 -0700 | [diff] [blame] | 1490 | (objective, error) -> { |
| 1491 | log.warn("port {} failed to updated NextObj {} on {}: {}", portNumber, nextId, deviceId, error); |
| 1492 | srManager.invalidateNextObj(objective.id()); |
| 1493 | }); |
Jonghwan Hyun | f810a7a | 2018-02-12 16:43:45 +0900 | [diff] [blame] | 1494 | |
| 1495 | flowObjectiveService.next(deviceId, nextObjBuilder.modify(context)); |
Jonghwan Hyun | 42fe105 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 1496 | } |
| 1497 | |
Jonghwan Hyun | f810a7a | 2018-02-12 16:43:45 +0900 | [diff] [blame] | 1498 | /** |
Ruchi Sahota | ef0761c | 2019-01-28 01:08:18 +0000 | [diff] [blame^] | 1499 | * Returns the next ID for the given host port from the store. |
| 1500 | * |
| 1501 | * @param hostMac mac of host for which Next ID is required. |
| 1502 | * @param hostVlanId vlan of host for which Next ID is required. |
| 1503 | * @param port port of device for which next ID is required. |
| 1504 | * @return next objective ID or -1 if an error occurred during retrieval |
| 1505 | */ |
| 1506 | public int getNextIdForHostPort(MacAddress hostMac, VlanId hostVlanId, PortNumber port) { |
| 1507 | |
| 1508 | MacAddress deviceMac; |
| 1509 | try { |
| 1510 | deviceMac = deviceConfig.getDeviceMac(deviceId); |
| 1511 | } catch (DeviceConfigNotFoundException e) { |
| 1512 | log.warn(e.getMessage() + " in getNextIdForHostPort"); |
| 1513 | return -1; |
| 1514 | } |
| 1515 | |
| 1516 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
| 1517 | tbuilder.deferred() |
| 1518 | .setEthDst(hostMac) |
| 1519 | .setEthSrc(deviceMac) |
| 1520 | .setVlanId(hostVlanId) |
| 1521 | .setOutput(port); |
| 1522 | |
| 1523 | TrafficSelector metadata = |
| 1524 | DefaultTrafficSelector.builder().matchVlanId(hostVlanId).build(); |
| 1525 | |
| 1526 | int nextId = getMacVlanNextObjectiveId(hostMac, hostVlanId, |
| 1527 | tbuilder.build(), metadata, true); |
| 1528 | |
| 1529 | log.debug("getNextId : hostMac {}, deviceMac {}, port {}, hostVlanId {} Treatment {} Meta {} nextId {} ", |
| 1530 | hostMac, deviceMac, port, hostVlanId, tbuilder.build(), metadata, nextId); |
| 1531 | |
| 1532 | return nextId; |
| 1533 | } |
| 1534 | |
| 1535 | /** |
| 1536 | * Updates the next objective for the given nextId . |
| 1537 | * |
| 1538 | * @param hostMac mac of host for which Next obj is to be updated. |
| 1539 | * @param hostVlanId vlan of host for which Next obj is to be updated. |
| 1540 | * @param port port with which to update the Next Obj. |
| 1541 | * @param nextId of Next Obj which needs to be updated. |
| 1542 | */ |
| 1543 | public void updateL3UcastGroupBucket(MacAddress hostMac, VlanId hostVlanId, PortNumber port, int nextId) { |
| 1544 | |
| 1545 | MacAddress deviceMac; |
| 1546 | try { |
| 1547 | deviceMac = deviceConfig.getDeviceMac(deviceId); |
| 1548 | } catch (DeviceConfigNotFoundException e) { |
| 1549 | log.warn(e.getMessage() + " in updateL3UcastGroupBucket"); |
| 1550 | return; |
| 1551 | } |
| 1552 | |
| 1553 | TrafficSelector metadata = |
| 1554 | DefaultTrafficSelector.builder().matchVlanId(hostVlanId).build(); |
| 1555 | |
| 1556 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
| 1557 | tbuilder.deferred() |
| 1558 | .setEthDst(hostMac) |
| 1559 | .setEthSrc(deviceMac) |
| 1560 | .setVlanId(hostVlanId) |
| 1561 | .setOutput(port); |
| 1562 | |
| 1563 | log.debug(" update L3Ucast : deviceMac {}, port {}, host {}/{}, nextid {}, Treatment {} Meta {}", |
| 1564 | deviceMac, port, hostMac, hostVlanId, nextId, tbuilder.build(), metadata); |
| 1565 | |
| 1566 | NextObjective.Builder nextObjBuilder = DefaultNextObjective |
| 1567 | .builder().withId(nextId) |
| 1568 | .withType(NextObjective.Type.SIMPLE).fromApp(appId) |
| 1569 | .addTreatment(tbuilder.build()) |
| 1570 | .withMeta(metadata); |
| 1571 | |
| 1572 | ObjectiveContext context = new DefaultObjectiveContext( |
| 1573 | (objective) -> log.debug(" NextId {} successfully updated host {} vlan {} with port {}", |
| 1574 | nextId, hostMac, hostVlanId, port), |
| 1575 | (objective, error) -> { |
| 1576 | log.warn(" NextId {} failed to update host {} vlan {} with port {}, error : {}", |
| 1577 | nextId, hostMac, hostVlanId, port, error); |
| 1578 | srManager.invalidateNextObj(objective.id()); |
| 1579 | }); |
| 1580 | |
| 1581 | NextObjective nextObj = nextObjBuilder.modify(context); |
| 1582 | flowObjectiveService.next(deviceId, nextObj); |
| 1583 | |
| 1584 | } |
| 1585 | |
| 1586 | /** |
Jonghwan Hyun | f810a7a | 2018-02-12 16:43:45 +0900 | [diff] [blame] | 1587 | * Adds a single port to the L2FG or removes it from the L2FG. |
| 1588 | * |
| 1589 | * @param vlanId the vlan id corresponding to this port |
| 1590 | * @param portNum the port on this device to be updated |
| 1591 | * @param nextId the next objective ID for the given vlan id |
| 1592 | * @param install if true, adds the port to L2FG. If false, removes it from L2FG. |
| 1593 | */ |
| 1594 | public void updateGroupFromVlanConfiguration(VlanId vlanId, PortNumber portNum, int nextId, boolean install) { |
Jonghwan Hyun | 42fe105 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 1595 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 1596 | if (toPopVlan(portNum, vlanId)) { |
| 1597 | tBuilder.popVlan(); |
| 1598 | } |
| 1599 | tBuilder.setOutput(portNum); |
| 1600 | |
| 1601 | TrafficSelector metadata = |
| 1602 | DefaultTrafficSelector.builder().matchVlanId(vlanId).build(); |
| 1603 | |
| 1604 | NextObjective.Builder nextObjBuilder = DefaultNextObjective |
| 1605 | .builder().withId(nextId) |
| 1606 | .withType(NextObjective.Type.BROADCAST).fromApp(appId) |
| 1607 | .addTreatment(tBuilder.build()) |
| 1608 | .withMeta(metadata); |
| 1609 | |
| 1610 | ObjectiveContext context = new DefaultObjectiveContext( |
| 1611 | (objective) -> log.debug("port {} successfully removedFrom NextObj {} on {}", |
| 1612 | portNum, nextId, deviceId), |
Charles Chan | 55b806f | 2018-08-23 14:30:33 -0700 | [diff] [blame] | 1613 | (objective, error) -> { |
| 1614 | log.warn("port {} failed to removedFrom NextObj {} on {}: {}", portNum, nextId, deviceId, error); |
| 1615 | srManager.invalidateNextObj(objective.id()); |
| 1616 | }); |
Jonghwan Hyun | 42fe105 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 1617 | |
| 1618 | if (install) { |
| 1619 | flowObjectiveService.next(deviceId, nextObjBuilder.addToExisting(context)); |
| 1620 | } else { |
| 1621 | flowObjectiveService.next(deviceId, nextObjBuilder.removeFromExisting(context)); |
| 1622 | } |
| 1623 | } |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 1624 | |
| 1625 | /** |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 1626 | * Performs bucket verification operation for all hash groups in this device. |
| 1627 | * Checks RouteHandler to ensure that routing is stable before attempting |
| 1628 | * verification. Verification involves creating a nextObjective with |
| 1629 | * operation VERIFY for existing next objectives in the store, and passing |
| 1630 | * it to the driver. It is the driver that actually performs the verification |
| 1631 | * by adding or removing buckets to match the verification next objective |
| 1632 | * created here. |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 1633 | */ |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 1634 | protected final class BucketCorrector implements Runnable { |
| 1635 | Integer nextId; |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 1636 | |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 1637 | BucketCorrector() { |
| 1638 | this.nextId = null; |
| 1639 | } |
| 1640 | |
| 1641 | BucketCorrector(Integer nextId) { |
| 1642 | this.nextId = nextId; |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 1643 | } |
| 1644 | |
| 1645 | @Override |
| 1646 | public void run() { |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 1647 | if (!srManager.mastershipService.isLocalMaster(deviceId)) { |
| 1648 | return; |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 1649 | } |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 1650 | DefaultRoutingHandler rh = srManager.getRoutingHandler(); |
| 1651 | if (rh == null) { |
| 1652 | return; |
| 1653 | } |
| 1654 | if (!rh.isRoutingStable()) { |
| 1655 | return; |
| 1656 | } |
| 1657 | rh.acquireRoutingLock(); |
| 1658 | try { |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 1659 | log.trace("running bucket corrector for dev: {}", deviceId); |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 1660 | Set<DestinationSetNextObjectiveStoreKey> dsKeySet = dsNextObjStore.entrySet() |
| 1661 | .stream() |
| 1662 | .filter(entry -> entry.getKey().deviceId().equals(deviceId)) |
Pier Luigi | 63edd93 | 2018-01-14 21:56:11 +0100 | [diff] [blame] | 1663 | // Filter out PW transit groups or include them if MPLS ECMP is supported |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 1664 | .filter(entry -> !entry.getKey().destinationSet().notBos() || |
| 1665 | (entry.getKey().destinationSet().notBos() && srManager.getMplsEcmp())) |
| 1666 | // Filter out simple SWAP groups or include them if MPLS ECMP is supported |
| 1667 | .filter(entry -> !entry.getKey().destinationSet().swap() || |
| 1668 | (entry.getKey().destinationSet().swap() && srManager.getMplsEcmp())) |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 1669 | .map(entry -> entry.getKey()) |
| 1670 | .collect(Collectors.toSet()); |
| 1671 | for (DestinationSetNextObjectiveStoreKey dsKey : dsKeySet) { |
| 1672 | NextNeighbors next = dsNextObjStore.get(dsKey); |
| 1673 | if (next == null) { |
| 1674 | continue; |
| 1675 | } |
| 1676 | int nid = next.nextId(); |
| 1677 | if (nextId != null && nextId != nid) { |
| 1678 | continue; |
| 1679 | } |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 1680 | log.trace("bkt-corr: dsNextObjStore for device {}: {}", |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 1681 | deviceId, dsKey, next); |
| 1682 | TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder(); |
Saurav Das | 09c2c4d | 2018-08-13 15:34:26 -0700 | [diff] [blame] | 1683 | metabuilder.matchVlanId(srManager.getDefaultInternalVlan()); |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 1684 | NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder() |
| 1685 | .withId(nid) |
| 1686 | .withType(NextObjective.Type.HASHED) |
| 1687 | .withMeta(metabuilder.build()) |
| 1688 | .fromApp(appId); |
| 1689 | |
| 1690 | next.dstNextHops().forEach((dstDev, nextHops) -> { |
| 1691 | int edgeLabel = dsKey.destinationSet().getEdgeLabel(dstDev); |
| 1692 | nextHops.forEach(neighbor -> { |
| 1693 | MacAddress neighborMac; |
| 1694 | try { |
| 1695 | neighborMac = deviceConfig.getDeviceMac(neighbor); |
| 1696 | } catch (DeviceConfigNotFoundException e) { |
| 1697 | log.warn(e.getMessage() + " Aborting neighbor" |
| 1698 | + neighbor); |
| 1699 | return; |
| 1700 | } |
| 1701 | devicePortMap.get(neighbor).forEach(port -> { |
Saurav Das | 9df5b7c | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 1702 | log.trace("verify in device {} nextId {}: bucket with" |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 1703 | + " port/label {}/{} to dst {} via {}", |
| 1704 | deviceId, nid, port, edgeLabel, |
| 1705 | dstDev, neighbor); |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 1706 | nextObjBuilder |
| 1707 | .addTreatment(treatmentBuilder(port, |
| 1708 | neighborMac, |
| 1709 | dsKey.destinationSet().swap(), |
| 1710 | edgeLabel)); |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 1711 | }); |
| 1712 | }); |
| 1713 | }); |
| 1714 | |
| 1715 | NextObjective nextObjective = nextObjBuilder.verify(); |
| 1716 | flowObjectiveService.next(deviceId, nextObjective); |
| 1717 | } |
| 1718 | } finally { |
| 1719 | rh.releaseRoutingLock(); |
| 1720 | } |
| 1721 | |
| 1722 | } |
| 1723 | |
| 1724 | TrafficTreatment treatmentBuilder(PortNumber outport, MacAddress dstMac, |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 1725 | boolean swap, int edgeLabel) { |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 1726 | TrafficTreatment.Builder tBuilder = |
| 1727 | DefaultTrafficTreatment.builder(); |
| 1728 | tBuilder.setOutput(outport) |
| 1729 | .setEthDst(dstMac) |
| 1730 | .setEthSrc(nodeMacAddr); |
| 1731 | if (edgeLabel != DestinationSet.NO_EDGE_LABEL) { |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 1732 | if (swap) { |
| 1733 | // swap label case |
| 1734 | tBuilder.setMpls(MplsLabel.mplsLabel(edgeLabel)); |
| 1735 | } else { |
| 1736 | // ecmp with label push case |
| 1737 | tBuilder.pushMpls() |
| 1738 | .copyTtlOut() |
| 1739 | .setMpls(MplsLabel.mplsLabel(edgeLabel)); |
| 1740 | } |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 1741 | } |
| 1742 | return tBuilder.build(); |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 1743 | } |
| 1744 | } |
| 1745 | |
Charles Chan | e0260e1 | 2018-08-22 17:56:47 -0700 | [diff] [blame] | 1746 | /** |
| 1747 | * Determines whether the hash group bucket should include a popVlan action. |
| 1748 | * We don't popVlan for PW. |
| 1749 | * |
| 1750 | * @param ds destination set |
| 1751 | * @return true if VLAN needs to be popped |
| 1752 | */ |
| 1753 | private boolean popVlanInHashGroup(DestinationSet ds) { |
| 1754 | return (ds.getTypeOfDstSet() != DestinationSet.DestinationSetType.SWAP_NOT_BOS) && |
| 1755 | (ds.getTypeOfDstSet() != DestinationSet.DestinationSetType.POP_NOT_BOS); |
| 1756 | } |
Pier Luigi | 63edd93 | 2018-01-14 21:56:11 +0100 | [diff] [blame] | 1757 | } |