blob: 1b8887bd269ef1d04a600f12f460c143698e7128 [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
Pier Ventref4b5fce2016-11-28 16:48:06 -0800523 * @param subnet IP prefix for which assigned vlan is desired
Saurav Das0e99e2b2015-10-28 12:39:42 -0700524 * @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) {
Pier Ventref4b5fce2016-11-28 16:48:06 -0800566 subnetVidStore.put(new SubnetAssignedVidStoreKey(deviceId, unsub),
567 VlanId.vlanId(nextAssignedVlan--));
568 log.info("Assigned vlan: {} to subnet: {} on device: {}",
569 nextAssignedVlan + 1, unsub, deviceId);
sanghob35a6192015-04-01 13:05:26 -0700570 }
Saurav Das0e99e2b2015-10-28 12:39:42 -0700571 return subnetVidStore.get(new SubnetAssignedVidStoreKey(deviceId, subnet));
sanghob35a6192015-04-01 13:05:26 -0700572 }
573
sangho1e575652015-05-14 00:39:53 -0700574 /**
Saurav Das0e99e2b2015-10-28 12:39:42 -0700575 * Returns the next objective ID for the given NeighborSet.
Saurav Das8a0732e2015-11-20 15:27:53 -0800576 * If the nextObjective does not exist, a new one is created and
Saurav Das4ce45962015-11-24 23:21:05 -0800577 * its id is returned.
sangho1e575652015-05-14 00:39:53 -0700578 *
sanghof9d0bf12015-05-19 11:57:42 -0700579 * @param deviceId Device ID
580 * @param ns NegighborSet
Saurav Das8a0732e2015-11-20 15:27:53 -0800581 * @param meta metadata passed into the creation of a Next Objective
582 * @return next objective ID or -1 if an error was encountered during the
583 * creation of the nextObjective
sangho1e575652015-05-14 00:39:53 -0700584 */
Saurav Das8a0732e2015-11-20 15:27:53 -0800585 public int getNextObjectiveId(DeviceId deviceId, NeighborSet ns,
586 TrafficSelector meta) {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700587 if (groupHandlerMap.get(deviceId) != null) {
588 log.trace("getNextObjectiveId query in device {}", deviceId);
589 return groupHandlerMap
Saurav Das8a0732e2015-11-20 15:27:53 -0800590 .get(deviceId).getNextObjectiveId(ns, meta);
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700591 } else {
Saurav Das4ce45962015-11-24 23:21:05 -0800592 log.warn("getNextObjectiveId query - groupHandler for device {} "
593 + "not found", deviceId);
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700594 return -1;
595 }
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700596 }
597
Charles Chanc42e84e2015-10-20 16:24:19 -0700598 /**
Saurav Das4ce45962015-11-24 23:21:05 -0800599 * Returns the next objective ID for the given subnet prefix. It is expected
600 * that the next-objective has been pre-created from configuration.
Charles Chanc42e84e2015-10-20 16:24:19 -0700601 *
602 * @param deviceId Device ID
603 * @param prefix Subnet
Saurav Das4ce45962015-11-24 23:21:05 -0800604 * @return next objective ID or -1 if it was not found
Charles Chanc42e84e2015-10-20 16:24:19 -0700605 */
606 public int getSubnetNextObjectiveId(DeviceId deviceId, IpPrefix prefix) {
607 if (groupHandlerMap.get(deviceId) != null) {
608 log.trace("getSubnetNextObjectiveId query in device {}", deviceId);
609 return groupHandlerMap
610 .get(deviceId).getSubnetNextObjectiveId(prefix);
611 } else {
Saurav Das4ce45962015-11-24 23:21:05 -0800612 log.warn("getSubnetNextObjectiveId query - groupHandler for "
613 + "device {} not found", deviceId);
614 return -1;
615 }
616 }
617
618 /**
619 * Returns the next objective ID for the given portNumber, given the treatment.
620 * There could be multiple different treatments to the same outport, which
621 * would result in different objectives. If the next object
622 * does not exist, a new one is created and its id is returned.
623 *
624 * @param deviceId Device ID
625 * @param portNum port number on device for which NextObjective is queried
626 * @param treatment the actions to apply on the packets (should include outport)
627 * @param meta metadata passed into the creation of a Next Objective if necessary
Saurav Das59232cf2016-04-27 18:35:50 -0700628 * @return next objective ID or -1 if an error occurred during retrieval or creation
Saurav Das4ce45962015-11-24 23:21:05 -0800629 */
630 public int getPortNextObjectiveId(DeviceId deviceId, PortNumber portNum,
631 TrafficTreatment treatment,
632 TrafficSelector meta) {
633 DefaultGroupHandler ghdlr = groupHandlerMap.get(deviceId);
634 if (ghdlr != null) {
635 return ghdlr.getPortNextObjectiveId(portNum, treatment, meta);
636 } else {
Charles Chane849c192016-01-11 18:28:54 -0800637 log.warn("getPortNextObjectiveId query - groupHandler for device {}"
638 + " not found", deviceId);
639 return -1;
640 }
641 }
642
sanghob35a6192015-04-01 13:05:26 -0700643 private class InternalPacketProcessor implements PacketProcessor {
sanghob35a6192015-04-01 13:05:26 -0700644 @Override
645 public void process(PacketContext context) {
646
647 if (context.isHandled()) {
648 return;
649 }
650
651 InboundPacket pkt = context.inPacket();
652 Ethernet ethernet = pkt.parsed();
Saurav Das4ce45962015-11-24 23:21:05 -0800653 log.trace("Rcvd pktin: {}", ethernet);
Pier Ventree0ae7a32016-11-23 09:57:42 -0800654 if (ethernet.getEtherType() == TYPE_ARP) {
Pier Ventre10bd8d12016-11-26 21:05:22 -0800655 log.warn("{} - we are still receiving ARP packets from {}",
656 context.inPacket().receivedFrom());
657 log.debug("{}", ethernet);
sanghob35a6192015-04-01 13:05:26 -0700658 } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV4) {
659 IPv4 ipPacket = (IPv4) ethernet.getPayload();
Charles Chan50035632017-01-13 17:20:44 -0800660 // ipHandler.addToPacketBuffer(ipPacket);
sanghob35a6192015-04-01 13:05:26 -0700661 if (ipPacket.getProtocol() == IPv4.PROTOCOL_ICMP) {
662 icmpHandler.processPacketIn(pkt);
663 } else {
Charles Chan50035632017-01-13 17:20:44 -0800664 // NOTE: We don't support IP learning at this moment so this
665 // is not necessary. Also it causes duplication of DHCP packets.
666 // ipHandler.processPacketIn(pkt);
sanghob35a6192015-04-01 13:05:26 -0700667 }
Pier Ventre10bd8d12016-11-26 21:05:22 -0800668 } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV6) {
669 IPv6 ipv6Packet = (IPv6) ethernet.getPayload();
670 /*
671 * TODO send to ICMPv6 handler and generalize the interaction with IP Handler
672 */
sanghob35a6192015-04-01 13:05:26 -0700673 }
674 }
675 }
676
677 private class InternalLinkListener implements LinkListener {
678 @Override
679 public void event(LinkEvent event) {
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700680 if (event.type() == LinkEvent.Type.LINK_ADDED
681 || event.type() == LinkEvent.Type.LINK_REMOVED) {
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700682 log.debug("Event {} received from Link Service", event.type());
sanghob35a6192015-04-01 13:05:26 -0700683 scheduleEventHandlerIfNotScheduled(event);
684 }
685 }
686 }
687
688 private class InternalDeviceListener implements DeviceListener {
sanghob35a6192015-04-01 13:05:26 -0700689 @Override
690 public void event(DeviceEvent event) {
sanghob35a6192015-04-01 13:05:26 -0700691 switch (event.type()) {
692 case DEVICE_ADDED:
Saurav Das1a129a02016-11-18 15:21:57 -0800693 case PORT_UPDATED:
694 case PORT_ADDED:
sangho20eff1d2015-04-13 15:15:58 -0700695 case DEVICE_UPDATED:
696 case DEVICE_AVAILABILITY_CHANGED:
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700697 log.debug("Event {} received from Device Service", event.type());
sanghob35a6192015-04-01 13:05:26 -0700698 scheduleEventHandlerIfNotScheduled(event);
699 break;
700 default:
701 }
702 }
703 }
704
Saurav Das4ce45962015-11-24 23:21:05 -0800705 @SuppressWarnings("rawtypes")
sanghob35a6192015-04-01 13:05:26 -0700706 private void scheduleEventHandlerIfNotScheduled(Event event) {
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700707 synchronized (threadSchedulerLock) {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700708 eventQueue.add(event);
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700709 numOfEventsQueued++;
710
711 if ((numOfHandlerScheduled - numOfHandlerExecution) == 0) {
712 //No pending scheduled event handling threads. So start a new one.
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700713 eventHandlerFuture = executorService
714 .schedule(eventHandler, 100, TimeUnit.MILLISECONDS);
715 numOfHandlerScheduled++;
716 }
Jonathan Hartc19f7c12016-04-12 15:39:44 -0700717 log.trace("numOfEventsQueued {}, numOfEventHandlerScheduled {}",
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700718 numOfEventsQueued,
719 numOfHandlerScheduled);
sanghob35a6192015-04-01 13:05:26 -0700720 }
sanghob35a6192015-04-01 13:05:26 -0700721 }
722
723 private class InternalEventHandler implements Runnable {
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700724 @Override
sanghob35a6192015-04-01 13:05:26 -0700725 public void run() {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700726 try {
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700727 while (true) {
Saurav Das4ce45962015-11-24 23:21:05 -0800728 @SuppressWarnings("rawtypes")
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700729 Event event = null;
730 synchronized (threadSchedulerLock) {
731 if (!eventQueue.isEmpty()) {
732 event = eventQueue.poll();
733 numOfEventsExecuted++;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700734 } else {
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700735 numOfHandlerExecution++;
736 log.debug("numOfHandlerExecution {} numOfEventsExecuted {}",
737 numOfHandlerExecution, numOfEventsExecuted);
738 break;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700739 }
sangho20eff1d2015-04-13 15:15:58 -0700740 }
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700741 if (event.type() == LinkEvent.Type.LINK_ADDED) {
742 processLinkAdded((Link) event.subject());
743 } else if (event.type() == LinkEvent.Type.LINK_REMOVED) {
Pier Ventre2c515312016-09-13 21:33:40 -0700744 Link linkRemoved = (Link) event.subject();
745 if (linkRemoved.src().elementId() instanceof DeviceId &&
746 !deviceService.isAvailable(linkRemoved.src().deviceId())) {
747 continue;
748 }
749 if (linkRemoved.dst().elementId() instanceof DeviceId &&
750 !deviceService.isAvailable(linkRemoved.dst().deviceId())) {
751 continue;
752 }
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700753 processLinkRemoved((Link) event.subject());
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700754 } else if (event.type() == DeviceEvent.Type.DEVICE_ADDED ||
755 event.type() == DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED ||
756 event.type() == DeviceEvent.Type.DEVICE_UPDATED) {
Saurav Das423fe2b2015-12-04 10:52:59 -0800757 DeviceId deviceId = ((Device) event.subject()).id();
758 if (deviceService.isAvailable(deviceId)) {
Saurav Das837e0bb2015-10-30 17:45:38 -0700759 log.info("Processing device event {} for available device {}",
760 event.type(), ((Device) event.subject()).id());
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700761 processDeviceAdded((Device) event.subject());
Saurav Das80980c72016-03-23 11:22:49 -0700762 } else {
763 log.info("Processing device event {} for unavailable device {}",
764 event.type(), ((Device) event.subject()).id());
765 processDeviceRemoved((Device) event.subject());
766 }
Saurav Das1a129a02016-11-18 15:21:57 -0800767 } else if (event.type() == DeviceEvent.Type.PORT_ADDED) {
Saurav Dasd2fded02016-12-02 15:43:47 -0800768 // typically these calls come when device is added first time
769 // so port filtering rules are handled at the device_added event.
770 // port added calls represent all ports on the device,
771 // enabled or not.
Saurav Das1a129a02016-11-18 15:21:57 -0800772 log.debug("** PORT ADDED {}/{} -> {}",
Saurav Dasd2fded02016-12-02 15:43:47 -0800773 ((DeviceEvent) event).subject().id(),
774 ((DeviceEvent) event).port().number(),
775 event.type());
Saurav Das1a129a02016-11-18 15:21:57 -0800776 } else if (event.type() == DeviceEvent.Type.PORT_UPDATED) {
Saurav Dasd2fded02016-12-02 15:43:47 -0800777 // these calls happen for every subsequent event
778 // ports enabled, disabled, switch goes away, comes back
Saurav Das1a129a02016-11-18 15:21:57 -0800779 log.info("** PORT UPDATED {}/{} -> {}",
780 event.subject(),
781 ((DeviceEvent) event).port(),
782 event.type());
783 processPortUpdated(((Device) event.subject()),
784 ((DeviceEvent) event).port());
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700785 } else {
786 log.warn("Unhandled event type: {}", event.type());
787 }
sanghob35a6192015-04-01 13:05:26 -0700788 }
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700789 } catch (Exception e) {
790 log.error("SegmentRouting event handler "
791 + "thread thrown an exception: {}", e);
sanghob35a6192015-04-01 13:05:26 -0700792 }
sanghob35a6192015-04-01 13:05:26 -0700793 }
794 }
795
sanghob35a6192015-04-01 13:05:26 -0700796 private void processLinkAdded(Link link) {
Saurav Dasb5c236e2016-06-07 10:08:06 -0700797 log.info("** LINK ADDED {}", link.toString());
Charles Chan0b4e6182015-11-03 10:42:14 -0800798 if (!deviceConfiguration.isConfigured(link.src().deviceId())) {
799 log.warn("Source device of this link is not configured.");
800 return;
801 }
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700802 //Irrespective whether the local is a MASTER or not for this device,
803 //create group handler instance and push default TTP flow rules.
804 //Because in a multi-instance setup, instances can initiate
805 //groups for any devices. Also the default TTP rules are needed
806 //to be pushed before inserting any IP table entries for any device
807 DefaultGroupHandler groupHandler = groupHandlerMap.get(link.src()
808 .deviceId());
809 if (groupHandler != null) {
Saurav Das8a0732e2015-11-20 15:27:53 -0800810 groupHandler.linkUp(link, mastershipService.isLocalMaster(
811 link.src().deviceId()));
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700812 } else {
813 Device device = deviceService.getDevice(link.src().deviceId());
814 if (device != null) {
815 log.warn("processLinkAdded: Link Added "
816 + "Notification without Device Added "
817 + "event, still handling it");
818 processDeviceAdded(device);
819 groupHandler = groupHandlerMap.get(link.src()
820 .deviceId());
Saurav Das8a0732e2015-11-20 15:27:53 -0800821 groupHandler.linkUp(link, mastershipService.isLocalMaster(device.id()));
sanghob35a6192015-04-01 13:05:26 -0700822 }
823 }
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700824
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700825 log.trace("Starting optimized route population process");
826 defaultRoutingHandler.populateRoutingRulesForLinkStatusChange(null);
827 //log.trace("processLinkAdded: re-starting route population process");
828 //defaultRoutingHandler.startPopulationProcess();
Charles Chan2199c302016-04-23 17:36:10 -0700829
830 mcastHandler.init();
sanghob35a6192015-04-01 13:05:26 -0700831 }
832
833 private void processLinkRemoved(Link link) {
Saurav Dasb5c236e2016-06-07 10:08:06 -0700834 log.info("** LINK REMOVED {}", link.toString());
sangho834e4b02015-05-01 09:38:25 -0700835 DefaultGroupHandler groupHandler = groupHandlerMap.get(link.src().deviceId());
836 if (groupHandler != null) {
Saurav Das423fe2b2015-12-04 10:52:59 -0800837 groupHandler.portDown(link.src().port(),
838 mastershipService.isLocalMaster(link.src().deviceId()));
sangho834e4b02015-05-01 09:38:25 -0700839 }
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700840 log.trace("Starting optimized route population process");
841 defaultRoutingHandler.populateRoutingRulesForLinkStatusChange(link);
842 //log.trace("processLinkRemoved: re-starting route population process");
843 //defaultRoutingHandler.startPopulationProcess();
Charles Chan2199c302016-04-23 17:36:10 -0700844
845 mcastHandler.processLinkDown(link);
sanghob35a6192015-04-01 13:05:26 -0700846 }
847
848 private void processDeviceAdded(Device device) {
Saurav Dasb5c236e2016-06-07 10:08:06 -0700849 log.info("** DEVICE ADDED with ID {}", device.id());
Charles Chan0b4e6182015-11-03 10:42:14 -0800850 if (deviceConfiguration == null || !deviceConfiguration.isConfigured(device.id())) {
Saurav Das2857f382015-11-03 14:39:27 -0800851 log.warn("Device configuration uploading. Device {} will be "
852 + "processed after config completes.", device.id());
853 return;
854 }
Charles Chan2199c302016-04-23 17:36:10 -0700855 processDeviceAddedInternal(device.id());
856 }
857
858 private void processDeviceAddedInternal(DeviceId deviceId) {
Saurav Das837e0bb2015-10-30 17:45:38 -0700859 // Irrespective of whether the local is a MASTER or not for this device,
860 // we need to create a SR-group-handler instance. This is because in a
861 // multi-instance setup, any instance can initiate forwarding/next-objectives
862 // for any switch (even if this instance is a SLAVE or not even connected
863 // to the switch). To handle this, a default-group-handler instance is necessary
864 // per switch.
Charles Chan2199c302016-04-23 17:36:10 -0700865 log.debug("Current groupHandlerMap devs: {}", groupHandlerMap.keySet());
866 if (groupHandlerMap.get(deviceId) == null) {
Charles Chan0b4e6182015-11-03 10:42:14 -0800867 DefaultGroupHandler groupHandler;
868 try {
869 groupHandler = DefaultGroupHandler.
Charles Chan2199c302016-04-23 17:36:10 -0700870 createGroupHandler(deviceId,
871 appId,
872 deviceConfiguration,
873 linkService,
874 flowObjectiveService,
875 this);
Charles Chan0b4e6182015-11-03 10:42:14 -0800876 } catch (DeviceConfigNotFoundException e) {
877 log.warn(e.getMessage() + " Aborting processDeviceAdded.");
878 return;
879 }
Charles Chan2199c302016-04-23 17:36:10 -0700880 log.debug("updating groupHandlerMap with new config for device: {}",
881 deviceId);
882 groupHandlerMap.put(deviceId, groupHandler);
Saurav Das2857f382015-11-03 14:39:27 -0800883 }
Saurav Dasb5c236e2016-06-07 10:08:06 -0700884 // Also, in some cases, drivers may need extra
885 // information to process rules (eg. Router IP/MAC); and so, we send
886 // port addressing rules to the driver as well irrespective of whether
887 // this instance is the master or not.
888 defaultRoutingHandler.populatePortAddressingRules(deviceId);
889
Charles Chan2199c302016-04-23 17:36:10 -0700890 if (mastershipService.isLocalMaster(deviceId)) {
Charles Chan03a73e02016-10-24 14:52:01 -0700891 hostHandler.init(deviceId);
Charles Chanfc5c7802016-05-17 13:13:55 -0700892 xConnectHandler.init(deviceId);
Charles Chan35fd1a72016-06-13 18:54:31 -0700893 cordConfigHandler.init(deviceId);
Charles Chan2199c302016-04-23 17:36:10 -0700894 DefaultGroupHandler groupHandler = groupHandlerMap.get(deviceId);
Charles Chanc42e84e2015-10-20 16:24:19 -0700895 groupHandler.createGroupsFromSubnetConfig();
Charles Chan2199c302016-04-23 17:36:10 -0700896 routingRulePopulator.populateSubnetBroadcastRule(deviceId);
Charles Chanc42e84e2015-10-20 16:24:19 -0700897 }
Charles Chan5270ed02016-01-30 23:22:37 -0800898
Charles Chan03a73e02016-10-24 14:52:01 -0700899 appCfgHandler.init(deviceId);
900 routeHandler.init(deviceId);
sanghob35a6192015-04-01 13:05:26 -0700901 }
902
Saurav Das80980c72016-03-23 11:22:49 -0700903 private void processDeviceRemoved(Device device) {
904 nsNextObjStore.entrySet().stream()
905 .filter(entry -> entry.getKey().deviceId().equals(device.id()))
906 .forEach(entry -> {
907 nsNextObjStore.remove(entry.getKey());
908 });
Saurav Das80980c72016-03-23 11:22:49 -0700909 subnetNextObjStore.entrySet().stream()
910 .filter(entry -> entry.getKey().deviceId().equals(device.id()))
911 .forEach(entry -> {
912 subnetNextObjStore.remove(entry.getKey());
913 });
Saurav Das80980c72016-03-23 11:22:49 -0700914 portNextObjStore.entrySet().stream()
915 .filter(entry -> entry.getKey().deviceId().equals(device.id()))
916 .forEach(entry -> {
917 portNextObjStore.remove(entry.getKey());
918 });
Saurav Das80980c72016-03-23 11:22:49 -0700919 subnetVidStore.entrySet().stream()
920 .filter(entry -> entry.getKey().deviceId().equals(device.id()))
921 .forEach(entry -> {
922 subnetVidStore.remove(entry.getKey());
923 });
Saurav Das80980c72016-03-23 11:22:49 -0700924 groupHandlerMap.remove(device.id());
Saurav Das80980c72016-03-23 11:22:49 -0700925 defaultRoutingHandler.purgeEcmpGraph(device.id());
Charles Chan2199c302016-04-23 17:36:10 -0700926 mcastHandler.removeDevice(device.id());
Charles Chanfc5c7802016-05-17 13:13:55 -0700927 xConnectHandler.removeDevice(device.id());
Saurav Das80980c72016-03-23 11:22:49 -0700928 }
929
Saurav Das1a129a02016-11-18 15:21:57 -0800930 private void processPortUpdated(Device device, Port port) {
931 if (deviceConfiguration == null || !deviceConfiguration.isConfigured(device.id())) {
932 log.warn("Device configuration uploading. Not handling port event for"
933 + "dev: {} port: {}", device.id(), port.number());
934 return;
935 }
936 /* XXX create method for single port filtering rules which are needed
937 for both switch-to-switch ports and edge ports
938 if (defaultRoutingHandler != null) {
939 defaultRoutingHandler.populatePortAddressingRules(
940 ((Device) event.subject()).id());
941 }*/
942
943 // portUpdated calls are for ports that have gone down or up. For switch
944 // to switch ports, link-events should take care of any re-routing or
945 // group editing necessary for port up/down. Here we only process edge ports
946 // that are already configured.
Pier Ventre10bd8d12016-11-26 21:05:22 -0800947 Ip4Prefix configuredSubnet = deviceConfiguration.getPortIPv4Subnet(device.id(),
Saurav Das1a129a02016-11-18 15:21:57 -0800948 port.number());
949 if (configuredSubnet == null) {
950 log.debug("Not handling port updated event for unconfigured port "
951 + "dev/port: {}/{}", device.id(), port.number());
952 return;
953 }
954 processEdgePort(device, port, configuredSubnet);
955 }
956
957 private void processEdgePort(Device device, Port port, Ip4Prefix subnet) {
958 boolean portUp = port.isEnabled();
959 if (portUp) {
960 log.info("Device:EdgePort {}:{} is enabled in subnet: {}", device.id(),
961 port.number(), subnet);
962 } else {
963 log.info("Device:EdgePort {}:{} is disabled in subnet: {}", device.id(),
964 port.number(), subnet);
965 }
966
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700967 DefaultGroupHandler groupHandler = groupHandlerMap.get(device.id());
sanghob35a6192015-04-01 13:05:26 -0700968 if (groupHandler != null) {
Saurav Das1a129a02016-11-18 15:21:57 -0800969 groupHandler.processEdgePort(port.number(), subnet, portUp,
Saurav Das423fe2b2015-12-04 10:52:59 -0800970 mastershipService.isLocalMaster(device.id()));
Saurav Das1a129a02016-11-18 15:21:57 -0800971 } else {
972 log.warn("Group handler not found for dev:{}. Not handling edge port"
973 + " {} event for port:{}", device.id(),
974 (portUp) ? "UP" : "DOWN", port.number());
sanghob35a6192015-04-01 13:05:26 -0700975 }
976 }
sangho1e575652015-05-14 00:39:53 -0700977
Pier Ventre10bd8d12016-11-26 21:05:22 -0800978 /**
979 * Registers the given connect point with the NRS, this is necessary
980 * to receive the NDP and ARP packets from the NRS.
981 *
982 * @param portToRegister connect point to register
983 */
984 public void registerConnectPoint(ConnectPoint portToRegister) {
985 /*
986 * First we register the ARP handler.
987 */
988 this.neighbourResolutionService.registerNeighbourHandler(
989 portToRegister,
990 neighbourHandler,
991 appId
992 );
993 }
994
Charles Chand6832882015-10-05 17:50:33 -0700995 private class InternalConfigListener implements NetworkConfigListener {
Charles Chan2c15aca2016-11-09 20:51:44 -0800996 SegmentRoutingManager srManager;
Charles Chan4636be02015-10-07 14:21:45 -0700997
Charles Chane849c192016-01-11 18:28:54 -0800998 /**
999 * Constructs the internal network config listener.
1000 *
Charles Chan2c15aca2016-11-09 20:51:44 -08001001 * @param srManager segment routing manager
Charles Chane849c192016-01-11 18:28:54 -08001002 */
Charles Chan2c15aca2016-11-09 20:51:44 -08001003 public InternalConfigListener(SegmentRoutingManager srManager) {
1004 this.srManager = srManager;
Charles Chan4636be02015-10-07 14:21:45 -07001005 }
1006
Charles Chane849c192016-01-11 18:28:54 -08001007 /**
1008 * Reads network config and initializes related data structure accordingly.
1009 */
Charles Chan4636be02015-10-07 14:21:45 -07001010 public void configureNetwork() {
Pier Ventre10bd8d12016-11-26 21:05:22 -08001011
Charles Chan2c15aca2016-11-09 20:51:44 -08001012 deviceConfiguration = new DeviceConfiguration(srManager);
Charles Chan4636be02015-10-07 14:21:45 -07001013
Charles Chan2c15aca2016-11-09 20:51:44 -08001014 arpHandler = new ArpHandler(srManager);
1015 icmpHandler = new IcmpHandler(srManager);
1016 ipHandler = new IpHandler(srManager);
1017 routingRulePopulator = new RoutingRulePopulator(srManager);
1018 defaultRoutingHandler = new DefaultRoutingHandler(srManager);
Charles Chan4636be02015-10-07 14:21:45 -07001019
1020 tunnelHandler = new TunnelHandler(linkService, deviceConfiguration,
1021 groupHandlerMap, tunnelStore);
1022 policyHandler = new PolicyHandler(appId, deviceConfiguration,
1023 flowObjectiveService,
1024 tunnelHandler, policyStore);
1025
Charles Chan4636be02015-10-07 14:21:45 -07001026 for (Device device : deviceService.getDevices()) {
Charles Chan2199c302016-04-23 17:36:10 -07001027 processDeviceAddedInternal(device.id());
Charles Chan4636be02015-10-07 14:21:45 -07001028 }
1029
1030 defaultRoutingHandler.startPopulationProcess();
Charles Chan2199c302016-04-23 17:36:10 -07001031 mcastHandler.init();
Charles Chan4636be02015-10-07 14:21:45 -07001032 }
1033
Charles Chand6832882015-10-05 17:50:33 -07001034 @Override
1035 public void event(NetworkConfigEvent event) {
Charles Chan5270ed02016-01-30 23:22:37 -08001036 // TODO move this part to NetworkConfigEventHandler
1037 if (event.configClass().equals(SegmentRoutingDeviceConfig.class)) {
1038 switch (event.type()) {
1039 case CONFIG_ADDED:
1040 log.info("Segment Routing Config added.");
1041 configureNetwork();
1042 break;
1043 case CONFIG_UPDATED:
1044 log.info("Segment Routing Config updated.");
1045 // TODO support dynamic configuration
1046 break;
1047 default:
1048 break;
Charles Chanb8e10c82015-10-14 11:24:40 -07001049 }
Charles Chan5270ed02016-01-30 23:22:37 -08001050 } else if (event.configClass().equals(SegmentRoutingAppConfig.class)) {
Charles Chanfc5c7802016-05-17 13:13:55 -07001051 checkState(appCfgHandler != null, "NetworkConfigEventHandler is not initialized");
Charles Chan5270ed02016-01-30 23:22:37 -08001052 switch (event.type()) {
1053 case CONFIG_ADDED:
Charles Chanfc5c7802016-05-17 13:13:55 -07001054 appCfgHandler.processAppConfigAdded(event);
Charles Chan5270ed02016-01-30 23:22:37 -08001055 break;
1056 case CONFIG_UPDATED:
Charles Chanfc5c7802016-05-17 13:13:55 -07001057 appCfgHandler.processAppConfigUpdated(event);
Charles Chan5270ed02016-01-30 23:22:37 -08001058 break;
1059 case CONFIG_REMOVED:
Charles Chanfc5c7802016-05-17 13:13:55 -07001060 appCfgHandler.processAppConfigRemoved(event);
1061 break;
1062 default:
1063 break;
1064 }
Charles Chan03a73e02016-10-24 14:52:01 -07001065 configureNetwork();
Charles Chanfc5c7802016-05-17 13:13:55 -07001066 } else if (event.configClass().equals(XConnectConfig.class)) {
1067 checkState(xConnectHandler != null, "XConnectHandler is not initialized");
1068 switch (event.type()) {
1069 case CONFIG_ADDED:
1070 xConnectHandler.processXConnectConfigAdded(event);
1071 break;
1072 case CONFIG_UPDATED:
1073 xConnectHandler.processXConnectConfigUpdated(event);
1074 break;
1075 case CONFIG_REMOVED:
1076 xConnectHandler.processXConnectConfigRemoved(event);
Charles Chan5270ed02016-01-30 23:22:37 -08001077 break;
1078 default:
1079 break;
Charles Chanb8e10c82015-10-14 11:24:40 -07001080 }
Charles Chand6832882015-10-05 17:50:33 -07001081 }
1082 }
1083 }
Charles Chan68aa62d2015-11-09 16:37:23 -08001084
1085 private class InternalHostListener implements HostListener {
Charles Chan68aa62d2015-11-09 16:37:23 -08001086 @Override
1087 public void event(HostEvent event) {
1088 // Do not proceed without mastership
1089 DeviceId deviceId = event.subject().location().deviceId();
1090 if (!mastershipService.isLocalMaster(deviceId)) {
1091 return;
1092 }
1093
1094 switch (event.type()) {
1095 case HOST_ADDED:
Charles Chand2990362016-04-18 13:44:03 -07001096 hostHandler.processHostAddedEvent(event);
Charles Chan68aa62d2015-11-09 16:37:23 -08001097 break;
1098 case HOST_MOVED:
Charles Chand2990362016-04-18 13:44:03 -07001099 hostHandler.processHostMovedEvent(event);
Charles Chan68aa62d2015-11-09 16:37:23 -08001100 break;
1101 case HOST_REMOVED:
Charles Chand2990362016-04-18 13:44:03 -07001102 hostHandler.processHostRemoveEvent(event);
Charles Chan68aa62d2015-11-09 16:37:23 -08001103 break;
1104 case HOST_UPDATED:
Charles Chand2990362016-04-18 13:44:03 -07001105 hostHandler.processHostUpdatedEvent(event);
Charles Chan68aa62d2015-11-09 16:37:23 -08001106 break;
1107 default:
1108 log.warn("Unsupported host event type: {}", event.type());
1109 break;
1110 }
1111 }
1112 }
1113
Charles Chand55e84d2016-03-30 17:54:24 -07001114 private class InternalMcastListener implements McastListener {
1115 @Override
1116 public void event(McastEvent event) {
1117 switch (event.type()) {
1118 case SOURCE_ADDED:
Charles Chand2990362016-04-18 13:44:03 -07001119 mcastHandler.processSourceAdded(event);
Charles Chand55e84d2016-03-30 17:54:24 -07001120 break;
1121 case SINK_ADDED:
Charles Chand2990362016-04-18 13:44:03 -07001122 mcastHandler.processSinkAdded(event);
Charles Chand55e84d2016-03-30 17:54:24 -07001123 break;
1124 case SINK_REMOVED:
Charles Chand2990362016-04-18 13:44:03 -07001125 mcastHandler.processSinkRemoved(event);
Charles Chand55e84d2016-03-30 17:54:24 -07001126 break;
1127 case ROUTE_ADDED:
1128 case ROUTE_REMOVED:
1129 default:
1130 break;
1131 }
1132 }
1133 }
Charles Chan35fd1a72016-06-13 18:54:31 -07001134
1135 private class InternalCordConfigListener implements CordConfigListener {
1136 @Override
1137 public void event(CordConfigEvent event) {
1138 switch (event.type()) {
1139 case ACCESS_AGENT_ADDED:
1140 cordConfigHandler.processAccessAgentAddedEvent(event);
1141 break;
1142 case ACCESS_AGENT_UPDATED:
1143 cordConfigHandler.processAccessAgentUpdatedEvent(event);
1144 break;
1145 case ACCESS_AGENT_REMOVED:
1146 cordConfigHandler.processAccessAgentRemovedEvent(event);
1147 break;
1148 case ACCESS_DEVICE_ADDED:
1149 case ACCESS_DEVICE_UPDATED:
1150 case ACCESS_DEVICE_REMOVED:
1151 default:
1152 break;
1153 }
1154 }
1155 }
Charles Chan03a73e02016-10-24 14:52:01 -07001156
1157 private class InternalRouteEventListener implements RouteListener {
1158 @Override
1159 public void event(RouteEvent event) {
1160 switch (event.type()) {
1161 case ROUTE_ADDED:
1162 routeHandler.processRouteAdded(event);
1163 break;
1164 case ROUTE_UPDATED:
1165 routeHandler.processRouteUpdated(event);
1166 break;
1167 case ROUTE_REMOVED:
1168 routeHandler.processRouteRemoved(event);
1169 break;
1170 default:
1171 break;
1172 }
1173 }
1174 }
sanghob35a6192015-04-01 13:05:26 -07001175}