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