blob: 69a807926fe823dbda31c91ebcc352e866d1ea9b [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;
Pier Luigi721b6622017-02-03 13:34:21 -080041import org.onosproject.incubator.net.intf.Interface;
Charles Chan2c15aca2016-11-09 20:51:44 -080042import org.onosproject.incubator.net.intf.InterfaceService;
Charles Chan03a73e02016-10-24 14:52:01 -070043import org.onosproject.incubator.net.routing.RouteEvent;
44import org.onosproject.incubator.net.routing.RouteListener;
45import org.onosproject.incubator.net.routing.RouteService;
Pier Ventre735b8c82016-12-02 08:16:05 -080046import org.onosproject.incubator.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 Chand2990362016-04-18 13:44:03 -070091import org.onosproject.segmentrouting.storekey.SubnetAssignedVidStoreKey;
Charles Chan59cc16d2017-02-02 16:20:42 -080092import org.onosproject.segmentrouting.storekey.VlanNextObjectiveStoreKey;
Charles Chanfc5c7802016-05-17 13:13:55 -070093import org.onosproject.segmentrouting.storekey.XConnectStoreKey;
Pier Ventref34966c2016-11-07 16:21:04 -080094import org.onosproject.segmentrouting.pwaas.L2TunnelHandler;
Jonathan Hartc19f7c12016-04-12 15:39:44 -070095import org.onosproject.store.serializers.KryoNamespaces;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -070096import org.onosproject.store.service.EventuallyConsistentMap;
97import org.onosproject.store.service.EventuallyConsistentMapBuilder;
98import org.onosproject.store.service.StorageService;
99import org.onosproject.store.service.WallClockTimestamp;
sanghob35a6192015-04-01 13:05:26 -0700100import org.slf4j.Logger;
101import org.slf4j.LoggerFactory;
102
sangho1e575652015-05-14 00:39:53 -0700103import java.util.List;
sanghob35a6192015-04-01 13:05:26 -0700104import java.util.Map;
Saurav Dasc88d4662017-05-15 15:34:25 -0700105import java.util.Map.Entry;
Charles Chan65238242017-06-22 18:03:14 -0700106import java.util.Optional;
Saurav Das0e99e2b2015-10-28 12:39:42 -0700107import java.util.Set;
sanghob35a6192015-04-01 13:05:26 -0700108import java.util.concurrent.ConcurrentHashMap;
109import java.util.concurrent.ConcurrentLinkedQueue;
110import java.util.concurrent.Executors;
111import java.util.concurrent.ScheduledExecutorService;
112import java.util.concurrent.ScheduledFuture;
113import java.util.concurrent.TimeUnit;
Saurav Das7bcbe702017-06-13 15:35:54 -0700114import java.util.concurrent.atomic.AtomicBoolean;
Charles Chan7ffd81f2017-02-08 15:52:08 -0800115import java.util.stream.Collectors;
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");
Pier Luigi7e415132017-01-12 22:46:39 -0800364 compCfgService.preSetProperty("org.onosproject.incubator.net.neighbour.impl.NeighbourResolutionManager",
365 "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 Chan73316522017-07-20 16:16:25 -0700372 compCfgService.preSetProperty("org.onosproject.incubator.store.routing.impl.RouteStoreImpl",
373 "distributed", "true");
Saurav Das80980c72016-03-23 11:22:49 -0700374
Charles Chanb8e10c82015-10-14 11:24:40 -0700375 processor = new InternalPacketProcessor();
376 linkListener = new InternalLinkListener();
377 deviceListener = new InternalDeviceListener();
Charles Chanfc5c7802016-05-17 13:13:55 -0700378 appCfgHandler = new AppConfigHandler(this);
379 xConnectHandler = new XConnectHandler(this);
Charles Chand2990362016-04-18 13:44:03 -0700380 mcastHandler = new McastHandler(this);
381 hostHandler = new HostHandler(this);
Charles Chan03a73e02016-10-24 14:52:01 -0700382 routeHandler = new RouteHandler(this);
Pier Ventre735b8c82016-12-02 08:16:05 -0800383 neighbourHandler = new SegmentRoutingNeighbourDispatcher(this);
Pier Ventref34966c2016-11-07 16:21:04 -0800384 l2TunnelHandler = new L2TunnelHandler(this);
Charles Chanb8e10c82015-10-14 11:24:40 -0700385
Charles Chan3e783d02016-02-26 22:19:52 -0800386 cfgService.addListener(cfgListener);
Charles Chand55e84d2016-03-30 17:54:24 -0700387 cfgService.registerConfigFactory(deviceConfigFactory);
388 cfgService.registerConfigFactory(appConfigFactory);
Charles Chanfc5c7802016-05-17 13:13:55 -0700389 cfgService.registerConfigFactory(xConnectConfigFactory);
Charles Chand55e84d2016-03-30 17:54:24 -0700390 cfgService.registerConfigFactory(mcastConfigFactory);
Pier Ventref34966c2016-11-07 16:21:04 -0800391 cfgService.registerConfigFactory(pwaasConfigFactory);
Charles Chan5270ed02016-01-30 23:22:37 -0800392 hostService.addListener(hostListener);
Charles Chanb8e10c82015-10-14 11:24:40 -0700393 packetService.addProcessor(processor, PacketProcessor.director(2));
394 linkService.addListener(linkListener);
395 deviceService.addListener(deviceListener);
Charles Chand55e84d2016-03-30 17:54:24 -0700396 multicastRouteService.addListener(mcastListener);
Charles Chanc7a8a682017-06-19 00:43:31 -0700397 routeService.addListener(routeListener);
Charles Chanb8e10c82015-10-14 11:24:40 -0700398
399 cfgListener.configureNetwork();
400
sanghob35a6192015-04-01 13:05:26 -0700401 log.info("Started");
402 }
403
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700404 private KryoNamespace.Builder createSerializer() {
405 return new KryoNamespace.Builder()
406 .register(KryoNamespaces.API)
Saurav Das7bcbe702017-06-13 15:35:54 -0700407 .register(DestinationSetNextObjectiveStoreKey.class,
Charles Chan59cc16d2017-02-02 16:20:42 -0800408 VlanNextObjectiveStoreKey.class,
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700409 SubnetAssignedVidStoreKey.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();
495 for (Device device : deviceService.getDevices()) {
Saurav Das018605f2017-02-18 14:05:44 -0800496 if (mastershipService.isLocalMaster(device.id())) {
497 defaultRoutingHandler.populatePortAddressingRules(device.id());
498 }
Saurav Das59232cf2016-04-27 18:35:50 -0700499 }
500 defaultRoutingHandler.startPopulationProcess();
501 }
502
Charles Chanc81c45b2016-10-20 17:02:44 -0700503 @Override
Pier Ventre10bd8d12016-11-26 21:05:22 -0800504 public Map<DeviceId, Set<IpPrefix>> getDeviceSubnetMap() {
505 Map<DeviceId, Set<IpPrefix>> deviceSubnetMap = Maps.newHashMap();
Charles Chanc81c45b2016-10-20 17:02:44 -0700506 deviceService.getAvailableDevices().forEach(device -> {
507 deviceSubnetMap.put(device.id(), deviceConfiguration.getSubnets(device.id()));
508 });
509 return deviceSubnetMap;
510 }
511
Saurav Dasc88d4662017-05-15 15:34:25 -0700512
513 @Override
514 public ImmutableMap<DeviceId, EcmpShortestPathGraph> getCurrentEcmpSpg() {
515 if (defaultRoutingHandler != null) {
516 return defaultRoutingHandler.getCurrentEmcpSpgMap();
517 } else {
518 return null;
519 }
520 }
521
522 @Override
Saurav Das7bcbe702017-06-13 15:35:54 -0700523 public ImmutableMap<DestinationSetNextObjectiveStoreKey, NextNeighbors> getDestinationSet() {
524 if (dsNextObjStore != null) {
525 return ImmutableMap.copyOf(dsNextObjStore.entrySet());
Saurav Dasc88d4662017-05-15 15:34:25 -0700526 } else {
527 return ImmutableMap.of();
528 }
529 }
530
sanghof9d0bf12015-05-19 11:57:42 -0700531 /**
Ray Milkeye4afdb52017-04-05 09:42:04 -0700532 * Extracts the application ID from the manager.
533 *
534 * @return application ID
535 */
536 public ApplicationId appId() {
537 return appId;
538 }
539
540 /**
541 * Returns the device configuration.
542 *
543 * @return device configuration
544 */
545 public DeviceConfiguration deviceConfiguration() {
546 return deviceConfiguration;
547 }
548
549 /**
Saurav Das7bcbe702017-06-13 15:35:54 -0700550 * Per device next objective ID store with (device id + destination set) as key.
Ray Milkeye4afdb52017-04-05 09:42:04 -0700551 *
552 * @return next objective ID store
553 */
Saurav Das7bcbe702017-06-13 15:35:54 -0700554 public EventuallyConsistentMap<DestinationSetNextObjectiveStoreKey, NextNeighbors>
555 dsNextObjStore() {
556 return dsNextObjStore;
Ray Milkeye4afdb52017-04-05 09:42:04 -0700557 }
558
559 /**
560 * Per device next objective ID store with (device id + subnet) as key.
561 *
562 * @return vlan next object store
563 */
564 public EventuallyConsistentMap<VlanNextObjectiveStoreKey, Integer> vlanNextObjStore() {
565 return vlanNextObjStore;
566 }
567
568 /**
569 * Per device next objective ID store with (device id + port) as key.
570 *
571 * @return port next object store.
572 */
573 public EventuallyConsistentMap<PortNextObjectiveStoreKey, Integer> portNextObjStore() {
574 return portNextObjStore;
575 }
576
577 /**
Saurav Das7bcbe702017-06-13 15:35:54 -0700578 * Returns the MPLS-ECMP configuration which indicates whether ECMP on
579 * labeled packets should be programmed or not.
Pier Ventre98161782016-10-31 15:00:01 -0700580 *
581 * @return MPLS-ECMP value
582 */
583 public boolean getMplsEcmp() {
584 SegmentRoutingAppConfig segmentRoutingAppConfig = cfgService
585 .getConfig(this.appId, SegmentRoutingAppConfig.class);
586 return segmentRoutingAppConfig != null && segmentRoutingAppConfig.mplsEcmp();
587 }
588
589 /**
sanghof9d0bf12015-05-19 11:57:42 -0700590 * Returns the tunnel object with the tunnel ID.
591 *
592 * @param tunnelId Tunnel ID
593 * @return Tunnel reference
594 */
sangho1e575652015-05-14 00:39:53 -0700595 public Tunnel getTunnel(String tunnelId) {
596 return tunnelHandler.getTunnel(tunnelId);
597 }
598
Charles Chan7ffd81f2017-02-08 15:52:08 -0800599 // TODO Consider moving these to InterfaceService
sanghob35a6192015-04-01 13:05:26 -0700600 /**
Charles Chan59cc16d2017-02-02 16:20:42 -0800601 * Returns untagged VLAN configured on given connect point.
Charles Chan7ffd81f2017-02-08 15:52:08 -0800602 * <p>
603 * Only returns the first match if there are multiple untagged VLAN configured
604 * on the connect point.
sanghob35a6192015-04-01 13:05:26 -0700605 *
Charles Chan59cc16d2017-02-02 16:20:42 -0800606 * @param connectPoint connect point
607 * @return untagged VLAN or null if not configured
sanghob35a6192015-04-01 13:05:26 -0700608 */
Charles Chan65238242017-06-22 18:03:14 -0700609 VlanId getUntaggedVlanId(ConnectPoint connectPoint) {
Charles Chan59cc16d2017-02-02 16:20:42 -0800610 return interfaceService.getInterfacesByPort(connectPoint).stream()
611 .filter(intf -> !intf.vlanUntagged().equals(VlanId.NONE))
612 .map(Interface::vlanUntagged)
613 .findFirst().orElse(null);
sanghob35a6192015-04-01 13:05:26 -0700614 }
615
sangho1e575652015-05-14 00:39:53 -0700616 /**
Charles Chan7ffd81f2017-02-08 15:52:08 -0800617 * Returns tagged VLAN configured on given connect point.
618 * <p>
619 * Returns all matches if there are multiple tagged VLAN configured
620 * on the connect point.
621 *
622 * @param connectPoint connect point
623 * @return tagged VLAN or empty set if not configured
624 */
Charles Chan65238242017-06-22 18:03:14 -0700625 Set<VlanId> getTaggedVlanId(ConnectPoint connectPoint) {
Charles Chan7ffd81f2017-02-08 15:52:08 -0800626 Set<Interface> interfaces = interfaceService.getInterfacesByPort(connectPoint);
627 return interfaces.stream()
628 .map(Interface::vlanTagged)
Charles Chan65238242017-06-22 18:03:14 -0700629 .flatMap(Set::stream)
Charles Chan7ffd81f2017-02-08 15:52:08 -0800630 .collect(Collectors.toSet());
631 }
632
633 /**
634 * Returns native VLAN configured on given connect point.
635 * <p>
636 * Only returns the first match if there are multiple native VLAN configured
637 * on the connect point.
638 *
639 * @param connectPoint connect point
640 * @return native VLAN or null if not configured
641 */
Charles Chan65238242017-06-22 18:03:14 -0700642 VlanId getNativeVlanId(ConnectPoint connectPoint) {
Charles Chan7ffd81f2017-02-08 15:52:08 -0800643 Set<Interface> interfaces = interfaceService.getInterfacesByPort(connectPoint);
644 return interfaces.stream()
645 .filter(intf -> !intf.vlanNative().equals(VlanId.NONE))
646 .map(Interface::vlanNative)
647 .findFirst()
648 .orElse(null);
649 }
650
651 /**
Charles Chanf9a52702017-06-16 15:19:24 -0700652 * Returns internal VLAN for untagged hosts on given connect point.
653 * <p>
654 * The internal VLAN is either vlan-untagged for an access port,
655 * or vlan-native for a trunk port.
656 *
657 * @param connectPoint connect point
658 * @return internal VLAN or null if both vlan-untagged and vlan-native are undefined
659 */
Charles Chan65238242017-06-22 18:03:14 -0700660 VlanId getInternalVlanId(ConnectPoint connectPoint) {
Charles Chanf9a52702017-06-16 15:19:24 -0700661 VlanId untaggedVlanId = getUntaggedVlanId(connectPoint);
662 VlanId nativeVlanId = getNativeVlanId(connectPoint);
663 return untaggedVlanId != null ? untaggedVlanId : nativeVlanId;
664 }
665
666 /**
Charles Chan65238242017-06-22 18:03:14 -0700667 * Returns optional pair device ID of given device.
668 *
669 * @param deviceId device ID
670 * @return optional pair device ID. Might be empty if pair device is not configured
671 */
672 Optional<DeviceId> getPairDeviceId(DeviceId deviceId) {
673 SegmentRoutingDeviceConfig deviceConfig =
674 cfgService.getConfig(deviceId, SegmentRoutingDeviceConfig.class);
675 return Optional.ofNullable(deviceConfig).map(SegmentRoutingDeviceConfig::pairDeviceId);
676 }
677 /**
678 * Returns optional pair device local port of given device.
679 *
680 * @param deviceId device ID
681 * @return optional pair device ID. Might be empty if pair device is not configured
682 */
683 Optional<PortNumber> getPairLocalPorts(DeviceId deviceId) {
684 SegmentRoutingDeviceConfig deviceConfig =
685 cfgService.getConfig(deviceId, SegmentRoutingDeviceConfig.class);
686 return Optional.ofNullable(deviceConfig).map(SegmentRoutingDeviceConfig::pairLocalPort);
687 }
688
689 /**
Charles Chan7ffd81f2017-02-08 15:52:08 -0800690 * Returns vlan port map of given device.
691 *
692 * @param deviceId device id
693 * @return vlan-port multimap
694 */
695 public Multimap<VlanId, PortNumber> getVlanPortMap(DeviceId deviceId) {
696 HashMultimap<VlanId, PortNumber> vlanPortMap = HashMultimap.create();
697
698 interfaceService.getInterfaces().stream()
699 .filter(intf -> intf.connectPoint().deviceId().equals(deviceId))
700 .forEach(intf -> {
701 vlanPortMap.put(intf.vlanUntagged(), intf.connectPoint().port());
Charles Chan65238242017-06-22 18:03:14 -0700702 intf.vlanTagged().forEach(vlanTagged ->
703 vlanPortMap.put(vlanTagged, intf.connectPoint().port())
704 );
Charles Chan7ffd81f2017-02-08 15:52:08 -0800705 vlanPortMap.put(intf.vlanNative(), intf.connectPoint().port());
706 });
707 vlanPortMap.removeAll(VlanId.NONE);
708
709 return vlanPortMap;
710 }
711
712 /**
Saurav Das4ce45962015-11-24 23:21:05 -0800713 * Returns the next objective ID for the given subnet prefix. It is expected
Charles Chan59cc16d2017-02-02 16:20:42 -0800714 * Returns the next objective ID for the given vlan id. It is expected
Saurav Das4ce45962015-11-24 23:21:05 -0800715 * that the next-objective has been pre-created from configuration.
Charles Chanc42e84e2015-10-20 16:24:19 -0700716 *
717 * @param deviceId Device ID
Charles Chan59cc16d2017-02-02 16:20:42 -0800718 * @param vlanId VLAN ID
Saurav Das4ce45962015-11-24 23:21:05 -0800719 * @return next objective ID or -1 if it was not found
Charles Chanc42e84e2015-10-20 16:24:19 -0700720 */
Charles Chan65238242017-06-22 18:03:14 -0700721 int getVlanNextObjectiveId(DeviceId deviceId, VlanId vlanId) {
Charles Chanc42e84e2015-10-20 16:24:19 -0700722 if (groupHandlerMap.get(deviceId) != null) {
Charles Chan59cc16d2017-02-02 16:20:42 -0800723 log.trace("getVlanNextObjectiveId query in device {}", deviceId);
724 return groupHandlerMap.get(deviceId).getVlanNextObjectiveId(vlanId);
Charles Chanc42e84e2015-10-20 16:24:19 -0700725 } else {
Charles Chan59cc16d2017-02-02 16:20:42 -0800726 log.warn("getVlanNextObjectiveId query - groupHandler for "
Saurav Das4ce45962015-11-24 23:21:05 -0800727 + "device {} not found", deviceId);
728 return -1;
729 }
730 }
731
732 /**
733 * Returns the next objective ID for the given portNumber, given the treatment.
734 * There could be multiple different treatments to the same outport, which
Saurav Das961beb22017-03-29 19:09:17 -0700735 * would result in different objectives. If the next object does not exist,
736 * and should be created, a new one is created and its id is returned.
Saurav Das4ce45962015-11-24 23:21:05 -0800737 *
738 * @param deviceId Device ID
739 * @param portNum port number on device for which NextObjective is queried
740 * @param treatment the actions to apply on the packets (should include outport)
741 * @param meta metadata passed into the creation of a Next Objective if necessary
Saurav Das961beb22017-03-29 19:09:17 -0700742 * @param createIfMissing true if a next object should be created if not found
Saurav Das59232cf2016-04-27 18:35:50 -0700743 * @return next objective ID or -1 if an error occurred during retrieval or creation
Saurav Das4ce45962015-11-24 23:21:05 -0800744 */
745 public int getPortNextObjectiveId(DeviceId deviceId, PortNumber portNum,
746 TrafficTreatment treatment,
Saurav Das961beb22017-03-29 19:09:17 -0700747 TrafficSelector meta,
748 boolean createIfMissing) {
Saurav Das4ce45962015-11-24 23:21:05 -0800749 DefaultGroupHandler ghdlr = groupHandlerMap.get(deviceId);
750 if (ghdlr != null) {
Saurav Das961beb22017-03-29 19:09:17 -0700751 return ghdlr.getPortNextObjectiveId(portNum, treatment, meta, createIfMissing);
Saurav Das4ce45962015-11-24 23:21:05 -0800752 } else {
Charles Chane849c192016-01-11 18:28:54 -0800753 log.warn("getPortNextObjectiveId query - groupHandler for device {}"
754 + " not found", deviceId);
755 return -1;
756 }
757 }
758
Saurav Dasc88d4662017-05-15 15:34:25 -0700759 /**
760 * Returns the group handler object for the specified device id.
761 *
762 * @param devId the device identifier
763 * @return the groupHandler object for the device id, or null if not found
764 */
Charles Chan65238242017-06-22 18:03:14 -0700765 DefaultGroupHandler getGroupHandler(DeviceId devId) {
Saurav Dasc88d4662017-05-15 15:34:25 -0700766 return groupHandlerMap.get(devId);
767 }
768
769 /**
770 * Returns true if this controller instance has seen this link before. The
771 * link may not be currently up, but as long as the link had been seen before
772 * this method will return true. The one exception is when the link was
773 * indeed seen before, but this controller instance was forced to forget it
774 * by a call to purgeSeenLink method.
775 *
776 * @param link the infrastructure link being queried
777 * @return true if this controller instance has seen this link before
778 */
Charles Chan65238242017-06-22 18:03:14 -0700779 boolean isSeenLink(Link link) {
Saurav Dasc88d4662017-05-15 15:34:25 -0700780 return seenLinks.containsKey(link);
781 }
782
783 /**
784 * Updates the seen link store. Updates can be for links that are currently
785 * available or not.
786 *
787 * @param link the link to update in the seen-link local store
788 * @param up the status of the link, true if up, false if down
789 */
Charles Chan65238242017-06-22 18:03:14 -0700790 void updateSeenLink(Link link, boolean up) {
Saurav Dasc88d4662017-05-15 15:34:25 -0700791 seenLinks.put(link, up);
792 }
793
794 /**
795 * Returns the status of a seen-link (up or down). If the link has not
796 * been seen-before, a null object is returned.
797 *
798 * @param link the infrastructure link being queried
799 * @return null if the link was not seen-before;
800 * true if the seen-link is up;
801 * false if the seen-link is down
802 */
Charles Chan65238242017-06-22 18:03:14 -0700803 Boolean isSeenLinkUp(Link link) {
Saurav Dasc88d4662017-05-15 15:34:25 -0700804 return seenLinks.get(link);
805 }
806
807 /**
808 * Makes this controller instance forget a previously seen before link.
809 *
810 * @param link the infrastructure link to purge
811 */
Charles Chan65238242017-06-22 18:03:14 -0700812 private void purgeSeenLink(Link link) {
Saurav Dasc88d4662017-05-15 15:34:25 -0700813 seenLinks.remove(link);
814 }
815
816 /**
817 * Returns the status of a link as parallel link. A parallel link
818 * is defined as a link which has common src and dst switches as another
819 * seen-link that is currently enabled. It is not necessary for the link being
820 * queried to be a seen-link.
821 *
822 * @param link the infrastructure link being queried
823 * @return true if a seen-link exists that is up, and shares the
824 * same src and dst switches as the link being queried
825 */
Charles Chan65238242017-06-22 18:03:14 -0700826 private boolean isParallelLink(Link link) {
Saurav Dasc88d4662017-05-15 15:34:25 -0700827 for (Entry<Link, Boolean> seen : seenLinks.entrySet()) {
828 Link seenLink = seen.getKey();
829 if (seenLink.equals(link)) {
830 continue;
831 }
832 if (seenLink.src().deviceId().equals(link.src().deviceId()) &&
833 seenLink.dst().deviceId().equals(link.dst().deviceId()) &&
834 seen.getValue()) {
835 return true;
836 }
837 }
838 return false;
839 }
840
Saurav Das7bcbe702017-06-13 15:35:54 -0700841 /**
842 * Returns true if the link being queried is a bidirectional link. A bidi
843 * link is defined as a link, whose reverse link - ie. the link in the reverse
844 * direction - has been seen-before and is up. It is not necessary for the link
845 * being queried to be a seen-link.
846 *
847 * @param link the infrastructure link being queried
848 * @return true if another unidirectional link exists in the reverse direction,
849 * has been seen-before and is up
850 */
851 public boolean isBidirectional(Link link) {
852 Link reverseLink = linkService.getLink(link.dst(), link.src());
853 if (reverseLink == null) {
854 return false;
855 }
856 Boolean result = isSeenLinkUp(reverseLink);
857 if (result == null) {
858 return false;
859 }
860 return result.booleanValue();
861 }
862
863 /**
864 * Determines if the given link should be avoided in routing calculations
865 * by policy or design.
866 *
867 * @param link the infrastructure link being queried
868 * @return true if link should be avoided
869 */
870 public boolean avoidLink(Link link) {
871 // XXX currently only avoids all pair-links. In the future can be
872 // extended to avoid any generic link
873 DeviceId src = link.src().deviceId();
874 PortNumber srcPort = link.src().port();
875 if (deviceConfiguration == null || !deviceConfiguration.isConfigured(src)) {
876 log.warn("Device {} not configured..cannot avoid link {}", src, link);
877 return false;
878 }
879 DeviceId pairDev;
880 PortNumber pairLocalPort, pairRemotePort = null;
881 try {
882 pairDev = deviceConfiguration.getPairDeviceId(src);
883 pairLocalPort = deviceConfiguration.getPairLocalPort(src);
884 if (pairDev != null) {
885 pairRemotePort = deviceConfiguration.getPairLocalPort(pairDev);
886 }
887 } catch (DeviceConfigNotFoundException e) {
888 log.warn("Pair dev for dev {} not configured..cannot avoid link {}",
889 src, link);
890 return false;
891 }
892
893 if (srcPort.equals(pairLocalPort) &&
894 link.dst().deviceId().equals(pairDev) &&
895 link.dst().port().equals(pairRemotePort)) {
896 return true;
897 }
898 return false;
899 }
900
sanghob35a6192015-04-01 13:05:26 -0700901 private class InternalPacketProcessor implements PacketProcessor {
sanghob35a6192015-04-01 13:05:26 -0700902 @Override
903 public void process(PacketContext context) {
904
905 if (context.isHandled()) {
906 return;
907 }
908
909 InboundPacket pkt = context.inPacket();
910 Ethernet ethernet = pkt.parsed();
Pier Luigi7dad71c2017-02-01 13:50:04 -0800911
912 if (ethernet == null) {
913 return;
914 }
915
Saurav Das7bcbe702017-06-13 15:35:54 -0700916 log.trace("Rcvd pktin from {}: {}", context.inPacket().receivedFrom(),
917 ethernet);
Pier Ventree0ae7a32016-11-23 09:57:42 -0800918 if (ethernet.getEtherType() == TYPE_ARP) {
Saurav Dasc88d4662017-05-15 15:34:25 -0700919 log.warn("Received unexpected ARP packet on {}",
920 context.inPacket().receivedFrom());
Saurav Das76ae6812017-03-15 15:15:14 -0700921 log.trace("{}", ethernet);
Pier Ventre968da122016-12-09 17:26:04 -0800922 return;
sanghob35a6192015-04-01 13:05:26 -0700923 } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV4) {
Pier Ventre735b8c82016-12-02 08:16:05 -0800924 IPv4 ipv4Packet = (IPv4) ethernet.getPayload();
925 //ipHandler.addToPacketBuffer(ipv4Packet);
926 if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_ICMP) {
927 icmpHandler.processIcmp(ethernet, pkt.receivedFrom());
sanghob35a6192015-04-01 13:05:26 -0700928 } else {
Charles Chan50035632017-01-13 17:20:44 -0800929 // NOTE: We don't support IP learning at this moment so this
930 // is not necessary. Also it causes duplication of DHCP packets.
Pier Ventre968da122016-12-09 17:26:04 -0800931 // ipHandler.processPacketIn(ipv4Packet, pkt.receivedFrom());
sanghob35a6192015-04-01 13:05:26 -0700932 }
Pier Ventre10bd8d12016-11-26 21:05:22 -0800933 } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV6) {
934 IPv6 ipv6Packet = (IPv6) ethernet.getPayload();
Pier Ventre735b8c82016-12-02 08:16:05 -0800935 //ipHandler.addToPacketBuffer(ipv6Packet);
Pier Luigi7dad71c2017-02-01 13:50:04 -0800936 // We deal with the packet only if the packet is a ICMP6 ECHO/REPLY
Pier Ventre735b8c82016-12-02 08:16:05 -0800937 if (ipv6Packet.getNextHeader() == IPv6.PROTOCOL_ICMP6) {
938 ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload();
939 if (icmp6Packet.getIcmpType() == ICMP6.ECHO_REQUEST ||
940 icmp6Packet.getIcmpType() == ICMP6.ECHO_REPLY) {
941 icmpHandler.processIcmpv6(ethernet, pkt.receivedFrom());
942 } else {
Saurav Dasc88d4662017-05-15 15:34:25 -0700943 log.trace("Received ICMPv6 0x{} - not handled",
Charles Chan0ed44fb2017-03-13 13:10:30 -0700944 Integer.toHexString(icmp6Packet.getIcmpType() & 0xff));
Pier Ventre735b8c82016-12-02 08:16:05 -0800945 }
946 } else {
947 // NOTE: We don't support IP learning at this moment so this
948 // is not necessary. Also it causes duplication of DHCPv6 packets.
949 // ipHandler.processPacketIn(ipv6Packet, pkt.receivedFrom());
950 }
sanghob35a6192015-04-01 13:05:26 -0700951 }
952 }
953 }
954
955 private class InternalLinkListener implements LinkListener {
956 @Override
957 public void event(LinkEvent event) {
Charles Chanb1f8c762017-03-29 16:39:05 -0700958 if (event.type() == LinkEvent.Type.LINK_ADDED ||
959 event.type() == LinkEvent.Type.LINK_UPDATED ||
960 event.type() == LinkEvent.Type.LINK_REMOVED) {
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700961 log.debug("Event {} received from Link Service", event.type());
sanghob35a6192015-04-01 13:05:26 -0700962 scheduleEventHandlerIfNotScheduled(event);
963 }
964 }
965 }
966
967 private class InternalDeviceListener implements DeviceListener {
sanghob35a6192015-04-01 13:05:26 -0700968 @Override
969 public void event(DeviceEvent event) {
sanghob35a6192015-04-01 13:05:26 -0700970 switch (event.type()) {
971 case DEVICE_ADDED:
Saurav Das1a129a02016-11-18 15:21:57 -0800972 case PORT_UPDATED:
973 case PORT_ADDED:
sangho20eff1d2015-04-13 15:15:58 -0700974 case DEVICE_UPDATED:
975 case DEVICE_AVAILABILITY_CHANGED:
Saurav Dasc88d4662017-05-15 15:34:25 -0700976 log.trace("Event {} received from Device Service", event.type());
sanghob35a6192015-04-01 13:05:26 -0700977 scheduleEventHandlerIfNotScheduled(event);
978 break;
979 default:
980 }
981 }
982 }
983
Saurav Das4ce45962015-11-24 23:21:05 -0800984 @SuppressWarnings("rawtypes")
sanghob35a6192015-04-01 13:05:26 -0700985 private void scheduleEventHandlerIfNotScheduled(Event event) {
Charles Chan65238242017-06-22 18:03:14 -0700986 synchronized (THREAD_SCHED_LOCK) {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700987 eventQueue.add(event);
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700988 numOfEventsQueued++;
989
990 if ((numOfHandlerScheduled - numOfHandlerExecution) == 0) {
991 //No pending scheduled event handling threads. So start a new one.
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700992 eventHandlerFuture = executorService
993 .schedule(eventHandler, 100, TimeUnit.MILLISECONDS);
994 numOfHandlerScheduled++;
995 }
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700996 log.trace("numOfEventsQueued {}, numOfEventHandlerScheduled {}",
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700997 numOfEventsQueued,
998 numOfHandlerScheduled);
sanghob35a6192015-04-01 13:05:26 -0700999 }
sanghob35a6192015-04-01 13:05:26 -07001000 }
1001
1002 private class InternalEventHandler implements Runnable {
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -07001003 @Override
sanghob35a6192015-04-01 13:05:26 -07001004 public void run() {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -07001005 try {
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -07001006 while (true) {
Saurav Das4ce45962015-11-24 23:21:05 -08001007 @SuppressWarnings("rawtypes")
Charles Chan65238242017-06-22 18:03:14 -07001008 Event event;
1009 synchronized (THREAD_SCHED_LOCK) {
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -07001010 if (!eventQueue.isEmpty()) {
1011 event = eventQueue.poll();
1012 numOfEventsExecuted++;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -07001013 } else {
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -07001014 numOfHandlerExecution++;
1015 log.debug("numOfHandlerExecution {} numOfEventsExecuted {}",
1016 numOfHandlerExecution, numOfEventsExecuted);
1017 break;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -07001018 }
sangho20eff1d2015-04-13 15:15:58 -07001019 }
Charles Chanb1f8c762017-03-29 16:39:05 -07001020 if (event.type() == LinkEvent.Type.LINK_ADDED ||
1021 event.type() == LinkEvent.Type.LINK_UPDATED) {
Saurav Dasc88d4662017-05-15 15:34:25 -07001022 // Note: do not update seenLinks here, otherwise every
1023 // link, even one seen for the first time, will be appear
1024 // to be a previously seen link
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -07001025 processLinkAdded((Link) event.subject());
1026 } else if (event.type() == LinkEvent.Type.LINK_REMOVED) {
Pier Ventre2c515312016-09-13 21:33:40 -07001027 Link linkRemoved = (Link) event.subject();
Saurav Dasc88d4662017-05-15 15:34:25 -07001028 if (linkRemoved.type() == Link.Type.DIRECT) {
1029 updateSeenLink(linkRemoved, false);
1030 }
1031 // device availability check helps to ensure that
1032 // multiple link-removed events are actually treated as a
1033 // single switch removed event. purgeSeenLink is necessary
1034 // so we do rerouting (instead of rehashing) when switch
1035 // comes back.
Pier Ventre2c515312016-09-13 21:33:40 -07001036 if (linkRemoved.src().elementId() instanceof DeviceId &&
1037 !deviceService.isAvailable(linkRemoved.src().deviceId())) {
Saurav Dasc88d4662017-05-15 15:34:25 -07001038 purgeSeenLink(linkRemoved);
Pier Ventre2c515312016-09-13 21:33:40 -07001039 continue;
1040 }
1041 if (linkRemoved.dst().elementId() instanceof DeviceId &&
1042 !deviceService.isAvailable(linkRemoved.dst().deviceId())) {
Saurav Dasc88d4662017-05-15 15:34:25 -07001043 purgeSeenLink(linkRemoved);
Pier Ventre2c515312016-09-13 21:33:40 -07001044 continue;
1045 }
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -07001046 processLinkRemoved((Link) event.subject());
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -07001047 } else if (event.type() == DeviceEvent.Type.DEVICE_ADDED ||
1048 event.type() == DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED ||
1049 event.type() == DeviceEvent.Type.DEVICE_UPDATED) {
Saurav Das423fe2b2015-12-04 10:52:59 -08001050 DeviceId deviceId = ((Device) event.subject()).id();
1051 if (deviceService.isAvailable(deviceId)) {
Saurav Das837e0bb2015-10-30 17:45:38 -07001052 log.info("Processing device event {} for available device {}",
1053 event.type(), ((Device) event.subject()).id());
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -07001054 processDeviceAdded((Device) event.subject());
Saurav Das80980c72016-03-23 11:22:49 -07001055 } else {
1056 log.info("Processing device event {} for unavailable device {}",
1057 event.type(), ((Device) event.subject()).id());
1058 processDeviceRemoved((Device) event.subject());
1059 }
Saurav Das1a129a02016-11-18 15:21:57 -08001060 } else if (event.type() == DeviceEvent.Type.PORT_ADDED) {
Saurav Dasd2fded02016-12-02 15:43:47 -08001061 // typically these calls come when device is added first time
1062 // so port filtering rules are handled at the device_added event.
1063 // port added calls represent all ports on the device,
1064 // enabled or not.
Saurav Dasc88d4662017-05-15 15:34:25 -07001065 log.trace("** PORT ADDED {}/{} -> {}",
Saurav Dasd2fded02016-12-02 15:43:47 -08001066 ((DeviceEvent) event).subject().id(),
1067 ((DeviceEvent) event).port().number(),
1068 event.type());
Saurav Das1a129a02016-11-18 15:21:57 -08001069 } else if (event.type() == DeviceEvent.Type.PORT_UPDATED) {
Saurav Dasd2fded02016-12-02 15:43:47 -08001070 // these calls happen for every subsequent event
1071 // ports enabled, disabled, switch goes away, comes back
Saurav Das1a129a02016-11-18 15:21:57 -08001072 log.info("** PORT UPDATED {}/{} -> {}",
1073 event.subject(),
1074 ((DeviceEvent) event).port(),
1075 event.type());
1076 processPortUpdated(((Device) event.subject()),
1077 ((DeviceEvent) event).port());
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -07001078 } else {
1079 log.warn("Unhandled event type: {}", event.type());
1080 }
sanghob35a6192015-04-01 13:05:26 -07001081 }
Srikanth Vavilapalli23181912015-05-04 09:48:09 -07001082 } catch (Exception e) {
1083 log.error("SegmentRouting event handler "
1084 + "thread thrown an exception: {}", e);
sanghob35a6192015-04-01 13:05:26 -07001085 }
sanghob35a6192015-04-01 13:05:26 -07001086 }
1087 }
1088
sanghob35a6192015-04-01 13:05:26 -07001089 private void processLinkAdded(Link link) {
Saurav Dasb5c236e2016-06-07 10:08:06 -07001090 log.info("** LINK ADDED {}", link.toString());
Charles Chan0b4e6182015-11-03 10:42:14 -08001091 if (!deviceConfiguration.isConfigured(link.src().deviceId())) {
Saurav Das7bcbe702017-06-13 15:35:54 -07001092 log.warn("Source device of this link is not configured..not processing");
Charles Chan0b4e6182015-11-03 10:42:14 -08001093 return;
1094 }
Saurav Dasc88d4662017-05-15 15:34:25 -07001095 if (link.type() != Link.Type.DIRECT) {
1096 // NOTE: A DIRECT link might be transiently marked as INDIRECT
1097 // if BDDP is received before LLDP. We can safely ignore that
1098 // until the LLDP is received and the link is marked as DIRECT.
1099 log.info("Ignore link {}->{}. Link type is {} instead of DIRECT.",
1100 link.src(), link.dst(), link.type());
1101 return;
1102 }
1103
1104 //Irrespective of whether the local is a MASTER or not for this device,
1105 //create group handler instance and push default TTP flow rules if needed,
1106 //as in a multi-instance setup, instances can initiate groups for any device.
Srikanth Vavilapalli23181912015-05-04 09:48:09 -07001107 DefaultGroupHandler groupHandler = groupHandlerMap.get(link.src()
1108 .deviceId());
1109 if (groupHandler != null) {
Saurav Dasc88d4662017-05-15 15:34:25 -07001110 groupHandler.portUpForLink(link);
Srikanth Vavilapalli23181912015-05-04 09:48:09 -07001111 } else {
1112 Device device = deviceService.getDevice(link.src().deviceId());
1113 if (device != null) {
1114 log.warn("processLinkAdded: Link Added "
1115 + "Notification without Device Added "
1116 + "event, still handling it");
1117 processDeviceAdded(device);
1118 groupHandler = groupHandlerMap.get(link.src()
1119 .deviceId());
Saurav Dasc88d4662017-05-15 15:34:25 -07001120 groupHandler.portUpForLink(link);
sanghob35a6192015-04-01 13:05:26 -07001121 }
1122 }
Srikanth Vavilapalli23181912015-05-04 09:48:09 -07001123
Saurav Das7bcbe702017-06-13 15:35:54 -07001124 /*// process link only if it is bidirectional
1125 if (!isBidirectional(link)) {
1126 log.debug("Link not bidirectional.. waiting for other direction "
1127 + "src {} --> dst {} ", link.dst(), link.src());
1128 // note that if we are not processing for routing, it should at least
1129 // be considered a seen-link
1130 updateSeenLink(link, true);
1131 return;
1132 }
1133 TO DO this ensure that rehash is still done correctly even if link is
1134 not processed for rerouting - perhaps rehash in both directions when
1135 it ultimately becomes bidi?
1136 */
1137
1138 log.debug("Starting optimized route population process for link "
1139 + "{} --> {}", link.src(), link.dst());
Saurav Dasc88d4662017-05-15 15:34:25 -07001140 boolean seenBefore = isSeenLink(link);
1141 defaultRoutingHandler.populateRoutingRulesForLinkStatusChange(null, link, null);
Saurav Das7bcbe702017-06-13 15:35:54 -07001142
1143 // It's possible that linkUp causes no route-path change as ECMP graph does
1144 // not change if the link is a parallel link (same src-dst as another link.
1145 // However we still need to update ECMP hash groups to include new buckets
1146 // for the link that has come up.
Saurav Dasc88d4662017-05-15 15:34:25 -07001147 if (mastershipService.isLocalMaster(link.src().deviceId())) {
Saurav Das7bcbe702017-06-13 15:35:54 -07001148 if (!seenBefore && isParallelLink(link)) {
Saurav Dasc88d4662017-05-15 15:34:25 -07001149 // if link seen first time, we need to ensure hash-groups have all ports
Saurav Das7bcbe702017-06-13 15:35:54 -07001150 log.debug("Attempting retryHash for paralled first-time link {}", link);
Saurav Dasc88d4662017-05-15 15:34:25 -07001151 groupHandler.retryHash(link, false, true);
1152 } else {
1153 //seen before-link
1154 if (isParallelLink(link)) {
Saurav Das7bcbe702017-06-13 15:35:54 -07001155 log.debug("Attempting retryHash for paralled seen-before "
1156 + "link {}", link);
Saurav Dasc88d4662017-05-15 15:34:25 -07001157 groupHandler.retryHash(link, false, false);
1158 }
1159 }
1160 }
Charles Chan2199c302016-04-23 17:36:10 -07001161
1162 mcastHandler.init();
sanghob35a6192015-04-01 13:05:26 -07001163 }
1164
1165 private void processLinkRemoved(Link link) {
Saurav Dasb5c236e2016-06-07 10:08:06 -07001166 log.info("** LINK REMOVED {}", link.toString());
Saurav Dasc88d4662017-05-15 15:34:25 -07001167 defaultRoutingHandler.populateRoutingRulesForLinkStatusChange(link, null, null);
1168
1169 // update local groupHandler stores
sangho834e4b02015-05-01 09:38:25 -07001170 DefaultGroupHandler groupHandler = groupHandlerMap.get(link.src().deviceId());
1171 if (groupHandler != null) {
Saurav Dasc88d4662017-05-15 15:34:25 -07001172 if (mastershipService.isLocalMaster(link.src().deviceId()) &&
1173 isParallelLink(link)) {
1174 groupHandler.retryHash(link, true, false);
1175 }
1176 // ensure local stores are updated
1177 groupHandler.portDown(link.src().port());
1178 } else {
1179 log.warn("group handler not found for dev:{} when removing link: {}",
1180 link.src().deviceId(), link);
sangho834e4b02015-05-01 09:38:25 -07001181 }
Charles Chan2199c302016-04-23 17:36:10 -07001182
1183 mcastHandler.processLinkDown(link);
sanghob35a6192015-04-01 13:05:26 -07001184 }
1185
1186 private void processDeviceAdded(Device device) {
Saurav Dasb5c236e2016-06-07 10:08:06 -07001187 log.info("** DEVICE ADDED with ID {}", device.id());
Charles Chan91ccbf72017-06-27 18:48:32 -07001188
1189 // NOTE: Punt ARP/NDP even when the device is not configured.
1190 // Host learning without network config is required for CORD config generator.
1191 routingRulePopulator.populateIpPunts(device.id());
1192 routingRulePopulator.populateArpNdpPunts(device.id());
1193
Charles Chan0b4e6182015-11-03 10:42:14 -08001194 if (deviceConfiguration == null || !deviceConfiguration.isConfigured(device.id())) {
Saurav Das7bcbe702017-06-13 15:35:54 -07001195 log.warn("Device configuration unavailable. Device {} will be "
1196 + "processed after configuration.", device.id());
Saurav Das2857f382015-11-03 14:39:27 -08001197 return;
1198 }
Charles Chan2199c302016-04-23 17:36:10 -07001199 processDeviceAddedInternal(device.id());
1200 }
1201
1202 private void processDeviceAddedInternal(DeviceId deviceId) {
Saurav Das837e0bb2015-10-30 17:45:38 -07001203 // Irrespective of whether the local is a MASTER or not for this device,
1204 // we need to create a SR-group-handler instance. This is because in a
1205 // multi-instance setup, any instance can initiate forwarding/next-objectives
1206 // for any switch (even if this instance is a SLAVE or not even connected
1207 // to the switch). To handle this, a default-group-handler instance is necessary
1208 // per switch.
Charles Chan2199c302016-04-23 17:36:10 -07001209 log.debug("Current groupHandlerMap devs: {}", groupHandlerMap.keySet());
1210 if (groupHandlerMap.get(deviceId) == null) {
Charles Chan0b4e6182015-11-03 10:42:14 -08001211 DefaultGroupHandler groupHandler;
1212 try {
1213 groupHandler = DefaultGroupHandler.
Charles Chan2199c302016-04-23 17:36:10 -07001214 createGroupHandler(deviceId,
1215 appId,
1216 deviceConfiguration,
1217 linkService,
1218 flowObjectiveService,
1219 this);
Charles Chan0b4e6182015-11-03 10:42:14 -08001220 } catch (DeviceConfigNotFoundException e) {
1221 log.warn(e.getMessage() + " Aborting processDeviceAdded.");
1222 return;
1223 }
Charles Chan2199c302016-04-23 17:36:10 -07001224 log.debug("updating groupHandlerMap with new config for device: {}",
1225 deviceId);
1226 groupHandlerMap.put(deviceId, groupHandler);
Saurav Das2857f382015-11-03 14:39:27 -08001227 }
Saurav Dasb5c236e2016-06-07 10:08:06 -07001228
Charles Chan2199c302016-04-23 17:36:10 -07001229 if (mastershipService.isLocalMaster(deviceId)) {
Saurav Das018605f2017-02-18 14:05:44 -08001230 defaultRoutingHandler.populatePortAddressingRules(deviceId);
Charles Chan03a73e02016-10-24 14:52:01 -07001231 hostHandler.init(deviceId);
Charles Chanfc5c7802016-05-17 13:13:55 -07001232 xConnectHandler.init(deviceId);
Charles Chan2199c302016-04-23 17:36:10 -07001233 DefaultGroupHandler groupHandler = groupHandlerMap.get(deviceId);
Charles Chan59cc16d2017-02-02 16:20:42 -08001234 groupHandler.createGroupsFromVlanConfig();
Charles Chan2199c302016-04-23 17:36:10 -07001235 routingRulePopulator.populateSubnetBroadcastRule(deviceId);
Charles Chanc42e84e2015-10-20 16:24:19 -07001236 }
Charles Chan5270ed02016-01-30 23:22:37 -08001237
Charles Chan03a73e02016-10-24 14:52:01 -07001238 appCfgHandler.init(deviceId);
1239 routeHandler.init(deviceId);
sanghob35a6192015-04-01 13:05:26 -07001240 }
1241
Saurav Das80980c72016-03-23 11:22:49 -07001242 private void processDeviceRemoved(Device device) {
Saurav Das7bcbe702017-06-13 15:35:54 -07001243 dsNextObjStore.entrySet().stream()
Saurav Das80980c72016-03-23 11:22:49 -07001244 .filter(entry -> entry.getKey().deviceId().equals(device.id()))
1245 .forEach(entry -> {
Saurav Das7bcbe702017-06-13 15:35:54 -07001246 dsNextObjStore.remove(entry.getKey());
Saurav Das80980c72016-03-23 11:22:49 -07001247 });
Charles Chan59cc16d2017-02-02 16:20:42 -08001248 vlanNextObjStore.entrySet().stream()
Saurav Das80980c72016-03-23 11:22:49 -07001249 .filter(entry -> entry.getKey().deviceId().equals(device.id()))
Charles Chan65238242017-06-22 18:03:14 -07001250 .forEach(entry -> vlanNextObjStore.remove(entry.getKey()));
Saurav Das80980c72016-03-23 11:22:49 -07001251 portNextObjStore.entrySet().stream()
1252 .filter(entry -> entry.getKey().deviceId().equals(device.id()))
Charles Chan65238242017-06-22 18:03:14 -07001253 .forEach(entry -> portNextObjStore.remove(entry.getKey()));
Charles Chaned3742352017-06-15 00:44:51 -07001254
1255 seenLinks.keySet().removeIf(key -> key.src().deviceId().equals(device.id()) ||
1256 key.dst().deviceId().equals(device.id()));
1257
Saurav Das80980c72016-03-23 11:22:49 -07001258 groupHandlerMap.remove(device.id());
Saurav Das80980c72016-03-23 11:22:49 -07001259 defaultRoutingHandler.purgeEcmpGraph(device.id());
Saurav Dasc88d4662017-05-15 15:34:25 -07001260 // Note that a switch going down is associated with all of its links
1261 // going down as well, but it is treated as a single switch down event
1262 // while the link-downs are ignored.
1263 defaultRoutingHandler
1264 .populateRoutingRulesForLinkStatusChange(null, null, device.id());
Charles Chan2199c302016-04-23 17:36:10 -07001265 mcastHandler.removeDevice(device.id());
Charles Chanfc5c7802016-05-17 13:13:55 -07001266 xConnectHandler.removeDevice(device.id());
Saurav Das80980c72016-03-23 11:22:49 -07001267 }
1268
Saurav Das1a129a02016-11-18 15:21:57 -08001269 private void processPortUpdated(Device device, Port port) {
1270 if (deviceConfiguration == null || !deviceConfiguration.isConfigured(device.id())) {
1271 log.warn("Device configuration uploading. Not handling port event for"
1272 + "dev: {} port: {}", device.id(), port.number());
1273 return;
1274 }
Saurav Das018605f2017-02-18 14:05:44 -08001275
1276 if (!mastershipService.isLocalMaster(device.id())) {
1277 log.debug("Not master for dev:{} .. not handling port updated event"
1278 + "for port {}", device.id(), port.number());
1279 return;
1280 }
1281
1282 // first we handle filtering rules associated with the port
1283 if (port.isEnabled()) {
1284 log.info("Switchport {}/{} enabled..programming filters",
1285 device.id(), port.number());
Charles Chan7e4f8192017-02-26 22:59:35 -08001286 routingRulePopulator.processSinglePortFilters(device.id(), port.number(), true);
Saurav Das018605f2017-02-18 14:05:44 -08001287 } else {
1288 log.info("Switchport {}/{} disabled..removing filters",
1289 device.id(), port.number());
Charles Chan7e4f8192017-02-26 22:59:35 -08001290 routingRulePopulator.processSinglePortFilters(device.id(), port.number(), false);
Saurav Das018605f2017-02-18 14:05:44 -08001291 }
Saurav Das1a129a02016-11-18 15:21:57 -08001292
1293 // portUpdated calls are for ports that have gone down or up. For switch
1294 // to switch ports, link-events should take care of any re-routing or
1295 // group editing necessary for port up/down. Here we only process edge ports
1296 // that are already configured.
Saurav Dasb0ae6ee2017-03-04 16:08:47 -08001297 ConnectPoint cp = new ConnectPoint(device.id(), port.number());
1298 VlanId untaggedVlan = getUntaggedVlanId(cp);
1299 VlanId nativeVlan = getNativeVlanId(cp);
1300 Set<VlanId> taggedVlans = getTaggedVlanId(cp);
Charles Chan59cc16d2017-02-02 16:20:42 -08001301
Saurav Dasb0ae6ee2017-03-04 16:08:47 -08001302 if (untaggedVlan == null && nativeVlan == null && taggedVlans.isEmpty()) {
Saurav Dasc88d4662017-05-15 15:34:25 -07001303 log.debug("Not handling port updated event for non-edge port (unconfigured) "
Saurav Das1a129a02016-11-18 15:21:57 -08001304 + "dev/port: {}/{}", device.id(), port.number());
1305 return;
1306 }
Saurav Dasb0ae6ee2017-03-04 16:08:47 -08001307 if (untaggedVlan != null) {
1308 processEdgePort(device, port, untaggedVlan, true);
1309 }
1310 if (nativeVlan != null) {
1311 processEdgePort(device, port, nativeVlan, true);
1312 }
1313 if (!taggedVlans.isEmpty()) {
1314 taggedVlans.forEach(tag -> processEdgePort(device, port, tag, false));
1315 }
Saurav Das1a129a02016-11-18 15:21:57 -08001316 }
1317
Saurav Dasb0ae6ee2017-03-04 16:08:47 -08001318 private void processEdgePort(Device device, Port port, VlanId vlanId,
1319 boolean popVlan) {
Saurav Das1a129a02016-11-18 15:21:57 -08001320 boolean portUp = port.isEnabled();
1321 if (portUp) {
Saurav Dasb0ae6ee2017-03-04 16:08:47 -08001322 log.info("Device:EdgePort {}:{} is enabled in vlan: {}", device.id(),
Charles Chan59cc16d2017-02-02 16:20:42 -08001323 port.number(), vlanId);
Saurav Das1a129a02016-11-18 15:21:57 -08001324 } else {
Saurav Dasb0ae6ee2017-03-04 16:08:47 -08001325 log.info("Device:EdgePort {}:{} is disabled in vlan: {}", device.id(),
Charles Chan59cc16d2017-02-02 16:20:42 -08001326 port.number(), vlanId);
Saurav Das1a129a02016-11-18 15:21:57 -08001327 }
1328
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -07001329 DefaultGroupHandler groupHandler = groupHandlerMap.get(device.id());
sanghob35a6192015-04-01 13:05:26 -07001330 if (groupHandler != null) {
Saurav Dasb0ae6ee2017-03-04 16:08:47 -08001331 groupHandler.processEdgePort(port.number(), vlanId, popVlan, portUp);
Saurav Das1a129a02016-11-18 15:21:57 -08001332 } else {
1333 log.warn("Group handler not found for dev:{}. Not handling edge port"
1334 + " {} event for port:{}", device.id(),
1335 (portUp) ? "UP" : "DOWN", port.number());
sanghob35a6192015-04-01 13:05:26 -07001336 }
1337 }
sangho1e575652015-05-14 00:39:53 -07001338
Pier Ventre10bd8d12016-11-26 21:05:22 -08001339 /**
1340 * Registers the given connect point with the NRS, this is necessary
1341 * to receive the NDP and ARP packets from the NRS.
1342 *
1343 * @param portToRegister connect point to register
1344 */
1345 public void registerConnectPoint(ConnectPoint portToRegister) {
Charles Chan0aa674e2017-02-23 15:44:08 -08001346 neighbourResolutionService.registerNeighbourHandler(
Pier Ventre10bd8d12016-11-26 21:05:22 -08001347 portToRegister,
1348 neighbourHandler,
1349 appId
1350 );
1351 }
1352
Charles Chand6832882015-10-05 17:50:33 -07001353 private class InternalConfigListener implements NetworkConfigListener {
Saurav Das7bcbe702017-06-13 15:35:54 -07001354 private static final long PROGRAM_DELAY = 2;
Charles Chan2c15aca2016-11-09 20:51:44 -08001355 SegmentRoutingManager srManager;
Charles Chan4636be02015-10-07 14:21:45 -07001356
Charles Chane849c192016-01-11 18:28:54 -08001357 /**
1358 * Constructs the internal network config listener.
1359 *
Charles Chan2c15aca2016-11-09 20:51:44 -08001360 * @param srManager segment routing manager
Charles Chane849c192016-01-11 18:28:54 -08001361 */
Charles Chan65238242017-06-22 18:03:14 -07001362 InternalConfigListener(SegmentRoutingManager srManager) {
Charles Chan2c15aca2016-11-09 20:51:44 -08001363 this.srManager = srManager;
Charles Chan4636be02015-10-07 14:21:45 -07001364 }
1365
Charles Chane849c192016-01-11 18:28:54 -08001366 /**
1367 * Reads network config and initializes related data structure accordingly.
1368 */
Charles Chan4636be02015-10-07 14:21:45 -07001369 public void configureNetwork() {
Saurav Das7bcbe702017-06-13 15:35:54 -07001370 if (deviceConfiguration == null) {
1371 deviceConfiguration = new DeviceConfiguration(srManager);
1372 } else {
1373 deviceConfiguration.updateConfig();
1374 }
Charles Chan4636be02015-10-07 14:21:45 -07001375
Charles Chan2c15aca2016-11-09 20:51:44 -08001376 arpHandler = new ArpHandler(srManager);
1377 icmpHandler = new IcmpHandler(srManager);
1378 ipHandler = new IpHandler(srManager);
1379 routingRulePopulator = new RoutingRulePopulator(srManager);
1380 defaultRoutingHandler = new DefaultRoutingHandler(srManager);
Charles Chan4636be02015-10-07 14:21:45 -07001381
1382 tunnelHandler = new TunnelHandler(linkService, deviceConfiguration,
1383 groupHandlerMap, tunnelStore);
1384 policyHandler = new PolicyHandler(appId, deviceConfiguration,
1385 flowObjectiveService,
1386 tunnelHandler, policyStore);
Saurav Das7bcbe702017-06-13 15:35:54 -07001387 // add a small delay to absorb multiple network config added notifications
1388 if (!programmingScheduled.get()) {
1389 programmingScheduled.set(true);
1390 executorService.schedule(new ConfigChange(), PROGRAM_DELAY,
1391 TimeUnit.SECONDS);
Charles Chan4636be02015-10-07 14:21:45 -07001392 }
Charles Chan2199c302016-04-23 17:36:10 -07001393 mcastHandler.init();
Charles Chan4636be02015-10-07 14:21:45 -07001394 }
1395
Charles Chand6832882015-10-05 17:50:33 -07001396 @Override
1397 public void event(NetworkConfigEvent event) {
Charles Chan5270ed02016-01-30 23:22:37 -08001398 // TODO move this part to NetworkConfigEventHandler
1399 if (event.configClass().equals(SegmentRoutingDeviceConfig.class)) {
1400 switch (event.type()) {
1401 case CONFIG_ADDED:
Charles Chan278ce832017-06-26 15:25:09 -07001402 log.info("Segment Routing Device Config added for {}", event.subject());
Charles Chan5270ed02016-01-30 23:22:37 -08001403 configureNetwork();
1404 break;
1405 case CONFIG_UPDATED:
Charles Chan278ce832017-06-26 15:25:09 -07001406 log.info("Segment Routing Config updated for {}", event.subject());
1407 // TODO support dynamic configuration
1408 break;
1409 default:
1410 break;
1411 }
1412 } else if (event.configClass().equals(InterfaceConfig.class)) {
1413 switch (event.type()) {
1414 case CONFIG_ADDED:
1415 log.info("Interface Config added for {}", event.subject());
1416 configureNetwork();
1417 break;
1418 case CONFIG_UPDATED:
1419 log.info("Interface Config updated for {}", event.subject());
Charles Chan5270ed02016-01-30 23:22:37 -08001420 // TODO support dynamic configuration
1421 break;
1422 default:
1423 break;
Charles Chanb8e10c82015-10-14 11:24:40 -07001424 }
Charles Chan5270ed02016-01-30 23:22:37 -08001425 } else if (event.configClass().equals(SegmentRoutingAppConfig.class)) {
Charles Chanfc5c7802016-05-17 13:13:55 -07001426 checkState(appCfgHandler != null, "NetworkConfigEventHandler is not initialized");
Charles Chan5270ed02016-01-30 23:22:37 -08001427 switch (event.type()) {
1428 case CONFIG_ADDED:
Charles Chanfc5c7802016-05-17 13:13:55 -07001429 appCfgHandler.processAppConfigAdded(event);
Charles Chan5270ed02016-01-30 23:22:37 -08001430 break;
1431 case CONFIG_UPDATED:
Charles Chanfc5c7802016-05-17 13:13:55 -07001432 appCfgHandler.processAppConfigUpdated(event);
Charles Chan5270ed02016-01-30 23:22:37 -08001433 break;
1434 case CONFIG_REMOVED:
Charles Chanfc5c7802016-05-17 13:13:55 -07001435 appCfgHandler.processAppConfigRemoved(event);
1436 break;
1437 default:
1438 break;
1439 }
Charles Chan03a73e02016-10-24 14:52:01 -07001440 configureNetwork();
Charles Chanfc5c7802016-05-17 13:13:55 -07001441 } else if (event.configClass().equals(XConnectConfig.class)) {
1442 checkState(xConnectHandler != null, "XConnectHandler is not initialized");
1443 switch (event.type()) {
1444 case CONFIG_ADDED:
1445 xConnectHandler.processXConnectConfigAdded(event);
1446 break;
1447 case CONFIG_UPDATED:
1448 xConnectHandler.processXConnectConfigUpdated(event);
1449 break;
1450 case CONFIG_REMOVED:
1451 xConnectHandler.processXConnectConfigRemoved(event);
Charles Chan5270ed02016-01-30 23:22:37 -08001452 break;
1453 default:
1454 break;
Charles Chanb8e10c82015-10-14 11:24:40 -07001455 }
Pier Ventref34966c2016-11-07 16:21:04 -08001456 } else if (event.configClass().equals(PwaasConfig.class)) {
1457 checkState(l2TunnelHandler != null, "L2TunnelHandler is not initialized");
1458 switch (event.type()) {
1459 case CONFIG_ADDED:
1460 l2TunnelHandler.processPwaasConfigAdded(event);
1461 break;
1462 case CONFIG_UPDATED:
1463 l2TunnelHandler.processPwaasConfigUpdated(event);
1464 break;
1465 case CONFIG_REMOVED:
1466 l2TunnelHandler.processPwaasConfigRemoved(event);
1467 break;
1468 default:
1469 break;
1470 }
Charles Chand6832882015-10-05 17:50:33 -07001471 }
1472 }
Saurav Das7bcbe702017-06-13 15:35:54 -07001473
1474 private final class ConfigChange implements Runnable {
1475 @Override
1476 public void run() {
1477 programmingScheduled.set(false);
1478 for (Device device : deviceService.getDevices()) {
1479 processDeviceAdded(device);
1480 }
1481 defaultRoutingHandler.startPopulationProcess();
1482 }
1483 }
Charles Chand6832882015-10-05 17:50:33 -07001484 }
Charles Chan68aa62d2015-11-09 16:37:23 -08001485
1486 private class InternalHostListener implements HostListener {
Charles Chan68aa62d2015-11-09 16:37:23 -08001487 @Override
1488 public void event(HostEvent event) {
1489 // Do not proceed without mastership
1490 DeviceId deviceId = event.subject().location().deviceId();
1491 if (!mastershipService.isLocalMaster(deviceId)) {
1492 return;
1493 }
1494
1495 switch (event.type()) {
1496 case HOST_ADDED:
Charles Chand2990362016-04-18 13:44:03 -07001497 hostHandler.processHostAddedEvent(event);
Charles Chan68aa62d2015-11-09 16:37:23 -08001498 break;
1499 case HOST_MOVED:
Charles Chand2990362016-04-18 13:44:03 -07001500 hostHandler.processHostMovedEvent(event);
Charles Chan68aa62d2015-11-09 16:37:23 -08001501 break;
1502 case HOST_REMOVED:
Charles Chanf9a52702017-06-16 15:19:24 -07001503 hostHandler.processHostRemovedEvent(event);
Charles Chan68aa62d2015-11-09 16:37:23 -08001504 break;
1505 case HOST_UPDATED:
Charles Chand2990362016-04-18 13:44:03 -07001506 hostHandler.processHostUpdatedEvent(event);
Charles Chan68aa62d2015-11-09 16:37:23 -08001507 break;
1508 default:
1509 log.warn("Unsupported host event type: {}", event.type());
1510 break;
1511 }
1512 }
1513 }
1514
Charles Chand55e84d2016-03-30 17:54:24 -07001515 private class InternalMcastListener implements McastListener {
1516 @Override
1517 public void event(McastEvent event) {
1518 switch (event.type()) {
1519 case SOURCE_ADDED:
Charles Chand2990362016-04-18 13:44:03 -07001520 mcastHandler.processSourceAdded(event);
Charles Chand55e84d2016-03-30 17:54:24 -07001521 break;
1522 case SINK_ADDED:
Charles Chand2990362016-04-18 13:44:03 -07001523 mcastHandler.processSinkAdded(event);
Charles Chand55e84d2016-03-30 17:54:24 -07001524 break;
1525 case SINK_REMOVED:
Charles Chand2990362016-04-18 13:44:03 -07001526 mcastHandler.processSinkRemoved(event);
Charles Chand55e84d2016-03-30 17:54:24 -07001527 break;
1528 case ROUTE_ADDED:
1529 case ROUTE_REMOVED:
1530 default:
1531 break;
1532 }
1533 }
1534 }
Charles Chan35fd1a72016-06-13 18:54:31 -07001535
Charles Chan03a73e02016-10-24 14:52:01 -07001536 private class InternalRouteEventListener implements RouteListener {
1537 @Override
1538 public void event(RouteEvent event) {
1539 switch (event.type()) {
1540 case ROUTE_ADDED:
1541 routeHandler.processRouteAdded(event);
1542 break;
1543 case ROUTE_UPDATED:
1544 routeHandler.processRouteUpdated(event);
1545 break;
1546 case ROUTE_REMOVED:
1547 routeHandler.processRouteRemoved(event);
1548 break;
1549 default:
1550 break;
1551 }
1552 }
1553 }
Saurav Dasc88d4662017-05-15 15:34:25 -07001554
sanghob35a6192015-04-01 13:05:26 -07001555}