blob: dc1a25a7a95fbf24a1c7113aafe8680e162ab598 [file] [log] [blame]
Charles Chandebfea32016-10-24 14:52:01 -07001/*
Brian O'Connor0947d7e2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Charles Chandebfea32016-10-24 14:52:01 -07003 *
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
17package org.onosproject.segmentrouting;
18
Saurav Das261c3002017-06-13 15:35:54 -070019import com.google.common.collect.Sets;
20
Charles Chandebfea32016-10-24 14:52:01 -070021import org.onlab.packet.IpPrefix;
22import org.onlab.packet.MacAddress;
Charles Chan90772a72017-02-08 15:52:08 -080023import org.onlab.packet.VlanId;
Charles Chanf0ae41e2017-08-23 13:55:39 -070024import org.onosproject.net.ConnectPoint;
pierventrea3989be2021-01-08 16:43:17 +010025import org.onosproject.net.Host;
Charles Chan910be6a2017-08-23 14:46:43 -070026import org.onosproject.net.PortNumber;
27import org.onosproject.net.host.HostEvent;
Ray Milkeya8154312017-08-08 13:00:43 -070028import org.onosproject.routeservice.ResolvedRoute;
29import org.onosproject.routeservice.RouteEvent;
Charles Chandebfea32016-10-24 14:52:01 -070030import org.onosproject.net.DeviceId;
Charles Chan910be6a2017-08-23 14:46:43 -070031import org.onosproject.routeservice.RouteInfo;
Charles Chanfab61472021-06-14 23:31:23 -070032import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException;
Charles Chandebfea32016-10-24 14:52:01 -070033import org.slf4j.Logger;
34import org.slf4j.LoggerFactory;
35
Charles Chan5eec3b12019-04-18 14:30:41 -070036import java.util.List;
Charles Chan910be6a2017-08-23 14:46:43 -070037import java.util.Collection;
Charles Chanee8dbf82017-06-22 14:15:05 -070038import java.util.Objects;
Charles Chan910be6a2017-08-23 14:46:43 -070039import java.util.Optional;
40import java.util.Set;
Charles Chan910be6a2017-08-23 14:46:43 -070041import java.util.stream.Collectors;
Charles Chanee8dbf82017-06-22 14:15:05 -070042
Charles Chandebfea32016-10-24 14:52:01 -070043/**
44 * Handles RouteEvent and manages routing entries.
45 */
46public class RouteHandler {
47 private static final Logger log = LoggerFactory.getLogger(RouteHandler.class);
48 private final SegmentRoutingManager srManager;
49
Charles Chanf0ae41e2017-08-23 13:55:39 -070050 RouteHandler(SegmentRoutingManager srManager) {
Charles Chandebfea32016-10-24 14:52:01 -070051 this.srManager = srManager;
52 }
53
54 protected void init(DeviceId deviceId) {
Charles Chan7d20a4e2018-04-13 14:01:49 -040055 srManager.routeService.getRouteTables().stream()
56 .map(srManager.routeService::getRoutes)
57 .flatMap(Collection::stream)
58 .map(RouteInfo::allRoutes)
Charles Chan12a8a842020-02-14 13:23:57 -080059 .filter(allRoutes -> allRoutes.stream().anyMatch(resolvedRoute ->
60 srManager.nextHopLocations(resolvedRoute).stream()
61 .anyMatch(cp -> deviceId.equals(cp.deviceId()))))
62 .forEach(rr -> processRouteAddedInternal(rr, true));
Charles Chandebfea32016-10-24 14:52:01 -070063 }
64
Charles Chanf0ae41e2017-08-23 13:55:39 -070065 void processRouteAdded(RouteEvent event) {
Charles Chan12a8a842020-02-14 13:23:57 -080066 processRouteAddedInternal(event.alternatives(), false);
Charles Chandebfea32016-10-24 14:52:01 -070067 }
68
Charles Chan12a8a842020-02-14 13:23:57 -080069 /**
70 * Internal logic that handles route addition.
71 *
72 * @param routes collection of routes to be processed
73 * @param populateRouteOnly true if we only want to populateRoute but not populateSubnet.
74 * Set it to true when initializing a device coming up.
75 * populateSubnet will be done when link comes up later so it is redundant.
76 * populateRoute still needs to be done for statically configured next hop hosts.
77 */
78 private void processRouteAddedInternal(Collection<ResolvedRoute> routes, boolean populateRouteOnly) {
Charles Chanee8dbf82017-06-22 14:15:05 -070079 if (!isReady()) {
Charles Chan910be6a2017-08-23 14:46:43 -070080 log.info("System is not ready. Skip adding route for {}", routes);
Charles Chanee8dbf82017-06-22 14:15:05 -070081 return;
82 }
83
Charles Chan910be6a2017-08-23 14:46:43 -070084 log.info("processRouteAddedInternal. routes={}", routes);
Charles Chanf0ae41e2017-08-23 13:55:39 -070085
Charles Chan482b6422018-04-09 11:52:08 -040086 if (routes.size() > 2) {
87 log.info("Route {} has more than two next hops. Do not process route change", routes);
88 return;
89 }
90
Charles Chanfab61472021-06-14 23:31:23 -070091 if (routes.isEmpty()) {
Charles Chan12a8a842020-02-14 13:23:57 -080092 log.warn("No resolved route found. Abort processRouteAddedInternal");
Charles Chanfab61472021-06-14 23:31:23 -070093 return;
Charles Chan12a8a842020-02-14 13:23:57 -080094 }
95
Charles Chan910be6a2017-08-23 14:46:43 -070096 Set<ConnectPoint> allLocations = Sets.newHashSet();
97 Set<IpPrefix> allPrefixes = Sets.newHashSet();
98 routes.forEach(route -> {
99 allLocations.addAll(srManager.nextHopLocations(route));
100 allPrefixes.add(route.prefix());
101 });
102 log.debug("RouteAdded. populateSubnet {}, {}", allLocations, allPrefixes);
103 srManager.defaultRoutingHandler.populateSubnet(allLocations, allPrefixes);
Charles Chandebfea32016-10-24 14:52:01 -0700104
Charles Chan910be6a2017-08-23 14:46:43 -0700105 routes.forEach(route -> {
106 IpPrefix prefix = route.prefix();
107 MacAddress nextHopMac = route.nextHopMac();
108 VlanId nextHopVlan = route.nextHopVlan();
109 Set<ConnectPoint> locations = srManager.nextHopLocations(route);
110
111 locations.forEach(location -> {
112 log.debug("RouteAdded. addSubnet {}, {}", location, prefix);
113 srManager.deviceConfiguration.addSubnet(location, prefix);
114 log.debug("RouteAdded populateRoute {}, {}, {}, {}", location, prefix, nextHopMac, nextHopVlan);
115 srManager.defaultRoutingHandler.populateRoute(location.deviceId(), prefix,
Ruchi Sahota71bcb4e2019-01-28 01:08:18 +0000116 nextHopMac, nextHopVlan, location.port(), false);
Charles Chanfab61472021-06-14 23:31:23 -0700117
118 processSingleLeafPairIfNeeded(locations, location, prefix, nextHopVlan);
Charles Chan910be6a2017-08-23 14:46:43 -0700119 });
120 });
Charles Chandebfea32016-10-24 14:52:01 -0700121 }
122
Charles Chanf0ae41e2017-08-23 13:55:39 -0700123 void processRouteUpdated(RouteEvent event) {
Charles Chanfbcb8812018-04-18 18:41:05 -0700124 processRouteUpdatedInternal(Sets.newHashSet(event.alternatives()),
125 Sets.newHashSet(event.prevAlternatives()));
Charles Chan910be6a2017-08-23 14:46:43 -0700126 }
127
128 void processAlternativeRoutesChanged(RouteEvent event) {
Charles Chanfbcb8812018-04-18 18:41:05 -0700129 processRouteUpdatedInternal(Sets.newHashSet(event.alternatives()),
130 Sets.newHashSet(event.prevAlternatives()));
Charles Chan910be6a2017-08-23 14:46:43 -0700131 }
132
133 private void processRouteUpdatedInternal(Set<ResolvedRoute> routes, Set<ResolvedRoute> oldRoutes) {
134 if (!isReady()) {
135 log.info("System is not ready. Skip updating route for {} -> {}", oldRoutes, routes);
136 return;
137 }
138
139 log.info("processRouteUpdatedInternal. routes={}, oldRoutes={}", routes, oldRoutes);
140
Charles Chan482b6422018-04-09 11:52:08 -0400141 if (routes.size() > 2) {
142 log.info("Route {} has more than two next hops. Do not process route change", routes);
143 return;
144 }
145
Charles Chan910be6a2017-08-23 14:46:43 -0700146 Set<ConnectPoint> allLocations = Sets.newHashSet();
147 Set<IpPrefix> allPrefixes = Sets.newHashSet();
148 routes.forEach(route -> {
149 allLocations.addAll(srManager.nextHopLocations(route));
150 allPrefixes.add(route.prefix());
151 });
Charles Chan482b6422018-04-09 11:52:08 -0400152
153 // Just come back from an invalid next hop count
154 // Revoke subnet from all locations and reset oldRoutes such that system will be reprogrammed from scratch
155 if (oldRoutes.size() > 2) {
156 log.info("Revoke subnet {} and reset oldRoutes");
157 srManager.defaultRoutingHandler.revokeSubnet(allPrefixes);
158 oldRoutes = Sets.newHashSet();
159 }
160
Charles Chan910be6a2017-08-23 14:46:43 -0700161 log.debug("RouteUpdated. populateSubnet {}, {}", allLocations, allPrefixes);
162 srManager.defaultRoutingHandler.populateSubnet(allLocations, allPrefixes);
163
Charles Chan910be6a2017-08-23 14:46:43 -0700164 Set<ResolvedRoute> toBeRemoved = Sets.difference(oldRoutes, routes).immutableCopy();
165 Set<ResolvedRoute> toBeAdded = Sets.difference(routes, oldRoutes).immutableCopy();
166
167 toBeRemoved.forEach(route -> {
168 srManager.nextHopLocations(route).forEach(oldLocation -> {
Charles Chan06f626c2018-02-05 17:20:05 -0800169 if (toBeAdded.stream().map(srManager::nextHopLocations)
170 .flatMap(Set::stream).map(ConnectPoint::deviceId)
171 .noneMatch(deviceId -> deviceId.equals(oldLocation.deviceId()))) {
172 IpPrefix prefix = route.prefix();
173 log.debug("RouteUpdated. removeSubnet {}, {}", oldLocation, prefix);
174 srManager.deviceConfiguration.removeSubnet(oldLocation, prefix);
175 // We don't remove the flow on the old location in occasion of two next hops becoming one
176 // since the populateSubnet will point the old location to the new location via spine.
177 }
Charles Chan910be6a2017-08-23 14:46:43 -0700178 });
179 });
180
181 toBeAdded.forEach(route -> {
182 IpPrefix prefix = route.prefix();
183 MacAddress nextHopMac = route.nextHopMac();
184 VlanId nextHopVlan = route.nextHopVlan();
185 Set<ConnectPoint> locations = srManager.nextHopLocations(route);
186
187 locations.forEach(location -> {
188 log.debug("RouteUpdated. addSubnet {}, {}", location, prefix);
189 srManager.deviceConfiguration.addSubnet(location, prefix);
190 log.debug("RouteUpdated. populateRoute {}, {}, {}, {}", location, prefix, nextHopMac, nextHopVlan);
191 srManager.defaultRoutingHandler.populateRoute(location.deviceId(), prefix,
Ruchi Sahota71bcb4e2019-01-28 01:08:18 +0000192 nextHopMac, nextHopVlan, location.port(), false);
Charles Chanfab61472021-06-14 23:31:23 -0700193
194 processSingleLeafPairIfNeeded(locations, location, prefix, nextHopVlan);
Charles Chan910be6a2017-08-23 14:46:43 -0700195 });
196 });
Charles Chandebfea32016-10-24 14:52:01 -0700197 }
198
Charles Chanf0ae41e2017-08-23 13:55:39 -0700199 void processRouteRemoved(RouteEvent event) {
Charles Chanfbcb8812018-04-18 18:41:05 -0700200 processRouteRemovedInternal(event.alternatives());
Charles Chandebfea32016-10-24 14:52:01 -0700201 }
202
Charles Chan910be6a2017-08-23 14:46:43 -0700203 private void processRouteRemovedInternal(Collection<ResolvedRoute> routes) {
Charles Chanee8dbf82017-06-22 14:15:05 -0700204 if (!isReady()) {
Charles Chan910be6a2017-08-23 14:46:43 -0700205 log.info("System is not ready. Skip removing route for {}", routes);
Charles Chanee8dbf82017-06-22 14:15:05 -0700206 return;
207 }
208
Charles Chan910be6a2017-08-23 14:46:43 -0700209 log.info("processRouteRemovedInternal. routes={}", routes);
Charles Chanf0ae41e2017-08-23 13:55:39 -0700210
Charles Chan910be6a2017-08-23 14:46:43 -0700211 Set<IpPrefix> allPrefixes = Sets.newHashSet();
212 routes.forEach(route -> {
213 allPrefixes.add(route.prefix());
214 });
215 log.debug("RouteRemoved. revokeSubnet {}", allPrefixes);
216 srManager.defaultRoutingHandler.revokeSubnet(allPrefixes);
Charles Chandebfea32016-10-24 14:52:01 -0700217
Charles Chan910be6a2017-08-23 14:46:43 -0700218 routes.forEach(route -> {
219 IpPrefix prefix = route.prefix();
220 MacAddress nextHopMac = route.nextHopMac();
221 VlanId nextHopVlan = route.nextHopVlan();
222 Set<ConnectPoint> locations = srManager.nextHopLocations(route);
223
224 locations.forEach(location -> {
225 log.debug("RouteRemoved. removeSubnet {}, {}", location, prefix);
226 srManager.deviceConfiguration.removeSubnet(location, prefix);
Charles Chanc4d68882018-03-15 16:41:10 -0700227 // We don't need to call revokeRoute again since revokeSubnet will remove the prefix
228 // from all devices, including the ones that next hop attaches to.
Charles Chanfab61472021-06-14 23:31:23 -0700229 // revokeSubnet will also remove flow on the pair device (if exist) pointing to current location.
Charles Chan910be6a2017-08-23 14:46:43 -0700230 });
231 });
232 }
233
234 void processHostMovedEvent(HostEvent event) {
235 log.info("processHostMovedEvent {}", event);
236 MacAddress hostMac = event.subject().mac();
237 VlanId hostVlanId = event.subject().vlan();
Ruchi Sahota07869322019-05-09 17:26:14 -0400238
Charles Chanfab61472021-06-14 23:31:23 -0700239 Set<ConnectPoint> prevLocations = event.prevSubject().locations()
240 .stream().map(h -> (ConnectPoint) h)
241 .collect(Collectors.toSet());
242 Set<ConnectPoint> newLocations = event.subject().locations()
243 .stream().map(h -> (ConnectPoint) h)
244 .collect(Collectors.toSet());
Charles Chan5eec3b12019-04-18 14:30:41 -0700245 List<Set<IpPrefix>> batchedSubnets =
246 srManager.deviceConfiguration.getBatchedSubnets(event.subject().id());
Charles Chanfab61472021-06-14 23:31:23 -0700247 Set<DeviceId> newDeviceIds = newLocations.stream().map(ConnectPoint::deviceId)
Ruchi Sahota07869322019-05-09 17:26:14 -0400248 .collect(Collectors.toSet());
249
250 // Set of deviceIDs of the previous locations where the host was connected
251 // Used to determine if host moved to different connect points
252 // on same device or moved to a different device altogether
Charles Chanfab61472021-06-14 23:31:23 -0700253 Set<DeviceId> oldDeviceIds = prevLocations.stream().map(ConnectPoint::deviceId)
Ruchi Sahota07869322019-05-09 17:26:14 -0400254 .collect(Collectors.toSet());
255
256 // L3 Ucast bucket needs to be updated only once per host
257 // and only when the no. of routes with the host as next-hop is not zero
258 if (!batchedSubnets.isEmpty()) {
259 // For each new location, if NextObj exists for the host, update with new location ..
260 Sets.difference(newLocations, prevLocations).forEach(newLocation -> {
pierventrea3989be2021-01-08 16:43:17 +0100261 // NOTE: that we use the nexthop vlanId to retrieve the nextId
262 // while the vlanId used to program the L3 unicast chain
263 // is derived from the port configuration. In case of
264 // a tagged interface we use host vlanId. Host vlan should
265 // be part of the tags configured for that port. See the
266 // code in DefaultGroupHandler.updateL3UcastGroupBucket
267 int nextId = srManager.getMacVlanNextObjectiveId(newLocation.deviceId(),
268 hostMac, hostVlanId, null, false);
269 if (nextId != -1) {
270 //Update the nextId group bucket
271 log.debug("HostMoved. NextId exists, update L3 Ucast Group Bucket {}, {}, {} --> {}",
272 newLocation, hostMac, hostVlanId, nextId);
273 srManager.updateMacVlanTreatment(newLocation.deviceId(), hostMac, hostVlanId,
274 newLocation.port(), nextId);
275 } else {
276 log.debug("HostMoved. NextId does not exist for this location {}, host {}/{}",
277 newLocation, hostMac, hostVlanId);
278 }
Ruchi Sahota07869322019-05-09 17:26:14 -0400279 });
280 }
Charles Chan910be6a2017-08-23 14:46:43 -0700281
Charles Chan5eec3b12019-04-18 14:30:41 -0700282 batchedSubnets.forEach(subnets -> {
283 log.debug("HostMoved. populateSubnet {}, {}", newLocations, subnets);
Charles Chanfab61472021-06-14 23:31:23 -0700284 srManager.defaultRoutingHandler.populateSubnet(newLocations, subnets);
Charles Chan910be6a2017-08-23 14:46:43 -0700285
Charles Chan5eec3b12019-04-18 14:30:41 -0700286 subnets.forEach(prefix -> {
Charles Chan5eec3b12019-04-18 14:30:41 -0700287 // For each old location
288 Sets.difference(prevLocations, newLocations).forEach(prevLocation -> {
Ruchi Sahota71bcb4e2019-01-28 01:08:18 +0000289
Charles Chan5eec3b12019-04-18 14:30:41 -0700290 // Remove flows for unchanged IPs only when the host moves from a switch to another.
291 // Otherwise, do not remove and let the adding part update the old flow
292 if (newDeviceIds.contains(prevLocation.deviceId())) {
293 return;
294 }
Ruchi Sahota71bcb4e2019-01-28 01:08:18 +0000295
Charles Chan5eec3b12019-04-18 14:30:41 -0700296 log.debug("HostMoved. removeSubnet {}, {}", prevLocation, prefix);
297 srManager.deviceConfiguration.removeSubnet(prevLocation, prefix);
Charles Chan4dcd5102019-02-28 15:40:57 -0800298
Charles Chan5eec3b12019-04-18 14:30:41 -0700299 // Do not remove flow from a device if the route is still reachable via its pair device.
Charles Chanfab61472021-06-14 23:31:23 -0700300 // If spine exists,
301 // populateSubnet above will update the flow to point to its pair device via spine.
302 // If spine does not exist,
303 // processSingleLeafPair below will update the flow to point to its pair device via pair port.
Charles Chan5eec3b12019-04-18 14:30:41 -0700304 DeviceId pairDeviceId = srManager.getPairDeviceId(prevLocation.deviceId()).orElse(null);
305 if (newLocations.stream().anyMatch(n -> n.deviceId().equals(pairDeviceId))) {
306 return;
307 }
Charles Chan4dcd5102019-02-28 15:40:57 -0800308
Charles Chan5eec3b12019-04-18 14:30:41 -0700309 log.debug("HostMoved. revokeRoute {}, {}, {}, {}", prevLocation, prefix, hostMac, hostVlanId);
310 srManager.defaultRoutingHandler.revokeRoute(prevLocation.deviceId(), prefix,
311 hostMac, hostVlanId, prevLocation.port(), false);
312 });
Charles Chan4dcd5102019-02-28 15:40:57 -0800313
Charles Chan5eec3b12019-04-18 14:30:41 -0700314 // For each new location, add all new IPs.
315 Sets.difference(newLocations, prevLocations).forEach(newLocation -> {
316 log.debug("HostMoved. addSubnet {}, {}", newLocation, prefix);
317 srManager.deviceConfiguration.addSubnet(newLocation, prefix);
318
319 //its a new connect point, not a move from an existing device, populateRoute
320 if (!oldDeviceIds.contains(newLocation.deviceId())) {
321 log.debug("HostMoved. populateRoute {}, {}, {}, {}", newLocation, prefix, hostMac, hostVlanId);
322 srManager.defaultRoutingHandler.populateRoute(newLocation.deviceId(), prefix,
323 hostMac, hostVlanId, newLocation.port(), false);
Charles Chan5eec3b12019-04-18 14:30:41 -0700324 }
325 });
Charles Chanfab61472021-06-14 23:31:23 -0700326
327 newLocations.forEach(location -> {
328 processSingleLeafPairIfNeeded(newLocations, location, prefix, hostVlanId);
329 });
Charles Chan910be6a2017-08-23 14:46:43 -0700330 });
Charles Chan910be6a2017-08-23 14:46:43 -0700331 });
Ruchi Sahota07869322019-05-09 17:26:14 -0400332
Charles Chan910be6a2017-08-23 14:46:43 -0700333 }
334
pierventrea3989be2021-01-08 16:43:17 +0100335 public void processIntfVlanUpdatedEvent(DeviceId deviceId, PortNumber portNum) {
336 log.info("processIntfVlanUpdatedEvent {}/{}", deviceId, portNum);
337
338 // Verify there are hosts attached to the port
339 ConnectPoint connectPoint = new ConnectPoint(deviceId, portNum);
340 Set<Host> hosts = srManager.hostService.getConnectedHosts(connectPoint);
341 if (hosts == null || hosts.size() == 0) {
342 log.debug("processIntfVlanUpdatedEvent: No hosts connected to {}", connectPoint);
343 return;
344 }
345
346 // Iterate over the hosts and update if needed the vlan of the nextobjective
347 hosts.forEach(host -> {
348 // Verify if there is a nexthop and only then update the l3 indirect unicast chain
349 int nextId = srManager.getMacVlanNextObjectiveId(deviceId, host.mac(), host.vlan(),
350 null, false);
351 if (nextId != -1) {
352 //Update the nextId group bucket
353 log.debug("intfVlanUpdated. NextId exists, update L3 Ucast Group Bucket {}, {}, {} --> {}",
354 connectPoint, host.mac(), host.vlan(), nextId);
355 // NOTE: that we use the nexthop vlanId to retrieve the nextId
356 // while the vlanId used to program the L3 unicast chain
357 // is derived from the port configuration. In case of
358 // a tagged interface we use host vlanId. Host vlan should
359 // be part of the tags configured for that port. See the
360 // code in DefaultGroupHandler.updateL3UcastGroupBucket
361 srManager.updateMacVlanTreatment(deviceId, host.mac(), host.vlan(), portNum, nextId);
362 } else {
363 log.debug("intfVlanUpdated. NextId does not exist for this location {}, host {}/{}",
364 connectPoint, host.mac(), host.vlan());
365 }
366 });
367 }
368
Charles Chanee8dbf82017-06-22 14:15:05 -0700369 private boolean isReady() {
370 return Objects.nonNull(srManager.deviceConfiguration) &&
Charles Chan910be6a2017-08-23 14:46:43 -0700371 Objects.nonNull(srManager.defaultRoutingHandler);
372 }
Charles Chanfab61472021-06-14 23:31:23 -0700373
374 protected boolean processSingleLeafPairIfNeeded(Set<ConnectPoint> locations, ConnectPoint location, IpPrefix prefix,
375 VlanId nextHopVlan) {
376 // Special handling for single leaf pair
377 if (!srManager.getInfraDeviceIds().isEmpty()) {
378 log.debug("Spine found. Skip single leaf pair handling");
379 return false;
380 }
381 Optional<DeviceId> pairDeviceId = srManager.getPairDeviceId(location.deviceId());
382 if (pairDeviceId.isEmpty()) {
383 log.debug("Pair device of {} not found", location.deviceId());
384 return false;
385 }
386 if (locations.stream().anyMatch(l -> l.deviceId().equals(pairDeviceId.get()))) {
387 log.debug("Pair device has a next hop available. Leave it as is.");
388 return false;
389 }
390 Optional<PortNumber> pairRemotePort = srManager.getPairLocalPort(pairDeviceId.get());
391 if (pairRemotePort.isEmpty()) {
392 log.debug("Pair remote port of {} not found", pairDeviceId.get());
393 return false;
394 }
395 // Use routerMac of the pair device as the next hop
396 MacAddress effectiveMac;
397 try {
398 effectiveMac = srManager.getDeviceMacAddress(location.deviceId());
399 } catch (DeviceConfigNotFoundException e) {
400 log.warn("Abort populateRoute on pair device {}. routerMac not found", pairDeviceId);
401 return false;
402 }
403 // Since the pairLocalPort is trunk port, use assigned vlan of original port
404 // when the host is untagged
405 VlanId effectiveVlan = Optional.ofNullable(srManager.getInternalVlanId(location)).orElse(nextHopVlan);
406
407 log.debug("Single leaf pair. populateRoute {}/{}, {}, {}, {}", pairDeviceId, pairRemotePort, prefix,
408 effectiveMac, effectiveVlan);
409 srManager.defaultRoutingHandler.populateRoute(pairDeviceId.get(), prefix,
410 effectiveMac, effectiveVlan, pairRemotePort.get(), false);
411
412 return true;
413 }
Charles Chandebfea32016-10-24 14:52:01 -0700414}