blob: 79dd832cddf8b12317b7bedc24bd5482ab87010b [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 Pantelopoulos96851252018-03-20 13:58:49 -0700106import org.onosproject.segmentrouting.pwaas.DefaultL2TunnelDescription;
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800107import org.onosproject.segmentrouting.pwaas.DefaultL2TunnelHandler;
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700108import org.onosproject.segmentrouting.pwaas.DefaultL2TunnelPolicy;
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -0800109
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
Andreas Pantelopoulos96851252018-03-20 13:58:49 -0700572 @Deprecated
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
Andreas Pantelopoulos96851252018-03-20 13:58:49 -0700583 L2TunnelHandler.Result retRes = L2TunnelHandler.Result.SUCCESS;
584 L2TunnelHandler.Result res;
585 for (DefaultL2TunnelDescription pw : bulkPseudowires) {
586 res = addPseudowire(pw);
587 if (res != L2TunnelHandler.Result.SUCCESS) {
588 log.error("Pseudowire with id {} can not be instantiated !", res);
589 retRes = res;
590 }
Andreas Pantelopoulosfc4bc2a2018-03-12 16:30:20 -0700591 }
Andreas Pantelopoulos96851252018-03-20 13:58:49 -0700592
593 return retRes;
Andreas Pantelopoulosfc4bc2a2018-03-12 16:30:20 -0700594 }
595
596 @Override
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -0800597 public L2TunnelHandler.Result addPseudowire(L2TunnelDescription l2TunnelDescription) {
598
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -0700599 // get both added and pending pseudowires
600 List<L2TunnelDescription> newPseudowires = new ArrayList<>();
601 newPseudowires.addAll(l2TunnelHandler.getL2Descriptions(false));
602 newPseudowires.addAll(l2TunnelHandler.getL2Descriptions(true));
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -0800603
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -0700604 // add the new pseudowire to the List
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -0800605 newPseudowires.add(l2TunnelDescription);
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -0700606 // validate the new list of pseudowires
Andreas Pantelopoulos96851252018-03-20 13:58:49 -0700607 L2TunnelHandler.Result res = configurationValidity(newPseudowires);
608 if (res == L2TunnelHandler.Result.SUCCESS) {
609 log.debug("Pseudowire with {} deployment started, check log for any errors in this process!",
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -0800610 l2TunnelDescription.l2Tunnel().tunnelId());
Andreas Pantelopoulos96851252018-03-20 13:58:49 -0700611 return l2TunnelHandler.deployPseudowire(l2TunnelDescription, false);
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -0800612 } else {
Andreas Pantelopoulos96851252018-03-20 13:58:49 -0700613 log.error("Pseudowire with {} can not be added, error in global validity!",
614 l2TunnelDescription.l2Tunnel().tunnelId());
615 return res;
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700616 }
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700617 }
618
619 @Override
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -0800620 public L2TunnelHandler.Result removePseudowire(Integer pwId) {
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700621
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -0700622 // get both added and pending pseudowires
623 Set<L2TunnelDescription> pseudowires = l2TunnelHandler.getL2Descriptions(false)
624 .stream()
625 .filter(pw -> pw.l2Tunnel().tunnelId() == pwId)
626 .collect(Collectors.toSet());
627 Set<L2TunnelDescription> pendingPseudowires = l2TunnelHandler.getL2Descriptions(true)
628 .stream()
629 .filter(pw -> pw.l2Tunnel().tunnelId() == pwId)
630 .collect(Collectors.toSet());
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700631
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -0700632 if ((pendingPseudowires.size() == 0) && (pseudowires.size() == 0)) {
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -0800633 log.error("Pseudowire with id {} does not exist", pwId);
Andreas Pantelopoulos96851252018-03-20 13:58:49 -0700634 return L2TunnelHandler.Result.WRONG_PARAMETERS
635 .appendError("Pseudowire does not exist.");
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -0700636 }
637 if (pendingPseudowires.size() != 0) {
638 log.info("Remove pseudowire from pending store!");
639 // will fill when we implement failure mechanism detection.
640 }
641 if (pseudowires.size() != 0) {
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -0800642 log.info("Removal of pseudowire with {} started, check log for any errors in this process!",
643 pwId);
Andreas Pantelopoulos96851252018-03-20 13:58:49 -0700644 return l2TunnelHandler.tearDownPseudowire(pwId);
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700645 }
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -0700646
647 return L2TunnelHandler.Result.SUCCESS;
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700648 }
649
650 @Override
Saurav Das07c74602016-04-27 18:35:50 -0700651 public void rerouteNetwork() {
652 cfgListener.configureNetwork();
Saurav Das07c74602016-04-27 18:35:50 -0700653 }
654
Charles Chand7844e52016-10-20 17:02:44 -0700655 @Override
Pier Ventreb6a7f342016-11-26 21:05:22 -0800656 public Map<DeviceId, Set<IpPrefix>> getDeviceSubnetMap() {
657 Map<DeviceId, Set<IpPrefix>> deviceSubnetMap = Maps.newHashMap();
Jonathan Hart61e24e12017-11-30 18:23:42 -0800658 deviceConfiguration.getRouters().forEach(device ->
659 deviceSubnetMap.put(device, deviceConfiguration.getSubnets(device)));
Charles Chand7844e52016-10-20 17:02:44 -0700660 return deviceSubnetMap;
661 }
662
Saurav Das62ae6792017-05-15 15:34:25 -0700663
664 @Override
665 public ImmutableMap<DeviceId, EcmpShortestPathGraph> getCurrentEcmpSpg() {
666 if (defaultRoutingHandler != null) {
667 return defaultRoutingHandler.getCurrentEmcpSpgMap();
668 } else {
669 return null;
670 }
671 }
672
673 @Override
Saurav Das261c3002017-06-13 15:35:54 -0700674 public ImmutableMap<DestinationSetNextObjectiveStoreKey, NextNeighbors> getDestinationSet() {
675 if (dsNextObjStore != null) {
676 return ImmutableMap.copyOf(dsNextObjStore.entrySet());
Saurav Das62ae6792017-05-15 15:34:25 -0700677 } else {
678 return ImmutableMap.of();
679 }
680 }
681
Saurav Dasfbe74572017-08-03 18:30:35 -0700682 @Override
683 public void verifyGroups(DeviceId id) {
684 DefaultGroupHandler gh = groupHandlerMap.get(id);
685 if (gh != null) {
686 gh.triggerBucketCorrector();
687 }
688 }
689
Saurav Das6430f412018-01-25 09:49:01 -0800690 @Override
691 public ImmutableMap<Link, Boolean> getSeenLinks() {
692 return linkHandler.getSeenLinks();
693 }
694
695 @Override
696 public ImmutableMap<DeviceId, Set<PortNumber>> getDownedPortState() {
697 return linkHandler.getDownedPorts();
698 }
699
Pier Luigi0f9635b2018-01-15 18:06:43 +0100700 @Override
701 public Map<McastStoreKey, Integer> getMcastNextIds(IpAddress mcastIp) {
702 return mcastHandler.getMcastNextIds(mcastIp);
703 }
704
705 @Override
Pier Luigi69f774d2018-02-28 12:10:50 +0100706 public Map<McastStoreKey, McastRole> getMcastRoles(IpAddress mcastIp) {
Pier Luigi0f9635b2018-01-15 18:06:43 +0100707 return mcastHandler.getMcastRoles(mcastIp);
708 }
709
710 @Override
711 public Map<ConnectPoint, List<ConnectPoint>> getMcastPaths(IpAddress mcastIp) {
712 return mcastHandler.getMcastPaths(mcastIp);
713 }
714
sangho80f1f892015-05-19 11:57:42 -0700715 /**
Ray Milkeyb85de082017-04-05 09:42:04 -0700716 * Extracts the application ID from the manager.
717 *
718 * @return application ID
719 */
720 public ApplicationId appId() {
721 return appId;
722 }
723
724 /**
725 * Returns the device configuration.
726 *
727 * @return device configuration
728 */
729 public DeviceConfiguration deviceConfiguration() {
730 return deviceConfiguration;
731 }
732
733 /**
Saurav Das261c3002017-06-13 15:35:54 -0700734 * Per device next objective ID store with (device id + destination set) as key.
Charles Chan53de91f2017-08-22 15:07:34 -0700735 * Used to keep track on MPLS group information.
Ray Milkeyb85de082017-04-05 09:42:04 -0700736 *
737 * @return next objective ID store
738 */
Saurav Das261c3002017-06-13 15:35:54 -0700739 public EventuallyConsistentMap<DestinationSetNextObjectiveStoreKey, NextNeighbors>
740 dsNextObjStore() {
741 return dsNextObjStore;
Ray Milkeyb85de082017-04-05 09:42:04 -0700742 }
743
744 /**
Charles Chan53de91f2017-08-22 15:07:34 -0700745 * Per device next objective ID store with (device id + vlanid) as key.
746 * Used to keep track on L2 flood group information.
Ray Milkeyb85de082017-04-05 09:42:04 -0700747 *
748 * @return vlan next object store
749 */
750 public EventuallyConsistentMap<VlanNextObjectiveStoreKey, Integer> vlanNextObjStore() {
751 return vlanNextObjStore;
752 }
753
754 /**
Charles Chan53de91f2017-08-22 15:07:34 -0700755 * Per device next objective ID store with (device id + port + treatment + meta) as key.
756 * Used to keep track on L2 interface group and L3 unicast group information.
Ray Milkeyb85de082017-04-05 09:42:04 -0700757 *
758 * @return port next object store.
759 */
760 public EventuallyConsistentMap<PortNextObjectiveStoreKey, Integer> portNextObjStore() {
761 return portNextObjStore;
762 }
763
764 /**
Saurav Das261c3002017-06-13 15:35:54 -0700765 * Returns the MPLS-ECMP configuration which indicates whether ECMP on
766 * labeled packets should be programmed or not.
Pier Ventre7a78de22016-10-31 15:00:01 -0700767 *
768 * @return MPLS-ECMP value
769 */
770 public boolean getMplsEcmp() {
771 SegmentRoutingAppConfig segmentRoutingAppConfig = cfgService
772 .getConfig(this.appId, SegmentRoutingAppConfig.class);
773 return segmentRoutingAppConfig != null && segmentRoutingAppConfig.mplsEcmp();
774 }
775
776 /**
sangho80f1f892015-05-19 11:57:42 -0700777 * Returns the tunnel object with the tunnel ID.
778 *
779 * @param tunnelId Tunnel ID
780 * @return Tunnel reference
781 */
sangho27462c62015-05-14 00:39:53 -0700782 public Tunnel getTunnel(String tunnelId) {
783 return tunnelHandler.getTunnel(tunnelId);
784 }
785
Charles Chan90772a72017-02-08 15:52:08 -0800786 // TODO Consider moving these to InterfaceService
sangho80f11cb2015-04-01 13:05:26 -0700787 /**
Charles Chan10b0fb72017-02-02 16:20:42 -0800788 * Returns untagged VLAN configured on given connect point.
Charles Chan90772a72017-02-08 15:52:08 -0800789 * <p>
790 * Only returns the first match if there are multiple untagged VLAN configured
791 * on the connect point.
sangho80f11cb2015-04-01 13:05:26 -0700792 *
Charles Chan10b0fb72017-02-02 16:20:42 -0800793 * @param connectPoint connect point
794 * @return untagged VLAN or null if not configured
sangho80f11cb2015-04-01 13:05:26 -0700795 */
Charles Chan3ed34d82017-06-22 18:03:14 -0700796 VlanId getUntaggedVlanId(ConnectPoint connectPoint) {
Charles Chan10b0fb72017-02-02 16:20:42 -0800797 return interfaceService.getInterfacesByPort(connectPoint).stream()
798 .filter(intf -> !intf.vlanUntagged().equals(VlanId.NONE))
799 .map(Interface::vlanUntagged)
800 .findFirst().orElse(null);
sangho80f11cb2015-04-01 13:05:26 -0700801 }
802
sangho27462c62015-05-14 00:39:53 -0700803 /**
Charles Chan90772a72017-02-08 15:52:08 -0800804 * Returns tagged VLAN configured on given connect point.
805 * <p>
806 * Returns all matches if there are multiple tagged VLAN configured
807 * on the connect point.
808 *
809 * @param connectPoint connect point
810 * @return tagged VLAN or empty set if not configured
811 */
Charles Chan3ed34d82017-06-22 18:03:14 -0700812 Set<VlanId> getTaggedVlanId(ConnectPoint connectPoint) {
Charles Chan90772a72017-02-08 15:52:08 -0800813 Set<Interface> interfaces = interfaceService.getInterfacesByPort(connectPoint);
814 return interfaces.stream()
815 .map(Interface::vlanTagged)
Charles Chan3ed34d82017-06-22 18:03:14 -0700816 .flatMap(Set::stream)
Charles Chan90772a72017-02-08 15:52:08 -0800817 .collect(Collectors.toSet());
818 }
819
820 /**
821 * Returns native VLAN configured on given connect point.
822 * <p>
823 * Only returns the first match if there are multiple native VLAN configured
824 * on the connect point.
825 *
826 * @param connectPoint connect point
827 * @return native VLAN or null if not configured
828 */
Charles Chan3ed34d82017-06-22 18:03:14 -0700829 VlanId getNativeVlanId(ConnectPoint connectPoint) {
Charles Chan90772a72017-02-08 15:52:08 -0800830 Set<Interface> interfaces = interfaceService.getInterfacesByPort(connectPoint);
831 return interfaces.stream()
832 .filter(intf -> !intf.vlanNative().equals(VlanId.NONE))
833 .map(Interface::vlanNative)
834 .findFirst()
835 .orElse(null);
836 }
837
838 /**
Charles Chand9265a32017-06-16 15:19:24 -0700839 * Returns internal VLAN for untagged hosts on given connect point.
840 * <p>
841 * The internal VLAN is either vlan-untagged for an access port,
842 * or vlan-native for a trunk port.
843 *
844 * @param connectPoint connect point
845 * @return internal VLAN or null if both vlan-untagged and vlan-native are undefined
846 */
Pier Luigi69f774d2018-02-28 12:10:50 +0100847 public VlanId getInternalVlanId(ConnectPoint connectPoint) {
Charles Chand9265a32017-06-16 15:19:24 -0700848 VlanId untaggedVlanId = getUntaggedVlanId(connectPoint);
849 VlanId nativeVlanId = getNativeVlanId(connectPoint);
850 return untaggedVlanId != null ? untaggedVlanId : nativeVlanId;
851 }
852
853 /**
Charles Chan3ed34d82017-06-22 18:03:14 -0700854 * Returns optional pair device ID of given device.
855 *
856 * @param deviceId device ID
857 * @return optional pair device ID. Might be empty if pair device is not configured
858 */
859 Optional<DeviceId> getPairDeviceId(DeviceId deviceId) {
860 SegmentRoutingDeviceConfig deviceConfig =
861 cfgService.getConfig(deviceId, SegmentRoutingDeviceConfig.class);
862 return Optional.ofNullable(deviceConfig).map(SegmentRoutingDeviceConfig::pairDeviceId);
863 }
864 /**
865 * Returns optional pair device local port of given device.
866 *
867 * @param deviceId device ID
868 * @return optional pair device ID. Might be empty if pair device is not configured
869 */
870 Optional<PortNumber> getPairLocalPorts(DeviceId deviceId) {
871 SegmentRoutingDeviceConfig deviceConfig =
872 cfgService.getConfig(deviceId, SegmentRoutingDeviceConfig.class);
873 return Optional.ofNullable(deviceConfig).map(SegmentRoutingDeviceConfig::pairLocalPort);
874 }
875
876 /**
Charles Chan910be6a2017-08-23 14:46:43 -0700877 * Determine if current instance is the master of given connect point.
878 *
879 * @param cp connect point
880 * @return true if current instance is the master of given connect point
881 */
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700882 public boolean isMasterOf(ConnectPoint cp) {
Charles Chan910be6a2017-08-23 14:46:43 -0700883 boolean isMaster = mastershipService.isLocalMaster(cp.deviceId());
884 if (!isMaster) {
885 log.debug(NOT_MASTER, cp);
886 }
887 return isMaster;
888 }
889
890 /**
Charles Chanf0ae41e2017-08-23 13:55:39 -0700891 * Returns locations of given resolved route.
892 *
893 * @param resolvedRoute resolved route
894 * @return locations of nexthop. Might be empty if next hop is not found
895 */
896 Set<ConnectPoint> nextHopLocations(ResolvedRoute resolvedRoute) {
897 HostId hostId = HostId.hostId(resolvedRoute.nextHopMac(), resolvedRoute.nextHopVlan());
898 return Optional.ofNullable(hostService.getHost(hostId))
899 .map(Host::locations).orElse(Sets.newHashSet())
900 .stream().map(l -> (ConnectPoint) l).collect(Collectors.toSet());
901 }
902
903 /**
Charles Chan90772a72017-02-08 15:52:08 -0800904 * Returns vlan port map of given device.
905 *
906 * @param deviceId device id
907 * @return vlan-port multimap
908 */
909 public Multimap<VlanId, PortNumber> getVlanPortMap(DeviceId deviceId) {
910 HashMultimap<VlanId, PortNumber> vlanPortMap = HashMultimap.create();
911
912 interfaceService.getInterfaces().stream()
913 .filter(intf -> intf.connectPoint().deviceId().equals(deviceId))
914 .forEach(intf -> {
915 vlanPortMap.put(intf.vlanUntagged(), intf.connectPoint().port());
Charles Chan3ed34d82017-06-22 18:03:14 -0700916 intf.vlanTagged().forEach(vlanTagged ->
917 vlanPortMap.put(vlanTagged, intf.connectPoint().port())
918 );
Charles Chan90772a72017-02-08 15:52:08 -0800919 vlanPortMap.put(intf.vlanNative(), intf.connectPoint().port());
920 });
921 vlanPortMap.removeAll(VlanId.NONE);
922
923 return vlanPortMap;
924 }
925
926 /**
Charles Chan10b0fb72017-02-02 16:20:42 -0800927 * Returns the next objective ID for the given vlan id. It is expected
Saurav Das2d94d312015-11-24 23:21:05 -0800928 * that the next-objective has been pre-created from configuration.
Charles Chan77277672015-10-20 16:24:19 -0700929 *
930 * @param deviceId Device ID
Charles Chan10b0fb72017-02-02 16:20:42 -0800931 * @param vlanId VLAN ID
Saurav Das2d94d312015-11-24 23:21:05 -0800932 * @return next objective ID or -1 if it was not found
Charles Chan77277672015-10-20 16:24:19 -0700933 */
Charles Chan3ed34d82017-06-22 18:03:14 -0700934 int getVlanNextObjectiveId(DeviceId deviceId, VlanId vlanId) {
Charles Chan77277672015-10-20 16:24:19 -0700935 if (groupHandlerMap.get(deviceId) != null) {
Charles Chan10b0fb72017-02-02 16:20:42 -0800936 log.trace("getVlanNextObjectiveId query in device {}", deviceId);
937 return groupHandlerMap.get(deviceId).getVlanNextObjectiveId(vlanId);
Charles Chan77277672015-10-20 16:24:19 -0700938 } else {
Charles Chan10b0fb72017-02-02 16:20:42 -0800939 log.warn("getVlanNextObjectiveId query - groupHandler for "
Saurav Das2d94d312015-11-24 23:21:05 -0800940 + "device {} not found", deviceId);
941 return -1;
942 }
943 }
944
945 /**
946 * Returns the next objective ID for the given portNumber, given the treatment.
947 * There could be multiple different treatments to the same outport, which
Saurav Das2cb38292017-03-29 19:09:17 -0700948 * would result in different objectives. If the next object does not exist,
949 * and should be created, a new one is created and its id is returned.
Saurav Das2d94d312015-11-24 23:21:05 -0800950 *
951 * @param deviceId Device ID
952 * @param portNum port number on device for which NextObjective is queried
953 * @param treatment the actions to apply on the packets (should include outport)
954 * @param meta metadata passed into the creation of a Next Objective if necessary
Saurav Das2cb38292017-03-29 19:09:17 -0700955 * @param createIfMissing true if a next object should be created if not found
Saurav Das07c74602016-04-27 18:35:50 -0700956 * @return next objective ID or -1 if an error occurred during retrieval or creation
Saurav Das2d94d312015-11-24 23:21:05 -0800957 */
958 public int getPortNextObjectiveId(DeviceId deviceId, PortNumber portNum,
959 TrafficTreatment treatment,
Saurav Das2cb38292017-03-29 19:09:17 -0700960 TrafficSelector meta,
961 boolean createIfMissing) {
Saurav Das2d94d312015-11-24 23:21:05 -0800962 DefaultGroupHandler ghdlr = groupHandlerMap.get(deviceId);
963 if (ghdlr != null) {
Saurav Das2cb38292017-03-29 19:09:17 -0700964 return ghdlr.getPortNextObjectiveId(portNum, treatment, meta, createIfMissing);
Saurav Das2d94d312015-11-24 23:21:05 -0800965 } else {
Charles Chanb7f75ac2016-01-11 18:28:54 -0800966 log.warn("getPortNextObjectiveId query - groupHandler for device {}"
967 + " not found", deviceId);
968 return -1;
969 }
970 }
971
Saurav Das62ae6792017-05-15 15:34:25 -0700972 /**
973 * Returns the group handler object for the specified device id.
974 *
975 * @param devId the device identifier
976 * @return the groupHandler object for the device id, or null if not found
977 */
Charles Chan3ed34d82017-06-22 18:03:14 -0700978 DefaultGroupHandler getGroupHandler(DeviceId devId) {
Saurav Das62ae6792017-05-15 15:34:25 -0700979 return groupHandlerMap.get(devId);
980 }
981
982 /**
Saurav Dasfbe74572017-08-03 18:30:35 -0700983 * Returns the default routing handler object.
984 *
985 * @return the default routing handler object
986 */
987 public DefaultRoutingHandler getRoutingHandler() {
988 return defaultRoutingHandler;
989 }
990
sangho80f11cb2015-04-01 13:05:26 -0700991 private class InternalPacketProcessor implements PacketProcessor {
sangho80f11cb2015-04-01 13:05:26 -0700992 @Override
993 public void process(PacketContext context) {
994
995 if (context.isHandled()) {
996 return;
997 }
998
999 InboundPacket pkt = context.inPacket();
1000 Ethernet ethernet = pkt.parsed();
Pier Luigi37a35432017-02-01 13:50:04 -08001001
1002 if (ethernet == null) {
1003 return;
1004 }
1005
Saurav Das261c3002017-06-13 15:35:54 -07001006 log.trace("Rcvd pktin from {}: {}", context.inPacket().receivedFrom(),
1007 ethernet);
Pier Ventreadb4ae62016-11-23 09:57:42 -08001008 if (ethernet.getEtherType() == TYPE_ARP) {
Saurav Das62ae6792017-05-15 15:34:25 -07001009 log.warn("Received unexpected ARP packet on {}",
1010 context.inPacket().receivedFrom());
Saurav Das368cf212017-03-15 15:15:14 -07001011 log.trace("{}", ethernet);
Pier Ventre6b2c1b32016-12-09 17:26:04 -08001012 return;
sangho80f11cb2015-04-01 13:05:26 -07001013 } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV4) {
Pier Ventreb6b81d52016-12-02 08:16:05 -08001014 IPv4 ipv4Packet = (IPv4) ethernet.getPayload();
1015 //ipHandler.addToPacketBuffer(ipv4Packet);
1016 if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_ICMP) {
1017 icmpHandler.processIcmp(ethernet, pkt.receivedFrom());
sangho80f11cb2015-04-01 13:05:26 -07001018 } else {
Charles Chand041ad82017-01-13 17:20:44 -08001019 // NOTE: We don't support IP learning at this moment so this
1020 // is not necessary. Also it causes duplication of DHCP packets.
Pier Ventre6b2c1b32016-12-09 17:26:04 -08001021 // ipHandler.processPacketIn(ipv4Packet, pkt.receivedFrom());
sangho80f11cb2015-04-01 13:05:26 -07001022 }
Pier Ventreb6a7f342016-11-26 21:05:22 -08001023 } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV6) {
1024 IPv6 ipv6Packet = (IPv6) ethernet.getPayload();
Pier Ventreb6b81d52016-12-02 08:16:05 -08001025 //ipHandler.addToPacketBuffer(ipv6Packet);
Pier Luigi37a35432017-02-01 13:50:04 -08001026 // We deal with the packet only if the packet is a ICMP6 ECHO/REPLY
Pier Ventreb6b81d52016-12-02 08:16:05 -08001027 if (ipv6Packet.getNextHeader() == IPv6.PROTOCOL_ICMP6) {
1028 ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload();
1029 if (icmp6Packet.getIcmpType() == ICMP6.ECHO_REQUEST ||
1030 icmp6Packet.getIcmpType() == ICMP6.ECHO_REPLY) {
1031 icmpHandler.processIcmpv6(ethernet, pkt.receivedFrom());
1032 } else {
Saurav Das62ae6792017-05-15 15:34:25 -07001033 log.trace("Received ICMPv6 0x{} - not handled",
Charles Chand3727b72017-03-13 13:10:30 -07001034 Integer.toHexString(icmp6Packet.getIcmpType() & 0xff));
Pier Ventreb6b81d52016-12-02 08:16:05 -08001035 }
1036 } else {
1037 // NOTE: We don't support IP learning at this moment so this
1038 // is not necessary. Also it causes duplication of DHCPv6 packets.
1039 // ipHandler.processPacketIn(ipv6Packet, pkt.receivedFrom());
1040 }
sangho80f11cb2015-04-01 13:05:26 -07001041 }
1042 }
1043 }
1044
Saurav Das2d94d312015-11-24 23:21:05 -08001045 @SuppressWarnings("rawtypes")
sangho80f11cb2015-04-01 13:05:26 -07001046 private void scheduleEventHandlerIfNotScheduled(Event event) {
Charles Chan3ed34d82017-06-22 18:03:14 -07001047 synchronized (THREAD_SCHED_LOCK) {
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -07001048 eventQueue.add(event);
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -07001049 numOfEventsQueued++;
1050
1051 if ((numOfHandlerScheduled - numOfHandlerExecution) == 0) {
1052 //No pending scheduled event handling threads. So start a new one.
Charles Chan3f4aca62018-03-21 16:57:47 -07001053 executorService.schedule(eventHandler, 100, TimeUnit.MILLISECONDS);
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -07001054 numOfHandlerScheduled++;
1055 }
Jonathan Hart54541d12016-04-12 15:39:44 -07001056 log.trace("numOfEventsQueued {}, numOfEventHandlerScheduled {}",
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -07001057 numOfEventsQueued,
1058 numOfHandlerScheduled);
sangho80f11cb2015-04-01 13:05:26 -07001059 }
sangho80f11cb2015-04-01 13:05:26 -07001060 }
1061
1062 private class InternalEventHandler implements Runnable {
Srikanth Vavilapalli37a461b2015-04-07 15:12:32 -07001063 @Override
sangho80f11cb2015-04-01 13:05:26 -07001064 public void run() {
Pier Luigi8f362362018-02-12 09:56:20 +01001065 while (true) {
1066 try {
Saurav Das2d94d312015-11-24 23:21:05 -08001067 @SuppressWarnings("rawtypes")
Charles Chan3ed34d82017-06-22 18:03:14 -07001068 Event event;
1069 synchronized (THREAD_SCHED_LOCK) {
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -07001070 if (!eventQueue.isEmpty()) {
1071 event = eventQueue.poll();
1072 numOfEventsExecuted++;
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -07001073 } else {
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -07001074 numOfHandlerExecution++;
1075 log.debug("numOfHandlerExecution {} numOfEventsExecuted {}",
1076 numOfHandlerExecution, numOfEventsExecuted);
1077 break;
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -07001078 }
sanghofb7c7292015-04-13 15:15:58 -07001079 }
Pier Luigid8a15162018-02-15 16:33:08 +01001080 // TODO We should also change SR routing and PW to listen to TopologyEvents
Charles Chan0cff8aa2017-03-29 16:39:05 -07001081 if (event.type() == LinkEvent.Type.LINK_ADDED ||
1082 event.type() == LinkEvent.Type.LINK_UPDATED) {
Saurav Dase6c448a2018-01-18 12:07:33 -08001083 linkHandler.processLinkAdded((Link) event.subject());
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -07001084 } else if (event.type() == LinkEvent.Type.LINK_REMOVED) {
Saurav Dase6c448a2018-01-18 12:07:33 -08001085 linkHandler.processLinkRemoved((Link) event.subject());
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -07001086 } else if (event.type() == DeviceEvent.Type.DEVICE_ADDED ||
1087 event.type() == DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED ||
1088 event.type() == DeviceEvent.Type.DEVICE_UPDATED) {
Saurav Das62af8802015-12-04 10:52:59 -08001089 DeviceId deviceId = ((Device) event.subject()).id();
1090 if (deviceService.isAvailable(deviceId)) {
Saurav Dascea556f2018-03-05 14:37:16 -08001091 log.info("** DEVICE UP Processing device event {} "
1092 + "for available device {}",
Saurav Dasc28b3432015-10-30 17:45:38 -07001093 event.type(), ((Device) event.subject()).id());
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -07001094 processDeviceAdded((Device) event.subject());
Saurav Dasc3604f12016-03-23 11:22:49 -07001095 } else {
Saurav Dascea556f2018-03-05 14:37:16 -08001096 log.info(" ** DEVICE DOWN Processing device event {}"
1097 + " for unavailable device {}",
Pier Luigi8f362362018-02-12 09:56:20 +01001098 event.type(), ((Device) event.subject()).id());
Saurav Dasc3604f12016-03-23 11:22:49 -07001099 processDeviceRemoved((Device) event.subject());
1100 }
Saurav Dasf0f592d2016-11-18 15:21:57 -08001101 } else if (event.type() == DeviceEvent.Type.PORT_ADDED) {
Saurav Dasd1872b02016-12-02 15:43:47 -08001102 // typically these calls come when device is added first time
1103 // so port filtering rules are handled at the device_added event.
1104 // port added calls represent all ports on the device,
1105 // enabled or not.
Saurav Das62ae6792017-05-15 15:34:25 -07001106 log.trace("** PORT ADDED {}/{} -> {}",
Saurav Dasd1872b02016-12-02 15:43:47 -08001107 ((DeviceEvent) event).subject().id(),
1108 ((DeviceEvent) event).port().number(),
1109 event.type());
Saurav Dasf0f592d2016-11-18 15:21:57 -08001110 } else if (event.type() == DeviceEvent.Type.PORT_UPDATED) {
Saurav Dasd1872b02016-12-02 15:43:47 -08001111 // these calls happen for every subsequent event
1112 // ports enabled, disabled, switch goes away, comes back
Saurav Dasf0f592d2016-11-18 15:21:57 -08001113 log.info("** PORT UPDATED {}/{} -> {}",
1114 event.subject(),
1115 ((DeviceEvent) event).port(),
1116 event.type());
1117 processPortUpdated(((Device) event.subject()),
1118 ((DeviceEvent) event).port());
Pier Luigid8a15162018-02-15 16:33:08 +01001119 } else if (event.type() == TopologyEvent.Type.TOPOLOGY_CHANGED) {
1120 // Process topology event, needed for all modules relying on
1121 // topology service for path computation
1122 TopologyEvent topologyEvent = (TopologyEvent) event;
1123 log.info("Processing topology event {}, topology age {}, reasons {}",
1124 event.type(), topologyEvent.subject().time(),
1125 topologyEvent.reasons().size());
1126 topologyHandler.processTopologyChange(topologyEvent.reasons());
Charles Chan3f4aca62018-03-21 16:57:47 -07001127 } else if (event.type() == HostEvent.Type.HOST_ADDED) {
1128 hostHandler.processHostAddedEvent((HostEvent) event);
1129 } else if (event.type() == HostEvent.Type.HOST_MOVED) {
1130 hostHandler.processHostMovedEvent((HostEvent) event);
1131 routeHandler.processHostMovedEvent((HostEvent) event);
1132 } else if (event.type() == HostEvent.Type.HOST_REMOVED) {
1133 hostHandler.processHostRemovedEvent((HostEvent) event);
1134 } else if (event.type() == HostEvent.Type.HOST_UPDATED) {
1135 hostHandler.processHostUpdatedEvent((HostEvent) event);
1136 } else if (event.type() == RouteEvent.Type.ROUTE_ADDED) {
1137 routeHandler.processRouteAdded((RouteEvent) event);
1138 } else if (event.type() == RouteEvent.Type.ROUTE_UPDATED) {
1139 routeHandler.processRouteUpdated((RouteEvent) event);
1140 } else if (event.type() == RouteEvent.Type.ROUTE_REMOVED) {
1141 routeHandler.processRouteRemoved((RouteEvent) event);
1142 } else if (event.type() == RouteEvent.Type.ALTERNATIVE_ROUTES_CHANGED) {
1143 routeHandler.processAlternativeRoutesChanged((RouteEvent) event);
1144 } else if (event.type() == McastEvent.Type.SOURCE_ADDED ||
1145 event.type() == McastEvent.Type.SOURCE_UPDATED ||
1146 event.type() == McastEvent.Type.SINK_ADDED ||
1147 event.type() == McastEvent.Type.SINK_REMOVED ||
1148 event.type() == McastEvent.Type.ROUTE_REMOVED) {
1149 mcastHandler.processMcastEvent((McastEvent) event);
1150 } else if (event.type() == NetworkConfigEvent.Type.CONFIG_ADDED) {
1151 NetworkConfigEvent netcfgEvent = (NetworkConfigEvent) event;
1152 Class configClass = netcfgEvent.configClass();
1153 if (configClass.equals(SegmentRoutingAppConfig.class)) {
1154 appCfgHandler.processAppConfigAdded(netcfgEvent);
1155 log.info("App config event .. configuring network");
1156 cfgListener.configureNetwork();
1157 } else if (configClass.equals(SegmentRoutingDeviceConfig.class)) {
1158 log.info("Segment Routing Device Config added for {}", event.subject());
1159 cfgListener.configureNetwork();
1160 } else if (configClass.equals(XConnectConfig.class)) {
1161 xConnectHandler.processXConnectConfigAdded(netcfgEvent);
1162 } else if (configClass.equals(InterfaceConfig.class)) {
1163 log.info("Interface Config added for {}", event.subject());
1164 cfgListener.configureNetwork();
1165 } else {
1166 log.error("Unhandled config class: {}", configClass);
1167 }
1168 } else if (event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED) {
1169 NetworkConfigEvent netcfgEvent = (NetworkConfigEvent) event;
1170 Class configClass = netcfgEvent.configClass();
1171 if (configClass.equals(SegmentRoutingAppConfig.class)) {
1172 appCfgHandler.processAppConfigUpdated(netcfgEvent);
1173 log.info("App config event .. configuring network");
1174 cfgListener.configureNetwork();
1175 } else if (configClass.equals(SegmentRoutingDeviceConfig.class)) {
1176 log.info("Segment Routing Device Config updated for {}", event.subject());
1177 createOrUpdateDeviceConfiguration();
1178 } else if (configClass.equals(XConnectConfig.class)) {
1179 xConnectHandler.processXConnectConfigUpdated(netcfgEvent);
1180 } else if (configClass.equals(InterfaceConfig.class)) {
1181 log.info("Interface Config updated for {}", event.subject());
1182 createOrUpdateDeviceConfiguration();
1183 updateInterface((InterfaceConfig) netcfgEvent.config().get(),
1184 (InterfaceConfig) netcfgEvent.prevConfig().get());
1185 } else {
1186 log.error("Unhandled config class: {}", configClass);
1187 }
1188 } else if (event.type() == NetworkConfigEvent.Type.CONFIG_REMOVED) {
1189 NetworkConfigEvent netcfgEvent = (NetworkConfigEvent) event;
1190 Class configClass = netcfgEvent.configClass();
1191 if (configClass.equals(SegmentRoutingAppConfig.class)) {
1192 appCfgHandler.processAppConfigRemoved(netcfgEvent);
1193 log.info("App config event .. configuring network");
1194 cfgListener.configureNetwork();
1195 } else if (configClass.equals(SegmentRoutingDeviceConfig.class)) {
1196 // TODO Handle sr device config removal
1197 log.info("SegmentRoutingDeviceConfig removal is not handled in current implementation");
1198 } else if (configClass.equals(XConnectConfig.class)) {
1199 xConnectHandler.processXConnectConfigRemoved(netcfgEvent);
1200 } else if (configClass.equals(InterfaceConfig.class)) {
1201 // TODO Handle interface removal
1202 log.info("InterfaceConfig removal is not handled in current implementation");
1203 } else {
1204 log.error("Unhandled config class: {}", configClass);
1205 }
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -07001206 } else {
1207 log.warn("Unhandled event type: {}", event.type());
1208 }
Pier Luigi8f362362018-02-12 09:56:20 +01001209 } catch (Exception e) {
1210 log.error("SegmentRouting event handler thread thrown an exception: {}",
1211 e.getMessage(), e);
sangho80f11cb2015-04-01 13:05:26 -07001212 }
1213 }
sangho80f11cb2015-04-01 13:05:26 -07001214 }
1215 }
1216
Saurav Dase6c448a2018-01-18 12:07:33 -08001217 void processDeviceAdded(Device device) {
Saurav Dasb149be12016-06-07 10:08:06 -07001218 log.info("** DEVICE ADDED with ID {}", device.id());
Charles Chan9bd6aea2017-06-27 18:48:32 -07001219
1220 // NOTE: Punt ARP/NDP even when the device is not configured.
1221 // Host learning without network config is required for CORD config generator.
1222 routingRulePopulator.populateIpPunts(device.id());
1223 routingRulePopulator.populateArpNdpPunts(device.id());
1224
Charles Chan319d1a22015-11-03 10:42:14 -08001225 if (deviceConfiguration == null || !deviceConfiguration.isConfigured(device.id())) {
Saurav Das261c3002017-06-13 15:35:54 -07001226 log.warn("Device configuration unavailable. Device {} will be "
1227 + "processed after configuration.", device.id());
Saurav Das8ec0ec42015-11-03 14:39:27 -08001228 return;
1229 }
Charles Chan72779502016-04-23 17:36:10 -07001230 processDeviceAddedInternal(device.id());
1231 }
1232
1233 private void processDeviceAddedInternal(DeviceId deviceId) {
Saurav Dasc28b3432015-10-30 17:45:38 -07001234 // Irrespective of whether the local is a MASTER or not for this device,
1235 // we need to create a SR-group-handler instance. This is because in a
1236 // multi-instance setup, any instance can initiate forwarding/next-objectives
1237 // for any switch (even if this instance is a SLAVE or not even connected
1238 // to the switch). To handle this, a default-group-handler instance is necessary
1239 // per switch.
Charles Chan72779502016-04-23 17:36:10 -07001240 log.debug("Current groupHandlerMap devs: {}", groupHandlerMap.keySet());
1241 if (groupHandlerMap.get(deviceId) == null) {
Charles Chan319d1a22015-11-03 10:42:14 -08001242 DefaultGroupHandler groupHandler;
1243 try {
1244 groupHandler = DefaultGroupHandler.
Charles Chan72779502016-04-23 17:36:10 -07001245 createGroupHandler(deviceId,
1246 appId,
1247 deviceConfiguration,
1248 linkService,
1249 flowObjectiveService,
1250 this);
Charles Chan319d1a22015-11-03 10:42:14 -08001251 } catch (DeviceConfigNotFoundException e) {
1252 log.warn(e.getMessage() + " Aborting processDeviceAdded.");
1253 return;
1254 }
Saurav Das2b6a00f2017-12-05 15:00:23 -08001255 log.debug("updating groupHandlerMap with new grpHdlr for device: {}",
Charles Chan72779502016-04-23 17:36:10 -07001256 deviceId);
1257 groupHandlerMap.put(deviceId, groupHandler);
Saurav Das8ec0ec42015-11-03 14:39:27 -08001258 }
Saurav Dasb149be12016-06-07 10:08:06 -07001259
Charles Chan72779502016-04-23 17:36:10 -07001260 if (mastershipService.isLocalMaster(deviceId)) {
Saurav Dasf9332192017-02-18 14:05:44 -08001261 defaultRoutingHandler.populatePortAddressingRules(deviceId);
Charles Chandebfea32016-10-24 14:52:01 -07001262 hostHandler.init(deviceId);
Charles Chan82f19972016-05-17 13:13:55 -07001263 xConnectHandler.init(deviceId);
Charles Chan72779502016-04-23 17:36:10 -07001264 DefaultGroupHandler groupHandler = groupHandlerMap.get(deviceId);
Charles Chan10b0fb72017-02-02 16:20:42 -08001265 groupHandler.createGroupsFromVlanConfig();
Charles Chan72779502016-04-23 17:36:10 -07001266 routingRulePopulator.populateSubnetBroadcastRule(deviceId);
Charles Chan77277672015-10-20 16:24:19 -07001267 }
Charles Chan82ab1932016-01-30 23:22:37 -08001268
Charles Chandebfea32016-10-24 14:52:01 -07001269 appCfgHandler.init(deviceId);
1270 routeHandler.init(deviceId);
sangho80f11cb2015-04-01 13:05:26 -07001271 }
1272
Saurav Dasc3604f12016-03-23 11:22:49 -07001273 private void processDeviceRemoved(Device device) {
Saurav Das261c3002017-06-13 15:35:54 -07001274 dsNextObjStore.entrySet().stream()
Saurav Dasc3604f12016-03-23 11:22:49 -07001275 .filter(entry -> entry.getKey().deviceId().equals(device.id()))
Charles Chan873661e2017-11-30 15:37:50 -08001276 .forEach(entry -> dsNextObjStore.remove(entry.getKey()));
Charles Chan10b0fb72017-02-02 16:20:42 -08001277 vlanNextObjStore.entrySet().stream()
Saurav Dasc3604f12016-03-23 11:22:49 -07001278 .filter(entry -> entry.getKey().deviceId().equals(device.id()))
Charles Chan3ed34d82017-06-22 18:03:14 -07001279 .forEach(entry -> vlanNextObjStore.remove(entry.getKey()));
Saurav Dasc3604f12016-03-23 11:22:49 -07001280 portNextObjStore.entrySet().stream()
1281 .filter(entry -> entry.getKey().deviceId().equals(device.id()))
Charles Chan3ed34d82017-06-22 18:03:14 -07001282 .forEach(entry -> portNextObjStore.remove(entry.getKey()));
Saurav Dase6c448a2018-01-18 12:07:33 -08001283 linkHandler.processDeviceRemoved(device);
Charles Chan17d75d82017-06-15 00:44:51 -07001284
Saurav Dasfbe74572017-08-03 18:30:35 -07001285 DefaultGroupHandler gh = groupHandlerMap.remove(device.id());
1286 if (gh != null) {
1287 gh.shutdown();
1288 }
Saurav Das62ae6792017-05-15 15:34:25 -07001289 // Note that a switch going down is associated with all of its links
1290 // going down as well, but it is treated as a single switch down event
1291 // while the link-downs are ignored.
1292 defaultRoutingHandler
1293 .populateRoutingRulesForLinkStatusChange(null, null, device.id());
Saurav Das6430f412018-01-25 09:49:01 -08001294 defaultRoutingHandler.purgeEcmpGraph(device.id());
Charles Chan82f19972016-05-17 13:13:55 -07001295 xConnectHandler.removeDevice(device.id());
Saurav Das97241862018-02-14 14:14:54 -08001296
1297 // Cleanup all internal groupHandler stores for this device. Should be
1298 // done after all rerouting or rehashing has been completed
1299 groupHandlerMap.entrySet()
1300 .forEach(entry -> entry.getValue().cleanUpForNeighborDown(device.id()));
Saurav Dasc3604f12016-03-23 11:22:49 -07001301 }
1302
Saurav Dasf0f592d2016-11-18 15:21:57 -08001303 private void processPortUpdated(Device device, Port port) {
1304 if (deviceConfiguration == null || !deviceConfiguration.isConfigured(device.id())) {
1305 log.warn("Device configuration uploading. Not handling port event for"
1306 + "dev: {} port: {}", device.id(), port.number());
1307 return;
1308 }
Saurav Dasf9332192017-02-18 14:05:44 -08001309
1310 if (!mastershipService.isLocalMaster(device.id())) {
1311 log.debug("Not master for dev:{} .. not handling port updated event"
1312 + "for port {}", device.id(), port.number());
1313 return;
1314 }
1315
1316 // first we handle filtering rules associated with the port
1317 if (port.isEnabled()) {
1318 log.info("Switchport {}/{} enabled..programming filters",
1319 device.id(), port.number());
Charles Chan43be46b2017-02-26 22:59:35 -08001320 routingRulePopulator.processSinglePortFilters(device.id(), port.number(), true);
Saurav Dasf9332192017-02-18 14:05:44 -08001321 } else {
1322 log.info("Switchport {}/{} disabled..removing filters",
1323 device.id(), port.number());
Charles Chan43be46b2017-02-26 22:59:35 -08001324 routingRulePopulator.processSinglePortFilters(device.id(), port.number(), false);
Saurav Dasf9332192017-02-18 14:05:44 -08001325 }
Saurav Dasf0f592d2016-11-18 15:21:57 -08001326
1327 // portUpdated calls are for ports that have gone down or up. For switch
1328 // to switch ports, link-events should take care of any re-routing or
1329 // group editing necessary for port up/down. Here we only process edge ports
1330 // that are already configured.
Saurav Das3fb28272017-03-04 16:08:47 -08001331 ConnectPoint cp = new ConnectPoint(device.id(), port.number());
1332 VlanId untaggedVlan = getUntaggedVlanId(cp);
1333 VlanId nativeVlan = getNativeVlanId(cp);
1334 Set<VlanId> taggedVlans = getTaggedVlanId(cp);
Charles Chan10b0fb72017-02-02 16:20:42 -08001335
Saurav Das3fb28272017-03-04 16:08:47 -08001336 if (untaggedVlan == null && nativeVlan == null && taggedVlans.isEmpty()) {
Saurav Das62ae6792017-05-15 15:34:25 -07001337 log.debug("Not handling port updated event for non-edge port (unconfigured) "
Saurav Dasf0f592d2016-11-18 15:21:57 -08001338 + "dev/port: {}/{}", device.id(), port.number());
1339 return;
1340 }
Saurav Das3fb28272017-03-04 16:08:47 -08001341 if (untaggedVlan != null) {
1342 processEdgePort(device, port, untaggedVlan, true);
1343 }
1344 if (nativeVlan != null) {
1345 processEdgePort(device, port, nativeVlan, true);
1346 }
1347 if (!taggedVlans.isEmpty()) {
1348 taggedVlans.forEach(tag -> processEdgePort(device, port, tag, false));
1349 }
Saurav Dasf0f592d2016-11-18 15:21:57 -08001350 }
1351
Saurav Das3fb28272017-03-04 16:08:47 -08001352 private void processEdgePort(Device device, Port port, VlanId vlanId,
1353 boolean popVlan) {
Saurav Dasf0f592d2016-11-18 15:21:57 -08001354 boolean portUp = port.isEnabled();
1355 if (portUp) {
Saurav Das3fb28272017-03-04 16:08:47 -08001356 log.info("Device:EdgePort {}:{} is enabled in vlan: {}", device.id(),
Charles Chan10b0fb72017-02-02 16:20:42 -08001357 port.number(), vlanId);
Charles Chan873661e2017-11-30 15:37:50 -08001358 hostHandler.processPortUp(new ConnectPoint(device.id(), port.number()));
Saurav Dasf0f592d2016-11-18 15:21:57 -08001359 } else {
Saurav Das3fb28272017-03-04 16:08:47 -08001360 log.info("Device:EdgePort {}:{} is disabled in vlan: {}", device.id(),
Charles Chan10b0fb72017-02-02 16:20:42 -08001361 port.number(), vlanId);
Saurav Dasf0f592d2016-11-18 15:21:57 -08001362 }
1363
Srikanth Vavilapalli64505482015-04-21 13:04:13 -07001364 DefaultGroupHandler groupHandler = groupHandlerMap.get(device.id());
sangho80f11cb2015-04-01 13:05:26 -07001365 if (groupHandler != null) {
Saurav Das3fb28272017-03-04 16:08:47 -08001366 groupHandler.processEdgePort(port.number(), vlanId, popVlan, portUp);
Saurav Dasf0f592d2016-11-18 15:21:57 -08001367 } else {
1368 log.warn("Group handler not found for dev:{}. Not handling edge port"
1369 + " {} event for port:{}", device.id(),
1370 (portUp) ? "UP" : "DOWN", port.number());
sangho80f11cb2015-04-01 13:05:26 -07001371 }
1372 }
sangho27462c62015-05-14 00:39:53 -07001373
Charles Chan8ca5a122017-10-20 16:06:55 -07001374 private void createOrUpdateDeviceConfiguration() {
1375 if (deviceConfiguration == null) {
Saurav Dase321cff2018-02-09 17:26:45 -08001376 log.info("Creating new DeviceConfiguration");
Charles Chan8ca5a122017-10-20 16:06:55 -07001377 deviceConfiguration = new DeviceConfiguration(this);
1378 } else {
Saurav Dase321cff2018-02-09 17:26:45 -08001379 log.info("Updating DeviceConfiguration");
Charles Chan8ca5a122017-10-20 16:06:55 -07001380 deviceConfiguration.updateConfig();
1381 }
1382 }
1383
Pier Ventreb6a7f342016-11-26 21:05:22 -08001384 /**
1385 * Registers the given connect point with the NRS, this is necessary
1386 * to receive the NDP and ARP packets from the NRS.
1387 *
1388 * @param portToRegister connect point to register
1389 */
1390 public void registerConnectPoint(ConnectPoint portToRegister) {
Charles Chan2e71ef32017-02-23 15:44:08 -08001391 neighbourResolutionService.registerNeighbourHandler(
Pier Ventreb6a7f342016-11-26 21:05:22 -08001392 portToRegister,
1393 neighbourHandler,
1394 appId
1395 );
1396 }
1397
Charles Chan72f556a2015-10-05 17:50:33 -07001398 private class InternalConfigListener implements NetworkConfigListener {
Saurav Das261c3002017-06-13 15:35:54 -07001399 private static final long PROGRAM_DELAY = 2;
Charles Chan46fdfaf2016-11-09 20:51:44 -08001400 SegmentRoutingManager srManager;
Charles Chane7c61022015-10-07 14:21:45 -07001401
Charles Chanb7f75ac2016-01-11 18:28:54 -08001402 /**
1403 * Constructs the internal network config listener.
1404 *
Charles Chan46fdfaf2016-11-09 20:51:44 -08001405 * @param srManager segment routing manager
Charles Chanb7f75ac2016-01-11 18:28:54 -08001406 */
Charles Chan3ed34d82017-06-22 18:03:14 -07001407 InternalConfigListener(SegmentRoutingManager srManager) {
Charles Chan46fdfaf2016-11-09 20:51:44 -08001408 this.srManager = srManager;
Charles Chane7c61022015-10-07 14:21:45 -07001409 }
1410
Charles Chanb7f75ac2016-01-11 18:28:54 -08001411 /**
1412 * Reads network config and initializes related data structure accordingly.
1413 */
Charles Chan873661e2017-11-30 15:37:50 -08001414 void configureNetwork() {
Saurav Dase321cff2018-02-09 17:26:45 -08001415 log.info("Configuring network ...");
Charles Chan8ca5a122017-10-20 16:06:55 -07001416 createOrUpdateDeviceConfiguration();
Charles Chane7c61022015-10-07 14:21:45 -07001417
Charles Chan46fdfaf2016-11-09 20:51:44 -08001418 arpHandler = new ArpHandler(srManager);
1419 icmpHandler = new IcmpHandler(srManager);
1420 ipHandler = new IpHandler(srManager);
1421 routingRulePopulator = new RoutingRulePopulator(srManager);
1422 defaultRoutingHandler = new DefaultRoutingHandler(srManager);
Charles Chane7c61022015-10-07 14:21:45 -07001423
1424 tunnelHandler = new TunnelHandler(linkService, deviceConfiguration,
1425 groupHandlerMap, tunnelStore);
1426 policyHandler = new PolicyHandler(appId, deviceConfiguration,
1427 flowObjectiveService,
1428 tunnelHandler, policyStore);
Saurav Das261c3002017-06-13 15:35:54 -07001429 // add a small delay to absorb multiple network config added notifications
1430 if (!programmingScheduled.get()) {
Saurav Dase321cff2018-02-09 17:26:45 -08001431 log.info("Buffering config calls for {} secs", PROGRAM_DELAY);
Saurav Das261c3002017-06-13 15:35:54 -07001432 programmingScheduled.set(true);
1433 executorService.schedule(new ConfigChange(), PROGRAM_DELAY,
1434 TimeUnit.SECONDS);
Charles Chane7c61022015-10-07 14:21:45 -07001435 }
Charles Chan72779502016-04-23 17:36:10 -07001436 mcastHandler.init();
Charles Chane7c61022015-10-07 14:21:45 -07001437 }
1438
Charles Chan72f556a2015-10-05 17:50:33 -07001439 @Override
1440 public void event(NetworkConfigEvent event) {
Charles Chan3f4aca62018-03-21 16:57:47 -07001441 checkState(appCfgHandler != null, "NetworkConfigEventHandler is not initialized");
1442 checkState(xConnectHandler != null, "XConnectHandler is not initialized");
1443 switch (event.type()) {
1444 case CONFIG_ADDED:
1445 case CONFIG_UPDATED:
1446 case CONFIG_REMOVED:
1447 log.trace("Schedule Network Config event {}", event);
1448 scheduleEventHandlerIfNotScheduled(event);
1449 break;
1450 default:
1451 break;
Charles Chan72f556a2015-10-05 17:50:33 -07001452 }
1453 }
Saurav Das261c3002017-06-13 15:35:54 -07001454
Charles Chanc4a68c32018-01-03 16:26:32 -08001455 @Override
1456 public boolean isRelevant(NetworkConfigEvent event) {
Saurav Dase321cff2018-02-09 17:26:45 -08001457 if (event.type() == CONFIG_REGISTERED ||
1458 event.type() == CONFIG_UNREGISTERED) {
1459 log.debug("Ignore event {} due to type mismatch", event);
1460 return false;
Charles Chanc4a68c32018-01-03 16:26:32 -08001461 }
Saurav Dase321cff2018-02-09 17:26:45 -08001462
1463 if (!event.configClass().equals(SegmentRoutingDeviceConfig.class) &&
1464 !event.configClass().equals(SegmentRoutingAppConfig.class) &&
1465 !event.configClass().equals(InterfaceConfig.class) &&
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -08001466 !event.configClass().equals(XConnectConfig.class)) {
Saurav Dase321cff2018-02-09 17:26:45 -08001467 log.debug("Ignore event {} due to class mismatch", event);
1468 return false;
1469 }
1470
1471 return true;
Charles Chanc4a68c32018-01-03 16:26:32 -08001472 }
1473
Saurav Das261c3002017-06-13 15:35:54 -07001474 private final class ConfigChange implements Runnable {
1475 @Override
1476 public void run() {
1477 programmingScheduled.set(false);
Saurav Dase321cff2018-02-09 17:26:45 -08001478 log.info("Reacting to config changes after buffer delay");
Saurav Das261c3002017-06-13 15:35:54 -07001479 for (Device device : deviceService.getDevices()) {
1480 processDeviceAdded(device);
1481 }
1482 defaultRoutingHandler.startPopulationProcess();
1483 }
1484 }
Charles Chan72f556a2015-10-05 17:50:33 -07001485 }
Charles Chanf4586112015-11-09 16:37:23 -08001486
Charles Chan3f4aca62018-03-21 16:57:47 -07001487 private class InternalLinkListener implements LinkListener {
1488 @Override
1489 public void event(LinkEvent event) {
1490 if (event.type() == LinkEvent.Type.LINK_ADDED ||
1491 event.type() == LinkEvent.Type.LINK_UPDATED ||
1492 event.type() == LinkEvent.Type.LINK_REMOVED) {
1493 log.trace("Schedule Link event {}", event);
1494 scheduleEventHandlerIfNotScheduled(event);
1495 }
1496 }
1497 }
1498
1499 private class InternalDeviceListener implements DeviceListener {
1500 @Override
1501 public void event(DeviceEvent event) {
1502 switch (event.type()) {
1503 case DEVICE_ADDED:
1504 case PORT_UPDATED:
1505 case PORT_ADDED:
1506 case DEVICE_UPDATED:
1507 case DEVICE_AVAILABILITY_CHANGED:
1508 log.trace("Schedule Device event {}", event);
1509 scheduleEventHandlerIfNotScheduled(event);
1510 break;
1511 default:
1512 }
1513 }
1514 }
1515
1516 private class InternalTopologyListener implements TopologyListener {
1517 @Override
1518 public void event(TopologyEvent event) {
1519 switch (event.type()) {
1520 case TOPOLOGY_CHANGED:
1521 log.trace("Schedule Topology event {}", event);
1522 scheduleEventHandlerIfNotScheduled(event);
1523 break;
1524 default:
1525 }
1526 }
1527 }
1528
Charles Chanf4586112015-11-09 16:37:23 -08001529 private class InternalHostListener implements HostListener {
Charles Chanf4586112015-11-09 16:37:23 -08001530 @Override
1531 public void event(HostEvent event) {
Charles Chanf4586112015-11-09 16:37:23 -08001532 switch (event.type()) {
1533 case HOST_ADDED:
Charles Chanf4586112015-11-09 16:37:23 -08001534 case HOST_MOVED:
Charles Chanf4586112015-11-09 16:37:23 -08001535 case HOST_REMOVED:
Charles Chanf4586112015-11-09 16:37:23 -08001536 case HOST_UPDATED:
Charles Chan3f4aca62018-03-21 16:57:47 -07001537 log.trace("Schedule Host event {}", event);
1538 scheduleEventHandlerIfNotScheduled(event);
Charles Chanf4586112015-11-09 16:37:23 -08001539 break;
1540 default:
1541 log.warn("Unsupported host event type: {}", event.type());
1542 break;
1543 }
1544 }
1545 }
1546
Charles Chanc91c8782016-03-30 17:54:24 -07001547 private class InternalMcastListener implements McastListener {
1548 @Override
1549 public void event(McastEvent event) {
1550 switch (event.type()) {
1551 case SOURCE_ADDED:
Pier Luigie80d6b42018-02-26 12:31:38 +01001552 case SOURCE_UPDATED:
Charles Chanc91c8782016-03-30 17:54:24 -07001553 case SINK_ADDED:
Charles Chanc91c8782016-03-30 17:54:24 -07001554 case SINK_REMOVED:
Charles Chanc91c8782016-03-30 17:54:24 -07001555 case ROUTE_REMOVED:
Charles Chan3f4aca62018-03-21 16:57:47 -07001556 log.trace("Schedule Mcast event {}", event);
1557 scheduleEventHandlerIfNotScheduled(event);
Pier Luigi6786b922018-02-02 16:19:11 +01001558 break;
1559 case ROUTE_ADDED:
Charles Chanc91c8782016-03-30 17:54:24 -07001560 default:
Charles Chan3f4aca62018-03-21 16:57:47 -07001561 log.warn("Unsupported mcast event type: {}", event.type());
Charles Chanc91c8782016-03-30 17:54:24 -07001562 break;
1563 }
1564 }
1565 }
Charles Chan41f5ec02016-06-13 18:54:31 -07001566
Charles Chandebfea32016-10-24 14:52:01 -07001567 private class InternalRouteEventListener implements RouteListener {
1568 @Override
1569 public void event(RouteEvent event) {
1570 switch (event.type()) {
1571 case ROUTE_ADDED:
Charles Chandebfea32016-10-24 14:52:01 -07001572 case ROUTE_UPDATED:
Charles Chandebfea32016-10-24 14:52:01 -07001573 case ROUTE_REMOVED:
Charles Chan910be6a2017-08-23 14:46:43 -07001574 case ALTERNATIVE_ROUTES_CHANGED:
Charles Chan3f4aca62018-03-21 16:57:47 -07001575 log.trace("Schedule Route event {}", event);
1576 scheduleEventHandlerIfNotScheduled(event);
Charles Chan910be6a2017-08-23 14:46:43 -07001577 break;
Charles Chandebfea32016-10-24 14:52:01 -07001578 default:
Charles Chan3f4aca62018-03-21 16:57:47 -07001579 log.warn("Unsupported route event type: {}", event.type());
Charles Chandebfea32016-10-24 14:52:01 -07001580 break;
1581 }
1582 }
1583 }
Saurav Das62ae6792017-05-15 15:34:25 -07001584
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07001585 private void updateInterface(InterfaceConfig conf, InterfaceConfig prevConf) {
1586 try {
1587 Set<Interface> intfs = conf.getInterfaces();
1588 Set<Interface> prevIntfs = prevConf.getInterfaces();
1589
1590 // Now we only handle one interface config at each port.
1591 if (intfs.size() != 1 || prevIntfs.size() != 1) {
1592 log.warn("Interface update aborted - one at a time is allowed, " +
1593 "but {} / {}(prev) received.", intfs.size(), prevIntfs.size());
1594 return;
1595 }
1596
1597 Interface intf = intfs.stream().findFirst().get();
1598 Interface prevIntf = prevIntfs.stream().findFirst().get();
1599
1600 DeviceId deviceId = intf.connectPoint().deviceId();
1601 PortNumber portNum = intf.connectPoint().port();
1602
1603 if (!mastershipService.isLocalMaster(deviceId)) {
1604 log.debug("CONFIG_UPDATED event for interfaces should be " +
1605 "handled by master node for device {}", deviceId);
1606 return;
1607 }
1608
1609 removeSubnetConfig(prevIntf.connectPoint(),
1610 Sets.difference(new HashSet<>(prevIntf.ipAddressesList()),
1611 new HashSet<>(intf.ipAddressesList())));
1612
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09001613 if (!prevIntf.vlanNative().equals(VlanId.NONE)
1614 && !prevIntf.vlanNative().equals(intf.vlanUntagged())
1615 && !prevIntf.vlanNative().equals(intf.vlanNative())) {
1616 if (intf.vlanTagged().contains(prevIntf.vlanNative())) {
1617 // Update filtering objective and L2IG group bucket
1618 updatePortVlanTreatment(deviceId, portNum, prevIntf.vlanNative(), false);
1619 } else {
1620 // RemoveVlanNative
1621 updateVlanConfigInternal(deviceId, portNum, prevIntf.vlanNative(), true, false);
1622 }
1623 }
1624
1625 if (!prevIntf.vlanUntagged().equals(VlanId.NONE)
1626 && !prevIntf.vlanUntagged().equals(intf.vlanUntagged())
1627 && !prevIntf.vlanUntagged().equals(intf.vlanNative())) {
1628 if (intf.vlanTagged().contains(prevIntf.vlanUntagged())) {
1629 // Update filtering objective and L2IG group bucket
1630 updatePortVlanTreatment(deviceId, portNum, prevIntf.vlanUntagged(), false);
1631 } else {
1632 // RemoveVlanUntagged
1633 updateVlanConfigInternal(deviceId, portNum, prevIntf.vlanUntagged(), true, false);
1634 }
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07001635 }
1636
1637 if (!prevIntf.vlanTagged().isEmpty() && !intf.vlanTagged().equals(prevIntf.vlanTagged())) {
1638 // RemoveVlanTagged
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09001639 Sets.difference(prevIntf.vlanTagged(), intf.vlanTagged()).stream()
1640 .filter(i -> !intf.vlanUntagged().equals(i))
1641 .filter(i -> !intf.vlanNative().equals(i))
1642 .forEach(vlanId -> updateVlanConfigInternal(
1643 deviceId, portNum, vlanId, false, false));
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07001644 }
1645
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09001646 if (!intf.vlanNative().equals(VlanId.NONE)
1647 && !prevIntf.vlanNative().equals(intf.vlanNative())
1648 && !prevIntf.vlanUntagged().equals(intf.vlanNative())) {
1649 if (prevIntf.vlanTagged().contains(intf.vlanNative())) {
1650 // Update filtering objective and L2IG group bucket
1651 updatePortVlanTreatment(deviceId, portNum, intf.vlanNative(), true);
1652 } else {
1653 // AddVlanNative
1654 updateVlanConfigInternal(deviceId, portNum, intf.vlanNative(), true, true);
1655 }
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07001656 }
1657
1658 if (!intf.vlanTagged().isEmpty() && !intf.vlanTagged().equals(prevIntf.vlanTagged())) {
1659 // AddVlanTagged
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09001660 Sets.difference(intf.vlanTagged(), prevIntf.vlanTagged()).stream()
1661 .filter(i -> !prevIntf.vlanUntagged().equals(i))
1662 .filter(i -> !prevIntf.vlanNative().equals(i))
1663 .forEach(vlanId -> updateVlanConfigInternal(
1664 deviceId, portNum, vlanId, false, true)
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07001665 );
1666 }
1667
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09001668 if (!intf.vlanUntagged().equals(VlanId.NONE)
1669 && !prevIntf.vlanUntagged().equals(intf.vlanUntagged())
1670 && !prevIntf.vlanNative().equals(intf.vlanUntagged())) {
1671 if (prevIntf.vlanTagged().contains(intf.vlanUntagged())) {
1672 // Update filtering objective and L2IG group bucket
1673 updatePortVlanTreatment(deviceId, portNum, intf.vlanUntagged(), true);
1674 } else {
1675 // AddVlanUntagged
1676 updateVlanConfigInternal(deviceId, portNum, intf.vlanUntagged(), true, true);
1677 }
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07001678 }
1679 addSubnetConfig(prevIntf.connectPoint(),
1680 Sets.difference(new HashSet<>(intf.ipAddressesList()),
1681 new HashSet<>(prevIntf.ipAddressesList())));
1682 } catch (ConfigException e) {
1683 log.error("Error in configuration");
1684 }
1685 }
1686
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09001687 private void updatePortVlanTreatment(DeviceId deviceId, PortNumber portNum,
1688 VlanId vlanId, boolean pushVlan) {
1689 DefaultGroupHandler grpHandler = getGroupHandler(deviceId);
1690 if (grpHandler == null) {
1691 log.warn("Failed to retrieve group handler for device {}", deviceId);
1692 return;
1693 }
1694
1695 // Update filtering objective for a single port
1696 routingRulePopulator.updateSinglePortFilters(deviceId, portNum, !pushVlan, vlanId, false);
1697 routingRulePopulator.updateSinglePortFilters(deviceId, portNum, pushVlan, vlanId, true);
1698
1699 if (getVlanNextObjectiveId(deviceId, vlanId) != -1) {
1700 // Update L2IG bucket of the port
1701 grpHandler.updateL2InterfaceGroupBucket(portNum, vlanId, pushVlan);
1702 } else {
1703 log.warn("Failed to retrieve next objective for vlan {} in device {}:{}", vlanId, deviceId, portNum);
1704 }
1705 }
1706
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07001707 private void updateVlanConfigInternal(DeviceId deviceId, PortNumber portNum,
1708 VlanId vlanId, boolean pushVlan, boolean install) {
1709 DefaultGroupHandler grpHandler = getGroupHandler(deviceId);
1710 if (grpHandler == null) {
1711 log.warn("Failed to retrieve group handler for device {}", deviceId);
1712 return;
1713 }
1714
1715 // Update filtering objective for a single port
1716 routingRulePopulator.updateSinglePortFilters(deviceId, portNum, pushVlan, vlanId, install);
1717
1718 // Update filtering objective for multicast ingress port
1719 mcastHandler.updateFilterToDevice(deviceId, portNum, vlanId, install);
1720
1721 int nextId = getVlanNextObjectiveId(deviceId, vlanId);
1722
1723 if (nextId != -1 && !install) {
1724 // Update next objective for a single port as an output port
1725 // Remove a single port from L2FG
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09001726 grpHandler.updateGroupFromVlanConfiguration(vlanId, portNum, nextId, install);
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07001727 // Remove L2 Bridging rule and L3 Unicast rule to the host
1728 hostHandler.processIntfVlanUpdatedEvent(deviceId, portNum, vlanId, pushVlan, install);
1729 // Remove broadcast forwarding rule and corresponding L2FG for VLAN
1730 // only if there is no port configured on that VLAN ID
1731 if (!getVlanPortMap(deviceId).containsKey(vlanId)) {
1732 // Remove broadcast forwarding rule for the VLAN
1733 routingRulePopulator.updateSubnetBroadcastRule(deviceId, vlanId, install);
1734 // Remove L2FG for VLAN
1735 grpHandler.removeBcastGroupFromVlan(deviceId, portNum, vlanId, pushVlan);
1736 } else {
1737 // Remove L2IG of the port
1738 grpHandler.removePortNextObjective(deviceId, portNum, vlanId, pushVlan);
1739 }
1740 } else if (install) {
1741 if (nextId != -1) {
1742 // Add a single port to L2FG
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09001743 grpHandler.updateGroupFromVlanConfiguration(vlanId, portNum, nextId, install);
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07001744 } else {
1745 // Create L2FG for VLAN
1746 grpHandler.createBcastGroupFromVlan(vlanId, Collections.singleton(portNum));
1747 routingRulePopulator.updateSubnetBroadcastRule(deviceId, vlanId, install);
1748 }
1749 hostHandler.processIntfVlanUpdatedEvent(deviceId, portNum, vlanId, pushVlan, install);
1750 } else {
1751 log.warn("Failed to retrieve next objective for vlan {} in device {}:{}", vlanId, deviceId, portNum);
1752 }
1753 }
1754
1755 private void removeSubnetConfig(ConnectPoint cp, Set<InterfaceIpAddress> ipAddressSet) {
1756 Set<IpPrefix> ipPrefixSet = ipAddressSet.stream().
1757 map(InterfaceIpAddress::subnetAddress).collect(Collectors.toSet());
1758
1759 Set<InterfaceIpAddress> deviceIntfIpAddrs = interfaceService.getInterfaces().stream()
1760 .filter(intf -> intf.connectPoint().deviceId().equals(cp.deviceId()))
1761 .filter(intf -> !intf.connectPoint().equals(cp))
1762 .flatMap(intf -> intf.ipAddressesList().stream())
1763 .collect(Collectors.toSet());
1764 // 1. Partial subnet population
1765 // Remove routing rules for removed subnet from previous configuration,
1766 // which does not also exist in other interfaces in the same device
1767 Set<IpPrefix> deviceIpPrefixSet = deviceIntfIpAddrs.stream()
1768 .map(InterfaceIpAddress::subnetAddress)
1769 .collect(Collectors.toSet());
1770
1771 defaultRoutingHandler.revokeSubnet(
1772 ipPrefixSet.stream()
1773 .filter(ipPrefix -> !deviceIpPrefixSet.contains(ipPrefix))
1774 .collect(Collectors.toSet()));
1775
1776 // 2. Interface IP punts
1777 // Remove IP punts for old Intf address
1778 Set<IpAddress> deviceIpAddrs = deviceIntfIpAddrs.stream()
1779 .map(InterfaceIpAddress::ipAddress)
1780 .collect(Collectors.toSet());
1781 ipAddressSet.stream()
1782 .map(InterfaceIpAddress::ipAddress)
1783 .filter(interfaceIpAddress -> !deviceIpAddrs.contains(interfaceIpAddress))
1784 .forEach(interfaceIpAddress ->
1785 routingRulePopulator.revokeSingleIpPunts(
1786 cp.deviceId(), interfaceIpAddress));
1787
1788 // 3. Host unicast routing rule
1789 // Remove unicast routing rule
1790 hostHandler.processIntfIpUpdatedEvent(cp, ipPrefixSet, false);
1791 }
1792
1793 private void addSubnetConfig(ConnectPoint cp, Set<InterfaceIpAddress> ipAddressSet) {
1794 Set<IpPrefix> ipPrefixSet = ipAddressSet.stream().
1795 map(InterfaceIpAddress::subnetAddress).collect(Collectors.toSet());
1796
1797 Set<InterfaceIpAddress> deviceIntfIpAddrs = interfaceService.getInterfaces().stream()
1798 .filter(intf -> intf.connectPoint().deviceId().equals(cp.deviceId()))
1799 .filter(intf -> !intf.connectPoint().equals(cp))
1800 .flatMap(intf -> intf.ipAddressesList().stream())
1801 .collect(Collectors.toSet());
1802 // 1. Partial subnet population
1803 // Add routing rules for newly added subnet, which does not also exist in
1804 // other interfaces in the same device
1805 Set<IpPrefix> deviceIpPrefixSet = deviceIntfIpAddrs.stream()
1806 .map(InterfaceIpAddress::subnetAddress)
1807 .collect(Collectors.toSet());
1808
1809 defaultRoutingHandler.populateSubnet(
1810 Collections.singleton(cp),
1811 ipPrefixSet.stream()
1812 .filter(ipPrefix -> !deviceIpPrefixSet.contains(ipPrefix))
1813 .collect(Collectors.toSet()));
1814
1815 // 2. Interface IP punts
1816 // Add IP punts for new Intf address
1817 Set<IpAddress> deviceIpAddrs = deviceIntfIpAddrs.stream()
1818 .map(InterfaceIpAddress::ipAddress)
1819 .collect(Collectors.toSet());
1820 ipAddressSet.stream()
1821 .map(InterfaceIpAddress::ipAddress)
1822 .filter(interfaceIpAddress -> !deviceIpAddrs.contains(interfaceIpAddress))
1823 .forEach(interfaceIpAddress ->
1824 routingRulePopulator.populateSingleIpPunts(
1825 cp.deviceId(), interfaceIpAddress));
1826
1827 // 3. Host unicast routing rule
1828 // Add unicast routing rule
1829 hostHandler.processIntfIpUpdatedEvent(cp, ipPrefixSet, true);
1830 }
sangho80f11cb2015-04-01 13:05:26 -07001831}