Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0947d7e | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [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 | */ |
| 16 | |
| 17 | package org.onosproject.segmentrouting; |
| 18 | |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 19 | import com.google.common.collect.Sets; |
| 20 | |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 21 | import org.onlab.packet.IpPrefix; |
| 22 | import org.onlab.packet.MacAddress; |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 23 | import org.onlab.packet.VlanId; |
Charles Chan | f0ae41e | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 24 | import org.onosproject.net.ConnectPoint; |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 25 | import org.onosproject.net.HostLocation; |
| 26 | import org.onosproject.net.PortNumber; |
| 27 | import org.onosproject.net.host.HostEvent; |
Ray Milkey | a815431 | 2017-08-08 13:00:43 -0700 | [diff] [blame] | 28 | import org.onosproject.routeservice.ResolvedRoute; |
| 29 | import org.onosproject.routeservice.RouteEvent; |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 30 | import org.onosproject.net.DeviceId; |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 31 | import org.onosproject.routeservice.RouteInfo; |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 32 | import org.slf4j.Logger; |
| 33 | import org.slf4j.LoggerFactory; |
| 34 | |
Ruchi Sahota | 71bcb4e | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 35 | import java.util.HashMap; |
Charles Chan | 5eec3b1 | 2019-04-18 14:30:41 -0700 | [diff] [blame^] | 36 | import java.util.List; |
Ruchi Sahota | 71bcb4e | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 37 | import java.util.Map; |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 38 | import java.util.Collection; |
Charles Chan | ee8dbf8 | 2017-06-22 14:15:05 -0700 | [diff] [blame] | 39 | import java.util.Objects; |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 40 | import java.util.Optional; |
| 41 | import java.util.Set; |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 42 | import java.util.stream.Collectors; |
Charles Chan | ee8dbf8 | 2017-06-22 14:15:05 -0700 | [diff] [blame] | 43 | |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 44 | /** |
| 45 | * Handles RouteEvent and manages routing entries. |
| 46 | */ |
| 47 | public class RouteHandler { |
| 48 | private static final Logger log = LoggerFactory.getLogger(RouteHandler.class); |
| 49 | private final SegmentRoutingManager srManager; |
| 50 | |
Charles Chan | f0ae41e | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 51 | RouteHandler(SegmentRoutingManager srManager) { |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 52 | this.srManager = srManager; |
| 53 | } |
| 54 | |
| 55 | protected void init(DeviceId deviceId) { |
Charles Chan | 7d20a4e | 2018-04-13 14:01:49 -0400 | [diff] [blame] | 56 | Optional<DeviceId> pairDeviceId = srManager.getPairDeviceId(deviceId); |
| 57 | |
| 58 | srManager.routeService.getRouteTables().stream() |
| 59 | .map(srManager.routeService::getRoutes) |
| 60 | .flatMap(Collection::stream) |
| 61 | .map(RouteInfo::allRoutes) |
| 62 | .filter(allRoutes -> allRoutes.stream().allMatch(resolvedRoute -> |
| 63 | srManager.nextHopLocations(resolvedRoute).stream().allMatch(cp -> |
| 64 | deviceId.equals(cp.deviceId()) || |
| 65 | (pairDeviceId.isPresent() && pairDeviceId.get().equals(cp.deviceId())) |
| 66 | ))) |
| 67 | .forEach(this::processRouteAddedInternal); |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Charles Chan | f0ae41e | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 70 | void processRouteAdded(RouteEvent event) { |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 71 | processRouteAddedInternal(event.alternatives()); |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 74 | private void processRouteAddedInternal(Collection<ResolvedRoute> routes) { |
Charles Chan | ee8dbf8 | 2017-06-22 14:15:05 -0700 | [diff] [blame] | 75 | if (!isReady()) { |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 76 | log.info("System is not ready. Skip adding route for {}", routes); |
Charles Chan | ee8dbf8 | 2017-06-22 14:15:05 -0700 | [diff] [blame] | 77 | return; |
| 78 | } |
| 79 | |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 80 | log.info("processRouteAddedInternal. routes={}", routes); |
Charles Chan | f0ae41e | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 81 | |
Charles Chan | 482b642 | 2018-04-09 11:52:08 -0400 | [diff] [blame] | 82 | if (routes.size() > 2) { |
| 83 | log.info("Route {} has more than two next hops. Do not process route change", routes); |
| 84 | return; |
| 85 | } |
| 86 | |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 87 | Set<ConnectPoint> allLocations = Sets.newHashSet(); |
| 88 | Set<IpPrefix> allPrefixes = Sets.newHashSet(); |
| 89 | routes.forEach(route -> { |
| 90 | allLocations.addAll(srManager.nextHopLocations(route)); |
| 91 | allPrefixes.add(route.prefix()); |
| 92 | }); |
| 93 | log.debug("RouteAdded. populateSubnet {}, {}", allLocations, allPrefixes); |
| 94 | srManager.defaultRoutingHandler.populateSubnet(allLocations, allPrefixes); |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 95 | |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 96 | routes.forEach(route -> { |
| 97 | IpPrefix prefix = route.prefix(); |
| 98 | MacAddress nextHopMac = route.nextHopMac(); |
| 99 | VlanId nextHopVlan = route.nextHopVlan(); |
| 100 | Set<ConnectPoint> locations = srManager.nextHopLocations(route); |
| 101 | |
| 102 | locations.forEach(location -> { |
| 103 | log.debug("RouteAdded. addSubnet {}, {}", location, prefix); |
| 104 | srManager.deviceConfiguration.addSubnet(location, prefix); |
| 105 | log.debug("RouteAdded populateRoute {}, {}, {}, {}", location, prefix, nextHopMac, nextHopVlan); |
| 106 | srManager.defaultRoutingHandler.populateRoute(location.deviceId(), prefix, |
Ruchi Sahota | 71bcb4e | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 107 | nextHopMac, nextHopVlan, location.port(), false); |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 108 | }); |
| 109 | }); |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Charles Chan | f0ae41e | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 112 | void processRouteUpdated(RouteEvent event) { |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 113 | processRouteUpdatedInternal(Sets.newHashSet(event.alternatives()), |
| 114 | Sets.newHashSet(event.prevAlternatives())); |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | void processAlternativeRoutesChanged(RouteEvent event) { |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 118 | processRouteUpdatedInternal(Sets.newHashSet(event.alternatives()), |
| 119 | Sets.newHashSet(event.prevAlternatives())); |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | private void processRouteUpdatedInternal(Set<ResolvedRoute> routes, Set<ResolvedRoute> oldRoutes) { |
| 123 | if (!isReady()) { |
| 124 | log.info("System is not ready. Skip updating route for {} -> {}", oldRoutes, routes); |
| 125 | return; |
| 126 | } |
| 127 | |
| 128 | log.info("processRouteUpdatedInternal. routes={}, oldRoutes={}", routes, oldRoutes); |
| 129 | |
Charles Chan | 482b642 | 2018-04-09 11:52:08 -0400 | [diff] [blame] | 130 | if (routes.size() > 2) { |
| 131 | log.info("Route {} has more than two next hops. Do not process route change", routes); |
| 132 | return; |
| 133 | } |
| 134 | |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 135 | Set<ConnectPoint> allLocations = Sets.newHashSet(); |
| 136 | Set<IpPrefix> allPrefixes = Sets.newHashSet(); |
| 137 | routes.forEach(route -> { |
| 138 | allLocations.addAll(srManager.nextHopLocations(route)); |
| 139 | allPrefixes.add(route.prefix()); |
| 140 | }); |
Charles Chan | 482b642 | 2018-04-09 11:52:08 -0400 | [diff] [blame] | 141 | |
| 142 | // Just come back from an invalid next hop count |
| 143 | // Revoke subnet from all locations and reset oldRoutes such that system will be reprogrammed from scratch |
| 144 | if (oldRoutes.size() > 2) { |
| 145 | log.info("Revoke subnet {} and reset oldRoutes"); |
| 146 | srManager.defaultRoutingHandler.revokeSubnet(allPrefixes); |
| 147 | oldRoutes = Sets.newHashSet(); |
| 148 | } |
| 149 | |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 150 | log.debug("RouteUpdated. populateSubnet {}, {}", allLocations, allPrefixes); |
| 151 | srManager.defaultRoutingHandler.populateSubnet(allLocations, allPrefixes); |
| 152 | |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 153 | Set<ResolvedRoute> toBeRemoved = Sets.difference(oldRoutes, routes).immutableCopy(); |
| 154 | Set<ResolvedRoute> toBeAdded = Sets.difference(routes, oldRoutes).immutableCopy(); |
| 155 | |
| 156 | toBeRemoved.forEach(route -> { |
| 157 | srManager.nextHopLocations(route).forEach(oldLocation -> { |
Charles Chan | 06f626c | 2018-02-05 17:20:05 -0800 | [diff] [blame] | 158 | if (toBeAdded.stream().map(srManager::nextHopLocations) |
| 159 | .flatMap(Set::stream).map(ConnectPoint::deviceId) |
| 160 | .noneMatch(deviceId -> deviceId.equals(oldLocation.deviceId()))) { |
| 161 | IpPrefix prefix = route.prefix(); |
| 162 | log.debug("RouteUpdated. removeSubnet {}, {}", oldLocation, prefix); |
| 163 | srManager.deviceConfiguration.removeSubnet(oldLocation, prefix); |
| 164 | // We don't remove the flow on the old location in occasion of two next hops becoming one |
| 165 | // since the populateSubnet will point the old location to the new location via spine. |
| 166 | } |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 167 | }); |
| 168 | }); |
| 169 | |
| 170 | toBeAdded.forEach(route -> { |
| 171 | IpPrefix prefix = route.prefix(); |
| 172 | MacAddress nextHopMac = route.nextHopMac(); |
| 173 | VlanId nextHopVlan = route.nextHopVlan(); |
| 174 | Set<ConnectPoint> locations = srManager.nextHopLocations(route); |
| 175 | |
| 176 | locations.forEach(location -> { |
| 177 | log.debug("RouteUpdated. addSubnet {}, {}", location, prefix); |
| 178 | srManager.deviceConfiguration.addSubnet(location, prefix); |
| 179 | log.debug("RouteUpdated. populateRoute {}, {}, {}, {}", location, prefix, nextHopMac, nextHopVlan); |
| 180 | srManager.defaultRoutingHandler.populateRoute(location.deviceId(), prefix, |
Ruchi Sahota | 71bcb4e | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 181 | nextHopMac, nextHopVlan, location.port(), false); |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 182 | }); |
| 183 | }); |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Charles Chan | f0ae41e | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 186 | void processRouteRemoved(RouteEvent event) { |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 187 | processRouteRemovedInternal(event.alternatives()); |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 190 | private void processRouteRemovedInternal(Collection<ResolvedRoute> routes) { |
Charles Chan | ee8dbf8 | 2017-06-22 14:15:05 -0700 | [diff] [blame] | 191 | if (!isReady()) { |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 192 | log.info("System is not ready. Skip removing route for {}", routes); |
Charles Chan | ee8dbf8 | 2017-06-22 14:15:05 -0700 | [diff] [blame] | 193 | return; |
| 194 | } |
| 195 | |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 196 | log.info("processRouteRemovedInternal. routes={}", routes); |
Charles Chan | f0ae41e | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 197 | |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 198 | Set<IpPrefix> allPrefixes = Sets.newHashSet(); |
| 199 | routes.forEach(route -> { |
| 200 | allPrefixes.add(route.prefix()); |
| 201 | }); |
| 202 | log.debug("RouteRemoved. revokeSubnet {}", allPrefixes); |
| 203 | srManager.defaultRoutingHandler.revokeSubnet(allPrefixes); |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 204 | |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 205 | routes.forEach(route -> { |
| 206 | IpPrefix prefix = route.prefix(); |
| 207 | MacAddress nextHopMac = route.nextHopMac(); |
| 208 | VlanId nextHopVlan = route.nextHopVlan(); |
| 209 | Set<ConnectPoint> locations = srManager.nextHopLocations(route); |
| 210 | |
| 211 | locations.forEach(location -> { |
| 212 | log.debug("RouteRemoved. removeSubnet {}, {}", location, prefix); |
| 213 | srManager.deviceConfiguration.removeSubnet(location, prefix); |
Charles Chan | c4d6888 | 2018-03-15 16:41:10 -0700 | [diff] [blame] | 214 | // We don't need to call revokeRoute again since revokeSubnet will remove the prefix |
| 215 | // from all devices, including the ones that next hop attaches to. |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 216 | |
| 217 | // Also remove redirection flows on the pair device if exists. |
| 218 | Optional<DeviceId> pairDeviceId = srManager.getPairDeviceId(location.deviceId()); |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 219 | Optional<PortNumber> pairLocalPort = srManager.getPairLocalPort(location.deviceId()); |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 220 | if (pairDeviceId.isPresent() && pairLocalPort.isPresent()) { |
| 221 | // NOTE: Since the pairLocalPort is trunk port, use assigned vlan of original port |
| 222 | // when the host is untagged |
| 223 | VlanId vlanId = Optional.ofNullable(srManager.getInternalVlanId(location)).orElse(nextHopVlan); |
| 224 | |
| 225 | log.debug("RouteRemoved. revokeRoute {}, {}, {}, {}", location, prefix, nextHopMac, nextHopVlan); |
| 226 | srManager.defaultRoutingHandler.revokeRoute(pairDeviceId.get(), prefix, |
Ruchi Sahota | 71bcb4e | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 227 | nextHopMac, vlanId, pairLocalPort.get(), false); |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 228 | } |
| 229 | }); |
| 230 | }); |
| 231 | } |
| 232 | |
| 233 | void processHostMovedEvent(HostEvent event) { |
| 234 | log.info("processHostMovedEvent {}", event); |
| 235 | MacAddress hostMac = event.subject().mac(); |
| 236 | VlanId hostVlanId = event.subject().vlan(); |
Ruchi Sahota | 71bcb4e | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 237 | // map of nextId for prev port in each device |
| 238 | Map<DeviceId, Integer> nextIdMap = new HashMap<>(); |
Charles Chan | 5eec3b1 | 2019-04-18 14:30:41 -0700 | [diff] [blame^] | 239 | Set<HostLocation> prevLocations = event.prevSubject().locations(); |
| 240 | Set<HostLocation> newLocations = event.subject().locations(); |
| 241 | Set<ConnectPoint> connectPoints = newLocations.stream().map(l -> (ConnectPoint) l).collect(Collectors.toSet()); |
| 242 | List<Set<IpPrefix>> batchedSubnets = |
| 243 | srManager.deviceConfiguration.getBatchedSubnets(event.subject().id()); |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 244 | |
Charles Chan | 5eec3b1 | 2019-04-18 14:30:41 -0700 | [diff] [blame^] | 245 | batchedSubnets.forEach(subnets -> { |
| 246 | log.debug("HostMoved. populateSubnet {}, {}", newLocations, subnets); |
| 247 | srManager.defaultRoutingHandler.populateSubnet(connectPoints, subnets); |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 248 | |
Charles Chan | 5eec3b1 | 2019-04-18 14:30:41 -0700 | [diff] [blame^] | 249 | subnets.forEach(prefix -> { |
| 250 | Set<DeviceId> newDeviceIds = newLocations.stream().map(HostLocation::deviceId) |
| 251 | .collect(Collectors.toSet()); |
Charles Chan | 0720379 | 2018-07-17 16:33:11 -0700 | [diff] [blame] | 252 | |
Charles Chan | 5eec3b1 | 2019-04-18 14:30:41 -0700 | [diff] [blame^] | 253 | // Set of deviceIDs of the previous locations where the host was connected |
| 254 | // Used to determine if host moved to different connect points |
| 255 | // on same device or moved to a different device altogether |
| 256 | Set<DeviceId> oldDeviceIds = prevLocations.stream().map(HostLocation::deviceId) |
| 257 | .collect(Collectors.toSet()); |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 258 | |
Charles Chan | 5eec3b1 | 2019-04-18 14:30:41 -0700 | [diff] [blame^] | 259 | // For each old location |
| 260 | Sets.difference(prevLocations, newLocations).forEach(prevLocation -> { |
| 261 | //find next Id for each old port, add to map |
| 262 | int nextId = srManager.getNextIdForHostPort(prevLocation.deviceId(), hostMac, |
| 263 | hostVlanId, prevLocation.port()); |
| 264 | log.debug("HostMoved. NextId For Host {}, {}, {}, {} {}", prevLocation, prefix, |
| 265 | hostMac, hostVlanId, nextId); |
Ruchi Sahota | 71bcb4e | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 266 | |
Charles Chan | 5eec3b1 | 2019-04-18 14:30:41 -0700 | [diff] [blame^] | 267 | nextIdMap.put(prevLocation.deviceId(), nextId); |
Ruchi Sahota | 71bcb4e | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 268 | |
Charles Chan | 5eec3b1 | 2019-04-18 14:30:41 -0700 | [diff] [blame^] | 269 | // Remove flows for unchanged IPs only when the host moves from a switch to another. |
| 270 | // Otherwise, do not remove and let the adding part update the old flow |
| 271 | if (newDeviceIds.contains(prevLocation.deviceId())) { |
| 272 | return; |
| 273 | } |
Ruchi Sahota | 71bcb4e | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 274 | |
Charles Chan | 5eec3b1 | 2019-04-18 14:30:41 -0700 | [diff] [blame^] | 275 | log.debug("HostMoved. removeSubnet {}, {}", prevLocation, prefix); |
| 276 | srManager.deviceConfiguration.removeSubnet(prevLocation, prefix); |
Charles Chan | 4dcd510 | 2019-02-28 15:40:57 -0800 | [diff] [blame] | 277 | |
Charles Chan | 5eec3b1 | 2019-04-18 14:30:41 -0700 | [diff] [blame^] | 278 | // Do not remove flow from a device if the route is still reachable via its pair device. |
| 279 | // populateSubnet will update the flow to point to its pair device via spine. |
| 280 | DeviceId pairDeviceId = srManager.getPairDeviceId(prevLocation.deviceId()).orElse(null); |
| 281 | if (newLocations.stream().anyMatch(n -> n.deviceId().equals(pairDeviceId))) { |
| 282 | return; |
| 283 | } |
Charles Chan | 4dcd510 | 2019-02-28 15:40:57 -0800 | [diff] [blame] | 284 | |
Charles Chan | 5eec3b1 | 2019-04-18 14:30:41 -0700 | [diff] [blame^] | 285 | log.debug("HostMoved. revokeRoute {}, {}, {}, {}", prevLocation, prefix, hostMac, hostVlanId); |
| 286 | srManager.defaultRoutingHandler.revokeRoute(prevLocation.deviceId(), prefix, |
| 287 | hostMac, hostVlanId, prevLocation.port(), false); |
| 288 | }); |
Charles Chan | 4dcd510 | 2019-02-28 15:40:57 -0800 | [diff] [blame] | 289 | |
Charles Chan | 5eec3b1 | 2019-04-18 14:30:41 -0700 | [diff] [blame^] | 290 | // For each new location, add all new IPs. |
| 291 | Sets.difference(newLocations, prevLocations).forEach(newLocation -> { |
| 292 | log.debug("HostMoved. addSubnet {}, {}", newLocation, prefix); |
| 293 | srManager.deviceConfiguration.addSubnet(newLocation, prefix); |
| 294 | |
| 295 | //its a new connect point, not a move from an existing device, populateRoute |
| 296 | if (!oldDeviceIds.contains(newLocation.deviceId())) { |
| 297 | log.debug("HostMoved. populateRoute {}, {}, {}, {}", newLocation, prefix, hostMac, hostVlanId); |
| 298 | srManager.defaultRoutingHandler.populateRoute(newLocation.deviceId(), prefix, |
| 299 | hostMac, hostVlanId, newLocation.port(), false); |
| 300 | } else { |
| 301 | // update same flow to point to new nextObj |
| 302 | VlanId vlanId = Optional.ofNullable(srManager.getInternalVlanId(newLocation)).orElse(hostVlanId); |
| 303 | //use nextIdMap to send new port details to update the nextId group bucket |
| 304 | log.debug("HostMoved. update L3 Ucast Group Bucket {}, {}, {} --> {}", |
| 305 | newLocation, hostMac, vlanId, nextIdMap.get(newLocation.deviceId())); |
| 306 | srManager.updateMacVlanTreatment(newLocation.deviceId(), hostMac, vlanId, |
| 307 | newLocation.port(), nextIdMap.get(newLocation.deviceId())); |
| 308 | } |
| 309 | }); |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 310 | }); |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 311 | }); |
| 312 | } |
| 313 | |
Charles Chan | ee8dbf8 | 2017-06-22 14:15:05 -0700 | [diff] [blame] | 314 | private boolean isReady() { |
| 315 | return Objects.nonNull(srManager.deviceConfiguration) && |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 316 | Objects.nonNull(srManager.defaultRoutingHandler); |
| 317 | } |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 318 | } |