blob: 88a81cc948e11897ea9564690878951b9fb27037 [file] [log] [blame]
sangho80f11cb2015-04-01 13:05:26 -07001/*
Brian O'Connor0947d7e2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
sangho80f11cb2015-04-01 13:05:26 -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 */
16package org.onosproject.segmentrouting;
17
Jonathan Hart61e24e12017-11-30 18:23:42 -080018import com.google.common.collect.HashMultimap;
19import com.google.common.collect.ImmutableMap;
20import com.google.common.collect.Maps;
21import com.google.common.collect.Multimap;
Charles Chanf0ae41e2017-08-23 13:55:39 -070022import com.google.common.collect.Sets;
sangho80f11cb2015-04-01 13:05:26 -070023import org.apache.felix.scr.annotations.Activate;
24import org.apache.felix.scr.annotations.Component;
25import org.apache.felix.scr.annotations.Deactivate;
Charles Chan873661e2017-11-30 15:37:50 -080026import org.apache.felix.scr.annotations.Modified;
27import org.apache.felix.scr.annotations.Property;
sangho80f11cb2015-04-01 13:05:26 -070028import org.apache.felix.scr.annotations.Reference;
29import org.apache.felix.scr.annotations.ReferenceCardinality;
sangho27462c62015-05-14 00:39:53 -070030import org.apache.felix.scr.annotations.Service;
sangho80f11cb2015-04-01 13:05:26 -070031import org.onlab.packet.Ethernet;
Pier Ventreb6b81d52016-12-02 08:16:05 -080032import org.onlab.packet.ICMP6;
Charles Chan77277672015-10-20 16:24:19 -070033import org.onlab.packet.IPv4;
Pier Ventreb6a7f342016-11-26 21:05:22 -080034import org.onlab.packet.IPv6;
Jonghwan Hyune5ef7622017-08-25 17:48:36 -070035import org.onlab.packet.IpAddress;
Charles Chan77277672015-10-20 16:24:19 -070036import org.onlab.packet.IpPrefix;
Jonathan Hart54541d12016-04-12 15:39:44 -070037import org.onlab.packet.VlanId;
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -070038import org.onlab.util.KryoNamespace;
Charles Chan873661e2017-11-30 15:37:50 -080039import org.onlab.util.Tools;
Saurav Dasc3604f12016-03-23 11:22:49 -070040import org.onosproject.cfg.ComponentConfigService;
Pier Luigi580fd8a2018-01-16 10:47:50 +010041import org.onosproject.cluster.ClusterService;
42import org.onosproject.cluster.LeadershipService;
sangho80f11cb2015-04-01 13:05:26 -070043import org.onosproject.core.ApplicationId;
44import org.onosproject.core.CoreService;
45import org.onosproject.event.Event;
Jonathan Hart54541d12016-04-12 15:39:44 -070046import org.onosproject.mastership.MastershipService;
Pier Ventreb6a7f342016-11-26 21:05:22 -080047import org.onosproject.net.ConnectPoint;
Jonathan Hart54541d12016-04-12 15:39:44 -070048import org.onosproject.net.Device;
49import org.onosproject.net.DeviceId;
Charles Chanf0ae41e2017-08-23 13:55:39 -070050import org.onosproject.net.Host;
51import org.onosproject.net.HostId;
Jonathan Hart54541d12016-04-12 15:39:44 -070052import org.onosproject.net.Link;
53import org.onosproject.net.Port;
Charles Chanf4586112015-11-09 16:37:23 -080054import org.onosproject.net.PortNumber;
Jonghwan Hyune5ef7622017-08-25 17:48:36 -070055import org.onosproject.net.config.ConfigException;
Charles Chan72f556a2015-10-05 17:50:33 -070056import org.onosproject.net.config.ConfigFactory;
57import org.onosproject.net.config.NetworkConfigEvent;
Charles Chan72f556a2015-10-05 17:50:33 -070058import org.onosproject.net.config.NetworkConfigListener;
Jonathan Hart54541d12016-04-12 15:39:44 -070059import org.onosproject.net.config.NetworkConfigRegistry;
Ray Milkeyae0068a2017-08-15 11:02:29 -070060import org.onosproject.net.config.basics.InterfaceConfig;
61import org.onosproject.net.config.basics.McastConfig;
Charles Chan72f556a2015-10-05 17:50:33 -070062import org.onosproject.net.config.basics.SubjectFactories;
Saurav Dase6c448a2018-01-18 12:07:33 -080063import org.onosproject.net.device.DeviceAdminService;
Jonathan Hart54541d12016-04-12 15:39:44 -070064import org.onosproject.net.device.DeviceEvent;
65import org.onosproject.net.device.DeviceListener;
66import org.onosproject.net.device.DeviceService;
Charles Chanf4586112015-11-09 16:37:23 -080067import org.onosproject.net.flow.TrafficSelector;
68import org.onosproject.net.flow.TrafficTreatment;
Jonathan Hart54541d12016-04-12 15:39:44 -070069import org.onosproject.net.flowobjective.FlowObjectiveService;
Charles Chanf4586112015-11-09 16:37:23 -080070import org.onosproject.net.host.HostEvent;
71import org.onosproject.net.host.HostListener;
Charles Chan873661e2017-11-30 15:37:50 -080072import org.onosproject.net.host.HostLocationProbingService;
Pier Ventreb6a7f342016-11-26 21:05:22 -080073import org.onosproject.net.host.HostService;
Jonghwan Hyune5ef7622017-08-25 17:48:36 -070074import org.onosproject.net.host.InterfaceIpAddress;
Ray Milkeyae0068a2017-08-15 11:02:29 -070075import org.onosproject.net.intf.Interface;
76import org.onosproject.net.intf.InterfaceService;
Pier Ventreb6a7f342016-11-26 21:05:22 -080077import org.onosproject.net.link.LinkEvent;
78import org.onosproject.net.link.LinkListener;
79import org.onosproject.net.link.LinkService;
Charles Chanc91c8782016-03-30 17:54:24 -070080import org.onosproject.net.mcast.McastEvent;
81import org.onosproject.net.mcast.McastListener;
82import org.onosproject.net.mcast.MulticastRouteService;
Ray Milkeyae0068a2017-08-15 11:02:29 -070083import org.onosproject.net.neighbour.NeighbourResolutionService;
Pier Ventreb6a7f342016-11-26 21:05:22 -080084import org.onosproject.net.packet.InboundPacket;
85import org.onosproject.net.packet.PacketContext;
86import org.onosproject.net.packet.PacketProcessor;
87import org.onosproject.net.packet.PacketService;
Pier Luigid8a15162018-02-15 16:33:08 +010088import org.onosproject.net.topology.TopologyEvent;
89import org.onosproject.net.topology.TopologyListener;
Charles Chanc91c8782016-03-30 17:54:24 -070090import org.onosproject.net.topology.TopologyService;
Charles Chanf0ae41e2017-08-23 13:55:39 -070091import org.onosproject.routeservice.ResolvedRoute;
Ray Milkeyae0068a2017-08-15 11:02:29 -070092import org.onosproject.routeservice.RouteEvent;
93import org.onosproject.routeservice.RouteListener;
94import org.onosproject.routeservice.RouteService;
Charles Chanc91c8782016-03-30 17:54:24 -070095import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException;
96import org.onosproject.segmentrouting.config.DeviceConfiguration;
Pier Ventre6b19e482016-11-07 16:21:04 -080097import org.onosproject.segmentrouting.config.SegmentRoutingAppConfig;
Ray Milkeyae0068a2017-08-15 11:02:29 -070098import org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig;
Charles Chan82f19972016-05-17 13:13:55 -070099import org.onosproject.segmentrouting.config.XConnectConfig;
Charles Chanc91c8782016-03-30 17:54:24 -0700100import org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler;
Saurav Das261c3002017-06-13 15:35:54 -0700101import org.onosproject.segmentrouting.grouphandler.DestinationSet;
102import org.onosproject.segmentrouting.grouphandler.NextNeighbors;
Pier Luigi69f774d2018-02-28 12:10:50 +0100103import org.onosproject.segmentrouting.mcast.McastHandler;
104import org.onosproject.segmentrouting.mcast.McastRole;
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700105import org.onosproject.segmentrouting.pwaas.DefaultL2Tunnel;
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800106import org.onosproject.segmentrouting.pwaas.DefaultL2TunnelHandler;
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700107import org.onosproject.segmentrouting.pwaas.DefaultL2TunnelPolicy;
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -0800108import org.onosproject.segmentrouting.pwaas.DefaultL2TunnelDescription;
109
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800110import org.onosproject.segmentrouting.pwaas.L2Tunnel;
Ray Milkeyae0068a2017-08-15 11:02:29 -0700111import org.onosproject.segmentrouting.pwaas.L2TunnelHandler;
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800112import org.onosproject.segmentrouting.pwaas.L2TunnelPolicy;
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -0800113import org.onosproject.segmentrouting.pwaas.L2TunnelDescription;
114
Saurav Das261c3002017-06-13 15:35:54 -0700115import org.onosproject.segmentrouting.storekey.DestinationSetNextObjectiveStoreKey;
Pier Luigi0f9635b2018-01-15 18:06:43 +0100116import org.onosproject.segmentrouting.storekey.McastStoreKey;
Charles Chan1eaf4802016-04-18 13:44:03 -0700117import org.onosproject.segmentrouting.storekey.PortNextObjectiveStoreKey;
Charles Chan10b0fb72017-02-02 16:20:42 -0800118import org.onosproject.segmentrouting.storekey.VlanNextObjectiveStoreKey;
Charles Chan82f19972016-05-17 13:13:55 -0700119import org.onosproject.segmentrouting.storekey.XConnectStoreKey;
Jonathan Hart54541d12016-04-12 15:39:44 -0700120import org.onosproject.store.serializers.KryoNamespaces;
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700121import org.onosproject.store.service.EventuallyConsistentMap;
122import org.onosproject.store.service.EventuallyConsistentMapBuilder;
123import org.onosproject.store.service.StorageService;
124import org.onosproject.store.service.WallClockTimestamp;
Charles Chan873661e2017-11-30 15:37:50 -0800125import org.osgi.service.component.ComponentContext;
sangho80f11cb2015-04-01 13:05:26 -0700126import org.slf4j.Logger;
127import org.slf4j.LoggerFactory;
128
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -0700129import java.util.ArrayList;
Jonathan Hart61e24e12017-11-30 18:23:42 -0800130import java.util.Collections;
Charles Chan873661e2017-11-30 15:37:50 -0800131import java.util.Dictionary;
Jonathan Hart61e24e12017-11-30 18:23:42 -0800132import java.util.HashSet;
133import java.util.List;
134import java.util.Map;
Jonathan Hart61e24e12017-11-30 18:23:42 -0800135import java.util.Optional;
136import java.util.Set;
137import java.util.concurrent.ConcurrentHashMap;
138import java.util.concurrent.ConcurrentLinkedQueue;
139import java.util.concurrent.Executors;
140import java.util.concurrent.ScheduledExecutorService;
Jonathan Hart61e24e12017-11-30 18:23:42 -0800141import java.util.concurrent.TimeUnit;
142import java.util.concurrent.atomic.AtomicBoolean;
143import java.util.stream.Collectors;
sangho80f11cb2015-04-01 13:05:26 -0700144
Charles Chand6d25332016-02-26 22:19:52 -0800145import static com.google.common.base.Preconditions.checkState;
Pier Ventreadb4ae62016-11-23 09:57:42 -0800146import static org.onlab.packet.Ethernet.TYPE_ARP;
Yuta HIGUCHIebee2f12016-07-21 16:54:33 -0700147import static org.onlab.util.Tools.groupedThreads;
Saurav Dase321cff2018-02-09 17:26:45 -0800148import static org.onosproject.net.config.NetworkConfigEvent.Type.CONFIG_REGISTERED;
149import static org.onosproject.net.config.NetworkConfigEvent.Type.CONFIG_UNREGISTERED;
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -0800150import static org.onosproject.segmentrouting.pwaas.PwaasUtil.configurationValidity;
Charles Chand6d25332016-02-26 22:19:52 -0800151
Charles Chanb7f75ac2016-01-11 18:28:54 -0800152/**
153 * Segment routing manager.
154 */
Jonathan Hart54541d12016-04-12 15:39:44 -0700155@Service
156@Component(immediate = true)
sangho27462c62015-05-14 00:39:53 -0700157public class SegmentRoutingManager implements SegmentRoutingService {
sangho80f11cb2015-04-01 13:05:26 -0700158
Charles Chan46fdfaf2016-11-09 20:51:44 -0800159 private static Logger log = LoggerFactory.getLogger(SegmentRoutingManager.class);
Charles Chan910be6a2017-08-23 14:46:43 -0700160 private static final String NOT_MASTER = "Current instance is not the master of {}. Ignore.";
sangho80f11cb2015-04-01 13:05:26 -0700161
162 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chandebfea32016-10-24 14:52:01 -0700163 private ComponentConfigService compCfgService;
sangho80f11cb2015-04-01 13:05:26 -0700164
165 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Pier Ventreb6a7f342016-11-26 21:05:22 -0800166 private NeighbourResolutionService neighbourResolutionService;
167
168 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Pier Luigi69f774d2018-02-28 12:10:50 +0100169 public CoreService coreService;
sangho80f11cb2015-04-01 13:05:26 -0700170
171 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chandebfea32016-10-24 14:52:01 -0700172 PacketService packetService;
sangho80f11cb2015-04-01 13:05:26 -0700173
174 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chandebfea32016-10-24 14:52:01 -0700175 HostService hostService;
sangho80f11cb2015-04-01 13:05:26 -0700176
177 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan873661e2017-11-30 15:37:50 -0800178 HostLocationProbingService probingService;
179
180 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Pier Luigi69f774d2018-02-28 12:10:50 +0100181 public DeviceService deviceService;
sangho80f11cb2015-04-01 13:05:26 -0700182
183 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Saurav Dase6c448a2018-01-18 12:07:33 -0800184 DeviceAdminService deviceAdminService;
185
186 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Pier Ventref3cf5b92016-11-09 14:17:26 -0800187 public FlowObjectiveService flowObjectiveService;
sangho80f11cb2015-04-01 13:05:26 -0700188
189 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Pier Luigi69f774d2018-02-28 12:10:50 +0100190 public LinkService linkService;
sangho27462c62015-05-14 00:39:53 -0700191
Charles Chan82ab1932016-01-30 23:22:37 -0800192 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Pier Ventref3cf5b92016-11-09 14:17:26 -0800193 public MastershipService mastershipService;
Charles Chandebfea32016-10-24 14:52:01 -0700194
195 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Pier Ventref3cf5b92016-11-09 14:17:26 -0800196 public StorageService storageService;
Charles Chandebfea32016-10-24 14:52:01 -0700197
198 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Pier Luigi69f774d2018-02-28 12:10:50 +0100199 public MulticastRouteService multicastRouteService;
Charles Chandebfea32016-10-24 14:52:01 -0700200
201 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan83163812018-01-09 13:45:07 -0800202 public TopologyService topologyService;
Charles Chandebfea32016-10-24 14:52:01 -0700203
204 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chandebfea32016-10-24 14:52:01 -0700205 RouteService routeService;
Charles Chan82ab1932016-01-30 23:22:37 -0800206
207 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan46fdfaf2016-11-09 20:51:44 -0800208 public NetworkConfigRegistry cfgService;
Charles Chan82ab1932016-01-30 23:22:37 -0800209
Saurav Dasc3604f12016-03-23 11:22:49 -0700210 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan46fdfaf2016-11-09 20:51:44 -0800211 public InterfaceService interfaceService;
212
Pier Luigi580fd8a2018-01-16 10:47:50 +0100213 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
214 public ClusterService clusterService;
215
216 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
217 public LeadershipService leadershipService;
218
Charles Chan873661e2017-11-30 15:37:50 -0800219 @Property(name = "activeProbing", boolValue = true,
220 label = "Enable active probing to discover dual-homed hosts.")
221 boolean activeProbing = true;
222
Charles Chandebfea32016-10-24 14:52:01 -0700223 ArpHandler arpHandler = null;
224 IcmpHandler icmpHandler = null;
225 IpHandler ipHandler = null;
226 RoutingRulePopulator routingRulePopulator = null;
Ray Milkeyb85de082017-04-05 09:42:04 -0700227 ApplicationId appId;
228 DeviceConfiguration deviceConfiguration = null;
sangho80f11cb2015-04-01 13:05:26 -0700229
Charles Chandebfea32016-10-24 14:52:01 -0700230 DefaultRoutingHandler defaultRoutingHandler = null;
sangho27462c62015-05-14 00:39:53 -0700231 private TunnelHandler tunnelHandler = null;
232 private PolicyHandler policyHandler = null;
Charles Chan2b078ae2015-10-14 11:24:40 -0700233 private InternalPacketProcessor processor = null;
234 private InternalLinkListener linkListener = null;
235 private InternalDeviceListener deviceListener = null;
Charles Chan82f19972016-05-17 13:13:55 -0700236 private AppConfigHandler appCfgHandler = null;
Pier Luigi69f774d2018-02-28 12:10:50 +0100237 public XConnectHandler xConnectHandler = null;
Saurav Dase6c448a2018-01-18 12:07:33 -0800238 McastHandler mcastHandler = null;
239 HostHandler hostHandler = null;
Pier Ventreb6a7f342016-11-26 21:05:22 -0800240 private RouteHandler routeHandler = null;
Saurav Dase6c448a2018-01-18 12:07:33 -0800241 LinkHandler linkHandler = null;
Pier Ventreb6b81d52016-12-02 08:16:05 -0800242 private SegmentRoutingNeighbourDispatcher neighbourHandler = null;
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -0800243 private DefaultL2TunnelHandler l2TunnelHandler = null;
Pier Luigid8a15162018-02-15 16:33:08 +0100244 private TopologyHandler topologyHandler = null;
sangho80f11cb2015-04-01 13:05:26 -0700245 private InternalEventHandler eventHandler = new InternalEventHandler();
Charles Chan82ab1932016-01-30 23:22:37 -0800246 private final InternalHostListener hostListener = new InternalHostListener();
Charles Chanc91c8782016-03-30 17:54:24 -0700247 private final InternalConfigListener cfgListener = new InternalConfigListener(this);
248 private final InternalMcastListener mcastListener = new InternalMcastListener();
Charles Chandebfea32016-10-24 14:52:01 -0700249 private final InternalRouteEventListener routeListener = new InternalRouteEventListener();
Pier Luigid8a15162018-02-15 16:33:08 +0100250 private final InternalTopologyListener topologyListener = new InternalTopologyListener();
sangho80f11cb2015-04-01 13:05:26 -0700251
Srikanth Vavilapalli64505482015-04-21 13:04:13 -0700252 private ScheduledExecutorService executorService = Executors
Yuta HIGUCHIebee2f12016-07-21 16:54:33 -0700253 .newScheduledThreadPool(1, groupedThreads("SegmentRoutingManager", "event-%d", log));
sangho80f11cb2015-04-01 13:05:26 -0700254
Saurav Das2d94d312015-11-24 23:21:05 -0800255 @SuppressWarnings("rawtypes")
Yuta HIGUCHIebee2f12016-07-21 16:54:33 -0700256 private ConcurrentLinkedQueue<Event> eventQueue = new ConcurrentLinkedQueue<>();
Saurav Dase6c448a2018-01-18 12:07:33 -0800257 Map<DeviceId, DefaultGroupHandler> groupHandlerMap =
Charles Chanb7f75ac2016-01-11 18:28:54 -0800258 new ConcurrentHashMap<>();
259 /**
Saurav Das261c3002017-06-13 15:35:54 -0700260 * Per device next objective ID store with (device id + destination set) as key.
Charles Chan53de91f2017-08-22 15:07:34 -0700261 * Used to keep track on MPLS group information.
Charles Chanb7f75ac2016-01-11 18:28:54 -0800262 */
Charles Chan873661e2017-11-30 15:37:50 -0800263 private EventuallyConsistentMap<DestinationSetNextObjectiveStoreKey, NextNeighbors>
Saurav Das261c3002017-06-13 15:35:54 -0700264 dsNextObjStore = null;
Charles Chanb7f75ac2016-01-11 18:28:54 -0800265 /**
Charles Chan53de91f2017-08-22 15:07:34 -0700266 * Per device next objective ID store with (device id + vlanid) as key.
267 * Used to keep track on L2 flood group information.
Charles Chanb7f75ac2016-01-11 18:28:54 -0800268 */
Charles Chan873661e2017-11-30 15:37:50 -0800269 private EventuallyConsistentMap<VlanNextObjectiveStoreKey, Integer>
Charles Chan10b0fb72017-02-02 16:20:42 -0800270 vlanNextObjStore = null;
Charles Chanb7f75ac2016-01-11 18:28:54 -0800271 /**
Charles Chan53de91f2017-08-22 15:07:34 -0700272 * Per device next objective ID store with (device id + port + treatment + meta) as key.
273 * Used to keep track on L2 interface group and L3 unicast group information.
Charles Chanb7f75ac2016-01-11 18:28:54 -0800274 */
Charles Chan873661e2017-11-30 15:37:50 -0800275 private EventuallyConsistentMap<PortNextObjectiveStoreKey, Integer>
Saurav Das2d94d312015-11-24 23:21:05 -0800276 portNextObjStore = null;
Charles Chan10b0fb72017-02-02 16:20:42 -0800277
Saurav Das2d94d312015-11-24 23:21:05 -0800278 private EventuallyConsistentMap<String, Tunnel> tunnelStore = null;
279 private EventuallyConsistentMap<String, Policy> policyStore = null;
sangho4a5c42a2015-05-20 22:16:38 -0700280
Saurav Das261c3002017-06-13 15:35:54 -0700281 private AtomicBoolean programmingScheduled = new AtomicBoolean();
282
Charles Chanc91c8782016-03-30 17:54:24 -0700283 private final ConfigFactory<DeviceId, SegmentRoutingDeviceConfig> deviceConfigFactory =
Charles Chan82f19972016-05-17 13:13:55 -0700284 new ConfigFactory<DeviceId, SegmentRoutingDeviceConfig>(
285 SubjectFactories.DEVICE_SUBJECT_FACTORY,
Charles Chanc91c8782016-03-30 17:54:24 -0700286 SegmentRoutingDeviceConfig.class, "segmentrouting") {
Charles Chan72f556a2015-10-05 17:50:33 -0700287 @Override
Charles Chan82ab1932016-01-30 23:22:37 -0800288 public SegmentRoutingDeviceConfig createConfig() {
289 return new SegmentRoutingDeviceConfig();
Charles Chan72f556a2015-10-05 17:50:33 -0700290 }
291 };
Pier Ventre6b19e482016-11-07 16:21:04 -0800292
Charles Chanc91c8782016-03-30 17:54:24 -0700293 private final ConfigFactory<ApplicationId, SegmentRoutingAppConfig> appConfigFactory =
Charles Chan82f19972016-05-17 13:13:55 -0700294 new ConfigFactory<ApplicationId, SegmentRoutingAppConfig>(
295 SubjectFactories.APP_SUBJECT_FACTORY,
Charles Chanc91c8782016-03-30 17:54:24 -0700296 SegmentRoutingAppConfig.class, "segmentrouting") {
Charles Chan82ab1932016-01-30 23:22:37 -0800297 @Override
298 public SegmentRoutingAppConfig createConfig() {
299 return new SegmentRoutingAppConfig();
300 }
301 };
Pier Ventre6b19e482016-11-07 16:21:04 -0800302
Charles Chan82f19972016-05-17 13:13:55 -0700303 private final ConfigFactory<ApplicationId, XConnectConfig> xConnectConfigFactory =
304 new ConfigFactory<ApplicationId, XConnectConfig>(
305 SubjectFactories.APP_SUBJECT_FACTORY,
306 XConnectConfig.class, "xconnect") {
307 @Override
308 public XConnectConfig createConfig() {
309 return new XConnectConfig();
310 }
311 };
Pier Ventre6b19e482016-11-07 16:21:04 -0800312
Charles Chanc91c8782016-03-30 17:54:24 -0700313 private ConfigFactory<ApplicationId, McastConfig> mcastConfigFactory =
Charles Chan82f19972016-05-17 13:13:55 -0700314 new ConfigFactory<ApplicationId, McastConfig>(
315 SubjectFactories.APP_SUBJECT_FACTORY,
Charles Chanc91c8782016-03-30 17:54:24 -0700316 McastConfig.class, "multicast") {
317 @Override
318 public McastConfig createConfig() {
319 return new McastConfig();
320 }
321 };
322
Charles Chan3ed34d82017-06-22 18:03:14 -0700323 private static final Object THREAD_SCHED_LOCK = new Object();
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -0700324 private static int numOfEventsQueued = 0;
325 private static int numOfEventsExecuted = 0;
sangho80f11cb2015-04-01 13:05:26 -0700326 private static int numOfHandlerExecution = 0;
327 private static int numOfHandlerScheduled = 0;
328
Charles Chan1963f4f2016-02-18 14:22:42 -0800329 /**
330 * Segment Routing App ID.
331 */
Charles Chan46fdfaf2016-11-09 20:51:44 -0800332 public static final String APP_NAME = "org.onosproject.segmentrouting";
Charles Chan10b0fb72017-02-02 16:20:42 -0800333
Charles Chanb7f75ac2016-01-11 18:28:54 -0800334 /**
335 * The default VLAN ID assigned to the interfaces without subnet config.
336 */
Charles Chan10b0fb72017-02-02 16:20:42 -0800337 public static final VlanId INTERNAL_VLAN = VlanId.vlanId((short) 4094);
Saurav Das7c305372015-10-28 12:39:42 -0700338
sangho80f11cb2015-04-01 13:05:26 -0700339 @Activate
Charles Chan873661e2017-11-30 15:37:50 -0800340 protected void activate(ComponentContext context) {
Charles Chan46fdfaf2016-11-09 20:51:44 -0800341 appId = coreService.registerApplication(APP_NAME);
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700342
343 log.debug("Creating EC map nsnextobjectivestore");
Saurav Das261c3002017-06-13 15:35:54 -0700344 EventuallyConsistentMapBuilder<DestinationSetNextObjectiveStoreKey, NextNeighbors>
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700345 nsNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder();
Saurav Das261c3002017-06-13 15:35:54 -0700346 dsNextObjStore = nsNextObjMapBuilder
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700347 .withName("nsnextobjectivestore")
Jonathan Hart54541d12016-04-12 15:39:44 -0700348 .withSerializer(createSerializer())
Madan Jampani675ae202015-06-24 19:05:56 -0700349 .withTimestampProvider((k, v) -> new WallClockTimestamp())
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700350 .build();
Saurav Das261c3002017-06-13 15:35:54 -0700351 log.trace("Current size {}", dsNextObjStore.size());
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700352
Charles Chan10b0fb72017-02-02 16:20:42 -0800353 log.debug("Creating EC map vlannextobjectivestore");
354 EventuallyConsistentMapBuilder<VlanNextObjectiveStoreKey, Integer>
355 vlanNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder();
356 vlanNextObjStore = vlanNextObjMapBuilder
357 .withName("vlannextobjectivestore")
Jonathan Hart54541d12016-04-12 15:39:44 -0700358 .withSerializer(createSerializer())
Charles Chan77277672015-10-20 16:24:19 -0700359 .withTimestampProvider((k, v) -> new WallClockTimestamp())
360 .build();
361
Saurav Das2d94d312015-11-24 23:21:05 -0800362 log.debug("Creating EC map subnetnextobjectivestore");
363 EventuallyConsistentMapBuilder<PortNextObjectiveStoreKey, Integer>
364 portNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder();
365 portNextObjStore = portNextObjMapBuilder
366 .withName("portnextobjectivestore")
Jonathan Hart54541d12016-04-12 15:39:44 -0700367 .withSerializer(createSerializer())
Saurav Das2d94d312015-11-24 23:21:05 -0800368 .withTimestampProvider((k, v) -> new WallClockTimestamp())
369 .build();
370
sangho4a5c42a2015-05-20 22:16:38 -0700371 EventuallyConsistentMapBuilder<String, Tunnel> tunnelMapBuilder =
372 storageService.eventuallyConsistentMapBuilder();
sangho4a5c42a2015-05-20 22:16:38 -0700373 tunnelStore = tunnelMapBuilder
374 .withName("tunnelstore")
Jonathan Hart54541d12016-04-12 15:39:44 -0700375 .withSerializer(createSerializer())
Madan Jampani675ae202015-06-24 19:05:56 -0700376 .withTimestampProvider((k, v) -> new WallClockTimestamp())
sangho4a5c42a2015-05-20 22:16:38 -0700377 .build();
378
379 EventuallyConsistentMapBuilder<String, Policy> policyMapBuilder =
380 storageService.eventuallyConsistentMapBuilder();
sangho4a5c42a2015-05-20 22:16:38 -0700381 policyStore = policyMapBuilder
382 .withName("policystore")
Jonathan Hart54541d12016-04-12 15:39:44 -0700383 .withSerializer(createSerializer())
Madan Jampani675ae202015-06-24 19:05:56 -0700384 .withTimestampProvider((k, v) -> new WallClockTimestamp())
sangho4a5c42a2015-05-20 22:16:38 -0700385 .build();
386
Saurav Dasc3604f12016-03-23 11:22:49 -0700387 compCfgService.preSetProperty("org.onosproject.net.group.impl.GroupManager",
Pier Luigib9632ba2017-01-12 18:14:58 -0800388 "purgeOnDisconnection", "true");
Saurav Dasc3604f12016-03-23 11:22:49 -0700389 compCfgService.preSetProperty("org.onosproject.net.flow.impl.FlowRuleManager",
Pier Luigib9632ba2017-01-12 18:14:58 -0800390 "purgeOnDisconnection", "true");
Pier Luigib9632ba2017-01-12 18:14:58 -0800391 compCfgService.preSetProperty("org.onosproject.provider.host.impl.HostLocationProvider",
392 "requestInterceptsEnabled", "false");
Charles Chanc1909e12017-08-08 15:13:37 -0700393 compCfgService.preSetProperty("org.onosproject.net.neighbour.impl.NeighbourResolutionManager",
Pier Luigibc976df2017-01-12 22:46:39 -0800394 "requestInterceptsEnabled", "false");
Charles Chan9597f8d2017-07-24 15:56:10 -0700395 compCfgService.preSetProperty("org.onosproject.dhcprelay.DhcpRelayManager",
Pier Luigibc976df2017-01-12 22:46:39 -0800396 "arpEnabled", "false");
Pier Luigi0ebeb312017-02-02 22:31:34 -0800397 compCfgService.preSetProperty("org.onosproject.net.host.impl.HostManager",
398 "greedyLearningIpv6", "true");
Charles Chancf8ea472017-02-28 15:15:17 -0800399 compCfgService.preSetProperty("org.onosproject.routing.cpr.ControlPlaneRedirectManager",
400 "forceUnprovision", "true");
Charles Chanc7b73c72017-08-10 16:57:28 -0700401 compCfgService.preSetProperty("org.onosproject.routeservice.store.RouteStoreImpl",
Charles Chan4c95c0d2017-07-20 16:16:25 -0700402 "distributed", "true");
Charles Chan804772f2017-08-14 11:42:11 -0700403 compCfgService.preSetProperty("org.onosproject.provider.host.impl.HostLocationProvider",
404 "multihomingEnabled", "true");
Charles Chan0c9c19f2017-11-29 19:54:20 -0800405 compCfgService.preSetProperty("org.onosproject.provider.lldp.impl.LldpLinkProvider",
406 "staleLinkAge", "15000");
407 compCfgService.preSetProperty("org.onosproject.net.host.impl.HostManager",
408 "allowDuplicateIps", "false");
Charles Chan873661e2017-11-30 15:37:50 -0800409 compCfgService.registerProperties(getClass());
410 modified(context);
Saurav Dasc3604f12016-03-23 11:22:49 -0700411
Charles Chan2b078ae2015-10-14 11:24:40 -0700412 processor = new InternalPacketProcessor();
413 linkListener = new InternalLinkListener();
414 deviceListener = new InternalDeviceListener();
Charles Chan82f19972016-05-17 13:13:55 -0700415 appCfgHandler = new AppConfigHandler(this);
416 xConnectHandler = new XConnectHandler(this);
Charles Chan1eaf4802016-04-18 13:44:03 -0700417 mcastHandler = new McastHandler(this);
418 hostHandler = new HostHandler(this);
Saurav Dase6c448a2018-01-18 12:07:33 -0800419 linkHandler = new LinkHandler(this);
Charles Chandebfea32016-10-24 14:52:01 -0700420 routeHandler = new RouteHandler(this);
Pier Ventreb6b81d52016-12-02 08:16:05 -0800421 neighbourHandler = new SegmentRoutingNeighbourDispatcher(this);
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800422 l2TunnelHandler = new DefaultL2TunnelHandler(this);
Pier Luigid8a15162018-02-15 16:33:08 +0100423 topologyHandler = new TopologyHandler(this);
Charles Chan2b078ae2015-10-14 11:24:40 -0700424
Charles Chand6d25332016-02-26 22:19:52 -0800425 cfgService.addListener(cfgListener);
Charles Chanc91c8782016-03-30 17:54:24 -0700426 cfgService.registerConfigFactory(deviceConfigFactory);
427 cfgService.registerConfigFactory(appConfigFactory);
Charles Chan82f19972016-05-17 13:13:55 -0700428 cfgService.registerConfigFactory(xConnectConfigFactory);
Charles Chanc91c8782016-03-30 17:54:24 -0700429 cfgService.registerConfigFactory(mcastConfigFactory);
Saurav Dase321cff2018-02-09 17:26:45 -0800430 log.info("Configuring network before adding listeners");
Charles Chan6961f222018-01-04 14:26:07 -0800431 cfgListener.configureNetwork();
432
Charles Chan82ab1932016-01-30 23:22:37 -0800433 hostService.addListener(hostListener);
Charles Chan2b078ae2015-10-14 11:24:40 -0700434 packetService.addProcessor(processor, PacketProcessor.director(2));
435 linkService.addListener(linkListener);
436 deviceService.addListener(deviceListener);
Charles Chanc91c8782016-03-30 17:54:24 -0700437 multicastRouteService.addListener(mcastListener);
Charles Chanfd48c222017-06-19 00:43:31 -0700438 routeService.addListener(routeListener);
Pier Luigid8a15162018-02-15 16:33:08 +0100439 topologyService.addListener(topologyListener);
Charles Chan2b078ae2015-10-14 11:24:40 -0700440
Charles Chanc12c3d02018-03-09 15:53:44 -0800441 linkHandler.init();
Andreas Pantelopoulos75eef062018-01-11 07:53:48 -0800442 l2TunnelHandler.init();
443
sangho80f11cb2015-04-01 13:05:26 -0700444 log.info("Started");
445 }
446
Saurav Dase6c448a2018-01-18 12:07:33 -0800447 KryoNamespace.Builder createSerializer() {
Jonathan Hart54541d12016-04-12 15:39:44 -0700448 return new KryoNamespace.Builder()
449 .register(KryoNamespaces.API)
Saurav Das261c3002017-06-13 15:35:54 -0700450 .register(DestinationSetNextObjectiveStoreKey.class,
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800451 VlanNextObjectiveStoreKey.class,
452 DestinationSet.class,
453 NextNeighbors.class,
454 Tunnel.class,
455 DefaultTunnel.class,
456 Policy.class,
457 TunnelPolicy.class,
458 Policy.Type.class,
459 PortNextObjectiveStoreKey.class,
460 XConnectStoreKey.class,
461 L2Tunnel.class,
462 L2TunnelPolicy.class,
463 DefaultL2Tunnel.class,
464 DefaultL2TunnelPolicy.class
Jonathan Hart54541d12016-04-12 15:39:44 -0700465 );
466 }
467
sangho80f11cb2015-04-01 13:05:26 -0700468 @Deactivate
469 protected void deactivate() {
Charles Chan72f556a2015-10-05 17:50:33 -0700470 cfgService.removeListener(cfgListener);
Charles Chanc91c8782016-03-30 17:54:24 -0700471 cfgService.unregisterConfigFactory(deviceConfigFactory);
472 cfgService.unregisterConfigFactory(appConfigFactory);
Charles Chandebfea32016-10-24 14:52:01 -0700473 cfgService.unregisterConfigFactory(xConnectConfigFactory);
Charles Chanc91c8782016-03-30 17:54:24 -0700474 cfgService.unregisterConfigFactory(mcastConfigFactory);
Charles Chan873661e2017-11-30 15:37:50 -0800475 compCfgService.unregisterProperties(getClass(), false);
Charles Chan72f556a2015-10-05 17:50:33 -0700476
Charles Chanfd48c222017-06-19 00:43:31 -0700477 hostService.removeListener(hostListener);
sangho80f11cb2015-04-01 13:05:26 -0700478 packetService.removeProcessor(processor);
Charles Chan2b078ae2015-10-14 11:24:40 -0700479 linkService.removeListener(linkListener);
480 deviceService.removeListener(deviceListener);
Charles Chanc91c8782016-03-30 17:54:24 -0700481 multicastRouteService.removeListener(mcastListener);
Charles Chandebfea32016-10-24 14:52:01 -0700482 routeService.removeListener(routeListener);
Pier Luigid8a15162018-02-15 16:33:08 +0100483 topologyService.removeListener(topologyListener);
Charles Chanc91c8782016-03-30 17:54:24 -0700484
Charles Chan2e71ef32017-02-23 15:44:08 -0800485 neighbourResolutionService.unregisterNeighbourHandlers(appId);
486
sangho80f11cb2015-04-01 13:05:26 -0700487 processor = null;
Charles Chan2b078ae2015-10-14 11:24:40 -0700488 linkListener = null;
Charles Chanc91c8782016-03-30 17:54:24 -0700489 deviceListener = null;
Charles Chan2b078ae2015-10-14 11:24:40 -0700490 groupHandlerMap.clear();
491
Saurav Das261c3002017-06-13 15:35:54 -0700492 dsNextObjStore.destroy();
Charles Chan10b0fb72017-02-02 16:20:42 -0800493 vlanNextObjStore.destroy();
Charles Chanc91c8782016-03-30 17:54:24 -0700494 portNextObjStore.destroy();
Charles Chanc91c8782016-03-30 17:54:24 -0700495 tunnelStore.destroy();
496 policyStore.destroy();
Pier Luigi35dab3f2018-01-25 16:16:02 +0100497
498 mcastHandler.terminate();
sangho80f11cb2015-04-01 13:05:26 -0700499 log.info("Stopped");
500 }
501
Charles Chan873661e2017-11-30 15:37:50 -0800502 @Modified
503 private void modified(ComponentContext context) {
504 Dictionary<?, ?> properties = context.getProperties();
505 if (properties == null) {
506 return;
507 }
508
509 String strActiveProving = Tools.get(properties, "activeProbing");
510 boolean expectActiveProbing = Boolean.parseBoolean(strActiveProving);
511
512 if (expectActiveProbing != activeProbing) {
513 activeProbing = expectActiveProbing;
514 log.info("{} active probing", activeProbing ? "Enabling" : "Disabling");
515 }
516 }
517
sangho27462c62015-05-14 00:39:53 -0700518 @Override
519 public List<Tunnel> getTunnels() {
520 return tunnelHandler.getTunnels();
521 }
522
523 @Override
sanghobd812f82015-06-29 14:58:47 -0700524 public TunnelHandler.Result createTunnel(Tunnel tunnel) {
525 return tunnelHandler.createTunnel(tunnel);
sangho27462c62015-05-14 00:39:53 -0700526 }
527
528 @Override
sanghobd812f82015-06-29 14:58:47 -0700529 public TunnelHandler.Result removeTunnel(Tunnel tunnel) {
sangho27462c62015-05-14 00:39:53 -0700530 for (Policy policy: policyHandler.getPolicies()) {
531 if (policy.type() == Policy.Type.TUNNEL_FLOW) {
532 TunnelPolicy tunnelPolicy = (TunnelPolicy) policy;
533 if (tunnelPolicy.tunnelId().equals(tunnel.id())) {
534 log.warn("Cannot remove the tunnel used by a policy");
sanghobd812f82015-06-29 14:58:47 -0700535 return TunnelHandler.Result.TUNNEL_IN_USE;
sangho27462c62015-05-14 00:39:53 -0700536 }
537 }
538 }
sanghobd812f82015-06-29 14:58:47 -0700539 return tunnelHandler.removeTunnel(tunnel);
sangho27462c62015-05-14 00:39:53 -0700540 }
541
542 @Override
sanghobd812f82015-06-29 14:58:47 -0700543 public PolicyHandler.Result removePolicy(Policy policy) {
544 return policyHandler.removePolicy(policy);
sangho27462c62015-05-14 00:39:53 -0700545 }
546
547 @Override
sanghobd812f82015-06-29 14:58:47 -0700548 public PolicyHandler.Result createPolicy(Policy policy) {
549 return policyHandler.createPolicy(policy);
sangho27462c62015-05-14 00:39:53 -0700550 }
551
552 @Override
553 public List<Policy> getPolicies() {
554 return policyHandler.getPolicies();
555 }
556
Saurav Das07c74602016-04-27 18:35:50 -0700557 @Override
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -0700558 public Set<L2TunnelDescription> getL2TunnelDescriptions(boolean pending) {
559 return l2TunnelHandler.getL2Descriptions(pending);
Andreas Pantelopoulosfc4bc2a2018-03-12 16:30:20 -0700560 }
561
562 @Override
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800563 public List<L2Tunnel> getL2Tunnels() {
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700564 return l2TunnelHandler.getL2Tunnels();
565 }
566
567 @Override
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800568 public List<L2TunnelPolicy> getL2Policies() {
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700569 return l2TunnelHandler.getL2Policies();
570 }
571
572 @Override
Andreas Pantelopoulosfc4bc2a2018-03-12 16:30:20 -0700573 public L2TunnelHandler.Result addPseudowiresBulk(List<DefaultL2TunnelDescription> bulkPseudowires) {
574
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -0700575 // get both added and pending pseudowires
576 List<L2TunnelDescription> pseudowires = new ArrayList<>();
577 pseudowires.addAll(l2TunnelHandler.getL2Descriptions(false));
578 pseudowires.addAll(l2TunnelHandler.getL2Descriptions(true));
Andreas Pantelopoulosfc4bc2a2018-03-12 16:30:20 -0700579 pseudowires.addAll(bulkPseudowires);
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -0700580
Andreas Pantelopoulosfc4bc2a2018-03-12 16:30:20 -0700581 Set<L2TunnelDescription> newPseudowires = new HashSet(bulkPseudowires);
582
583 // check global validity for all the new pseudowires, if it fails
584 // do not add any of them
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -0700585 log.debug("Verifying set of pseudowires {}", pseudowires);
Andreas Pantelopoulosfc4bc2a2018-03-12 16:30:20 -0700586 boolean res = configurationValidity(pseudowires);
587 if (res) {
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -0700588 log.debug("Pseudowire configuration is valid, deploying pseudowires!");
Andreas Pantelopoulosfc4bc2a2018-03-12 16:30:20 -0700589 l2TunnelHandler.deploy(newPseudowires);
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -0700590
Andreas Pantelopoulosfc4bc2a2018-03-12 16:30:20 -0700591 return L2TunnelHandler.Result.SUCCESS;
592 } else {
593 log.error("Bulk pseudowires {} can not be added, error in global configuration!",
594 newPseudowires);
595 return L2TunnelHandler.Result.ADDITION_ERROR;
596 }
597 }
598
599 @Override
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -0800600 public L2TunnelHandler.Result addPseudowire(L2TunnelDescription l2TunnelDescription) {
601
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -0700602 // get both added and pending pseudowires
603 List<L2TunnelDescription> newPseudowires = new ArrayList<>();
604 newPseudowires.addAll(l2TunnelHandler.getL2Descriptions(false));
605 newPseudowires.addAll(l2TunnelHandler.getL2Descriptions(true));
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -0800606
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -0700607 // add the new pseudowire to the List
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -0800608 newPseudowires.add(l2TunnelDescription);
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -0700609 // validate the new list of pseudowires
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -0800610 boolean res = configurationValidity(newPseudowires);
611 if (res) {
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -0800612 // deploy a set with ONLY the new pseudowire
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -0700613 Set<L2TunnelDescription> pwToDeploy = new HashSet<>();
614 pwToDeploy.add(l2TunnelDescription);
615 l2TunnelHandler.deploy(pwToDeploy);
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -0800616
617 log.info("Pseudowire with {} deployment started, check log for any errors in this process!",
618 l2TunnelDescription.l2Tunnel().tunnelId());
619 return L2TunnelHandler.Result.SUCCESS;
620 } else {
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -0800621 log.error("Pseudowire with {} can not be added!", l2TunnelDescription.l2Tunnel().tunnelId());
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700622 return L2TunnelHandler.Result.ADDITION_ERROR;
623 }
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700624 }
625
626 @Override
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -0800627 public L2TunnelHandler.Result removePseudowire(Integer pwId) {
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700628
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -0700629 // get both added and pending pseudowires
630 Set<L2TunnelDescription> pseudowires = l2TunnelHandler.getL2Descriptions(false)
631 .stream()
632 .filter(pw -> pw.l2Tunnel().tunnelId() == pwId)
633 .collect(Collectors.toSet());
634 Set<L2TunnelDescription> pendingPseudowires = l2TunnelHandler.getL2Descriptions(true)
635 .stream()
636 .filter(pw -> pw.l2Tunnel().tunnelId() == pwId)
637 .collect(Collectors.toSet());
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700638
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -0700639 if ((pendingPseudowires.size() == 0) && (pseudowires.size() == 0)) {
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -0800640 log.error("Pseudowire with id {} does not exist", pwId);
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700641 return L2TunnelHandler.Result.REMOVAL_ERROR;
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -0700642 }
643 if (pendingPseudowires.size() != 0) {
644 log.info("Remove pseudowire from pending store!");
645 // will fill when we implement failure mechanism detection.
646 }
647 if (pseudowires.size() != 0) {
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -0800648 l2TunnelHandler.tearDown(new HashSet<>(pseudowires));
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -0800649 log.info("Removal of pseudowire with {} started, check log for any errors in this process!",
650 pwId);
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700651 }
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -0700652
653 return L2TunnelHandler.Result.SUCCESS;
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700654 }
655
656 @Override
Saurav Das07c74602016-04-27 18:35:50 -0700657 public void rerouteNetwork() {
658 cfgListener.configureNetwork();
Saurav Das07c74602016-04-27 18:35:50 -0700659 }
660
Charles Chand7844e52016-10-20 17:02:44 -0700661 @Override
Pier Ventreb6a7f342016-11-26 21:05:22 -0800662 public Map<DeviceId, Set<IpPrefix>> getDeviceSubnetMap() {
663 Map<DeviceId, Set<IpPrefix>> deviceSubnetMap = Maps.newHashMap();
Jonathan Hart61e24e12017-11-30 18:23:42 -0800664 deviceConfiguration.getRouters().forEach(device ->
665 deviceSubnetMap.put(device, deviceConfiguration.getSubnets(device)));
Charles Chand7844e52016-10-20 17:02:44 -0700666 return deviceSubnetMap;
667 }
668
Saurav Das62ae6792017-05-15 15:34:25 -0700669
670 @Override
671 public ImmutableMap<DeviceId, EcmpShortestPathGraph> getCurrentEcmpSpg() {
672 if (defaultRoutingHandler != null) {
673 return defaultRoutingHandler.getCurrentEmcpSpgMap();
674 } else {
675 return null;
676 }
677 }
678
679 @Override
Saurav Das261c3002017-06-13 15:35:54 -0700680 public ImmutableMap<DestinationSetNextObjectiveStoreKey, NextNeighbors> getDestinationSet() {
681 if (dsNextObjStore != null) {
682 return ImmutableMap.copyOf(dsNextObjStore.entrySet());
Saurav Das62ae6792017-05-15 15:34:25 -0700683 } else {
684 return ImmutableMap.of();
685 }
686 }
687
Saurav Dasfbe74572017-08-03 18:30:35 -0700688 @Override
689 public void verifyGroups(DeviceId id) {
690 DefaultGroupHandler gh = groupHandlerMap.get(id);
691 if (gh != null) {
692 gh.triggerBucketCorrector();
693 }
694 }
695
Saurav Das6430f412018-01-25 09:49:01 -0800696 @Override
697 public ImmutableMap<Link, Boolean> getSeenLinks() {
698 return linkHandler.getSeenLinks();
699 }
700
701 @Override
702 public ImmutableMap<DeviceId, Set<PortNumber>> getDownedPortState() {
703 return linkHandler.getDownedPorts();
704 }
705
Pier Luigi0f9635b2018-01-15 18:06:43 +0100706 @Override
707 public Map<McastStoreKey, Integer> getMcastNextIds(IpAddress mcastIp) {
708 return mcastHandler.getMcastNextIds(mcastIp);
709 }
710
711 @Override
Pier Luigi69f774d2018-02-28 12:10:50 +0100712 public Map<McastStoreKey, McastRole> getMcastRoles(IpAddress mcastIp) {
Pier Luigi0f9635b2018-01-15 18:06:43 +0100713 return mcastHandler.getMcastRoles(mcastIp);
714 }
715
716 @Override
717 public Map<ConnectPoint, List<ConnectPoint>> getMcastPaths(IpAddress mcastIp) {
718 return mcastHandler.getMcastPaths(mcastIp);
719 }
720
sangho80f1f892015-05-19 11:57:42 -0700721 /**
Ray Milkeyb85de082017-04-05 09:42:04 -0700722 * Extracts the application ID from the manager.
723 *
724 * @return application ID
725 */
726 public ApplicationId appId() {
727 return appId;
728 }
729
730 /**
731 * Returns the device configuration.
732 *
733 * @return device configuration
734 */
735 public DeviceConfiguration deviceConfiguration() {
736 return deviceConfiguration;
737 }
738
739 /**
Saurav Das261c3002017-06-13 15:35:54 -0700740 * Per device next objective ID store with (device id + destination set) as key.
Charles Chan53de91f2017-08-22 15:07:34 -0700741 * Used to keep track on MPLS group information.
Ray Milkeyb85de082017-04-05 09:42:04 -0700742 *
743 * @return next objective ID store
744 */
Saurav Das261c3002017-06-13 15:35:54 -0700745 public EventuallyConsistentMap<DestinationSetNextObjectiveStoreKey, NextNeighbors>
746 dsNextObjStore() {
747 return dsNextObjStore;
Ray Milkeyb85de082017-04-05 09:42:04 -0700748 }
749
750 /**
Charles Chan53de91f2017-08-22 15:07:34 -0700751 * Per device next objective ID store with (device id + vlanid) as key.
752 * Used to keep track on L2 flood group information.
Ray Milkeyb85de082017-04-05 09:42:04 -0700753 *
754 * @return vlan next object store
755 */
756 public EventuallyConsistentMap<VlanNextObjectiveStoreKey, Integer> vlanNextObjStore() {
757 return vlanNextObjStore;
758 }
759
760 /**
Charles Chan53de91f2017-08-22 15:07:34 -0700761 * Per device next objective ID store with (device id + port + treatment + meta) as key.
762 * Used to keep track on L2 interface group and L3 unicast group information.
Ray Milkeyb85de082017-04-05 09:42:04 -0700763 *
764 * @return port next object store.
765 */
766 public EventuallyConsistentMap<PortNextObjectiveStoreKey, Integer> portNextObjStore() {
767 return portNextObjStore;
768 }
769
770 /**
Saurav Das261c3002017-06-13 15:35:54 -0700771 * Returns the MPLS-ECMP configuration which indicates whether ECMP on
772 * labeled packets should be programmed or not.
Pier Ventre7a78de22016-10-31 15:00:01 -0700773 *
774 * @return MPLS-ECMP value
775 */
776 public boolean getMplsEcmp() {
777 SegmentRoutingAppConfig segmentRoutingAppConfig = cfgService
778 .getConfig(this.appId, SegmentRoutingAppConfig.class);
779 return segmentRoutingAppConfig != null && segmentRoutingAppConfig.mplsEcmp();
780 }
781
782 /**
sangho80f1f892015-05-19 11:57:42 -0700783 * Returns the tunnel object with the tunnel ID.
784 *
785 * @param tunnelId Tunnel ID
786 * @return Tunnel reference
787 */
sangho27462c62015-05-14 00:39:53 -0700788 public Tunnel getTunnel(String tunnelId) {
789 return tunnelHandler.getTunnel(tunnelId);
790 }
791
Charles Chan90772a72017-02-08 15:52:08 -0800792 // TODO Consider moving these to InterfaceService
sangho80f11cb2015-04-01 13:05:26 -0700793 /**
Charles Chan10b0fb72017-02-02 16:20:42 -0800794 * Returns untagged VLAN configured on given connect point.
Charles Chan90772a72017-02-08 15:52:08 -0800795 * <p>
796 * Only returns the first match if there are multiple untagged VLAN configured
797 * on the connect point.
sangho80f11cb2015-04-01 13:05:26 -0700798 *
Charles Chan10b0fb72017-02-02 16:20:42 -0800799 * @param connectPoint connect point
800 * @return untagged VLAN or null if not configured
sangho80f11cb2015-04-01 13:05:26 -0700801 */
Charles Chan3ed34d82017-06-22 18:03:14 -0700802 VlanId getUntaggedVlanId(ConnectPoint connectPoint) {
Charles Chan10b0fb72017-02-02 16:20:42 -0800803 return interfaceService.getInterfacesByPort(connectPoint).stream()
804 .filter(intf -> !intf.vlanUntagged().equals(VlanId.NONE))
805 .map(Interface::vlanUntagged)
806 .findFirst().orElse(null);
sangho80f11cb2015-04-01 13:05:26 -0700807 }
808
sangho27462c62015-05-14 00:39:53 -0700809 /**
Charles Chan90772a72017-02-08 15:52:08 -0800810 * Returns tagged VLAN configured on given connect point.
811 * <p>
812 * Returns all matches if there are multiple tagged VLAN configured
813 * on the connect point.
814 *
815 * @param connectPoint connect point
816 * @return tagged VLAN or empty set if not configured
817 */
Charles Chan3ed34d82017-06-22 18:03:14 -0700818 Set<VlanId> getTaggedVlanId(ConnectPoint connectPoint) {
Charles Chan90772a72017-02-08 15:52:08 -0800819 Set<Interface> interfaces = interfaceService.getInterfacesByPort(connectPoint);
820 return interfaces.stream()
821 .map(Interface::vlanTagged)
Charles Chan3ed34d82017-06-22 18:03:14 -0700822 .flatMap(Set::stream)
Charles Chan90772a72017-02-08 15:52:08 -0800823 .collect(Collectors.toSet());
824 }
825
826 /**
827 * Returns native VLAN configured on given connect point.
828 * <p>
829 * Only returns the first match if there are multiple native VLAN configured
830 * on the connect point.
831 *
832 * @param connectPoint connect point
833 * @return native VLAN or null if not configured
834 */
Charles Chan3ed34d82017-06-22 18:03:14 -0700835 VlanId getNativeVlanId(ConnectPoint connectPoint) {
Charles Chan90772a72017-02-08 15:52:08 -0800836 Set<Interface> interfaces = interfaceService.getInterfacesByPort(connectPoint);
837 return interfaces.stream()
838 .filter(intf -> !intf.vlanNative().equals(VlanId.NONE))
839 .map(Interface::vlanNative)
840 .findFirst()
841 .orElse(null);
842 }
843
844 /**
Charles Chand9265a32017-06-16 15:19:24 -0700845 * Returns internal VLAN for untagged hosts on given connect point.
846 * <p>
847 * The internal VLAN is either vlan-untagged for an access port,
848 * or vlan-native for a trunk port.
849 *
850 * @param connectPoint connect point
851 * @return internal VLAN or null if both vlan-untagged and vlan-native are undefined
852 */
Pier Luigi69f774d2018-02-28 12:10:50 +0100853 public VlanId getInternalVlanId(ConnectPoint connectPoint) {
Charles Chand9265a32017-06-16 15:19:24 -0700854 VlanId untaggedVlanId = getUntaggedVlanId(connectPoint);
855 VlanId nativeVlanId = getNativeVlanId(connectPoint);
856 return untaggedVlanId != null ? untaggedVlanId : nativeVlanId;
857 }
858
859 /**
Charles Chan3ed34d82017-06-22 18:03:14 -0700860 * Returns optional pair device ID of given device.
861 *
862 * @param deviceId device ID
863 * @return optional pair device ID. Might be empty if pair device is not configured
864 */
865 Optional<DeviceId> getPairDeviceId(DeviceId deviceId) {
866 SegmentRoutingDeviceConfig deviceConfig =
867 cfgService.getConfig(deviceId, SegmentRoutingDeviceConfig.class);
868 return Optional.ofNullable(deviceConfig).map(SegmentRoutingDeviceConfig::pairDeviceId);
869 }
870 /**
871 * Returns optional pair device local port of given device.
872 *
873 * @param deviceId device ID
874 * @return optional pair device ID. Might be empty if pair device is not configured
875 */
876 Optional<PortNumber> getPairLocalPorts(DeviceId deviceId) {
877 SegmentRoutingDeviceConfig deviceConfig =
878 cfgService.getConfig(deviceId, SegmentRoutingDeviceConfig.class);
879 return Optional.ofNullable(deviceConfig).map(SegmentRoutingDeviceConfig::pairLocalPort);
880 }
881
882 /**
Charles Chan910be6a2017-08-23 14:46:43 -0700883 * Determine if current instance is the master of given connect point.
884 *
885 * @param cp connect point
886 * @return true if current instance is the master of given connect point
887 */
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700888 public boolean isMasterOf(ConnectPoint cp) {
Charles Chan910be6a2017-08-23 14:46:43 -0700889 boolean isMaster = mastershipService.isLocalMaster(cp.deviceId());
890 if (!isMaster) {
891 log.debug(NOT_MASTER, cp);
892 }
893 return isMaster;
894 }
895
896 /**
Charles Chanf0ae41e2017-08-23 13:55:39 -0700897 * Returns locations of given resolved route.
898 *
899 * @param resolvedRoute resolved route
900 * @return locations of nexthop. Might be empty if next hop is not found
901 */
902 Set<ConnectPoint> nextHopLocations(ResolvedRoute resolvedRoute) {
903 HostId hostId = HostId.hostId(resolvedRoute.nextHopMac(), resolvedRoute.nextHopVlan());
904 return Optional.ofNullable(hostService.getHost(hostId))
905 .map(Host::locations).orElse(Sets.newHashSet())
906 .stream().map(l -> (ConnectPoint) l).collect(Collectors.toSet());
907 }
908
909 /**
Charles Chan90772a72017-02-08 15:52:08 -0800910 * Returns vlan port map of given device.
911 *
912 * @param deviceId device id
913 * @return vlan-port multimap
914 */
915 public Multimap<VlanId, PortNumber> getVlanPortMap(DeviceId deviceId) {
916 HashMultimap<VlanId, PortNumber> vlanPortMap = HashMultimap.create();
917
918 interfaceService.getInterfaces().stream()
919 .filter(intf -> intf.connectPoint().deviceId().equals(deviceId))
920 .forEach(intf -> {
921 vlanPortMap.put(intf.vlanUntagged(), intf.connectPoint().port());
Charles Chan3ed34d82017-06-22 18:03:14 -0700922 intf.vlanTagged().forEach(vlanTagged ->
923 vlanPortMap.put(vlanTagged, intf.connectPoint().port())
924 );
Charles Chan90772a72017-02-08 15:52:08 -0800925 vlanPortMap.put(intf.vlanNative(), intf.connectPoint().port());
926 });
927 vlanPortMap.removeAll(VlanId.NONE);
928
929 return vlanPortMap;
930 }
931
932 /**
Charles Chan10b0fb72017-02-02 16:20:42 -0800933 * Returns the next objective ID for the given vlan id. It is expected
Saurav Das2d94d312015-11-24 23:21:05 -0800934 * that the next-objective has been pre-created from configuration.
Charles Chan77277672015-10-20 16:24:19 -0700935 *
936 * @param deviceId Device ID
Charles Chan10b0fb72017-02-02 16:20:42 -0800937 * @param vlanId VLAN ID
Saurav Das2d94d312015-11-24 23:21:05 -0800938 * @return next objective ID or -1 if it was not found
Charles Chan77277672015-10-20 16:24:19 -0700939 */
Charles Chan3ed34d82017-06-22 18:03:14 -0700940 int getVlanNextObjectiveId(DeviceId deviceId, VlanId vlanId) {
Charles Chan77277672015-10-20 16:24:19 -0700941 if (groupHandlerMap.get(deviceId) != null) {
Charles Chan10b0fb72017-02-02 16:20:42 -0800942 log.trace("getVlanNextObjectiveId query in device {}", deviceId);
943 return groupHandlerMap.get(deviceId).getVlanNextObjectiveId(vlanId);
Charles Chan77277672015-10-20 16:24:19 -0700944 } else {
Charles Chan10b0fb72017-02-02 16:20:42 -0800945 log.warn("getVlanNextObjectiveId query - groupHandler for "
Saurav Das2d94d312015-11-24 23:21:05 -0800946 + "device {} not found", deviceId);
947 return -1;
948 }
949 }
950
951 /**
952 * Returns the next objective ID for the given portNumber, given the treatment.
953 * There could be multiple different treatments to the same outport, which
Saurav Das2cb38292017-03-29 19:09:17 -0700954 * would result in different objectives. If the next object does not exist,
955 * and should be created, a new one is created and its id is returned.
Saurav Das2d94d312015-11-24 23:21:05 -0800956 *
957 * @param deviceId Device ID
958 * @param portNum port number on device for which NextObjective is queried
959 * @param treatment the actions to apply on the packets (should include outport)
960 * @param meta metadata passed into the creation of a Next Objective if necessary
Saurav Das2cb38292017-03-29 19:09:17 -0700961 * @param createIfMissing true if a next object should be created if not found
Saurav Das07c74602016-04-27 18:35:50 -0700962 * @return next objective ID or -1 if an error occurred during retrieval or creation
Saurav Das2d94d312015-11-24 23:21:05 -0800963 */
964 public int getPortNextObjectiveId(DeviceId deviceId, PortNumber portNum,
965 TrafficTreatment treatment,
Saurav Das2cb38292017-03-29 19:09:17 -0700966 TrafficSelector meta,
967 boolean createIfMissing) {
Saurav Das2d94d312015-11-24 23:21:05 -0800968 DefaultGroupHandler ghdlr = groupHandlerMap.get(deviceId);
969 if (ghdlr != null) {
Saurav Das2cb38292017-03-29 19:09:17 -0700970 return ghdlr.getPortNextObjectiveId(portNum, treatment, meta, createIfMissing);
Saurav Das2d94d312015-11-24 23:21:05 -0800971 } else {
Charles Chanb7f75ac2016-01-11 18:28:54 -0800972 log.warn("getPortNextObjectiveId query - groupHandler for device {}"
973 + " not found", deviceId);
974 return -1;
975 }
976 }
977
Saurav Das62ae6792017-05-15 15:34:25 -0700978 /**
979 * Returns the group handler object for the specified device id.
980 *
981 * @param devId the device identifier
982 * @return the groupHandler object for the device id, or null if not found
983 */
Charles Chan3ed34d82017-06-22 18:03:14 -0700984 DefaultGroupHandler getGroupHandler(DeviceId devId) {
Saurav Das62ae6792017-05-15 15:34:25 -0700985 return groupHandlerMap.get(devId);
986 }
987
988 /**
Saurav Dasfbe74572017-08-03 18:30:35 -0700989 * Returns the default routing handler object.
990 *
991 * @return the default routing handler object
992 */
993 public DefaultRoutingHandler getRoutingHandler() {
994 return defaultRoutingHandler;
995 }
996
sangho80f11cb2015-04-01 13:05:26 -0700997 private class InternalPacketProcessor implements PacketProcessor {
sangho80f11cb2015-04-01 13:05:26 -0700998 @Override
999 public void process(PacketContext context) {
1000
1001 if (context.isHandled()) {
1002 return;
1003 }
1004
1005 InboundPacket pkt = context.inPacket();
1006 Ethernet ethernet = pkt.parsed();
Pier Luigi37a35432017-02-01 13:50:04 -08001007
1008 if (ethernet == null) {
1009 return;
1010 }
1011
Saurav Das261c3002017-06-13 15:35:54 -07001012 log.trace("Rcvd pktin from {}: {}", context.inPacket().receivedFrom(),
1013 ethernet);
Pier Ventreadb4ae62016-11-23 09:57:42 -08001014 if (ethernet.getEtherType() == TYPE_ARP) {
Saurav Das62ae6792017-05-15 15:34:25 -07001015 log.warn("Received unexpected ARP packet on {}",
1016 context.inPacket().receivedFrom());
Saurav Das368cf212017-03-15 15:15:14 -07001017 log.trace("{}", ethernet);
Pier Ventre6b2c1b32016-12-09 17:26:04 -08001018 return;
sangho80f11cb2015-04-01 13:05:26 -07001019 } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV4) {
Pier Ventreb6b81d52016-12-02 08:16:05 -08001020 IPv4 ipv4Packet = (IPv4) ethernet.getPayload();
1021 //ipHandler.addToPacketBuffer(ipv4Packet);
1022 if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_ICMP) {
1023 icmpHandler.processIcmp(ethernet, pkt.receivedFrom());
sangho80f11cb2015-04-01 13:05:26 -07001024 } else {
Charles Chand041ad82017-01-13 17:20:44 -08001025 // NOTE: We don't support IP learning at this moment so this
1026 // is not necessary. Also it causes duplication of DHCP packets.
Pier Ventre6b2c1b32016-12-09 17:26:04 -08001027 // ipHandler.processPacketIn(ipv4Packet, pkt.receivedFrom());
sangho80f11cb2015-04-01 13:05:26 -07001028 }
Pier Ventreb6a7f342016-11-26 21:05:22 -08001029 } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV6) {
1030 IPv6 ipv6Packet = (IPv6) ethernet.getPayload();
Pier Ventreb6b81d52016-12-02 08:16:05 -08001031 //ipHandler.addToPacketBuffer(ipv6Packet);
Pier Luigi37a35432017-02-01 13:50:04 -08001032 // We deal with the packet only if the packet is a ICMP6 ECHO/REPLY
Pier Ventreb6b81d52016-12-02 08:16:05 -08001033 if (ipv6Packet.getNextHeader() == IPv6.PROTOCOL_ICMP6) {
1034 ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload();
1035 if (icmp6Packet.getIcmpType() == ICMP6.ECHO_REQUEST ||
1036 icmp6Packet.getIcmpType() == ICMP6.ECHO_REPLY) {
1037 icmpHandler.processIcmpv6(ethernet, pkt.receivedFrom());
1038 } else {
Saurav Das62ae6792017-05-15 15:34:25 -07001039 log.trace("Received ICMPv6 0x{} - not handled",
Charles Chand3727b72017-03-13 13:10:30 -07001040 Integer.toHexString(icmp6Packet.getIcmpType() & 0xff));
Pier Ventreb6b81d52016-12-02 08:16:05 -08001041 }
1042 } else {
1043 // NOTE: We don't support IP learning at this moment so this
1044 // is not necessary. Also it causes duplication of DHCPv6 packets.
1045 // ipHandler.processPacketIn(ipv6Packet, pkt.receivedFrom());
1046 }
sangho80f11cb2015-04-01 13:05:26 -07001047 }
1048 }
1049 }
1050
Saurav Das2d94d312015-11-24 23:21:05 -08001051 @SuppressWarnings("rawtypes")
sangho80f11cb2015-04-01 13:05:26 -07001052 private void scheduleEventHandlerIfNotScheduled(Event event) {
Charles Chan3ed34d82017-06-22 18:03:14 -07001053 synchronized (THREAD_SCHED_LOCK) {
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -07001054 eventQueue.add(event);
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -07001055 numOfEventsQueued++;
1056
1057 if ((numOfHandlerScheduled - numOfHandlerExecution) == 0) {
1058 //No pending scheduled event handling threads. So start a new one.
Charles Chan3f4aca62018-03-21 16:57:47 -07001059 executorService.schedule(eventHandler, 100, TimeUnit.MILLISECONDS);
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -07001060 numOfHandlerScheduled++;
1061 }
Jonathan Hart54541d12016-04-12 15:39:44 -07001062 log.trace("numOfEventsQueued {}, numOfEventHandlerScheduled {}",
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -07001063 numOfEventsQueued,
1064 numOfHandlerScheduled);
sangho80f11cb2015-04-01 13:05:26 -07001065 }
sangho80f11cb2015-04-01 13:05:26 -07001066 }
1067
1068 private class InternalEventHandler implements Runnable {
Srikanth Vavilapalli37a461b2015-04-07 15:12:32 -07001069 @Override
sangho80f11cb2015-04-01 13:05:26 -07001070 public void run() {
Pier Luigi8f362362018-02-12 09:56:20 +01001071 while (true) {
1072 try {
Saurav Das2d94d312015-11-24 23:21:05 -08001073 @SuppressWarnings("rawtypes")
Charles Chan3ed34d82017-06-22 18:03:14 -07001074 Event event;
1075 synchronized (THREAD_SCHED_LOCK) {
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -07001076 if (!eventQueue.isEmpty()) {
1077 event = eventQueue.poll();
1078 numOfEventsExecuted++;
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -07001079 } else {
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -07001080 numOfHandlerExecution++;
1081 log.debug("numOfHandlerExecution {} numOfEventsExecuted {}",
1082 numOfHandlerExecution, numOfEventsExecuted);
1083 break;
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -07001084 }
sanghofb7c7292015-04-13 15:15:58 -07001085 }
Pier Luigid8a15162018-02-15 16:33:08 +01001086 // TODO We should also change SR routing and PW to listen to TopologyEvents
Charles Chan0cff8aa2017-03-29 16:39:05 -07001087 if (event.type() == LinkEvent.Type.LINK_ADDED ||
1088 event.type() == LinkEvent.Type.LINK_UPDATED) {
Saurav Dase6c448a2018-01-18 12:07:33 -08001089 linkHandler.processLinkAdded((Link) event.subject());
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -07001090 } else if (event.type() == LinkEvent.Type.LINK_REMOVED) {
Saurav Dase6c448a2018-01-18 12:07:33 -08001091 linkHandler.processLinkRemoved((Link) event.subject());
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -07001092 } else if (event.type() == DeviceEvent.Type.DEVICE_ADDED ||
1093 event.type() == DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED ||
1094 event.type() == DeviceEvent.Type.DEVICE_UPDATED) {
Saurav Das62af8802015-12-04 10:52:59 -08001095 DeviceId deviceId = ((Device) event.subject()).id();
1096 if (deviceService.isAvailable(deviceId)) {
Saurav Dascea556f2018-03-05 14:37:16 -08001097 log.info("** DEVICE UP Processing device event {} "
1098 + "for available device {}",
Saurav Dasc28b3432015-10-30 17:45:38 -07001099 event.type(), ((Device) event.subject()).id());
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -07001100 processDeviceAdded((Device) event.subject());
Saurav Dasc3604f12016-03-23 11:22:49 -07001101 } else {
Saurav Dascea556f2018-03-05 14:37:16 -08001102 log.info(" ** DEVICE DOWN Processing device event {}"
1103 + " for unavailable device {}",
Pier Luigi8f362362018-02-12 09:56:20 +01001104 event.type(), ((Device) event.subject()).id());
Saurav Dasc3604f12016-03-23 11:22:49 -07001105 processDeviceRemoved((Device) event.subject());
1106 }
Saurav Dasf0f592d2016-11-18 15:21:57 -08001107 } else if (event.type() == DeviceEvent.Type.PORT_ADDED) {
Saurav Dasd1872b02016-12-02 15:43:47 -08001108 // typically these calls come when device is added first time
1109 // so port filtering rules are handled at the device_added event.
1110 // port added calls represent all ports on the device,
1111 // enabled or not.
Saurav Das62ae6792017-05-15 15:34:25 -07001112 log.trace("** PORT ADDED {}/{} -> {}",
Saurav Dasd1872b02016-12-02 15:43:47 -08001113 ((DeviceEvent) event).subject().id(),
1114 ((DeviceEvent) event).port().number(),
1115 event.type());
Saurav Dasf0f592d2016-11-18 15:21:57 -08001116 } else if (event.type() == DeviceEvent.Type.PORT_UPDATED) {
Saurav Dasd1872b02016-12-02 15:43:47 -08001117 // these calls happen for every subsequent event
1118 // ports enabled, disabled, switch goes away, comes back
Saurav Dasf0f592d2016-11-18 15:21:57 -08001119 log.info("** PORT UPDATED {}/{} -> {}",
1120 event.subject(),
1121 ((DeviceEvent) event).port(),
1122 event.type());
1123 processPortUpdated(((Device) event.subject()),
1124 ((DeviceEvent) event).port());
Pier Luigid8a15162018-02-15 16:33:08 +01001125 } else if (event.type() == TopologyEvent.Type.TOPOLOGY_CHANGED) {
1126 // Process topology event, needed for all modules relying on
1127 // topology service for path computation
1128 TopologyEvent topologyEvent = (TopologyEvent) event;
1129 log.info("Processing topology event {}, topology age {}, reasons {}",
1130 event.type(), topologyEvent.subject().time(),
1131 topologyEvent.reasons().size());
1132 topologyHandler.processTopologyChange(topologyEvent.reasons());
Charles Chan3f4aca62018-03-21 16:57:47 -07001133 } else if (event.type() == HostEvent.Type.HOST_ADDED) {
1134 hostHandler.processHostAddedEvent((HostEvent) event);
1135 } else if (event.type() == HostEvent.Type.HOST_MOVED) {
1136 hostHandler.processHostMovedEvent((HostEvent) event);
1137 routeHandler.processHostMovedEvent((HostEvent) event);
1138 } else if (event.type() == HostEvent.Type.HOST_REMOVED) {
1139 hostHandler.processHostRemovedEvent((HostEvent) event);
1140 } else if (event.type() == HostEvent.Type.HOST_UPDATED) {
1141 hostHandler.processHostUpdatedEvent((HostEvent) event);
1142 } else if (event.type() == RouteEvent.Type.ROUTE_ADDED) {
1143 routeHandler.processRouteAdded((RouteEvent) event);
1144 } else if (event.type() == RouteEvent.Type.ROUTE_UPDATED) {
1145 routeHandler.processRouteUpdated((RouteEvent) event);
1146 } else if (event.type() == RouteEvent.Type.ROUTE_REMOVED) {
1147 routeHandler.processRouteRemoved((RouteEvent) event);
1148 } else if (event.type() == RouteEvent.Type.ALTERNATIVE_ROUTES_CHANGED) {
1149 routeHandler.processAlternativeRoutesChanged((RouteEvent) event);
1150 } else if (event.type() == McastEvent.Type.SOURCE_ADDED ||
1151 event.type() == McastEvent.Type.SOURCE_UPDATED ||
1152 event.type() == McastEvent.Type.SINK_ADDED ||
1153 event.type() == McastEvent.Type.SINK_REMOVED ||
1154 event.type() == McastEvent.Type.ROUTE_REMOVED) {
1155 mcastHandler.processMcastEvent((McastEvent) event);
1156 } else if (event.type() == NetworkConfigEvent.Type.CONFIG_ADDED) {
1157 NetworkConfigEvent netcfgEvent = (NetworkConfigEvent) event;
1158 Class configClass = netcfgEvent.configClass();
1159 if (configClass.equals(SegmentRoutingAppConfig.class)) {
1160 appCfgHandler.processAppConfigAdded(netcfgEvent);
1161 log.info("App config event .. configuring network");
1162 cfgListener.configureNetwork();
1163 } else if (configClass.equals(SegmentRoutingDeviceConfig.class)) {
1164 log.info("Segment Routing Device Config added for {}", event.subject());
1165 cfgListener.configureNetwork();
1166 } else if (configClass.equals(XConnectConfig.class)) {
1167 xConnectHandler.processXConnectConfigAdded(netcfgEvent);
1168 } else if (configClass.equals(InterfaceConfig.class)) {
1169 log.info("Interface Config added for {}", event.subject());
1170 cfgListener.configureNetwork();
1171 } else {
1172 log.error("Unhandled config class: {}", configClass);
1173 }
1174 } else if (event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED) {
1175 NetworkConfigEvent netcfgEvent = (NetworkConfigEvent) event;
1176 Class configClass = netcfgEvent.configClass();
1177 if (configClass.equals(SegmentRoutingAppConfig.class)) {
1178 appCfgHandler.processAppConfigUpdated(netcfgEvent);
1179 log.info("App config event .. configuring network");
1180 cfgListener.configureNetwork();
1181 } else if (configClass.equals(SegmentRoutingDeviceConfig.class)) {
1182 log.info("Segment Routing Device Config updated for {}", event.subject());
1183 createOrUpdateDeviceConfiguration();
1184 } else if (configClass.equals(XConnectConfig.class)) {
1185 xConnectHandler.processXConnectConfigUpdated(netcfgEvent);
1186 } else if (configClass.equals(InterfaceConfig.class)) {
1187 log.info("Interface Config updated for {}", event.subject());
1188 createOrUpdateDeviceConfiguration();
1189 updateInterface((InterfaceConfig) netcfgEvent.config().get(),
1190 (InterfaceConfig) netcfgEvent.prevConfig().get());
1191 } else {
1192 log.error("Unhandled config class: {}", configClass);
1193 }
1194 } else if (event.type() == NetworkConfigEvent.Type.CONFIG_REMOVED) {
1195 NetworkConfigEvent netcfgEvent = (NetworkConfigEvent) event;
1196 Class configClass = netcfgEvent.configClass();
1197 if (configClass.equals(SegmentRoutingAppConfig.class)) {
1198 appCfgHandler.processAppConfigRemoved(netcfgEvent);
1199 log.info("App config event .. configuring network");
1200 cfgListener.configureNetwork();
1201 } else if (configClass.equals(SegmentRoutingDeviceConfig.class)) {
1202 // TODO Handle sr device config removal
1203 log.info("SegmentRoutingDeviceConfig removal is not handled in current implementation");
1204 } else if (configClass.equals(XConnectConfig.class)) {
1205 xConnectHandler.processXConnectConfigRemoved(netcfgEvent);
1206 } else if (configClass.equals(InterfaceConfig.class)) {
1207 // TODO Handle interface removal
1208 log.info("InterfaceConfig removal is not handled in current implementation");
1209 } else {
1210 log.error("Unhandled config class: {}", configClass);
1211 }
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -07001212 } else {
1213 log.warn("Unhandled event type: {}", event.type());
1214 }
Pier Luigi8f362362018-02-12 09:56:20 +01001215 } catch (Exception e) {
1216 log.error("SegmentRouting event handler thread thrown an exception: {}",
1217 e.getMessage(), e);
sangho80f11cb2015-04-01 13:05:26 -07001218 }
1219 }
sangho80f11cb2015-04-01 13:05:26 -07001220 }
1221 }
1222
Saurav Dase6c448a2018-01-18 12:07:33 -08001223 void processDeviceAdded(Device device) {
Saurav Dasb149be12016-06-07 10:08:06 -07001224 log.info("** DEVICE ADDED with ID {}", device.id());
Charles Chan9bd6aea2017-06-27 18:48:32 -07001225
1226 // NOTE: Punt ARP/NDP even when the device is not configured.
1227 // Host learning without network config is required for CORD config generator.
1228 routingRulePopulator.populateIpPunts(device.id());
1229 routingRulePopulator.populateArpNdpPunts(device.id());
1230
Charles Chan319d1a22015-11-03 10:42:14 -08001231 if (deviceConfiguration == null || !deviceConfiguration.isConfigured(device.id())) {
Saurav Das261c3002017-06-13 15:35:54 -07001232 log.warn("Device configuration unavailable. Device {} will be "
1233 + "processed after configuration.", device.id());
Saurav Das8ec0ec42015-11-03 14:39:27 -08001234 return;
1235 }
Charles Chan72779502016-04-23 17:36:10 -07001236 processDeviceAddedInternal(device.id());
1237 }
1238
1239 private void processDeviceAddedInternal(DeviceId deviceId) {
Saurav Dasc28b3432015-10-30 17:45:38 -07001240 // Irrespective of whether the local is a MASTER or not for this device,
1241 // we need to create a SR-group-handler instance. This is because in a
1242 // multi-instance setup, any instance can initiate forwarding/next-objectives
1243 // for any switch (even if this instance is a SLAVE or not even connected
1244 // to the switch). To handle this, a default-group-handler instance is necessary
1245 // per switch.
Charles Chan72779502016-04-23 17:36:10 -07001246 log.debug("Current groupHandlerMap devs: {}", groupHandlerMap.keySet());
1247 if (groupHandlerMap.get(deviceId) == null) {
Charles Chan319d1a22015-11-03 10:42:14 -08001248 DefaultGroupHandler groupHandler;
1249 try {
1250 groupHandler = DefaultGroupHandler.
Charles Chan72779502016-04-23 17:36:10 -07001251 createGroupHandler(deviceId,
1252 appId,
1253 deviceConfiguration,
1254 linkService,
1255 flowObjectiveService,
1256 this);
Charles Chan319d1a22015-11-03 10:42:14 -08001257 } catch (DeviceConfigNotFoundException e) {
1258 log.warn(e.getMessage() + " Aborting processDeviceAdded.");
1259 return;
1260 }
Saurav Das2b6a00f2017-12-05 15:00:23 -08001261 log.debug("updating groupHandlerMap with new grpHdlr for device: {}",
Charles Chan72779502016-04-23 17:36:10 -07001262 deviceId);
1263 groupHandlerMap.put(deviceId, groupHandler);
Saurav Das8ec0ec42015-11-03 14:39:27 -08001264 }
Saurav Dasb149be12016-06-07 10:08:06 -07001265
Charles Chan72779502016-04-23 17:36:10 -07001266 if (mastershipService.isLocalMaster(deviceId)) {
Saurav Dasf9332192017-02-18 14:05:44 -08001267 defaultRoutingHandler.populatePortAddressingRules(deviceId);
Charles Chandebfea32016-10-24 14:52:01 -07001268 hostHandler.init(deviceId);
Charles Chan82f19972016-05-17 13:13:55 -07001269 xConnectHandler.init(deviceId);
Charles Chan72779502016-04-23 17:36:10 -07001270 DefaultGroupHandler groupHandler = groupHandlerMap.get(deviceId);
Charles Chan10b0fb72017-02-02 16:20:42 -08001271 groupHandler.createGroupsFromVlanConfig();
Charles Chan72779502016-04-23 17:36:10 -07001272 routingRulePopulator.populateSubnetBroadcastRule(deviceId);
Charles Chan77277672015-10-20 16:24:19 -07001273 }
Charles Chan82ab1932016-01-30 23:22:37 -08001274
Charles Chandebfea32016-10-24 14:52:01 -07001275 appCfgHandler.init(deviceId);
1276 routeHandler.init(deviceId);
sangho80f11cb2015-04-01 13:05:26 -07001277 }
1278
Saurav Dasc3604f12016-03-23 11:22:49 -07001279 private void processDeviceRemoved(Device device) {
Saurav Das261c3002017-06-13 15:35:54 -07001280 dsNextObjStore.entrySet().stream()
Saurav Dasc3604f12016-03-23 11:22:49 -07001281 .filter(entry -> entry.getKey().deviceId().equals(device.id()))
Charles Chan873661e2017-11-30 15:37:50 -08001282 .forEach(entry -> dsNextObjStore.remove(entry.getKey()));
Charles Chan10b0fb72017-02-02 16:20:42 -08001283 vlanNextObjStore.entrySet().stream()
Saurav Dasc3604f12016-03-23 11:22:49 -07001284 .filter(entry -> entry.getKey().deviceId().equals(device.id()))
Charles Chan3ed34d82017-06-22 18:03:14 -07001285 .forEach(entry -> vlanNextObjStore.remove(entry.getKey()));
Saurav Dasc3604f12016-03-23 11:22:49 -07001286 portNextObjStore.entrySet().stream()
1287 .filter(entry -> entry.getKey().deviceId().equals(device.id()))
Charles Chan3ed34d82017-06-22 18:03:14 -07001288 .forEach(entry -> portNextObjStore.remove(entry.getKey()));
Saurav Dase6c448a2018-01-18 12:07:33 -08001289 linkHandler.processDeviceRemoved(device);
Charles Chan17d75d82017-06-15 00:44:51 -07001290
Saurav Dasfbe74572017-08-03 18:30:35 -07001291 DefaultGroupHandler gh = groupHandlerMap.remove(device.id());
1292 if (gh != null) {
1293 gh.shutdown();
1294 }
Saurav Das62ae6792017-05-15 15:34:25 -07001295 // Note that a switch going down is associated with all of its links
1296 // going down as well, but it is treated as a single switch down event
1297 // while the link-downs are ignored.
1298 defaultRoutingHandler
1299 .populateRoutingRulesForLinkStatusChange(null, null, device.id());
Saurav Das6430f412018-01-25 09:49:01 -08001300 defaultRoutingHandler.purgeEcmpGraph(device.id());
Charles Chan82f19972016-05-17 13:13:55 -07001301 xConnectHandler.removeDevice(device.id());
Saurav Das97241862018-02-14 14:14:54 -08001302
1303 // Cleanup all internal groupHandler stores for this device. Should be
1304 // done after all rerouting or rehashing has been completed
1305 groupHandlerMap.entrySet()
1306 .forEach(entry -> entry.getValue().cleanUpForNeighborDown(device.id()));
Saurav Dasc3604f12016-03-23 11:22:49 -07001307 }
1308
Saurav Dasf0f592d2016-11-18 15:21:57 -08001309 private void processPortUpdated(Device device, Port port) {
1310 if (deviceConfiguration == null || !deviceConfiguration.isConfigured(device.id())) {
1311 log.warn("Device configuration uploading. Not handling port event for"
1312 + "dev: {} port: {}", device.id(), port.number());
1313 return;
1314 }
Saurav Dasf9332192017-02-18 14:05:44 -08001315
1316 if (!mastershipService.isLocalMaster(device.id())) {
1317 log.debug("Not master for dev:{} .. not handling port updated event"
1318 + "for port {}", device.id(), port.number());
1319 return;
1320 }
1321
1322 // first we handle filtering rules associated with the port
1323 if (port.isEnabled()) {
1324 log.info("Switchport {}/{} enabled..programming filters",
1325 device.id(), port.number());
Charles Chan43be46b2017-02-26 22:59:35 -08001326 routingRulePopulator.processSinglePortFilters(device.id(), port.number(), true);
Saurav Dasf9332192017-02-18 14:05:44 -08001327 } else {
1328 log.info("Switchport {}/{} disabled..removing filters",
1329 device.id(), port.number());
Charles Chan43be46b2017-02-26 22:59:35 -08001330 routingRulePopulator.processSinglePortFilters(device.id(), port.number(), false);
Saurav Dasf9332192017-02-18 14:05:44 -08001331 }
Saurav Dasf0f592d2016-11-18 15:21:57 -08001332
1333 // portUpdated calls are for ports that have gone down or up. For switch
1334 // to switch ports, link-events should take care of any re-routing or
1335 // group editing necessary for port up/down. Here we only process edge ports
1336 // that are already configured.
Saurav Das3fb28272017-03-04 16:08:47 -08001337 ConnectPoint cp = new ConnectPoint(device.id(), port.number());
1338 VlanId untaggedVlan = getUntaggedVlanId(cp);
1339 VlanId nativeVlan = getNativeVlanId(cp);
1340 Set<VlanId> taggedVlans = getTaggedVlanId(cp);
Charles Chan10b0fb72017-02-02 16:20:42 -08001341
Saurav Das3fb28272017-03-04 16:08:47 -08001342 if (untaggedVlan == null && nativeVlan == null && taggedVlans.isEmpty()) {
Saurav Das62ae6792017-05-15 15:34:25 -07001343 log.debug("Not handling port updated event for non-edge port (unconfigured) "
Saurav Dasf0f592d2016-11-18 15:21:57 -08001344 + "dev/port: {}/{}", device.id(), port.number());
1345 return;
1346 }
Saurav Das3fb28272017-03-04 16:08:47 -08001347 if (untaggedVlan != null) {
1348 processEdgePort(device, port, untaggedVlan, true);
1349 }
1350 if (nativeVlan != null) {
1351 processEdgePort(device, port, nativeVlan, true);
1352 }
1353 if (!taggedVlans.isEmpty()) {
1354 taggedVlans.forEach(tag -> processEdgePort(device, port, tag, false));
1355 }
Saurav Dasf0f592d2016-11-18 15:21:57 -08001356 }
1357
Saurav Das3fb28272017-03-04 16:08:47 -08001358 private void processEdgePort(Device device, Port port, VlanId vlanId,
1359 boolean popVlan) {
Saurav Dasf0f592d2016-11-18 15:21:57 -08001360 boolean portUp = port.isEnabled();
1361 if (portUp) {
Saurav Das3fb28272017-03-04 16:08:47 -08001362 log.info("Device:EdgePort {}:{} is enabled in vlan: {}", device.id(),
Charles Chan10b0fb72017-02-02 16:20:42 -08001363 port.number(), vlanId);
Charles Chan873661e2017-11-30 15:37:50 -08001364 hostHandler.processPortUp(new ConnectPoint(device.id(), port.number()));
Saurav Dasf0f592d2016-11-18 15:21:57 -08001365 } else {
Saurav Das3fb28272017-03-04 16:08:47 -08001366 log.info("Device:EdgePort {}:{} is disabled in vlan: {}", device.id(),
Charles Chan10b0fb72017-02-02 16:20:42 -08001367 port.number(), vlanId);
Saurav Dasf0f592d2016-11-18 15:21:57 -08001368 }
1369
Srikanth Vavilapalli64505482015-04-21 13:04:13 -07001370 DefaultGroupHandler groupHandler = groupHandlerMap.get(device.id());
sangho80f11cb2015-04-01 13:05:26 -07001371 if (groupHandler != null) {
Saurav Das3fb28272017-03-04 16:08:47 -08001372 groupHandler.processEdgePort(port.number(), vlanId, popVlan, portUp);
Saurav Dasf0f592d2016-11-18 15:21:57 -08001373 } else {
1374 log.warn("Group handler not found for dev:{}. Not handling edge port"
1375 + " {} event for port:{}", device.id(),
1376 (portUp) ? "UP" : "DOWN", port.number());
sangho80f11cb2015-04-01 13:05:26 -07001377 }
1378 }
sangho27462c62015-05-14 00:39:53 -07001379
Charles Chan8ca5a122017-10-20 16:06:55 -07001380 private void createOrUpdateDeviceConfiguration() {
1381 if (deviceConfiguration == null) {
Saurav Dase321cff2018-02-09 17:26:45 -08001382 log.info("Creating new DeviceConfiguration");
Charles Chan8ca5a122017-10-20 16:06:55 -07001383 deviceConfiguration = new DeviceConfiguration(this);
1384 } else {
Saurav Dase321cff2018-02-09 17:26:45 -08001385 log.info("Updating DeviceConfiguration");
Charles Chan8ca5a122017-10-20 16:06:55 -07001386 deviceConfiguration.updateConfig();
1387 }
1388 }
1389
Pier Ventreb6a7f342016-11-26 21:05:22 -08001390 /**
1391 * Registers the given connect point with the NRS, this is necessary
1392 * to receive the NDP and ARP packets from the NRS.
1393 *
1394 * @param portToRegister connect point to register
1395 */
1396 public void registerConnectPoint(ConnectPoint portToRegister) {
Charles Chan2e71ef32017-02-23 15:44:08 -08001397 neighbourResolutionService.registerNeighbourHandler(
Pier Ventreb6a7f342016-11-26 21:05:22 -08001398 portToRegister,
1399 neighbourHandler,
1400 appId
1401 );
1402 }
1403
Charles Chan72f556a2015-10-05 17:50:33 -07001404 private class InternalConfigListener implements NetworkConfigListener {
Saurav Das261c3002017-06-13 15:35:54 -07001405 private static final long PROGRAM_DELAY = 2;
Charles Chan46fdfaf2016-11-09 20:51:44 -08001406 SegmentRoutingManager srManager;
Charles Chane7c61022015-10-07 14:21:45 -07001407
Charles Chanb7f75ac2016-01-11 18:28:54 -08001408 /**
1409 * Constructs the internal network config listener.
1410 *
Charles Chan46fdfaf2016-11-09 20:51:44 -08001411 * @param srManager segment routing manager
Charles Chanb7f75ac2016-01-11 18:28:54 -08001412 */
Charles Chan3ed34d82017-06-22 18:03:14 -07001413 InternalConfigListener(SegmentRoutingManager srManager) {
Charles Chan46fdfaf2016-11-09 20:51:44 -08001414 this.srManager = srManager;
Charles Chane7c61022015-10-07 14:21:45 -07001415 }
1416
Charles Chanb7f75ac2016-01-11 18:28:54 -08001417 /**
1418 * Reads network config and initializes related data structure accordingly.
1419 */
Charles Chan873661e2017-11-30 15:37:50 -08001420 void configureNetwork() {
Saurav Dase321cff2018-02-09 17:26:45 -08001421 log.info("Configuring network ...");
Charles Chan8ca5a122017-10-20 16:06:55 -07001422 createOrUpdateDeviceConfiguration();
Charles Chane7c61022015-10-07 14:21:45 -07001423
Charles Chan46fdfaf2016-11-09 20:51:44 -08001424 arpHandler = new ArpHandler(srManager);
1425 icmpHandler = new IcmpHandler(srManager);
1426 ipHandler = new IpHandler(srManager);
1427 routingRulePopulator = new RoutingRulePopulator(srManager);
1428 defaultRoutingHandler = new DefaultRoutingHandler(srManager);
Charles Chane7c61022015-10-07 14:21:45 -07001429
1430 tunnelHandler = new TunnelHandler(linkService, deviceConfiguration,
1431 groupHandlerMap, tunnelStore);
1432 policyHandler = new PolicyHandler(appId, deviceConfiguration,
1433 flowObjectiveService,
1434 tunnelHandler, policyStore);
Saurav Das261c3002017-06-13 15:35:54 -07001435 // add a small delay to absorb multiple network config added notifications
1436 if (!programmingScheduled.get()) {
Saurav Dase321cff2018-02-09 17:26:45 -08001437 log.info("Buffering config calls for {} secs", PROGRAM_DELAY);
Saurav Das261c3002017-06-13 15:35:54 -07001438 programmingScheduled.set(true);
1439 executorService.schedule(new ConfigChange(), PROGRAM_DELAY,
1440 TimeUnit.SECONDS);
Charles Chane7c61022015-10-07 14:21:45 -07001441 }
Charles Chan72779502016-04-23 17:36:10 -07001442 mcastHandler.init();
Charles Chane7c61022015-10-07 14:21:45 -07001443 }
1444
Charles Chan72f556a2015-10-05 17:50:33 -07001445 @Override
1446 public void event(NetworkConfigEvent event) {
Charles Chan3f4aca62018-03-21 16:57:47 -07001447 checkState(appCfgHandler != null, "NetworkConfigEventHandler is not initialized");
1448 checkState(xConnectHandler != null, "XConnectHandler is not initialized");
1449 switch (event.type()) {
1450 case CONFIG_ADDED:
1451 case CONFIG_UPDATED:
1452 case CONFIG_REMOVED:
1453 log.trace("Schedule Network Config event {}", event);
1454 scheduleEventHandlerIfNotScheduled(event);
1455 break;
1456 default:
1457 break;
Charles Chan72f556a2015-10-05 17:50:33 -07001458 }
1459 }
Saurav Das261c3002017-06-13 15:35:54 -07001460
Charles Chanc4a68c32018-01-03 16:26:32 -08001461 @Override
1462 public boolean isRelevant(NetworkConfigEvent event) {
Saurav Dase321cff2018-02-09 17:26:45 -08001463 if (event.type() == CONFIG_REGISTERED ||
1464 event.type() == CONFIG_UNREGISTERED) {
1465 log.debug("Ignore event {} due to type mismatch", event);
1466 return false;
Charles Chanc4a68c32018-01-03 16:26:32 -08001467 }
Saurav Dase321cff2018-02-09 17:26:45 -08001468
1469 if (!event.configClass().equals(SegmentRoutingDeviceConfig.class) &&
1470 !event.configClass().equals(SegmentRoutingAppConfig.class) &&
1471 !event.configClass().equals(InterfaceConfig.class) &&
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -08001472 !event.configClass().equals(XConnectConfig.class)) {
Saurav Dase321cff2018-02-09 17:26:45 -08001473 log.debug("Ignore event {} due to class mismatch", event);
1474 return false;
1475 }
1476
1477 return true;
Charles Chanc4a68c32018-01-03 16:26:32 -08001478 }
1479
Saurav Das261c3002017-06-13 15:35:54 -07001480 private final class ConfigChange implements Runnable {
1481 @Override
1482 public void run() {
1483 programmingScheduled.set(false);
Saurav Dase321cff2018-02-09 17:26:45 -08001484 log.info("Reacting to config changes after buffer delay");
Saurav Das261c3002017-06-13 15:35:54 -07001485 for (Device device : deviceService.getDevices()) {
1486 processDeviceAdded(device);
1487 }
1488 defaultRoutingHandler.startPopulationProcess();
1489 }
1490 }
Charles Chan72f556a2015-10-05 17:50:33 -07001491 }
Charles Chanf4586112015-11-09 16:37:23 -08001492
Charles Chan3f4aca62018-03-21 16:57:47 -07001493 private class InternalLinkListener implements LinkListener {
1494 @Override
1495 public void event(LinkEvent event) {
1496 if (event.type() == LinkEvent.Type.LINK_ADDED ||
1497 event.type() == LinkEvent.Type.LINK_UPDATED ||
1498 event.type() == LinkEvent.Type.LINK_REMOVED) {
1499 log.trace("Schedule Link event {}", event);
1500 scheduleEventHandlerIfNotScheduled(event);
1501 }
1502 }
1503 }
1504
1505 private class InternalDeviceListener implements DeviceListener {
1506 @Override
1507 public void event(DeviceEvent event) {
1508 switch (event.type()) {
1509 case DEVICE_ADDED:
1510 case PORT_UPDATED:
1511 case PORT_ADDED:
1512 case DEVICE_UPDATED:
1513 case DEVICE_AVAILABILITY_CHANGED:
1514 log.trace("Schedule Device event {}", event);
1515 scheduleEventHandlerIfNotScheduled(event);
1516 break;
1517 default:
1518 }
1519 }
1520 }
1521
1522 private class InternalTopologyListener implements TopologyListener {
1523 @Override
1524 public void event(TopologyEvent event) {
1525 switch (event.type()) {
1526 case TOPOLOGY_CHANGED:
1527 log.trace("Schedule Topology event {}", event);
1528 scheduleEventHandlerIfNotScheduled(event);
1529 break;
1530 default:
1531 }
1532 }
1533 }
1534
Charles Chanf4586112015-11-09 16:37:23 -08001535 private class InternalHostListener implements HostListener {
Charles Chanf4586112015-11-09 16:37:23 -08001536 @Override
1537 public void event(HostEvent event) {
Charles Chanf4586112015-11-09 16:37:23 -08001538 switch (event.type()) {
1539 case HOST_ADDED:
Charles Chanf4586112015-11-09 16:37:23 -08001540 case HOST_MOVED:
Charles Chanf4586112015-11-09 16:37:23 -08001541 case HOST_REMOVED:
Charles Chanf4586112015-11-09 16:37:23 -08001542 case HOST_UPDATED:
Charles Chan3f4aca62018-03-21 16:57:47 -07001543 log.trace("Schedule Host event {}", event);
1544 scheduleEventHandlerIfNotScheduled(event);
Charles Chanf4586112015-11-09 16:37:23 -08001545 break;
1546 default:
1547 log.warn("Unsupported host event type: {}", event.type());
1548 break;
1549 }
1550 }
1551 }
1552
Charles Chanc91c8782016-03-30 17:54:24 -07001553 private class InternalMcastListener implements McastListener {
1554 @Override
1555 public void event(McastEvent event) {
1556 switch (event.type()) {
1557 case SOURCE_ADDED:
Pier Luigie80d6b42018-02-26 12:31:38 +01001558 case SOURCE_UPDATED:
Charles Chanc91c8782016-03-30 17:54:24 -07001559 case SINK_ADDED:
Charles Chanc91c8782016-03-30 17:54:24 -07001560 case SINK_REMOVED:
Charles Chanc91c8782016-03-30 17:54:24 -07001561 case ROUTE_REMOVED:
Charles Chan3f4aca62018-03-21 16:57:47 -07001562 log.trace("Schedule Mcast event {}", event);
1563 scheduleEventHandlerIfNotScheduled(event);
Pier Luigi6786b922018-02-02 16:19:11 +01001564 break;
1565 case ROUTE_ADDED:
Charles Chanc91c8782016-03-30 17:54:24 -07001566 default:
Charles Chan3f4aca62018-03-21 16:57:47 -07001567 log.warn("Unsupported mcast event type: {}", event.type());
Charles Chanc91c8782016-03-30 17:54:24 -07001568 break;
1569 }
1570 }
1571 }
Charles Chan41f5ec02016-06-13 18:54:31 -07001572
Charles Chandebfea32016-10-24 14:52:01 -07001573 private class InternalRouteEventListener implements RouteListener {
1574 @Override
1575 public void event(RouteEvent event) {
1576 switch (event.type()) {
1577 case ROUTE_ADDED:
Charles Chandebfea32016-10-24 14:52:01 -07001578 case ROUTE_UPDATED:
Charles Chandebfea32016-10-24 14:52:01 -07001579 case ROUTE_REMOVED:
Charles Chan910be6a2017-08-23 14:46:43 -07001580 case ALTERNATIVE_ROUTES_CHANGED:
Charles Chan3f4aca62018-03-21 16:57:47 -07001581 log.trace("Schedule Route event {}", event);
1582 scheduleEventHandlerIfNotScheduled(event);
Charles Chan910be6a2017-08-23 14:46:43 -07001583 break;
Charles Chandebfea32016-10-24 14:52:01 -07001584 default:
Charles Chan3f4aca62018-03-21 16:57:47 -07001585 log.warn("Unsupported route event type: {}", event.type());
Charles Chandebfea32016-10-24 14:52:01 -07001586 break;
1587 }
1588 }
1589 }
Saurav Das62ae6792017-05-15 15:34:25 -07001590
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07001591 private void updateInterface(InterfaceConfig conf, InterfaceConfig prevConf) {
1592 try {
1593 Set<Interface> intfs = conf.getInterfaces();
1594 Set<Interface> prevIntfs = prevConf.getInterfaces();
1595
1596 // Now we only handle one interface config at each port.
1597 if (intfs.size() != 1 || prevIntfs.size() != 1) {
1598 log.warn("Interface update aborted - one at a time is allowed, " +
1599 "but {} / {}(prev) received.", intfs.size(), prevIntfs.size());
1600 return;
1601 }
1602
1603 Interface intf = intfs.stream().findFirst().get();
1604 Interface prevIntf = prevIntfs.stream().findFirst().get();
1605
1606 DeviceId deviceId = intf.connectPoint().deviceId();
1607 PortNumber portNum = intf.connectPoint().port();
1608
1609 if (!mastershipService.isLocalMaster(deviceId)) {
1610 log.debug("CONFIG_UPDATED event for interfaces should be " +
1611 "handled by master node for device {}", deviceId);
1612 return;
1613 }
1614
1615 removeSubnetConfig(prevIntf.connectPoint(),
1616 Sets.difference(new HashSet<>(prevIntf.ipAddressesList()),
1617 new HashSet<>(intf.ipAddressesList())));
1618
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09001619 if (!prevIntf.vlanNative().equals(VlanId.NONE)
1620 && !prevIntf.vlanNative().equals(intf.vlanUntagged())
1621 && !prevIntf.vlanNative().equals(intf.vlanNative())) {
1622 if (intf.vlanTagged().contains(prevIntf.vlanNative())) {
1623 // Update filtering objective and L2IG group bucket
1624 updatePortVlanTreatment(deviceId, portNum, prevIntf.vlanNative(), false);
1625 } else {
1626 // RemoveVlanNative
1627 updateVlanConfigInternal(deviceId, portNum, prevIntf.vlanNative(), true, false);
1628 }
1629 }
1630
1631 if (!prevIntf.vlanUntagged().equals(VlanId.NONE)
1632 && !prevIntf.vlanUntagged().equals(intf.vlanUntagged())
1633 && !prevIntf.vlanUntagged().equals(intf.vlanNative())) {
1634 if (intf.vlanTagged().contains(prevIntf.vlanUntagged())) {
1635 // Update filtering objective and L2IG group bucket
1636 updatePortVlanTreatment(deviceId, portNum, prevIntf.vlanUntagged(), false);
1637 } else {
1638 // RemoveVlanUntagged
1639 updateVlanConfigInternal(deviceId, portNum, prevIntf.vlanUntagged(), true, false);
1640 }
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07001641 }
1642
1643 if (!prevIntf.vlanTagged().isEmpty() && !intf.vlanTagged().equals(prevIntf.vlanTagged())) {
1644 // RemoveVlanTagged
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09001645 Sets.difference(prevIntf.vlanTagged(), intf.vlanTagged()).stream()
1646 .filter(i -> !intf.vlanUntagged().equals(i))
1647 .filter(i -> !intf.vlanNative().equals(i))
1648 .forEach(vlanId -> updateVlanConfigInternal(
1649 deviceId, portNum, vlanId, false, false));
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07001650 }
1651
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09001652 if (!intf.vlanNative().equals(VlanId.NONE)
1653 && !prevIntf.vlanNative().equals(intf.vlanNative())
1654 && !prevIntf.vlanUntagged().equals(intf.vlanNative())) {
1655 if (prevIntf.vlanTagged().contains(intf.vlanNative())) {
1656 // Update filtering objective and L2IG group bucket
1657 updatePortVlanTreatment(deviceId, portNum, intf.vlanNative(), true);
1658 } else {
1659 // AddVlanNative
1660 updateVlanConfigInternal(deviceId, portNum, intf.vlanNative(), true, true);
1661 }
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07001662 }
1663
1664 if (!intf.vlanTagged().isEmpty() && !intf.vlanTagged().equals(prevIntf.vlanTagged())) {
1665 // AddVlanTagged
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09001666 Sets.difference(intf.vlanTagged(), prevIntf.vlanTagged()).stream()
1667 .filter(i -> !prevIntf.vlanUntagged().equals(i))
1668 .filter(i -> !prevIntf.vlanNative().equals(i))
1669 .forEach(vlanId -> updateVlanConfigInternal(
1670 deviceId, portNum, vlanId, false, true)
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07001671 );
1672 }
1673
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09001674 if (!intf.vlanUntagged().equals(VlanId.NONE)
1675 && !prevIntf.vlanUntagged().equals(intf.vlanUntagged())
1676 && !prevIntf.vlanNative().equals(intf.vlanUntagged())) {
1677 if (prevIntf.vlanTagged().contains(intf.vlanUntagged())) {
1678 // Update filtering objective and L2IG group bucket
1679 updatePortVlanTreatment(deviceId, portNum, intf.vlanUntagged(), true);
1680 } else {
1681 // AddVlanUntagged
1682 updateVlanConfigInternal(deviceId, portNum, intf.vlanUntagged(), true, true);
1683 }
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07001684 }
1685 addSubnetConfig(prevIntf.connectPoint(),
1686 Sets.difference(new HashSet<>(intf.ipAddressesList()),
1687 new HashSet<>(prevIntf.ipAddressesList())));
1688 } catch (ConfigException e) {
1689 log.error("Error in configuration");
1690 }
1691 }
1692
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09001693 private void updatePortVlanTreatment(DeviceId deviceId, PortNumber portNum,
1694 VlanId vlanId, boolean pushVlan) {
1695 DefaultGroupHandler grpHandler = getGroupHandler(deviceId);
1696 if (grpHandler == null) {
1697 log.warn("Failed to retrieve group handler for device {}", deviceId);
1698 return;
1699 }
1700
1701 // Update filtering objective for a single port
1702 routingRulePopulator.updateSinglePortFilters(deviceId, portNum, !pushVlan, vlanId, false);
1703 routingRulePopulator.updateSinglePortFilters(deviceId, portNum, pushVlan, vlanId, true);
1704
1705 if (getVlanNextObjectiveId(deviceId, vlanId) != -1) {
1706 // Update L2IG bucket of the port
1707 grpHandler.updateL2InterfaceGroupBucket(portNum, vlanId, pushVlan);
1708 } else {
1709 log.warn("Failed to retrieve next objective for vlan {} in device {}:{}", vlanId, deviceId, portNum);
1710 }
1711 }
1712
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07001713 private void updateVlanConfigInternal(DeviceId deviceId, PortNumber portNum,
1714 VlanId vlanId, boolean pushVlan, boolean install) {
1715 DefaultGroupHandler grpHandler = getGroupHandler(deviceId);
1716 if (grpHandler == null) {
1717 log.warn("Failed to retrieve group handler for device {}", deviceId);
1718 return;
1719 }
1720
1721 // Update filtering objective for a single port
1722 routingRulePopulator.updateSinglePortFilters(deviceId, portNum, pushVlan, vlanId, install);
1723
1724 // Update filtering objective for multicast ingress port
1725 mcastHandler.updateFilterToDevice(deviceId, portNum, vlanId, install);
1726
1727 int nextId = getVlanNextObjectiveId(deviceId, vlanId);
1728
1729 if (nextId != -1 && !install) {
1730 // Update next objective for a single port as an output port
1731 // Remove a single port from L2FG
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09001732 grpHandler.updateGroupFromVlanConfiguration(vlanId, portNum, nextId, install);
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07001733 // Remove L2 Bridging rule and L3 Unicast rule to the host
1734 hostHandler.processIntfVlanUpdatedEvent(deviceId, portNum, vlanId, pushVlan, install);
1735 // Remove broadcast forwarding rule and corresponding L2FG for VLAN
1736 // only if there is no port configured on that VLAN ID
1737 if (!getVlanPortMap(deviceId).containsKey(vlanId)) {
1738 // Remove broadcast forwarding rule for the VLAN
1739 routingRulePopulator.updateSubnetBroadcastRule(deviceId, vlanId, install);
1740 // Remove L2FG for VLAN
1741 grpHandler.removeBcastGroupFromVlan(deviceId, portNum, vlanId, pushVlan);
1742 } else {
1743 // Remove L2IG of the port
1744 grpHandler.removePortNextObjective(deviceId, portNum, vlanId, pushVlan);
1745 }
1746 } else if (install) {
1747 if (nextId != -1) {
1748 // Add a single port to L2FG
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09001749 grpHandler.updateGroupFromVlanConfiguration(vlanId, portNum, nextId, install);
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07001750 } else {
1751 // Create L2FG for VLAN
1752 grpHandler.createBcastGroupFromVlan(vlanId, Collections.singleton(portNum));
1753 routingRulePopulator.updateSubnetBroadcastRule(deviceId, vlanId, install);
1754 }
1755 hostHandler.processIntfVlanUpdatedEvent(deviceId, portNum, vlanId, pushVlan, install);
1756 } else {
1757 log.warn("Failed to retrieve next objective for vlan {} in device {}:{}", vlanId, deviceId, portNum);
1758 }
1759 }
1760
1761 private void removeSubnetConfig(ConnectPoint cp, Set<InterfaceIpAddress> ipAddressSet) {
1762 Set<IpPrefix> ipPrefixSet = ipAddressSet.stream().
1763 map(InterfaceIpAddress::subnetAddress).collect(Collectors.toSet());
1764
1765 Set<InterfaceIpAddress> deviceIntfIpAddrs = interfaceService.getInterfaces().stream()
1766 .filter(intf -> intf.connectPoint().deviceId().equals(cp.deviceId()))
1767 .filter(intf -> !intf.connectPoint().equals(cp))
1768 .flatMap(intf -> intf.ipAddressesList().stream())
1769 .collect(Collectors.toSet());
1770 // 1. Partial subnet population
1771 // Remove routing rules for removed subnet from previous configuration,
1772 // which does not also exist in other interfaces in the same device
1773 Set<IpPrefix> deviceIpPrefixSet = deviceIntfIpAddrs.stream()
1774 .map(InterfaceIpAddress::subnetAddress)
1775 .collect(Collectors.toSet());
1776
1777 defaultRoutingHandler.revokeSubnet(
1778 ipPrefixSet.stream()
1779 .filter(ipPrefix -> !deviceIpPrefixSet.contains(ipPrefix))
1780 .collect(Collectors.toSet()));
1781
1782 // 2. Interface IP punts
1783 // Remove IP punts for old Intf address
1784 Set<IpAddress> deviceIpAddrs = deviceIntfIpAddrs.stream()
1785 .map(InterfaceIpAddress::ipAddress)
1786 .collect(Collectors.toSet());
1787 ipAddressSet.stream()
1788 .map(InterfaceIpAddress::ipAddress)
1789 .filter(interfaceIpAddress -> !deviceIpAddrs.contains(interfaceIpAddress))
1790 .forEach(interfaceIpAddress ->
1791 routingRulePopulator.revokeSingleIpPunts(
1792 cp.deviceId(), interfaceIpAddress));
1793
1794 // 3. Host unicast routing rule
1795 // Remove unicast routing rule
1796 hostHandler.processIntfIpUpdatedEvent(cp, ipPrefixSet, false);
1797 }
1798
1799 private void addSubnetConfig(ConnectPoint cp, Set<InterfaceIpAddress> ipAddressSet) {
1800 Set<IpPrefix> ipPrefixSet = ipAddressSet.stream().
1801 map(InterfaceIpAddress::subnetAddress).collect(Collectors.toSet());
1802
1803 Set<InterfaceIpAddress> deviceIntfIpAddrs = interfaceService.getInterfaces().stream()
1804 .filter(intf -> intf.connectPoint().deviceId().equals(cp.deviceId()))
1805 .filter(intf -> !intf.connectPoint().equals(cp))
1806 .flatMap(intf -> intf.ipAddressesList().stream())
1807 .collect(Collectors.toSet());
1808 // 1. Partial subnet population
1809 // Add routing rules for newly added subnet, which does not also exist in
1810 // other interfaces in the same device
1811 Set<IpPrefix> deviceIpPrefixSet = deviceIntfIpAddrs.stream()
1812 .map(InterfaceIpAddress::subnetAddress)
1813 .collect(Collectors.toSet());
1814
1815 defaultRoutingHandler.populateSubnet(
1816 Collections.singleton(cp),
1817 ipPrefixSet.stream()
1818 .filter(ipPrefix -> !deviceIpPrefixSet.contains(ipPrefix))
1819 .collect(Collectors.toSet()));
1820
1821 // 2. Interface IP punts
1822 // Add IP punts for new Intf address
1823 Set<IpAddress> deviceIpAddrs = deviceIntfIpAddrs.stream()
1824 .map(InterfaceIpAddress::ipAddress)
1825 .collect(Collectors.toSet());
1826 ipAddressSet.stream()
1827 .map(InterfaceIpAddress::ipAddress)
1828 .filter(interfaceIpAddress -> !deviceIpAddrs.contains(interfaceIpAddress))
1829 .forEach(interfaceIpAddress ->
1830 routingRulePopulator.populateSingleIpPunts(
1831 cp.deviceId(), interfaceIpAddress));
1832
1833 // 3. Host unicast routing rule
1834 // Add unicast routing rule
1835 hostHandler.processIntfIpUpdatedEvent(cp, ipPrefixSet, true);
1836 }
sangho80f11cb2015-04-01 13:05:26 -07001837}