blob: 071fe3e1972c2688198142d5ea6155571b04251a [file] [log] [blame]
sanghob35a6192015-04-01 13:05:26 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
sanghob35a6192015-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
Charles Chan7ffd81f2017-02-08 15:52:08 -080018import com.google.common.collect.HashMultimap;
Saurav Dasc88d4662017-05-15 15:34:25 -070019import com.google.common.collect.ImmutableMap;
Charles Chanc81c45b2016-10-20 17:02:44 -070020import com.google.common.collect.Maps;
Charles Chan7ffd81f2017-02-08 15:52:08 -080021import com.google.common.collect.Multimap;
sanghob35a6192015-04-01 13:05:26 -070022import org.apache.felix.scr.annotations.Activate;
23import org.apache.felix.scr.annotations.Component;
24import org.apache.felix.scr.annotations.Deactivate;
25import org.apache.felix.scr.annotations.Reference;
26import org.apache.felix.scr.annotations.ReferenceCardinality;
sangho1e575652015-05-14 00:39:53 -070027import org.apache.felix.scr.annotations.Service;
sanghob35a6192015-04-01 13:05:26 -070028import org.onlab.packet.Ethernet;
Pier Ventre735b8c82016-12-02 08:16:05 -080029import org.onlab.packet.ICMP6;
Charles Chanc42e84e2015-10-20 16:24:19 -070030import org.onlab.packet.IPv4;
Pier Ventre10bd8d12016-11-26 21:05:22 -080031import org.onlab.packet.IPv6;
Charles Chanc42e84e2015-10-20 16:24:19 -070032import org.onlab.packet.IpPrefix;
Jonathan Hartc19f7c12016-04-12 15:39:44 -070033import org.onlab.packet.VlanId;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -070034import org.onlab.util.KryoNamespace;
Saurav Das80980c72016-03-23 11:22:49 -070035import org.onosproject.cfg.ComponentConfigService;
sanghob35a6192015-04-01 13:05:26 -070036import org.onosproject.core.ApplicationId;
37import org.onosproject.core.CoreService;
38import org.onosproject.event.Event;
Charles Chan278ce832017-06-26 15:25:09 -070039import org.onosproject.incubator.net.config.basics.InterfaceConfig;
Charles Chand55e84d2016-03-30 17:54:24 -070040import org.onosproject.incubator.net.config.basics.McastConfig;
Ray Milkeyfacf2862017-08-03 11:58:29 -070041import org.onosproject.net.intf.Interface;
42import org.onosproject.net.intf.InterfaceService;
Ray Milkey69ec8712017-08-08 13:00:43 -070043import org.onosproject.routeservice.RouteEvent;
44import org.onosproject.routeservice.RouteListener;
45import org.onosproject.routeservice.RouteService;
Ray Milkeyb65d7842017-08-03 16:28:24 -070046import org.onosproject.net.neighbour.NeighbourResolutionService;
Jonathan Hartc19f7c12016-04-12 15:39:44 -070047import org.onosproject.mastership.MastershipService;
Pier Ventre10bd8d12016-11-26 21:05:22 -080048import org.onosproject.net.ConnectPoint;
Jonathan Hartc19f7c12016-04-12 15:39:44 -070049import org.onosproject.net.Device;
50import org.onosproject.net.DeviceId;
51import org.onosproject.net.Link;
52import org.onosproject.net.Port;
Charles Chan68aa62d2015-11-09 16:37:23 -080053import org.onosproject.net.PortNumber;
Charles Chand6832882015-10-05 17:50:33 -070054import org.onosproject.net.config.ConfigFactory;
55import org.onosproject.net.config.NetworkConfigEvent;
Charles Chand6832882015-10-05 17:50:33 -070056import org.onosproject.net.config.NetworkConfigListener;
Jonathan Hartc19f7c12016-04-12 15:39:44 -070057import org.onosproject.net.config.NetworkConfigRegistry;
Charles Chand6832882015-10-05 17:50:33 -070058import org.onosproject.net.config.basics.SubjectFactories;
Jonathan Hartc19f7c12016-04-12 15:39:44 -070059import org.onosproject.net.device.DeviceEvent;
60import org.onosproject.net.device.DeviceListener;
61import org.onosproject.net.device.DeviceService;
Charles Chan68aa62d2015-11-09 16:37:23 -080062import org.onosproject.net.flow.TrafficSelector;
63import org.onosproject.net.flow.TrafficTreatment;
Jonathan Hartc19f7c12016-04-12 15:39:44 -070064import org.onosproject.net.flowobjective.FlowObjectiveService;
Charles Chan68aa62d2015-11-09 16:37:23 -080065import org.onosproject.net.host.HostEvent;
66import org.onosproject.net.host.HostListener;
Pier Ventre10bd8d12016-11-26 21:05:22 -080067import org.onosproject.net.host.HostService;
68import org.onosproject.net.link.LinkEvent;
69import org.onosproject.net.link.LinkListener;
70import org.onosproject.net.link.LinkService;
Charles Chand55e84d2016-03-30 17:54:24 -070071import org.onosproject.net.mcast.McastEvent;
72import org.onosproject.net.mcast.McastListener;
73import org.onosproject.net.mcast.MulticastRouteService;
Pier Ventre10bd8d12016-11-26 21:05:22 -080074import org.onosproject.net.packet.InboundPacket;
75import org.onosproject.net.packet.PacketContext;
76import org.onosproject.net.packet.PacketProcessor;
77import org.onosproject.net.packet.PacketService;
Pier Ventre42287df2016-11-09 14:17:26 -080078import org.onosproject.net.topology.PathService;
Charles Chand55e84d2016-03-30 17:54:24 -070079import org.onosproject.net.topology.TopologyService;
80import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException;
81import org.onosproject.segmentrouting.config.DeviceConfiguration;
Pier Ventref34966c2016-11-07 16:21:04 -080082import org.onosproject.segmentrouting.config.PwaasConfig;
Pier Ventre10bd8d12016-11-26 21:05:22 -080083import org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig;
Pier Ventref34966c2016-11-07 16:21:04 -080084import org.onosproject.segmentrouting.config.SegmentRoutingAppConfig;
Charles Chanfc5c7802016-05-17 13:13:55 -070085import org.onosproject.segmentrouting.config.XConnectConfig;
Charles Chand55e84d2016-03-30 17:54:24 -070086import org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler;
Saurav Das7bcbe702017-06-13 15:35:54 -070087import org.onosproject.segmentrouting.grouphandler.DestinationSet;
88import org.onosproject.segmentrouting.grouphandler.NextNeighbors;
89import org.onosproject.segmentrouting.storekey.DestinationSetNextObjectiveStoreKey;
Charles Chand2990362016-04-18 13:44:03 -070090import org.onosproject.segmentrouting.storekey.PortNextObjectiveStoreKey;
Charles Chan59cc16d2017-02-02 16:20:42 -080091import org.onosproject.segmentrouting.storekey.VlanNextObjectiveStoreKey;
Charles Chanfc5c7802016-05-17 13:13:55 -070092import org.onosproject.segmentrouting.storekey.XConnectStoreKey;
Pier Ventref34966c2016-11-07 16:21:04 -080093import org.onosproject.segmentrouting.pwaas.L2TunnelHandler;
Jonathan Hartc19f7c12016-04-12 15:39:44 -070094import org.onosproject.store.serializers.KryoNamespaces;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -070095import org.onosproject.store.service.EventuallyConsistentMap;
96import org.onosproject.store.service.EventuallyConsistentMapBuilder;
97import org.onosproject.store.service.StorageService;
98import org.onosproject.store.service.WallClockTimestamp;
sanghob35a6192015-04-01 13:05:26 -070099import org.slf4j.Logger;
100import org.slf4j.LoggerFactory;
101
sangho1e575652015-05-14 00:39:53 -0700102import java.util.List;
sanghob35a6192015-04-01 13:05:26 -0700103import java.util.Map;
Saurav Dasc88d4662017-05-15 15:34:25 -0700104import java.util.Map.Entry;
Charles Chan65238242017-06-22 18:03:14 -0700105import java.util.Optional;
Saurav Das0e99e2b2015-10-28 12:39:42 -0700106import java.util.Set;
sanghob35a6192015-04-01 13:05:26 -0700107import java.util.concurrent.ConcurrentHashMap;
108import java.util.concurrent.ConcurrentLinkedQueue;
109import java.util.concurrent.Executors;
110import java.util.concurrent.ScheduledExecutorService;
111import java.util.concurrent.ScheduledFuture;
112import java.util.concurrent.TimeUnit;
Saurav Das7bcbe702017-06-13 15:35:54 -0700113import java.util.concurrent.atomic.AtomicBoolean;
Charles Chan7ffd81f2017-02-08 15:52:08 -0800114import java.util.stream.Collectors;
sanghob35a6192015-04-01 13:05:26 -0700115
Charles Chan3e783d02016-02-26 22:19:52 -0800116import static com.google.common.base.Preconditions.checkState;
Pier Ventree0ae7a32016-11-23 09:57:42 -0800117import static org.onlab.packet.Ethernet.TYPE_ARP;
Yuta HIGUCHI1624df12016-07-21 16:54:33 -0700118import static org.onlab.util.Tools.groupedThreads;
Charles Chan3e783d02016-02-26 22:19:52 -0800119
Charles Chane849c192016-01-11 18:28:54 -0800120/**
121 * Segment routing manager.
122 */
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700123@Service
124@Component(immediate = true)
sangho1e575652015-05-14 00:39:53 -0700125public class SegmentRoutingManager implements SegmentRoutingService {
sanghob35a6192015-04-01 13:05:26 -0700126
Charles Chan2c15aca2016-11-09 20:51:44 -0800127 private static Logger log = LoggerFactory.getLogger(SegmentRoutingManager.class);
sanghob35a6192015-04-01 13:05:26 -0700128
129 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan03a73e02016-10-24 14:52:01 -0700130 private ComponentConfigService compCfgService;
sanghob35a6192015-04-01 13:05:26 -0700131
132 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Pier Ventre10bd8d12016-11-26 21:05:22 -0800133 private NeighbourResolutionService neighbourResolutionService;
134
135 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Pier Ventre42287df2016-11-09 14:17:26 -0800136 public PathService pathService;
137
138 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan03a73e02016-10-24 14:52:01 -0700139 CoreService coreService;
sanghob35a6192015-04-01 13:05:26 -0700140
141 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan03a73e02016-10-24 14:52:01 -0700142 PacketService packetService;
sanghob35a6192015-04-01 13:05:26 -0700143
144 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan03a73e02016-10-24 14:52:01 -0700145 HostService hostService;
sanghob35a6192015-04-01 13:05:26 -0700146
147 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan03a73e02016-10-24 14:52:01 -0700148 DeviceService deviceService;
sanghob35a6192015-04-01 13:05:26 -0700149
150 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Pier Ventre42287df2016-11-09 14:17:26 -0800151 public FlowObjectiveService flowObjectiveService;
sanghob35a6192015-04-01 13:05:26 -0700152
153 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan03a73e02016-10-24 14:52:01 -0700154 LinkService linkService;
sangho1e575652015-05-14 00:39:53 -0700155
Charles Chan5270ed02016-01-30 23:22:37 -0800156 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Pier Ventre42287df2016-11-09 14:17:26 -0800157 public MastershipService mastershipService;
Charles Chan03a73e02016-10-24 14:52:01 -0700158
159 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Pier Ventre42287df2016-11-09 14:17:26 -0800160 public StorageService storageService;
Charles Chan03a73e02016-10-24 14:52:01 -0700161
162 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
163 MulticastRouteService multicastRouteService;
164
165 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
166 TopologyService topologyService;
167
168 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan03a73e02016-10-24 14:52:01 -0700169 RouteService routeService;
Charles Chan5270ed02016-01-30 23:22:37 -0800170
171 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan2c15aca2016-11-09 20:51:44 -0800172 public NetworkConfigRegistry cfgService;
Charles Chan5270ed02016-01-30 23:22:37 -0800173
Saurav Das80980c72016-03-23 11:22:49 -0700174 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan2c15aca2016-11-09 20:51:44 -0800175 public InterfaceService interfaceService;
176
Charles Chan03a73e02016-10-24 14:52:01 -0700177 ArpHandler arpHandler = null;
178 IcmpHandler icmpHandler = null;
179 IpHandler ipHandler = null;
180 RoutingRulePopulator routingRulePopulator = null;
Ray Milkeye4afdb52017-04-05 09:42:04 -0700181 ApplicationId appId;
182 DeviceConfiguration deviceConfiguration = null;
sanghob35a6192015-04-01 13:05:26 -0700183
Charles Chan03a73e02016-10-24 14:52:01 -0700184 DefaultRoutingHandler defaultRoutingHandler = null;
sangho1e575652015-05-14 00:39:53 -0700185 private TunnelHandler tunnelHandler = null;
186 private PolicyHandler policyHandler = null;
Charles Chanb8e10c82015-10-14 11:24:40 -0700187 private InternalPacketProcessor processor = null;
188 private InternalLinkListener linkListener = null;
189 private InternalDeviceListener deviceListener = null;
Charles Chanfc5c7802016-05-17 13:13:55 -0700190 private AppConfigHandler appCfgHandler = null;
Charles Chan03a73e02016-10-24 14:52:01 -0700191 XConnectHandler xConnectHandler = null;
Charles Chand2990362016-04-18 13:44:03 -0700192 private McastHandler mcastHandler = null;
Charles Chan65238242017-06-22 18:03:14 -0700193 private HostHandler hostHandler = null;
Pier Ventre10bd8d12016-11-26 21:05:22 -0800194 private RouteHandler routeHandler = null;
Pier Ventre735b8c82016-12-02 08:16:05 -0800195 private SegmentRoutingNeighbourDispatcher neighbourHandler = null;
Pier Ventref34966c2016-11-07 16:21:04 -0800196 private L2TunnelHandler l2TunnelHandler = null;
sanghob35a6192015-04-01 13:05:26 -0700197 private InternalEventHandler eventHandler = new InternalEventHandler();
Charles Chan5270ed02016-01-30 23:22:37 -0800198 private final InternalHostListener hostListener = new InternalHostListener();
Charles Chand55e84d2016-03-30 17:54:24 -0700199 private final InternalConfigListener cfgListener = new InternalConfigListener(this);
200 private final InternalMcastListener mcastListener = new InternalMcastListener();
Charles Chan03a73e02016-10-24 14:52:01 -0700201 private final InternalRouteEventListener routeListener = new InternalRouteEventListener();
sanghob35a6192015-04-01 13:05:26 -0700202
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700203 private ScheduledExecutorService executorService = Executors
Yuta HIGUCHI1624df12016-07-21 16:54:33 -0700204 .newScheduledThreadPool(1, groupedThreads("SegmentRoutingManager", "event-%d", log));
sanghob35a6192015-04-01 13:05:26 -0700205
Saurav Das4ce45962015-11-24 23:21:05 -0800206 @SuppressWarnings("unused")
sanghob35a6192015-04-01 13:05:26 -0700207 private static ScheduledFuture<?> eventHandlerFuture = null;
Saurav Das4ce45962015-11-24 23:21:05 -0800208 @SuppressWarnings("rawtypes")
Yuta HIGUCHI1624df12016-07-21 16:54:33 -0700209 private ConcurrentLinkedQueue<Event> eventQueue = new ConcurrentLinkedQueue<>();
Charles Chan68aa62d2015-11-09 16:37:23 -0800210 private Map<DeviceId, DefaultGroupHandler> groupHandlerMap =
Charles Chane849c192016-01-11 18:28:54 -0800211 new ConcurrentHashMap<>();
212 /**
Saurav Das7bcbe702017-06-13 15:35:54 -0700213 * Per device next objective ID store with (device id + destination set) as key.
Charles Chane849c192016-01-11 18:28:54 -0800214 */
Saurav Das7bcbe702017-06-13 15:35:54 -0700215 EventuallyConsistentMap<DestinationSetNextObjectiveStoreKey, NextNeighbors>
216 dsNextObjStore = null;
Charles Chane849c192016-01-11 18:28:54 -0800217 /**
218 * Per device next objective ID store with (device id + subnet) as key.
219 */
Ray Milkeye4afdb52017-04-05 09:42:04 -0700220 EventuallyConsistentMap<VlanNextObjectiveStoreKey, Integer>
Charles Chan59cc16d2017-02-02 16:20:42 -0800221 vlanNextObjStore = null;
Charles Chane849c192016-01-11 18:28:54 -0800222 /**
223 * Per device next objective ID store with (device id + port) as key.
224 */
Ray Milkeye4afdb52017-04-05 09:42:04 -0700225 EventuallyConsistentMap<PortNextObjectiveStoreKey, Integer>
Saurav Das4ce45962015-11-24 23:21:05 -0800226 portNextObjStore = null;
Charles Chan59cc16d2017-02-02 16:20:42 -0800227
Saurav Dasc88d4662017-05-15 15:34:25 -0700228 // Local store for all links seen and their present status, used for
229 // optimized routing. The existence of the link in the keys is enough to know
230 // if the link has been "seen-before" by this instance of the controller.
231 // The boolean value indicates if the link is currently up or not.
232 // XXX Currently the optimized routing logic depends on "forgetting" a link
233 // when a switch goes down, but "remembering" it when only the link goes down.
234 // Consider changing this logic so we can use the Link Service instead of
235 // a local cache.
236 private Map<Link, Boolean> seenLinks = new ConcurrentHashMap<>();
237
Saurav Das4ce45962015-11-24 23:21:05 -0800238 private EventuallyConsistentMap<String, Tunnel> tunnelStore = null;
239 private EventuallyConsistentMap<String, Policy> policyStore = null;
sangho0b2b6d12015-05-20 22:16:38 -0700240
Saurav Das7bcbe702017-06-13 15:35:54 -0700241 private AtomicBoolean programmingScheduled = new AtomicBoolean();
242
Charles Chand55e84d2016-03-30 17:54:24 -0700243 private final ConfigFactory<DeviceId, SegmentRoutingDeviceConfig> deviceConfigFactory =
Charles Chanfc5c7802016-05-17 13:13:55 -0700244 new ConfigFactory<DeviceId, SegmentRoutingDeviceConfig>(
245 SubjectFactories.DEVICE_SUBJECT_FACTORY,
Charles Chand55e84d2016-03-30 17:54:24 -0700246 SegmentRoutingDeviceConfig.class, "segmentrouting") {
Charles Chand6832882015-10-05 17:50:33 -0700247 @Override
Charles Chan5270ed02016-01-30 23:22:37 -0800248 public SegmentRoutingDeviceConfig createConfig() {
249 return new SegmentRoutingDeviceConfig();
Charles Chand6832882015-10-05 17:50:33 -0700250 }
251 };
Pier Ventref34966c2016-11-07 16:21:04 -0800252
Charles Chand55e84d2016-03-30 17:54:24 -0700253 private final ConfigFactory<ApplicationId, SegmentRoutingAppConfig> appConfigFactory =
Charles Chanfc5c7802016-05-17 13:13:55 -0700254 new ConfigFactory<ApplicationId, SegmentRoutingAppConfig>(
255 SubjectFactories.APP_SUBJECT_FACTORY,
Charles Chand55e84d2016-03-30 17:54:24 -0700256 SegmentRoutingAppConfig.class, "segmentrouting") {
Charles Chan5270ed02016-01-30 23:22:37 -0800257 @Override
258 public SegmentRoutingAppConfig createConfig() {
259 return new SegmentRoutingAppConfig();
260 }
261 };
Pier Ventref34966c2016-11-07 16:21:04 -0800262
Charles Chanfc5c7802016-05-17 13:13:55 -0700263 private final ConfigFactory<ApplicationId, XConnectConfig> xConnectConfigFactory =
264 new ConfigFactory<ApplicationId, XConnectConfig>(
265 SubjectFactories.APP_SUBJECT_FACTORY,
266 XConnectConfig.class, "xconnect") {
267 @Override
268 public XConnectConfig createConfig() {
269 return new XConnectConfig();
270 }
271 };
Pier Ventref34966c2016-11-07 16:21:04 -0800272
Charles Chand55e84d2016-03-30 17:54:24 -0700273 private ConfigFactory<ApplicationId, McastConfig> mcastConfigFactory =
Charles Chanfc5c7802016-05-17 13:13:55 -0700274 new ConfigFactory<ApplicationId, McastConfig>(
275 SubjectFactories.APP_SUBJECT_FACTORY,
Charles Chand55e84d2016-03-30 17:54:24 -0700276 McastConfig.class, "multicast") {
277 @Override
278 public McastConfig createConfig() {
279 return new McastConfig();
280 }
281 };
282
Pier Ventref34966c2016-11-07 16:21:04 -0800283 private final ConfigFactory<ApplicationId, PwaasConfig> pwaasConfigFactory =
284 new ConfigFactory<ApplicationId, PwaasConfig>(
285 SubjectFactories.APP_SUBJECT_FACTORY,
286 PwaasConfig.class, "pwaas") {
287 @Override
288 public PwaasConfig createConfig() {
289 return new PwaasConfig();
290 }
291 };
292
Charles Chan65238242017-06-22 18:03:14 -0700293 private static final Object THREAD_SCHED_LOCK = new Object();
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700294 private static int numOfEventsQueued = 0;
295 private static int numOfEventsExecuted = 0;
sanghob35a6192015-04-01 13:05:26 -0700296 private static int numOfHandlerExecution = 0;
297 private static int numOfHandlerScheduled = 0;
298
Charles Chan116188d2016-02-18 14:22:42 -0800299 /**
300 * Segment Routing App ID.
301 */
Charles Chan2c15aca2016-11-09 20:51:44 -0800302 public static final String APP_NAME = "org.onosproject.segmentrouting";
Charles Chan59cc16d2017-02-02 16:20:42 -0800303
Charles Chane849c192016-01-11 18:28:54 -0800304 /**
305 * The default VLAN ID assigned to the interfaces without subnet config.
306 */
Charles Chan59cc16d2017-02-02 16:20:42 -0800307 public static final VlanId INTERNAL_VLAN = VlanId.vlanId((short) 4094);
Saurav Das0e99e2b2015-10-28 12:39:42 -0700308
sanghob35a6192015-04-01 13:05:26 -0700309 @Activate
310 protected void activate() {
Charles Chan2c15aca2016-11-09 20:51:44 -0800311 appId = coreService.registerApplication(APP_NAME);
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700312
313 log.debug("Creating EC map nsnextobjectivestore");
Saurav Das7bcbe702017-06-13 15:35:54 -0700314 EventuallyConsistentMapBuilder<DestinationSetNextObjectiveStoreKey, NextNeighbors>
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700315 nsNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder();
Saurav Das7bcbe702017-06-13 15:35:54 -0700316 dsNextObjStore = nsNextObjMapBuilder
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700317 .withName("nsnextobjectivestore")
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700318 .withSerializer(createSerializer())
Madan Jampanibcf1a482015-06-24 19:05:56 -0700319 .withTimestampProvider((k, v) -> new WallClockTimestamp())
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700320 .build();
Saurav Das7bcbe702017-06-13 15:35:54 -0700321 log.trace("Current size {}", dsNextObjStore.size());
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700322
Charles Chan59cc16d2017-02-02 16:20:42 -0800323 log.debug("Creating EC map vlannextobjectivestore");
324 EventuallyConsistentMapBuilder<VlanNextObjectiveStoreKey, Integer>
325 vlanNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder();
326 vlanNextObjStore = vlanNextObjMapBuilder
327 .withName("vlannextobjectivestore")
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700328 .withSerializer(createSerializer())
Charles Chanc42e84e2015-10-20 16:24:19 -0700329 .withTimestampProvider((k, v) -> new WallClockTimestamp())
330 .build();
331
Saurav Das4ce45962015-11-24 23:21:05 -0800332 log.debug("Creating EC map subnetnextobjectivestore");
333 EventuallyConsistentMapBuilder<PortNextObjectiveStoreKey, Integer>
334 portNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder();
335 portNextObjStore = portNextObjMapBuilder
336 .withName("portnextobjectivestore")
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700337 .withSerializer(createSerializer())
Saurav Das4ce45962015-11-24 23:21:05 -0800338 .withTimestampProvider((k, v) -> new WallClockTimestamp())
339 .build();
340
sangho0b2b6d12015-05-20 22:16:38 -0700341 EventuallyConsistentMapBuilder<String, Tunnel> tunnelMapBuilder =
342 storageService.eventuallyConsistentMapBuilder();
sangho0b2b6d12015-05-20 22:16:38 -0700343 tunnelStore = tunnelMapBuilder
344 .withName("tunnelstore")
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700345 .withSerializer(createSerializer())
Madan Jampanibcf1a482015-06-24 19:05:56 -0700346 .withTimestampProvider((k, v) -> new WallClockTimestamp())
sangho0b2b6d12015-05-20 22:16:38 -0700347 .build();
348
349 EventuallyConsistentMapBuilder<String, Policy> policyMapBuilder =
350 storageService.eventuallyConsistentMapBuilder();
sangho0b2b6d12015-05-20 22:16:38 -0700351 policyStore = policyMapBuilder
352 .withName("policystore")
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700353 .withSerializer(createSerializer())
Madan Jampanibcf1a482015-06-24 19:05:56 -0700354 .withTimestampProvider((k, v) -> new WallClockTimestamp())
sangho0b2b6d12015-05-20 22:16:38 -0700355 .build();
356
Saurav Das80980c72016-03-23 11:22:49 -0700357 compCfgService.preSetProperty("org.onosproject.net.group.impl.GroupManager",
Pier Luigi9e5c5ca2017-01-12 18:14:58 -0800358 "purgeOnDisconnection", "true");
Saurav Das80980c72016-03-23 11:22:49 -0700359 compCfgService.preSetProperty("org.onosproject.net.flow.impl.FlowRuleManager",
Pier Luigi9e5c5ca2017-01-12 18:14:58 -0800360 "purgeOnDisconnection", "true");
Pier Luigi9e5c5ca2017-01-12 18:14:58 -0800361 compCfgService.preSetProperty("org.onosproject.provider.host.impl.HostLocationProvider",
362 "requestInterceptsEnabled", "false");
Charles Chand3baaba2017-08-08 15:13:37 -0700363 compCfgService.preSetProperty("org.onosproject.net.neighbour.impl.NeighbourResolutionManager",
Pier Luigi7e415132017-01-12 22:46:39 -0800364 "requestInterceptsEnabled", "false");
Charles Chanc760f382017-07-24 15:56:10 -0700365 compCfgService.preSetProperty("org.onosproject.dhcprelay.DhcpRelayManager",
Pier Luigi7e415132017-01-12 22:46:39 -0800366 "arpEnabled", "false");
Pier Luigi9b1d6262017-02-02 22:31:34 -0800367 compCfgService.preSetProperty("org.onosproject.net.host.impl.HostManager",
368 "greedyLearningIpv6", "true");
Charles Chanc6d227e2017-02-28 15:15:17 -0800369 compCfgService.preSetProperty("org.onosproject.routing.cpr.ControlPlaneRedirectManager",
370 "forceUnprovision", "true");
Charles Chanef624ed2017-08-10 16:57:28 -0700371 compCfgService.preSetProperty("org.onosproject.routeservice.store.RouteStoreImpl",
Charles Chan73316522017-07-20 16:16:25 -0700372 "distributed", "true");
Charles Chan35a32322017-08-14 11:42:11 -0700373 compCfgService.preSetProperty("org.onosproject.provider.host.impl.HostLocationProvider",
374 "multihomingEnabled", "true");
Saurav Das80980c72016-03-23 11:22:49 -0700375
Charles Chanb8e10c82015-10-14 11:24:40 -0700376 processor = new InternalPacketProcessor();
377 linkListener = new InternalLinkListener();
378 deviceListener = new InternalDeviceListener();
Charles Chanfc5c7802016-05-17 13:13:55 -0700379 appCfgHandler = new AppConfigHandler(this);
380 xConnectHandler = new XConnectHandler(this);
Charles Chand2990362016-04-18 13:44:03 -0700381 mcastHandler = new McastHandler(this);
382 hostHandler = new HostHandler(this);
Charles Chan03a73e02016-10-24 14:52:01 -0700383 routeHandler = new RouteHandler(this);
Pier Ventre735b8c82016-12-02 08:16:05 -0800384 neighbourHandler = new SegmentRoutingNeighbourDispatcher(this);
Pier Ventref34966c2016-11-07 16:21:04 -0800385 l2TunnelHandler = new L2TunnelHandler(this);
Charles Chanb8e10c82015-10-14 11:24:40 -0700386
Charles Chan3e783d02016-02-26 22:19:52 -0800387 cfgService.addListener(cfgListener);
Charles Chand55e84d2016-03-30 17:54:24 -0700388 cfgService.registerConfigFactory(deviceConfigFactory);
389 cfgService.registerConfigFactory(appConfigFactory);
Charles Chanfc5c7802016-05-17 13:13:55 -0700390 cfgService.registerConfigFactory(xConnectConfigFactory);
Charles Chand55e84d2016-03-30 17:54:24 -0700391 cfgService.registerConfigFactory(mcastConfigFactory);
Pier Ventref34966c2016-11-07 16:21:04 -0800392 cfgService.registerConfigFactory(pwaasConfigFactory);
Charles Chan5270ed02016-01-30 23:22:37 -0800393 hostService.addListener(hostListener);
Charles Chanb8e10c82015-10-14 11:24:40 -0700394 packetService.addProcessor(processor, PacketProcessor.director(2));
395 linkService.addListener(linkListener);
396 deviceService.addListener(deviceListener);
Charles Chand55e84d2016-03-30 17:54:24 -0700397 multicastRouteService.addListener(mcastListener);
Charles Chanc7a8a682017-06-19 00:43:31 -0700398 routeService.addListener(routeListener);
Charles Chanb8e10c82015-10-14 11:24:40 -0700399
400 cfgListener.configureNetwork();
401
sanghob35a6192015-04-01 13:05:26 -0700402 log.info("Started");
403 }
404
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700405 private KryoNamespace.Builder createSerializer() {
406 return new KryoNamespace.Builder()
407 .register(KryoNamespaces.API)
Saurav Das7bcbe702017-06-13 15:35:54 -0700408 .register(DestinationSetNextObjectiveStoreKey.class,
Charles Chan59cc16d2017-02-02 16:20:42 -0800409 VlanNextObjectiveStoreKey.class,
Saurav Das7bcbe702017-06-13 15:35:54 -0700410 DestinationSet.class,
411 NextNeighbors.class,
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700412 Tunnel.class,
413 DefaultTunnel.class,
414 Policy.class,
415 TunnelPolicy.class,
416 Policy.Type.class,
417 PortNextObjectiveStoreKey.class,
Charles Chanfc5c7802016-05-17 13:13:55 -0700418 XConnectStoreKey.class
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700419 );
420 }
421
sanghob35a6192015-04-01 13:05:26 -0700422 @Deactivate
423 protected void deactivate() {
Charles Chand6832882015-10-05 17:50:33 -0700424 cfgService.removeListener(cfgListener);
Charles Chand55e84d2016-03-30 17:54:24 -0700425 cfgService.unregisterConfigFactory(deviceConfigFactory);
426 cfgService.unregisterConfigFactory(appConfigFactory);
Charles Chan03a73e02016-10-24 14:52:01 -0700427 cfgService.unregisterConfigFactory(xConnectConfigFactory);
Charles Chand55e84d2016-03-30 17:54:24 -0700428 cfgService.unregisterConfigFactory(mcastConfigFactory);
Pier Ventref34966c2016-11-07 16:21:04 -0800429 cfgService.unregisterConfigFactory(pwaasConfigFactory);
Charles Chand6832882015-10-05 17:50:33 -0700430
Charles Chanc7a8a682017-06-19 00:43:31 -0700431 hostService.removeListener(hostListener);
sanghob35a6192015-04-01 13:05:26 -0700432 packetService.removeProcessor(processor);
Charles Chanb8e10c82015-10-14 11:24:40 -0700433 linkService.removeListener(linkListener);
434 deviceService.removeListener(deviceListener);
Charles Chand55e84d2016-03-30 17:54:24 -0700435 multicastRouteService.removeListener(mcastListener);
Charles Chan03a73e02016-10-24 14:52:01 -0700436 routeService.removeListener(routeListener);
Charles Chand55e84d2016-03-30 17:54:24 -0700437
Charles Chan0aa674e2017-02-23 15:44:08 -0800438 neighbourResolutionService.unregisterNeighbourHandlers(appId);
439
sanghob35a6192015-04-01 13:05:26 -0700440 processor = null;
Charles Chanb8e10c82015-10-14 11:24:40 -0700441 linkListener = null;
Charles Chand55e84d2016-03-30 17:54:24 -0700442 deviceListener = null;
Charles Chanb8e10c82015-10-14 11:24:40 -0700443 groupHandlerMap.clear();
444
Saurav Das7bcbe702017-06-13 15:35:54 -0700445 dsNextObjStore.destroy();
Charles Chan59cc16d2017-02-02 16:20:42 -0800446 vlanNextObjStore.destroy();
Charles Chand55e84d2016-03-30 17:54:24 -0700447 portNextObjStore.destroy();
Charles Chand55e84d2016-03-30 17:54:24 -0700448 tunnelStore.destroy();
449 policyStore.destroy();
sanghob35a6192015-04-01 13:05:26 -0700450 log.info("Stopped");
451 }
452
sangho1e575652015-05-14 00:39:53 -0700453 @Override
454 public List<Tunnel> getTunnels() {
455 return tunnelHandler.getTunnels();
456 }
457
458 @Override
sangho71abe1b2015-06-29 14:58:47 -0700459 public TunnelHandler.Result createTunnel(Tunnel tunnel) {
460 return tunnelHandler.createTunnel(tunnel);
sangho1e575652015-05-14 00:39:53 -0700461 }
462
463 @Override
sangho71abe1b2015-06-29 14:58:47 -0700464 public TunnelHandler.Result removeTunnel(Tunnel tunnel) {
sangho1e575652015-05-14 00:39:53 -0700465 for (Policy policy: policyHandler.getPolicies()) {
466 if (policy.type() == Policy.Type.TUNNEL_FLOW) {
467 TunnelPolicy tunnelPolicy = (TunnelPolicy) policy;
468 if (tunnelPolicy.tunnelId().equals(tunnel.id())) {
469 log.warn("Cannot remove the tunnel used by a policy");
sangho71abe1b2015-06-29 14:58:47 -0700470 return TunnelHandler.Result.TUNNEL_IN_USE;
sangho1e575652015-05-14 00:39:53 -0700471 }
472 }
473 }
sangho71abe1b2015-06-29 14:58:47 -0700474 return tunnelHandler.removeTunnel(tunnel);
sangho1e575652015-05-14 00:39:53 -0700475 }
476
477 @Override
sangho71abe1b2015-06-29 14:58:47 -0700478 public PolicyHandler.Result removePolicy(Policy policy) {
479 return policyHandler.removePolicy(policy);
sangho1e575652015-05-14 00:39:53 -0700480 }
481
482 @Override
sangho71abe1b2015-06-29 14:58:47 -0700483 public PolicyHandler.Result createPolicy(Policy policy) {
484 return policyHandler.createPolicy(policy);
sangho1e575652015-05-14 00:39:53 -0700485 }
486
487 @Override
488 public List<Policy> getPolicies() {
489 return policyHandler.getPolicies();
490 }
491
Saurav Das59232cf2016-04-27 18:35:50 -0700492 @Override
493 public void rerouteNetwork() {
494 cfgListener.configureNetwork();
Saurav Das59232cf2016-04-27 18:35:50 -0700495 }
496
Charles Chanc81c45b2016-10-20 17:02:44 -0700497 @Override
Pier Ventre10bd8d12016-11-26 21:05:22 -0800498 public Map<DeviceId, Set<IpPrefix>> getDeviceSubnetMap() {
499 Map<DeviceId, Set<IpPrefix>> deviceSubnetMap = Maps.newHashMap();
Charles Chanc81c45b2016-10-20 17:02:44 -0700500 deviceService.getAvailableDevices().forEach(device -> {
501 deviceSubnetMap.put(device.id(), deviceConfiguration.getSubnets(device.id()));
502 });
503 return deviceSubnetMap;
504 }
505
Saurav Dasc88d4662017-05-15 15:34:25 -0700506
507 @Override
508 public ImmutableMap<DeviceId, EcmpShortestPathGraph> getCurrentEcmpSpg() {
509 if (defaultRoutingHandler != null) {
510 return defaultRoutingHandler.getCurrentEmcpSpgMap();
511 } else {
512 return null;
513 }
514 }
515
516 @Override
Saurav Das7bcbe702017-06-13 15:35:54 -0700517 public ImmutableMap<DestinationSetNextObjectiveStoreKey, NextNeighbors> getDestinationSet() {
518 if (dsNextObjStore != null) {
519 return ImmutableMap.copyOf(dsNextObjStore.entrySet());
Saurav Dasc88d4662017-05-15 15:34:25 -0700520 } else {
521 return ImmutableMap.of();
522 }
523 }
524
Saurav Dasceccf242017-08-03 18:30:35 -0700525 @Override
526 public void verifyGroups(DeviceId id) {
527 DefaultGroupHandler gh = groupHandlerMap.get(id);
528 if (gh != null) {
529 gh.triggerBucketCorrector();
530 }
531 }
532
sanghof9d0bf12015-05-19 11:57:42 -0700533 /**
Ray Milkeye4afdb52017-04-05 09:42:04 -0700534 * Extracts the application ID from the manager.
535 *
536 * @return application ID
537 */
538 public ApplicationId appId() {
539 return appId;
540 }
541
542 /**
543 * Returns the device configuration.
544 *
545 * @return device configuration
546 */
547 public DeviceConfiguration deviceConfiguration() {
548 return deviceConfiguration;
549 }
550
551 /**
Saurav Das7bcbe702017-06-13 15:35:54 -0700552 * Per device next objective ID store with (device id + destination set) as key.
Ray Milkeye4afdb52017-04-05 09:42:04 -0700553 *
554 * @return next objective ID store
555 */
Saurav Das7bcbe702017-06-13 15:35:54 -0700556 public EventuallyConsistentMap<DestinationSetNextObjectiveStoreKey, NextNeighbors>
557 dsNextObjStore() {
558 return dsNextObjStore;
Ray Milkeye4afdb52017-04-05 09:42:04 -0700559 }
560
561 /**
562 * Per device next objective ID store with (device id + subnet) as key.
563 *
564 * @return vlan next object store
565 */
566 public EventuallyConsistentMap<VlanNextObjectiveStoreKey, Integer> vlanNextObjStore() {
567 return vlanNextObjStore;
568 }
569
570 /**
571 * Per device next objective ID store with (device id + port) as key.
572 *
573 * @return port next object store.
574 */
575 public EventuallyConsistentMap<PortNextObjectiveStoreKey, Integer> portNextObjStore() {
576 return portNextObjStore;
577 }
578
579 /**
Saurav Das7bcbe702017-06-13 15:35:54 -0700580 * Returns the MPLS-ECMP configuration which indicates whether ECMP on
581 * labeled packets should be programmed or not.
Pier Ventre98161782016-10-31 15:00:01 -0700582 *
583 * @return MPLS-ECMP value
584 */
585 public boolean getMplsEcmp() {
586 SegmentRoutingAppConfig segmentRoutingAppConfig = cfgService
587 .getConfig(this.appId, SegmentRoutingAppConfig.class);
588 return segmentRoutingAppConfig != null && segmentRoutingAppConfig.mplsEcmp();
589 }
590
591 /**
sanghof9d0bf12015-05-19 11:57:42 -0700592 * Returns the tunnel object with the tunnel ID.
593 *
594 * @param tunnelId Tunnel ID
595 * @return Tunnel reference
596 */
sangho1e575652015-05-14 00:39:53 -0700597 public Tunnel getTunnel(String tunnelId) {
598 return tunnelHandler.getTunnel(tunnelId);
599 }
600
Charles Chan7ffd81f2017-02-08 15:52:08 -0800601 // TODO Consider moving these to InterfaceService
sanghob35a6192015-04-01 13:05:26 -0700602 /**
Charles Chan59cc16d2017-02-02 16:20:42 -0800603 * Returns untagged VLAN configured on given connect point.
Charles Chan7ffd81f2017-02-08 15:52:08 -0800604 * <p>
605 * Only returns the first match if there are multiple untagged VLAN configured
606 * on the connect point.
sanghob35a6192015-04-01 13:05:26 -0700607 *
Charles Chan59cc16d2017-02-02 16:20:42 -0800608 * @param connectPoint connect point
609 * @return untagged VLAN or null if not configured
sanghob35a6192015-04-01 13:05:26 -0700610 */
Charles Chan65238242017-06-22 18:03:14 -0700611 VlanId getUntaggedVlanId(ConnectPoint connectPoint) {
Charles Chan59cc16d2017-02-02 16:20:42 -0800612 return interfaceService.getInterfacesByPort(connectPoint).stream()
613 .filter(intf -> !intf.vlanUntagged().equals(VlanId.NONE))
614 .map(Interface::vlanUntagged)
615 .findFirst().orElse(null);
sanghob35a6192015-04-01 13:05:26 -0700616 }
617
sangho1e575652015-05-14 00:39:53 -0700618 /**
Charles Chan7ffd81f2017-02-08 15:52:08 -0800619 * Returns tagged VLAN configured on given connect point.
620 * <p>
621 * Returns all matches if there are multiple tagged VLAN configured
622 * on the connect point.
623 *
624 * @param connectPoint connect point
625 * @return tagged VLAN or empty set if not configured
626 */
Charles Chan65238242017-06-22 18:03:14 -0700627 Set<VlanId> getTaggedVlanId(ConnectPoint connectPoint) {
Charles Chan7ffd81f2017-02-08 15:52:08 -0800628 Set<Interface> interfaces = interfaceService.getInterfacesByPort(connectPoint);
629 return interfaces.stream()
630 .map(Interface::vlanTagged)
Charles Chan65238242017-06-22 18:03:14 -0700631 .flatMap(Set::stream)
Charles Chan7ffd81f2017-02-08 15:52:08 -0800632 .collect(Collectors.toSet());
633 }
634
635 /**
636 * Returns native VLAN configured on given connect point.
637 * <p>
638 * Only returns the first match if there are multiple native VLAN configured
639 * on the connect point.
640 *
641 * @param connectPoint connect point
642 * @return native VLAN or null if not configured
643 */
Charles Chan65238242017-06-22 18:03:14 -0700644 VlanId getNativeVlanId(ConnectPoint connectPoint) {
Charles Chan7ffd81f2017-02-08 15:52:08 -0800645 Set<Interface> interfaces = interfaceService.getInterfacesByPort(connectPoint);
646 return interfaces.stream()
647 .filter(intf -> !intf.vlanNative().equals(VlanId.NONE))
648 .map(Interface::vlanNative)
649 .findFirst()
650 .orElse(null);
651 }
652
653 /**
Charles Chanf9a52702017-06-16 15:19:24 -0700654 * Returns internal VLAN for untagged hosts on given connect point.
655 * <p>
656 * The internal VLAN is either vlan-untagged for an access port,
657 * or vlan-native for a trunk port.
658 *
659 * @param connectPoint connect point
660 * @return internal VLAN or null if both vlan-untagged and vlan-native are undefined
661 */
Charles Chan65238242017-06-22 18:03:14 -0700662 VlanId getInternalVlanId(ConnectPoint connectPoint) {
Charles Chanf9a52702017-06-16 15:19:24 -0700663 VlanId untaggedVlanId = getUntaggedVlanId(connectPoint);
664 VlanId nativeVlanId = getNativeVlanId(connectPoint);
665 return untaggedVlanId != null ? untaggedVlanId : nativeVlanId;
666 }
667
668 /**
Charles Chan65238242017-06-22 18:03:14 -0700669 * Returns optional pair device ID of given device.
670 *
671 * @param deviceId device ID
672 * @return optional pair device ID. Might be empty if pair device is not configured
673 */
674 Optional<DeviceId> getPairDeviceId(DeviceId deviceId) {
675 SegmentRoutingDeviceConfig deviceConfig =
676 cfgService.getConfig(deviceId, SegmentRoutingDeviceConfig.class);
677 return Optional.ofNullable(deviceConfig).map(SegmentRoutingDeviceConfig::pairDeviceId);
678 }
679 /**
680 * Returns optional pair device local port of given device.
681 *
682 * @param deviceId device ID
683 * @return optional pair device ID. Might be empty if pair device is not configured
684 */
685 Optional<PortNumber> getPairLocalPorts(DeviceId deviceId) {
686 SegmentRoutingDeviceConfig deviceConfig =
687 cfgService.getConfig(deviceId, SegmentRoutingDeviceConfig.class);
688 return Optional.ofNullable(deviceConfig).map(SegmentRoutingDeviceConfig::pairLocalPort);
689 }
690
691 /**
Charles Chan7ffd81f2017-02-08 15:52:08 -0800692 * Returns vlan port map of given device.
693 *
694 * @param deviceId device id
695 * @return vlan-port multimap
696 */
697 public Multimap<VlanId, PortNumber> getVlanPortMap(DeviceId deviceId) {
698 HashMultimap<VlanId, PortNumber> vlanPortMap = HashMultimap.create();
699
700 interfaceService.getInterfaces().stream()
701 .filter(intf -> intf.connectPoint().deviceId().equals(deviceId))
702 .forEach(intf -> {
703 vlanPortMap.put(intf.vlanUntagged(), intf.connectPoint().port());
Charles Chan65238242017-06-22 18:03:14 -0700704 intf.vlanTagged().forEach(vlanTagged ->
705 vlanPortMap.put(vlanTagged, intf.connectPoint().port())
706 );
Charles Chan7ffd81f2017-02-08 15:52:08 -0800707 vlanPortMap.put(intf.vlanNative(), intf.connectPoint().port());
708 });
709 vlanPortMap.removeAll(VlanId.NONE);
710
711 return vlanPortMap;
712 }
713
714 /**
Saurav Das4ce45962015-11-24 23:21:05 -0800715 * Returns the next objective ID for the given subnet prefix. It is expected
Charles Chan59cc16d2017-02-02 16:20:42 -0800716 * Returns the next objective ID for the given vlan id. It is expected
Saurav Das4ce45962015-11-24 23:21:05 -0800717 * that the next-objective has been pre-created from configuration.
Charles Chanc42e84e2015-10-20 16:24:19 -0700718 *
719 * @param deviceId Device ID
Charles Chan59cc16d2017-02-02 16:20:42 -0800720 * @param vlanId VLAN ID
Saurav Das4ce45962015-11-24 23:21:05 -0800721 * @return next objective ID or -1 if it was not found
Charles Chanc42e84e2015-10-20 16:24:19 -0700722 */
Charles Chan65238242017-06-22 18:03:14 -0700723 int getVlanNextObjectiveId(DeviceId deviceId, VlanId vlanId) {
Charles Chanc42e84e2015-10-20 16:24:19 -0700724 if (groupHandlerMap.get(deviceId) != null) {
Charles Chan59cc16d2017-02-02 16:20:42 -0800725 log.trace("getVlanNextObjectiveId query in device {}", deviceId);
726 return groupHandlerMap.get(deviceId).getVlanNextObjectiveId(vlanId);
Charles Chanc42e84e2015-10-20 16:24:19 -0700727 } else {
Charles Chan59cc16d2017-02-02 16:20:42 -0800728 log.warn("getVlanNextObjectiveId query - groupHandler for "
Saurav Das4ce45962015-11-24 23:21:05 -0800729 + "device {} not found", deviceId);
730 return -1;
731 }
732 }
733
734 /**
735 * Returns the next objective ID for the given portNumber, given the treatment.
736 * There could be multiple different treatments to the same outport, which
Saurav Das961beb22017-03-29 19:09:17 -0700737 * would result in different objectives. If the next object does not exist,
738 * and should be created, a new one is created and its id is returned.
Saurav Das4ce45962015-11-24 23:21:05 -0800739 *
740 * @param deviceId Device ID
741 * @param portNum port number on device for which NextObjective is queried
742 * @param treatment the actions to apply on the packets (should include outport)
743 * @param meta metadata passed into the creation of a Next Objective if necessary
Saurav Das961beb22017-03-29 19:09:17 -0700744 * @param createIfMissing true if a next object should be created if not found
Saurav Das59232cf2016-04-27 18:35:50 -0700745 * @return next objective ID or -1 if an error occurred during retrieval or creation
Saurav Das4ce45962015-11-24 23:21:05 -0800746 */
747 public int getPortNextObjectiveId(DeviceId deviceId, PortNumber portNum,
748 TrafficTreatment treatment,
Saurav Das961beb22017-03-29 19:09:17 -0700749 TrafficSelector meta,
750 boolean createIfMissing) {
Saurav Das4ce45962015-11-24 23:21:05 -0800751 DefaultGroupHandler ghdlr = groupHandlerMap.get(deviceId);
752 if (ghdlr != null) {
Saurav Das961beb22017-03-29 19:09:17 -0700753 return ghdlr.getPortNextObjectiveId(portNum, treatment, meta, createIfMissing);
Saurav Das4ce45962015-11-24 23:21:05 -0800754 } else {
Charles Chane849c192016-01-11 18:28:54 -0800755 log.warn("getPortNextObjectiveId query - groupHandler for device {}"
756 + " not found", deviceId);
757 return -1;
758 }
759 }
760
Saurav Dasc88d4662017-05-15 15:34:25 -0700761 /**
762 * Returns the group handler object for the specified device id.
763 *
764 * @param devId the device identifier
765 * @return the groupHandler object for the device id, or null if not found
766 */
Charles Chan65238242017-06-22 18:03:14 -0700767 DefaultGroupHandler getGroupHandler(DeviceId devId) {
Saurav Dasc88d4662017-05-15 15:34:25 -0700768 return groupHandlerMap.get(devId);
769 }
770
771 /**
Saurav Dasceccf242017-08-03 18:30:35 -0700772 * Returns the default routing handler object.
773 *
774 * @return the default routing handler object
775 */
776 public DefaultRoutingHandler getRoutingHandler() {
777 return defaultRoutingHandler;
778 }
779
780 /**
Saurav Dasc88d4662017-05-15 15:34:25 -0700781 * Returns true if this controller instance has seen this link before. The
782 * link may not be currently up, but as long as the link had been seen before
783 * this method will return true. The one exception is when the link was
784 * indeed seen before, but this controller instance was forced to forget it
785 * by a call to purgeSeenLink method.
786 *
787 * @param link the infrastructure link being queried
788 * @return true if this controller instance has seen this link before
789 */
Charles Chan65238242017-06-22 18:03:14 -0700790 boolean isSeenLink(Link link) {
Saurav Dasc88d4662017-05-15 15:34:25 -0700791 return seenLinks.containsKey(link);
792 }
793
794 /**
795 * Updates the seen link store. Updates can be for links that are currently
796 * available or not.
797 *
798 * @param link the link to update in the seen-link local store
799 * @param up the status of the link, true if up, false if down
800 */
Charles Chan65238242017-06-22 18:03:14 -0700801 void updateSeenLink(Link link, boolean up) {
Saurav Dasc88d4662017-05-15 15:34:25 -0700802 seenLinks.put(link, up);
803 }
804
805 /**
806 * Returns the status of a seen-link (up or down). If the link has not
807 * been seen-before, a null object is returned.
808 *
809 * @param link the infrastructure link being queried
810 * @return null if the link was not seen-before;
811 * true if the seen-link is up;
812 * false if the seen-link is down
813 */
Charles Chan65238242017-06-22 18:03:14 -0700814 Boolean isSeenLinkUp(Link link) {
Saurav Dasc88d4662017-05-15 15:34:25 -0700815 return seenLinks.get(link);
816 }
817
818 /**
819 * Makes this controller instance forget a previously seen before link.
820 *
821 * @param link the infrastructure link to purge
822 */
Charles Chan65238242017-06-22 18:03:14 -0700823 private void purgeSeenLink(Link link) {
Saurav Dasc88d4662017-05-15 15:34:25 -0700824 seenLinks.remove(link);
825 }
826
827 /**
828 * Returns the status of a link as parallel link. A parallel link
829 * is defined as a link which has common src and dst switches as another
830 * seen-link that is currently enabled. It is not necessary for the link being
831 * queried to be a seen-link.
832 *
833 * @param link the infrastructure link being queried
834 * @return true if a seen-link exists that is up, and shares the
835 * same src and dst switches as the link being queried
836 */
Charles Chan65238242017-06-22 18:03:14 -0700837 private boolean isParallelLink(Link link) {
Saurav Dasc88d4662017-05-15 15:34:25 -0700838 for (Entry<Link, Boolean> seen : seenLinks.entrySet()) {
839 Link seenLink = seen.getKey();
840 if (seenLink.equals(link)) {
841 continue;
842 }
843 if (seenLink.src().deviceId().equals(link.src().deviceId()) &&
844 seenLink.dst().deviceId().equals(link.dst().deviceId()) &&
845 seen.getValue()) {
846 return true;
847 }
848 }
849 return false;
850 }
851
Saurav Das7bcbe702017-06-13 15:35:54 -0700852 /**
853 * Returns true if the link being queried is a bidirectional link. A bidi
854 * link is defined as a link, whose reverse link - ie. the link in the reverse
855 * direction - has been seen-before and is up. It is not necessary for the link
856 * being queried to be a seen-link.
857 *
858 * @param link the infrastructure link being queried
859 * @return true if another unidirectional link exists in the reverse direction,
860 * has been seen-before and is up
861 */
862 public boolean isBidirectional(Link link) {
863 Link reverseLink = linkService.getLink(link.dst(), link.src());
864 if (reverseLink == null) {
865 return false;
866 }
867 Boolean result = isSeenLinkUp(reverseLink);
868 if (result == null) {
869 return false;
870 }
871 return result.booleanValue();
872 }
873
874 /**
875 * Determines if the given link should be avoided in routing calculations
876 * by policy or design.
877 *
878 * @param link the infrastructure link being queried
879 * @return true if link should be avoided
880 */
881 public boolean avoidLink(Link link) {
882 // XXX currently only avoids all pair-links. In the future can be
883 // extended to avoid any generic link
884 DeviceId src = link.src().deviceId();
885 PortNumber srcPort = link.src().port();
886 if (deviceConfiguration == null || !deviceConfiguration.isConfigured(src)) {
887 log.warn("Device {} not configured..cannot avoid link {}", src, link);
888 return false;
889 }
890 DeviceId pairDev;
891 PortNumber pairLocalPort, pairRemotePort = null;
892 try {
893 pairDev = deviceConfiguration.getPairDeviceId(src);
894 pairLocalPort = deviceConfiguration.getPairLocalPort(src);
895 if (pairDev != null) {
896 pairRemotePort = deviceConfiguration.getPairLocalPort(pairDev);
897 }
898 } catch (DeviceConfigNotFoundException e) {
899 log.warn("Pair dev for dev {} not configured..cannot avoid link {}",
900 src, link);
901 return false;
902 }
903
904 if (srcPort.equals(pairLocalPort) &&
905 link.dst().deviceId().equals(pairDev) &&
906 link.dst().port().equals(pairRemotePort)) {
907 return true;
908 }
909 return false;
910 }
911
sanghob35a6192015-04-01 13:05:26 -0700912 private class InternalPacketProcessor implements PacketProcessor {
sanghob35a6192015-04-01 13:05:26 -0700913 @Override
914 public void process(PacketContext context) {
915
916 if (context.isHandled()) {
917 return;
918 }
919
920 InboundPacket pkt = context.inPacket();
921 Ethernet ethernet = pkt.parsed();
Pier Luigi7dad71c2017-02-01 13:50:04 -0800922
923 if (ethernet == null) {
924 return;
925 }
926
Saurav Das7bcbe702017-06-13 15:35:54 -0700927 log.trace("Rcvd pktin from {}: {}", context.inPacket().receivedFrom(),
928 ethernet);
Pier Ventree0ae7a32016-11-23 09:57:42 -0800929 if (ethernet.getEtherType() == TYPE_ARP) {
Saurav Dasc88d4662017-05-15 15:34:25 -0700930 log.warn("Received unexpected ARP packet on {}",
931 context.inPacket().receivedFrom());
Saurav Das76ae6812017-03-15 15:15:14 -0700932 log.trace("{}", ethernet);
Pier Ventre968da122016-12-09 17:26:04 -0800933 return;
sanghob35a6192015-04-01 13:05:26 -0700934 } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV4) {
Pier Ventre735b8c82016-12-02 08:16:05 -0800935 IPv4 ipv4Packet = (IPv4) ethernet.getPayload();
936 //ipHandler.addToPacketBuffer(ipv4Packet);
937 if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_ICMP) {
938 icmpHandler.processIcmp(ethernet, pkt.receivedFrom());
sanghob35a6192015-04-01 13:05:26 -0700939 } else {
Charles Chan50035632017-01-13 17:20:44 -0800940 // NOTE: We don't support IP learning at this moment so this
941 // is not necessary. Also it causes duplication of DHCP packets.
Pier Ventre968da122016-12-09 17:26:04 -0800942 // ipHandler.processPacketIn(ipv4Packet, pkt.receivedFrom());
sanghob35a6192015-04-01 13:05:26 -0700943 }
Pier Ventre10bd8d12016-11-26 21:05:22 -0800944 } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV6) {
945 IPv6 ipv6Packet = (IPv6) ethernet.getPayload();
Pier Ventre735b8c82016-12-02 08:16:05 -0800946 //ipHandler.addToPacketBuffer(ipv6Packet);
Pier Luigi7dad71c2017-02-01 13:50:04 -0800947 // We deal with the packet only if the packet is a ICMP6 ECHO/REPLY
Pier Ventre735b8c82016-12-02 08:16:05 -0800948 if (ipv6Packet.getNextHeader() == IPv6.PROTOCOL_ICMP6) {
949 ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload();
950 if (icmp6Packet.getIcmpType() == ICMP6.ECHO_REQUEST ||
951 icmp6Packet.getIcmpType() == ICMP6.ECHO_REPLY) {
952 icmpHandler.processIcmpv6(ethernet, pkt.receivedFrom());
953 } else {
Saurav Dasc88d4662017-05-15 15:34:25 -0700954 log.trace("Received ICMPv6 0x{} - not handled",
Charles Chan0ed44fb2017-03-13 13:10:30 -0700955 Integer.toHexString(icmp6Packet.getIcmpType() & 0xff));
Pier Ventre735b8c82016-12-02 08:16:05 -0800956 }
957 } else {
958 // NOTE: We don't support IP learning at this moment so this
959 // is not necessary. Also it causes duplication of DHCPv6 packets.
960 // ipHandler.processPacketIn(ipv6Packet, pkt.receivedFrom());
961 }
sanghob35a6192015-04-01 13:05:26 -0700962 }
963 }
964 }
965
966 private class InternalLinkListener implements LinkListener {
967 @Override
968 public void event(LinkEvent event) {
Charles Chanb1f8c762017-03-29 16:39:05 -0700969 if (event.type() == LinkEvent.Type.LINK_ADDED ||
970 event.type() == LinkEvent.Type.LINK_UPDATED ||
971 event.type() == LinkEvent.Type.LINK_REMOVED) {
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700972 log.debug("Event {} received from Link Service", event.type());
sanghob35a6192015-04-01 13:05:26 -0700973 scheduleEventHandlerIfNotScheduled(event);
974 }
975 }
976 }
977
978 private class InternalDeviceListener implements DeviceListener {
sanghob35a6192015-04-01 13:05:26 -0700979 @Override
980 public void event(DeviceEvent event) {
sanghob35a6192015-04-01 13:05:26 -0700981 switch (event.type()) {
982 case DEVICE_ADDED:
Saurav Das1a129a02016-11-18 15:21:57 -0800983 case PORT_UPDATED:
984 case PORT_ADDED:
sangho20eff1d2015-04-13 15:15:58 -0700985 case DEVICE_UPDATED:
986 case DEVICE_AVAILABILITY_CHANGED:
Saurav Dasc88d4662017-05-15 15:34:25 -0700987 log.trace("Event {} received from Device Service", event.type());
sanghob35a6192015-04-01 13:05:26 -0700988 scheduleEventHandlerIfNotScheduled(event);
989 break;
990 default:
991 }
992 }
993 }
994
Saurav Das4ce45962015-11-24 23:21:05 -0800995 @SuppressWarnings("rawtypes")
sanghob35a6192015-04-01 13:05:26 -0700996 private void scheduleEventHandlerIfNotScheduled(Event event) {
Charles Chan65238242017-06-22 18:03:14 -0700997 synchronized (THREAD_SCHED_LOCK) {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700998 eventQueue.add(event);
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700999 numOfEventsQueued++;
1000
1001 if ((numOfHandlerScheduled - numOfHandlerExecution) == 0) {
1002 //No pending scheduled event handling threads. So start a new one.
Srikanth Vavilapalli23181912015-05-04 09:48:09 -07001003 eventHandlerFuture = executorService
1004 .schedule(eventHandler, 100, TimeUnit.MILLISECONDS);
1005 numOfHandlerScheduled++;
1006 }
Jonathan Hartc19f7c12016-04-12 15:39:44 -07001007 log.trace("numOfEventsQueued {}, numOfEventHandlerScheduled {}",
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -07001008 numOfEventsQueued,
1009 numOfHandlerScheduled);
sanghob35a6192015-04-01 13:05:26 -07001010 }
sanghob35a6192015-04-01 13:05:26 -07001011 }
1012
1013 private class InternalEventHandler implements Runnable {
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -07001014 @Override
sanghob35a6192015-04-01 13:05:26 -07001015 public void run() {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -07001016 try {
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -07001017 while (true) {
Saurav Das4ce45962015-11-24 23:21:05 -08001018 @SuppressWarnings("rawtypes")
Charles Chan65238242017-06-22 18:03:14 -07001019 Event event;
1020 synchronized (THREAD_SCHED_LOCK) {
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -07001021 if (!eventQueue.isEmpty()) {
1022 event = eventQueue.poll();
1023 numOfEventsExecuted++;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -07001024 } else {
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -07001025 numOfHandlerExecution++;
1026 log.debug("numOfHandlerExecution {} numOfEventsExecuted {}",
1027 numOfHandlerExecution, numOfEventsExecuted);
1028 break;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -07001029 }
sangho20eff1d2015-04-13 15:15:58 -07001030 }
Charles Chanb1f8c762017-03-29 16:39:05 -07001031 if (event.type() == LinkEvent.Type.LINK_ADDED ||
1032 event.type() == LinkEvent.Type.LINK_UPDATED) {
Saurav Dasc88d4662017-05-15 15:34:25 -07001033 // Note: do not update seenLinks here, otherwise every
1034 // link, even one seen for the first time, will be appear
1035 // to be a previously seen link
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -07001036 processLinkAdded((Link) event.subject());
1037 } else if (event.type() == LinkEvent.Type.LINK_REMOVED) {
Pier Ventre2c515312016-09-13 21:33:40 -07001038 Link linkRemoved = (Link) event.subject();
Saurav Dasc88d4662017-05-15 15:34:25 -07001039 if (linkRemoved.type() == Link.Type.DIRECT) {
1040 updateSeenLink(linkRemoved, false);
1041 }
1042 // device availability check helps to ensure that
1043 // multiple link-removed events are actually treated as a
1044 // single switch removed event. purgeSeenLink is necessary
1045 // so we do rerouting (instead of rehashing) when switch
1046 // comes back.
Pier Ventre2c515312016-09-13 21:33:40 -07001047 if (linkRemoved.src().elementId() instanceof DeviceId &&
1048 !deviceService.isAvailable(linkRemoved.src().deviceId())) {
Saurav Dasc88d4662017-05-15 15:34:25 -07001049 purgeSeenLink(linkRemoved);
Pier Ventre2c515312016-09-13 21:33:40 -07001050 continue;
1051 }
1052 if (linkRemoved.dst().elementId() instanceof DeviceId &&
1053 !deviceService.isAvailable(linkRemoved.dst().deviceId())) {
Saurav Dasc88d4662017-05-15 15:34:25 -07001054 purgeSeenLink(linkRemoved);
Pier Ventre2c515312016-09-13 21:33:40 -07001055 continue;
1056 }
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -07001057 processLinkRemoved((Link) event.subject());
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -07001058 } else if (event.type() == DeviceEvent.Type.DEVICE_ADDED ||
1059 event.type() == DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED ||
1060 event.type() == DeviceEvent.Type.DEVICE_UPDATED) {
Saurav Das423fe2b2015-12-04 10:52:59 -08001061 DeviceId deviceId = ((Device) event.subject()).id();
1062 if (deviceService.isAvailable(deviceId)) {
Saurav Das837e0bb2015-10-30 17:45:38 -07001063 log.info("Processing device event {} for available device {}",
1064 event.type(), ((Device) event.subject()).id());
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -07001065 processDeviceAdded((Device) event.subject());
Saurav Das80980c72016-03-23 11:22:49 -07001066 } else {
1067 log.info("Processing device event {} for unavailable device {}",
1068 event.type(), ((Device) event.subject()).id());
1069 processDeviceRemoved((Device) event.subject());
1070 }
Saurav Das1a129a02016-11-18 15:21:57 -08001071 } else if (event.type() == DeviceEvent.Type.PORT_ADDED) {
Saurav Dasd2fded02016-12-02 15:43:47 -08001072 // typically these calls come when device is added first time
1073 // so port filtering rules are handled at the device_added event.
1074 // port added calls represent all ports on the device,
1075 // enabled or not.
Saurav Dasc88d4662017-05-15 15:34:25 -07001076 log.trace("** PORT ADDED {}/{} -> {}",
Saurav Dasd2fded02016-12-02 15:43:47 -08001077 ((DeviceEvent) event).subject().id(),
1078 ((DeviceEvent) event).port().number(),
1079 event.type());
Saurav Das1a129a02016-11-18 15:21:57 -08001080 } else if (event.type() == DeviceEvent.Type.PORT_UPDATED) {
Saurav Dasd2fded02016-12-02 15:43:47 -08001081 // these calls happen for every subsequent event
1082 // ports enabled, disabled, switch goes away, comes back
Saurav Das1a129a02016-11-18 15:21:57 -08001083 log.info("** PORT UPDATED {}/{} -> {}",
1084 event.subject(),
1085 ((DeviceEvent) event).port(),
1086 event.type());
1087 processPortUpdated(((Device) event.subject()),
1088 ((DeviceEvent) event).port());
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -07001089 } else {
1090 log.warn("Unhandled event type: {}", event.type());
1091 }
sanghob35a6192015-04-01 13:05:26 -07001092 }
Srikanth Vavilapalli23181912015-05-04 09:48:09 -07001093 } catch (Exception e) {
1094 log.error("SegmentRouting event handler "
1095 + "thread thrown an exception: {}", e);
sanghob35a6192015-04-01 13:05:26 -07001096 }
sanghob35a6192015-04-01 13:05:26 -07001097 }
1098 }
1099
sanghob35a6192015-04-01 13:05:26 -07001100 private void processLinkAdded(Link link) {
Saurav Dasb5c236e2016-06-07 10:08:06 -07001101 log.info("** LINK ADDED {}", link.toString());
Charles Chan0b4e6182015-11-03 10:42:14 -08001102 if (!deviceConfiguration.isConfigured(link.src().deviceId())) {
Saurav Das7bcbe702017-06-13 15:35:54 -07001103 log.warn("Source device of this link is not configured..not processing");
Charles Chan0b4e6182015-11-03 10:42:14 -08001104 return;
1105 }
Saurav Dasc88d4662017-05-15 15:34:25 -07001106 if (link.type() != Link.Type.DIRECT) {
1107 // NOTE: A DIRECT link might be transiently marked as INDIRECT
1108 // if BDDP is received before LLDP. We can safely ignore that
1109 // until the LLDP is received and the link is marked as DIRECT.
1110 log.info("Ignore link {}->{}. Link type is {} instead of DIRECT.",
1111 link.src(), link.dst(), link.type());
1112 return;
1113 }
1114
1115 //Irrespective of whether the local is a MASTER or not for this device,
1116 //create group handler instance and push default TTP flow rules if needed,
1117 //as in a multi-instance setup, instances can initiate groups for any device.
Srikanth Vavilapalli23181912015-05-04 09:48:09 -07001118 DefaultGroupHandler groupHandler = groupHandlerMap.get(link.src()
1119 .deviceId());
1120 if (groupHandler != null) {
Saurav Dasc88d4662017-05-15 15:34:25 -07001121 groupHandler.portUpForLink(link);
Srikanth Vavilapalli23181912015-05-04 09:48:09 -07001122 } else {
1123 Device device = deviceService.getDevice(link.src().deviceId());
1124 if (device != null) {
1125 log.warn("processLinkAdded: Link Added "
1126 + "Notification without Device Added "
1127 + "event, still handling it");
1128 processDeviceAdded(device);
1129 groupHandler = groupHandlerMap.get(link.src()
1130 .deviceId());
Saurav Dasc88d4662017-05-15 15:34:25 -07001131 groupHandler.portUpForLink(link);
sanghob35a6192015-04-01 13:05:26 -07001132 }
1133 }
Srikanth Vavilapalli23181912015-05-04 09:48:09 -07001134
Saurav Das7bcbe702017-06-13 15:35:54 -07001135 /*// process link only if it is bidirectional
1136 if (!isBidirectional(link)) {
1137 log.debug("Link not bidirectional.. waiting for other direction "
1138 + "src {} --> dst {} ", link.dst(), link.src());
1139 // note that if we are not processing for routing, it should at least
1140 // be considered a seen-link
1141 updateSeenLink(link, true);
1142 return;
1143 }
1144 TO DO this ensure that rehash is still done correctly even if link is
1145 not processed for rerouting - perhaps rehash in both directions when
1146 it ultimately becomes bidi?
1147 */
1148
1149 log.debug("Starting optimized route population process for link "
1150 + "{} --> {}", link.src(), link.dst());
Saurav Dasc88d4662017-05-15 15:34:25 -07001151 boolean seenBefore = isSeenLink(link);
1152 defaultRoutingHandler.populateRoutingRulesForLinkStatusChange(null, link, null);
Saurav Das7bcbe702017-06-13 15:35:54 -07001153
1154 // It's possible that linkUp causes no route-path change as ECMP graph does
1155 // not change if the link is a parallel link (same src-dst as another link.
1156 // However we still need to update ECMP hash groups to include new buckets
1157 // for the link that has come up.
Saurav Dasc88d4662017-05-15 15:34:25 -07001158 if (mastershipService.isLocalMaster(link.src().deviceId())) {
Saurav Das7bcbe702017-06-13 15:35:54 -07001159 if (!seenBefore && isParallelLink(link)) {
Saurav Dasc88d4662017-05-15 15:34:25 -07001160 // if link seen first time, we need to ensure hash-groups have all ports
Saurav Das7bcbe702017-06-13 15:35:54 -07001161 log.debug("Attempting retryHash for paralled first-time link {}", link);
Saurav Dasc88d4662017-05-15 15:34:25 -07001162 groupHandler.retryHash(link, false, true);
1163 } else {
1164 //seen before-link
1165 if (isParallelLink(link)) {
Saurav Das7bcbe702017-06-13 15:35:54 -07001166 log.debug("Attempting retryHash for paralled seen-before "
1167 + "link {}", link);
Saurav Dasc88d4662017-05-15 15:34:25 -07001168 groupHandler.retryHash(link, false, false);
1169 }
1170 }
1171 }
Charles Chan2199c302016-04-23 17:36:10 -07001172
1173 mcastHandler.init();
sanghob35a6192015-04-01 13:05:26 -07001174 }
1175
1176 private void processLinkRemoved(Link link) {
Saurav Dasb5c236e2016-06-07 10:08:06 -07001177 log.info("** LINK REMOVED {}", link.toString());
Saurav Dasc88d4662017-05-15 15:34:25 -07001178 defaultRoutingHandler.populateRoutingRulesForLinkStatusChange(link, null, null);
1179
1180 // update local groupHandler stores
sangho834e4b02015-05-01 09:38:25 -07001181 DefaultGroupHandler groupHandler = groupHandlerMap.get(link.src().deviceId());
1182 if (groupHandler != null) {
Saurav Dasc88d4662017-05-15 15:34:25 -07001183 if (mastershipService.isLocalMaster(link.src().deviceId()) &&
1184 isParallelLink(link)) {
1185 groupHandler.retryHash(link, true, false);
1186 }
1187 // ensure local stores are updated
1188 groupHandler.portDown(link.src().port());
1189 } else {
1190 log.warn("group handler not found for dev:{} when removing link: {}",
1191 link.src().deviceId(), link);
sangho834e4b02015-05-01 09:38:25 -07001192 }
Charles Chan2199c302016-04-23 17:36:10 -07001193
1194 mcastHandler.processLinkDown(link);
sanghob35a6192015-04-01 13:05:26 -07001195 }
1196
1197 private void processDeviceAdded(Device device) {
Saurav Dasb5c236e2016-06-07 10:08:06 -07001198 log.info("** DEVICE ADDED with ID {}", device.id());
Charles Chan91ccbf72017-06-27 18:48:32 -07001199
1200 // NOTE: Punt ARP/NDP even when the device is not configured.
1201 // Host learning without network config is required for CORD config generator.
1202 routingRulePopulator.populateIpPunts(device.id());
1203 routingRulePopulator.populateArpNdpPunts(device.id());
1204
Charles Chan0b4e6182015-11-03 10:42:14 -08001205 if (deviceConfiguration == null || !deviceConfiguration.isConfigured(device.id())) {
Saurav Das7bcbe702017-06-13 15:35:54 -07001206 log.warn("Device configuration unavailable. Device {} will be "
1207 + "processed after configuration.", device.id());
Saurav Das2857f382015-11-03 14:39:27 -08001208 return;
1209 }
Charles Chan2199c302016-04-23 17:36:10 -07001210 processDeviceAddedInternal(device.id());
1211 }
1212
1213 private void processDeviceAddedInternal(DeviceId deviceId) {
Saurav Das837e0bb2015-10-30 17:45:38 -07001214 // Irrespective of whether the local is a MASTER or not for this device,
1215 // we need to create a SR-group-handler instance. This is because in a
1216 // multi-instance setup, any instance can initiate forwarding/next-objectives
1217 // for any switch (even if this instance is a SLAVE or not even connected
1218 // to the switch). To handle this, a default-group-handler instance is necessary
1219 // per switch.
Charles Chan2199c302016-04-23 17:36:10 -07001220 log.debug("Current groupHandlerMap devs: {}", groupHandlerMap.keySet());
1221 if (groupHandlerMap.get(deviceId) == null) {
Charles Chan0b4e6182015-11-03 10:42:14 -08001222 DefaultGroupHandler groupHandler;
1223 try {
1224 groupHandler = DefaultGroupHandler.
Charles Chan2199c302016-04-23 17:36:10 -07001225 createGroupHandler(deviceId,
1226 appId,
1227 deviceConfiguration,
1228 linkService,
1229 flowObjectiveService,
1230 this);
Charles Chan0b4e6182015-11-03 10:42:14 -08001231 } catch (DeviceConfigNotFoundException e) {
1232 log.warn(e.getMessage() + " Aborting processDeviceAdded.");
1233 return;
1234 }
Charles Chan2199c302016-04-23 17:36:10 -07001235 log.debug("updating groupHandlerMap with new config for device: {}",
1236 deviceId);
1237 groupHandlerMap.put(deviceId, groupHandler);
Saurav Das2857f382015-11-03 14:39:27 -08001238 }
Saurav Dasb5c236e2016-06-07 10:08:06 -07001239
Charles Chan2199c302016-04-23 17:36:10 -07001240 if (mastershipService.isLocalMaster(deviceId)) {
Saurav Das018605f2017-02-18 14:05:44 -08001241 defaultRoutingHandler.populatePortAddressingRules(deviceId);
Charles Chan03a73e02016-10-24 14:52:01 -07001242 hostHandler.init(deviceId);
Charles Chanfc5c7802016-05-17 13:13:55 -07001243 xConnectHandler.init(deviceId);
Charles Chan2199c302016-04-23 17:36:10 -07001244 DefaultGroupHandler groupHandler = groupHandlerMap.get(deviceId);
Charles Chan59cc16d2017-02-02 16:20:42 -08001245 groupHandler.createGroupsFromVlanConfig();
Charles Chan2199c302016-04-23 17:36:10 -07001246 routingRulePopulator.populateSubnetBroadcastRule(deviceId);
Charles Chanc42e84e2015-10-20 16:24:19 -07001247 }
Charles Chan5270ed02016-01-30 23:22:37 -08001248
Charles Chan03a73e02016-10-24 14:52:01 -07001249 appCfgHandler.init(deviceId);
1250 routeHandler.init(deviceId);
sanghob35a6192015-04-01 13:05:26 -07001251 }
1252
Saurav Das80980c72016-03-23 11:22:49 -07001253 private void processDeviceRemoved(Device device) {
Saurav Das7bcbe702017-06-13 15:35:54 -07001254 dsNextObjStore.entrySet().stream()
Saurav Das80980c72016-03-23 11:22:49 -07001255 .filter(entry -> entry.getKey().deviceId().equals(device.id()))
1256 .forEach(entry -> {
Saurav Das7bcbe702017-06-13 15:35:54 -07001257 dsNextObjStore.remove(entry.getKey());
Saurav Das80980c72016-03-23 11:22:49 -07001258 });
Charles Chan59cc16d2017-02-02 16:20:42 -08001259 vlanNextObjStore.entrySet().stream()
Saurav Das80980c72016-03-23 11:22:49 -07001260 .filter(entry -> entry.getKey().deviceId().equals(device.id()))
Charles Chan65238242017-06-22 18:03:14 -07001261 .forEach(entry -> vlanNextObjStore.remove(entry.getKey()));
Saurav Das80980c72016-03-23 11:22:49 -07001262 portNextObjStore.entrySet().stream()
1263 .filter(entry -> entry.getKey().deviceId().equals(device.id()))
Charles Chan65238242017-06-22 18:03:14 -07001264 .forEach(entry -> portNextObjStore.remove(entry.getKey()));
Charles Chaned3742352017-06-15 00:44:51 -07001265
1266 seenLinks.keySet().removeIf(key -> key.src().deviceId().equals(device.id()) ||
1267 key.dst().deviceId().equals(device.id()));
1268
Saurav Dasceccf242017-08-03 18:30:35 -07001269 DefaultGroupHandler gh = groupHandlerMap.remove(device.id());
1270 if (gh != null) {
1271 gh.shutdown();
1272 }
Saurav Das80980c72016-03-23 11:22:49 -07001273 defaultRoutingHandler.purgeEcmpGraph(device.id());
Saurav Dasc88d4662017-05-15 15:34:25 -07001274 // Note that a switch going down is associated with all of its links
1275 // going down as well, but it is treated as a single switch down event
1276 // while the link-downs are ignored.
1277 defaultRoutingHandler
1278 .populateRoutingRulesForLinkStatusChange(null, null, device.id());
Charles Chan2199c302016-04-23 17:36:10 -07001279 mcastHandler.removeDevice(device.id());
Charles Chanfc5c7802016-05-17 13:13:55 -07001280 xConnectHandler.removeDevice(device.id());
Saurav Das80980c72016-03-23 11:22:49 -07001281 }
1282
Saurav Das1a129a02016-11-18 15:21:57 -08001283 private void processPortUpdated(Device device, Port port) {
1284 if (deviceConfiguration == null || !deviceConfiguration.isConfigured(device.id())) {
1285 log.warn("Device configuration uploading. Not handling port event for"
1286 + "dev: {} port: {}", device.id(), port.number());
1287 return;
1288 }
Saurav Das018605f2017-02-18 14:05:44 -08001289
1290 if (!mastershipService.isLocalMaster(device.id())) {
1291 log.debug("Not master for dev:{} .. not handling port updated event"
1292 + "for port {}", device.id(), port.number());
1293 return;
1294 }
1295
1296 // first we handle filtering rules associated with the port
1297 if (port.isEnabled()) {
1298 log.info("Switchport {}/{} enabled..programming filters",
1299 device.id(), port.number());
Charles Chan7e4f8192017-02-26 22:59:35 -08001300 routingRulePopulator.processSinglePortFilters(device.id(), port.number(), true);
Saurav Das018605f2017-02-18 14:05:44 -08001301 } else {
1302 log.info("Switchport {}/{} disabled..removing filters",
1303 device.id(), port.number());
Charles Chan7e4f8192017-02-26 22:59:35 -08001304 routingRulePopulator.processSinglePortFilters(device.id(), port.number(), false);
Saurav Das018605f2017-02-18 14:05:44 -08001305 }
Saurav Das1a129a02016-11-18 15:21:57 -08001306
1307 // portUpdated calls are for ports that have gone down or up. For switch
1308 // to switch ports, link-events should take care of any re-routing or
1309 // group editing necessary for port up/down. Here we only process edge ports
1310 // that are already configured.
Saurav Dasb0ae6ee2017-03-04 16:08:47 -08001311 ConnectPoint cp = new ConnectPoint(device.id(), port.number());
1312 VlanId untaggedVlan = getUntaggedVlanId(cp);
1313 VlanId nativeVlan = getNativeVlanId(cp);
1314 Set<VlanId> taggedVlans = getTaggedVlanId(cp);
Charles Chan59cc16d2017-02-02 16:20:42 -08001315
Saurav Dasb0ae6ee2017-03-04 16:08:47 -08001316 if (untaggedVlan == null && nativeVlan == null && taggedVlans.isEmpty()) {
Saurav Dasc88d4662017-05-15 15:34:25 -07001317 log.debug("Not handling port updated event for non-edge port (unconfigured) "
Saurav Das1a129a02016-11-18 15:21:57 -08001318 + "dev/port: {}/{}", device.id(), port.number());
1319 return;
1320 }
Saurav Dasb0ae6ee2017-03-04 16:08:47 -08001321 if (untaggedVlan != null) {
1322 processEdgePort(device, port, untaggedVlan, true);
1323 }
1324 if (nativeVlan != null) {
1325 processEdgePort(device, port, nativeVlan, true);
1326 }
1327 if (!taggedVlans.isEmpty()) {
1328 taggedVlans.forEach(tag -> processEdgePort(device, port, tag, false));
1329 }
Saurav Das1a129a02016-11-18 15:21:57 -08001330 }
1331
Saurav Dasb0ae6ee2017-03-04 16:08:47 -08001332 private void processEdgePort(Device device, Port port, VlanId vlanId,
1333 boolean popVlan) {
Saurav Das1a129a02016-11-18 15:21:57 -08001334 boolean portUp = port.isEnabled();
1335 if (portUp) {
Saurav Dasb0ae6ee2017-03-04 16:08:47 -08001336 log.info("Device:EdgePort {}:{} is enabled in vlan: {}", device.id(),
Charles Chan59cc16d2017-02-02 16:20:42 -08001337 port.number(), vlanId);
Saurav Das1a129a02016-11-18 15:21:57 -08001338 } else {
Saurav Dasb0ae6ee2017-03-04 16:08:47 -08001339 log.info("Device:EdgePort {}:{} is disabled in vlan: {}", device.id(),
Charles Chan59cc16d2017-02-02 16:20:42 -08001340 port.number(), vlanId);
Saurav Das1a129a02016-11-18 15:21:57 -08001341 }
1342
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -07001343 DefaultGroupHandler groupHandler = groupHandlerMap.get(device.id());
sanghob35a6192015-04-01 13:05:26 -07001344 if (groupHandler != null) {
Saurav Dasb0ae6ee2017-03-04 16:08:47 -08001345 groupHandler.processEdgePort(port.number(), vlanId, popVlan, portUp);
Saurav Das1a129a02016-11-18 15:21:57 -08001346 } else {
1347 log.warn("Group handler not found for dev:{}. Not handling edge port"
1348 + " {} event for port:{}", device.id(),
1349 (portUp) ? "UP" : "DOWN", port.number());
sanghob35a6192015-04-01 13:05:26 -07001350 }
1351 }
sangho1e575652015-05-14 00:39:53 -07001352
Pier Ventre10bd8d12016-11-26 21:05:22 -08001353 /**
1354 * Registers the given connect point with the NRS, this is necessary
1355 * to receive the NDP and ARP packets from the NRS.
1356 *
1357 * @param portToRegister connect point to register
1358 */
1359 public void registerConnectPoint(ConnectPoint portToRegister) {
Charles Chan0aa674e2017-02-23 15:44:08 -08001360 neighbourResolutionService.registerNeighbourHandler(
Pier Ventre10bd8d12016-11-26 21:05:22 -08001361 portToRegister,
1362 neighbourHandler,
1363 appId
1364 );
1365 }
1366
Charles Chand6832882015-10-05 17:50:33 -07001367 private class InternalConfigListener implements NetworkConfigListener {
Saurav Das7bcbe702017-06-13 15:35:54 -07001368 private static final long PROGRAM_DELAY = 2;
Charles Chan2c15aca2016-11-09 20:51:44 -08001369 SegmentRoutingManager srManager;
Charles Chan4636be02015-10-07 14:21:45 -07001370
Charles Chane849c192016-01-11 18:28:54 -08001371 /**
1372 * Constructs the internal network config listener.
1373 *
Charles Chan2c15aca2016-11-09 20:51:44 -08001374 * @param srManager segment routing manager
Charles Chane849c192016-01-11 18:28:54 -08001375 */
Charles Chan65238242017-06-22 18:03:14 -07001376 InternalConfigListener(SegmentRoutingManager srManager) {
Charles Chan2c15aca2016-11-09 20:51:44 -08001377 this.srManager = srManager;
Charles Chan4636be02015-10-07 14:21:45 -07001378 }
1379
Charles Chane849c192016-01-11 18:28:54 -08001380 /**
1381 * Reads network config and initializes related data structure accordingly.
1382 */
Charles Chan4636be02015-10-07 14:21:45 -07001383 public void configureNetwork() {
Saurav Das7bcbe702017-06-13 15:35:54 -07001384 if (deviceConfiguration == null) {
1385 deviceConfiguration = new DeviceConfiguration(srManager);
1386 } else {
1387 deviceConfiguration.updateConfig();
1388 }
Charles Chan4636be02015-10-07 14:21:45 -07001389
Charles Chan2c15aca2016-11-09 20:51:44 -08001390 arpHandler = new ArpHandler(srManager);
1391 icmpHandler = new IcmpHandler(srManager);
1392 ipHandler = new IpHandler(srManager);
1393 routingRulePopulator = new RoutingRulePopulator(srManager);
1394 defaultRoutingHandler = new DefaultRoutingHandler(srManager);
Charles Chan4636be02015-10-07 14:21:45 -07001395
1396 tunnelHandler = new TunnelHandler(linkService, deviceConfiguration,
1397 groupHandlerMap, tunnelStore);
1398 policyHandler = new PolicyHandler(appId, deviceConfiguration,
1399 flowObjectiveService,
1400 tunnelHandler, policyStore);
Saurav Das7bcbe702017-06-13 15:35:54 -07001401 // add a small delay to absorb multiple network config added notifications
1402 if (!programmingScheduled.get()) {
1403 programmingScheduled.set(true);
1404 executorService.schedule(new ConfigChange(), PROGRAM_DELAY,
1405 TimeUnit.SECONDS);
Charles Chan4636be02015-10-07 14:21:45 -07001406 }
Charles Chan2199c302016-04-23 17:36:10 -07001407 mcastHandler.init();
Charles Chan4636be02015-10-07 14:21:45 -07001408 }
1409
Charles Chand6832882015-10-05 17:50:33 -07001410 @Override
1411 public void event(NetworkConfigEvent event) {
Charles Chan5270ed02016-01-30 23:22:37 -08001412 // TODO move this part to NetworkConfigEventHandler
1413 if (event.configClass().equals(SegmentRoutingDeviceConfig.class)) {
1414 switch (event.type()) {
1415 case CONFIG_ADDED:
Charles Chan278ce832017-06-26 15:25:09 -07001416 log.info("Segment Routing Device Config added for {}", event.subject());
Charles Chan5270ed02016-01-30 23:22:37 -08001417 configureNetwork();
1418 break;
1419 case CONFIG_UPDATED:
Charles Chan278ce832017-06-26 15:25:09 -07001420 log.info("Segment Routing Config updated for {}", event.subject());
1421 // TODO support dynamic configuration
1422 break;
1423 default:
1424 break;
1425 }
1426 } else if (event.configClass().equals(InterfaceConfig.class)) {
1427 switch (event.type()) {
1428 case CONFIG_ADDED:
1429 log.info("Interface Config added for {}", event.subject());
1430 configureNetwork();
1431 break;
1432 case CONFIG_UPDATED:
1433 log.info("Interface Config updated for {}", event.subject());
Charles Chan5270ed02016-01-30 23:22:37 -08001434 // TODO support dynamic configuration
1435 break;
1436 default:
1437 break;
Charles Chanb8e10c82015-10-14 11:24:40 -07001438 }
Charles Chan5270ed02016-01-30 23:22:37 -08001439 } else if (event.configClass().equals(SegmentRoutingAppConfig.class)) {
Charles Chanfc5c7802016-05-17 13:13:55 -07001440 checkState(appCfgHandler != null, "NetworkConfigEventHandler is not initialized");
Charles Chan5270ed02016-01-30 23:22:37 -08001441 switch (event.type()) {
1442 case CONFIG_ADDED:
Charles Chanfc5c7802016-05-17 13:13:55 -07001443 appCfgHandler.processAppConfigAdded(event);
Charles Chan5270ed02016-01-30 23:22:37 -08001444 break;
1445 case CONFIG_UPDATED:
Charles Chanfc5c7802016-05-17 13:13:55 -07001446 appCfgHandler.processAppConfigUpdated(event);
Charles Chan5270ed02016-01-30 23:22:37 -08001447 break;
1448 case CONFIG_REMOVED:
Charles Chanfc5c7802016-05-17 13:13:55 -07001449 appCfgHandler.processAppConfigRemoved(event);
1450 break;
1451 default:
1452 break;
1453 }
Charles Chan03a73e02016-10-24 14:52:01 -07001454 configureNetwork();
Charles Chanfc5c7802016-05-17 13:13:55 -07001455 } else if (event.configClass().equals(XConnectConfig.class)) {
1456 checkState(xConnectHandler != null, "XConnectHandler is not initialized");
1457 switch (event.type()) {
1458 case CONFIG_ADDED:
1459 xConnectHandler.processXConnectConfigAdded(event);
1460 break;
1461 case CONFIG_UPDATED:
1462 xConnectHandler.processXConnectConfigUpdated(event);
1463 break;
1464 case CONFIG_REMOVED:
1465 xConnectHandler.processXConnectConfigRemoved(event);
Charles Chan5270ed02016-01-30 23:22:37 -08001466 break;
1467 default:
1468 break;
Charles Chanb8e10c82015-10-14 11:24:40 -07001469 }
Pier Ventref34966c2016-11-07 16:21:04 -08001470 } else if (event.configClass().equals(PwaasConfig.class)) {
1471 checkState(l2TunnelHandler != null, "L2TunnelHandler is not initialized");
1472 switch (event.type()) {
1473 case CONFIG_ADDED:
1474 l2TunnelHandler.processPwaasConfigAdded(event);
1475 break;
1476 case CONFIG_UPDATED:
1477 l2TunnelHandler.processPwaasConfigUpdated(event);
1478 break;
1479 case CONFIG_REMOVED:
1480 l2TunnelHandler.processPwaasConfigRemoved(event);
1481 break;
1482 default:
1483 break;
1484 }
Charles Chand6832882015-10-05 17:50:33 -07001485 }
1486 }
Saurav Das7bcbe702017-06-13 15:35:54 -07001487
1488 private final class ConfigChange implements Runnable {
1489 @Override
1490 public void run() {
1491 programmingScheduled.set(false);
1492 for (Device device : deviceService.getDevices()) {
1493 processDeviceAdded(device);
1494 }
1495 defaultRoutingHandler.startPopulationProcess();
1496 }
1497 }
Charles Chand6832882015-10-05 17:50:33 -07001498 }
Charles Chan68aa62d2015-11-09 16:37:23 -08001499
1500 private class InternalHostListener implements HostListener {
Charles Chan68aa62d2015-11-09 16:37:23 -08001501 @Override
1502 public void event(HostEvent event) {
Charles Chan68aa62d2015-11-09 16:37:23 -08001503 switch (event.type()) {
1504 case HOST_ADDED:
Charles Chand2990362016-04-18 13:44:03 -07001505 hostHandler.processHostAddedEvent(event);
Charles Chan68aa62d2015-11-09 16:37:23 -08001506 break;
1507 case HOST_MOVED:
Charles Chand2990362016-04-18 13:44:03 -07001508 hostHandler.processHostMovedEvent(event);
Charles Chan68aa62d2015-11-09 16:37:23 -08001509 break;
1510 case HOST_REMOVED:
Charles Chanf9a52702017-06-16 15:19:24 -07001511 hostHandler.processHostRemovedEvent(event);
Charles Chan68aa62d2015-11-09 16:37:23 -08001512 break;
1513 case HOST_UPDATED:
Charles Chand2990362016-04-18 13:44:03 -07001514 hostHandler.processHostUpdatedEvent(event);
Charles Chan68aa62d2015-11-09 16:37:23 -08001515 break;
1516 default:
1517 log.warn("Unsupported host event type: {}", event.type());
1518 break;
1519 }
1520 }
1521 }
1522
Charles Chand55e84d2016-03-30 17:54:24 -07001523 private class InternalMcastListener implements McastListener {
1524 @Override
1525 public void event(McastEvent event) {
1526 switch (event.type()) {
1527 case SOURCE_ADDED:
Charles Chand2990362016-04-18 13:44:03 -07001528 mcastHandler.processSourceAdded(event);
Charles Chand55e84d2016-03-30 17:54:24 -07001529 break;
1530 case SINK_ADDED:
Charles Chand2990362016-04-18 13:44:03 -07001531 mcastHandler.processSinkAdded(event);
Charles Chand55e84d2016-03-30 17:54:24 -07001532 break;
1533 case SINK_REMOVED:
Charles Chand2990362016-04-18 13:44:03 -07001534 mcastHandler.processSinkRemoved(event);
Charles Chand55e84d2016-03-30 17:54:24 -07001535 break;
1536 case ROUTE_ADDED:
1537 case ROUTE_REMOVED:
1538 default:
1539 break;
1540 }
1541 }
1542 }
Charles Chan35fd1a72016-06-13 18:54:31 -07001543
Charles Chan03a73e02016-10-24 14:52:01 -07001544 private class InternalRouteEventListener implements RouteListener {
1545 @Override
1546 public void event(RouteEvent event) {
1547 switch (event.type()) {
1548 case ROUTE_ADDED:
1549 routeHandler.processRouteAdded(event);
1550 break;
1551 case ROUTE_UPDATED:
1552 routeHandler.processRouteUpdated(event);
1553 break;
1554 case ROUTE_REMOVED:
1555 routeHandler.processRouteRemoved(event);
1556 break;
1557 default:
1558 break;
1559 }
1560 }
1561 }
Saurav Dasc88d4662017-05-15 15:34:25 -07001562
sanghob35a6192015-04-01 13:05:26 -07001563}