Fixing ForwardingRulesManager code that
[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         @SuppressWarnings("deprecation")
960         public void run() {
961             if ((clusterContainerService != null)
962                     && !clusterContainerService.amICoordinator()) {
963                 return;
964             }
965             if ((switchManager != null)
966                     && !switchManager.isHostRefreshEnabled()) {
967                 /*
968                  * The host probe procedure was disabled by CLI
969                  */
970                 return;
971             }
972             if (hostsDB == null) {
973                 /* hostsDB is not allocated yet */
974                 logger
975                         .error("ARPRefreshHandler(): hostsDB is not allocated yet:");
976                 return;
977             }
978             for (Entry<InetAddress, HostNodeConnector> entry : hostsDB
979                     .entrySet()) {
980                 HostNodeConnector host = entry.getValue();
981                 if (host.isStaticHost()) {
982                     /* this host was learned via API3, don't age it out */
983                     continue;
984                 }
985
986                 short arp_cntdown = host.getArpSendCountDown();
987                 arp_cntdown--;
988                 if (arp_cntdown > switchManager.getHostRetryCount()) {
989                     host.setArpSendCountDown(arp_cntdown);
990                 } else if (arp_cntdown <= 0) {
991                     /* No ARP Reply received in last 2 minutes, remove this host and inform applications*/
992                     removeKnownHost(entry.getKey());
993                     notifyHostLearnedOrRemoved(host, false);
994                 } else if (arp_cntdown <= switchManager.getHostRetryCount()) {
995                     /* Use the services of arphandler to check if host is still there */
996                     // logger.info("Probe for Host:{}", host);
997                     //logger.info("ARP Probing ("+arp_cntdown+") for "+host.toString());
998                     logger.trace("ARP Probing ({}) for {}({})", new Object[] {
999                             arp_cntdown,
1000                             host.getNetworkAddress().getHostAddress(),
1001                             HexEncode.bytesToHexString(host
1002                                     .getDataLayerAddressBytes()) });
1003                     host.setArpSendCountDown(arp_cntdown);
1004                     hostFinder.probe(host);
1005                 }
1006             }
1007         }
1008     }
1009
1010     /**
1011      * Inform the controller IP to MAC binding of a host and its
1012      * connectivity to an openflow switch in terms of Node, port, and
1013      * VLAN.
1014      *
1015      * @param networkAddr   IP address of the host
1016      * @param dataLayer         Address MAC address of the host
1017      * @param nc            NodeConnector to which host is connected
1018      * @param port          Port of the switch to which host is connected
1019      * @param vlan          Vlan of which this host is member of
1020      *
1021      * @return Status           The status object as described in {@code Status}
1022      *                                          indicating the result of this action.
1023      */
1024
1025     public Status addStaticHostReq(InetAddress networkAddr,
1026             byte[] dataLayerAddress, NodeConnector nc, short vlan) {
1027         if (dataLayerAddress.length != 6) {
1028                 return new Status(StatusCode.BADREQUEST, "Invalid MAC address");
1029         }
1030
1031         HostNodeConnector host = null;
1032         try {
1033             host = new HostNodeConnector(dataLayerAddress, networkAddr, nc,
1034                                          vlan);
1035             if (hostExists(host)) {
1036                 // This host is already learned either via ARP or through a northbound request
1037                 HostNodeConnector transHost = hostsDB.get(networkAddr);
1038                 transHost.setStaticHost(true);
1039                 return new Status(StatusCode.SUCCESS, null);
1040             }
1041             host.setStaticHost(true);
1042             /*
1043              * Before adding host, Check if the switch and the port have already come up
1044              */
1045             if (switchManager.isNodeConnectorEnabled(nc)) {
1046                 learnNewHost(host);
1047                 notifyHostLearnedOrRemoved(host, true);
1048             } else {
1049                 inactiveStaticHosts.put(nc, host);
1050                 logger
1051                         .debug(
1052                                 "Switch or switchport is not up, adding host {} to inactive list",
1053                                 networkAddr.getHostName());
1054             }
1055             return new Status(StatusCode.SUCCESS, null);
1056         } catch (ConstructionException e) {
1057             return new Status(StatusCode.INTERNALERROR, "Host could not be created");
1058         }
1059
1060     }
1061
1062     /**
1063      * Update the controller IP to MAC binding of a host and its
1064      * connectivity to an openflow switch in terms of
1065      * switch id, switch port, and VLAN.
1066      *
1067      * @param networkAddr   IP address of the host
1068      * @param dataLayer         Address MAC address of the host
1069      * @param nc            NodeConnector to which host is connected
1070      * @param port          Port of the switch to which host is connected
1071      * @param vlan          Vlan of which this host is member of
1072      *
1073      * @return boolean          true if the host was added successfully,
1074      * false otherwise
1075      */
1076     public boolean updateHostReq(InetAddress networkAddr,
1077                                  byte[] dataLayerAddress, NodeConnector nc,
1078                                  short vlan) {
1079         if (nc == null) {
1080             return false;
1081         }
1082         HostNodeConnector host = null;
1083         try {
1084             host = new HostNodeConnector(dataLayerAddress, networkAddr, nc,
1085                                          vlan);
1086             if (!hostExists(host)) {
1087                 if ((inactiveStaticHosts.get(nc)) != null) {
1088                     inactiveStaticHosts.replace(nc, host);
1089                     return true;
1090                 }
1091                 return false;
1092             }
1093             hostsDB.replace(networkAddr, host);
1094             return true;
1095         } catch (ConstructionException e) {
1096         }
1097         return false;
1098     }
1099
1100     /**
1101      * Remove from the controller IP to MAC binding of a host and its
1102      * connectivity to an openflow switch
1103      *
1104      * @param networkAddr   IP address of the host
1105      *
1106      * @return boolean          true if the host was removed successfully,
1107      * false otherwise
1108      */
1109
1110     public Status removeStaticHostReq(InetAddress networkAddress) {
1111         // Check if host is in active hosts database
1112         HostNodeConnector host = getHostFromOnActiveDB(networkAddress);
1113         if (host != null) {
1114             // Validation check
1115             if (!host.isStaticHost()) {
1116                 return new Status(StatusCode.FORBIDDEN,
1117                                 "Host " + networkAddress.getHostName() + 
1118                                 " is not static");
1119             }
1120             // Remove and notify
1121             notifyHostLearnedOrRemoved(host, false);
1122             removeKnownHost(networkAddress);
1123             return new Status(StatusCode.SUCCESS, null);
1124         }
1125
1126         // Check if host is in inactive hosts database
1127         Entry<NodeConnector, HostNodeConnector> entry = getHostFromInactiveDB(networkAddress);
1128         if (entry != null) {
1129             host = entry.getValue();
1130             // Validation check
1131             if (!host.isStaticHost()) {
1132                 return new Status(StatusCode.FORBIDDEN,
1133                                 "Host " + networkAddress.getHostName() + 
1134                                 " is not static");
1135             }
1136             this.removeHostFromInactiveDB(networkAddress);
1137             return new Status(StatusCode.SUCCESS, null);
1138         }
1139
1140         // Host is neither in active nor inactive hosts database
1141         return new Status(StatusCode.NOTFOUND, "Host does not exist");
1142     }
1143
1144     @Override
1145     public void modeChangeNotify(Node node, boolean proactive) {
1146         logger.debug("Set Switch {} Mode to {}", node.getID(), proactive);
1147     }
1148
1149     @Override
1150     public void notifyNode(Node node, UpdateType type,
1151             Map<String, Property> propMap) {
1152         if (node == null)
1153             return;
1154
1155         switch (type) {
1156         case REMOVED:
1157             long sid = (Long) node.getID();
1158             logger.debug("Received removedSwitch for sw id {}", HexEncode
1159                     .longToHexString(sid));
1160             for (Entry<InetAddress, HostNodeConnector> entry : hostsDB
1161                     .entrySet()) {
1162                 HostNodeConnector host = entry.getValue();
1163                 if (host.getnodeconnectornodeId() == sid) {
1164                     logger.debug("Switch: {} is down, remove from Hosts_DB",
1165                             sid);
1166                     removeKnownHost(entry.getKey());
1167                     notifyHostLearnedOrRemoved(host, false);
1168                 }
1169             }
1170             break;
1171         default:
1172             break;
1173         }
1174     }
1175
1176     @Override
1177     public void notifyNodeConnector(NodeConnector nodeConnector,
1178             UpdateType type, Map<String, Property> propMap) {
1179         if (nodeConnector == null)
1180             return;
1181
1182         boolean up = false;
1183         switch (type) {
1184         case ADDED:
1185             up = true;
1186             break;
1187         case REMOVED:
1188             break;
1189         case CHANGED:
1190             State state = (State) propMap.get(State.StatePropName);
1191             if ((state != null) && (state.getValue() == State.EDGE_UP)) {
1192                 up = true;
1193             }
1194             break;
1195         default:
1196             return;
1197         }
1198
1199         if (up) {
1200             handleNodeConnectorStatusUp(nodeConnector);
1201         } else {
1202             handleNodeConnectorStatusDown(nodeConnector);
1203         }
1204     }
1205
1206     @Override
1207     public Status addStaticHost(String networkAddress, String dataLayerAddress,
1208                                 NodeConnector nc, String vlan) {
1209         try {
1210             InetAddress ip = InetAddress.getByName(networkAddress);
1211             if (nc == null) {
1212                 return new Status(StatusCode.BADREQUEST, "Invalid NodeId");
1213             }
1214             return addStaticHostReq(ip,
1215                                     HexEncode
1216                                     .bytesFromHexString(dataLayerAddress),
1217                                     nc,
1218                     Short.valueOf(vlan));
1219         } catch (UnknownHostException e) {
1220             logger.error("",e);
1221             return new Status(StatusCode.BADREQUEST, "Invalid Address");
1222         }
1223     }
1224
1225     @Override
1226     public Status removeStaticHost(String networkAddress) {
1227         InetAddress address;
1228         try {
1229             address = InetAddress.getByName(networkAddress);
1230             return removeStaticHostReq(address);
1231         } catch (UnknownHostException e) {
1232             logger.error("",e);
1233             return new Status(StatusCode.BADREQUEST, "Invalid Address");
1234         }
1235     }
1236
1237     private void handleNodeConnectorStatusUp(NodeConnector nodeConnector) {
1238         ARPPending arphost;
1239
1240         logger.debug("handleNodeConnectorStatusUp {}", nodeConnector);
1241
1242         for (int i = 0; i < failedARPReqList.size(); i++) {
1243             arphost = failedARPReqList.get(i);
1244             logger.debug("Sending the ARP from FailedARPReqList fors IP: {}",
1245                     arphost.getHostIP().getHostAddress());
1246             hostFinder.find(arphost.getHostIP());
1247         }
1248         HostNodeConnector host = inactiveStaticHosts.get(nodeConnector);
1249         if (host != null) {
1250             inactiveStaticHosts.remove(nodeConnector);
1251             learnNewHost(host);
1252             notifyHostLearnedOrRemoved(host, true);
1253         }
1254     }
1255
1256     private void handleNodeConnectorStatusDown(NodeConnector nodeConnector) {
1257         long sid = (Long) nodeConnector.getNode().getID();
1258         short port = (Short) nodeConnector.getID();
1259
1260         logger.debug("handleNodeConnectorStatusDown {}", nodeConnector);
1261
1262         for (Entry<InetAddress, HostNodeConnector> entry : hostsDB.entrySet()) {
1263             HostNodeConnector host = entry.getValue();
1264             if ((host.getnodeconnectornodeId() == sid)
1265                     && (host.getnodeconnectorportId() == port)) {
1266                 logger.debug(
1267                         "Switch: {}, Port: {} is down, remove from Hosts_DB",
1268                         sid, port);
1269                 removeKnownHost(entry.getKey());
1270                 notifyHostLearnedOrRemoved(host, false);
1271             }
1272         }
1273     }
1274
1275     void setClusterContainerService(IClusterContainerServices s) {
1276         logger.debug("Cluster Service set");
1277         this.clusterContainerService = s;
1278     }
1279
1280     void unsetClusterContainerService(IClusterContainerServices s) {
1281         if (this.clusterContainerService == s) {
1282             logger.debug("Cluster Service removed!");
1283             this.clusterContainerService = null;
1284         }
1285     }
1286
1287     void setSwitchManager(ISwitchManager s) {
1288         logger.debug("SwitchManager set");
1289         this.switchManager = s;
1290     }
1291
1292     void unsetSwitchManager(ISwitchManager s) {
1293         if (this.switchManager == s) {
1294             logger.debug("SwitchManager removed!");
1295             this.switchManager = null;
1296         }
1297     }
1298
1299     public String getContainerName() {
1300         if (containerName == null)
1301             return GlobalConstants.DEFAULT.toString();
1302         return containerName;
1303     }
1304
1305     /**
1306      * Function called by the dependency manager when all the required
1307      * dependencies are satisfied
1308      *
1309      */
1310     void init(Component c) {
1311         Dictionary<?, ?> props = c.getServiceProperties();
1312         if (props != null) {
1313             this.containerName = (String) props.get("containerName");
1314             logger.debug("Running containerName: {}", this.containerName);
1315         } else {
1316             // In the Global instance case the containerName is empty
1317             this.containerName = "";
1318         }
1319         startUp();
1320     }
1321
1322     /**
1323      * Function called by the dependency manager when at least one
1324      * dependency become unsatisfied or when the component is shutting
1325      * down because for example bundle is being stopped.
1326      *
1327      */
1328     void destroy() {
1329         destroyCache();
1330     }
1331
1332     /**
1333      * Function called by dependency manager after "init ()" is called
1334      * and after the services provided by the class are registered in
1335      * the service registry
1336      *
1337      */
1338     void start() {
1339     }
1340
1341     /**
1342      * Function called by the dependency manager before the services
1343      * exported by the component are unregistered, this will be
1344      * followed by a "destroy ()" calls
1345      *
1346      */
1347     void stop() {
1348     }
1349
1350     @Override
1351     public void edgeOverUtilized(Edge edge) {
1352         // TODO Auto-generated method stub
1353
1354     }
1355
1356     @Override
1357     public void edgeUtilBackToNormal(Edge edge) {
1358         // TODO Auto-generated method stub
1359
1360     }
1361
1362 }