2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.hosttracker.internal;
11 import java.net.InetAddress;
12 import java.net.UnknownHostException;
13 import java.util.ArrayList;
14 import java.util.Collections;
15 import java.util.Dictionary;
16 import java.util.EnumSet;
17 import java.util.HashSet;
18 import java.util.List;
20 import java.util.Map.Entry;
22 import java.util.Timer;
23 import java.util.TimerTask;
24 import java.util.concurrent.Callable;
25 import java.util.concurrent.ConcurrentHashMap;
26 import java.util.concurrent.ConcurrentMap;
27 import java.util.concurrent.CopyOnWriteArraySet;
28 import java.util.concurrent.ExecutorService;
29 import java.util.concurrent.Executors;
30 import java.util.concurrent.Future;
32 import org.apache.felix.dm.Component;
33 import org.eclipse.osgi.framework.console.CommandInterpreter;
34 import org.eclipse.osgi.framework.console.CommandProvider;
35 import org.opendaylight.controller.clustering.services.CacheConfigException;
36 import org.opendaylight.controller.clustering.services.CacheExistException;
37 import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
38 import org.opendaylight.controller.clustering.services.IClusterContainerServices;
39 import org.opendaylight.controller.clustering.services.IClusterServices;
40 import org.opendaylight.controller.hosttracker.HostIdFactory;
41 import org.opendaylight.controller.hosttracker.IHostId;
42 import org.opendaylight.controller.hosttracker.IPHostId;
43 import org.opendaylight.controller.hosttracker.IPMacHostId;
44 import org.opendaylight.controller.hosttracker.IfHostListener;
45 import org.opendaylight.controller.hosttracker.IfIptoHost;
46 import org.opendaylight.controller.hosttracker.IfNewHostNotify;
47 import org.opendaylight.controller.hosttracker.hostAware.HostNodeConnector;
48 import org.opendaylight.controller.hosttracker.hostAware.IHostFinder;
49 import org.opendaylight.controller.sal.core.ConstructionException;
50 import org.opendaylight.controller.sal.core.Edge;
51 import org.opendaylight.controller.sal.core.Host;
52 import org.opendaylight.controller.sal.core.Node;
53 import org.opendaylight.controller.sal.core.NodeConnector;
54 import org.opendaylight.controller.sal.core.Property;
55 import org.opendaylight.controller.sal.core.State;
56 import org.opendaylight.controller.sal.core.Tier;
57 import org.opendaylight.controller.sal.core.UpdateType;
58 import org.opendaylight.controller.sal.packet.address.DataLinkAddress;
59 import org.opendaylight.controller.sal.packet.address.EthernetAddress;
60 import org.opendaylight.controller.sal.topology.TopoEdgeUpdate;
61 import org.opendaylight.controller.sal.utils.GlobalConstants;
62 import org.opendaylight.controller.sal.utils.HexEncode;
63 import org.opendaylight.controller.sal.utils.NetUtils;
64 import org.opendaylight.controller.sal.utils.NodeCreator;
65 import org.opendaylight.controller.sal.utils.Status;
66 import org.opendaylight.controller.sal.utils.StatusCode;
67 import org.opendaylight.controller.switchmanager.IInventoryListener;
68 import org.opendaylight.controller.switchmanager.ISwitchManager;
69 import org.opendaylight.controller.switchmanager.ISwitchManagerAware;
70 import org.opendaylight.controller.switchmanager.Subnet;
71 import org.opendaylight.controller.topologymanager.ITopologyManager;
72 import org.opendaylight.controller.topologymanager.ITopologyManagerAware;
73 import org.osgi.framework.BundleContext;
74 import org.osgi.framework.FrameworkUtil;
75 import org.slf4j.Logger;
76 import org.slf4j.LoggerFactory;
79 * @file HostTracker.java This class tracks the location of IP Hosts as to which
80 * Switch, Port, VLAN, they are connected to, as well as their MAC
81 * address. This is done dynamically as well as statically. The dynamic
82 * mechanism consists of listening to ARP messages as well sending ARP
83 * requests. Static mechanism consists of Northbound APIs to add or remove
84 * the hosts from the local database. ARP aging is also implemented to age
85 * out dynamically learned hosts. Interface methods are provided for other
86 * applications to 1. Query the local database for a single host 2. Get a
87 * list of all hosts 3. Get notification if a host is learned/added or
88 * removed the database
93 * HostTracker db key scheme implementation support. Support has been added for
94 * IP only or IP + MAC scheme as of now. User can use either of the schemes
95 * based on the configuration done in config.ini file. By default IP only key
96 * scheme is choosen. The attribute to be set in config.ini is
97 * hosttracker.keyscheme. It could have a value of 0 or 1 as of now. 0 is for IP
98 * only scheme. 1 is for IP + MAC scheme.
103 public class HostTracker implements IfIptoHost, IfHostListener, ISwitchManagerAware, IInventoryListener,
104 ITopologyManagerAware, ICacheUpdateAware<IHostId, HostNodeConnector>, CommandProvider {
105 static final String ACTIVE_HOST_CACHE = "hosttracker.ActiveHosts";
106 static final String INACTIVE_HOST_CACHE = "hosttracker.InactiveHosts";
107 private static final Logger logger = LoggerFactory.getLogger(HostTracker.class);
108 protected final Set<IHostFinder> hostFinder = new CopyOnWriteArraySet<IHostFinder>();;
109 protected ConcurrentMap<IHostId, HostNodeConnector> hostsDB;
111 * Following is a list of hosts which have been requested by NB APIs to be
112 * added, but either the switch or the port is not sup, so they will be
113 * added here until both come up
115 private ConcurrentMap<NodeConnector, HostNodeConnector> inactiveStaticHosts;
116 private final Set<IfNewHostNotify> newHostNotify = Collections.synchronizedSet(new HashSet<IfNewHostNotify>());
118 private ITopologyManager topologyManager;
119 protected IClusterContainerServices clusterContainerService = null;
120 protected ISwitchManager switchManager = null;
122 private Timer arpRefreshTimer;
123 private String containerName = null;
124 private ExecutorService executor;
125 protected boolean stopping;
126 private static boolean hostRefresh = true;
127 private static int hostRetryCount = 5;
128 private String keyScheme = null;
130 private static class ARPPending {
131 protected IHostId hostId;
132 protected short sent_count;
133 protected HostTrackerCallable hostTrackerCallable;
135 public IHostId getHostId() {
139 public short getSent_count() {
143 public HostTrackerCallable getHostTrackerCallable() {
144 return hostTrackerCallable;
147 public void setHostId(IHostId id) {
151 public void setSent_count(short count) {
152 this.sent_count = count;
155 public void setHostTrackerCallable(HostTrackerCallable callable) {
156 hostTrackerCallable = callable;
160 // This list contains the hosts for which ARP requests are being sent
162 ConcurrentMap<IHostId, ARPPending> ARPPendingList;
164 * This list below contains the hosts which were initially in ARPPendingList
165 * above, but ARP response didn't come from there hosts after multiple
166 * attempts over 8 seconds. The assumption is that the response didn't come
167 * back due to one of the following possibilities: 1. The L3 interface
168 * wasn't created for this host in the controller. This would cause
169 * arphandler not to know where to send the ARP 2. The host facing port is
170 * down 3. The IP host doesn't exist or is not responding to ARP requests
172 * Conditions 1 and 2 above can be recovered if ARP is sent when the
173 * relevant L3 interface is added or the port facing host comes up. Whenever
174 * L3 interface is added or host facing port comes up, ARP will be sent to
175 * hosts in this list.
177 * We can't recover from condition 3 above
179 ConcurrentMap<IHostId, ARPPending> failedARPReqList;
181 public HostTracker() {
184 private void startUp() {
185 nonClusterObjectCreate();
191 timer.schedule(new OutStandingARPHandler(), 4000, 4000);
192 executor = Executors.newFixedThreadPool(2);
193 /* ARP Refresh Timer to go off every 5 seconds to implement ARP aging */
194 arpRefreshTimer = new Timer();
195 arpRefreshTimer.schedule(new ARPRefreshHandler(), 5000, 5000);
196 keyScheme = HostIdFactory.getScheme();
197 logger.debug("startUp: Caches created, timers started");
200 private void allocateCache() {
201 if (this.clusterContainerService == null) {
202 logger.error("un-initialized clusterContainerService, can't create cache");
205 logger.debug("Creating Cache for HostTracker");
207 this.clusterContainerService.createCache(ACTIVE_HOST_CACHE,
208 EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
209 this.clusterContainerService.createCache(INACTIVE_HOST_CACHE,
210 EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
211 } catch (CacheConfigException cce) {
212 logger.error("Cache couldn't be created for HostTracker - check cache mode");
213 } catch (CacheExistException cce) {
214 logger.error("Cache for HostTracker already exists, destroy and recreate");
216 logger.debug("Cache successfully created for HostTracker");
219 @SuppressWarnings({ "unchecked" })
220 private void retrieveCache() {
221 if (this.clusterContainerService == null) {
222 logger.error("un-initialized clusterContainerService, can't retrieve cache");
225 logger.debug("Retrieving cache for HostTrackerAH");
226 hostsDB = (ConcurrentMap<IHostId, HostNodeConnector>) this.clusterContainerService.getCache(ACTIVE_HOST_CACHE);
227 if (hostsDB == null) {
228 logger.error("Cache couldn't be retrieved for HostTracker");
230 logger.debug("Cache was successfully retrieved for HostTracker");
231 logger.debug("Retrieving cache for HostTrackerIH");
232 inactiveStaticHosts = (ConcurrentMap<NodeConnector, HostNodeConnector>) this.clusterContainerService
233 .getCache(INACTIVE_HOST_CACHE);
234 if (inactiveStaticHosts == null) {
235 logger.error("Cache couldn't be retrieved for HostTrackerIH");
237 logger.debug("Cache was successfully retrieved for HostTrackerIH");
240 public void nonClusterObjectCreate() {
241 hostsDB = new ConcurrentHashMap<IHostId, HostNodeConnector>();
242 inactiveStaticHosts = new ConcurrentHashMap<NodeConnector, HostNodeConnector>();
243 ARPPendingList = new ConcurrentHashMap<IHostId, ARPPending>();
244 failedARPReqList = new ConcurrentHashMap<IHostId, ARPPending>();
247 public void shutDown() {
250 public void setnewHostNotify(IfNewHostNotify obj) {
251 this.newHostNotify.add(obj);
254 public void unsetnewHostNotify(IfNewHostNotify obj) {
255 this.newHostNotify.remove(obj);
258 public void setArpHandler(IHostFinder hostFinder) {
259 if (this.hostFinder != null) {
260 this.hostFinder.add(hostFinder);
264 public void unsetArpHandler(IHostFinder hostFinder) {
265 if (this.hostFinder != null) {
266 logger.debug("Arp Handler Service removed!");
267 this.hostFinder.remove(hostFinder);
271 public void setTopologyManager(ITopologyManager s) {
272 this.topologyManager = s;
275 public void unsetTopologyManager(ITopologyManager s) {
276 if (this.topologyManager == s) {
277 logger.debug("Topology Manager Service removed!");
278 this.topologyManager = null;
282 private boolean hostExists(HostNodeConnector host) {
283 IHostId id = HostIdFactory.create(host.getNetworkAddress(), host.getDataLayerAddress());
284 HostNodeConnector lhost = hostsDB.get(id);
285 return host.equals(lhost);
288 private HostNodeConnector getHostFromOnActiveDB(IHostId id) {
289 return hostsDB.get(id);
292 private Entry<NodeConnector, HostNodeConnector> getHostFromInactiveDB(IHostId id) {
293 for (Entry<NodeConnector, HostNodeConnector> entry : inactiveStaticHosts.entrySet()) {
294 HostNodeConnector hnc = entry.getValue();
295 IHostId cmpId = HostIdFactory.create(hnc.getNetworkAddress(), hnc.getDataLayerAddress());
296 if (cmpId.equals(id)) {
297 logger.debug("getHostFromInactiveDB(): Inactive Host found for ID:{} ", decodeIPFromId(id));
301 logger.debug("getHostFromInactiveDB() Inactive Host Not found for ID: {}", decodeIPFromId(id));
305 private void removeHostFromInactiveDB(IHostId id) {
306 NodeConnector nodeConnector = null;
307 for (Entry<NodeConnector, HostNodeConnector> entry : inactiveStaticHosts.entrySet()) {
308 HostNodeConnector hnc = entry.getValue();
309 IHostId cmpId = HostIdFactory.create(hnc.getNetworkAddress(), hnc.getDataLayerAddress());
310 if (cmpId.equals(id)) {
311 nodeConnector = entry.getKey();
315 if (nodeConnector != null) {
316 inactiveStaticHosts.remove(nodeConnector);
317 logger.debug("removeHostFromInactiveDB(): Host Removed for IP: {}", decodeIPFromId(id));
320 logger.debug("removeHostFromInactiveDB(): Host Not found for IP: {}", decodeIPFromId(id));
323 protected boolean hostMoved(HostNodeConnector host) {
324 IHostId id = HostIdFactory.create(host.getNetworkAddress(), host.getDataLayerAddress());
325 if (hostQuery(id) != null) {
332 public HostNodeConnector hostQuery(IHostId id) {
333 return hostsDB.get(id);
337 public Future<HostNodeConnector> discoverHost(IHostId id) {
338 if (executor == null) {
339 logger.debug("discoverHost: Null executor");
342 Callable<HostNodeConnector> worker = new HostTrackerCallable(this, id);
343 Future<HostNodeConnector> submit = executor.submit(worker);
348 public HostNodeConnector hostFind(IHostId id) {
350 * Sometimes at boot with containers configured in the startup we hit
351 * this path (from TIF) when hostFinder has not been set yet Caller
352 * already handles the null return
355 if (hostFinder == null) {
356 logger.debug("Exiting hostFind, null hostFinder");
360 HostNodeConnector host = hostQuery(id);
362 logger.debug("hostFind(): Host found for IP: {}", id);
366 /* Add this host to ARPPending List for any potential retries */
368 addToARPPendingList(id);
369 logger.debug("hostFind(): Host Not Found for IP: {}, Inititated Host Discovery ...", id);
371 /* host is not found, initiate a discovery */
372 for (IHostFinder hf : hostFinder) {
373 InetAddress addr = decodeIPFromId(id);
380 public Set<HostNodeConnector> getAllHosts() {
381 Set<HostNodeConnector> allHosts = new HashSet<HostNodeConnector>(hostsDB.values());
386 public Set<HostNodeConnector> getActiveStaticHosts() {
387 Set<HostNodeConnector> list = new HashSet<HostNodeConnector>();
388 for (Entry<IHostId, HostNodeConnector> entry : hostsDB.entrySet()) {
389 HostNodeConnector host = entry.getValue();
390 if (host.isStaticHost()) {
398 public Set<HostNodeConnector> getInactiveStaticHosts() {
399 Set<HostNodeConnector> list = new HashSet<HostNodeConnector>(inactiveStaticHosts.values());
403 private void addToARPPendingList(IHostId id) {
404 ARPPending arphost = new ARPPending();
406 arphost.setHostId(id);
407 arphost.setSent_count((short) 1);
408 ARPPendingList.put(id, arphost);
409 logger.debug("Host Added to ARPPending List, IP: {}", decodeIPFromId(id));
413 public void setCallableOnPendingARP(IHostId id, HostTrackerCallable callable) {
415 for (Entry<IHostId, ARPPending> entry : ARPPendingList.entrySet()) {
416 arphost = entry.getValue();
417 if (arphost.getHostId().equals(id)) {
418 arphost.setHostTrackerCallable(callable);
423 private void processPendingARPReqs(IHostId id) {
426 if ((arphost = ARPPendingList.remove(id)) != null) {
427 // Remove the arphost from ARPPendingList as it has been learned now
428 logger.debug("Host Removed from ARPPending List, IP: {}", id);
429 HostTrackerCallable htCallable = arphost.getHostTrackerCallable();
430 if (htCallable != null) {
437 * It could have been a host from the FailedARPReqList
440 if (failedARPReqList.containsKey(id)) {
441 failedARPReqList.remove(id);
442 logger.debug("Host Removed from FailedARPReqList List, IP: {}", decodeIPFromId(id));
447 private void learnNewHost(HostNodeConnector host) {
448 IHostId id = HostIdFactory.create(host.getNetworkAddress(), host.getDataLayerAddress());
449 host.initArpSendCountDown();
450 HostNodeConnector rHost = hostsDB.putIfAbsent(id, host);
452 // Another host is already learned for this IP address, replace it
453 replaceHost(id, rHost, host);
455 logger.debug("New Host Learned: MAC: {} IP: {}", HexEncode.bytesToHexString(host
456 .getDataLayerAddressBytes()), host.getNetworkAddress().getHostAddress());
460 private void replaceHost(IHostId id, HostNodeConnector removedHost, HostNodeConnector newHost) {
461 // Ignore ARP messages from internal nodes
462 NodeConnector newHostNc = newHost.getnodeConnector();
463 boolean newHostIsInternal = topologyManager.isInternal(newHostNc);
464 if (newHostIsInternal) {
468 newHost.initArpSendCountDown();
470 if (hostsDB.replace(id, removedHost, newHost)) {
471 logger.debug("Host move occurred: Old Host IP:{}, New Host IP: {}", removedHost.getNetworkAddress()
472 .getHostAddress(), newHost.getNetworkAddress().getHostAddress());
473 logger.debug("Old Host MAC: {}, New Host MAC: {}",
474 HexEncode.bytesToHexString(removedHost.getDataLayerAddressBytes()),
475 HexEncode.bytesToHexString(newHost.getDataLayerAddressBytes()));
476 // Display the Old and New HostNodeConnectors also
477 logger.debug("Old {}, New {}", removedHost, newHost);
480 * Host replacement has failed, do the recovery
482 hostsDB.put(id, newHost);
483 logger.error("Host replacement failed. Overwrite the host. Replaced Host: {}, New Host: {}", removedHost,
486 notifyHostLearnedOrRemoved(removedHost, false);
487 notifyHostLearnedOrRemoved(newHost, true);
488 if (!newHost.isStaticHost()) {
489 processPendingARPReqs(id);
494 private void removeKnownHost(IHostId key) {
495 HostNodeConnector host = hostsDB.get(key);
497 logger.debug("Removing Host: IP:{}", host.getNetworkAddress().getHostAddress());
500 logger.error("removeKnownHost(): Host for IP address {} not found in hostsDB", decodeIPFromId(key));
504 private class NotifyHostThread extends Thread {
506 private final HostNodeConnector host;
508 public NotifyHostThread(HostNodeConnector h) {
514 HostNodeConnector removedHost = null;
515 InetAddress networkAddr = host.getNetworkAddress();
516 IHostId id = HostIdFactory.create(networkAddr, host.getDataLayerAddress());
517 /* Check for Host Move case */
518 if (hostMoved(host)) {
520 * Host has been moved from one location (switch,port, MAC, or
521 * VLAN) to another. Replace the existing host and its previous
522 * location parameters with new information, and notify the
523 * applications listening to host move.
526 removedHost = hostsDB.get(id);
527 if (removedHost != null) {
528 replaceHost(id, removedHost, host);
531 logger.error("Host to be removed not found in hostsDB");
538 /* check if there is an outstanding request for this host */
539 processPendingARPReqs(id);
540 notifyHostLearnedOrRemoved(host, true);
545 public void hostListener(HostNodeConnector host) {
546 logger.debug("Received for Host: IP {}, MAC {}, {}", host.getNetworkAddress().getHostAddress(),
547 HexEncode.bytesToHexString(host.getDataLayerAddressBytes()), host);
548 if (hostExists(host)) {
549 IHostId id = HostIdFactory.create(host.getNetworkAddress(), host.getDataLayerAddress());
550 HostNodeConnector existinghost = hostsDB.get(id);
551 existinghost.initArpSendCountDown();
554 hostsDB.put(id, existinghost);
555 logger.debug("hostListener returned without adding the host");
558 new NotifyHostThread(host).start();
561 // Notify whoever is interested that a new host was learned (dynamically or
563 private void notifyHostLearnedOrRemoved(HostNodeConnector host, boolean add) {
564 // Update listeners if any
565 if (newHostNotify != null) {
566 logger.debug("Notifying Applications for Host {} Being {}", host.getNetworkAddress().getHostAddress(),
567 add ? "Added" : "Deleted");
568 synchronized (this.newHostNotify) {
569 for (IfNewHostNotify ta : newHostNotify) {
572 ta.notifyHTClient(host);
574 ta.notifyHTClientHostRemoved(host);
576 } catch (Exception e) {
577 logger.error("Exception on new host notification", e);
582 logger.error("notifyHostLearnedOrRemoved(): New host notify is null");
585 // Topology update is for some reason outside of listeners registry
587 Node node = host.getnodeconnectorNode();
589 NodeConnector p = host.getnodeConnector();
591 DataLinkAddress dla = new EthernetAddress(host.getDataLayerAddressBytes());
592 h = new Host(dla, host.getNetworkAddress());
593 } catch (ConstructionException ce) {
598 if (topologyManager != null && p != null && h != null) {
599 logger.debug("Notifying Topology Manager for Host {} Being {}", h.getNetworkAddress().getHostAddress(),
600 add ? "Added" : "Deleted");
602 Tier tier = new Tier(1);
603 switchManager.setNodeProp(node, tier);
604 topologyManager.updateHostLink(p, h, UpdateType.ADDED, null);
606 // No need to reset the tiering if no other hosts are currently
608 // If this switch was discovered to be an access switch, it
609 // still is even if the host is down
610 Tier tier = new Tier(0);
611 switchManager.setNodeProp(node, tier);
612 topologyManager.updateHostLink(p, h, UpdateType.REMOVED, null);
618 * When a new Host is learnt by the hosttracker module, it places the
619 * directly connected Node in Tier-1 & using this function, updates the Tier
620 * value for all other Nodes in the network hierarchy.
622 * This is a recursive function and it takes care of updating the Tier value
623 * for all the connected and eligible Nodes.
626 * Node that represents one of the Vertex in the Topology Graph.
628 * The Tier on which n belongs
630 @SuppressWarnings("unused")
631 private void updateSwitchTiers(Node n, int currentTier) {
632 Map<Node, Set<Edge>> ndlinks = topologyManager.getNodeEdges();
633 if (ndlinks == null) {
634 logger.debug("updateSwitchTiers(): ndlinks null for Node: {}, Tier:{}", n, currentTier);
637 Set<Edge> links = ndlinks.get(n);
639 logger.debug("updateSwitchTiers(): links null for ndlinks:{}", ndlinks);
642 ArrayList<Node> needsVisiting = new ArrayList<Node>();
643 for (Edge lt : links) {
644 if (!lt.getHeadNodeConnector().getType().equals(NodeConnector.NodeConnectorIDType.OPENFLOW)) {
645 // We don't want to work on Node that are not openflow
649 Node dstNode = lt.getHeadNodeConnector().getNode();
650 if (switchNeedsTieringUpdate(dstNode, currentTier + 1)) {
651 Tier t = new Tier(currentTier + 1);
652 switchManager.setNodeProp(dstNode, t);
653 needsVisiting.add(dstNode);
658 * Due to the nature of the problem, having a separate loop for nodes
659 * that needs visiting provides a decent walk optimization.
661 for (Node node : needsVisiting) {
662 updateSwitchTiers(node, currentTier + 1);
667 * Internal convenience routine to check the eligibility of a Switch for a
668 * Tier update. Any Node with Tier=0 or a Tier value that is greater than
669 * the new Tier Value is eligible for the update.
672 * Node for which the Tier update eligibility is checked
675 * @return <code>true</code> if the Node is eligible for Tier Update
676 * <code>false</code> otherwise
679 private boolean switchNeedsTieringUpdate(Node n, int tier) {
681 logger.error("switchNeedsTieringUpdate(): Null node for tier: {}", tier);
685 * Node could have gone down
687 if (!switchManager.getNodes().contains(n)) {
690 // This is the case where Tier was never set for this node
691 Tier t = (Tier) switchManager.getNodeProp(n, Tier.TierPropName);
695 if (t.getValue() == 0) {
697 } else if (t.getValue() > tier) {
704 * Internal convenience routine to clear all the Tier values to 0. This
705 * cleanup is performed during cases such as Topology Change where the
706 * existing Tier values might become incorrect
708 @SuppressWarnings("unused")
709 private void clearTiers() {
710 Set<Node> nodes = null;
711 if (switchManager == null) {
712 logger.error("clearTiers(): Null switchManager");
715 nodes = switchManager.getNodes();
717 for (Node n : nodes) {
718 Tier t = new Tier(0);
719 switchManager.setNodeProp(n, t);
724 * Internal convenience routine to print the hierarchies of switches.
726 @SuppressWarnings("unused")
727 private void logHierarchies(ArrayList<ArrayList<String>> hierarchies) {
728 String hierarchyString = null;
730 for (ArrayList<String> hierarchy : hierarchies) {
731 StringBuffer buf = new StringBuffer();
732 buf.append("Hierarchy#").append(num).append(" : ");
733 for (String switchName : hierarchy) {
734 buf.append(switchName).append("/");
736 logger.debug("{} -> {}", getContainerName(), buf);
742 * getHostNetworkHierarchy is the Back-end routine for the North-Bound API
743 * that returns the Network Hierarchy for a given Host. This API is
744 * typically used by applications like Hadoop for Rack Awareness
748 * IP-Address of the host/node.
749 * @return Network Hierarchies represented by an Array of Array (of
750 * Switch-Ids as String).
753 public List<List<String>> getHostNetworkHierarchy(IHostId id) {
754 HostNodeConnector host = hostQuery(id);
759 List<List<String>> hierarchies = new ArrayList<List<String>>();
760 ArrayList<String> currHierarchy = new ArrayList<String>();
761 hierarchies.add(currHierarchy);
763 Node node = host.getnodeconnectorNode();
764 updateCurrentHierarchy(node, currHierarchy, hierarchies);
769 * dpidToHostNameHack is a hack function for Cisco Live Hadoop Demo. Mininet
770 * is used as the network for Hadoop Demos & in order to give a meaningful
771 * rack-awareness switch names, the DPID is organized in ASCII Characters
772 * and retrieved as string.
776 * @return Ascii String represented by the DPID.
778 private String dpidToHostNameHack(long dpid) {
779 String hex = Long.toHexString(dpid);
781 StringBuffer sb = new StringBuffer();
783 for (int i = 0; i < hex.length(); i++) {
784 result = (int) ((dpid >> (i * 8)) & 0xff);
791 sb.append(String.format("%c", result));
793 return sb.reverse().toString();
797 * A convenient recursive routine to obtain the Hierarchy of Switches.
800 * Current Node in the Recursive routine.
801 * @param currHierarchy
802 * Array of Nodes that make this hierarchy on which the Current
804 * @param fullHierarchy
805 * Array of multiple Hierarchies that represent a given host.
807 @SuppressWarnings("unchecked")
808 private void updateCurrentHierarchy(Node node, ArrayList<String> currHierarchy, List<List<String>> fullHierarchy) {
809 currHierarchy.add(dpidToHostNameHack((Long) node.getID()));
810 // Shallow copy as required
811 ArrayList<String> currHierarchyClone = (ArrayList<String>) currHierarchy.clone();
813 Map<Node, Set<Edge>> ndlinks = topologyManager.getNodeEdges();
814 if (ndlinks == null) {
815 logger.debug("updateCurrentHierarchy(): topologyManager returned null ndlinks for node: {}", node);
818 Node n = NodeCreator.createOFNode((Long) node.getID());
819 Set<Edge> links = ndlinks.get(n);
821 logger.debug("updateCurrentHierarchy(): Null links for ndlinks");
824 for (Edge lt : links) {
825 if (!lt.getHeadNodeConnector().getType().equals(NodeConnector.NodeConnectorIDType.OPENFLOW)) {
826 // We don't want to work on Node that are not openflow
830 Node dstNode = lt.getHeadNodeConnector().getNode();
832 Tier nodeTier = (Tier) switchManager.getNodeProp(node, Tier.TierPropName);
834 * If the host is directly attached to the src node, then the node
835 * should have been assigned the "Access" tier in
836 * notifyHostLearnedOrRemoved. If not, it would be assigned
837 * "Unknown" tier. Thus the tier of host attached node cannot be
838 * null. If the src node here, is the next node in the hierarchy of
839 * the nodes, then its tier cannot be null
842 Tier dstNodeTier = (Tier) switchManager.getNodeProp(dstNode, Tier.TierPropName);
844 * Skip if the tier of the destination node is null
846 if (dstNodeTier == null) {
849 if (dstNodeTier.getValue() > nodeTier.getValue()) {
850 ArrayList<String> buildHierarchy = currHierarchy;
851 if (currHierarchy.size() > currHierarchyClone.size()) {
852 // Shallow copy as required
853 buildHierarchy = (ArrayList<String>) currHierarchyClone.clone();
854 fullHierarchy.add(buildHierarchy);
856 updateCurrentHierarchy(dstNode, buildHierarchy, fullHierarchy);
861 private void debugEdgeUpdate(Edge e, UpdateType type, Set<Property> props) {
863 Short srcPort = null;
865 Short dstPort = null;
866 boolean added = false;
867 String srcType = null;
868 String dstType = null;
870 if (e == null || type == null) {
871 logger.error("Edge or Update type are null!");
874 srcType = e.getTailNodeConnector().getType();
875 dstType = e.getHeadNodeConnector().getType();
877 if (srcType.equals(NodeConnector.NodeConnectorIDType.PRODUCTION)) {
878 logger.debug("Skip updates for {}", e);
882 if (!srcType.equals(NodeConnector.NodeConnectorIDType.OPENFLOW)) {
883 logger.debug("For now we cannot handle updates for non-openflow nodes");
887 if (dstType.equals(NodeConnector.NodeConnectorIDType.PRODUCTION)) {
888 logger.debug("Skip updates for {}", e);
892 if (!dstType.equals(NodeConnector.NodeConnectorIDType.OPENFLOW)) {
893 logger.debug("For now we cannot handle updates for non-openflow nodes");
897 // At this point we know we got an openflow update, so
898 // lets fill everything accordingly.
899 srcNid = (Long) e.getTailNodeConnector().getNode().getID();
900 srcPort = (Short) e.getTailNodeConnector().getID();
901 dstNid = (Long) e.getHeadNodeConnector().getNode().getID();
902 dstPort = (Short) e.getHeadNodeConnector().getID();
904 // Now lets update the added flag
915 logger.debug("HostTracker Topology linkUpdate handling src:{}[port {}] dst:{}[port {}] added: {}",
916 new Object[] { srcNid, srcPort, dstNid, dstPort, added });
920 public void edgeUpdate(List<TopoEdgeUpdate> topoedgeupdateList) {
921 if (logger.isDebugEnabled()) {
922 for (TopoEdgeUpdate topoEdgeUpdate : topoedgeupdateList) {
923 Edge e = topoEdgeUpdate.getEdge();
924 Set<Property> p = topoEdgeUpdate.getProperty();
925 UpdateType type = topoEdgeUpdate.getUpdateType();
927 debugEdgeUpdate(e, type, p);
933 public void subnetNotify(Subnet sub, boolean add) {
934 logger.debug("Received subnet notification: {} add={}", sub, add);
936 for (Entry<IHostId, ARPPending> entry : failedARPReqList.entrySet()) {
938 arphost = entry.getValue();
939 if (hostFinder == null) {
940 logger.warn("ARPHandler Services are not available on subnet addition");
943 logger.debug("Sending the ARP from FailedARPReqList fors IP: {}", decodeIPFromId(arphost.getHostId()));
944 for (IHostFinder hf : hostFinder) {
945 hf.find(decodeIPFromId(arphost.getHostId()));
952 * This thread runs every 4 seconds
955 class OutStandingARPHandler extends TimerTask {
963 for (Entry<IHostId, ARPPending> entry : ARPPendingList.entrySet()) {
964 arphost = entry.getValue();
966 if (hostsDB.containsKey(arphost.getHostId())) {
967 // this host is already learned, shouldn't be in
969 // Remove it and continue
970 logger.warn("Learned Host {} found in ARPPendingList", decodeIPFromId(arphost.getHostId()));
971 ARPPendingList.remove(entry.getKey());
974 if (arphost.getSent_count() < hostRetryCount) {
976 * No reply has been received of first ARP Req, send the
977 * next one. Before sending the ARP, check if ARPHandler
978 * is available or not
980 if (hostFinder == null) {
981 logger.warn("ARPHandler Services are not available for Outstanding ARPs");
984 for (IHostFinder hf : hostFinder) {
985 hf.find(decodeIPFromId(arphost.getHostId()));
987 arphost.sent_count++;
988 logger.debug("ARP Sent from ARPPending List, IP: {}", decodeIPFromId(arphost.getHostId()));
989 } else if (arphost.getSent_count() >= hostRetryCount) {
991 * ARP requests have been sent without receiving a
992 * reply, remove this from the pending list
994 ARPPendingList.remove(entry.getKey());
996 "ARP reply not received after multiple attempts, removing from Pending List IP: {}",
997 decodeIPFromId(arphost.getHostId()));
999 * Add this host to a different list which will be
1000 * processed on link up events
1002 logger.debug("Adding the host to FailedARPReqList IP: {}", decodeIPFromId(arphost.getHostId()));
1003 failedARPReqList.put(entry.getKey(), arphost);
1006 logger.error("Inavlid arp_sent count for entry: {}", entry);
1009 } catch (IllegalStateException e) {
1010 logger.debug("IllegalStateException Received by OutStandingARPHandler from: {}", e.getMessage());
1015 private class ARPRefreshHandler extends TimerTask {
1018 if ((clusterContainerService != null) && !clusterContainerService.amICoordinator()) {
1026 * The host probe procedure is turned off
1030 if (hostsDB == null) {
1031 /* hostsDB is not allocated yet */
1032 logger.error("ARPRefreshHandler(): hostsDB is not allocated yet:");
1036 for (Entry<IHostId, HostNodeConnector> entry : hostsDB.entrySet()) {
1037 HostNodeConnector host = entry.getValue();
1038 if (host.isStaticHost()) {
1039 /* this host was learned via API3, don't age it out */
1043 short arp_cntdown = host.getArpSendCountDown();
1045 if (arp_cntdown > hostRetryCount) {
1046 host.setArpSendCountDown(arp_cntdown);
1047 } else if (arp_cntdown <= 0) {
1049 * No ARP Reply received in last 2 minutes, remove this
1050 * host and inform applications
1052 removeKnownHost(entry.getKey());
1053 notifyHostLearnedOrRemoved(host, false);
1054 } else if (arp_cntdown <= hostRetryCount) {
1056 * Use the services of arphandler to check if host is
1059 if (logger.isTraceEnabled()) {
1061 "ARP Probing ({}) for {}({})",
1062 new Object[] { arp_cntdown, host.getNetworkAddress().getHostAddress(),
1063 HexEncode.bytesToHexString(host.getDataLayerAddressBytes()) });
1065 host.setArpSendCountDown(arp_cntdown);
1066 if (hostFinder == null) {
1068 * If hostfinder is not available, then can't send
1069 * the probe. However, continue the age out the
1070 * hosts since we don't know if the host is indeed
1073 logger.trace("ARPHandler is not avaialable, can't send the probe");
1076 for (IHostFinder hf : hostFinder) {
1081 } catch (IllegalStateException e) {
1082 logger.debug("IllegalStateException Received by ARPRefreshHandler from: {}", e.getMessage());
1088 * Inform the controller IP to MAC binding of a host and its connectivity to
1089 * an openflow switch in terms of Node, port, and VLAN.
1091 * @param networkAddr
1092 * IP address of the host
1094 * Address MAC address of the host
1096 * NodeConnector to which host is connected
1098 * Port of the switch to which host is connected
1100 * Vlan of which this host is member of
1102 * @return Status The status object as described in {@code Status}
1103 * indicating the result of this action.
1106 protected Status addStaticHostReq(InetAddress networkAddr, byte[] dataLayerAddress, NodeConnector nc, short vlan) {
1107 if (dataLayerAddress.length != NetUtils.MACAddrLengthInBytes) {
1108 return new Status(StatusCode.BADREQUEST, "Invalid MAC address");
1112 return new Status(StatusCode.BADREQUEST, "Invalid NodeConnector");
1114 HostNodeConnector host = null;
1116 host = new HostNodeConnector(dataLayerAddress, networkAddr, nc, vlan);
1117 IHostId id = HostIdFactory.create(networkAddr, new EthernetAddress(dataLayerAddress));
1118 if (hostExists(host)) {
1119 // This host is already learned either via ARP or through a
1120 // northbound request
1121 HostNodeConnector transHost = hostsDB.get(networkAddr);
1122 transHost.setStaticHost(true);
1123 return new Status(StatusCode.SUCCESS);
1126 if (hostsDB.get(id) != null) {
1127 // There is already a host with this IP address (but behind
1128 // a different (switch, port, vlan) tuple. Return an error
1129 return new Status(StatusCode.CONFLICT, "Host with this IP already exists.");
1131 host.setStaticHost(true);
1133 * Check if the nc is an ISL port
1135 if (topologyManager != null) {
1136 if (topologyManager.isInternal(nc)) {
1137 return new Status(StatusCode.BADREQUEST, "Cannot add host on ISL port");
1141 * Before adding host, Check if the switch and the port have already
1144 if (switchManager.isNodeConnectorEnabled(nc)) {
1146 processPendingARPReqs(id);
1147 notifyHostLearnedOrRemoved(host, true);
1149 inactiveStaticHosts.put(nc, host);
1150 logger.debug("Switch or switchport is not up, adding host {} to inactive list",
1151 networkAddr.getHostName());
1153 return new Status(StatusCode.SUCCESS);
1154 } catch (ConstructionException e) {
1155 logger.error("", e);
1156 return new Status(StatusCode.INTERNALERROR, "Host could not be created");
1162 * Update the controller IP to MAC binding of a host and its connectivity to
1163 * an openflow switch in terms of switch id, switch port, and VLAN.
1165 * @param networkAddr
1166 * IP address of the host
1168 * Address MAC address of the host
1170 * NodeConnector to which host is connected
1172 * Port of the switch to which host is connected
1174 * Vlan of which this host is member of
1176 * @return Status The status object as described in {@code Status}
1177 * indicating the result of this action.
1179 public Status updateHostReq(InetAddress networkAddr, byte[] dataLayerAddress, NodeConnector nc, short vlan) {
1180 HostNodeConnector tobeUpdatedHost;
1181 HostNodeConnector host = null;
1183 if (dataLayerAddress.length != NetUtils.MACAddrLengthInBytes) {
1184 return new Status(StatusCode.BADREQUEST, "Invalid MAC address");
1188 return new Status(StatusCode.BADREQUEST, "Invalid NodeConnector");
1192 host = new HostNodeConnector(dataLayerAddress, networkAddr, nc, vlan);
1193 if (hostExists(host)) {
1194 return new Status(StatusCode.BADREQUEST, "Host already exists");
1197 IHostId id = HostIdFactory.create(networkAddr, new EthernetAddress(dataLayerAddress));
1199 if ((tobeUpdatedHost = hostsDB.get(networkAddr)) != null) {
1200 if (hostsDB.replace(id, tobeUpdatedHost, host)) {
1201 logger.debug("Host replaced from hostsDB. Old host: {} New Host: {}", tobeUpdatedHost, host);
1202 notifyHostLearnedOrRemoved(tobeUpdatedHost, false);
1203 notifyHostLearnedOrRemoved(host, true);
1204 return new Status(StatusCode.SUCCESS);
1206 logger.error("Static host replacement failed from hostsDB, Replaced Host: {}, New Host: {}",
1207 tobeUpdatedHost, host);
1208 return new Status(StatusCode.INTERNALERROR,
1209 "Host Replacement Failed due to presence of another host with same IP");
1213 // Check if the host exists in inactive hosts database
1214 if ((tobeUpdatedHost = inactiveStaticHosts.get(nc)) != null) {
1215 if (inactiveStaticHosts.replace(nc, tobeUpdatedHost, host)) {
1216 logger.debug("Host replaced from inactive hostsDB. Old host: {} New Host: {}", tobeUpdatedHost,
1218 return new Status(StatusCode.SUCCESS);
1220 logger.error("Static host replacement failed, Replaced Host: {}, New Host: {}", tobeUpdatedHost,
1222 return new Status(StatusCode.INTERNALERROR,
1223 "Host Replacement Failed due to presence of another host with same IP");
1227 // Host doesn't exist
1228 return new Status(StatusCode.BADREQUEST, "Host doesn't exists, can't update");
1229 } catch (ConstructionException e) {
1230 logger.error("", e);
1231 return new Status(StatusCode.INTERNALERROR, "host object creation failure");
1236 * Remove from the controller IP to MAC binding of a host and its
1237 * connectivity to an openflow switch
1239 * @param networkAddr
1240 * IP address of the host
1242 * @return boolean true if the host was removed successfully, false
1246 public Status removeStaticHostReq(InetAddress networkAddress, DataLinkAddress mac) {
1247 // Check if host is in active hosts database
1248 IHostId id = HostIdFactory.create(networkAddress, mac);
1249 HostNodeConnector host = getHostFromOnActiveDB(id);
1252 if (!host.isStaticHost()) {
1253 return new Status(StatusCode.FORBIDDEN, "Host " + networkAddress.getHostName() + " is not static");
1255 // Remove and notify
1256 notifyHostLearnedOrRemoved(host, false);
1257 removeKnownHost(id);
1258 return new Status(StatusCode.SUCCESS, null);
1261 // Check if host is in inactive hosts database
1262 Entry<NodeConnector, HostNodeConnector> entry = getHostFromInactiveDB(id);
1263 if (entry != null) {
1264 host = entry.getValue();
1266 if (!host.isStaticHost()) {
1267 return new Status(StatusCode.FORBIDDEN, "Host " + networkAddress.getHostName() + " is not static");
1269 this.removeHostFromInactiveDB(id);
1270 return new Status(StatusCode.SUCCESS, null);
1273 // Host is neither in active nor inactive hosts database
1274 return new Status(StatusCode.NOTFOUND, "Host does not exist");
1278 public void modeChangeNotify(Node node, boolean proactive) {
1279 logger.debug("Set Switch {} Mode to {}", node.getID(), proactive);
1283 public void notifyNode(Node node, UpdateType type, Map<String, Property> propMap) {
1290 logger.debug("Received removed node {}", node);
1291 for (Entry<IHostId, HostNodeConnector> entry : hostsDB.entrySet()) {
1292 HostNodeConnector host = entry.getValue();
1293 if (host.getnodeconnectorNode().equals(node)) {
1294 logger.debug("Node: {} is down, remove from Hosts_DB", node);
1295 removeKnownHost(entry.getKey());
1296 notifyHostLearnedOrRemoved(host, false);
1306 public void notifyNodeConnector(NodeConnector nodeConnector, UpdateType type, Map<String, Property> propMap) {
1307 if (nodeConnector == null) {
1319 State state = (State) propMap.get(State.StatePropName);
1320 if ((state != null) && (state.getValue() == State.EDGE_UP)) {
1329 handleNodeConnectorStatusUp(nodeConnector);
1331 handleNodeConnectorStatusDown(nodeConnector);
1336 public Status addStaticHost(String networkAddress, String dataLayerAddress, NodeConnector nc, String vlan) {
1338 InetAddress ip = InetAddress.getByName(networkAddress);
1340 if (vlan != null && !vlan.isEmpty()) {
1341 vl = Short.decode(vlan);
1342 if (vl < 1 || vl > 4095) {
1343 return new Status(StatusCode.BADREQUEST, "Host vlan out of range [1 - 4095]");
1347 return addStaticHostReq(ip, HexEncode.bytesFromHexString(dataLayerAddress), nc, vl);
1349 } catch (UnknownHostException e) {
1350 logger.debug("Invalid host IP specified when adding static host", e);
1351 return new Status(StatusCode.BADREQUEST, "Invalid Host IP Address");
1352 } catch (NumberFormatException nfe) {
1353 logger.debug("Invalid host vlan or MAC specified when adding static host", nfe);
1354 return new Status(StatusCode.BADREQUEST, "Invalid Host vLan/MAC");
1359 public Status removeStaticHost(String networkAddress) {
1361 if ((keyScheme != null) && (!keyScheme.equals(HostIdFactory.DEFAULT_IP_KEY_SCHEME))) {
1362 return new Status(StatusCode.NOTALLOWED, "Host DB Key scheme used is not IP only scheme.");
1364 InetAddress address = InetAddress.getByName(networkAddress);
1365 return removeStaticHostReq(address, null);
1366 } catch (UnknownHostException e) {
1367 logger.debug("Invalid IP Address when trying to remove host", e);
1368 return new Status(StatusCode.BADREQUEST, "Invalid IP Address when trying to remove host");
1373 public Status removeStaticHostUsingIPAndMac(String networkAddress, String macAddress) {
1375 if ((keyScheme != null) && (keyScheme.equals(HostIdFactory.DEFAULT_IP_KEY_SCHEME))) {
1376 return new Status(StatusCode.NOTALLOWED, "Host DB Key scheme used is not IP only scheme.");
1378 InetAddress address = InetAddress.getByName(networkAddress);
1379 DataLinkAddress mac = new EthernetAddress(HexEncode.bytesFromHexString(macAddress));
1380 return removeStaticHostReq(address, mac);
1381 } catch (UnknownHostException e) {
1382 logger.debug("Invalid IP Address when trying to remove host", e);
1383 return new Status(StatusCode.BADREQUEST, "Invalid IP Address when trying to remove host");
1384 } catch (ConstructionException e) {
1385 // TODO Auto-generated catch block
1386 e.printStackTrace();
1387 return new Status(StatusCode.BADREQUEST, "Invalid Input parameters have been passed.");
1391 private InetAddress decodeIPFromId(IHostId id) {
1392 if ((keyScheme != null) && (keyScheme.equals(HostIdFactory.DEFAULT_IP_KEY_SCHEME))) {
1393 IPHostId ipId = (IPHostId) id;
1394 return (ipId.getIpAddress());
1395 } else if ((keyScheme != null) && (keyScheme.equals(HostIdFactory.IP_MAC_KEY_SCHEME))) {
1396 IPMacHostId ipMacId = (IPMacHostId) id;
1397 return (ipMacId.getIpAddress());
1402 private DataLinkAddress decodeMacFromId(IHostId id) {
1403 if ((keyScheme != null) && (!keyScheme.equals(HostIdFactory.DEFAULT_IP_KEY_SCHEME))) {
1404 IPMacHostId ipMacId = (IPMacHostId) id;
1405 return (ipMacId.getMacAddr());
1411 private void handleNodeConnectorStatusUp(NodeConnector nodeConnector) {
1413 HostNodeConnector host = null;
1415 logger.trace("handleNodeConnectorStatusUp {}", nodeConnector);
1417 for (Entry<IHostId, ARPPending> entry : failedARPReqList.entrySet()) {
1418 arphost = entry.getValue();
1419 logger.trace("Sending the ARP from FailedARPReqList fors IP: {}", arphost.getHostId());
1420 if (hostFinder == null) {
1421 logger.warn("ARPHandler is not available at interface up");
1422 logger.warn("Since this event is missed, host(s) connected to interface {} may not be discovered",
1427 // Send a broadcast ARP only on the interface which just came up.
1428 // Use hostFinder's "probe" method
1430 byte[] dataLayerAddress = NetUtils.getBroadcastMACAddr();
1431 host = new HostNodeConnector(dataLayerAddress, decodeIPFromId(arphost.getHostId()), nodeConnector,
1433 for (IHostFinder hf : hostFinder) {
1436 } catch (ConstructionException e) {
1437 logger.debug("HostNodeConnector couldn't be created for Host: {}, NodeConnector: {}",
1438 arphost.getHostId(), nodeConnector);
1439 logger.error("", e);
1443 host = inactiveStaticHosts.get(nodeConnector);
1445 inactiveStaticHosts.remove(nodeConnector);
1447 IHostId id = HostIdFactory.create(host.getNetworkAddress(), host.getDataLayerAddress());
1448 processPendingARPReqs(id);
1449 notifyHostLearnedOrRemoved(host, true);
1453 private void handleNodeConnectorStatusDown(NodeConnector nodeConnector) {
1454 logger.trace("handleNodeConnectorStatusDown {}", nodeConnector);
1456 for (Entry<IHostId, HostNodeConnector> entry : hostsDB.entrySet()) {
1457 HostNodeConnector host = entry.getValue();
1458 if (host.getnodeConnector().equals(nodeConnector)) {
1459 logger.debug(" NodeConnector: {} is down, remove from Hosts_DB", nodeConnector);
1460 removeKnownHost(entry.getKey());
1461 notifyHostLearnedOrRemoved(host, false);
1466 void setClusterContainerService(IClusterContainerServices s) {
1467 logger.debug("Cluster Service set");
1468 this.clusterContainerService = s;
1471 void unsetClusterContainerService(IClusterContainerServices s) {
1472 if (this.clusterContainerService == s) {
1473 logger.debug("Cluster Service removed!");
1474 this.clusterContainerService = null;
1478 void setSwitchManager(ISwitchManager s) {
1479 logger.debug("SwitchManager set");
1480 this.switchManager = s;
1483 void unsetSwitchManager(ISwitchManager s) {
1484 if (this.switchManager == s) {
1485 logger.debug("SwitchManager removed!");
1486 this.switchManager = null;
1490 public String getContainerName() {
1491 if (containerName == null) {
1492 return GlobalConstants.DEFAULT.toString();
1494 return containerName;
1498 * Function called by the dependency manager when all the required
1499 * dependencies are satisfied
1502 void init(Component c) {
1503 Dictionary<?, ?> props = c.getServiceProperties();
1504 if (props != null) {
1505 this.containerName = (String) props.get("containerName");
1506 logger.debug("Running containerName: {}", this.containerName);
1508 // In the Global instance case the containerName is empty
1509 this.containerName = "";
1513 logger.debug("key Scheme in hosttracker is {}", keyScheme);
1517 * Function called by the dependency manager when at least one dependency
1518 * become unsatisfied or when the component is shutting down because for
1519 * example bundle is being stopped.
1526 * Function called by dependency manager after "init ()" is called and after
1527 * the services provided by the class are registered in the service registry
1531 registerWithOSGIConsole();
1535 * Function called by the dependency manager before the services exported by
1536 * the component are unregistered, this will be followed by a "destroy ()"
1545 arpRefreshTimer.cancel();
1547 executor.shutdownNow();
1551 public void edgeOverUtilized(Edge edge) {
1556 public void edgeUtilBackToNormal(Edge edge) {
1561 public void entryCreated(IHostId key, String cacheName, boolean originLocal) {
1565 processPendingARPReqs(key);
1569 public void entryUpdated(IHostId key, HostNodeConnector new_value, String cacheName, boolean originLocal) {
1573 public void entryDeleted(IHostId key, String cacheName, boolean originLocal) {
1576 private void registerWithOSGIConsole() {
1577 BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
1578 bundleContext.registerService(CommandProvider.class.getName(), this, null);
1582 public String getHelp() {
1586 public void _dumpPendingARPReqList(CommandInterpreter ci) {
1588 for (Entry<IHostId, ARPPending> entry : ARPPendingList.entrySet()) {
1589 arphost = entry.getValue();
1590 ci.println(arphost.getHostId().toString());
1594 public void _dumpFailedARPReqList(CommandInterpreter ci) {
1596 for (Entry<IHostId, ARPPending> entry : failedARPReqList.entrySet()) {
1597 arphost = entry.getValue();
1598 ci.println(arphost.getHostId().toString());
1603 public HostNodeConnector hostFind(InetAddress addr) {
1604 IHostId id = HostIdFactory.create(addr, null);
1605 return (hostFind(id));
1609 public HostNodeConnector hostQuery(InetAddress addr) {
1610 IHostId id = HostIdFactory.create(addr, null);
1611 return (hostQuery(id));
1615 public Future<HostNodeConnector> discoverHost(InetAddress addr) {
1616 IHostId id = HostIdFactory.create(addr, null);
1617 return discoverHost(id);
1621 public List<List<String>> getHostNetworkHierarchy(InetAddress addr) {
1622 IHostId id = HostIdFactory.create(addr, null);
1623 return getHostNetworkHierarchy(id);