blob: 4fc7b723198bbcbd401417bef1a4d103afec8864 [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
Ray Milkey6c1f0f02017-08-15 11:02:29 -070018import java.util.List;
19import java.util.Map;
20import java.util.Map.Entry;
21import java.util.Optional;
22import java.util.Set;
23import java.util.concurrent.ConcurrentHashMap;
24import java.util.concurrent.ConcurrentLinkedQueue;
25import java.util.concurrent.Executors;
26import java.util.concurrent.ScheduledExecutorService;
27import java.util.concurrent.ScheduledFuture;
28import java.util.concurrent.TimeUnit;
29import java.util.concurrent.atomic.AtomicBoolean;
30import java.util.stream.Collectors;
31
sanghob35a6192015-04-01 13:05:26 -070032import org.apache.felix.scr.annotations.Activate;
33import org.apache.felix.scr.annotations.Component;
34import org.apache.felix.scr.annotations.Deactivate;
35import org.apache.felix.scr.annotations.Reference;
36import org.apache.felix.scr.annotations.ReferenceCardinality;
sangho1e575652015-05-14 00:39:53 -070037import org.apache.felix.scr.annotations.Service;
sanghob35a6192015-04-01 13:05:26 -070038import org.onlab.packet.Ethernet;
Pier Ventre735b8c82016-12-02 08:16:05 -080039import org.onlab.packet.ICMP6;
Charles Chanc42e84e2015-10-20 16:24:19 -070040import org.onlab.packet.IPv4;
Pier Ventre10bd8d12016-11-26 21:05:22 -080041import org.onlab.packet.IPv6;
Charles Chanc42e84e2015-10-20 16:24:19 -070042import org.onlab.packet.IpPrefix;
Jonathan Hartc19f7c12016-04-12 15:39:44 -070043import org.onlab.packet.VlanId;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -070044import org.onlab.util.KryoNamespace;
Saurav Das80980c72016-03-23 11:22:49 -070045import org.onosproject.cfg.ComponentConfigService;
sanghob35a6192015-04-01 13:05:26 -070046import org.onosproject.core.ApplicationId;
47import org.onosproject.core.CoreService;
48import org.onosproject.event.Event;
Jonathan Hartc19f7c12016-04-12 15:39:44 -070049import org.onosproject.mastership.MastershipService;
Pier Ventre10bd8d12016-11-26 21:05:22 -080050import org.onosproject.net.ConnectPoint;
Jonathan Hartc19f7c12016-04-12 15:39:44 -070051import org.onosproject.net.Device;
52import org.onosproject.net.DeviceId;
53import org.onosproject.net.Link;
54import org.onosproject.net.Port;
Charles Chan68aa62d2015-11-09 16:37:23 -080055import org.onosproject.net.PortNumber;
Charles Chand6832882015-10-05 17:50:33 -070056import org.onosproject.net.config.ConfigFactory;
57import org.onosproject.net.config.NetworkConfigEvent;
Charles Chand6832882015-10-05 17:50:33 -070058import org.onosproject.net.config.NetworkConfigListener;
Jonathan Hartc19f7c12016-04-12 15:39:44 -070059import org.onosproject.net.config.NetworkConfigRegistry;
Ray Milkey6c1f0f02017-08-15 11:02:29 -070060import org.onosproject.net.config.basics.InterfaceConfig;
61import org.onosproject.net.config.basics.McastConfig;
Charles Chand6832882015-10-05 17:50:33 -070062import org.onosproject.net.config.basics.SubjectFactories;
Jonathan Hartc19f7c12016-04-12 15:39:44 -070063import org.onosproject.net.device.DeviceEvent;
64import org.onosproject.net.device.DeviceListener;
65import org.onosproject.net.device.DeviceService;
Charles Chan68aa62d2015-11-09 16:37:23 -080066import org.onosproject.net.flow.TrafficSelector;
67import org.onosproject.net.flow.TrafficTreatment;
Jonathan Hartc19f7c12016-04-12 15:39:44 -070068import org.onosproject.net.flowobjective.FlowObjectiveService;
Charles Chan68aa62d2015-11-09 16:37:23 -080069import org.onosproject.net.host.HostEvent;
70import org.onosproject.net.host.HostListener;
Pier Ventre10bd8d12016-11-26 21:05:22 -080071import org.onosproject.net.host.HostService;
Ray Milkey6c1f0f02017-08-15 11:02:29 -070072import org.onosproject.net.intf.Interface;
73import org.onosproject.net.intf.InterfaceService;
Pier Ventre10bd8d12016-11-26 21:05:22 -080074import org.onosproject.net.link.LinkEvent;
75import org.onosproject.net.link.LinkListener;
76import org.onosproject.net.link.LinkService;
Charles Chand55e84d2016-03-30 17:54:24 -070077import org.onosproject.net.mcast.McastEvent;
78import org.onosproject.net.mcast.McastListener;
79import org.onosproject.net.mcast.MulticastRouteService;
Ray Milkey6c1f0f02017-08-15 11:02:29 -070080import org.onosproject.net.neighbour.NeighbourResolutionService;
Pier Ventre10bd8d12016-11-26 21:05:22 -080081import org.onosproject.net.packet.InboundPacket;
82import org.onosproject.net.packet.PacketContext;
83import org.onosproject.net.packet.PacketProcessor;
84import org.onosproject.net.packet.PacketService;
Pier Ventre42287df2016-11-09 14:17:26 -080085import org.onosproject.net.topology.PathService;
Charles Chand55e84d2016-03-30 17:54:24 -070086import org.onosproject.net.topology.TopologyService;
Ray Milkey6c1f0f02017-08-15 11:02:29 -070087import org.onosproject.routeservice.RouteEvent;
88import org.onosproject.routeservice.RouteListener;
89import org.onosproject.routeservice.RouteService;
Charles Chand55e84d2016-03-30 17:54:24 -070090import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException;
91import org.onosproject.segmentrouting.config.DeviceConfiguration;
Pier Ventref34966c2016-11-07 16:21:04 -080092import org.onosproject.segmentrouting.config.PwaasConfig;
Pier Ventref34966c2016-11-07 16:21:04 -080093import org.onosproject.segmentrouting.config.SegmentRoutingAppConfig;
Ray Milkey6c1f0f02017-08-15 11:02:29 -070094import org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig;
Charles Chanfc5c7802016-05-17 13:13:55 -070095import org.onosproject.segmentrouting.config.XConnectConfig;
Charles Chand55e84d2016-03-30 17:54:24 -070096import org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler;
Saurav Das7bcbe702017-06-13 15:35:54 -070097import org.onosproject.segmentrouting.grouphandler.DestinationSet;
98import org.onosproject.segmentrouting.grouphandler.NextNeighbors;
Ray Milkey6c1f0f02017-08-15 11:02:29 -070099import org.onosproject.segmentrouting.pwaas.L2TunnelHandler;
Saurav Das7bcbe702017-06-13 15:35:54 -0700100import org.onosproject.segmentrouting.storekey.DestinationSetNextObjectiveStoreKey;
Charles Chand2990362016-04-18 13:44:03 -0700101import org.onosproject.segmentrouting.storekey.PortNextObjectiveStoreKey;
Charles Chan59cc16d2017-02-02 16:20:42 -0800102import org.onosproject.segmentrouting.storekey.VlanNextObjectiveStoreKey;
Charles Chanfc5c7802016-05-17 13:13:55 -0700103import org.onosproject.segmentrouting.storekey.XConnectStoreKey;
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700104import org.onosproject.store.serializers.KryoNamespaces;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700105import org.onosproject.store.service.EventuallyConsistentMap;
106import org.onosproject.store.service.EventuallyConsistentMapBuilder;
107import org.onosproject.store.service.StorageService;
108import org.onosproject.store.service.WallClockTimestamp;
sanghob35a6192015-04-01 13:05:26 -0700109import org.slf4j.Logger;
110import org.slf4j.LoggerFactory;
111
Ray Milkey6c1f0f02017-08-15 11:02:29 -0700112import com.google.common.collect.HashMultimap;
113import com.google.common.collect.ImmutableMap;
114import com.google.common.collect.Maps;
115import com.google.common.collect.Multimap;
sanghob35a6192015-04-01 13:05:26 -0700116
Charles Chan3e783d02016-02-26 22:19:52 -0800117import static com.google.common.base.Preconditions.checkState;
Pier Ventree0ae7a32016-11-23 09:57:42 -0800118import static org.onlab.packet.Ethernet.TYPE_ARP;
Yuta HIGUCHI1624df12016-07-21 16:54:33 -0700119import static org.onlab.util.Tools.groupedThreads;
Charles Chan3e783d02016-02-26 22:19:52 -0800120
Charles Chane849c192016-01-11 18:28:54 -0800121/**
122 * Segment routing manager.
123 */
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700124@Service
125@Component(immediate = true)
sangho1e575652015-05-14 00:39:53 -0700126public class SegmentRoutingManager implements SegmentRoutingService {
sanghob35a6192015-04-01 13:05:26 -0700127
Charles Chan2c15aca2016-11-09 20:51:44 -0800128 private static Logger log = LoggerFactory.getLogger(SegmentRoutingManager.class);
sanghob35a6192015-04-01 13:05:26 -0700129
130 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan03a73e02016-10-24 14:52:01 -0700131 private ComponentConfigService compCfgService;
sanghob35a6192015-04-01 13:05:26 -0700132
133 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Pier Ventre10bd8d12016-11-26 21:05:22 -0800134 private NeighbourResolutionService neighbourResolutionService;
135
136 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Pier Ventre42287df2016-11-09 14:17:26 -0800137 public PathService pathService;
138
139 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan03a73e02016-10-24 14:52:01 -0700140 CoreService coreService;
sanghob35a6192015-04-01 13:05:26 -0700141
142 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan03a73e02016-10-24 14:52:01 -0700143 PacketService packetService;
sanghob35a6192015-04-01 13:05:26 -0700144
145 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan03a73e02016-10-24 14:52:01 -0700146 HostService hostService;
sanghob35a6192015-04-01 13:05:26 -0700147
148 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan03a73e02016-10-24 14:52:01 -0700149 DeviceService deviceService;
sanghob35a6192015-04-01 13:05:26 -0700150
151 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Pier Ventre42287df2016-11-09 14:17:26 -0800152 public FlowObjectiveService flowObjectiveService;
sanghob35a6192015-04-01 13:05:26 -0700153
154 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan03a73e02016-10-24 14:52:01 -0700155 LinkService linkService;
sangho1e575652015-05-14 00:39:53 -0700156
Charles Chan5270ed02016-01-30 23:22:37 -0800157 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Pier Ventre42287df2016-11-09 14:17:26 -0800158 public MastershipService mastershipService;
Charles Chan03a73e02016-10-24 14:52:01 -0700159
160 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Pier Ventre42287df2016-11-09 14:17:26 -0800161 public StorageService storageService;
Charles Chan03a73e02016-10-24 14:52:01 -0700162
163 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
164 MulticastRouteService multicastRouteService;
165
166 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
167 TopologyService topologyService;
168
169 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan03a73e02016-10-24 14:52:01 -0700170 RouteService routeService;
Charles Chan5270ed02016-01-30 23:22:37 -0800171
172 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan2c15aca2016-11-09 20:51:44 -0800173 public NetworkConfigRegistry cfgService;
Charles Chan5270ed02016-01-30 23:22:37 -0800174
Saurav Das80980c72016-03-23 11:22:49 -0700175 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan2c15aca2016-11-09 20:51:44 -0800176 public InterfaceService interfaceService;
177
Charles Chan03a73e02016-10-24 14:52:01 -0700178 ArpHandler arpHandler = null;
179 IcmpHandler icmpHandler = null;
180 IpHandler ipHandler = null;
181 RoutingRulePopulator routingRulePopulator = null;
Ray Milkeye4afdb52017-04-05 09:42:04 -0700182 ApplicationId appId;
183 DeviceConfiguration deviceConfiguration = null;
sanghob35a6192015-04-01 13:05:26 -0700184
Charles Chan03a73e02016-10-24 14:52:01 -0700185 DefaultRoutingHandler defaultRoutingHandler = null;
sangho1e575652015-05-14 00:39:53 -0700186 private TunnelHandler tunnelHandler = null;
187 private PolicyHandler policyHandler = null;
Charles Chanb8e10c82015-10-14 11:24:40 -0700188 private InternalPacketProcessor processor = null;
189 private InternalLinkListener linkListener = null;
190 private InternalDeviceListener deviceListener = null;
Charles Chanfc5c7802016-05-17 13:13:55 -0700191 private AppConfigHandler appCfgHandler = null;
Charles Chan03a73e02016-10-24 14:52:01 -0700192 XConnectHandler xConnectHandler = null;
Charles Chand2990362016-04-18 13:44:03 -0700193 private McastHandler mcastHandler = null;
Charles Chan65238242017-06-22 18:03:14 -0700194 private HostHandler hostHandler = null;
Pier Ventre10bd8d12016-11-26 21:05:22 -0800195 private RouteHandler routeHandler = null;
Pier Ventre735b8c82016-12-02 08:16:05 -0800196 private SegmentRoutingNeighbourDispatcher neighbourHandler = null;
Pier Ventref34966c2016-11-07 16:21:04 -0800197 private L2TunnelHandler l2TunnelHandler = null;
sanghob35a6192015-04-01 13:05:26 -0700198 private InternalEventHandler eventHandler = new InternalEventHandler();
Charles Chan5270ed02016-01-30 23:22:37 -0800199 private final InternalHostListener hostListener = new InternalHostListener();
Charles Chand55e84d2016-03-30 17:54:24 -0700200 private final InternalConfigListener cfgListener = new InternalConfigListener(this);
201 private final InternalMcastListener mcastListener = new InternalMcastListener();
Charles Chan03a73e02016-10-24 14:52:01 -0700202 private final InternalRouteEventListener routeListener = new InternalRouteEventListener();
sanghob35a6192015-04-01 13:05:26 -0700203
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700204 private ScheduledExecutorService executorService = Executors
Yuta HIGUCHI1624df12016-07-21 16:54:33 -0700205 .newScheduledThreadPool(1, groupedThreads("SegmentRoutingManager", "event-%d", log));
sanghob35a6192015-04-01 13:05:26 -0700206
Saurav Das4ce45962015-11-24 23:21:05 -0800207 @SuppressWarnings("unused")
sanghob35a6192015-04-01 13:05:26 -0700208 private static ScheduledFuture<?> eventHandlerFuture = null;
Saurav Das4ce45962015-11-24 23:21:05 -0800209 @SuppressWarnings("rawtypes")
Yuta HIGUCHI1624df12016-07-21 16:54:33 -0700210 private ConcurrentLinkedQueue<Event> eventQueue = new ConcurrentLinkedQueue<>();
Charles Chan68aa62d2015-11-09 16:37:23 -0800211 private Map<DeviceId, DefaultGroupHandler> groupHandlerMap =
Charles Chane849c192016-01-11 18:28:54 -0800212 new ConcurrentHashMap<>();
213 /**
Saurav Das7bcbe702017-06-13 15:35:54 -0700214 * Per device next objective ID store with (device id + destination set) as key.
Charles Chane849c192016-01-11 18:28:54 -0800215 */
Saurav Das7bcbe702017-06-13 15:35:54 -0700216 EventuallyConsistentMap<DestinationSetNextObjectiveStoreKey, NextNeighbors>
217 dsNextObjStore = null;
Charles Chane849c192016-01-11 18:28:54 -0800218 /**
219 * Per device next objective ID store with (device id + subnet) as key.
220 */
Ray Milkeye4afdb52017-04-05 09:42:04 -0700221 EventuallyConsistentMap<VlanNextObjectiveStoreKey, Integer>
Charles Chan59cc16d2017-02-02 16:20:42 -0800222 vlanNextObjStore = null;
Charles Chane849c192016-01-11 18:28:54 -0800223 /**
224 * Per device next objective ID store with (device id + port) as key.
225 */
Ray Milkeye4afdb52017-04-05 09:42:04 -0700226 EventuallyConsistentMap<PortNextObjectiveStoreKey, Integer>
Saurav Das4ce45962015-11-24 23:21:05 -0800227 portNextObjStore = null;
Charles Chan59cc16d2017-02-02 16:20:42 -0800228
Saurav Dasc88d4662017-05-15 15:34:25 -0700229 // Local store for all links seen and their present status, used for
230 // optimized routing. The existence of the link in the keys is enough to know
231 // if the link has been "seen-before" by this instance of the controller.
232 // The boolean value indicates if the link is currently up or not.
233 // XXX Currently the optimized routing logic depends on "forgetting" a link
234 // when a switch goes down, but "remembering" it when only the link goes down.
235 // Consider changing this logic so we can use the Link Service instead of
236 // a local cache.
237 private Map<Link, Boolean> seenLinks = new ConcurrentHashMap<>();
238
Saurav Das4ce45962015-11-24 23:21:05 -0800239 private EventuallyConsistentMap<String, Tunnel> tunnelStore = null;
240 private EventuallyConsistentMap<String, Policy> policyStore = null;
sangho0b2b6d12015-05-20 22:16:38 -0700241
Saurav Das7bcbe702017-06-13 15:35:54 -0700242 private AtomicBoolean programmingScheduled = new AtomicBoolean();
243
Charles Chand55e84d2016-03-30 17:54:24 -0700244 private final ConfigFactory<DeviceId, SegmentRoutingDeviceConfig> deviceConfigFactory =
Charles Chanfc5c7802016-05-17 13:13:55 -0700245 new ConfigFactory<DeviceId, SegmentRoutingDeviceConfig>(
246 SubjectFactories.DEVICE_SUBJECT_FACTORY,
Charles Chand55e84d2016-03-30 17:54:24 -0700247 SegmentRoutingDeviceConfig.class, "segmentrouting") {
Charles Chand6832882015-10-05 17:50:33 -0700248 @Override
Charles Chan5270ed02016-01-30 23:22:37 -0800249 public SegmentRoutingDeviceConfig createConfig() {
250 return new SegmentRoutingDeviceConfig();
Charles Chand6832882015-10-05 17:50:33 -0700251 }
252 };
Pier Ventref34966c2016-11-07 16:21:04 -0800253
Charles Chand55e84d2016-03-30 17:54:24 -0700254 private final ConfigFactory<ApplicationId, SegmentRoutingAppConfig> appConfigFactory =
Charles Chanfc5c7802016-05-17 13:13:55 -0700255 new ConfigFactory<ApplicationId, SegmentRoutingAppConfig>(
256 SubjectFactories.APP_SUBJECT_FACTORY,
Charles Chand55e84d2016-03-30 17:54:24 -0700257 SegmentRoutingAppConfig.class, "segmentrouting") {
Charles Chan5270ed02016-01-30 23:22:37 -0800258 @Override
259 public SegmentRoutingAppConfig createConfig() {
260 return new SegmentRoutingAppConfig();
261 }
262 };
Pier Ventref34966c2016-11-07 16:21:04 -0800263
Charles Chanfc5c7802016-05-17 13:13:55 -0700264 private final ConfigFactory<ApplicationId, XConnectConfig> xConnectConfigFactory =
265 new ConfigFactory<ApplicationId, XConnectConfig>(
266 SubjectFactories.APP_SUBJECT_FACTORY,
267 XConnectConfig.class, "xconnect") {
268 @Override
269 public XConnectConfig createConfig() {
270 return new XConnectConfig();
271 }
272 };
Pier Ventref34966c2016-11-07 16:21:04 -0800273
Charles Chand55e84d2016-03-30 17:54:24 -0700274 private ConfigFactory<ApplicationId, McastConfig> mcastConfigFactory =
Charles Chanfc5c7802016-05-17 13:13:55 -0700275 new ConfigFactory<ApplicationId, McastConfig>(
276 SubjectFactories.APP_SUBJECT_FACTORY,
Charles Chand55e84d2016-03-30 17:54:24 -0700277 McastConfig.class, "multicast") {
278 @Override
279 public McastConfig createConfig() {
280 return new McastConfig();
281 }
282 };
283
Pier Ventref34966c2016-11-07 16:21:04 -0800284 private final ConfigFactory<ApplicationId, PwaasConfig> pwaasConfigFactory =
285 new ConfigFactory<ApplicationId, PwaasConfig>(
286 SubjectFactories.APP_SUBJECT_FACTORY,
287 PwaasConfig.class, "pwaas") {
288 @Override
289 public PwaasConfig createConfig() {
290 return new PwaasConfig();
291 }
292 };
293
Charles Chan65238242017-06-22 18:03:14 -0700294 private static final Object THREAD_SCHED_LOCK = new Object();
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700295 private static int numOfEventsQueued = 0;
296 private static int numOfEventsExecuted = 0;
sanghob35a6192015-04-01 13:05:26 -0700297 private static int numOfHandlerExecution = 0;
298 private static int numOfHandlerScheduled = 0;
299
Charles Chan116188d2016-02-18 14:22:42 -0800300 /**
301 * Segment Routing App ID.
302 */
Charles Chan2c15aca2016-11-09 20:51:44 -0800303 public static final String APP_NAME = "org.onosproject.segmentrouting";
Charles Chan59cc16d2017-02-02 16:20:42 -0800304
Charles Chane849c192016-01-11 18:28:54 -0800305 /**
306 * The default VLAN ID assigned to the interfaces without subnet config.
307 */
Charles Chan59cc16d2017-02-02 16:20:42 -0800308 public static final VlanId INTERNAL_VLAN = VlanId.vlanId((short) 4094);
Saurav Das0e99e2b2015-10-28 12:39:42 -0700309
sanghob35a6192015-04-01 13:05:26 -0700310 @Activate
311 protected void activate() {
Charles Chan2c15aca2016-11-09 20:51:44 -0800312 appId = coreService.registerApplication(APP_NAME);
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700313
314 log.debug("Creating EC map nsnextobjectivestore");
Saurav Das7bcbe702017-06-13 15:35:54 -0700315 EventuallyConsistentMapBuilder<DestinationSetNextObjectiveStoreKey, NextNeighbors>
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700316 nsNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder();
Saurav Das7bcbe702017-06-13 15:35:54 -0700317 dsNextObjStore = nsNextObjMapBuilder
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700318 .withName("nsnextobjectivestore")
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700319 .withSerializer(createSerializer())
Madan Jampanibcf1a482015-06-24 19:05:56 -0700320 .withTimestampProvider((k, v) -> new WallClockTimestamp())
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700321 .build();
Saurav Das7bcbe702017-06-13 15:35:54 -0700322 log.trace("Current size {}", dsNextObjStore.size());
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700323
Charles Chan59cc16d2017-02-02 16:20:42 -0800324 log.debug("Creating EC map vlannextobjectivestore");
325 EventuallyConsistentMapBuilder<VlanNextObjectiveStoreKey, Integer>
326 vlanNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder();
327 vlanNextObjStore = vlanNextObjMapBuilder
328 .withName("vlannextobjectivestore")
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700329 .withSerializer(createSerializer())
Charles Chanc42e84e2015-10-20 16:24:19 -0700330 .withTimestampProvider((k, v) -> new WallClockTimestamp())
331 .build();
332
Saurav Das4ce45962015-11-24 23:21:05 -0800333 log.debug("Creating EC map subnetnextobjectivestore");
334 EventuallyConsistentMapBuilder<PortNextObjectiveStoreKey, Integer>
335 portNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder();
336 portNextObjStore = portNextObjMapBuilder
337 .withName("portnextobjectivestore")
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700338 .withSerializer(createSerializer())
Saurav Das4ce45962015-11-24 23:21:05 -0800339 .withTimestampProvider((k, v) -> new WallClockTimestamp())
340 .build();
341
sangho0b2b6d12015-05-20 22:16:38 -0700342 EventuallyConsistentMapBuilder<String, Tunnel> tunnelMapBuilder =
343 storageService.eventuallyConsistentMapBuilder();
sangho0b2b6d12015-05-20 22:16:38 -0700344 tunnelStore = tunnelMapBuilder
345 .withName("tunnelstore")
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700346 .withSerializer(createSerializer())
Madan Jampanibcf1a482015-06-24 19:05:56 -0700347 .withTimestampProvider((k, v) -> new WallClockTimestamp())
sangho0b2b6d12015-05-20 22:16:38 -0700348 .build();
349
350 EventuallyConsistentMapBuilder<String, Policy> policyMapBuilder =
351 storageService.eventuallyConsistentMapBuilder();
sangho0b2b6d12015-05-20 22:16:38 -0700352 policyStore = policyMapBuilder
353 .withName("policystore")
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700354 .withSerializer(createSerializer())
Madan Jampanibcf1a482015-06-24 19:05:56 -0700355 .withTimestampProvider((k, v) -> new WallClockTimestamp())
sangho0b2b6d12015-05-20 22:16:38 -0700356 .build();
357
Saurav Das80980c72016-03-23 11:22:49 -0700358 compCfgService.preSetProperty("org.onosproject.net.group.impl.GroupManager",
Pier Luigi9e5c5ca2017-01-12 18:14:58 -0800359 "purgeOnDisconnection", "true");
Saurav Das80980c72016-03-23 11:22:49 -0700360 compCfgService.preSetProperty("org.onosproject.net.flow.impl.FlowRuleManager",
Pier Luigi9e5c5ca2017-01-12 18:14:58 -0800361 "purgeOnDisconnection", "true");
Pier Luigi9e5c5ca2017-01-12 18:14:58 -0800362 compCfgService.preSetProperty("org.onosproject.provider.host.impl.HostLocationProvider",
363 "requestInterceptsEnabled", "false");
Charles Chand3baaba2017-08-08 15:13:37 -0700364 compCfgService.preSetProperty("org.onosproject.net.neighbour.impl.NeighbourResolutionManager",
Pier Luigi7e415132017-01-12 22:46:39 -0800365 "requestInterceptsEnabled", "false");
Charles Chanc760f382017-07-24 15:56:10 -0700366 compCfgService.preSetProperty("org.onosproject.dhcprelay.DhcpRelayManager",
Pier Luigi7e415132017-01-12 22:46:39 -0800367 "arpEnabled", "false");
Pier Luigi9b1d6262017-02-02 22:31:34 -0800368 compCfgService.preSetProperty("org.onosproject.net.host.impl.HostManager",
369 "greedyLearningIpv6", "true");
Charles Chanc6d227e2017-02-28 15:15:17 -0800370 compCfgService.preSetProperty("org.onosproject.routing.cpr.ControlPlaneRedirectManager",
371 "forceUnprovision", "true");
Charles Chanef624ed2017-08-10 16:57:28 -0700372 compCfgService.preSetProperty("org.onosproject.routeservice.store.RouteStoreImpl",
Charles Chan73316522017-07-20 16:16:25 -0700373 "distributed", "true");
Charles Chan35a32322017-08-14 11:42:11 -0700374 compCfgService.preSetProperty("org.onosproject.provider.host.impl.HostLocationProvider",
375 "multihomingEnabled", "true");
Saurav Das80980c72016-03-23 11:22:49 -0700376
Charles Chanb8e10c82015-10-14 11:24:40 -0700377 processor = new InternalPacketProcessor();
378 linkListener = new InternalLinkListener();
379 deviceListener = new InternalDeviceListener();
Charles Chanfc5c7802016-05-17 13:13:55 -0700380 appCfgHandler = new AppConfigHandler(this);
381 xConnectHandler = new XConnectHandler(this);
Charles Chand2990362016-04-18 13:44:03 -0700382 mcastHandler = new McastHandler(this);
383 hostHandler = new HostHandler(this);
Charles Chan03a73e02016-10-24 14:52:01 -0700384 routeHandler = new RouteHandler(this);
Pier Ventre735b8c82016-12-02 08:16:05 -0800385 neighbourHandler = new SegmentRoutingNeighbourDispatcher(this);
Pier Ventref34966c2016-11-07 16:21:04 -0800386 l2TunnelHandler = new L2TunnelHandler(this);
Charles Chanb8e10c82015-10-14 11:24:40 -0700387
Charles Chan3e783d02016-02-26 22:19:52 -0800388 cfgService.addListener(cfgListener);
Charles Chand55e84d2016-03-30 17:54:24 -0700389 cfgService.registerConfigFactory(deviceConfigFactory);
390 cfgService.registerConfigFactory(appConfigFactory);
Charles Chanfc5c7802016-05-17 13:13:55 -0700391 cfgService.registerConfigFactory(xConnectConfigFactory);
Charles Chand55e84d2016-03-30 17:54:24 -0700392 cfgService.registerConfigFactory(mcastConfigFactory);
Pier Ventref34966c2016-11-07 16:21:04 -0800393 cfgService.registerConfigFactory(pwaasConfigFactory);
Charles Chan5270ed02016-01-30 23:22:37 -0800394 hostService.addListener(hostListener);
Charles Chanb8e10c82015-10-14 11:24:40 -0700395 packetService.addProcessor(processor, PacketProcessor.director(2));
396 linkService.addListener(linkListener);
397 deviceService.addListener(deviceListener);
Charles Chand55e84d2016-03-30 17:54:24 -0700398 multicastRouteService.addListener(mcastListener);
Charles Chanc7a8a682017-06-19 00:43:31 -0700399 routeService.addListener(routeListener);
Charles Chanb8e10c82015-10-14 11:24:40 -0700400
401 cfgListener.configureNetwork();
402
sanghob35a6192015-04-01 13:05:26 -0700403 log.info("Started");
404 }
405
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700406 private KryoNamespace.Builder createSerializer() {
407 return new KryoNamespace.Builder()
408 .register(KryoNamespaces.API)
Saurav Das7bcbe702017-06-13 15:35:54 -0700409 .register(DestinationSetNextObjectiveStoreKey.class,
Charles Chan59cc16d2017-02-02 16:20:42 -0800410 VlanNextObjectiveStoreKey.class,
Saurav Das7bcbe702017-06-13 15:35:54 -0700411 DestinationSet.class,
412 NextNeighbors.class,
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700413 Tunnel.class,
414 DefaultTunnel.class,
415 Policy.class,
416 TunnelPolicy.class,
417 Policy.Type.class,
418 PortNextObjectiveStoreKey.class,
Charles Chanfc5c7802016-05-17 13:13:55 -0700419 XConnectStoreKey.class
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700420 );
421 }
422
sanghob35a6192015-04-01 13:05:26 -0700423 @Deactivate
424 protected void deactivate() {
Charles Chand6832882015-10-05 17:50:33 -0700425 cfgService.removeListener(cfgListener);
Charles Chand55e84d2016-03-30 17:54:24 -0700426 cfgService.unregisterConfigFactory(deviceConfigFactory);
427 cfgService.unregisterConfigFactory(appConfigFactory);
Charles Chan03a73e02016-10-24 14:52:01 -0700428 cfgService.unregisterConfigFactory(xConnectConfigFactory);
Charles Chand55e84d2016-03-30 17:54:24 -0700429 cfgService.unregisterConfigFactory(mcastConfigFactory);
Pier Ventref34966c2016-11-07 16:21:04 -0800430 cfgService.unregisterConfigFactory(pwaasConfigFactory);
Charles Chand6832882015-10-05 17:50:33 -0700431
Charles Chanc7a8a682017-06-19 00:43:31 -0700432 hostService.removeListener(hostListener);
sanghob35a6192015-04-01 13:05:26 -0700433 packetService.removeProcessor(processor);
Charles Chanb8e10c82015-10-14 11:24:40 -0700434 linkService.removeListener(linkListener);
435 deviceService.removeListener(deviceListener);
Charles Chand55e84d2016-03-30 17:54:24 -0700436 multicastRouteService.removeListener(mcastListener);
Charles Chan03a73e02016-10-24 14:52:01 -0700437 routeService.removeListener(routeListener);
Charles Chand55e84d2016-03-30 17:54:24 -0700438
Charles Chan0aa674e2017-02-23 15:44:08 -0800439 neighbourResolutionService.unregisterNeighbourHandlers(appId);
440
sanghob35a6192015-04-01 13:05:26 -0700441 processor = null;
Charles Chanb8e10c82015-10-14 11:24:40 -0700442 linkListener = null;
Charles Chand55e84d2016-03-30 17:54:24 -0700443 deviceListener = null;
Charles Chanb8e10c82015-10-14 11:24:40 -0700444 groupHandlerMap.clear();
445
Saurav Das7bcbe702017-06-13 15:35:54 -0700446 dsNextObjStore.destroy();
Charles Chan59cc16d2017-02-02 16:20:42 -0800447 vlanNextObjStore.destroy();
Charles Chand55e84d2016-03-30 17:54:24 -0700448 portNextObjStore.destroy();
Charles Chand55e84d2016-03-30 17:54:24 -0700449 tunnelStore.destroy();
450 policyStore.destroy();
sanghob35a6192015-04-01 13:05:26 -0700451 log.info("Stopped");
452 }
453
sangho1e575652015-05-14 00:39:53 -0700454 @Override
455 public List<Tunnel> getTunnels() {
456 return tunnelHandler.getTunnels();
457 }
458
459 @Override
sangho71abe1b2015-06-29 14:58:47 -0700460 public TunnelHandler.Result createTunnel(Tunnel tunnel) {
461 return tunnelHandler.createTunnel(tunnel);
sangho1e575652015-05-14 00:39:53 -0700462 }
463
464 @Override
sangho71abe1b2015-06-29 14:58:47 -0700465 public TunnelHandler.Result removeTunnel(Tunnel tunnel) {
sangho1e575652015-05-14 00:39:53 -0700466 for (Policy policy: policyHandler.getPolicies()) {
467 if (policy.type() == Policy.Type.TUNNEL_FLOW) {
468 TunnelPolicy tunnelPolicy = (TunnelPolicy) policy;
469 if (tunnelPolicy.tunnelId().equals(tunnel.id())) {
470 log.warn("Cannot remove the tunnel used by a policy");
sangho71abe1b2015-06-29 14:58:47 -0700471 return TunnelHandler.Result.TUNNEL_IN_USE;
sangho1e575652015-05-14 00:39:53 -0700472 }
473 }
474 }
sangho71abe1b2015-06-29 14:58:47 -0700475 return tunnelHandler.removeTunnel(tunnel);
sangho1e575652015-05-14 00:39:53 -0700476 }
477
478 @Override
sangho71abe1b2015-06-29 14:58:47 -0700479 public PolicyHandler.Result removePolicy(Policy policy) {
480 return policyHandler.removePolicy(policy);
sangho1e575652015-05-14 00:39:53 -0700481 }
482
483 @Override
sangho71abe1b2015-06-29 14:58:47 -0700484 public PolicyHandler.Result createPolicy(Policy policy) {
485 return policyHandler.createPolicy(policy);
sangho1e575652015-05-14 00:39:53 -0700486 }
487
488 @Override
489 public List<Policy> getPolicies() {
490 return policyHandler.getPolicies();
491 }
492
Saurav Das59232cf2016-04-27 18:35:50 -0700493 @Override
494 public void rerouteNetwork() {
495 cfgListener.configureNetwork();
Saurav Das59232cf2016-04-27 18:35:50 -0700496 }
497
Charles Chanc81c45b2016-10-20 17:02:44 -0700498 @Override
Pier Ventre10bd8d12016-11-26 21:05:22 -0800499 public Map<DeviceId, Set<IpPrefix>> getDeviceSubnetMap() {
500 Map<DeviceId, Set<IpPrefix>> deviceSubnetMap = Maps.newHashMap();
Charles Chanc81c45b2016-10-20 17:02:44 -0700501 deviceService.getAvailableDevices().forEach(device -> {
502 deviceSubnetMap.put(device.id(), deviceConfiguration.getSubnets(device.id()));
503 });
504 return deviceSubnetMap;
505 }
506
Saurav Dasc88d4662017-05-15 15:34:25 -0700507
508 @Override
509 public ImmutableMap<DeviceId, EcmpShortestPathGraph> getCurrentEcmpSpg() {
510 if (defaultRoutingHandler != null) {
511 return defaultRoutingHandler.getCurrentEmcpSpgMap();
512 } else {
513 return null;
514 }
515 }
516
517 @Override
Saurav Das7bcbe702017-06-13 15:35:54 -0700518 public ImmutableMap<DestinationSetNextObjectiveStoreKey, NextNeighbors> getDestinationSet() {
519 if (dsNextObjStore != null) {
520 return ImmutableMap.copyOf(dsNextObjStore.entrySet());
Saurav Dasc88d4662017-05-15 15:34:25 -0700521 } else {
522 return ImmutableMap.of();
523 }
524 }
525
Saurav Dasceccf242017-08-03 18:30:35 -0700526 @Override
527 public void verifyGroups(DeviceId id) {
528 DefaultGroupHandler gh = groupHandlerMap.get(id);
529 if (gh != null) {
530 gh.triggerBucketCorrector();
531 }
532 }
533
sanghof9d0bf12015-05-19 11:57:42 -0700534 /**
Ray Milkeye4afdb52017-04-05 09:42:04 -0700535 * Extracts the application ID from the manager.
536 *
537 * @return application ID
538 */
539 public ApplicationId appId() {
540 return appId;
541 }
542
543 /**
544 * Returns the device configuration.
545 *
546 * @return device configuration
547 */
548 public DeviceConfiguration deviceConfiguration() {
549 return deviceConfiguration;
550 }
551
552 /**
Saurav Das7bcbe702017-06-13 15:35:54 -0700553 * Per device next objective ID store with (device id + destination set) as key.
Ray Milkeye4afdb52017-04-05 09:42:04 -0700554 *
555 * @return next objective ID store
556 */
Saurav Das7bcbe702017-06-13 15:35:54 -0700557 public EventuallyConsistentMap<DestinationSetNextObjectiveStoreKey, NextNeighbors>
558 dsNextObjStore() {
559 return dsNextObjStore;
Ray Milkeye4afdb52017-04-05 09:42:04 -0700560 }
561
562 /**
563 * Per device next objective ID store with (device id + subnet) as key.
564 *
565 * @return vlan next object store
566 */
567 public EventuallyConsistentMap<VlanNextObjectiveStoreKey, Integer> vlanNextObjStore() {
568 return vlanNextObjStore;
569 }
570
571 /**
572 * Per device next objective ID store with (device id + port) as key.
573 *
574 * @return port next object store.
575 */
576 public EventuallyConsistentMap<PortNextObjectiveStoreKey, Integer> portNextObjStore() {
577 return portNextObjStore;
578 }
579
580 /**
Saurav Das7bcbe702017-06-13 15:35:54 -0700581 * Returns the MPLS-ECMP configuration which indicates whether ECMP on
582 * labeled packets should be programmed or not.
Pier Ventre98161782016-10-31 15:00:01 -0700583 *
584 * @return MPLS-ECMP value
585 */
586 public boolean getMplsEcmp() {
587 SegmentRoutingAppConfig segmentRoutingAppConfig = cfgService
588 .getConfig(this.appId, SegmentRoutingAppConfig.class);
589 return segmentRoutingAppConfig != null && segmentRoutingAppConfig.mplsEcmp();
590 }
591
592 /**
sanghof9d0bf12015-05-19 11:57:42 -0700593 * Returns the tunnel object with the tunnel ID.
594 *
595 * @param tunnelId Tunnel ID
596 * @return Tunnel reference
597 */
sangho1e575652015-05-14 00:39:53 -0700598 public Tunnel getTunnel(String tunnelId) {
599 return tunnelHandler.getTunnel(tunnelId);
600 }
601
Charles Chan7ffd81f2017-02-08 15:52:08 -0800602 // TODO Consider moving these to InterfaceService
sanghob35a6192015-04-01 13:05:26 -0700603 /**
Charles Chan59cc16d2017-02-02 16:20:42 -0800604 * Returns untagged VLAN configured on given connect point.
Charles Chan7ffd81f2017-02-08 15:52:08 -0800605 * <p>
606 * Only returns the first match if there are multiple untagged VLAN configured
607 * on the connect point.
sanghob35a6192015-04-01 13:05:26 -0700608 *
Charles Chan59cc16d2017-02-02 16:20:42 -0800609 * @param connectPoint connect point
610 * @return untagged VLAN or null if not configured
sanghob35a6192015-04-01 13:05:26 -0700611 */
Charles Chan65238242017-06-22 18:03:14 -0700612 VlanId getUntaggedVlanId(ConnectPoint connectPoint) {
Charles Chan59cc16d2017-02-02 16:20:42 -0800613 return interfaceService.getInterfacesByPort(connectPoint).stream()
614 .filter(intf -> !intf.vlanUntagged().equals(VlanId.NONE))
615 .map(Interface::vlanUntagged)
616 .findFirst().orElse(null);
sanghob35a6192015-04-01 13:05:26 -0700617 }
618
sangho1e575652015-05-14 00:39:53 -0700619 /**
Charles Chan7ffd81f2017-02-08 15:52:08 -0800620 * Returns tagged VLAN configured on given connect point.
621 * <p>
622 * Returns all matches if there are multiple tagged VLAN configured
623 * on the connect point.
624 *
625 * @param connectPoint connect point
626 * @return tagged VLAN or empty set if not configured
627 */
Charles Chan65238242017-06-22 18:03:14 -0700628 Set<VlanId> getTaggedVlanId(ConnectPoint connectPoint) {
Charles Chan7ffd81f2017-02-08 15:52:08 -0800629 Set<Interface> interfaces = interfaceService.getInterfacesByPort(connectPoint);
630 return interfaces.stream()
631 .map(Interface::vlanTagged)
Charles Chan65238242017-06-22 18:03:14 -0700632 .flatMap(Set::stream)
Charles Chan7ffd81f2017-02-08 15:52:08 -0800633 .collect(Collectors.toSet());
634 }
635
636 /**
637 * Returns native VLAN configured on given connect point.
638 * <p>
639 * Only returns the first match if there are multiple native VLAN configured
640 * on the connect point.
641 *
642 * @param connectPoint connect point
643 * @return native VLAN or null if not configured
644 */
Charles Chan65238242017-06-22 18:03:14 -0700645 VlanId getNativeVlanId(ConnectPoint connectPoint) {
Charles Chan7ffd81f2017-02-08 15:52:08 -0800646 Set<Interface> interfaces = interfaceService.getInterfacesByPort(connectPoint);
647 return interfaces.stream()
648 .filter(intf -> !intf.vlanNative().equals(VlanId.NONE))
649 .map(Interface::vlanNative)
650 .findFirst()
651 .orElse(null);
652 }
653
654 /**
Charles Chanf9a52702017-06-16 15:19:24 -0700655 * Returns internal VLAN for untagged hosts on given connect point.
656 * <p>
657 * The internal VLAN is either vlan-untagged for an access port,
658 * or vlan-native for a trunk port.
659 *
660 * @param connectPoint connect point
661 * @return internal VLAN or null if both vlan-untagged and vlan-native are undefined
662 */
Charles Chan65238242017-06-22 18:03:14 -0700663 VlanId getInternalVlanId(ConnectPoint connectPoint) {
Charles Chanf9a52702017-06-16 15:19:24 -0700664 VlanId untaggedVlanId = getUntaggedVlanId(connectPoint);
665 VlanId nativeVlanId = getNativeVlanId(connectPoint);
666 return untaggedVlanId != null ? untaggedVlanId : nativeVlanId;
667 }
668
669 /**
Charles Chan65238242017-06-22 18:03:14 -0700670 * Returns optional pair device ID of given device.
671 *
672 * @param deviceId device ID
673 * @return optional pair device ID. Might be empty if pair device is not configured
674 */
675 Optional<DeviceId> getPairDeviceId(DeviceId deviceId) {
676 SegmentRoutingDeviceConfig deviceConfig =
677 cfgService.getConfig(deviceId, SegmentRoutingDeviceConfig.class);
678 return Optional.ofNullable(deviceConfig).map(SegmentRoutingDeviceConfig::pairDeviceId);
679 }
680 /**
681 * Returns optional pair device local port of given device.
682 *
683 * @param deviceId device ID
684 * @return optional pair device ID. Might be empty if pair device is not configured
685 */
686 Optional<PortNumber> getPairLocalPorts(DeviceId deviceId) {
687 SegmentRoutingDeviceConfig deviceConfig =
688 cfgService.getConfig(deviceId, SegmentRoutingDeviceConfig.class);
689 return Optional.ofNullable(deviceConfig).map(SegmentRoutingDeviceConfig::pairLocalPort);
690 }
691
692 /**
Charles Chan7ffd81f2017-02-08 15:52:08 -0800693 * Returns vlan port map of given device.
694 *
695 * @param deviceId device id
696 * @return vlan-port multimap
697 */
698 public Multimap<VlanId, PortNumber> getVlanPortMap(DeviceId deviceId) {
699 HashMultimap<VlanId, PortNumber> vlanPortMap = HashMultimap.create();
700
701 interfaceService.getInterfaces().stream()
702 .filter(intf -> intf.connectPoint().deviceId().equals(deviceId))
703 .forEach(intf -> {
704 vlanPortMap.put(intf.vlanUntagged(), intf.connectPoint().port());
Charles Chan65238242017-06-22 18:03:14 -0700705 intf.vlanTagged().forEach(vlanTagged ->
706 vlanPortMap.put(vlanTagged, intf.connectPoint().port())
707 );
Charles Chan7ffd81f2017-02-08 15:52:08 -0800708 vlanPortMap.put(intf.vlanNative(), intf.connectPoint().port());
709 });
710 vlanPortMap.removeAll(VlanId.NONE);
711
712 return vlanPortMap;
713 }
714
715 /**
Saurav Das4ce45962015-11-24 23:21:05 -0800716 * Returns the next objective ID for the given subnet prefix. It is expected
Charles Chan59cc16d2017-02-02 16:20:42 -0800717 * Returns the next objective ID for the given vlan id. It is expected
Saurav Das4ce45962015-11-24 23:21:05 -0800718 * that the next-objective has been pre-created from configuration.
Charles Chanc42e84e2015-10-20 16:24:19 -0700719 *
720 * @param deviceId Device ID
Charles Chan59cc16d2017-02-02 16:20:42 -0800721 * @param vlanId VLAN ID
Saurav Das4ce45962015-11-24 23:21:05 -0800722 * @return next objective ID or -1 if it was not found
Charles Chanc42e84e2015-10-20 16:24:19 -0700723 */
Charles Chan65238242017-06-22 18:03:14 -0700724 int getVlanNextObjectiveId(DeviceId deviceId, VlanId vlanId) {
Charles Chanc42e84e2015-10-20 16:24:19 -0700725 if (groupHandlerMap.get(deviceId) != null) {
Charles Chan59cc16d2017-02-02 16:20:42 -0800726 log.trace("getVlanNextObjectiveId query in device {}", deviceId);
727 return groupHandlerMap.get(deviceId).getVlanNextObjectiveId(vlanId);
Charles Chanc42e84e2015-10-20 16:24:19 -0700728 } else {
Charles Chan59cc16d2017-02-02 16:20:42 -0800729 log.warn("getVlanNextObjectiveId query - groupHandler for "
Saurav Das4ce45962015-11-24 23:21:05 -0800730 + "device {} not found", deviceId);
731 return -1;
732 }
733 }
734
735 /**
736 * Returns the next objective ID for the given portNumber, given the treatment.
737 * There could be multiple different treatments to the same outport, which
Saurav Das961beb22017-03-29 19:09:17 -0700738 * would result in different objectives. If the next object does not exist,
739 * and should be created, a new one is created and its id is returned.
Saurav Das4ce45962015-11-24 23:21:05 -0800740 *
741 * @param deviceId Device ID
742 * @param portNum port number on device for which NextObjective is queried
743 * @param treatment the actions to apply on the packets (should include outport)
744 * @param meta metadata passed into the creation of a Next Objective if necessary
Saurav Das961beb22017-03-29 19:09:17 -0700745 * @param createIfMissing true if a next object should be created if not found
Saurav Das59232cf2016-04-27 18:35:50 -0700746 * @return next objective ID or -1 if an error occurred during retrieval or creation
Saurav Das4ce45962015-11-24 23:21:05 -0800747 */
748 public int getPortNextObjectiveId(DeviceId deviceId, PortNumber portNum,
749 TrafficTreatment treatment,
Saurav Das961beb22017-03-29 19:09:17 -0700750 TrafficSelector meta,
751 boolean createIfMissing) {
Saurav Das4ce45962015-11-24 23:21:05 -0800752 DefaultGroupHandler ghdlr = groupHandlerMap.get(deviceId);
753 if (ghdlr != null) {
Saurav Das961beb22017-03-29 19:09:17 -0700754 return ghdlr.getPortNextObjectiveId(portNum, treatment, meta, createIfMissing);
Saurav Das4ce45962015-11-24 23:21:05 -0800755 } else {
Charles Chane849c192016-01-11 18:28:54 -0800756 log.warn("getPortNextObjectiveId query - groupHandler for device {}"
757 + " not found", deviceId);
758 return -1;
759 }
760 }
761
Saurav Dasc88d4662017-05-15 15:34:25 -0700762 /**
763 * Returns the group handler object for the specified device id.
764 *
765 * @param devId the device identifier
766 * @return the groupHandler object for the device id, or null if not found
767 */
Charles Chan65238242017-06-22 18:03:14 -0700768 DefaultGroupHandler getGroupHandler(DeviceId devId) {
Saurav Dasc88d4662017-05-15 15:34:25 -0700769 return groupHandlerMap.get(devId);
770 }
771
772 /**
Saurav Dasceccf242017-08-03 18:30:35 -0700773 * Returns the default routing handler object.
774 *
775 * @return the default routing handler object
776 */
777 public DefaultRoutingHandler getRoutingHandler() {
778 return defaultRoutingHandler;
779 }
780
781 /**
Saurav Dasc88d4662017-05-15 15:34:25 -0700782 * Returns true if this controller instance has seen this link before. The
783 * link may not be currently up, but as long as the link had been seen before
784 * this method will return true. The one exception is when the link was
785 * indeed seen before, but this controller instance was forced to forget it
786 * by a call to purgeSeenLink method.
787 *
788 * @param link the infrastructure link being queried
789 * @return true if this controller instance has seen this link before
790 */
Charles Chan65238242017-06-22 18:03:14 -0700791 boolean isSeenLink(Link link) {
Saurav Dasc88d4662017-05-15 15:34:25 -0700792 return seenLinks.containsKey(link);
793 }
794
795 /**
796 * Updates the seen link store. Updates can be for links that are currently
797 * available or not.
798 *
799 * @param link the link to update in the seen-link local store
800 * @param up the status of the link, true if up, false if down
801 */
Charles Chan65238242017-06-22 18:03:14 -0700802 void updateSeenLink(Link link, boolean up) {
Saurav Dasc88d4662017-05-15 15:34:25 -0700803 seenLinks.put(link, up);
804 }
805
806 /**
807 * Returns the status of a seen-link (up or down). If the link has not
808 * been seen-before, a null object is returned.
809 *
810 * @param link the infrastructure link being queried
811 * @return null if the link was not seen-before;
812 * true if the seen-link is up;
813 * false if the seen-link is down
814 */
Charles Chan65238242017-06-22 18:03:14 -0700815 Boolean isSeenLinkUp(Link link) {
Saurav Dasc88d4662017-05-15 15:34:25 -0700816 return seenLinks.get(link);
817 }
818
819 /**
820 * Makes this controller instance forget a previously seen before link.
821 *
822 * @param link the infrastructure link to purge
823 */
Charles Chan65238242017-06-22 18:03:14 -0700824 private void purgeSeenLink(Link link) {
Saurav Dasc88d4662017-05-15 15:34:25 -0700825 seenLinks.remove(link);
826 }
827
828 /**
829 * Returns the status of a link as parallel link. A parallel link
830 * is defined as a link which has common src and dst switches as another
831 * seen-link that is currently enabled. It is not necessary for the link being
832 * queried to be a seen-link.
833 *
834 * @param link the infrastructure link being queried
835 * @return true if a seen-link exists that is up, and shares the
836 * same src and dst switches as the link being queried
837 */
Charles Chan65238242017-06-22 18:03:14 -0700838 private boolean isParallelLink(Link link) {
Saurav Dasc88d4662017-05-15 15:34:25 -0700839 for (Entry<Link, Boolean> seen : seenLinks.entrySet()) {
840 Link seenLink = seen.getKey();
841 if (seenLink.equals(link)) {
842 continue;
843 }
844 if (seenLink.src().deviceId().equals(link.src().deviceId()) &&
845 seenLink.dst().deviceId().equals(link.dst().deviceId()) &&
846 seen.getValue()) {
847 return true;
848 }
849 }
850 return false;
851 }
852
Saurav Das7bcbe702017-06-13 15:35:54 -0700853 /**
854 * Returns true if the link being queried is a bidirectional link. A bidi
855 * link is defined as a link, whose reverse link - ie. the link in the reverse
856 * direction - has been seen-before and is up. It is not necessary for the link
857 * being queried to be a seen-link.
858 *
859 * @param link the infrastructure link being queried
860 * @return true if another unidirectional link exists in the reverse direction,
861 * has been seen-before and is up
862 */
863 public boolean isBidirectional(Link link) {
864 Link reverseLink = linkService.getLink(link.dst(), link.src());
865 if (reverseLink == null) {
866 return false;
867 }
868 Boolean result = isSeenLinkUp(reverseLink);
869 if (result == null) {
870 return false;
871 }
872 return result.booleanValue();
873 }
874
875 /**
876 * Determines if the given link should be avoided in routing calculations
877 * by policy or design.
878 *
879 * @param link the infrastructure link being queried
880 * @return true if link should be avoided
881 */
882 public boolean avoidLink(Link link) {
883 // XXX currently only avoids all pair-links. In the future can be
884 // extended to avoid any generic link
885 DeviceId src = link.src().deviceId();
886 PortNumber srcPort = link.src().port();
887 if (deviceConfiguration == null || !deviceConfiguration.isConfigured(src)) {
888 log.warn("Device {} not configured..cannot avoid link {}", src, link);
889 return false;
890 }
891 DeviceId pairDev;
892 PortNumber pairLocalPort, pairRemotePort = null;
893 try {
894 pairDev = deviceConfiguration.getPairDeviceId(src);
895 pairLocalPort = deviceConfiguration.getPairLocalPort(src);
896 if (pairDev != null) {
897 pairRemotePort = deviceConfiguration.getPairLocalPort(pairDev);
898 }
899 } catch (DeviceConfigNotFoundException e) {
900 log.warn("Pair dev for dev {} not configured..cannot avoid link {}",
901 src, link);
902 return false;
903 }
904
905 if (srcPort.equals(pairLocalPort) &&
906 link.dst().deviceId().equals(pairDev) &&
907 link.dst().port().equals(pairRemotePort)) {
908 return true;
909 }
910 return false;
911 }
912
sanghob35a6192015-04-01 13:05:26 -0700913 private class InternalPacketProcessor implements PacketProcessor {
sanghob35a6192015-04-01 13:05:26 -0700914 @Override
915 public void process(PacketContext context) {
916
917 if (context.isHandled()) {
918 return;
919 }
920
921 InboundPacket pkt = context.inPacket();
922 Ethernet ethernet = pkt.parsed();
Pier Luigi7dad71c2017-02-01 13:50:04 -0800923
924 if (ethernet == null) {
925 return;
926 }
927
Saurav Das7bcbe702017-06-13 15:35:54 -0700928 log.trace("Rcvd pktin from {}: {}", context.inPacket().receivedFrom(),
929 ethernet);
Pier Ventree0ae7a32016-11-23 09:57:42 -0800930 if (ethernet.getEtherType() == TYPE_ARP) {
Saurav Dasc88d4662017-05-15 15:34:25 -0700931 log.warn("Received unexpected ARP packet on {}",
932 context.inPacket().receivedFrom());
Saurav Das76ae6812017-03-15 15:15:14 -0700933 log.trace("{}", ethernet);
Pier Ventre968da122016-12-09 17:26:04 -0800934 return;
sanghob35a6192015-04-01 13:05:26 -0700935 } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV4) {
Pier Ventre735b8c82016-12-02 08:16:05 -0800936 IPv4 ipv4Packet = (IPv4) ethernet.getPayload();
937 //ipHandler.addToPacketBuffer(ipv4Packet);
938 if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_ICMP) {
939 icmpHandler.processIcmp(ethernet, pkt.receivedFrom());
sanghob35a6192015-04-01 13:05:26 -0700940 } else {
Charles Chan50035632017-01-13 17:20:44 -0800941 // NOTE: We don't support IP learning at this moment so this
942 // is not necessary. Also it causes duplication of DHCP packets.
Pier Ventre968da122016-12-09 17:26:04 -0800943 // ipHandler.processPacketIn(ipv4Packet, pkt.receivedFrom());
sanghob35a6192015-04-01 13:05:26 -0700944 }
Pier Ventre10bd8d12016-11-26 21:05:22 -0800945 } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV6) {
946 IPv6 ipv6Packet = (IPv6) ethernet.getPayload();
Pier Ventre735b8c82016-12-02 08:16:05 -0800947 //ipHandler.addToPacketBuffer(ipv6Packet);
Pier Luigi7dad71c2017-02-01 13:50:04 -0800948 // We deal with the packet only if the packet is a ICMP6 ECHO/REPLY
Pier Ventre735b8c82016-12-02 08:16:05 -0800949 if (ipv6Packet.getNextHeader() == IPv6.PROTOCOL_ICMP6) {
950 ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload();
951 if (icmp6Packet.getIcmpType() == ICMP6.ECHO_REQUEST ||
952 icmp6Packet.getIcmpType() == ICMP6.ECHO_REPLY) {
953 icmpHandler.processIcmpv6(ethernet, pkt.receivedFrom());
954 } else {
Saurav Dasc88d4662017-05-15 15:34:25 -0700955 log.trace("Received ICMPv6 0x{} - not handled",
Charles Chan0ed44fb2017-03-13 13:10:30 -0700956 Integer.toHexString(icmp6Packet.getIcmpType() & 0xff));
Pier Ventre735b8c82016-12-02 08:16:05 -0800957 }
958 } else {
959 // NOTE: We don't support IP learning at this moment so this
960 // is not necessary. Also it causes duplication of DHCPv6 packets.
961 // ipHandler.processPacketIn(ipv6Packet, pkt.receivedFrom());
962 }
sanghob35a6192015-04-01 13:05:26 -0700963 }
964 }
965 }
966
967 private class InternalLinkListener implements LinkListener {
968 @Override
969 public void event(LinkEvent event) {
Charles Chanb1f8c762017-03-29 16:39:05 -0700970 if (event.type() == LinkEvent.Type.LINK_ADDED ||
971 event.type() == LinkEvent.Type.LINK_UPDATED ||
972 event.type() == LinkEvent.Type.LINK_REMOVED) {
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700973 log.debug("Event {} received from Link Service", event.type());
sanghob35a6192015-04-01 13:05:26 -0700974 scheduleEventHandlerIfNotScheduled(event);
975 }
976 }
977 }
978
979 private class InternalDeviceListener implements DeviceListener {
sanghob35a6192015-04-01 13:05:26 -0700980 @Override
981 public void event(DeviceEvent event) {
sanghob35a6192015-04-01 13:05:26 -0700982 switch (event.type()) {
983 case DEVICE_ADDED:
Saurav Das1a129a02016-11-18 15:21:57 -0800984 case PORT_UPDATED:
985 case PORT_ADDED:
sangho20eff1d2015-04-13 15:15:58 -0700986 case DEVICE_UPDATED:
987 case DEVICE_AVAILABILITY_CHANGED:
Saurav Dasc88d4662017-05-15 15:34:25 -0700988 log.trace("Event {} received from Device Service", event.type());
sanghob35a6192015-04-01 13:05:26 -0700989 scheduleEventHandlerIfNotScheduled(event);
990 break;
991 default:
992 }
993 }
994 }
995
Saurav Das4ce45962015-11-24 23:21:05 -0800996 @SuppressWarnings("rawtypes")
sanghob35a6192015-04-01 13:05:26 -0700997 private void scheduleEventHandlerIfNotScheduled(Event event) {
Charles Chan65238242017-06-22 18:03:14 -0700998 synchronized (THREAD_SCHED_LOCK) {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700999 eventQueue.add(event);
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -07001000 numOfEventsQueued++;
1001
1002 if ((numOfHandlerScheduled - numOfHandlerExecution) == 0) {
1003 //No pending scheduled event handling threads. So start a new one.
Srikanth Vavilapalli23181912015-05-04 09:48:09 -07001004 eventHandlerFuture = executorService
1005 .schedule(eventHandler, 100, TimeUnit.MILLISECONDS);
1006 numOfHandlerScheduled++;
1007 }
Jonathan Hartc19f7c12016-04-12 15:39:44 -07001008 log.trace("numOfEventsQueued {}, numOfEventHandlerScheduled {}",
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -07001009 numOfEventsQueued,
1010 numOfHandlerScheduled);
sanghob35a6192015-04-01 13:05:26 -07001011 }
sanghob35a6192015-04-01 13:05:26 -07001012 }
1013
1014 private class InternalEventHandler implements Runnable {
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -07001015 @Override
sanghob35a6192015-04-01 13:05:26 -07001016 public void run() {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -07001017 try {
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -07001018 while (true) {
Saurav Das4ce45962015-11-24 23:21:05 -08001019 @SuppressWarnings("rawtypes")
Charles Chan65238242017-06-22 18:03:14 -07001020 Event event;
1021 synchronized (THREAD_SCHED_LOCK) {
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -07001022 if (!eventQueue.isEmpty()) {
1023 event = eventQueue.poll();
1024 numOfEventsExecuted++;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -07001025 } else {
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -07001026 numOfHandlerExecution++;
1027 log.debug("numOfHandlerExecution {} numOfEventsExecuted {}",
1028 numOfHandlerExecution, numOfEventsExecuted);
1029 break;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -07001030 }
sangho20eff1d2015-04-13 15:15:58 -07001031 }
Charles Chanb1f8c762017-03-29 16:39:05 -07001032 if (event.type() == LinkEvent.Type.LINK_ADDED ||
1033 event.type() == LinkEvent.Type.LINK_UPDATED) {
Saurav Dasc88d4662017-05-15 15:34:25 -07001034 // Note: do not update seenLinks here, otherwise every
1035 // link, even one seen for the first time, will be appear
1036 // to be a previously seen link
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -07001037 processLinkAdded((Link) event.subject());
1038 } else if (event.type() == LinkEvent.Type.LINK_REMOVED) {
Pier Ventre2c515312016-09-13 21:33:40 -07001039 Link linkRemoved = (Link) event.subject();
Saurav Dasc88d4662017-05-15 15:34:25 -07001040 if (linkRemoved.type() == Link.Type.DIRECT) {
1041 updateSeenLink(linkRemoved, false);
1042 }
1043 // device availability check helps to ensure that
1044 // multiple link-removed events are actually treated as a
1045 // single switch removed event. purgeSeenLink is necessary
1046 // so we do rerouting (instead of rehashing) when switch
1047 // comes back.
Pier Ventre2c515312016-09-13 21:33:40 -07001048 if (linkRemoved.src().elementId() instanceof DeviceId &&
1049 !deviceService.isAvailable(linkRemoved.src().deviceId())) {
Saurav Dasc88d4662017-05-15 15:34:25 -07001050 purgeSeenLink(linkRemoved);
Pier Ventre2c515312016-09-13 21:33:40 -07001051 continue;
1052 }
1053 if (linkRemoved.dst().elementId() instanceof DeviceId &&
1054 !deviceService.isAvailable(linkRemoved.dst().deviceId())) {
Saurav Dasc88d4662017-05-15 15:34:25 -07001055 purgeSeenLink(linkRemoved);
Pier Ventre2c515312016-09-13 21:33:40 -07001056 continue;
1057 }
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -07001058 processLinkRemoved((Link) event.subject());
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -07001059 } else if (event.type() == DeviceEvent.Type.DEVICE_ADDED ||
1060 event.type() == DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED ||
1061 event.type() == DeviceEvent.Type.DEVICE_UPDATED) {
Saurav Das423fe2b2015-12-04 10:52:59 -08001062 DeviceId deviceId = ((Device) event.subject()).id();
1063 if (deviceService.isAvailable(deviceId)) {
Saurav Das837e0bb2015-10-30 17:45:38 -07001064 log.info("Processing device event {} for available device {}",
1065 event.type(), ((Device) event.subject()).id());
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -07001066 processDeviceAdded((Device) event.subject());
Saurav Das80980c72016-03-23 11:22:49 -07001067 } else {
1068 log.info("Processing device event {} for unavailable device {}",
1069 event.type(), ((Device) event.subject()).id());
1070 processDeviceRemoved((Device) event.subject());
1071 }
Saurav Das1a129a02016-11-18 15:21:57 -08001072 } else if (event.type() == DeviceEvent.Type.PORT_ADDED) {
Saurav Dasd2fded02016-12-02 15:43:47 -08001073 // typically these calls come when device is added first time
1074 // so port filtering rules are handled at the device_added event.
1075 // port added calls represent all ports on the device,
1076 // enabled or not.
Saurav Dasc88d4662017-05-15 15:34:25 -07001077 log.trace("** PORT ADDED {}/{} -> {}",
Saurav Dasd2fded02016-12-02 15:43:47 -08001078 ((DeviceEvent) event).subject().id(),
1079 ((DeviceEvent) event).port().number(),
1080 event.type());
Saurav Das1a129a02016-11-18 15:21:57 -08001081 } else if (event.type() == DeviceEvent.Type.PORT_UPDATED) {
Saurav Dasd2fded02016-12-02 15:43:47 -08001082 // these calls happen for every subsequent event
1083 // ports enabled, disabled, switch goes away, comes back
Saurav Das1a129a02016-11-18 15:21:57 -08001084 log.info("** PORT UPDATED {}/{} -> {}",
1085 event.subject(),
1086 ((DeviceEvent) event).port(),
1087 event.type());
1088 processPortUpdated(((Device) event.subject()),
1089 ((DeviceEvent) event).port());
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -07001090 } else {
1091 log.warn("Unhandled event type: {}", event.type());
1092 }
sanghob35a6192015-04-01 13:05:26 -07001093 }
Srikanth Vavilapalli23181912015-05-04 09:48:09 -07001094 } catch (Exception e) {
1095 log.error("SegmentRouting event handler "
1096 + "thread thrown an exception: {}", e);
sanghob35a6192015-04-01 13:05:26 -07001097 }
sanghob35a6192015-04-01 13:05:26 -07001098 }
1099 }
1100
sanghob35a6192015-04-01 13:05:26 -07001101 private void processLinkAdded(Link link) {
Saurav Dasb5c236e2016-06-07 10:08:06 -07001102 log.info("** LINK ADDED {}", link.toString());
Charles Chan0b4e6182015-11-03 10:42:14 -08001103 if (!deviceConfiguration.isConfigured(link.src().deviceId())) {
Saurav Das7bcbe702017-06-13 15:35:54 -07001104 log.warn("Source device of this link is not configured..not processing");
Charles Chan0b4e6182015-11-03 10:42:14 -08001105 return;
1106 }
Saurav Dasc88d4662017-05-15 15:34:25 -07001107 if (link.type() != Link.Type.DIRECT) {
1108 // NOTE: A DIRECT link might be transiently marked as INDIRECT
1109 // if BDDP is received before LLDP. We can safely ignore that
1110 // until the LLDP is received and the link is marked as DIRECT.
1111 log.info("Ignore link {}->{}. Link type is {} instead of DIRECT.",
1112 link.src(), link.dst(), link.type());
1113 return;
1114 }
1115
1116 //Irrespective of whether the local is a MASTER or not for this device,
1117 //create group handler instance and push default TTP flow rules if needed,
1118 //as in a multi-instance setup, instances can initiate groups for any device.
Srikanth Vavilapalli23181912015-05-04 09:48:09 -07001119 DefaultGroupHandler groupHandler = groupHandlerMap.get(link.src()
1120 .deviceId());
1121 if (groupHandler != null) {
Saurav Dasc88d4662017-05-15 15:34:25 -07001122 groupHandler.portUpForLink(link);
Srikanth Vavilapalli23181912015-05-04 09:48:09 -07001123 } else {
1124 Device device = deviceService.getDevice(link.src().deviceId());
1125 if (device != null) {
1126 log.warn("processLinkAdded: Link Added "
1127 + "Notification without Device Added "
1128 + "event, still handling it");
1129 processDeviceAdded(device);
1130 groupHandler = groupHandlerMap.get(link.src()
1131 .deviceId());
Saurav Dasc88d4662017-05-15 15:34:25 -07001132 groupHandler.portUpForLink(link);
sanghob35a6192015-04-01 13:05:26 -07001133 }
1134 }
Srikanth Vavilapalli23181912015-05-04 09:48:09 -07001135
Saurav Das7bcbe702017-06-13 15:35:54 -07001136 /*// process link only if it is bidirectional
1137 if (!isBidirectional(link)) {
1138 log.debug("Link not bidirectional.. waiting for other direction "
1139 + "src {} --> dst {} ", link.dst(), link.src());
1140 // note that if we are not processing for routing, it should at least
1141 // be considered a seen-link
1142 updateSeenLink(link, true);
1143 return;
1144 }
1145 TO DO this ensure that rehash is still done correctly even if link is
1146 not processed for rerouting - perhaps rehash in both directions when
1147 it ultimately becomes bidi?
1148 */
1149
1150 log.debug("Starting optimized route population process for link "
1151 + "{} --> {}", link.src(), link.dst());
Saurav Dasc88d4662017-05-15 15:34:25 -07001152 boolean seenBefore = isSeenLink(link);
1153 defaultRoutingHandler.populateRoutingRulesForLinkStatusChange(null, link, null);
Saurav Das7bcbe702017-06-13 15:35:54 -07001154
1155 // It's possible that linkUp causes no route-path change as ECMP graph does
1156 // not change if the link is a parallel link (same src-dst as another link.
1157 // However we still need to update ECMP hash groups to include new buckets
1158 // for the link that has come up.
Saurav Dasc88d4662017-05-15 15:34:25 -07001159 if (mastershipService.isLocalMaster(link.src().deviceId())) {
Saurav Das7bcbe702017-06-13 15:35:54 -07001160 if (!seenBefore && isParallelLink(link)) {
Saurav Dasc88d4662017-05-15 15:34:25 -07001161 // if link seen first time, we need to ensure hash-groups have all ports
Saurav Das7bcbe702017-06-13 15:35:54 -07001162 log.debug("Attempting retryHash for paralled first-time link {}", link);
Saurav Dasc88d4662017-05-15 15:34:25 -07001163 groupHandler.retryHash(link, false, true);
1164 } else {
1165 //seen before-link
1166 if (isParallelLink(link)) {
Saurav Das7bcbe702017-06-13 15:35:54 -07001167 log.debug("Attempting retryHash for paralled seen-before "
1168 + "link {}", link);
Saurav Dasc88d4662017-05-15 15:34:25 -07001169 groupHandler.retryHash(link, false, false);
1170 }
1171 }
1172 }
Charles Chan2199c302016-04-23 17:36:10 -07001173
1174 mcastHandler.init();
sanghob35a6192015-04-01 13:05:26 -07001175 }
1176
1177 private void processLinkRemoved(Link link) {
Saurav Dasb5c236e2016-06-07 10:08:06 -07001178 log.info("** LINK REMOVED {}", link.toString());
Saurav Dasc88d4662017-05-15 15:34:25 -07001179 defaultRoutingHandler.populateRoutingRulesForLinkStatusChange(link, null, null);
1180
1181 // update local groupHandler stores
sangho834e4b02015-05-01 09:38:25 -07001182 DefaultGroupHandler groupHandler = groupHandlerMap.get(link.src().deviceId());
1183 if (groupHandler != null) {
Saurav Dasc88d4662017-05-15 15:34:25 -07001184 if (mastershipService.isLocalMaster(link.src().deviceId()) &&
1185 isParallelLink(link)) {
1186 groupHandler.retryHash(link, true, false);
1187 }
1188 // ensure local stores are updated
1189 groupHandler.portDown(link.src().port());
1190 } else {
1191 log.warn("group handler not found for dev:{} when removing link: {}",
1192 link.src().deviceId(), link);
sangho834e4b02015-05-01 09:38:25 -07001193 }
Charles Chan2199c302016-04-23 17:36:10 -07001194
1195 mcastHandler.processLinkDown(link);
sanghob35a6192015-04-01 13:05:26 -07001196 }
1197
1198 private void processDeviceAdded(Device device) {
Saurav Dasb5c236e2016-06-07 10:08:06 -07001199 log.info("** DEVICE ADDED with ID {}", device.id());
Charles Chan91ccbf72017-06-27 18:48:32 -07001200
1201 // NOTE: Punt ARP/NDP even when the device is not configured.
1202 // Host learning without network config is required for CORD config generator.
1203 routingRulePopulator.populateIpPunts(device.id());
1204 routingRulePopulator.populateArpNdpPunts(device.id());
1205
Charles Chan0b4e6182015-11-03 10:42:14 -08001206 if (deviceConfiguration == null || !deviceConfiguration.isConfigured(device.id())) {
Saurav Das7bcbe702017-06-13 15:35:54 -07001207 log.warn("Device configuration unavailable. Device {} will be "
1208 + "processed after configuration.", device.id());
Saurav Das2857f382015-11-03 14:39:27 -08001209 return;
1210 }
Charles Chan2199c302016-04-23 17:36:10 -07001211 processDeviceAddedInternal(device.id());
1212 }
1213
1214 private void processDeviceAddedInternal(DeviceId deviceId) {
Saurav Das837e0bb2015-10-30 17:45:38 -07001215 // Irrespective of whether the local is a MASTER or not for this device,
1216 // we need to create a SR-group-handler instance. This is because in a
1217 // multi-instance setup, any instance can initiate forwarding/next-objectives
1218 // for any switch (even if this instance is a SLAVE or not even connected
1219 // to the switch). To handle this, a default-group-handler instance is necessary
1220 // per switch.
Charles Chan2199c302016-04-23 17:36:10 -07001221 log.debug("Current groupHandlerMap devs: {}", groupHandlerMap.keySet());
1222 if (groupHandlerMap.get(deviceId) == null) {
Charles Chan0b4e6182015-11-03 10:42:14 -08001223 DefaultGroupHandler groupHandler;
1224 try {
1225 groupHandler = DefaultGroupHandler.
Charles Chan2199c302016-04-23 17:36:10 -07001226 createGroupHandler(deviceId,
1227 appId,
1228 deviceConfiguration,
1229 linkService,
1230 flowObjectiveService,
1231 this);
Charles Chan0b4e6182015-11-03 10:42:14 -08001232 } catch (DeviceConfigNotFoundException e) {
1233 log.warn(e.getMessage() + " Aborting processDeviceAdded.");
1234 return;
1235 }
Charles Chan2199c302016-04-23 17:36:10 -07001236 log.debug("updating groupHandlerMap with new config for device: {}",
1237 deviceId);
1238 groupHandlerMap.put(deviceId, groupHandler);
Saurav Das2857f382015-11-03 14:39:27 -08001239 }
Saurav Dasb5c236e2016-06-07 10:08:06 -07001240
Charles Chan2199c302016-04-23 17:36:10 -07001241 if (mastershipService.isLocalMaster(deviceId)) {
Saurav Das018605f2017-02-18 14:05:44 -08001242 defaultRoutingHandler.populatePortAddressingRules(deviceId);
Charles Chan03a73e02016-10-24 14:52:01 -07001243 hostHandler.init(deviceId);
Charles Chanfc5c7802016-05-17 13:13:55 -07001244 xConnectHandler.init(deviceId);
Charles Chan2199c302016-04-23 17:36:10 -07001245 DefaultGroupHandler groupHandler = groupHandlerMap.get(deviceId);
Charles Chan59cc16d2017-02-02 16:20:42 -08001246 groupHandler.createGroupsFromVlanConfig();
Charles Chan2199c302016-04-23 17:36:10 -07001247 routingRulePopulator.populateSubnetBroadcastRule(deviceId);
Charles Chanc42e84e2015-10-20 16:24:19 -07001248 }
Charles Chan5270ed02016-01-30 23:22:37 -08001249
Charles Chan03a73e02016-10-24 14:52:01 -07001250 appCfgHandler.init(deviceId);
1251 routeHandler.init(deviceId);
sanghob35a6192015-04-01 13:05:26 -07001252 }
1253
Saurav Das80980c72016-03-23 11:22:49 -07001254 private void processDeviceRemoved(Device device) {
Saurav Das7bcbe702017-06-13 15:35:54 -07001255 dsNextObjStore.entrySet().stream()
Saurav Das80980c72016-03-23 11:22:49 -07001256 .filter(entry -> entry.getKey().deviceId().equals(device.id()))
1257 .forEach(entry -> {
Saurav Das7bcbe702017-06-13 15:35:54 -07001258 dsNextObjStore.remove(entry.getKey());
Saurav Das80980c72016-03-23 11:22:49 -07001259 });
Charles Chan59cc16d2017-02-02 16:20:42 -08001260 vlanNextObjStore.entrySet().stream()
Saurav Das80980c72016-03-23 11:22:49 -07001261 .filter(entry -> entry.getKey().deviceId().equals(device.id()))
Charles Chan65238242017-06-22 18:03:14 -07001262 .forEach(entry -> vlanNextObjStore.remove(entry.getKey()));
Saurav Das80980c72016-03-23 11:22:49 -07001263 portNextObjStore.entrySet().stream()
1264 .filter(entry -> entry.getKey().deviceId().equals(device.id()))
Charles Chan65238242017-06-22 18:03:14 -07001265 .forEach(entry -> portNextObjStore.remove(entry.getKey()));
Charles Chaned3742352017-06-15 00:44:51 -07001266
1267 seenLinks.keySet().removeIf(key -> key.src().deviceId().equals(device.id()) ||
1268 key.dst().deviceId().equals(device.id()));
1269
Saurav Dasceccf242017-08-03 18:30:35 -07001270 DefaultGroupHandler gh = groupHandlerMap.remove(device.id());
1271 if (gh != null) {
1272 gh.shutdown();
1273 }
Saurav Das80980c72016-03-23 11:22:49 -07001274 defaultRoutingHandler.purgeEcmpGraph(device.id());
Saurav Dasc88d4662017-05-15 15:34:25 -07001275 // Note that a switch going down is associated with all of its links
1276 // going down as well, but it is treated as a single switch down event
1277 // while the link-downs are ignored.
1278 defaultRoutingHandler
1279 .populateRoutingRulesForLinkStatusChange(null, null, device.id());
Charles Chan2199c302016-04-23 17:36:10 -07001280 mcastHandler.removeDevice(device.id());
Charles Chanfc5c7802016-05-17 13:13:55 -07001281 xConnectHandler.removeDevice(device.id());
Saurav Das80980c72016-03-23 11:22:49 -07001282 }
1283
Saurav Das1a129a02016-11-18 15:21:57 -08001284 private void processPortUpdated(Device device, Port port) {
1285 if (deviceConfiguration == null || !deviceConfiguration.isConfigured(device.id())) {
1286 log.warn("Device configuration uploading. Not handling port event for"
1287 + "dev: {} port: {}", device.id(), port.number());
1288 return;
1289 }
Saurav Das018605f2017-02-18 14:05:44 -08001290
1291 if (!mastershipService.isLocalMaster(device.id())) {
1292 log.debug("Not master for dev:{} .. not handling port updated event"
1293 + "for port {}", device.id(), port.number());
1294 return;
1295 }
1296
1297 // first we handle filtering rules associated with the port
1298 if (port.isEnabled()) {
1299 log.info("Switchport {}/{} enabled..programming filters",
1300 device.id(), port.number());
Charles Chan7e4f8192017-02-26 22:59:35 -08001301 routingRulePopulator.processSinglePortFilters(device.id(), port.number(), true);
Saurav Das018605f2017-02-18 14:05:44 -08001302 } else {
1303 log.info("Switchport {}/{} disabled..removing filters",
1304 device.id(), port.number());
Charles Chan7e4f8192017-02-26 22:59:35 -08001305 routingRulePopulator.processSinglePortFilters(device.id(), port.number(), false);
Saurav Das018605f2017-02-18 14:05:44 -08001306 }
Saurav Das1a129a02016-11-18 15:21:57 -08001307
1308 // portUpdated calls are for ports that have gone down or up. For switch
1309 // to switch ports, link-events should take care of any re-routing or
1310 // group editing necessary for port up/down. Here we only process edge ports
1311 // that are already configured.
Saurav Dasb0ae6ee2017-03-04 16:08:47 -08001312 ConnectPoint cp = new ConnectPoint(device.id(), port.number());
1313 VlanId untaggedVlan = getUntaggedVlanId(cp);
1314 VlanId nativeVlan = getNativeVlanId(cp);
1315 Set<VlanId> taggedVlans = getTaggedVlanId(cp);
Charles Chan59cc16d2017-02-02 16:20:42 -08001316
Saurav Dasb0ae6ee2017-03-04 16:08:47 -08001317 if (untaggedVlan == null && nativeVlan == null && taggedVlans.isEmpty()) {
Saurav Dasc88d4662017-05-15 15:34:25 -07001318 log.debug("Not handling port updated event for non-edge port (unconfigured) "
Saurav Das1a129a02016-11-18 15:21:57 -08001319 + "dev/port: {}/{}", device.id(), port.number());
1320 return;
1321 }
Saurav Dasb0ae6ee2017-03-04 16:08:47 -08001322 if (untaggedVlan != null) {
1323 processEdgePort(device, port, untaggedVlan, true);
1324 }
1325 if (nativeVlan != null) {
1326 processEdgePort(device, port, nativeVlan, true);
1327 }
1328 if (!taggedVlans.isEmpty()) {
1329 taggedVlans.forEach(tag -> processEdgePort(device, port, tag, false));
1330 }
Saurav Das1a129a02016-11-18 15:21:57 -08001331 }
1332
Saurav Dasb0ae6ee2017-03-04 16:08:47 -08001333 private void processEdgePort(Device device, Port port, VlanId vlanId,
1334 boolean popVlan) {
Saurav Das1a129a02016-11-18 15:21:57 -08001335 boolean portUp = port.isEnabled();
1336 if (portUp) {
Saurav Dasb0ae6ee2017-03-04 16:08:47 -08001337 log.info("Device:EdgePort {}:{} is enabled in vlan: {}", device.id(),
Charles Chan59cc16d2017-02-02 16:20:42 -08001338 port.number(), vlanId);
Saurav Das1a129a02016-11-18 15:21:57 -08001339 } else {
Saurav Dasb0ae6ee2017-03-04 16:08:47 -08001340 log.info("Device:EdgePort {}:{} is disabled in vlan: {}", device.id(),
Charles Chan59cc16d2017-02-02 16:20:42 -08001341 port.number(), vlanId);
Saurav Das1a129a02016-11-18 15:21:57 -08001342 }
1343
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -07001344 DefaultGroupHandler groupHandler = groupHandlerMap.get(device.id());
sanghob35a6192015-04-01 13:05:26 -07001345 if (groupHandler != null) {
Saurav Dasb0ae6ee2017-03-04 16:08:47 -08001346 groupHandler.processEdgePort(port.number(), vlanId, popVlan, portUp);
Saurav Das1a129a02016-11-18 15:21:57 -08001347 } else {
1348 log.warn("Group handler not found for dev:{}. Not handling edge port"
1349 + " {} event for port:{}", device.id(),
1350 (portUp) ? "UP" : "DOWN", port.number());
sanghob35a6192015-04-01 13:05:26 -07001351 }
1352 }
sangho1e575652015-05-14 00:39:53 -07001353
Pier Ventre10bd8d12016-11-26 21:05:22 -08001354 /**
1355 * Registers the given connect point with the NRS, this is necessary
1356 * to receive the NDP and ARP packets from the NRS.
1357 *
1358 * @param portToRegister connect point to register
1359 */
1360 public void registerConnectPoint(ConnectPoint portToRegister) {
Charles Chan0aa674e2017-02-23 15:44:08 -08001361 neighbourResolutionService.registerNeighbourHandler(
Pier Ventre10bd8d12016-11-26 21:05:22 -08001362 portToRegister,
1363 neighbourHandler,
1364 appId
1365 );
1366 }
1367
Charles Chand6832882015-10-05 17:50:33 -07001368 private class InternalConfigListener implements NetworkConfigListener {
Saurav Das7bcbe702017-06-13 15:35:54 -07001369 private static final long PROGRAM_DELAY = 2;
Charles Chan2c15aca2016-11-09 20:51:44 -08001370 SegmentRoutingManager srManager;
Charles Chan4636be02015-10-07 14:21:45 -07001371
Charles Chane849c192016-01-11 18:28:54 -08001372 /**
1373 * Constructs the internal network config listener.
1374 *
Charles Chan2c15aca2016-11-09 20:51:44 -08001375 * @param srManager segment routing manager
Charles Chane849c192016-01-11 18:28:54 -08001376 */
Charles Chan65238242017-06-22 18:03:14 -07001377 InternalConfigListener(SegmentRoutingManager srManager) {
Charles Chan2c15aca2016-11-09 20:51:44 -08001378 this.srManager = srManager;
Charles Chan4636be02015-10-07 14:21:45 -07001379 }
1380
Charles Chane849c192016-01-11 18:28:54 -08001381 /**
1382 * Reads network config and initializes related data structure accordingly.
1383 */
Charles Chan4636be02015-10-07 14:21:45 -07001384 public void configureNetwork() {
Saurav Das7bcbe702017-06-13 15:35:54 -07001385 if (deviceConfiguration == null) {
1386 deviceConfiguration = new DeviceConfiguration(srManager);
1387 } else {
1388 deviceConfiguration.updateConfig();
1389 }
Charles Chan4636be02015-10-07 14:21:45 -07001390
Charles Chan2c15aca2016-11-09 20:51:44 -08001391 arpHandler = new ArpHandler(srManager);
1392 icmpHandler = new IcmpHandler(srManager);
1393 ipHandler = new IpHandler(srManager);
1394 routingRulePopulator = new RoutingRulePopulator(srManager);
1395 defaultRoutingHandler = new DefaultRoutingHandler(srManager);
Charles Chan4636be02015-10-07 14:21:45 -07001396
1397 tunnelHandler = new TunnelHandler(linkService, deviceConfiguration,
1398 groupHandlerMap, tunnelStore);
1399 policyHandler = new PolicyHandler(appId, deviceConfiguration,
1400 flowObjectiveService,
1401 tunnelHandler, policyStore);
Saurav Das7bcbe702017-06-13 15:35:54 -07001402 // add a small delay to absorb multiple network config added notifications
1403 if (!programmingScheduled.get()) {
1404 programmingScheduled.set(true);
1405 executorService.schedule(new ConfigChange(), PROGRAM_DELAY,
1406 TimeUnit.SECONDS);
Charles Chan4636be02015-10-07 14:21:45 -07001407 }
Charles Chan2199c302016-04-23 17:36:10 -07001408 mcastHandler.init();
Charles Chan4636be02015-10-07 14:21:45 -07001409 }
1410
Charles Chand6832882015-10-05 17:50:33 -07001411 @Override
1412 public void event(NetworkConfigEvent event) {
Charles Chan5270ed02016-01-30 23:22:37 -08001413 // TODO move this part to NetworkConfigEventHandler
1414 if (event.configClass().equals(SegmentRoutingDeviceConfig.class)) {
1415 switch (event.type()) {
1416 case CONFIG_ADDED:
Charles Chan278ce832017-06-26 15:25:09 -07001417 log.info("Segment Routing Device Config added for {}", event.subject());
Charles Chan5270ed02016-01-30 23:22:37 -08001418 configureNetwork();
1419 break;
1420 case CONFIG_UPDATED:
Charles Chan278ce832017-06-26 15:25:09 -07001421 log.info("Segment Routing Config updated for {}", event.subject());
1422 // TODO support dynamic configuration
1423 break;
1424 default:
1425 break;
1426 }
1427 } else if (event.configClass().equals(InterfaceConfig.class)) {
1428 switch (event.type()) {
1429 case CONFIG_ADDED:
1430 log.info("Interface Config added for {}", event.subject());
1431 configureNetwork();
1432 break;
1433 case CONFIG_UPDATED:
1434 log.info("Interface Config updated for {}", event.subject());
Charles Chan5270ed02016-01-30 23:22:37 -08001435 // TODO support dynamic configuration
1436 break;
1437 default:
1438 break;
Charles Chanb8e10c82015-10-14 11:24:40 -07001439 }
Charles Chan5270ed02016-01-30 23:22:37 -08001440 } else if (event.configClass().equals(SegmentRoutingAppConfig.class)) {
Charles Chanfc5c7802016-05-17 13:13:55 -07001441 checkState(appCfgHandler != null, "NetworkConfigEventHandler is not initialized");
Charles Chan5270ed02016-01-30 23:22:37 -08001442 switch (event.type()) {
1443 case CONFIG_ADDED:
Charles Chanfc5c7802016-05-17 13:13:55 -07001444 appCfgHandler.processAppConfigAdded(event);
Charles Chan5270ed02016-01-30 23:22:37 -08001445 break;
1446 case CONFIG_UPDATED:
Charles Chanfc5c7802016-05-17 13:13:55 -07001447 appCfgHandler.processAppConfigUpdated(event);
Charles Chan5270ed02016-01-30 23:22:37 -08001448 break;
1449 case CONFIG_REMOVED:
Charles Chanfc5c7802016-05-17 13:13:55 -07001450 appCfgHandler.processAppConfigRemoved(event);
1451 break;
1452 default:
1453 break;
1454 }
Charles Chan03a73e02016-10-24 14:52:01 -07001455 configureNetwork();
Charles Chanfc5c7802016-05-17 13:13:55 -07001456 } else if (event.configClass().equals(XConnectConfig.class)) {
1457 checkState(xConnectHandler != null, "XConnectHandler is not initialized");
1458 switch (event.type()) {
1459 case CONFIG_ADDED:
1460 xConnectHandler.processXConnectConfigAdded(event);
1461 break;
1462 case CONFIG_UPDATED:
1463 xConnectHandler.processXConnectConfigUpdated(event);
1464 break;
1465 case CONFIG_REMOVED:
1466 xConnectHandler.processXConnectConfigRemoved(event);
Charles Chan5270ed02016-01-30 23:22:37 -08001467 break;
1468 default:
1469 break;
Charles Chanb8e10c82015-10-14 11:24:40 -07001470 }
Pier Ventref34966c2016-11-07 16:21:04 -08001471 } else if (event.configClass().equals(PwaasConfig.class)) {
1472 checkState(l2TunnelHandler != null, "L2TunnelHandler is not initialized");
1473 switch (event.type()) {
1474 case CONFIG_ADDED:
1475 l2TunnelHandler.processPwaasConfigAdded(event);
1476 break;
1477 case CONFIG_UPDATED:
1478 l2TunnelHandler.processPwaasConfigUpdated(event);
1479 break;
1480 case CONFIG_REMOVED:
1481 l2TunnelHandler.processPwaasConfigRemoved(event);
1482 break;
1483 default:
1484 break;
1485 }
Charles Chand6832882015-10-05 17:50:33 -07001486 }
1487 }
Saurav Das7bcbe702017-06-13 15:35:54 -07001488
1489 private final class ConfigChange implements Runnable {
1490 @Override
1491 public void run() {
1492 programmingScheduled.set(false);
1493 for (Device device : deviceService.getDevices()) {
1494 processDeviceAdded(device);
1495 }
1496 defaultRoutingHandler.startPopulationProcess();
1497 }
1498 }
Charles Chand6832882015-10-05 17:50:33 -07001499 }
Charles Chan68aa62d2015-11-09 16:37:23 -08001500
1501 private class InternalHostListener implements HostListener {
Charles Chan68aa62d2015-11-09 16:37:23 -08001502 @Override
1503 public void event(HostEvent event) {
Charles Chan68aa62d2015-11-09 16:37:23 -08001504 switch (event.type()) {
1505 case HOST_ADDED:
Charles Chand2990362016-04-18 13:44:03 -07001506 hostHandler.processHostAddedEvent(event);
Charles Chan68aa62d2015-11-09 16:37:23 -08001507 break;
1508 case HOST_MOVED:
Charles Chand2990362016-04-18 13:44:03 -07001509 hostHandler.processHostMovedEvent(event);
Charles Chan68aa62d2015-11-09 16:37:23 -08001510 break;
1511 case HOST_REMOVED:
Charles Chanf9a52702017-06-16 15:19:24 -07001512 hostHandler.processHostRemovedEvent(event);
Charles Chan68aa62d2015-11-09 16:37:23 -08001513 break;
1514 case HOST_UPDATED:
Charles Chand2990362016-04-18 13:44:03 -07001515 hostHandler.processHostUpdatedEvent(event);
Charles Chan68aa62d2015-11-09 16:37:23 -08001516 break;
1517 default:
1518 log.warn("Unsupported host event type: {}", event.type());
1519 break;
1520 }
1521 }
1522 }
1523
Charles Chand55e84d2016-03-30 17:54:24 -07001524 private class InternalMcastListener implements McastListener {
1525 @Override
1526 public void event(McastEvent event) {
1527 switch (event.type()) {
1528 case SOURCE_ADDED:
Charles Chand2990362016-04-18 13:44:03 -07001529 mcastHandler.processSourceAdded(event);
Charles Chand55e84d2016-03-30 17:54:24 -07001530 break;
1531 case SINK_ADDED:
Charles Chand2990362016-04-18 13:44:03 -07001532 mcastHandler.processSinkAdded(event);
Charles Chand55e84d2016-03-30 17:54:24 -07001533 break;
1534 case SINK_REMOVED:
Charles Chand2990362016-04-18 13:44:03 -07001535 mcastHandler.processSinkRemoved(event);
Charles Chand55e84d2016-03-30 17:54:24 -07001536 break;
1537 case ROUTE_ADDED:
1538 case ROUTE_REMOVED:
1539 default:
1540 break;
1541 }
1542 }
1543 }
Charles Chan35fd1a72016-06-13 18:54:31 -07001544
Charles Chan03a73e02016-10-24 14:52:01 -07001545 private class InternalRouteEventListener implements RouteListener {
1546 @Override
1547 public void event(RouteEvent event) {
1548 switch (event.type()) {
1549 case ROUTE_ADDED:
1550 routeHandler.processRouteAdded(event);
1551 break;
1552 case ROUTE_UPDATED:
1553 routeHandler.processRouteUpdated(event);
1554 break;
1555 case ROUTE_REMOVED:
1556 routeHandler.processRouteRemoved(event);
1557 break;
1558 default:
1559 break;
1560 }
1561 }
1562 }
Saurav Dasc88d4662017-05-15 15:34:25 -07001563
sanghob35a6192015-04-01 13:05:26 -07001564}