blob: 02ed88a4720c18db2f044623fc2179a84eb88a8a [file] [log] [blame]
sanghob35a6192015-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;
sangho1e575652015-05-14 00:39:53 -070023import org.apache.felix.scr.annotations.Service;
sanghob35a6192015-04-01 13:05:26 -070024import org.onlab.packet.Ethernet;
25import org.onlab.packet.IPv4;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -070026import org.onlab.util.KryoNamespace;
sanghob35a6192015-04-01 13:05:26 -070027import org.onosproject.core.ApplicationId;
28import org.onosproject.core.CoreService;
29import org.onosproject.event.Event;
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070030import org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler;
31import org.onosproject.segmentrouting.grouphandler.NeighborSet;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -070032import org.onosproject.segmentrouting.grouphandler.NeighborSetNextObjectiveStoreKey;
sanghob35a6192015-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;
sanghob35a6192015-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 Vavilapallif5b234a2015-04-21 13:04:13 -070041import org.onosproject.net.flowobjective.FlowObjectiveService;
sanghob35a6192015-04-01 13:05:26 -070042import org.onosproject.net.group.GroupKey;
sanghob35a6192015-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 Vavilapalli4db76e32015-04-07 15:12:32 -070053import org.onosproject.segmentrouting.config.NetworkConfigManager;
Srikanth Vavilapalli23181912015-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;
sanghob35a6192015-04-01 13:05:26 -070059import org.slf4j.Logger;
60import org.slf4j.LoggerFactory;
61
Srikanth Vavilapalli23181912015-05-04 09:48:09 -070062import java.net.URI;
63import java.util.HashSet;
sangho1e575652015-05-14 00:39:53 -070064import java.util.List;
sanghob35a6192015-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")
sangho1e575652015-05-14 00:39:53 -070074@Service
sanghob35a6192015-04-01 13:05:26 -070075@Component(immediate = true)
sangho1e575652015-05-14 00:39:53 -070076public class SegmentRoutingManager implements SegmentRoutingService {
sanghob35a6192015-04-01 13:05:26 -070077
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070078 private static Logger log = LoggerFactory
79 .getLogger(SegmentRoutingManager.class);
sanghob35a6192015-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 Vavilapallif5b234a2015-04-21 13:04:13 -0700100 protected FlowObjectiveService flowObjectiveService;
sanghob35a6192015-04-01 13:05:26 -0700101
102 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
103 protected LinkService linkService;
104
105 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
sanghob35a6192015-04-01 13:05:26 -0700106 protected MastershipService mastershipService;
sangho1e575652015-05-14 00:39:53 -0700107
Srikanth Vavilapalli4db76e32015-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;
sanghob35a6192015-04-01 13:05:26 -0700112 protected ApplicationId appId;
sangho666cd6d2015-04-14 16:27:13 -0700113 protected DeviceConfiguration deviceConfiguration = null;
sanghob35a6192015-04-01 13:05:26 -0700114
sangho1e575652015-05-14 00:39:53 -0700115
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700116 private DefaultRoutingHandler defaultRoutingHandler = null;
sangho1e575652015-05-14 00:39:53 -0700117 private TunnelHandler tunnelHandler = null;
118 private PolicyHandler policyHandler = null;
sanghob35a6192015-04-01 13:05:26 -0700119 private InternalPacketProcessor processor = new InternalPacketProcessor();
120 private InternalEventHandler eventHandler = new InternalEventHandler();
121
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700122 private ScheduledExecutorService executorService = Executors
123 .newScheduledThreadPool(1);
sanghob35a6192015-04-01 13:05:26 -0700124
125 private static ScheduledFuture<?> eventHandlerFuture = null;
126 private ConcurrentLinkedQueue<Event> eventQueue = new ConcurrentLinkedQueue<Event>();
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700127 private Map<DeviceId, DefaultGroupHandler> groupHandlerMap = new ConcurrentHashMap<DeviceId, DefaultGroupHandler>();
Srikanth Vavilapalli23181912015-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;
sanghob35a6192015-04-01 13:05:26 -0700133
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700134 private NetworkConfigManager networkConfigService = new NetworkConfigManager();;
135
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700136 private Object threadSchedulerLock = new Object();
137 private static int numOfEventsQueued = 0;
138 private static int numOfEventsExecuted = 0;
sanghob35a6192015-04-01 13:05:26 -0700139 private static int numOfHandlerExecution = 0;
140 private static int numOfHandlerScheduled = 0;
141
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700142 private KryoNamespace.Builder kryoBuilder = null;
143
sanghob35a6192015-04-01 13:05:26 -0700144 @Activate
145 protected void activate() {
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700146 appId = coreService
147 .registerApplication("org.onosproject.segmentrouting");
Srikanth Vavilapalli23181912015-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 Vavilapalli4db76e32015-04-07 15:12:32 -0700170 networkConfigService.init();
171 deviceConfiguration = new DeviceConfiguration(networkConfigService);
Srikanth Vavilapalli4db76e32015-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);
sangho1e575652015-05-14 00:39:53 -0700177 tunnelHandler = new TunnelHandler();
178 policyHandler = new PolicyHandler();
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700179
sanghob35a6192015-04-01 13:05:26 -0700180 packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 2);
181 linkService.addListener(new InternalLinkListener());
sanghob35a6192015-04-01 13:05:26 -0700182 deviceService.addListener(new InternalDeviceListener());
183
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700184 for (Device device : deviceService.getDevices()) {
Srikanth Vavilapalli23181912015-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());
sanghob35a6192015-04-01 13:05:26 -0700197 }
198
sangho20eff1d2015-04-13 15:15:58 -0700199 defaultRoutingHandler.startPopulationProcess();
sanghob35a6192015-04-01 13:05:26 -0700200 log.info("Started");
sangho1e575652015-05-14 00:39:53 -0700201
sanghob35a6192015-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
sangho1e575652015-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
sanghof9d0bf12015-05-19 11:57:42 -0700252 /**
253 * Returns the tunnel object with the tunnel ID.
254 *
255 * @param tunnelId Tunnel ID
256 * @return Tunnel reference
257 */
sangho1e575652015-05-14 00:39:53 -0700258 public Tunnel getTunnel(String tunnelId) {
259 return tunnelHandler.getTunnel(tunnelId);
260 }
261
sanghob35a6192015-04-01 13:05:26 -0700262 /**
263 * Returns the GrouopKey object for the device and the NighborSet given.
264 *
265 * @param ns NeightborSet object for the GroupKey
266 * @return GroupKey object for the NeighborSet
267 */
268 public GroupKey getGroupKey(NeighborSet ns) {
269
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700270 for (DefaultGroupHandler groupHandler : groupHandlerMap.values()) {
sanghob35a6192015-04-01 13:05:26 -0700271 return groupHandler.getGroupKey(ns);
272 }
273
274 return null;
275 }
276
sangho1e575652015-05-14 00:39:53 -0700277 /**
sanghof9d0bf12015-05-19 11:57:42 -0700278 * Returns the next objective ID for the NeighborSet given. If the nextObjectiveID does not exist,
279 * a new one is created and returned.
sangho1e575652015-05-14 00:39:53 -0700280 *
sanghof9d0bf12015-05-19 11:57:42 -0700281 * @param deviceId Device ID
282 * @param ns NegighborSet
283 * @return next objective ID
sangho1e575652015-05-14 00:39:53 -0700284 */
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700285 public int getNextObjectiveId(DeviceId deviceId, NeighborSet ns) {
286
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700287 if (groupHandlerMap.get(deviceId) != null) {
288 log.trace("getNextObjectiveId query in device {}", deviceId);
289 return groupHandlerMap
290 .get(deviceId).getNextObjectiveId(ns);
291 } else {
292 log.warn("getNextObjectiveId query in device {} not found", deviceId);
293 return -1;
294 }
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700295 }
296
sangho1e575652015-05-14 00:39:53 -0700297 /**
sanghof9d0bf12015-05-19 11:57:42 -0700298 * Removes the next objective ID.
sangho1e575652015-05-14 00:39:53 -0700299 *
sanghof9d0bf12015-05-19 11:57:42 -0700300 * @param deviceId Device ID
301 * @param objectiveId next objective ID to remove
302 * @return true, if succeeds, false otherwise
sangho1e575652015-05-14 00:39:53 -0700303 */
304 public boolean removeNextObjective(DeviceId deviceId, int objectiveId) {
305 return groupHandlerMap.get(deviceId).removeGroup(objectiveId);
306 }
307
sanghob35a6192015-04-01 13:05:26 -0700308 private class InternalPacketProcessor implements PacketProcessor {
309
310 @Override
311 public void process(PacketContext context) {
312
313 if (context.isHandled()) {
314 return;
315 }
316
317 InboundPacket pkt = context.inPacket();
318 Ethernet ethernet = pkt.parsed();
319
320 if (ethernet.getEtherType() == Ethernet.TYPE_ARP) {
321 arpHandler.processPacketIn(pkt);
322 } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV4) {
323 IPv4 ipPacket = (IPv4) ethernet.getPayload();
324 ipHandler.addToPacketBuffer(ipPacket);
325 if (ipPacket.getProtocol() == IPv4.PROTOCOL_ICMP) {
326 icmpHandler.processPacketIn(pkt);
327 } else {
328 ipHandler.processPacketIn(pkt);
329 }
330 }
331 }
332 }
333
334 private class InternalLinkListener implements LinkListener {
335 @Override
336 public void event(LinkEvent event) {
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700337 if (event.type() == LinkEvent.Type.LINK_ADDED
338 || event.type() == LinkEvent.Type.LINK_REMOVED) {
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700339 log.debug("Event {} received from Link Service", event.type());
sanghob35a6192015-04-01 13:05:26 -0700340 scheduleEventHandlerIfNotScheduled(event);
341 }
342 }
343 }
344
345 private class InternalDeviceListener implements DeviceListener {
346
347 @Override
348 public void event(DeviceEvent event) {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700349 /*if (mastershipService.getLocalRole(event.subject().id()) != MastershipRole.MASTER) {
sanghob35a6192015-04-01 13:05:26 -0700350 log.debug("Local role {} is not MASTER for device {}",
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700351 mastershipService.getLocalRole(event.subject().id()),
352 event.subject().id());
sanghob35a6192015-04-01 13:05:26 -0700353 return;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700354 }*/
sanghob35a6192015-04-01 13:05:26 -0700355
356 switch (event.type()) {
357 case DEVICE_ADDED:
358 case PORT_REMOVED:
sangho20eff1d2015-04-13 15:15:58 -0700359 case DEVICE_UPDATED:
360 case DEVICE_AVAILABILITY_CHANGED:
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700361 log.debug("Event {} received from Device Service", event.type());
sanghob35a6192015-04-01 13:05:26 -0700362 scheduleEventHandlerIfNotScheduled(event);
363 break;
364 default:
365 }
366 }
367 }
368
sanghob35a6192015-04-01 13:05:26 -0700369 private void scheduleEventHandlerIfNotScheduled(Event event) {
370
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700371 synchronized (threadSchedulerLock) {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700372 eventQueue.add(event);
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700373 numOfEventsQueued++;
374
375 if ((numOfHandlerScheduled - numOfHandlerExecution) == 0) {
376 //No pending scheduled event handling threads. So start a new one.
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700377 eventHandlerFuture = executorService
378 .schedule(eventHandler, 100, TimeUnit.MILLISECONDS);
379 numOfHandlerScheduled++;
380 }
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700381 log.trace("numOfEventsQueued {}, numOfEventHanlderScheduled {}",
382 numOfEventsQueued,
383 numOfHandlerScheduled);
sanghob35a6192015-04-01 13:05:26 -0700384 }
sanghob35a6192015-04-01 13:05:26 -0700385 }
386
387 private class InternalEventHandler implements Runnable {
388
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700389 @Override
sanghob35a6192015-04-01 13:05:26 -0700390 public void run() {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700391 try {
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700392 while (true) {
393 Event event = null;
394 synchronized (threadSchedulerLock) {
395 if (!eventQueue.isEmpty()) {
396 event = eventQueue.poll();
397 numOfEventsExecuted++;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700398 } else {
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700399 numOfHandlerExecution++;
400 log.debug("numOfHandlerExecution {} numOfEventsExecuted {}",
401 numOfHandlerExecution, numOfEventsExecuted);
402 break;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700403 }
sangho20eff1d2015-04-13 15:15:58 -0700404 }
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700405 if (event.type() == LinkEvent.Type.LINK_ADDED) {
406 processLinkAdded((Link) event.subject());
407 } else if (event.type() == LinkEvent.Type.LINK_REMOVED) {
408 processLinkRemoved((Link) event.subject());
409 //} else if (event.type() == GroupEvent.Type.GROUP_ADDED) {
410 // processGroupAdded((Group) event.subject());
411 } else if (event.type() == DeviceEvent.Type.DEVICE_ADDED ||
412 event.type() == DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED ||
413 event.type() == DeviceEvent.Type.DEVICE_UPDATED) {
414 if (deviceService.isAvailable(((Device) event.subject()).id())) {
415 processDeviceAdded((Device) event.subject());
416 }
417 } else if (event.type() == DeviceEvent.Type.PORT_REMOVED) {
418 processPortRemoved((Device) event.subject(),
419 ((DeviceEvent) event).port());
420 } else {
421 log.warn("Unhandled event type: {}", event.type());
422 }
sanghob35a6192015-04-01 13:05:26 -0700423 }
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700424 } catch (Exception e) {
425 log.error("SegmentRouting event handler "
426 + "thread thrown an exception: {}", e);
sanghob35a6192015-04-01 13:05:26 -0700427 }
sanghob35a6192015-04-01 13:05:26 -0700428 }
429 }
430
sanghob35a6192015-04-01 13:05:26 -0700431 private void processLinkAdded(Link link) {
432 log.debug("A new link {} was added", link.toString());
433
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700434 //Irrespective whether the local is a MASTER or not for this device,
435 //create group handler instance and push default TTP flow rules.
436 //Because in a multi-instance setup, instances can initiate
437 //groups for any devices. Also the default TTP rules are needed
438 //to be pushed before inserting any IP table entries for any device
439 DefaultGroupHandler groupHandler = groupHandlerMap.get(link.src()
440 .deviceId());
441 if (groupHandler != null) {
442 groupHandler.linkUp(link);
443 } else {
444 Device device = deviceService.getDevice(link.src().deviceId());
445 if (device != null) {
446 log.warn("processLinkAdded: Link Added "
447 + "Notification without Device Added "
448 + "event, still handling it");
449 processDeviceAdded(device);
450 groupHandler = groupHandlerMap.get(link.src()
451 .deviceId());
sanghob35a6192015-04-01 13:05:26 -0700452 groupHandler.linkUp(link);
453 }
454 }
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700455
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700456 log.trace("Starting optimized route population process");
457 defaultRoutingHandler.populateRoutingRulesForLinkStatusChange(null);
458 //log.trace("processLinkAdded: re-starting route population process");
459 //defaultRoutingHandler.startPopulationProcess();
sanghob35a6192015-04-01 13:05:26 -0700460 }
461
462 private void processLinkRemoved(Link link) {
463 log.debug("A link {} was removed", link.toString());
sangho834e4b02015-05-01 09:38:25 -0700464 DefaultGroupHandler groupHandler = groupHandlerMap.get(link.src().deviceId());
465 if (groupHandler != null) {
466 groupHandler.portDown(link.src().port());
467 }
Srikanth Vavilapalli5428b6c2015-05-14 20:22:47 -0700468 log.trace("Starting optimized route population process");
469 defaultRoutingHandler.populateRoutingRulesForLinkStatusChange(link);
470 //log.trace("processLinkRemoved: re-starting route population process");
471 //defaultRoutingHandler.startPopulationProcess();
sanghob35a6192015-04-01 13:05:26 -0700472 }
473
474 private void processDeviceAdded(Device device) {
475 log.debug("A new device with ID {} was added", device.id());
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700476 //Irrespective whether the local is a MASTER or not for this device,
477 //create group handler instance and push default TTP flow rules.
478 //Because in a multi-instance setup, instances can initiate
479 //groups for any devices. Also the default TTP rules are needed
480 //to be pushed before inserting any IP table entries for any device
481 DefaultGroupHandler dgh = DefaultGroupHandler.
482 createGroupHandler(device.id(),
483 appId,
484 deviceConfiguration,
485 linkService,
486 flowObjectiveService,
487 nsNextObjStore);
sanghob35a6192015-04-01 13:05:26 -0700488 groupHandlerMap.put(device.id(), dgh);
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700489 defaultRoutingHandler.populateTtpRules(device.id());
sanghob35a6192015-04-01 13:05:26 -0700490 }
491
492 private void processPortRemoved(Device device, Port port) {
493 log.debug("Port {} was removed", port.toString());
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700494 DefaultGroupHandler groupHandler = groupHandlerMap.get(device.id());
sanghob35a6192015-04-01 13:05:26 -0700495 if (groupHandler != null) {
496 groupHandler.portDown(port.number());
497 }
498 }
sangho1e575652015-05-14 00:39:53 -0700499
500
501
sanghob35a6192015-04-01 13:05:26 -0700502}