blob: b6a621940cc79bfbf215eda13cc43fcfda0b14cb [file] [log] [blame]
sanghob35a6192015-04-01 13:05:26 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
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 Chanc81c45b2016-10-20 17:02:44 -070018import com.google.common.collect.Maps;
sanghob35a6192015-04-01 13:05:26 -070019import org.apache.felix.scr.annotations.Activate;
20import org.apache.felix.scr.annotations.Component;
21import org.apache.felix.scr.annotations.Deactivate;
22import org.apache.felix.scr.annotations.Reference;
23import org.apache.felix.scr.annotations.ReferenceCardinality;
sangho1e575652015-05-14 00:39:53 -070024import org.apache.felix.scr.annotations.Service;
sanghob35a6192015-04-01 13:05:26 -070025import org.onlab.packet.Ethernet;
Charles Chanc42e84e2015-10-20 16:24:19 -070026import org.onlab.packet.IPv4;
Pier Ventre10bd8d12016-11-26 21:05:22 -080027import org.onlab.packet.IPv6;
Charles Chanc42e84e2015-10-20 16:24:19 -070028import org.onlab.packet.Ip4Prefix;
Charles Chanc42e84e2015-10-20 16:24:19 -070029import org.onlab.packet.IpPrefix;
Jonathan Hartc19f7c12016-04-12 15:39:44 -070030import org.onlab.packet.VlanId;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -070031import org.onlab.util.KryoNamespace;
Saurav Das80980c72016-03-23 11:22:49 -070032import org.onosproject.cfg.ComponentConfigService;
sanghob35a6192015-04-01 13:05:26 -070033import org.onosproject.core.ApplicationId;
34import org.onosproject.core.CoreService;
35import org.onosproject.event.Event;
Charles Chand55e84d2016-03-30 17:54:24 -070036import org.onosproject.incubator.net.config.basics.McastConfig;
Charles Chan2c15aca2016-11-09 20:51:44 -080037import org.onosproject.incubator.net.intf.InterfaceService;
Pier Ventre10bd8d12016-11-26 21:05:22 -080038import org.onosproject.incubator.net.neighbour.NeighbourResolutionService;
Charles Chan03a73e02016-10-24 14:52:01 -070039import org.onosproject.incubator.net.routing.RouteEvent;
40import org.onosproject.incubator.net.routing.RouteListener;
41import org.onosproject.incubator.net.routing.RouteService;
Jonathan Hartc19f7c12016-04-12 15:39:44 -070042import org.onosproject.mastership.MastershipService;
Pier Ventre10bd8d12016-11-26 21:05:22 -080043import org.onosproject.net.ConnectPoint;
Jonathan Hartc19f7c12016-04-12 15:39:44 -070044import org.onosproject.net.Device;
45import org.onosproject.net.DeviceId;
46import org.onosproject.net.Link;
47import org.onosproject.net.Port;
Charles Chan68aa62d2015-11-09 16:37:23 -080048import org.onosproject.net.PortNumber;
Charles Chand6832882015-10-05 17:50:33 -070049import org.onosproject.net.config.ConfigFactory;
50import org.onosproject.net.config.NetworkConfigEvent;
Charles Chand6832882015-10-05 17:50:33 -070051import org.onosproject.net.config.NetworkConfigListener;
Jonathan Hartc19f7c12016-04-12 15:39:44 -070052import org.onosproject.net.config.NetworkConfigRegistry;
Charles Chand6832882015-10-05 17:50:33 -070053import org.onosproject.net.config.basics.SubjectFactories;
Jonathan Hartc19f7c12016-04-12 15:39:44 -070054import org.onosproject.net.device.DeviceEvent;
55import org.onosproject.net.device.DeviceListener;
56import org.onosproject.net.device.DeviceService;
Charles Chan68aa62d2015-11-09 16:37:23 -080057import org.onosproject.net.flow.TrafficSelector;
58import org.onosproject.net.flow.TrafficTreatment;
Jonathan Hartc19f7c12016-04-12 15:39:44 -070059import org.onosproject.net.flowobjective.FlowObjectiveService;
Charles Chan68aa62d2015-11-09 16:37:23 -080060import org.onosproject.net.host.HostEvent;
61import org.onosproject.net.host.HostListener;
Pier Ventre10bd8d12016-11-26 21:05:22 -080062import org.onosproject.net.host.HostService;
63import org.onosproject.net.link.LinkEvent;
64import org.onosproject.net.link.LinkListener;
65import org.onosproject.net.link.LinkService;
Charles Chand55e84d2016-03-30 17:54:24 -070066import org.onosproject.net.mcast.McastEvent;
67import org.onosproject.net.mcast.McastListener;
68import org.onosproject.net.mcast.MulticastRouteService;
Pier Ventre10bd8d12016-11-26 21:05:22 -080069import org.onosproject.net.packet.InboundPacket;
70import org.onosproject.net.packet.PacketContext;
71import org.onosproject.net.packet.PacketProcessor;
72import org.onosproject.net.packet.PacketService;
Charles Chand55e84d2016-03-30 17:54:24 -070073import org.onosproject.net.topology.TopologyService;
74import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException;
75import org.onosproject.segmentrouting.config.DeviceConfiguration;
Charles Chand55e84d2016-03-30 17:54:24 -070076import org.onosproject.segmentrouting.config.SegmentRoutingAppConfig;
Pier Ventre10bd8d12016-11-26 21:05:22 -080077import org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig;
Charles Chanfc5c7802016-05-17 13:13:55 -070078import org.onosproject.segmentrouting.config.XConnectConfig;
Charles Chand55e84d2016-03-30 17:54:24 -070079import org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler;
80import org.onosproject.segmentrouting.grouphandler.NeighborSet;
Charles Chand2990362016-04-18 13:44:03 -070081import org.onosproject.segmentrouting.storekey.NeighborSetNextObjectiveStoreKey;
82import org.onosproject.segmentrouting.storekey.PortNextObjectiveStoreKey;
Charles Chand2990362016-04-18 13:44:03 -070083import org.onosproject.segmentrouting.storekey.SubnetAssignedVidStoreKey;
84import org.onosproject.segmentrouting.storekey.SubnetNextObjectiveStoreKey;
Charles Chanfc5c7802016-05-17 13:13:55 -070085import org.onosproject.segmentrouting.storekey.XConnectStoreKey;
Jonathan Hartc19f7c12016-04-12 15:39:44 -070086import org.onosproject.store.serializers.KryoNamespaces;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -070087import org.onosproject.store.service.EventuallyConsistentMap;
88import org.onosproject.store.service.EventuallyConsistentMapBuilder;
89import org.onosproject.store.service.StorageService;
90import org.onosproject.store.service.WallClockTimestamp;
Charles Chan35fd1a72016-06-13 18:54:31 -070091import org.opencord.cordconfig.CordConfigEvent;
92import org.opencord.cordconfig.CordConfigListener;
93import org.opencord.cordconfig.CordConfigService;
sanghob35a6192015-04-01 13:05:26 -070094import org.slf4j.Logger;
95import org.slf4j.LoggerFactory;
96
Saurav Das0e99e2b2015-10-28 12:39:42 -070097import java.util.Collections;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -070098import java.util.HashSet;
sangho1e575652015-05-14 00:39:53 -070099import java.util.List;
sanghob35a6192015-04-01 13:05:26 -0700100import java.util.Map;
Saurav Das0e99e2b2015-10-28 12:39:42 -0700101import java.util.Set;
sanghob35a6192015-04-01 13:05:26 -0700102import java.util.concurrent.ConcurrentHashMap;
103import java.util.concurrent.ConcurrentLinkedQueue;
104import java.util.concurrent.Executors;
105import java.util.concurrent.ScheduledExecutorService;
106import java.util.concurrent.ScheduledFuture;
107import java.util.concurrent.TimeUnit;
Pier Ventre10bd8d12016-11-26 21:05:22 -0800108import java.util.stream.Collectors;
sanghob35a6192015-04-01 13:05:26 -0700109
Charles Chan3e783d02016-02-26 22:19:52 -0800110import static com.google.common.base.Preconditions.checkState;
Pier Ventree0ae7a32016-11-23 09:57:42 -0800111import static org.onlab.packet.Ethernet.TYPE_ARP;
Yuta HIGUCHI1624df12016-07-21 16:54:33 -0700112import static org.onlab.util.Tools.groupedThreads;
Charles Chan3e783d02016-02-26 22:19:52 -0800113
Charles Chane849c192016-01-11 18:28:54 -0800114/**
115 * Segment routing manager.
116 */
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700117@Service
118@Component(immediate = true)
sangho1e575652015-05-14 00:39:53 -0700119public class SegmentRoutingManager implements SegmentRoutingService {
sanghob35a6192015-04-01 13:05:26 -0700120
Charles Chan2c15aca2016-11-09 20:51:44 -0800121 private static Logger log = LoggerFactory.getLogger(SegmentRoutingManager.class);
sanghob35a6192015-04-01 13:05:26 -0700122
123 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan03a73e02016-10-24 14:52:01 -0700124 private ComponentConfigService compCfgService;
sanghob35a6192015-04-01 13:05:26 -0700125
126 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Pier Ventre10bd8d12016-11-26 21:05:22 -0800127 private NeighbourResolutionService neighbourResolutionService;
128
129 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan03a73e02016-10-24 14:52:01 -0700130 CoreService coreService;
sanghob35a6192015-04-01 13:05:26 -0700131
132 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan03a73e02016-10-24 14:52:01 -0700133 PacketService packetService;
sanghob35a6192015-04-01 13:05:26 -0700134
135 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan03a73e02016-10-24 14:52:01 -0700136 HostService hostService;
sanghob35a6192015-04-01 13:05:26 -0700137
138 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan03a73e02016-10-24 14:52:01 -0700139 DeviceService deviceService;
sanghob35a6192015-04-01 13:05:26 -0700140
141 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan03a73e02016-10-24 14:52:01 -0700142 FlowObjectiveService flowObjectiveService;
sanghob35a6192015-04-01 13:05:26 -0700143
144 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan03a73e02016-10-24 14:52:01 -0700145 LinkService linkService;
sangho1e575652015-05-14 00:39:53 -0700146
Charles Chan5270ed02016-01-30 23:22:37 -0800147 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan03a73e02016-10-24 14:52:01 -0700148 MastershipService mastershipService;
149
150 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
151 StorageService storageService;
152
153 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
154 MulticastRouteService multicastRouteService;
155
156 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
157 TopologyService topologyService;
158
159 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
160 CordConfigService cordConfigService;
161
162 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
163 RouteService routeService;
Charles Chan5270ed02016-01-30 23:22:37 -0800164
165 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan2c15aca2016-11-09 20:51:44 -0800166 public NetworkConfigRegistry cfgService;
Charles Chan5270ed02016-01-30 23:22:37 -0800167
Saurav Das80980c72016-03-23 11:22:49 -0700168 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Charles Chan2c15aca2016-11-09 20:51:44 -0800169 public InterfaceService interfaceService;
170
Charles Chan03a73e02016-10-24 14:52:01 -0700171 ArpHandler arpHandler = null;
172 IcmpHandler icmpHandler = null;
173 IpHandler ipHandler = null;
174 RoutingRulePopulator routingRulePopulator = null;
Charles Chan2c15aca2016-11-09 20:51:44 -0800175 public ApplicationId appId;
sangho666cd6d2015-04-14 16:27:13 -0700176 protected DeviceConfiguration deviceConfiguration = null;
sanghob35a6192015-04-01 13:05:26 -0700177
Charles Chan03a73e02016-10-24 14:52:01 -0700178 DefaultRoutingHandler defaultRoutingHandler = null;
sangho1e575652015-05-14 00:39:53 -0700179 private TunnelHandler tunnelHandler = null;
180 private PolicyHandler policyHandler = null;
Charles Chanb8e10c82015-10-14 11:24:40 -0700181 private InternalPacketProcessor processor = null;
182 private InternalLinkListener linkListener = null;
183 private InternalDeviceListener deviceListener = null;
Charles Chanfc5c7802016-05-17 13:13:55 -0700184 private AppConfigHandler appCfgHandler = null;
Charles Chan03a73e02016-10-24 14:52:01 -0700185 XConnectHandler xConnectHandler = null;
Charles Chand2990362016-04-18 13:44:03 -0700186 private McastHandler mcastHandler = null;
Charles Chan03a73e02016-10-24 14:52:01 -0700187 HostHandler hostHandler = null;
Charles Chan35fd1a72016-06-13 18:54:31 -0700188 private CordConfigHandler cordConfigHandler = null;
Pier Ventre10bd8d12016-11-26 21:05:22 -0800189 private RouteHandler routeHandler = null;
190 private SegmentRoutingNeighbourHandler neighbourHandler = null;
sanghob35a6192015-04-01 13:05:26 -0700191 private InternalEventHandler eventHandler = new InternalEventHandler();
Charles Chan5270ed02016-01-30 23:22:37 -0800192 private final InternalHostListener hostListener = new InternalHostListener();
Charles Chand55e84d2016-03-30 17:54:24 -0700193 private final InternalConfigListener cfgListener = new InternalConfigListener(this);
194 private final InternalMcastListener mcastListener = new InternalMcastListener();
Charles Chan35fd1a72016-06-13 18:54:31 -0700195 private final InternalCordConfigListener cordConfigListener = new InternalCordConfigListener();
Charles Chan03a73e02016-10-24 14:52:01 -0700196 private final InternalRouteEventListener routeListener = new InternalRouteEventListener();
sanghob35a6192015-04-01 13:05:26 -0700197
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700198 private ScheduledExecutorService executorService = Executors
Yuta HIGUCHI1624df12016-07-21 16:54:33 -0700199 .newScheduledThreadPool(1, groupedThreads("SegmentRoutingManager", "event-%d", log));
sanghob35a6192015-04-01 13:05:26 -0700200
Saurav Das4ce45962015-11-24 23:21:05 -0800201 @SuppressWarnings("unused")
sanghob35a6192015-04-01 13:05:26 -0700202 private static ScheduledFuture<?> eventHandlerFuture = null;
Saurav Das4ce45962015-11-24 23:21:05 -0800203 @SuppressWarnings("rawtypes")
Yuta HIGUCHI1624df12016-07-21 16:54:33 -0700204 private ConcurrentLinkedQueue<Event> eventQueue = new ConcurrentLinkedQueue<>();
Charles Chan68aa62d2015-11-09 16:37:23 -0800205 private Map<DeviceId, DefaultGroupHandler> groupHandlerMap =
Charles Chane849c192016-01-11 18:28:54 -0800206 new ConcurrentHashMap<>();
207 /**
208 * Per device next objective ID store with (device id + neighbor set) as key.
209 */
210 public EventuallyConsistentMap<NeighborSetNextObjectiveStoreKey, Integer>
Charles Chan68aa62d2015-11-09 16:37:23 -0800211 nsNextObjStore = null;
Charles Chane849c192016-01-11 18:28:54 -0800212 /**
213 * Per device next objective ID store with (device id + subnet) as key.
214 */
215 public EventuallyConsistentMap<SubnetNextObjectiveStoreKey, Integer>
Charles Chan68aa62d2015-11-09 16:37:23 -0800216 subnetNextObjStore = null;
Charles Chane849c192016-01-11 18:28:54 -0800217 /**
218 * Per device next objective ID store with (device id + port) as key.
219 */
220 public EventuallyConsistentMap<PortNextObjectiveStoreKey, Integer>
Saurav Das4ce45962015-11-24 23:21:05 -0800221 portNextObjStore = null;
Saurav Das0e99e2b2015-10-28 12:39:42 -0700222 // Per device, per-subnet assigned-vlans store, with (device id + subnet
223 // IPv4 prefix) as key
224 private EventuallyConsistentMap<SubnetAssignedVidStoreKey, VlanId>
Charles Chane849c192016-01-11 18:28:54 -0800225 subnetVidStore = null;
Saurav Das4ce45962015-11-24 23:21:05 -0800226 private EventuallyConsistentMap<String, Tunnel> tunnelStore = null;
227 private EventuallyConsistentMap<String, Policy> policyStore = null;
sangho0b2b6d12015-05-20 22:16:38 -0700228
Charles Chand55e84d2016-03-30 17:54:24 -0700229 private final ConfigFactory<DeviceId, SegmentRoutingDeviceConfig> deviceConfigFactory =
Charles Chanfc5c7802016-05-17 13:13:55 -0700230 new ConfigFactory<DeviceId, SegmentRoutingDeviceConfig>(
231 SubjectFactories.DEVICE_SUBJECT_FACTORY,
Charles Chand55e84d2016-03-30 17:54:24 -0700232 SegmentRoutingDeviceConfig.class, "segmentrouting") {
Charles Chand6832882015-10-05 17:50:33 -0700233 @Override
Charles Chan5270ed02016-01-30 23:22:37 -0800234 public SegmentRoutingDeviceConfig createConfig() {
235 return new SegmentRoutingDeviceConfig();
Charles Chand6832882015-10-05 17:50:33 -0700236 }
237 };
Charles Chand55e84d2016-03-30 17:54:24 -0700238 private final ConfigFactory<ApplicationId, SegmentRoutingAppConfig> appConfigFactory =
Charles Chanfc5c7802016-05-17 13:13:55 -0700239 new ConfigFactory<ApplicationId, SegmentRoutingAppConfig>(
240 SubjectFactories.APP_SUBJECT_FACTORY,
Charles Chand55e84d2016-03-30 17:54:24 -0700241 SegmentRoutingAppConfig.class, "segmentrouting") {
Charles Chan5270ed02016-01-30 23:22:37 -0800242 @Override
243 public SegmentRoutingAppConfig createConfig() {
244 return new SegmentRoutingAppConfig();
245 }
246 };
Charles Chanfc5c7802016-05-17 13:13:55 -0700247 private final ConfigFactory<ApplicationId, XConnectConfig> xConnectConfigFactory =
248 new ConfigFactory<ApplicationId, XConnectConfig>(
249 SubjectFactories.APP_SUBJECT_FACTORY,
250 XConnectConfig.class, "xconnect") {
251 @Override
252 public XConnectConfig createConfig() {
253 return new XConnectConfig();
254 }
255 };
Charles Chand55e84d2016-03-30 17:54:24 -0700256 private ConfigFactory<ApplicationId, McastConfig> mcastConfigFactory =
Charles Chanfc5c7802016-05-17 13:13:55 -0700257 new ConfigFactory<ApplicationId, McastConfig>(
258 SubjectFactories.APP_SUBJECT_FACTORY,
Charles Chand55e84d2016-03-30 17:54:24 -0700259 McastConfig.class, "multicast") {
260 @Override
261 public McastConfig createConfig() {
262 return new McastConfig();
263 }
264 };
265
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700266 private Object threadSchedulerLock = new Object();
267 private static int numOfEventsQueued = 0;
268 private static int numOfEventsExecuted = 0;
sanghob35a6192015-04-01 13:05:26 -0700269 private static int numOfHandlerExecution = 0;
270 private static int numOfHandlerScheduled = 0;
271
Charles Chan116188d2016-02-18 14:22:42 -0800272 /**
273 * Segment Routing App ID.
274 */
Charles Chan2c15aca2016-11-09 20:51:44 -0800275 public static final String APP_NAME = "org.onosproject.segmentrouting";
Charles Chane849c192016-01-11 18:28:54 -0800276 /**
277 * The starting value of per-subnet VLAN ID assignment.
278 */
Saurav Das0e99e2b2015-10-28 12:39:42 -0700279 private static final short ASSIGNED_VLAN_START = 4093;
Charles Chane849c192016-01-11 18:28:54 -0800280 /**
281 * The default VLAN ID assigned to the interfaces without subnet config.
282 */
Saurav Das0e99e2b2015-10-28 12:39:42 -0700283 public static final short ASSIGNED_VLAN_NO_SUBNET = 4094;
284
sanghob35a6192015-04-01 13:05:26 -0700285 @Activate
286 protected void activate() {
Charles Chan2c15aca2016-11-09 20:51:44 -0800287 appId = coreService.registerApplication(APP_NAME);
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700288
289 log.debug("Creating EC map nsnextobjectivestore");
290 EventuallyConsistentMapBuilder<NeighborSetNextObjectiveStoreKey, Integer>
291 nsNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder();
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700292 nsNextObjStore = nsNextObjMapBuilder
293 .withName("nsnextobjectivestore")
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700294 .withSerializer(createSerializer())
Madan Jampanibcf1a482015-06-24 19:05:56 -0700295 .withTimestampProvider((k, v) -> new WallClockTimestamp())
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700296 .build();
297 log.trace("Current size {}", nsNextObjStore.size());
298
Charles Chanc42e84e2015-10-20 16:24:19 -0700299 log.debug("Creating EC map subnetnextobjectivestore");
300 EventuallyConsistentMapBuilder<SubnetNextObjectiveStoreKey, Integer>
301 subnetNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder();
Charles Chanc42e84e2015-10-20 16:24:19 -0700302 subnetNextObjStore = subnetNextObjMapBuilder
303 .withName("subnetnextobjectivestore")
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700304 .withSerializer(createSerializer())
Charles Chanc42e84e2015-10-20 16:24:19 -0700305 .withTimestampProvider((k, v) -> new WallClockTimestamp())
306 .build();
307
Saurav Das4ce45962015-11-24 23:21:05 -0800308 log.debug("Creating EC map subnetnextobjectivestore");
309 EventuallyConsistentMapBuilder<PortNextObjectiveStoreKey, Integer>
310 portNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder();
311 portNextObjStore = portNextObjMapBuilder
312 .withName("portnextobjectivestore")
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700313 .withSerializer(createSerializer())
Saurav Das4ce45962015-11-24 23:21:05 -0800314 .withTimestampProvider((k, v) -> new WallClockTimestamp())
315 .build();
316
sangho0b2b6d12015-05-20 22:16:38 -0700317 EventuallyConsistentMapBuilder<String, Tunnel> tunnelMapBuilder =
318 storageService.eventuallyConsistentMapBuilder();
sangho0b2b6d12015-05-20 22:16:38 -0700319 tunnelStore = tunnelMapBuilder
320 .withName("tunnelstore")
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700321 .withSerializer(createSerializer())
Madan Jampanibcf1a482015-06-24 19:05:56 -0700322 .withTimestampProvider((k, v) -> new WallClockTimestamp())
sangho0b2b6d12015-05-20 22:16:38 -0700323 .build();
324
325 EventuallyConsistentMapBuilder<String, Policy> policyMapBuilder =
326 storageService.eventuallyConsistentMapBuilder();
sangho0b2b6d12015-05-20 22:16:38 -0700327 policyStore = policyMapBuilder
328 .withName("policystore")
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700329 .withSerializer(createSerializer())
Madan Jampanibcf1a482015-06-24 19:05:56 -0700330 .withTimestampProvider((k, v) -> new WallClockTimestamp())
sangho0b2b6d12015-05-20 22:16:38 -0700331 .build();
332
Saurav Das0e99e2b2015-10-28 12:39:42 -0700333 EventuallyConsistentMapBuilder<SubnetAssignedVidStoreKey, VlanId>
334 subnetVidStoreMapBuilder = storageService.eventuallyConsistentMapBuilder();
Saurav Das0e99e2b2015-10-28 12:39:42 -0700335 subnetVidStore = subnetVidStoreMapBuilder
336 .withName("subnetvidstore")
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700337 .withSerializer(createSerializer())
Saurav Das0e99e2b2015-10-28 12:39:42 -0700338 .withTimestampProvider((k, v) -> new WallClockTimestamp())
339 .build();
340
Saurav Das80980c72016-03-23 11:22:49 -0700341 compCfgService.preSetProperty("org.onosproject.net.group.impl.GroupManager",
Pier Luigi9e5c5ca2017-01-12 18:14:58 -0800342 "purgeOnDisconnection", "true");
Saurav Das80980c72016-03-23 11:22:49 -0700343 compCfgService.preSetProperty("org.onosproject.net.flow.impl.FlowRuleManager",
Pier Luigi9e5c5ca2017-01-12 18:14:58 -0800344 "purgeOnDisconnection", "true");
Charles Chan03a73e02016-10-24 14:52:01 -0700345 compCfgService.preSetProperty("org.onosproject.vrouter.Vrouter",
Charles Chan77899532017-01-18 20:00:13 -0800346 "fibInstallerEnabled", "false");
Pier Luigi9e5c5ca2017-01-12 18:14:58 -0800347 compCfgService.preSetProperty("org.onosproject.provider.host.impl.HostLocationProvider",
348 "requestInterceptsEnabled", "false");
Pier Luigi7e415132017-01-12 22:46:39 -0800349 compCfgService.preSetProperty("org.onosproject.incubator.net.neighbour.impl.NeighbourResolutionManager",
350 "requestInterceptsEnabled", "false");
351 compCfgService.preSetProperty("org.onosproject.dhcprelay.DhcpRelay",
352 "arpEnabled", "false");
Saurav Das80980c72016-03-23 11:22:49 -0700353
Charles Chanb8e10c82015-10-14 11:24:40 -0700354 processor = new InternalPacketProcessor();
355 linkListener = new InternalLinkListener();
356 deviceListener = new InternalDeviceListener();
Charles Chanfc5c7802016-05-17 13:13:55 -0700357 appCfgHandler = new AppConfigHandler(this);
358 xConnectHandler = new XConnectHandler(this);
Charles Chand2990362016-04-18 13:44:03 -0700359 mcastHandler = new McastHandler(this);
360 hostHandler = new HostHandler(this);
Charles Chan35fd1a72016-06-13 18:54:31 -0700361 cordConfigHandler = new CordConfigHandler(this);
Charles Chan03a73e02016-10-24 14:52:01 -0700362 routeHandler = new RouteHandler(this);
Pier Ventre10bd8d12016-11-26 21:05:22 -0800363 neighbourHandler = new SegmentRoutingNeighbourHandler(this);
Charles Chanb8e10c82015-10-14 11:24:40 -0700364
Charles Chan3e783d02016-02-26 22:19:52 -0800365 cfgService.addListener(cfgListener);
Charles Chand55e84d2016-03-30 17:54:24 -0700366 cfgService.registerConfigFactory(deviceConfigFactory);
367 cfgService.registerConfigFactory(appConfigFactory);
Charles Chanfc5c7802016-05-17 13:13:55 -0700368 cfgService.registerConfigFactory(xConnectConfigFactory);
Charles Chand55e84d2016-03-30 17:54:24 -0700369 cfgService.registerConfigFactory(mcastConfigFactory);
Charles Chan5270ed02016-01-30 23:22:37 -0800370 hostService.addListener(hostListener);
Charles Chanb8e10c82015-10-14 11:24:40 -0700371 packetService.addProcessor(processor, PacketProcessor.director(2));
372 linkService.addListener(linkListener);
373 deviceService.addListener(deviceListener);
Charles Chand55e84d2016-03-30 17:54:24 -0700374 multicastRouteService.addListener(mcastListener);
Charles Chan35fd1a72016-06-13 18:54:31 -0700375 cordConfigService.addListener(cordConfigListener);
Charles Chanb8e10c82015-10-14 11:24:40 -0700376
377 cfgListener.configureNetwork();
378
Charles Chan03a73e02016-10-24 14:52:01 -0700379 routeService.addListener(routeListener);
380
sanghob35a6192015-04-01 13:05:26 -0700381 log.info("Started");
382 }
383
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700384 private KryoNamespace.Builder createSerializer() {
385 return new KryoNamespace.Builder()
386 .register(KryoNamespaces.API)
387 .register(NeighborSetNextObjectiveStoreKey.class,
388 SubnetNextObjectiveStoreKey.class,
389 SubnetAssignedVidStoreKey.class,
390 NeighborSet.class,
391 Tunnel.class,
392 DefaultTunnel.class,
393 Policy.class,
394 TunnelPolicy.class,
395 Policy.Type.class,
396 PortNextObjectiveStoreKey.class,
Charles Chanfc5c7802016-05-17 13:13:55 -0700397 XConnectStoreKey.class
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700398 );
399 }
400
sanghob35a6192015-04-01 13:05:26 -0700401 @Deactivate
402 protected void deactivate() {
Charles Chand6832882015-10-05 17:50:33 -0700403 cfgService.removeListener(cfgListener);
Charles Chand55e84d2016-03-30 17:54:24 -0700404 cfgService.unregisterConfigFactory(deviceConfigFactory);
405 cfgService.unregisterConfigFactory(appConfigFactory);
Charles Chan03a73e02016-10-24 14:52:01 -0700406 cfgService.unregisterConfigFactory(xConnectConfigFactory);
Charles Chand55e84d2016-03-30 17:54:24 -0700407 cfgService.unregisterConfigFactory(mcastConfigFactory);
Charles Chand6832882015-10-05 17:50:33 -0700408
sanghob35a6192015-04-01 13:05:26 -0700409 packetService.removeProcessor(processor);
Charles Chanb8e10c82015-10-14 11:24:40 -0700410 linkService.removeListener(linkListener);
411 deviceService.removeListener(deviceListener);
Charles Chand55e84d2016-03-30 17:54:24 -0700412 multicastRouteService.removeListener(mcastListener);
Charles Chan35fd1a72016-06-13 18:54:31 -0700413 cordConfigService.removeListener(cordConfigListener);
Charles Chan03a73e02016-10-24 14:52:01 -0700414 routeService.removeListener(routeListener);
Charles Chand55e84d2016-03-30 17:54:24 -0700415
sanghob35a6192015-04-01 13:05:26 -0700416 processor = null;
Charles Chanb8e10c82015-10-14 11:24:40 -0700417 linkListener = null;
Charles Chand55e84d2016-03-30 17:54:24 -0700418 deviceListener = null;
Charles Chanb8e10c82015-10-14 11:24:40 -0700419 groupHandlerMap.clear();
420
Charles Chand55e84d2016-03-30 17:54:24 -0700421 nsNextObjStore.destroy();
422 subnetNextObjStore.destroy();
423 portNextObjStore.destroy();
Charles Chand55e84d2016-03-30 17:54:24 -0700424 tunnelStore.destroy();
425 policyStore.destroy();
426 subnetVidStore.destroy();
sanghob35a6192015-04-01 13:05:26 -0700427 log.info("Stopped");
428 }
429
sangho1e575652015-05-14 00:39:53 -0700430 @Override
431 public List<Tunnel> getTunnels() {
432 return tunnelHandler.getTunnels();
433 }
434
435 @Override
sangho71abe1b2015-06-29 14:58:47 -0700436 public TunnelHandler.Result createTunnel(Tunnel tunnel) {
437 return tunnelHandler.createTunnel(tunnel);
sangho1e575652015-05-14 00:39:53 -0700438 }
439
440 @Override
sangho71abe1b2015-06-29 14:58:47 -0700441 public TunnelHandler.Result removeTunnel(Tunnel tunnel) {
sangho1e575652015-05-14 00:39:53 -0700442 for (Policy policy: policyHandler.getPolicies()) {
443 if (policy.type() == Policy.Type.TUNNEL_FLOW) {
444 TunnelPolicy tunnelPolicy = (TunnelPolicy) policy;
445 if (tunnelPolicy.tunnelId().equals(tunnel.id())) {
446 log.warn("Cannot remove the tunnel used by a policy");
sangho71abe1b2015-06-29 14:58:47 -0700447 return TunnelHandler.Result.TUNNEL_IN_USE;
sangho1e575652015-05-14 00:39:53 -0700448 }
449 }
450 }
sangho71abe1b2015-06-29 14:58:47 -0700451 return tunnelHandler.removeTunnel(tunnel);
sangho1e575652015-05-14 00:39:53 -0700452 }
453
454 @Override
sangho71abe1b2015-06-29 14:58:47 -0700455 public PolicyHandler.Result removePolicy(Policy policy) {
456 return policyHandler.removePolicy(policy);
sangho1e575652015-05-14 00:39:53 -0700457 }
458
459 @Override
sangho71abe1b2015-06-29 14:58:47 -0700460 public PolicyHandler.Result createPolicy(Policy policy) {
461 return policyHandler.createPolicy(policy);
sangho1e575652015-05-14 00:39:53 -0700462 }
463
464 @Override
465 public List<Policy> getPolicies() {
466 return policyHandler.getPolicies();
467 }
468
Saurav Das59232cf2016-04-27 18:35:50 -0700469 @Override
470 public void rerouteNetwork() {
471 cfgListener.configureNetwork();
472 for (Device device : deviceService.getDevices()) {
473 defaultRoutingHandler.populatePortAddressingRules(device.id());
474 }
475 defaultRoutingHandler.startPopulationProcess();
476 }
477
Charles Chanc81c45b2016-10-20 17:02:44 -0700478 @Override
Pier Ventre10bd8d12016-11-26 21:05:22 -0800479 public Map<DeviceId, Set<IpPrefix>> getDeviceSubnetMap() {
480 Map<DeviceId, Set<IpPrefix>> deviceSubnetMap = Maps.newHashMap();
Charles Chanc81c45b2016-10-20 17:02:44 -0700481 deviceService.getAvailableDevices().forEach(device -> {
482 deviceSubnetMap.put(device.id(), deviceConfiguration.getSubnets(device.id()));
483 });
484 return deviceSubnetMap;
485 }
486
sanghof9d0bf12015-05-19 11:57:42 -0700487 /**
Pier Ventre98161782016-10-31 15:00:01 -0700488 * Returns the MPLS-ECMP configuration.
489 *
490 * @return MPLS-ECMP value
491 */
492 public boolean getMplsEcmp() {
493 SegmentRoutingAppConfig segmentRoutingAppConfig = cfgService
494 .getConfig(this.appId, SegmentRoutingAppConfig.class);
495 return segmentRoutingAppConfig != null && segmentRoutingAppConfig.mplsEcmp();
496 }
497
498 /**
sanghof9d0bf12015-05-19 11:57:42 -0700499 * Returns the tunnel object with the tunnel ID.
500 *
501 * @param tunnelId Tunnel ID
502 * @return Tunnel reference
503 */
sangho1e575652015-05-14 00:39:53 -0700504 public Tunnel getTunnel(String tunnelId) {
505 return tunnelHandler.getTunnel(tunnelId);
506 }
507
sanghob35a6192015-04-01 13:05:26 -0700508 /**
Saurav Das0e99e2b2015-10-28 12:39:42 -0700509 * Returns the vlan-id assigned to the subnet configured for a device.
510 * If no vlan-id has been assigned, a new one is assigned out of a pool of ids,
511 * if and only if this controller instance is the master for the device.
512 * <p>
513 * USAGE: The assigned vlans are meant to be applied to untagged packets on those
514 * switches/pipelines that need this functionality. These vids are meant
515 * to be used internally within a switch, and thus need to be unique only
516 * on a switch level. Note that packets never go out on the wire with these
517 * vlans. Currently, vlan ids are assigned from value 4093 down.
518 * Vlan id 4094 expected to be used for all ports that are not assigned subnets.
519 * Vlan id 4095 is reserved and unused. Only a single vlan id is assigned
520 * per subnet.
sanghob35a6192015-04-01 13:05:26 -0700521 *
Saurav Das0e99e2b2015-10-28 12:39:42 -0700522 * @param deviceId switch dpid
523 * @param subnet IPv4 prefix for which assigned vlan is desired
524 * @return VlanId assigned for the subnet on the device, or
525 * null if no vlan assignment was found and this instance is not
526 * the master for the device.
sanghob35a6192015-04-01 13:05:26 -0700527 */
Charles Chane849c192016-01-11 18:28:54 -0800528 // TODO: We should avoid assigning VLAN IDs that are used by VLAN cross-connection.
Pier Ventre10bd8d12016-11-26 21:05:22 -0800529 public VlanId getSubnetAssignedVlanId(DeviceId deviceId, IpPrefix subnet) {
Saurav Das0e99e2b2015-10-28 12:39:42 -0700530 VlanId assignedVid = subnetVidStore.get(new SubnetAssignedVidStoreKey(
531 deviceId, subnet));
532 if (assignedVid != null) {
533 log.debug("Query for subnet:{} on device:{} returned assigned-vlan "
534 + "{}", subnet, deviceId, assignedVid);
535 return assignedVid;
536 }
537 //check mastership for the right to assign a vlan
538 if (!mastershipService.isLocalMaster(deviceId)) {
539 log.warn("This controller instance is not the master for device {}. "
540 + "Cannot assign vlan-id for subnet {}", deviceId, subnet);
541 return null;
542 }
543 // vlan assignment is expensive but done only once
Pier Ventre10bd8d12016-11-26 21:05:22 -0800544 // FIXME for now we will do assignment considering only the ipv4 subnet.
545 Set<Ip4Prefix> configuredSubnets = deviceConfiguration.getSubnets(deviceId)
546 .stream()
547 .filter(IpPrefix::isIp4)
548 .map(IpPrefix::getIp4Prefix)
549 .collect(Collectors.toSet());
Saurav Das0e99e2b2015-10-28 12:39:42 -0700550 Set<Short> assignedVlans = new HashSet<>();
551 Set<Ip4Prefix> unassignedSubnets = new HashSet<>();
552 for (Ip4Prefix sub : configuredSubnets) {
553 VlanId v = subnetVidStore.get(new SubnetAssignedVidStoreKey(deviceId,
554 sub));
555 if (v != null) {
556 assignedVlans.add(v.toShort());
557 } else {
558 unassignedSubnets.add(sub);
559 }
560 }
561 short nextAssignedVlan = ASSIGNED_VLAN_START;
562 if (!assignedVlans.isEmpty()) {
563 nextAssignedVlan = (short) (Collections.min(assignedVlans) - 1);
564 }
565 for (Ip4Prefix unsub : unassignedSubnets) {
Charles Chan5270ed02016-01-30 23:22:37 -0800566 // Special case for default route. Assign default VLAN ID to /32 and /0 subnets
567 if (unsub.prefixLength() == IpPrefix.MAX_INET_MASK_LENGTH ||
568 unsub.prefixLength() == 0) {
569 subnetVidStore.put(new SubnetAssignedVidStoreKey(deviceId, unsub),
570 VlanId.vlanId(ASSIGNED_VLAN_NO_SUBNET));
571 } else {
572 subnetVidStore.put(new SubnetAssignedVidStoreKey(deviceId, unsub),
573 VlanId.vlanId(nextAssignedVlan--));
574 log.info("Assigned vlan: {} to subnet: {} on device: {}",
575 nextAssignedVlan + 1, unsub, deviceId);
576 }
sanghob35a6192015-04-01 13:05:26 -0700577 }
578
Saurav Das0e99e2b2015-10-28 12:39:42 -0700579 return subnetVidStore.get(new SubnetAssignedVidStoreKey(deviceId, subnet));
sanghob35a6192015-04-01 13:05:26 -0700580 }
581
sangho1e575652015-05-14 00:39:53 -0700582 /**
Saurav Das0e99e2b2015-10-28 12:39:42 -0700583 * Returns the next objective ID for the given NeighborSet.
Saurav Das8a0732e2015-11-20 15:27:53 -0800584 * If the nextObjective does not exist, a new one is created and
Saurav Das4ce45962015-11-24 23:21:05 -0800585 * its id is returned.
sangho1e575652015-05-14 00:39:53 -0700586 *
sanghof9d0bf12015-05-19 11:57:42 -0700587 * @param deviceId Device ID
588 * @param ns NegighborSet
Saurav Das8a0732e2015-11-20 15:27:53 -0800589 * @param meta metadata passed into the creation of a Next Objective
590 * @return next objective ID or -1 if an error was encountered during the
591 * creation of the nextObjective
sangho1e575652015-05-14 00:39:53 -0700592 */
Saurav Das8a0732e2015-11-20 15:27:53 -0800593 public int getNextObjectiveId(DeviceId deviceId, NeighborSet ns,
594 TrafficSelector meta) {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700595 if (groupHandlerMap.get(deviceId) != null) {
596 log.trace("getNextObjectiveId query in device {}", deviceId);
597 return groupHandlerMap
Saurav Das8a0732e2015-11-20 15:27:53 -0800598 .get(deviceId).getNextObjectiveId(ns, meta);
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700599 } else {
Saurav Das4ce45962015-11-24 23:21:05 -0800600 log.warn("getNextObjectiveId query - groupHandler for device {} "
601 + "not found", deviceId);
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700602 return -1;
603 }
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700604 }
605
Charles Chanc42e84e2015-10-20 16:24:19 -0700606 /**
Saurav Das4ce45962015-11-24 23:21:05 -0800607 * Returns the next objective ID for the given subnet prefix. It is expected
608 * that the next-objective has been pre-created from configuration.
Charles Chanc42e84e2015-10-20 16:24:19 -0700609 *
610 * @param deviceId Device ID
611 * @param prefix Subnet
Saurav Das4ce45962015-11-24 23:21:05 -0800612 * @return next objective ID or -1 if it was not found
Charles Chanc42e84e2015-10-20 16:24:19 -0700613 */
614 public int getSubnetNextObjectiveId(DeviceId deviceId, IpPrefix prefix) {
615 if (groupHandlerMap.get(deviceId) != null) {
616 log.trace("getSubnetNextObjectiveId query in device {}", deviceId);
617 return groupHandlerMap
618 .get(deviceId).getSubnetNextObjectiveId(prefix);
619 } else {
Saurav Das4ce45962015-11-24 23:21:05 -0800620 log.warn("getSubnetNextObjectiveId query - groupHandler for "
621 + "device {} not found", deviceId);
622 return -1;
623 }
624 }
625
626 /**
627 * Returns the next objective ID for the given portNumber, given the treatment.
628 * There could be multiple different treatments to the same outport, which
629 * would result in different objectives. If the next object
630 * does not exist, a new one is created and its id is returned.
631 *
632 * @param deviceId Device ID
633 * @param portNum port number on device for which NextObjective is queried
634 * @param treatment the actions to apply on the packets (should include outport)
635 * @param meta metadata passed into the creation of a Next Objective if necessary
Saurav Das59232cf2016-04-27 18:35:50 -0700636 * @return next objective ID or -1 if an error occurred during retrieval or creation
Saurav Das4ce45962015-11-24 23:21:05 -0800637 */
638 public int getPortNextObjectiveId(DeviceId deviceId, PortNumber portNum,
639 TrafficTreatment treatment,
640 TrafficSelector meta) {
641 DefaultGroupHandler ghdlr = groupHandlerMap.get(deviceId);
642 if (ghdlr != null) {
643 return ghdlr.getPortNextObjectiveId(portNum, treatment, meta);
644 } else {
Charles Chane849c192016-01-11 18:28:54 -0800645 log.warn("getPortNextObjectiveId query - groupHandler for device {}"
646 + " not found", deviceId);
647 return -1;
648 }
649 }
650
sanghob35a6192015-04-01 13:05:26 -0700651 private class InternalPacketProcessor implements PacketProcessor {
sanghob35a6192015-04-01 13:05:26 -0700652 @Override
653 public void process(PacketContext context) {
654
655 if (context.isHandled()) {
656 return;
657 }
658
659 InboundPacket pkt = context.inPacket();
660 Ethernet ethernet = pkt.parsed();
Saurav Das4ce45962015-11-24 23:21:05 -0800661 log.trace("Rcvd pktin: {}", ethernet);
Pier Ventree0ae7a32016-11-23 09:57:42 -0800662 if (ethernet.getEtherType() == TYPE_ARP) {
Pier Ventre10bd8d12016-11-26 21:05:22 -0800663 log.warn("{} - we are still receiving ARP packets from {}",
664 context.inPacket().receivedFrom());
665 log.debug("{}", ethernet);
sanghob35a6192015-04-01 13:05:26 -0700666 } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV4) {
667 IPv4 ipPacket = (IPv4) ethernet.getPayload();
Charles Chan50035632017-01-13 17:20:44 -0800668 // ipHandler.addToPacketBuffer(ipPacket);
sanghob35a6192015-04-01 13:05:26 -0700669 if (ipPacket.getProtocol() == IPv4.PROTOCOL_ICMP) {
670 icmpHandler.processPacketIn(pkt);
671 } else {
Charles Chan50035632017-01-13 17:20:44 -0800672 // NOTE: We don't support IP learning at this moment so this
673 // is not necessary. Also it causes duplication of DHCP packets.
674 // ipHandler.processPacketIn(pkt);
sanghob35a6192015-04-01 13:05:26 -0700675 }
Pier Ventre10bd8d12016-11-26 21:05:22 -0800676 } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV6) {
677 IPv6 ipv6Packet = (IPv6) ethernet.getPayload();
678 /*
679 * TODO send to ICMPv6 handler and generalize the interaction with IP Handler
680 */
sanghob35a6192015-04-01 13:05:26 -0700681 }
682 }
683 }
684
685 private class InternalLinkListener implements LinkListener {
686 @Override
687 public void event(LinkEvent event) {
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700688 if (event.type() == LinkEvent.Type.LINK_ADDED
689 || event.type() == LinkEvent.Type.LINK_REMOVED) {
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700690 log.debug("Event {} received from Link Service", event.type());
sanghob35a6192015-04-01 13:05:26 -0700691 scheduleEventHandlerIfNotScheduled(event);
692 }
693 }
694 }
695
696 private class InternalDeviceListener implements DeviceListener {
sanghob35a6192015-04-01 13:05:26 -0700697 @Override
698 public void event(DeviceEvent event) {
sanghob35a6192015-04-01 13:05:26 -0700699 switch (event.type()) {
700 case DEVICE_ADDED:
Saurav Das1a129a02016-11-18 15:21:57 -0800701 case PORT_UPDATED:
702 case PORT_ADDED:
sangho20eff1d2015-04-13 15:15:58 -0700703 case DEVICE_UPDATED:
704 case DEVICE_AVAILABILITY_CHANGED:
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700705 log.debug("Event {} received from Device Service", event.type());
sanghob35a6192015-04-01 13:05:26 -0700706 scheduleEventHandlerIfNotScheduled(event);
707 break;
708 default:
709 }
710 }
711 }
712
Saurav Das4ce45962015-11-24 23:21:05 -0800713 @SuppressWarnings("rawtypes")
sanghob35a6192015-04-01 13:05:26 -0700714 private void scheduleEventHandlerIfNotScheduled(Event event) {
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700715 synchronized (threadSchedulerLock) {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700716 eventQueue.add(event);
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700717 numOfEventsQueued++;
718
719 if ((numOfHandlerScheduled - numOfHandlerExecution) == 0) {
720 //No pending scheduled event handling threads. So start a new one.
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700721 eventHandlerFuture = executorService
722 .schedule(eventHandler, 100, TimeUnit.MILLISECONDS);
723 numOfHandlerScheduled++;
724 }
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700725 log.trace("numOfEventsQueued {}, numOfEventHandlerScheduled {}",
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700726 numOfEventsQueued,
727 numOfHandlerScheduled);
sanghob35a6192015-04-01 13:05:26 -0700728 }
sanghob35a6192015-04-01 13:05:26 -0700729 }
730
731 private class InternalEventHandler implements Runnable {
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700732 @Override
sanghob35a6192015-04-01 13:05:26 -0700733 public void run() {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700734 try {
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700735 while (true) {
Saurav Das4ce45962015-11-24 23:21:05 -0800736 @SuppressWarnings("rawtypes")
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700737 Event event = null;
738 synchronized (threadSchedulerLock) {
739 if (!eventQueue.isEmpty()) {
740 event = eventQueue.poll();
741 numOfEventsExecuted++;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700742 } else {
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700743 numOfHandlerExecution++;
744 log.debug("numOfHandlerExecution {} numOfEventsExecuted {}",
745 numOfHandlerExecution, numOfEventsExecuted);
746 break;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700747 }
sangho20eff1d2015-04-13 15:15:58 -0700748 }
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700749 if (event.type() == LinkEvent.Type.LINK_ADDED) {
750 processLinkAdded((Link) event.subject());
751 } else if (event.type() == LinkEvent.Type.LINK_REMOVED) {
Pier Ventre2c515312016-09-13 21:33:40 -0700752 Link linkRemoved = (Link) event.subject();
753 if (linkRemoved.src().elementId() instanceof DeviceId &&
754 !deviceService.isAvailable(linkRemoved.src().deviceId())) {
755 continue;
756 }
757 if (linkRemoved.dst().elementId() instanceof DeviceId &&
758 !deviceService.isAvailable(linkRemoved.dst().deviceId())) {
759 continue;
760 }
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700761 processLinkRemoved((Link) event.subject());
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700762 } else if (event.type() == DeviceEvent.Type.DEVICE_ADDED ||
763 event.type() == DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED ||
764 event.type() == DeviceEvent.Type.DEVICE_UPDATED) {
Saurav Das423fe2b2015-12-04 10:52:59 -0800765 DeviceId deviceId = ((Device) event.subject()).id();
766 if (deviceService.isAvailable(deviceId)) {
Saurav Das837e0bb2015-10-30 17:45:38 -0700767 log.info("Processing device event {} for available device {}",
768 event.type(), ((Device) event.subject()).id());
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700769 processDeviceAdded((Device) event.subject());
Saurav Das80980c72016-03-23 11:22:49 -0700770 } else {
771 log.info("Processing device event {} for unavailable device {}",
772 event.type(), ((Device) event.subject()).id());
773 processDeviceRemoved((Device) event.subject());
774 }
Saurav Das1a129a02016-11-18 15:21:57 -0800775 } else if (event.type() == DeviceEvent.Type.PORT_ADDED) {
Saurav Dasd2fded02016-12-02 15:43:47 -0800776 // typically these calls come when device is added first time
777 // so port filtering rules are handled at the device_added event.
778 // port added calls represent all ports on the device,
779 // enabled or not.
Saurav Das1a129a02016-11-18 15:21:57 -0800780 log.debug("** PORT ADDED {}/{} -> {}",
Saurav Dasd2fded02016-12-02 15:43:47 -0800781 ((DeviceEvent) event).subject().id(),
782 ((DeviceEvent) event).port().number(),
783 event.type());
Saurav Das1a129a02016-11-18 15:21:57 -0800784 } else if (event.type() == DeviceEvent.Type.PORT_UPDATED) {
Saurav Dasd2fded02016-12-02 15:43:47 -0800785 // these calls happen for every subsequent event
786 // ports enabled, disabled, switch goes away, comes back
Saurav Das1a129a02016-11-18 15:21:57 -0800787 log.info("** PORT UPDATED {}/{} -> {}",
788 event.subject(),
789 ((DeviceEvent) event).port(),
790 event.type());
791 processPortUpdated(((Device) event.subject()),
792 ((DeviceEvent) event).port());
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700793 } else {
794 log.warn("Unhandled event type: {}", event.type());
795 }
sanghob35a6192015-04-01 13:05:26 -0700796 }
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700797 } catch (Exception e) {
798 log.error("SegmentRouting event handler "
799 + "thread thrown an exception: {}", e);
sanghob35a6192015-04-01 13:05:26 -0700800 }
sanghob35a6192015-04-01 13:05:26 -0700801 }
802 }
803
sanghob35a6192015-04-01 13:05:26 -0700804 private void processLinkAdded(Link link) {
Saurav Dasb5c236e2016-06-07 10:08:06 -0700805 log.info("** LINK ADDED {}", link.toString());
Charles Chan0b4e6182015-11-03 10:42:14 -0800806 if (!deviceConfiguration.isConfigured(link.src().deviceId())) {
807 log.warn("Source device of this link is not configured.");
808 return;
809 }
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700810 //Irrespective whether the local is a MASTER or not for this device,
811 //create group handler instance and push default TTP flow rules.
812 //Because in a multi-instance setup, instances can initiate
813 //groups for any devices. Also the default TTP rules are needed
814 //to be pushed before inserting any IP table entries for any device
815 DefaultGroupHandler groupHandler = groupHandlerMap.get(link.src()
816 .deviceId());
817 if (groupHandler != null) {
Saurav Das8a0732e2015-11-20 15:27:53 -0800818 groupHandler.linkUp(link, mastershipService.isLocalMaster(
819 link.src().deviceId()));
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700820 } else {
821 Device device = deviceService.getDevice(link.src().deviceId());
822 if (device != null) {
823 log.warn("processLinkAdded: Link Added "
824 + "Notification without Device Added "
825 + "event, still handling it");
826 processDeviceAdded(device);
827 groupHandler = groupHandlerMap.get(link.src()
828 .deviceId());
Saurav Das8a0732e2015-11-20 15:27:53 -0800829 groupHandler.linkUp(link, mastershipService.isLocalMaster(device.id()));
sanghob35a6192015-04-01 13:05:26 -0700830 }
831 }
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700832
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700833 log.trace("Starting optimized route population process");
834 defaultRoutingHandler.populateRoutingRulesForLinkStatusChange(null);
835 //log.trace("processLinkAdded: re-starting route population process");
836 //defaultRoutingHandler.startPopulationProcess();
Charles Chan2199c302016-04-23 17:36:10 -0700837
838 mcastHandler.init();
sanghob35a6192015-04-01 13:05:26 -0700839 }
840
841 private void processLinkRemoved(Link link) {
Saurav Dasb5c236e2016-06-07 10:08:06 -0700842 log.info("** LINK REMOVED {}", link.toString());
sangho834e4b02015-05-01 09:38:25 -0700843 DefaultGroupHandler groupHandler = groupHandlerMap.get(link.src().deviceId());
844 if (groupHandler != null) {
Saurav Das423fe2b2015-12-04 10:52:59 -0800845 groupHandler.portDown(link.src().port(),
846 mastershipService.isLocalMaster(link.src().deviceId()));
sangho834e4b02015-05-01 09:38:25 -0700847 }
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700848 log.trace("Starting optimized route population process");
849 defaultRoutingHandler.populateRoutingRulesForLinkStatusChange(link);
850 //log.trace("processLinkRemoved: re-starting route population process");
851 //defaultRoutingHandler.startPopulationProcess();
Charles Chan2199c302016-04-23 17:36:10 -0700852
853 mcastHandler.processLinkDown(link);
sanghob35a6192015-04-01 13:05:26 -0700854 }
855
856 private void processDeviceAdded(Device device) {
Saurav Dasb5c236e2016-06-07 10:08:06 -0700857 log.info("** DEVICE ADDED with ID {}", device.id());
Charles Chan0b4e6182015-11-03 10:42:14 -0800858 if (deviceConfiguration == null || !deviceConfiguration.isConfigured(device.id())) {
Saurav Das2857f382015-11-03 14:39:27 -0800859 log.warn("Device configuration uploading. Device {} will be "
860 + "processed after config completes.", device.id());
861 return;
862 }
Charles Chan2199c302016-04-23 17:36:10 -0700863 processDeviceAddedInternal(device.id());
864 }
865
866 private void processDeviceAddedInternal(DeviceId deviceId) {
Saurav Das837e0bb2015-10-30 17:45:38 -0700867 // Irrespective of whether the local is a MASTER or not for this device,
868 // we need to create a SR-group-handler instance. This is because in a
869 // multi-instance setup, any instance can initiate forwarding/next-objectives
870 // for any switch (even if this instance is a SLAVE or not even connected
871 // to the switch). To handle this, a default-group-handler instance is necessary
872 // per switch.
Charles Chan2199c302016-04-23 17:36:10 -0700873 log.debug("Current groupHandlerMap devs: {}", groupHandlerMap.keySet());
874 if (groupHandlerMap.get(deviceId) == null) {
Charles Chan0b4e6182015-11-03 10:42:14 -0800875 DefaultGroupHandler groupHandler;
876 try {
877 groupHandler = DefaultGroupHandler.
Charles Chan2199c302016-04-23 17:36:10 -0700878 createGroupHandler(deviceId,
879 appId,
880 deviceConfiguration,
881 linkService,
882 flowObjectiveService,
883 this);
Charles Chan0b4e6182015-11-03 10:42:14 -0800884 } catch (DeviceConfigNotFoundException e) {
885 log.warn(e.getMessage() + " Aborting processDeviceAdded.");
886 return;
887 }
Charles Chan2199c302016-04-23 17:36:10 -0700888 log.debug("updating groupHandlerMap with new config for device: {}",
889 deviceId);
890 groupHandlerMap.put(deviceId, groupHandler);
Saurav Das2857f382015-11-03 14:39:27 -0800891 }
Saurav Dasb5c236e2016-06-07 10:08:06 -0700892 // Also, in some cases, drivers may need extra
893 // information to process rules (eg. Router IP/MAC); and so, we send
894 // port addressing rules to the driver as well irrespective of whether
895 // this instance is the master or not.
896 defaultRoutingHandler.populatePortAddressingRules(deviceId);
897
Charles Chan2199c302016-04-23 17:36:10 -0700898 if (mastershipService.isLocalMaster(deviceId)) {
Charles Chan03a73e02016-10-24 14:52:01 -0700899 hostHandler.init(deviceId);
Charles Chanfc5c7802016-05-17 13:13:55 -0700900 xConnectHandler.init(deviceId);
Charles Chan35fd1a72016-06-13 18:54:31 -0700901 cordConfigHandler.init(deviceId);
Charles Chan2199c302016-04-23 17:36:10 -0700902 DefaultGroupHandler groupHandler = groupHandlerMap.get(deviceId);
Charles Chanc42e84e2015-10-20 16:24:19 -0700903 groupHandler.createGroupsFromSubnetConfig();
Charles Chan2199c302016-04-23 17:36:10 -0700904 routingRulePopulator.populateSubnetBroadcastRule(deviceId);
Charles Chanc42e84e2015-10-20 16:24:19 -0700905 }
Charles Chan5270ed02016-01-30 23:22:37 -0800906
Charles Chan03a73e02016-10-24 14:52:01 -0700907 appCfgHandler.init(deviceId);
908 routeHandler.init(deviceId);
sanghob35a6192015-04-01 13:05:26 -0700909 }
910
Saurav Das80980c72016-03-23 11:22:49 -0700911 private void processDeviceRemoved(Device device) {
912 nsNextObjStore.entrySet().stream()
913 .filter(entry -> entry.getKey().deviceId().equals(device.id()))
914 .forEach(entry -> {
915 nsNextObjStore.remove(entry.getKey());
916 });
Saurav Das80980c72016-03-23 11:22:49 -0700917 subnetNextObjStore.entrySet().stream()
918 .filter(entry -> entry.getKey().deviceId().equals(device.id()))
919 .forEach(entry -> {
920 subnetNextObjStore.remove(entry.getKey());
921 });
Saurav Das80980c72016-03-23 11:22:49 -0700922 portNextObjStore.entrySet().stream()
923 .filter(entry -> entry.getKey().deviceId().equals(device.id()))
924 .forEach(entry -> {
925 portNextObjStore.remove(entry.getKey());
926 });
Saurav Das80980c72016-03-23 11:22:49 -0700927 subnetVidStore.entrySet().stream()
928 .filter(entry -> entry.getKey().deviceId().equals(device.id()))
929 .forEach(entry -> {
930 subnetVidStore.remove(entry.getKey());
931 });
Saurav Das80980c72016-03-23 11:22:49 -0700932 groupHandlerMap.remove(device.id());
Saurav Das80980c72016-03-23 11:22:49 -0700933 defaultRoutingHandler.purgeEcmpGraph(device.id());
Charles Chan2199c302016-04-23 17:36:10 -0700934 mcastHandler.removeDevice(device.id());
Charles Chanfc5c7802016-05-17 13:13:55 -0700935 xConnectHandler.removeDevice(device.id());
Saurav Das80980c72016-03-23 11:22:49 -0700936 }
937
Saurav Das1a129a02016-11-18 15:21:57 -0800938 private void processPortUpdated(Device device, Port port) {
939 if (deviceConfiguration == null || !deviceConfiguration.isConfigured(device.id())) {
940 log.warn("Device configuration uploading. Not handling port event for"
941 + "dev: {} port: {}", device.id(), port.number());
942 return;
943 }
944 /* XXX create method for single port filtering rules which are needed
945 for both switch-to-switch ports and edge ports
946 if (defaultRoutingHandler != null) {
947 defaultRoutingHandler.populatePortAddressingRules(
948 ((Device) event.subject()).id());
949 }*/
950
951 // portUpdated calls are for ports that have gone down or up. For switch
952 // to switch ports, link-events should take care of any re-routing or
953 // group editing necessary for port up/down. Here we only process edge ports
954 // that are already configured.
Pier Ventre10bd8d12016-11-26 21:05:22 -0800955 Ip4Prefix configuredSubnet = deviceConfiguration.getPortIPv4Subnet(device.id(),
Saurav Das1a129a02016-11-18 15:21:57 -0800956 port.number());
957 if (configuredSubnet == null) {
958 log.debug("Not handling port updated event for unconfigured port "
959 + "dev/port: {}/{}", device.id(), port.number());
960 return;
961 }
962 processEdgePort(device, port, configuredSubnet);
963 }
964
965 private void processEdgePort(Device device, Port port, Ip4Prefix subnet) {
966 boolean portUp = port.isEnabled();
967 if (portUp) {
968 log.info("Device:EdgePort {}:{} is enabled in subnet: {}", device.id(),
969 port.number(), subnet);
970 } else {
971 log.info("Device:EdgePort {}:{} is disabled in subnet: {}", device.id(),
972 port.number(), subnet);
973 }
974
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700975 DefaultGroupHandler groupHandler = groupHandlerMap.get(device.id());
sanghob35a6192015-04-01 13:05:26 -0700976 if (groupHandler != null) {
Saurav Das1a129a02016-11-18 15:21:57 -0800977 groupHandler.processEdgePort(port.number(), subnet, portUp,
Saurav Das423fe2b2015-12-04 10:52:59 -0800978 mastershipService.isLocalMaster(device.id()));
Saurav Das1a129a02016-11-18 15:21:57 -0800979 } else {
980 log.warn("Group handler not found for dev:{}. Not handling edge port"
981 + " {} event for port:{}", device.id(),
982 (portUp) ? "UP" : "DOWN", port.number());
sanghob35a6192015-04-01 13:05:26 -0700983 }
984 }
sangho1e575652015-05-14 00:39:53 -0700985
Pier Ventre10bd8d12016-11-26 21:05:22 -0800986 /**
987 * Registers the given connect point with the NRS, this is necessary
988 * to receive the NDP and ARP packets from the NRS.
989 *
990 * @param portToRegister connect point to register
991 */
992 public void registerConnectPoint(ConnectPoint portToRegister) {
993 /*
994 * First we register the ARP handler.
995 */
996 this.neighbourResolutionService.registerNeighbourHandler(
997 portToRegister,
998 neighbourHandler,
999 appId
1000 );
1001 }
1002
Charles Chand6832882015-10-05 17:50:33 -07001003 private class InternalConfigListener implements NetworkConfigListener {
Charles Chan2c15aca2016-11-09 20:51:44 -08001004 SegmentRoutingManager srManager;
Charles Chan4636be02015-10-07 14:21:45 -07001005
Charles Chane849c192016-01-11 18:28:54 -08001006 /**
1007 * Constructs the internal network config listener.
1008 *
Charles Chan2c15aca2016-11-09 20:51:44 -08001009 * @param srManager segment routing manager
Charles Chane849c192016-01-11 18:28:54 -08001010 */
Charles Chan2c15aca2016-11-09 20:51:44 -08001011 public InternalConfigListener(SegmentRoutingManager srManager) {
1012 this.srManager = srManager;
Charles Chan4636be02015-10-07 14:21:45 -07001013 }
1014
Charles Chane849c192016-01-11 18:28:54 -08001015 /**
1016 * Reads network config and initializes related data structure accordingly.
1017 */
Charles Chan4636be02015-10-07 14:21:45 -07001018 public void configureNetwork() {
Pier Ventre10bd8d12016-11-26 21:05:22 -08001019
Charles Chan2c15aca2016-11-09 20:51:44 -08001020 deviceConfiguration = new DeviceConfiguration(srManager);
Charles Chan4636be02015-10-07 14:21:45 -07001021
Charles Chan2c15aca2016-11-09 20:51:44 -08001022 arpHandler = new ArpHandler(srManager);
1023 icmpHandler = new IcmpHandler(srManager);
1024 ipHandler = new IpHandler(srManager);
1025 routingRulePopulator = new RoutingRulePopulator(srManager);
1026 defaultRoutingHandler = new DefaultRoutingHandler(srManager);
Charles Chan4636be02015-10-07 14:21:45 -07001027
1028 tunnelHandler = new TunnelHandler(linkService, deviceConfiguration,
1029 groupHandlerMap, tunnelStore);
1030 policyHandler = new PolicyHandler(appId, deviceConfiguration,
1031 flowObjectiveService,
1032 tunnelHandler, policyStore);
1033
Charles Chan4636be02015-10-07 14:21:45 -07001034 for (Device device : deviceService.getDevices()) {
Charles Chan2199c302016-04-23 17:36:10 -07001035 processDeviceAddedInternal(device.id());
Charles Chan4636be02015-10-07 14:21:45 -07001036 }
1037
1038 defaultRoutingHandler.startPopulationProcess();
Charles Chan2199c302016-04-23 17:36:10 -07001039 mcastHandler.init();
Charles Chan4636be02015-10-07 14:21:45 -07001040 }
1041
Charles Chand6832882015-10-05 17:50:33 -07001042 @Override
1043 public void event(NetworkConfigEvent event) {
Charles Chan5270ed02016-01-30 23:22:37 -08001044 // TODO move this part to NetworkConfigEventHandler
1045 if (event.configClass().equals(SegmentRoutingDeviceConfig.class)) {
1046 switch (event.type()) {
1047 case CONFIG_ADDED:
1048 log.info("Segment Routing Config added.");
1049 configureNetwork();
1050 break;
1051 case CONFIG_UPDATED:
1052 log.info("Segment Routing Config updated.");
1053 // TODO support dynamic configuration
1054 break;
1055 default:
1056 break;
Charles Chanb8e10c82015-10-14 11:24:40 -07001057 }
Charles Chan5270ed02016-01-30 23:22:37 -08001058 } else if (event.configClass().equals(SegmentRoutingAppConfig.class)) {
Charles Chanfc5c7802016-05-17 13:13:55 -07001059 checkState(appCfgHandler != null, "NetworkConfigEventHandler is not initialized");
Charles Chan5270ed02016-01-30 23:22:37 -08001060 switch (event.type()) {
1061 case CONFIG_ADDED:
Charles Chanfc5c7802016-05-17 13:13:55 -07001062 appCfgHandler.processAppConfigAdded(event);
Charles Chan5270ed02016-01-30 23:22:37 -08001063 break;
1064 case CONFIG_UPDATED:
Charles Chanfc5c7802016-05-17 13:13:55 -07001065 appCfgHandler.processAppConfigUpdated(event);
Charles Chan5270ed02016-01-30 23:22:37 -08001066 break;
1067 case CONFIG_REMOVED:
Charles Chanfc5c7802016-05-17 13:13:55 -07001068 appCfgHandler.processAppConfigRemoved(event);
1069 break;
1070 default:
1071 break;
1072 }
Charles Chan03a73e02016-10-24 14:52:01 -07001073 configureNetwork();
Charles Chanfc5c7802016-05-17 13:13:55 -07001074 } else if (event.configClass().equals(XConnectConfig.class)) {
1075 checkState(xConnectHandler != null, "XConnectHandler is not initialized");
1076 switch (event.type()) {
1077 case CONFIG_ADDED:
1078 xConnectHandler.processXConnectConfigAdded(event);
1079 break;
1080 case CONFIG_UPDATED:
1081 xConnectHandler.processXConnectConfigUpdated(event);
1082 break;
1083 case CONFIG_REMOVED:
1084 xConnectHandler.processXConnectConfigRemoved(event);
Charles Chan5270ed02016-01-30 23:22:37 -08001085 break;
1086 default:
1087 break;
Charles Chanb8e10c82015-10-14 11:24:40 -07001088 }
Charles Chand6832882015-10-05 17:50:33 -07001089 }
1090 }
1091 }
Charles Chan68aa62d2015-11-09 16:37:23 -08001092
1093 private class InternalHostListener implements HostListener {
Charles Chan68aa62d2015-11-09 16:37:23 -08001094 @Override
1095 public void event(HostEvent event) {
1096 // Do not proceed without mastership
1097 DeviceId deviceId = event.subject().location().deviceId();
1098 if (!mastershipService.isLocalMaster(deviceId)) {
1099 return;
1100 }
1101
1102 switch (event.type()) {
1103 case HOST_ADDED:
Charles Chand2990362016-04-18 13:44:03 -07001104 hostHandler.processHostAddedEvent(event);
Charles Chan68aa62d2015-11-09 16:37:23 -08001105 break;
1106 case HOST_MOVED:
Charles Chand2990362016-04-18 13:44:03 -07001107 hostHandler.processHostMovedEvent(event);
Charles Chan68aa62d2015-11-09 16:37:23 -08001108 break;
1109 case HOST_REMOVED:
Charles Chand2990362016-04-18 13:44:03 -07001110 hostHandler.processHostRemoveEvent(event);
Charles Chan68aa62d2015-11-09 16:37:23 -08001111 break;
1112 case HOST_UPDATED:
Charles Chand2990362016-04-18 13:44:03 -07001113 hostHandler.processHostUpdatedEvent(event);
Charles Chan68aa62d2015-11-09 16:37:23 -08001114 break;
1115 default:
1116 log.warn("Unsupported host event type: {}", event.type());
1117 break;
1118 }
1119 }
1120 }
1121
Charles Chand55e84d2016-03-30 17:54:24 -07001122 private class InternalMcastListener implements McastListener {
1123 @Override
1124 public void event(McastEvent event) {
1125 switch (event.type()) {
1126 case SOURCE_ADDED:
Charles Chand2990362016-04-18 13:44:03 -07001127 mcastHandler.processSourceAdded(event);
Charles Chand55e84d2016-03-30 17:54:24 -07001128 break;
1129 case SINK_ADDED:
Charles Chand2990362016-04-18 13:44:03 -07001130 mcastHandler.processSinkAdded(event);
Charles Chand55e84d2016-03-30 17:54:24 -07001131 break;
1132 case SINK_REMOVED:
Charles Chand2990362016-04-18 13:44:03 -07001133 mcastHandler.processSinkRemoved(event);
Charles Chand55e84d2016-03-30 17:54:24 -07001134 break;
1135 case ROUTE_ADDED:
1136 case ROUTE_REMOVED:
1137 default:
1138 break;
1139 }
1140 }
1141 }
Charles Chan35fd1a72016-06-13 18:54:31 -07001142
1143 private class InternalCordConfigListener implements CordConfigListener {
1144 @Override
1145 public void event(CordConfigEvent event) {
1146 switch (event.type()) {
1147 case ACCESS_AGENT_ADDED:
1148 cordConfigHandler.processAccessAgentAddedEvent(event);
1149 break;
1150 case ACCESS_AGENT_UPDATED:
1151 cordConfigHandler.processAccessAgentUpdatedEvent(event);
1152 break;
1153 case ACCESS_AGENT_REMOVED:
1154 cordConfigHandler.processAccessAgentRemovedEvent(event);
1155 break;
1156 case ACCESS_DEVICE_ADDED:
1157 case ACCESS_DEVICE_UPDATED:
1158 case ACCESS_DEVICE_REMOVED:
1159 default:
1160 break;
1161 }
1162 }
1163 }
Charles Chan03a73e02016-10-24 14:52:01 -07001164
1165 private class InternalRouteEventListener implements RouteListener {
1166 @Override
1167 public void event(RouteEvent event) {
1168 switch (event.type()) {
1169 case ROUTE_ADDED:
1170 routeHandler.processRouteAdded(event);
1171 break;
1172 case ROUTE_UPDATED:
1173 routeHandler.processRouteUpdated(event);
1174 break;
1175 case ROUTE_REMOVED:
1176 routeHandler.processRouteRemoved(event);
1177 break;
1178 default:
1179 break;
1180 }
1181 }
1182 }
sanghob35a6192015-04-01 13:05:26 -07001183}