Fixed validation bug of YANG import statement
[controller.git] / opendaylight / hosttracker / src / main / java / org / opendaylight / controller / hosttracker / HostTracker.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 package org.opendaylight.controller.hosttracker;
11
12 import java.net.InetAddress;
13 import java.net.UnknownHostException;
14 import java.util.ArrayList;
15 import java.util.Collections;
16 import java.util.Dictionary;
17 import java.util.EnumSet;
18 import java.util.HashSet;
19 import java.util.List;
20 import java.util.Map;
21 import java.util.Map.Entry;
22 import java.util.Set;
23 import java.util.Timer;
24 import java.util.TimerTask;
25 import java.util.concurrent.Callable;
26 import java.util.concurrent.ConcurrentHashMap;
27 import java.util.concurrent.ConcurrentMap;
28 import java.util.concurrent.ExecutorService;
29 import java.util.concurrent.Executors;
30 import java.util.concurrent.Future;
31
32 import org.apache.felix.dm.Component;
33 import org.apache.taglibs.standard.lang.jstl.DivideOperator;
34 import org.opendaylight.controller.clustering.services.CacheConfigException;
35 import org.opendaylight.controller.clustering.services.CacheExistException;
36 import org.opendaylight.controller.clustering.services.IClusterContainerServices;
37 import org.opendaylight.controller.clustering.services.IClusterServices;
38 import org.opendaylight.controller.hosttracker.hostAware.HostNodeConnector;
39 import org.opendaylight.controller.hosttracker.hostAware.IHostFinder;
40 import org.opendaylight.controller.sal.core.ConstructionException;
41 import org.opendaylight.controller.sal.core.Edge;
42 import org.opendaylight.controller.sal.core.Host;
43 import org.opendaylight.controller.sal.core.Node;
44 import org.opendaylight.controller.sal.core.NodeConnector;
45 import org.opendaylight.controller.sal.core.Property;
46 import org.opendaylight.controller.sal.core.State;
47 import org.opendaylight.controller.sal.core.Tier;
48 import org.opendaylight.controller.sal.core.UpdateType;
49 import org.opendaylight.controller.sal.packet.address.DataLinkAddress;
50 import org.opendaylight.controller.sal.packet.address.EthernetAddress;
51 import org.opendaylight.controller.sal.utils.GlobalConstants;
52 import org.opendaylight.controller.sal.utils.HexEncode;
53 import org.opendaylight.controller.sal.utils.NodeCreator;
54 import org.opendaylight.controller.sal.utils.Status;
55 import org.opendaylight.controller.sal.utils.StatusCode;
56 import org.opendaylight.controller.switchmanager.IInventoryListener;
57 import org.opendaylight.controller.switchmanager.ISwitchManager;
58 import org.opendaylight.controller.switchmanager.ISwitchManagerAware;
59 import org.opendaylight.controller.switchmanager.Subnet;
60 import org.opendaylight.controller.topologymanager.ITopologyManager;
61 import org.opendaylight.controller.topologymanager.ITopologyManagerAware;
62 import org.slf4j.Logger;
63 import org.slf4j.LoggerFactory;
64
65 /**
66  * @file   HostTracker.java
67  * This class tracks the location of IP Hosts as to which Switch, Port, VLAN, they are 
68  * connected to, as well as their MAC address. This is done dynamically as well as statically.
69  * The dynamic mechanism consists of listening to ARP messages as well sending ARP requests.
70  * Static mechanism consists of Northbound APIs to add or remove the hosts from the local
71  * database. ARP aging is also implemented to age out dynamically learned hosts. Interface
72  * methods are provided for other applications to
73  *  1. Query the local database for a single host
74  *  2. Get a list of all hosts
75  *  3. Get notification if a host is learned/added or removed the database
76  */
77
78 public class HostTracker implements IfIptoHost, IfHostListener,
79         ISwitchManagerAware, IInventoryListener, ITopologyManagerAware {
80     private static final Logger logger = LoggerFactory
81             .getLogger(HostTracker.class);
82     private IHostFinder hostFinder;
83     private ConcurrentMap<InetAddress, HostNodeConnector> hostsDB;
84     /* Following is a list of hosts which have been requested by NB APIs to be added,
85      * but either the switch or the port is not sup, so they will be added here until
86      * both come up
87      */
88     private ConcurrentMap<NodeConnector, HostNodeConnector> inactiveStaticHosts;
89     private Set<IfNewHostNotify> newHostNotify = Collections
90             .synchronizedSet(new HashSet<IfNewHostNotify>());
91
92     private ITopologyManager topologyManager;
93     private IClusterContainerServices clusterContainerService = null;
94     private ISwitchManager switchManager = null;
95     private Timer timer;
96     private Timer arp_refresh_timer;
97     private String containerName = null;
98
99     private static class ARPPending {
100         protected InetAddress hostIP;
101         protected short sent_count;
102         protected HostTrackerCallable hostTrackerCallable;
103
104         public InetAddress getHostIP() {
105             return hostIP;
106         }
107
108         public short getSent_count() {
109             return sent_count;
110         }
111
112         public HostTrackerCallable getHostTrackerCallable() {
113             return hostTrackerCallable;
114         }
115
116         public void setHostIP(InetAddress networkAddr) {
117             this.hostIP = networkAddr;
118         }
119
120         public void setSent_count(short count) {
121             this.sent_count = count;
122         }
123
124         public void setHostTrackerCallable(HostTrackerCallable callable) {
125             hostTrackerCallable = callable;
126         }
127     }
128
129     //This list contains the hosts for which ARP requests are being sent periodically
130     private List<ARPPending> ARPPendingList = new ArrayList<HostTracker.ARPPending>();
131     /*
132      * This list below contains the hosts which were initially in ARPPendingList above,
133      * but ARP response didn't come from there hosts after multiple attempts over 8
134      * seconds. The assumption is that the response didn't come back due to one of the
135      * following possibilities:
136      *   1. The L3 interface wasn't created for this host in the controller. This would
137      *      cause arphandler not to know where to send the ARP
138      *   2. The host facing port is down
139      *   3. The IP host doesn't exist or is not responding to ARP requests
140      *
141      * Conditions 1 and 2 above can be recovered if ARP is sent when the relevant L3
142      * interface is added or the port facing host comes up. Whenever L3 interface is
143      * added or host facing port comes up, ARP will be sent to hosts in this list.
144      *
145      * We can't recover from condition 3 above
146      */
147     private ArrayList<ARPPending> failedARPReqList = new ArrayList<HostTracker.ARPPending>();
148
149     public HostTracker() {
150     }
151
152     private void startUp() {
153         allocateCache();
154         retrieveCache();
155
156         timer = new Timer();
157         timer.schedule(new OutStandingARPHandler(), 4000, 4000);
158
159         /* ARP Refresh Timer to go off every 5 seconds to implement ARP aging */
160         arp_refresh_timer = new Timer();
161         arp_refresh_timer.schedule(new ARPRefreshHandler(), 5000, 5000);
162         logger.debug("startUp: Caches created, timers started");
163     }
164
165     @SuppressWarnings("deprecation")
166         private void allocateCache() {
167         if (this.clusterContainerService == null) {
168             logger
169                     .error("un-initialized clusterContainerService, can't create cache");
170             return;
171         }
172         logger.debug("Creating Cache for HostTracker");
173         try {
174             this.clusterContainerService.createCache("hostTrackerAH", EnumSet
175                     .of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
176             this.clusterContainerService.createCache("hostTrackerIH", EnumSet
177                     .of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
178         } catch (CacheConfigException cce) {
179             logger
180                     .error("Cache couldn't be created for HostTracker -  check cache mode");
181         } catch (CacheExistException cce) {
182             logger
183                     .error("Cache for HostTracker already exists, destroy and recreate");
184         }
185         logger.debug("Cache successfully created for HostTracker");
186     }
187
188     @SuppressWarnings({ "unchecked", "deprecation" })
189     private void retrieveCache() {
190         if (this.clusterContainerService == null) {
191             logger
192                     .error("un-initialized clusterContainerService, can't retrieve cache");
193             return;
194         }
195         logger.debug("Retrieving cache for HostTrackerAH");
196         hostsDB = (ConcurrentMap<InetAddress, HostNodeConnector>) this.clusterContainerService
197                 .getCache("hostTrackerAH");
198         if (hostsDB == null) {
199             logger.error("Cache couldn't be retrieved for HostTracker");
200         }
201         logger.debug("Cache was successfully retrieved for HostTracker");
202         logger.debug("Retrieving cache for HostTrackerIH");
203         inactiveStaticHosts = (ConcurrentMap<NodeConnector, HostNodeConnector>) this.clusterContainerService
204                 .getCache("hostTrackerIH");
205         if (inactiveStaticHosts == null) {
206             logger.error("Cache couldn't be retrieved for HostTrackerIH");
207         }
208         logger.debug("Cache was successfully retrieved for HostTrackerIH");
209     }
210
211     public void nonClusterObjectCreate() {
212         hostsDB = new ConcurrentHashMap<InetAddress, HostNodeConnector>();
213         inactiveStaticHosts = new ConcurrentHashMap<NodeConnector, HostNodeConnector>();
214     }
215
216     @SuppressWarnings("deprecation")
217         private void destroyCache() {
218         if (this.clusterContainerService == null) {
219             logger.error("un-initialized clusterMger, can't destroy cache");
220             return;
221         }
222         logger.debug("Destroying Cache for HostTracker");
223         this.clusterContainerService.destroyCache("hostTrackerAH");
224         this.clusterContainerService.destroyCache("hostTrackerIH");
225         nonClusterObjectCreate();
226     }
227
228     public void shutDown() {
229     }
230
231     public void setnewHostNotify(IfNewHostNotify obj) {
232         this.newHostNotify.add(obj);
233     }
234
235     public void unsetnewHostNotify(IfNewHostNotify obj) {
236         this.newHostNotify.remove(obj);
237     }
238
239     public void setArpHandler(IHostFinder hostFinder) {
240         this.hostFinder = hostFinder;
241     }
242
243     public void unsetArpHandler(IHostFinder hostFinder) {
244         if (this.hostFinder == hostFinder) {
245             logger.debug("Arp Handler Service removed!");
246             this.hostFinder = null;
247         }
248     }
249
250     public void setTopologyManager(ITopologyManager s) {
251         this.topologyManager = s;
252     }
253
254     public void unsetTopologyManager(ITopologyManager s) {
255         if (this.topologyManager == s) {
256             logger.debug("Topology Manager Service removed!");
257             this.topologyManager = null;
258         }
259     }
260
261     private boolean hostExists(HostNodeConnector host) {
262         HostNodeConnector lhost = hostsDB.get(host.getNetworkAddress());
263         return host.equals(lhost);
264     }
265
266     private HostNodeConnector getHostFromOnActiveDB(InetAddress networkAddress) {
267         return hostsDB.get(networkAddress);
268     }
269
270     private Entry<NodeConnector, HostNodeConnector> getHostFromInactiveDB(
271             InetAddress networkAddress) {
272         for (Entry<NodeConnector, HostNodeConnector> entry : inactiveStaticHosts
273                 .entrySet()) {
274             if (entry.getValue().equalsByIP(networkAddress)) {
275                 logger
276                         .debug(
277                                 "getHostFromInactiveDB(): Inactive Host found for IP:{} ",
278                                 networkAddress.getHostAddress());
279                 return entry;
280             }
281         }
282         logger.debug(
283                 "getHostFromInactiveDB() Inactive Host Not found for IP: {}",
284                 networkAddress.getHostAddress());
285         return null;
286     }
287
288     private void removeHostFromInactiveDB(InetAddress networkAddress) {
289         NodeConnector nodeConnector = null;
290         for (Entry<NodeConnector, HostNodeConnector> entry : inactiveStaticHosts
291                 .entrySet()) {
292             if (entry.getValue().equalsByIP(networkAddress)) {
293                 nodeConnector = entry.getKey();
294                 break;
295             }
296         }
297         if (nodeConnector != null) {
298             inactiveStaticHosts.remove(nodeConnector);
299             logger.debug("removeHostFromInactiveDB(): Host Removed for IP: {}",
300                     networkAddress.getHostAddress());
301             return;
302         }
303         logger.debug("removeHostFromInactiveDB(): Host Not found for IP: {}",
304                 networkAddress.getHostAddress());
305     }
306
307     protected boolean hostMoved(HostNodeConnector host) {
308         if (hostQuery(host.getNetworkAddress()) != null) {
309             return true;
310         }
311         return false;
312     }
313
314     public HostNodeConnector hostQuery(InetAddress networkAddress) {
315         return hostsDB.get(networkAddress);
316     }
317
318     public Future<HostNodeConnector> discoverHost(InetAddress networkAddress) {
319         ExecutorService executor = Executors.newFixedThreadPool(1);
320         if (executor == null) {
321             logger.error("discoverHost: Null executor");
322             return null;
323         }
324         Callable<HostNodeConnector> worker = new HostTrackerCallable(this,
325                 networkAddress);
326         Future<HostNodeConnector> submit = executor.submit(worker);
327         return submit;
328     }
329
330     public HostNodeConnector hostFind(InetAddress networkAddress) {
331         /*
332          * Sometimes at boot with containers configured in the startup
333          * we hit this path (from TIF) when hostFinder has not been set yet
334          * Caller already handles the null return
335          */
336
337         if (hostFinder == null) {
338             logger.debug("Exiting hostFind, null hostFinder");
339             return null;
340         }
341
342         HostNodeConnector host = hostQuery(networkAddress);
343         if (host != null) {
344             logger.debug("hostFind(): Host found for IP: {}", networkAddress
345                     .getHostAddress());
346             return host;
347         }
348         /* host is not found, initiate a discovery */
349         hostFinder.find(networkAddress);
350         /* Also add this host to ARPPending List for any potential retries */
351         AddtoARPPendingList(networkAddress);
352         logger
353                 .debug(
354                         "hostFind(): Host Not Found for IP: {}, Inititated Host Discovery ...",
355                         networkAddress.getHostAddress());
356         return null;
357     }
358
359     public Set<HostNodeConnector> getAllHosts() {
360         Set<HostNodeConnector> allHosts = new HashSet<HostNodeConnector>();
361         for (Entry<InetAddress, HostNodeConnector> entry : hostsDB.entrySet()) {
362             HostNodeConnector host = entry.getValue();
363             allHosts.add(host);
364         }
365         logger.debug("Exiting getAllHosts, Found {} Hosts", allHosts.size());
366         return allHosts;
367     }
368
369     @Override
370     public Set<HostNodeConnector> getActiveStaticHosts() {
371         Set<HostNodeConnector> list = new HashSet<HostNodeConnector>();
372         for (Entry<InetAddress, HostNodeConnector> entry : hostsDB.entrySet()) {
373             HostNodeConnector host = entry.getValue();
374             if (host.isStaticHost()) {
375                 list.add(host);
376             }
377         }
378         logger.debug("getActiveStaticHosts(): Found {} Hosts", list.size());
379         return list;
380     }
381
382     @Override
383     public Set<HostNodeConnector> getInactiveStaticHosts() {
384         Set<HostNodeConnector> list = new HashSet<HostNodeConnector>();
385         for (Entry<NodeConnector, HostNodeConnector> entry : inactiveStaticHosts
386                 .entrySet()) {
387             list.add(entry.getValue());
388         }
389         logger.debug("getInactiveStaticHosts(): Found {} Hosts", list.size());
390         return list;
391     }
392
393     private void AddtoARPPendingList(InetAddress networkAddr) {
394         ARPPending arphost = new ARPPending();
395
396         arphost.setHostIP(networkAddr);
397         arphost.setSent_count((short) 1);
398         ARPPendingList.add(arphost);
399         logger.debug("Host Added to ARPPending List, IP: {}", networkAddr
400                 .toString());
401     }
402
403     private void removePendingARPFromList(int index) {
404         if (index >= ARPPendingList.size()) {
405             logger
406                     .warn(
407                             "removePendingARPFromList(): index greater than the List. Size:{}, Index:{}",
408                             ARPPendingList.size(), index);
409             return;
410         }
411         ARPPending arphost = ARPPendingList.remove(index);
412         HostTrackerCallable htCallable = arphost.getHostTrackerCallable();
413         if (htCallable != null)
414             htCallable.wakeup();
415     }
416
417     public void setCallableOnPendingARP(InetAddress networkAddr,
418             HostTrackerCallable callable) {
419         ARPPending arphost;
420         for (int i = 0; i < ARPPendingList.size(); i++) {
421             arphost = ARPPendingList.get(i);
422             if (arphost.getHostIP().equals(networkAddr)) {
423                 arphost.setHostTrackerCallable(callable);
424             }
425         }
426     }
427
428     private void ProcPendingARPReqs(InetAddress networkAddr) {
429         ARPPending arphost;
430
431         for (int i = 0; i < ARPPendingList.size(); i++) {
432             arphost = ARPPendingList.get(i);
433             if (arphost.getHostIP().equals(networkAddr)) {
434                 /* An ARP was sent for this host. The address is learned,
435                  * remove the request
436                  */
437                 removePendingARPFromList(i);
438                 logger.debug("Host Removed from ARPPending List, IP: {}",
439                         networkAddr.toString());
440                 return;
441             }
442         }
443
444         /*
445          * It could have been a host from the FailedARPReqList
446          */
447
448         for (int i = 0; i < failedARPReqList.size(); i++) {
449             arphost = failedARPReqList.get(i);
450             if (arphost.getHostIP().equals(networkAddr)) {
451                 /* An ARP was sent for this host. The address is learned,
452                  * remove the request
453                  */
454                 failedARPReqList.remove(i);
455                 logger.debug("Host Removed from FailedARPReqList List, IP: {}",
456                         networkAddr.toString());
457                 return;
458             }
459         }
460     }
461
462     // Learn a new Host
463     private void learnNewHost(HostNodeConnector host) {
464         host.initArpSendCountDown();
465         hostsDB.put(host.getNetworkAddress(), host);
466         logger.debug("New Host Learned: MAC: {}  IP: {}", HexEncode
467                 .bytesToHexString(host.getDataLayerAddressBytes()), host
468                 .getNetworkAddress().getHostAddress());
469     }
470
471     // Remove known Host
472     private void removeKnownHost(InetAddress key) {
473         HostNodeConnector host = hostsDB.get(key);
474         if (host != null) {
475             logger.debug("Removing Host: IP:{}", host.getNetworkAddress()
476                     .getHostAddress());
477             hostsDB.remove(key);
478         } else {
479             logger
480                     .error(
481                             "removeKnownHost(): Host for IP address {} not found in hostsDB",
482                             key.getHostAddress());
483         }
484     }
485
486     private class NotifyHostThread extends Thread {
487
488         private HostNodeConnector host;
489
490         public NotifyHostThread(HostNodeConnector h) {
491             this.host = h;
492         }
493
494         public void run() {
495             /* Check for Host Move case */
496             if (hostMoved(host)) {
497                 /*
498                  * Host has been moved from one location (switch,port, MAC, or VLAN).
499                  * Remove the existing host with its previous location parameters,
500                  * inform the applications, and add it as a new Host
501                  */
502                 HostNodeConnector removedHost = hostsDB.get(host
503                         .getNetworkAddress());
504                 removeKnownHost(host.getNetworkAddress());
505                 if (removedHost != null) {
506                     notifyHostLearnedOrRemoved(removedHost, false);
507                     logger.debug(
508                             "Host move occurred. Old Host:{}, New Host: {}",
509                             removedHost, host);
510                 } else {
511                     logger.error(
512                             "Host to be removed not found in hostsDB. Host {}",
513                             removedHost);
514                 }
515             }
516
517             /* check if there is an outstanding request for this host */
518             InetAddress networkAddr = host.getNetworkAddress();
519
520             // add and notify
521             learnNewHost(host);
522             ProcPendingARPReqs(networkAddr);
523             notifyHostLearnedOrRemoved(host, true);
524         }
525     }
526
527     public void hostListener(HostNodeConnector host) {
528
529         if (hostExists(host)) {
530             logger.debug("ARP received for Host: {}", host);
531             HostNodeConnector existinghost = hostsDB.get(host
532                     .getNetworkAddress());
533             existinghost.initArpSendCountDown();
534             return;
535         }
536         new NotifyHostThread(host).start();
537     }
538
539     // Notify whoever is interested that a new host was learned (dynamically or statically)
540     private void notifyHostLearnedOrRemoved(HostNodeConnector host, boolean add) {
541         // Update listeners if any
542         if (newHostNotify != null) {
543             synchronized (this.newHostNotify) {
544                 for (IfNewHostNotify ta : newHostNotify) {
545                     try {
546                         if (add) {
547                             ta.notifyHTClient(host);
548                         } else {
549                             ta.notifyHTClientHostRemoved(host);
550                         }
551                     } catch (Exception e) {
552                         logger.error("Exception on callback", e);
553                     }
554                 }
555             }
556         } else {
557             logger
558                     .error("notifyHostLearnedOrRemoved(): New host notify is null");
559         }
560
561         // Topology update is for some reason outside of listeners registry logic
562         Node node = host.getnodeconnectorNode();
563         Host h = null;
564         NodeConnector p = host.getnodeConnector();
565         try {
566             DataLinkAddress dla = new EthernetAddress(host
567                     .getDataLayerAddressBytes());
568             h = new org.opendaylight.controller.sal.core.Host(dla, host
569                     .getNetworkAddress());
570         } catch (ConstructionException ce) {
571             p = null;
572             h = null;
573         }
574
575         if (topologyManager != null && p != null && h != null) {
576             if (add == true) {
577                 Tier tier = new Tier(1);
578                 switchManager.setNodeProp(node, tier);
579                 topologyManager.updateHostLink(p, h, UpdateType.ADDED, null);
580                 /*
581                  * This is a temporary fix for Cisco Live's Hadoop Demonstration.
582                  * The concept of Tiering must be revisited based on other application requirements
583                  * and the design might warrant a separate module (as it involves tracking the topology/
584                  * host changes & updating the Tiering numbers in an effective manner).
585                  */
586                 updateSwitchTiers(node, 1);
587
588                 /*
589                  * The following 2 lines are added for testing purposes.
590                  * We can remove it once the North-Bound APIs are available for testing.
591
592                 ArrayList<ArrayList<String>> hierarchies = getHostNetworkHierarchy(host.getNetworkAddress());
593                 logHierarchies(hierarchies);
594                  */
595             } else {
596                 // No need to reset the tiering if no other hosts are currently connected
597                 // If this switch was discovered to be an access switch, it still is even if the host is down
598                 Tier tier = new Tier(0);
599                 switchManager.setNodeProp(node, tier);
600                 topologyManager.updateHostLink(p, h, UpdateType.REMOVED, null);
601             }
602         }
603     }
604
605     /**
606      * When a new Host is learnt by the hosttracker module, it places the directly connected Node
607      * in Tier-1 & using this function, updates the Tier value for all other Nodes in the network
608      * hierarchy.
609      *
610      * This is a recursive function and it takes care of updating the Tier value for all the connected
611      * and eligible Nodes.
612      *
613      * @param n Node that represents one of the Vertex in the Topology Graph.
614      * @param currentTier The Tier on which n belongs
615      */
616     private void updateSwitchTiers(Node n, int currentTier) {
617         Map<Node, Set<Edge>> ndlinks = topologyManager.getNodeEdges();
618         if (ndlinks == null) {
619             logger.debug(
620                     "updateSwitchTiers(): ndlinks null for Node: {}, Tier:{}",
621                     n, currentTier);
622             return;
623         }
624         Set<Edge> links = ndlinks.get(n);
625         if (links == null) {
626             logger.debug("updateSwitchTiers(): links null for ndlinks:{}",
627                     ndlinks);
628             return;
629         }
630         ArrayList<Node> needsVisiting = new ArrayList<Node>();
631         for (Edge lt : links) {
632             if (!lt.getHeadNodeConnector().getType().equals(
633                     NodeConnector.NodeConnectorIDType.OPENFLOW)) {
634                 // We don't want to work on Node that are not openflow
635                 // for now
636                 continue;
637             }
638             Node dstNode = lt.getHeadNodeConnector().getNode();
639             if (switchNeedsTieringUpdate(dstNode, currentTier + 1)) {
640                 Tier t = new Tier(currentTier + 1);
641                 switchManager.setNodeProp(dstNode, t);
642                 //logger.info("Updating Switch Tier "+ (currentTier+1) +" for "+String.format("%x", dstSw.getId()));
643                 needsVisiting.add(dstNode);
644             }
645         }
646
647         /*
648          * Due to the nature of the problem, having a separate loop for nodes
649          * that needs visiting provides a decent walk optimization.
650          */
651         for (Node node : needsVisiting) {
652             updateSwitchTiers(node, currentTier + 1);
653         }
654     }
655
656     /**
657      * Internal convenience routine to check the eligibility of a Switch for a Tier update.
658      * Any Node with Tier=0 or a Tier value that is greater than the new Tier Value is eligible
659      * for the update.
660      *
661      * @param n Node for which the Tier update eligibility is checked
662      * @param tier new Tier Value
663      * @return <code>true</code> if the Node is eligible for Tier Update
664      *         <code>false</code> otherwise
665      */
666
667     private boolean switchNeedsTieringUpdate(Node n, int tier) {
668         if (n == null) {
669             logger.error("switchNeedsTieringUpdate(): Null node for tier: {}",
670                     tier);
671             return false;
672         }
673         /*
674          * Node could have gone down
675          */
676         if (!switchManager.getNodes().contains(n)) {
677             return false;
678         }
679         // This is the case where Tier was never set for this node
680         Tier t = (Tier) switchManager.getNodeProp(n, Tier.TierPropName);
681         if (t == null)
682             return true;
683         if (t.getValue() == 0)
684             return true;
685         else if (t.getValue() > tier)
686             return true;
687         //logger.info(getContainerName()+" -> "+ "Switch "+String.format("%x", sw.getId())+ " is in better Tier "+sw.getTier()+" ... skipping "+tier);
688         return false;
689     }
690
691     /**
692      * Internal convenience routine to clear all the Tier values to 0.
693      * This cleanup is performed during cases such as Topology Change where the existing Tier values
694      * might become incorrect
695      */
696     private void clearTiers() {
697         Set<Node> nodes = null;
698         if (switchManager == null) {
699             logger.error("clearTiers(): Null switchManager");
700             return;
701         }
702         nodes = switchManager.getNodes();
703
704         for (Node n : nodes) {
705             Tier t = new Tier(0);
706             switchManager.setNodeProp(n, t);
707         }
708     }
709
710     /**
711      * Internal convenience routine to print the hierarchies of switches.
712      */
713     @SuppressWarnings("unused")
714     private void logHierarchies(ArrayList<ArrayList<String>> hierarchies) {
715         String hierarchyString = null;
716         int num = 1;
717         for (ArrayList<String> hierarchy : hierarchies) {
718             StringBuffer buf = new StringBuffer();
719             buf.append("Hierarchy#" + num + " : ");
720             for (String switchName : hierarchy) {
721                 buf.append(switchName + "/");
722             }
723             logger.debug("{} -> {}", getContainerName(), buf.toString());
724             num++;
725         }
726     }
727
728     /**
729      * getHostNetworkHierarchy is the Back-end routine for the North-Bound API that returns
730      * the Network Hierarchy for a given Host. This API is typically used by applications like
731      * Hadoop for Rack Awareness functionality.
732      *
733      * @param hostAddress IP-Address of the host/node.
734      * @return Network Hierarchies represented by an Array of Array (of Switch-Ids as String).
735      */
736     public List<List<String>> getHostNetworkHierarchy(InetAddress hostAddress) {
737         HostNodeConnector host = hostQuery(hostAddress);
738         if (host == null)
739             return null;
740
741         List<List<String>> hierarchies = new ArrayList<List<String>>();
742         ArrayList<String> currHierarchy = new ArrayList<String>();
743         hierarchies.add(currHierarchy);
744
745         Node node = host.getnodeconnectorNode();
746         updateCurrentHierarchy(node, currHierarchy, hierarchies);
747         return hierarchies;
748     }
749
750     /**
751      * dpidToHostNameHack is a hack function for Cisco Live Hadoop Demo.
752      * Mininet is used as the network for Hadoop Demos & in order to give a meaningful
753      * rack-awareness switch names, the DPID is organized in ASCII Characters and
754      * retrieved as string.
755      *
756      * @param dpid Switch DataPath Id
757      * @return Ascii String represented by the DPID.
758      */
759     private String dpidToHostNameHack(long dpid) {
760         String hex = Long.toHexString(dpid);
761
762         StringBuffer sb = new StringBuffer();
763         int result = 0;
764         for (int i = 0; i < hex.length(); i++) {
765             result = (int) ((dpid >> (i * 8)) & 0xff);
766             if (result == 0)
767                 continue;
768             if (result < 0x30)
769                 result += 0x40;
770             sb.append(String.format("%c", result));
771         }
772         return sb.reverse().toString();
773     }
774
775     /**
776      * A convenient recursive routine to obtain the Hierarchy of Switches.
777      *
778      * @param node Current Node in the Recursive routine.
779      * @param currHierarchy Array of Nodes that make this hierarchy on which the Current Switch belong
780      * @param fullHierarchy Array of multiple Hierarchies that represent a given host.
781      */
782     @SuppressWarnings("unchecked")
783     private void updateCurrentHierarchy(Node node,
784             ArrayList<String> currHierarchy, List<List<String>> fullHierarchy) {
785         //currHierarchy.add(String.format("%x", currSw.getId()));
786         currHierarchy.add(dpidToHostNameHack((Long) node.getID()));
787         ArrayList<String> currHierarchyClone = (ArrayList<String>) currHierarchy
788                 .clone(); //Shallow copy as required
789
790         Map<Node, Set<Edge>> ndlinks = topologyManager.getNodeEdges();
791         if (ndlinks == null) {
792             logger
793                     .debug(
794                             "updateCurrentHierarchy(): topologyManager returned null ndlinks for node: {}",
795                             node);
796             return;
797         }
798         Node n = NodeCreator.createOFNode((Long) node.getID());
799         Set<Edge> links = ndlinks.get(n);
800         if (links == null) {
801             logger.debug("updateCurrentHierarchy(): Null links for ndlinks");
802             return;
803         }
804         for (Edge lt : links) {
805             if (!lt.getHeadNodeConnector().getType().equals(
806                     NodeConnector.NodeConnectorIDType.OPENFLOW)) {
807                 // We don't want to work on Node that are not openflow
808                 // for now
809                 continue;
810             }
811             Node dstNode = lt.getHeadNodeConnector().getNode();
812
813             Tier nodeTier = (Tier) switchManager.getNodeProp(node,
814                     Tier.TierPropName);
815             Tier dstNodeTier = (Tier) switchManager.getNodeProp(dstNode,
816                     Tier.TierPropName);
817             if (dstNodeTier.getValue() > nodeTier.getValue()) {
818                 ArrayList<String> buildHierarchy = currHierarchy;
819                 if (currHierarchy.size() > currHierarchyClone.size()) {
820                     buildHierarchy = (ArrayList<String>) currHierarchyClone
821                             .clone(); //Shallow copy as required
822                     fullHierarchy.add(buildHierarchy);
823                 }
824                 updateCurrentHierarchy(dstNode, buildHierarchy, fullHierarchy);
825             }
826         }
827     }
828
829     @Override
830     public void edgeUpdate(Edge e, UpdateType type, Set<Property> props) {
831         Long srcNid = null;
832         Short srcPort = null;
833         Long dstNid = null;
834         Short dstPort = null;
835         boolean added = false;
836         String srcType = null;
837         String dstType = null;
838
839         if (e == null || type == null) {
840             logger.error("Edge or Update type are null!");
841             return;
842         } else {
843             srcType = e.getTailNodeConnector().getType();
844             dstType = e.getHeadNodeConnector().getType();
845
846             if (srcType.equals(NodeConnector.NodeConnectorIDType.PRODUCTION)) {
847                 logger.debug("Skip updates for {}", e);
848                 return;
849             }
850
851             if (!srcType.equals(NodeConnector.NodeConnectorIDType.OPENFLOW)) {
852                 logger.error("For now we cannot handle updates for "
853                         + "non-openflow nodes");
854                 return;
855             }
856
857             if (dstType.equals(NodeConnector.NodeConnectorIDType.PRODUCTION)) {
858                 logger.debug("Skip updates for {}", e);
859                 return;
860             }
861
862             if (!dstType.equals(NodeConnector.NodeConnectorIDType.OPENFLOW)) {
863                 logger.error("For now we cannot handle updates for "
864                         + "non-openflow nodes");
865                 return;
866             }
867
868             // At this point we know we got an openflow update, so
869             // lets fill everything accordingly.
870             srcNid = (Long) e.getTailNodeConnector().getNode()
871                     .getID();
872             srcPort = (Short) e.getTailNodeConnector().getID();
873             dstNid = (Long) e.getHeadNodeConnector().getNode()
874                     .getID();
875             dstPort = (Short) e.getHeadNodeConnector().getID();
876
877             // Now lets update the added flag
878             switch (type) {
879             case ADDED:
880             case CHANGED:
881                 added = true;
882                 break;
883             case REMOVED:
884                 added = false;
885             }
886         }
887
888         logger.debug("HostTracker Topology linkUpdate handling src:{}[port {}] dst:{}[port {}] added: {}",
889                      new Object[] { srcNid, srcPort, dstNid, dstPort, added });
890         clearTiers();
891         for (Entry<InetAddress, HostNodeConnector> entry : hostsDB.entrySet()) {
892             HostNodeConnector host = entry.getValue();
893             Node node = host.getnodeconnectorNode();
894             if (node != null) {
895                 Tier t = new Tier(1);
896                 switchManager.setNodeProp(node, t);
897                 updateSwitchTiers(node, 1);
898             }
899         }
900     }
901
902     public void subnetNotify(Subnet sub, boolean add) {
903         logger.debug("Received subnet notification: {}  add={}", sub, add);
904         if (add) {
905             for (int i = 0; i < failedARPReqList.size(); i++) {
906                 ARPPending arphost;
907                 arphost = failedARPReqList.get(i);
908                 logger.debug(
909                         "Sending the ARP from FailedARPReqList fors IP: {}",
910                         arphost.getHostIP().getHostAddress());
911                 hostFinder.find(arphost.getHostIP());
912             }
913         }
914     }
915
916     class OutStandingARPHandler extends TimerTask {
917         public void run() {
918             ARPPending arphost;
919             /* This routine runs every 4 seconds */
920             // logger.info ("ARP Handler called");
921             for (int i = 0; i < ARPPendingList.size(); i++) {
922                 arphost = ARPPendingList.get(i);
923                 if (arphost.getSent_count() < switchManager.getHostRetryCount()) {
924                     /* No reply has been received of first ARP Req, send the next one */
925                     hostFinder.find(arphost.getHostIP());
926                     arphost.sent_count++;
927                     logger.debug("ARP Sent from ARPPending List, IP: {}",
928                             arphost.getHostIP().getHostAddress());
929                 } else if (arphost.getSent_count() >= switchManager
930                         .getHostRetryCount()) {
931                     /* Two ARP requests have been sent without
932                      * receiving a reply, remove this from the
933                      * pending list
934                      */
935                     removePendingARPFromList(i);
936                     logger
937                             .debug(
938                                     "ARP reply not received after two attempts, removing from Pending List IP: {}",
939                                     arphost.getHostIP().getHostAddress());
940                     /*
941                      * Add this host to a different list which will be processed on link
942                      * up events
943                      */
944                     logger.debug("Adding the host to FailedARPReqList IP: {}",
945                             arphost.getHostIP().getHostAddress());
946                     failedARPReqList.add(arphost);
947
948                 } else {
949                     logger
950                             .error(
951                                     "Inavlid arp_sent count for entery at index: {}",
952                                     i);
953                 }
954             }
955         }
956     }
957
958     private class ARPRefreshHandler extends TimerTask {
959         public void run() {
960             if ((clusterContainerService != null)
961                     && !clusterContainerService.amICoordinator()) {
962                 return;
963             }
964             if ((switchManager != null)
965                     && !switchManager.isHostRefreshEnabled()) {
966                 /*
967                  * The host probe procedure was disabled by CLI
968                  */
969                 return;
970             }
971             if (hostsDB == null) {
972                 /* hostsDB is not allocated yet */
973                 logger
974                         .error("ARPRefreshHandler(): hostsDB is not allocated yet:");
975                 return;
976             }
977             for (Entry<InetAddress, HostNodeConnector> entry : hostsDB
978                     .entrySet()) {
979                 HostNodeConnector host = entry.getValue();
980                 if (host.isStaticHost()) {
981                     /* this host was learned via API3, don't age it out */
982                     continue;
983                 }
984
985                 short arp_cntdown = host.getArpSendCountDown();
986                 arp_cntdown--;
987                 if (arp_cntdown > switchManager.getHostRetryCount()) {
988                     host.setArpSendCountDown(arp_cntdown);
989                 } else if (arp_cntdown <= 0) {
990                     /* No ARP Reply received in last 2 minutes, remove this host and inform applications*/
991                     removeKnownHost(entry.getKey());
992                     notifyHostLearnedOrRemoved(host, false);
993                 } else if (arp_cntdown <= switchManager.getHostRetryCount()) {
994                     /* Use the services of arphandler to check if host is still there */
995                     // logger.info("Probe for Host:{}", host);
996                     //logger.info("ARP Probing ("+arp_cntdown+") for "+host.toString());
997                     logger.trace("ARP Probing ({}) for {}({})", new Object[] {
998                             arp_cntdown,
999                             host.getNetworkAddress().getHostAddress(),
1000                             HexEncode.bytesToHexString(host
1001                                     .getDataLayerAddressBytes()) });
1002                     host.setArpSendCountDown(arp_cntdown);
1003                     hostFinder.probe(host);
1004                 }
1005             }
1006         }
1007     }
1008
1009     /**
1010      * Inform the controller IP to MAC binding of a host and its
1011      * connectivity to an openflow switch in terms of Node, port, and
1012      * VLAN.
1013      *
1014      * @param networkAddr   IP address of the host
1015      * @param dataLayer         Address MAC address of the host
1016      * @param nc            NodeConnector to which host is connected
1017      * @param port          Port of the switch to which host is connected
1018      * @param vlan          Vlan of which this host is member of
1019      *
1020      * @return Status           The status object as described in {@code Status}
1021      *                                          indicating the result of this action.
1022      */
1023
1024     public Status addStaticHostReq(InetAddress networkAddr,
1025             byte[] dataLayerAddress, NodeConnector nc, short vlan) {
1026         if (dataLayerAddress.length != 6) {
1027                 return new Status(StatusCode.BADREQUEST, "Invalid MAC address");
1028         }
1029
1030         HostNodeConnector host = null;
1031         try {
1032             host = new HostNodeConnector(dataLayerAddress, networkAddr, nc,
1033                                          vlan);
1034             if (hostExists(host)) {
1035                 // This host is already learned either via ARP or through a northbound request
1036                 HostNodeConnector transHost = hostsDB.get(networkAddr);
1037                 transHost.setStaticHost(true);
1038                 return new Status(StatusCode.SUCCESS, null);
1039             }
1040             host.setStaticHost(true);
1041             /*
1042              * Before adding host, Check if the switch and the port have already come up
1043              */
1044             if (switchManager.isNodeConnectorEnabled(nc)) {
1045                 learnNewHost(host);
1046                 notifyHostLearnedOrRemoved(host, true);
1047             } else {
1048                 inactiveStaticHosts.put(nc, host);
1049                 logger
1050                         .debug(
1051                                 "Switch or switchport is not up, adding host {} to inactive list",
1052                                 networkAddr.getHostName());
1053             }
1054             return new Status(StatusCode.SUCCESS, null);
1055         } catch (ConstructionException e) {
1056             return new Status(StatusCode.INTERNALERROR, "Host could not be created");
1057         }
1058
1059     }
1060
1061     /**
1062      * Update the controller IP to MAC binding of a host and its
1063      * connectivity to an openflow switch in terms of
1064      * switch id, switch port, and VLAN.
1065      *
1066      * @param networkAddr   IP address of the host
1067      * @param dataLayer         Address MAC address of the host
1068      * @param nc            NodeConnector to which host is connected
1069      * @param port          Port of the switch to which host is connected
1070      * @param vlan          Vlan of which this host is member of
1071      *
1072      * @return boolean          true if the host was added successfully,
1073      * false otherwise
1074      */
1075     public boolean updateHostReq(InetAddress networkAddr,
1076                                  byte[] dataLayerAddress, NodeConnector nc,
1077                                  short vlan) {
1078         if (nc == null) {
1079             return false;
1080         }
1081         HostNodeConnector host = null;
1082         try {
1083             host = new HostNodeConnector(dataLayerAddress, networkAddr, nc,
1084                                          vlan);
1085             if (!hostExists(host)) {
1086                 if ((inactiveStaticHosts.get(nc)) != null) {
1087                     inactiveStaticHosts.replace(nc, host);
1088                     return true;
1089                 }
1090                 return false;
1091             }
1092             hostsDB.replace(networkAddr, host);
1093             return true;
1094         } catch (ConstructionException e) {
1095         }
1096         return false;
1097     }
1098
1099     /**
1100      * Remove from the controller IP to MAC binding of a host and its
1101      * connectivity to an openflow switch
1102      *
1103      * @param networkAddr   IP address of the host
1104      *
1105      * @return boolean          true if the host was removed successfully,
1106      * false otherwise
1107      */
1108
1109     public Status removeStaticHostReq(InetAddress networkAddress) {
1110         // Check if host is in active hosts database
1111         HostNodeConnector host = getHostFromOnActiveDB(networkAddress);
1112         if (host != null) {
1113             // Validation check
1114             if (!host.isStaticHost()) {
1115                 return new Status(StatusCode.FORBIDDEN,
1116                                 "Host " + networkAddress.getHostName() + 
1117                                 " is not static");
1118             }
1119             // Remove and notify
1120             notifyHostLearnedOrRemoved(host, false);
1121             removeKnownHost(networkAddress);
1122             return new Status(StatusCode.SUCCESS, null);
1123         }
1124
1125         // Check if host is in inactive hosts database
1126         Entry<NodeConnector, HostNodeConnector> entry = getHostFromInactiveDB(networkAddress);
1127         if (entry != null) {
1128             host = entry.getValue();
1129             // Validation check
1130             if (!host.isStaticHost()) {
1131                 return new Status(StatusCode.FORBIDDEN,
1132                                 "Host " + networkAddress.getHostName() + 
1133                                 " is not static");
1134             }
1135             this.removeHostFromInactiveDB(networkAddress);
1136             return new Status(StatusCode.SUCCESS, null);
1137         }
1138
1139         // Host is neither in active nor inactive hosts database
1140         return new Status(StatusCode.NOTFOUND, "Host does not exist");
1141     }
1142
1143     @Override
1144     public void modeChangeNotify(Node node, boolean proactive) {
1145         logger.debug("Set Switch {} Mode to {}", node.getID(), proactive);
1146     }
1147
1148     @Override
1149     public void notifyNode(Node node, UpdateType type,
1150             Map<String, Property> propMap) {
1151         if (node == null)
1152             return;
1153
1154         switch (type) {
1155         case REMOVED:
1156             long sid = (Long) node.getID();
1157             logger.debug("Received removedSwitch for sw id {}", HexEncode
1158                     .longToHexString(sid));
1159             for (Entry<InetAddress, HostNodeConnector> entry : hostsDB
1160                     .entrySet()) {
1161                 HostNodeConnector host = entry.getValue();
1162                 if (host.getnodeconnectornodeId() == sid) {
1163                     logger.debug("Switch: {} is down, remove from Hosts_DB",
1164                             sid);
1165                     removeKnownHost(entry.getKey());
1166                     notifyHostLearnedOrRemoved(host, false);
1167                 }
1168             }
1169             break;
1170         default:
1171             break;
1172         }
1173     }
1174
1175     @Override
1176     public void notifyNodeConnector(NodeConnector nodeConnector,
1177             UpdateType type, Map<String, Property> propMap) {
1178         if (nodeConnector == null)
1179             return;
1180
1181         boolean up = false;
1182         switch (type) {
1183         case ADDED:
1184             up = true;
1185             break;
1186         case REMOVED:
1187             break;
1188         case CHANGED:
1189             State state = (State) propMap.get(State.StatePropName);
1190             if ((state != null) && (state.getValue() == State.EDGE_UP)) {
1191                 up = true;
1192             }
1193             break;
1194         default:
1195             return;
1196         }
1197
1198         if (up) {
1199             handleNodeConnectorStatusUp(nodeConnector);
1200         } else {
1201             handleNodeConnectorStatusDown(nodeConnector);
1202         }
1203     }
1204
1205     @Override
1206     public Status addStaticHost(String networkAddress, String dataLayerAddress,
1207                                 NodeConnector nc, String vlan) {
1208         try {
1209             InetAddress ip = InetAddress.getByName(networkAddress);
1210             if (nc == null) {
1211                 return new Status(StatusCode.BADREQUEST, "Invalid NodeId");
1212             }
1213             return addStaticHostReq(ip,
1214                                     HexEncode
1215                                     .bytesFromHexString(dataLayerAddress),
1216                                     nc,
1217                     Short.valueOf(vlan));
1218         } catch (UnknownHostException e) {
1219             logger.error("",e);
1220             return new Status(StatusCode.BADREQUEST, "Invalid Address");
1221         }
1222     }
1223
1224     @Override
1225     public Status removeStaticHost(String networkAddress) {
1226         InetAddress address;
1227         try {
1228             address = InetAddress.getByName(networkAddress);
1229             return removeStaticHostReq(address);
1230         } catch (UnknownHostException e) {
1231             logger.error("",e);
1232             return new Status(StatusCode.BADREQUEST, "Invalid Address");
1233         }
1234     }
1235
1236     private void handleNodeConnectorStatusUp(NodeConnector nodeConnector) {
1237         ARPPending arphost;
1238
1239         logger.debug("handleNodeConnectorStatusUp {}", nodeConnector);
1240
1241         for (int i = 0; i < failedARPReqList.size(); i++) {
1242             arphost = failedARPReqList.get(i);
1243             logger.debug("Sending the ARP from FailedARPReqList fors IP: {}",
1244                     arphost.getHostIP().getHostAddress());
1245             hostFinder.find(arphost.getHostIP());
1246         }
1247         HostNodeConnector host = inactiveStaticHosts.get(nodeConnector);
1248         if (host != null) {
1249             inactiveStaticHosts.remove(nodeConnector);
1250             learnNewHost(host);
1251             notifyHostLearnedOrRemoved(host, true);
1252         }
1253     }
1254
1255     private void handleNodeConnectorStatusDown(NodeConnector nodeConnector) {
1256         long sid = (Long) nodeConnector.getNode().getID();
1257         short port = (Short) nodeConnector.getID();
1258
1259         logger.debug("handleNodeConnectorStatusDown {}", nodeConnector);
1260
1261         for (Entry<InetAddress, HostNodeConnector> entry : hostsDB.entrySet()) {
1262             HostNodeConnector host = entry.getValue();
1263             if ((host.getnodeconnectornodeId() == sid)
1264                     && (host.getnodeconnectorportId() == port)) {
1265                 logger.debug(
1266                         "Switch: {}, Port: {} is down, remove from Hosts_DB",
1267                         sid, port);
1268                 removeKnownHost(entry.getKey());
1269                 notifyHostLearnedOrRemoved(host, false);
1270             }
1271         }
1272     }
1273
1274     void setClusterContainerService(IClusterContainerServices s) {
1275         logger.debug("Cluster Service set");
1276         this.clusterContainerService = s;
1277     }
1278
1279     void unsetClusterContainerService(IClusterContainerServices s) {
1280         if (this.clusterContainerService == s) {
1281             logger.debug("Cluster Service removed!");
1282             this.clusterContainerService = null;
1283         }
1284     }
1285
1286     void setSwitchManager(ISwitchManager s) {
1287         logger.debug("SwitchManager set");
1288         this.switchManager = s;
1289     }
1290
1291     void unsetSwitchManager(ISwitchManager s) {
1292         if (this.switchManager == s) {
1293             logger.debug("SwitchManager removed!");
1294             this.switchManager = null;
1295         }
1296     }
1297
1298     public String getContainerName() {
1299         if (containerName == null)
1300             return GlobalConstants.DEFAULT.toString();
1301         return containerName;
1302     }
1303
1304     /**
1305      * Function called by the dependency manager when all the required
1306      * dependencies are satisfied
1307      *
1308      */
1309     void init(Component c) {
1310         Dictionary<?, ?> props = c.getServiceProperties();
1311         if (props != null) {
1312             this.containerName = (String) props.get("containerName");
1313             logger.debug("Running containerName: {}", this.containerName);
1314         } else {
1315             // In the Global instance case the containerName is empty
1316             this.containerName = "";
1317         }
1318         startUp();
1319     }
1320
1321     /**
1322      * Function called by the dependency manager when at least one
1323      * dependency become unsatisfied or when the component is shutting
1324      * down because for example bundle is being stopped.
1325      *
1326      */
1327     void destroy() {
1328         destroyCache();
1329     }
1330
1331     /**
1332      * Function called by dependency manager after "init ()" is called
1333      * and after the services provided by the class are registered in
1334      * the service registry
1335      *
1336      */
1337     void start() {
1338     }
1339
1340     /**
1341      * Function called by the dependency manager before the services
1342      * exported by the component are unregistered, this will be
1343      * followed by a "destroy ()" calls
1344      *
1345      */
1346     void stop() {
1347     }
1348
1349     @Override
1350     public void edgeOverUtilized(Edge edge) {
1351         // TODO Auto-generated method stub
1352
1353     }
1354
1355     @Override
1356     public void edgeUtilBackToNormal(Edge edge) {
1357         // TODO Auto-generated method stub
1358
1359     }
1360
1361 }