blob: 41cb65b025ec3a5fe905447cdbe21917ba652a51 [file] [log] [blame]
sangho80f11cb2015-04-01 13:05:26 -07001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
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
18import org.apache.felix.scr.annotations.Activate;
19import org.apache.felix.scr.annotations.Component;
20import org.apache.felix.scr.annotations.Deactivate;
21import org.apache.felix.scr.annotations.Reference;
22import org.apache.felix.scr.annotations.ReferenceCardinality;
sangho27462c62015-05-14 00:39:53 -070023import org.apache.felix.scr.annotations.Service;
sangho80f11cb2015-04-01 13:05:26 -070024import org.onlab.packet.Ethernet;
25import org.onlab.packet.IPv4;
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -070026import org.onlab.util.KryoNamespace;
sangho80f11cb2015-04-01 13:05:26 -070027import org.onosproject.core.ApplicationId;
28import org.onosproject.core.CoreService;
29import org.onosproject.event.Event;
Srikanth Vavilapalli37a461b2015-04-07 15:12:32 -070030import org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler;
31import org.onosproject.segmentrouting.grouphandler.NeighborSet;
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -070032import org.onosproject.segmentrouting.grouphandler.NeighborSetNextObjectiveStoreKey;
sangho80f11cb2015-04-01 13:05:26 -070033import org.onosproject.mastership.MastershipService;
34import org.onosproject.net.Device;
35import org.onosproject.net.DeviceId;
36import org.onosproject.net.Link;
sangho80f11cb2015-04-01 13:05:26 -070037import org.onosproject.net.Port;
38import org.onosproject.net.device.DeviceEvent;
39import org.onosproject.net.device.DeviceListener;
40import org.onosproject.net.device.DeviceService;
Srikanth Vavilapalli64505482015-04-21 13:04:13 -070041import org.onosproject.net.flowobjective.FlowObjectiveService;
sangho80f11cb2015-04-01 13:05:26 -070042import org.onosproject.net.group.GroupKey;
sangho80f11cb2015-04-01 13:05:26 -070043import org.onosproject.net.host.HostService;
44import org.onosproject.net.intent.IntentService;
45import org.onosproject.net.link.LinkEvent;
46import org.onosproject.net.link.LinkListener;
47import org.onosproject.net.link.LinkService;
48import org.onosproject.net.packet.InboundPacket;
49import org.onosproject.net.packet.PacketContext;
50import org.onosproject.net.packet.PacketProcessor;
51import org.onosproject.net.packet.PacketService;
52import org.onosproject.net.topology.TopologyService;
Srikanth Vavilapalli37a461b2015-04-07 15:12:32 -070053import org.onosproject.segmentrouting.config.NetworkConfigManager;
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -070054import org.onosproject.store.service.EventuallyConsistentMap;
55import org.onosproject.store.service.EventuallyConsistentMapBuilder;
56import org.onosproject.store.service.StorageService;
57import org.onosproject.store.service.WallClockTimestamp;
58import org.onosproject.store.service.WallclockClockManager;
sangho80f11cb2015-04-01 13:05:26 -070059import org.slf4j.Logger;
60import org.slf4j.LoggerFactory;
61
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -070062import java.net.URI;
63import java.util.HashSet;
sangho27462c62015-05-14 00:39:53 -070064import java.util.List;
sangho80f11cb2015-04-01 13:05:26 -070065import java.util.Map;
66import java.util.concurrent.ConcurrentHashMap;
67import java.util.concurrent.ConcurrentLinkedQueue;
68import java.util.concurrent.Executors;
69import java.util.concurrent.ScheduledExecutorService;
70import java.util.concurrent.ScheduledFuture;
71import java.util.concurrent.TimeUnit;
72
73@SuppressWarnings("ALL")
sangho27462c62015-05-14 00:39:53 -070074@Service
sangho80f11cb2015-04-01 13:05:26 -070075@Component(immediate = true)
sangho27462c62015-05-14 00:39:53 -070076public class SegmentRoutingManager implements SegmentRoutingService {
sangho80f11cb2015-04-01 13:05:26 -070077
Srikanth Vavilapalli64505482015-04-21 13:04:13 -070078 private static Logger log = LoggerFactory
79 .getLogger(SegmentRoutingManager.class);
sangho80f11cb2015-04-01 13:05:26 -070080
81 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
82 protected CoreService coreService;
83
84 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
85 protected TopologyService topologyService;
86
87 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
88 protected PacketService packetService;
89
90 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
91 protected IntentService intentService;
92
93 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
94 protected HostService hostService;
95
96 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
97 protected DeviceService deviceService;
98
99 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Srikanth Vavilapalli64505482015-04-21 13:04:13 -0700100 protected FlowObjectiveService flowObjectiveService;
sangho80f11cb2015-04-01 13:05:26 -0700101
102 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
103 protected LinkService linkService;
104
105 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
sangho80f11cb2015-04-01 13:05:26 -0700106 protected MastershipService mastershipService;
sangho27462c62015-05-14 00:39:53 -0700107
Srikanth Vavilapalli37a461b2015-04-07 15:12:32 -0700108 protected ArpHandler arpHandler = null;
109 protected IcmpHandler icmpHandler = null;
110 protected IpHandler ipHandler = null;
111 protected RoutingRulePopulator routingRulePopulator = null;
sangho80f11cb2015-04-01 13:05:26 -0700112 protected ApplicationId appId;
sangho9b169e32015-04-14 16:27:13 -0700113 protected DeviceConfiguration deviceConfiguration = null;
sangho80f11cb2015-04-01 13:05:26 -0700114
sangho27462c62015-05-14 00:39:53 -0700115
Srikanth Vavilapalli37a461b2015-04-07 15:12:32 -0700116 private DefaultRoutingHandler defaultRoutingHandler = null;
sangho27462c62015-05-14 00:39:53 -0700117 private TunnelHandler tunnelHandler = null;
118 private PolicyHandler policyHandler = null;
sangho80f11cb2015-04-01 13:05:26 -0700119 private InternalPacketProcessor processor = new InternalPacketProcessor();
120 private InternalEventHandler eventHandler = new InternalEventHandler();
121
Srikanth Vavilapalli64505482015-04-21 13:04:13 -0700122 private ScheduledExecutorService executorService = Executors
123 .newScheduledThreadPool(1);
sangho80f11cb2015-04-01 13:05:26 -0700124
125 private static ScheduledFuture<?> eventHandlerFuture = null;
126 private ConcurrentLinkedQueue<Event> eventQueue = new ConcurrentLinkedQueue<Event>();
Srikanth Vavilapalli64505482015-04-21 13:04:13 -0700127 private Map<DeviceId, DefaultGroupHandler> groupHandlerMap = new ConcurrentHashMap<DeviceId, DefaultGroupHandler>();
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700128 // Per device next objective ID store with (device id + neighbor set) as key
129 private EventuallyConsistentMap<NeighborSetNextObjectiveStoreKey,
130 Integer> nsNextObjStore = null;
131 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
132 protected StorageService storageService;
sangho80f11cb2015-04-01 13:05:26 -0700133
Srikanth Vavilapalli37a461b2015-04-07 15:12:32 -0700134 private NetworkConfigManager networkConfigService = new NetworkConfigManager();;
135
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -0700136 private Object threadSchedulerLock = new Object();
137 private static int numOfEventsQueued = 0;
138 private static int numOfEventsExecuted = 0;
sangho80f11cb2015-04-01 13:05:26 -0700139 private static int numOfHandlerExecution = 0;
140 private static int numOfHandlerScheduled = 0;
141
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700142 private KryoNamespace.Builder kryoBuilder = null;
143
sangho80f11cb2015-04-01 13:05:26 -0700144 @Activate
145 protected void activate() {
Srikanth Vavilapalli64505482015-04-21 13:04:13 -0700146 appId = coreService
147 .registerApplication("org.onosproject.segmentrouting");
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700148
149 kryoBuilder = new KryoNamespace.Builder()
150 .register(NeighborSetNextObjectiveStoreKey.class,
151 NeighborSet.class,
152 DeviceId.class,
153 URI.class,
154 WallClockTimestamp.class,
155 org.onosproject.cluster.NodeId.class,
156 HashSet.class
157 );
158
159 log.debug("Creating EC map nsnextobjectivestore");
160 EventuallyConsistentMapBuilder<NeighborSetNextObjectiveStoreKey, Integer>
161 nsNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder();
162
163 nsNextObjStore = nsNextObjMapBuilder
164 .withName("nsnextobjectivestore")
165 .withSerializer(kryoBuilder)
166 .withClockService(new WallclockClockManager<>())
167 .build();
168 log.trace("Current size {}", nsNextObjStore.size());
169
Srikanth Vavilapalli37a461b2015-04-07 15:12:32 -0700170 networkConfigService.init();
171 deviceConfiguration = new DeviceConfiguration(networkConfigService);
Srikanth Vavilapalli37a461b2015-04-07 15:12:32 -0700172 arpHandler = new ArpHandler(this);
173 icmpHandler = new IcmpHandler(this);
174 ipHandler = new IpHandler(this);
175 routingRulePopulator = new RoutingRulePopulator(this);
176 defaultRoutingHandler = new DefaultRoutingHandler(this);
sangho27462c62015-05-14 00:39:53 -0700177 tunnelHandler = new TunnelHandler();
178 policyHandler = new PolicyHandler();
Srikanth Vavilapalli37a461b2015-04-07 15:12:32 -0700179
sangho80f11cb2015-04-01 13:05:26 -0700180 packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 2);
181 linkService.addListener(new InternalLinkListener());
sangho80f11cb2015-04-01 13:05:26 -0700182 deviceService.addListener(new InternalDeviceListener());
183
Srikanth Vavilapalli64505482015-04-21 13:04:13 -0700184 for (Device device : deviceService.getDevices()) {
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700185 //Irrespective whether the local is a MASTER or not for this device,
186 //create group handler instance and push default TTP flow rules.
187 //Because in a multi-instance setup, instances can initiate
188 //groups for any devices. Also the default TTP rules are needed
189 //to be pushed before inserting any IP table entries for any device
190 DefaultGroupHandler groupHandler = DefaultGroupHandler
191 .createGroupHandler(device.id(), appId,
192 deviceConfiguration, linkService,
193 flowObjectiveService,
194 nsNextObjStore);
195 groupHandlerMap.put(device.id(), groupHandler);
196 defaultRoutingHandler.populateTtpRules(device.id());
sangho80f11cb2015-04-01 13:05:26 -0700197 }
198
sanghofb7c7292015-04-13 15:15:58 -0700199 defaultRoutingHandler.startPopulationProcess();
sangho80f11cb2015-04-01 13:05:26 -0700200 log.info("Started");
sangho27462c62015-05-14 00:39:53 -0700201
sangho80f11cb2015-04-01 13:05:26 -0700202 }
203
204 @Deactivate
205 protected void deactivate() {
206 packetService.removeProcessor(processor);
207 processor = null;
208 log.info("Stopped");
209 }
210
sangho27462c62015-05-14 00:39:53 -0700211
212 @Override
213 public List<Tunnel> getTunnels() {
214 return tunnelHandler.getTunnels();
215 }
216
217 @Override
218 public void createTunnel(Tunnel tunnel) {
219 tunnelHandler.createTunnel(tunnel);
220 }
221
222 @Override
223 public void removeTunnel(Tunnel tunnel) {
224 for (Policy policy: policyHandler.getPolicies()) {
225 if (policy.type() == Policy.Type.TUNNEL_FLOW) {
226 TunnelPolicy tunnelPolicy = (TunnelPolicy) policy;
227 if (tunnelPolicy.tunnelId().equals(tunnel.id())) {
228 log.warn("Cannot remove the tunnel used by a policy");
229 return;
230 }
231 }
232 }
233 tunnelHandler.removeTunnel(tunnel);
234 }
235
236 @Override
237 public void removePolicy(Policy policy) {
238 policyHandler.removePolicy(policy);
239
240 }
241
242 @Override
243 public void createPolicy(Policy policy) {
244 policyHandler.createPolicy(policy);
245 }
246
247 @Override
248 public List<Policy> getPolicies() {
249 return policyHandler.getPolicies();
250 }
251
252 public Tunnel getTunnel(String tunnelId) {
253 return tunnelHandler.getTunnel(tunnelId);
254 }
255
sangho80f11cb2015-04-01 13:05:26 -0700256 /**
257 * Returns the GrouopKey object for the device and the NighborSet given.
258 *
259 * @param ns NeightborSet object for the GroupKey
260 * @return GroupKey object for the NeighborSet
261 */
262 public GroupKey getGroupKey(NeighborSet ns) {
263
Srikanth Vavilapalli64505482015-04-21 13:04:13 -0700264 for (DefaultGroupHandler groupHandler : groupHandlerMap.values()) {
sangho80f11cb2015-04-01 13:05:26 -0700265 return groupHandler.getGroupKey(ns);
266 }
267
268 return null;
269 }
270
sangho27462c62015-05-14 00:39:53 -0700271 /**
272 *
273 * @param deviceId
274 * @param ns
275 * @return
276 */
Srikanth Vavilapalli64505482015-04-21 13:04:13 -0700277 public int getNextObjectiveId(DeviceId deviceId, NeighborSet ns) {
278
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700279 if (groupHandlerMap.get(deviceId) != null) {
280 log.trace("getNextObjectiveId query in device {}", deviceId);
281 return groupHandlerMap
282 .get(deviceId).getNextObjectiveId(ns);
283 } else {
284 log.warn("getNextObjectiveId query in device {} not found", deviceId);
285 return -1;
286 }
Srikanth Vavilapalli64505482015-04-21 13:04:13 -0700287 }
288
sangho27462c62015-05-14 00:39:53 -0700289 /**
290 *
291 * @param deviceId
292 * @param objectiveId
293 * @return
294 */
295 public boolean removeNextObjective(DeviceId deviceId, int objectiveId) {
296 return groupHandlerMap.get(deviceId).removeGroup(objectiveId);
297 }
298
sangho80f11cb2015-04-01 13:05:26 -0700299 private class InternalPacketProcessor implements PacketProcessor {
300
301 @Override
302 public void process(PacketContext context) {
303
304 if (context.isHandled()) {
305 return;
306 }
307
308 InboundPacket pkt = context.inPacket();
309 Ethernet ethernet = pkt.parsed();
310
311 if (ethernet.getEtherType() == Ethernet.TYPE_ARP) {
312 arpHandler.processPacketIn(pkt);
313 } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV4) {
314 IPv4 ipPacket = (IPv4) ethernet.getPayload();
315 ipHandler.addToPacketBuffer(ipPacket);
316 if (ipPacket.getProtocol() == IPv4.PROTOCOL_ICMP) {
317 icmpHandler.processPacketIn(pkt);
318 } else {
319 ipHandler.processPacketIn(pkt);
320 }
321 }
322 }
323 }
324
325 private class InternalLinkListener implements LinkListener {
326 @Override
327 public void event(LinkEvent event) {
Srikanth Vavilapalli64505482015-04-21 13:04:13 -0700328 if (event.type() == LinkEvent.Type.LINK_ADDED
329 || event.type() == LinkEvent.Type.LINK_REMOVED) {
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -0700330 log.debug("Event {} received from Link Service", event.type());
sangho80f11cb2015-04-01 13:05:26 -0700331 scheduleEventHandlerIfNotScheduled(event);
332 }
333 }
334 }
335
336 private class InternalDeviceListener implements DeviceListener {
337
338 @Override
339 public void event(DeviceEvent event) {
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700340 /*if (mastershipService.getLocalRole(event.subject().id()) != MastershipRole.MASTER) {
sangho80f11cb2015-04-01 13:05:26 -0700341 log.debug("Local role {} is not MASTER for device {}",
Srikanth Vavilapalli64505482015-04-21 13:04:13 -0700342 mastershipService.getLocalRole(event.subject().id()),
343 event.subject().id());
sangho80f11cb2015-04-01 13:05:26 -0700344 return;
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700345 }*/
sangho80f11cb2015-04-01 13:05:26 -0700346
347 switch (event.type()) {
348 case DEVICE_ADDED:
349 case PORT_REMOVED:
sanghofb7c7292015-04-13 15:15:58 -0700350 case DEVICE_UPDATED:
351 case DEVICE_AVAILABILITY_CHANGED:
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -0700352 log.debug("Event {} received from Device Service", event.type());
sangho80f11cb2015-04-01 13:05:26 -0700353 scheduleEventHandlerIfNotScheduled(event);
354 break;
355 default:
356 }
357 }
358 }
359
sangho80f11cb2015-04-01 13:05:26 -0700360 private void scheduleEventHandlerIfNotScheduled(Event event) {
361
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -0700362 synchronized (threadSchedulerLock) {
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700363 eventQueue.add(event);
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -0700364 numOfEventsQueued++;
365
366 if ((numOfHandlerScheduled - numOfHandlerExecution) == 0) {
367 //No pending scheduled event handling threads. So start a new one.
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700368 eventHandlerFuture = executorService
369 .schedule(eventHandler, 100, TimeUnit.MILLISECONDS);
370 numOfHandlerScheduled++;
371 }
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -0700372 log.trace("numOfEventsQueued {}, numOfEventHanlderScheduled {}",
373 numOfEventsQueued,
374 numOfHandlerScheduled);
sangho80f11cb2015-04-01 13:05:26 -0700375 }
sangho80f11cb2015-04-01 13:05:26 -0700376 }
377
378 private class InternalEventHandler implements Runnable {
379
Srikanth Vavilapalli37a461b2015-04-07 15:12:32 -0700380 @Override
sangho80f11cb2015-04-01 13:05:26 -0700381 public void run() {
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700382 try {
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -0700383 while (true) {
384 Event event = null;
385 synchronized (threadSchedulerLock) {
386 if (!eventQueue.isEmpty()) {
387 event = eventQueue.poll();
388 numOfEventsExecuted++;
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700389 } else {
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -0700390 numOfHandlerExecution++;
391 log.debug("numOfHandlerExecution {} numOfEventsExecuted {}",
392 numOfHandlerExecution, numOfEventsExecuted);
393 break;
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700394 }
sanghofb7c7292015-04-13 15:15:58 -0700395 }
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -0700396 if (event.type() == LinkEvent.Type.LINK_ADDED) {
397 processLinkAdded((Link) event.subject());
398 } else if (event.type() == LinkEvent.Type.LINK_REMOVED) {
399 processLinkRemoved((Link) event.subject());
400 //} else if (event.type() == GroupEvent.Type.GROUP_ADDED) {
401 // processGroupAdded((Group) event.subject());
402 } else if (event.type() == DeviceEvent.Type.DEVICE_ADDED ||
403 event.type() == DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED ||
404 event.type() == DeviceEvent.Type.DEVICE_UPDATED) {
405 if (deviceService.isAvailable(((Device) event.subject()).id())) {
406 processDeviceAdded((Device) event.subject());
407 }
408 } else if (event.type() == DeviceEvent.Type.PORT_REMOVED) {
409 processPortRemoved((Device) event.subject(),
410 ((DeviceEvent) event).port());
411 } else {
412 log.warn("Unhandled event type: {}", event.type());
413 }
sangho80f11cb2015-04-01 13:05:26 -0700414 }
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700415 } catch (Exception e) {
416 log.error("SegmentRouting event handler "
417 + "thread thrown an exception: {}", e);
sangho80f11cb2015-04-01 13:05:26 -0700418 }
sangho80f11cb2015-04-01 13:05:26 -0700419 }
420 }
421
sangho80f11cb2015-04-01 13:05:26 -0700422 private void processLinkAdded(Link link) {
423 log.debug("A new link {} was added", link.toString());
424
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700425 //Irrespective whether the local is a MASTER or not for this device,
426 //create group handler instance and push default TTP flow rules.
427 //Because in a multi-instance setup, instances can initiate
428 //groups for any devices. Also the default TTP rules are needed
429 //to be pushed before inserting any IP table entries for any device
430 DefaultGroupHandler groupHandler = groupHandlerMap.get(link.src()
431 .deviceId());
432 if (groupHandler != null) {
433 groupHandler.linkUp(link);
434 } else {
435 Device device = deviceService.getDevice(link.src().deviceId());
436 if (device != null) {
437 log.warn("processLinkAdded: Link Added "
438 + "Notification without Device Added "
439 + "event, still handling it");
440 processDeviceAdded(device);
441 groupHandler = groupHandlerMap.get(link.src()
442 .deviceId());
sangho80f11cb2015-04-01 13:05:26 -0700443 groupHandler.linkUp(link);
444 }
445 }
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700446
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -0700447 log.trace("Starting optimized route population process");
448 defaultRoutingHandler.populateRoutingRulesForLinkStatusChange(null);
449 //log.trace("processLinkAdded: re-starting route population process");
450 //defaultRoutingHandler.startPopulationProcess();
sangho80f11cb2015-04-01 13:05:26 -0700451 }
452
453 private void processLinkRemoved(Link link) {
454 log.debug("A link {} was removed", link.toString());
sangho2165d222015-05-01 09:38:25 -0700455 DefaultGroupHandler groupHandler = groupHandlerMap.get(link.src().deviceId());
456 if (groupHandler != null) {
457 groupHandler.portDown(link.src().port());
458 }
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -0700459 log.trace("Starting optimized route population process");
460 defaultRoutingHandler.populateRoutingRulesForLinkStatusChange(link);
461 //log.trace("processLinkRemoved: re-starting route population process");
462 //defaultRoutingHandler.startPopulationProcess();
sangho80f11cb2015-04-01 13:05:26 -0700463 }
464
465 private void processDeviceAdded(Device device) {
466 log.debug("A new device with ID {} was added", device.id());
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700467 //Irrespective whether the local is a MASTER or not for this device,
468 //create group handler instance and push default TTP flow rules.
469 //Because in a multi-instance setup, instances can initiate
470 //groups for any devices. Also the default TTP rules are needed
471 //to be pushed before inserting any IP table entries for any device
472 DefaultGroupHandler dgh = DefaultGroupHandler.
473 createGroupHandler(device.id(),
474 appId,
475 deviceConfiguration,
476 linkService,
477 flowObjectiveService,
478 nsNextObjStore);
sangho80f11cb2015-04-01 13:05:26 -0700479 groupHandlerMap.put(device.id(), dgh);
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700480 defaultRoutingHandler.populateTtpRules(device.id());
sangho80f11cb2015-04-01 13:05:26 -0700481 }
482
483 private void processPortRemoved(Device device, Port port) {
484 log.debug("Port {} was removed", port.toString());
Srikanth Vavilapalli64505482015-04-21 13:04:13 -0700485 DefaultGroupHandler groupHandler = groupHandlerMap.get(device.id());
sangho80f11cb2015-04-01 13:05:26 -0700486 if (groupHandler != null) {
487 groupHandler.portDown(port.number());
488 }
489 }
sangho27462c62015-05-14 00:39:53 -0700490
491
492
sangho80f11cb2015-04-01 13:05:26 -0700493}