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.switchmanager.internal;
11 import java.io.FileNotFoundException;
12 import java.io.IOException;
13 import java.io.ObjectInputStream;
14 import java.net.InetAddress;
15 import java.net.NetworkInterface;
16 import java.net.SocketException;
17 import java.util.ArrayList;
18 import java.util.Collections;
19 import java.util.Date;
20 import java.util.Dictionary;
21 import java.util.EnumSet;
22 import java.util.Enumeration;
23 import java.util.HashMap;
24 import java.util.HashSet;
25 import java.util.List;
28 import java.util.concurrent.ConcurrentHashMap;
29 import java.util.concurrent.ConcurrentMap;
30 import java.util.concurrent.CopyOnWriteArrayList;
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.configuration.IConfigurationContainerAware;
41 import org.opendaylight.controller.sal.core.Bandwidth;
42 import org.opendaylight.controller.sal.core.Config;
43 import org.opendaylight.controller.sal.core.Description;
44 import org.opendaylight.controller.sal.core.Name;
45 import org.opendaylight.controller.sal.core.Node;
46 import org.opendaylight.controller.sal.core.NodeConnector;
47 import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
48 import org.opendaylight.controller.sal.core.Property;
49 import org.opendaylight.controller.sal.core.State;
50 import org.opendaylight.controller.sal.core.Tier;
51 import org.opendaylight.controller.sal.core.UpdateType;
52 import org.opendaylight.controller.sal.inventory.IInventoryService;
53 import org.opendaylight.controller.sal.inventory.IListenInventoryUpdates;
54 import org.opendaylight.controller.sal.utils.StatusCode;
55 import org.opendaylight.controller.sal.utils.GlobalConstants;
56 import org.opendaylight.controller.sal.utils.IObjectReader;
57 import org.opendaylight.controller.sal.utils.NodeCreator;
58 import org.opendaylight.controller.sal.utils.ObjectReader;
59 import org.opendaylight.controller.sal.utils.ObjectWriter;
60 import org.opendaylight.controller.sal.utils.ServiceHelper;
61 import org.opendaylight.controller.sal.utils.Status;
62 import org.opendaylight.controller.switchmanager.IInventoryListener;
63 import org.opendaylight.controller.switchmanager.ISpanAware;
64 import org.opendaylight.controller.switchmanager.ISwitchManager;
65 import org.opendaylight.controller.switchmanager.ISwitchManagerAware;
66 import org.opendaylight.controller.switchmanager.SpanConfig;
67 import org.opendaylight.controller.switchmanager.Subnet;
68 import org.opendaylight.controller.switchmanager.SubnetConfig;
69 import org.opendaylight.controller.switchmanager.Switch;
70 import org.opendaylight.controller.switchmanager.SwitchConfig;
71 import org.osgi.framework.BundleContext;
72 import org.osgi.framework.FrameworkUtil;
73 import org.slf4j.Logger;
74 import org.slf4j.LoggerFactory;
77 * The class describes SwitchManager which is the central repository of all the
78 * inventory data including nodes, node connectors, properties attached, Layer3
79 * configurations, Span configurations, node configurations, network device
80 * representations viewed by Controller Web applications. One SwitchManager
81 * instance per container of the network. All the node/nodeConnector properties
82 * are maintained in the default container only.
84 public class SwitchManagerImpl implements ISwitchManager,
85 IConfigurationContainerAware, IObjectReader,
86 ICacheUpdateAware<Long, String>, IListenInventoryUpdates,
88 private static Logger log = LoggerFactory
89 .getLogger(SwitchManagerImpl.class);
90 private static String ROOT = GlobalConstants.STARTUPHOME.toString();
91 private static final String SAVE = "Save";
92 private String subnetFileName = null, spanFileName = null,
93 switchConfigFileName = null;
94 private List<NodeConnector> spanNodeConnectors = new CopyOnWriteArrayList<NodeConnector>();
95 private ConcurrentMap<InetAddress, Subnet> subnets; // set of Subnets keyed by the InetAddress
96 private ConcurrentMap<String, SubnetConfig> subnetsConfigList;
97 private ConcurrentMap<Integer, SpanConfig> spanConfigList;
98 private ConcurrentMap<String, SwitchConfig> nodeConfigList; // manually configured parameters for the node like name and tier
99 private ConcurrentMap<Long, String> configSaveEvent;
100 private ConcurrentMap<Node, Map<String, Property>> nodeProps; // properties are maintained in global container only
101 private ConcurrentMap<NodeConnector, Map<String, Property>> nodeConnectorProps; // properties are maintained in global container only
102 private ConcurrentMap<Node, Map<String, NodeConnector>> nodeConnectorNames;
103 private IInventoryService inventoryService;
104 private Set<ISwitchManagerAware> switchManagerAware = Collections
105 .synchronizedSet(new HashSet<ISwitchManagerAware>());
106 private Set<IInventoryListener> inventoryListeners = Collections
107 .synchronizedSet(new HashSet<IInventoryListener>());
108 private Set<ISpanAware> spanAware = Collections
109 .synchronizedSet(new HashSet<ISpanAware>());
111 private static boolean hostRefresh = true;
112 private int hostRetryCount = 5;
113 private IClusterContainerServices clusterContainerService = null;
114 private String containerName = null;
115 private boolean isDefaultContainer = true;
117 public enum ReasonCode {
118 SUCCESS("Success"), FAILURE("Failure"), INVALID_CONF(
119 "Invalid Configuration"), EXIST("Entry Already Exist"), CONFLICT(
120 "Configuration Conflict with Existing Entry");
124 private ReasonCode(String name) {
128 public String toString() {
133 public void notifySubnetChange(Subnet sub, boolean add) {
134 synchronized (switchManagerAware) {
135 for (Object subAware : switchManagerAware) {
137 ((ISwitchManagerAware) subAware).subnetNotify(sub, add);
138 } catch (Exception e) {
139 log.error("Failed to notify Subnet change {}",
146 public void notifySpanPortChange(Node node, List<NodeConnector> ports,
148 synchronized (spanAware) {
149 for (Object sa : spanAware) {
151 ((ISpanAware) sa).spanUpdate(node, ports, add);
152 } catch (Exception e) {
153 log.error("Failed to notify Span Interface change {}",
160 private void notifyModeChange(Node node, boolean proactive) {
161 synchronized (switchManagerAware) {
162 for (ISwitchManagerAware service : switchManagerAware) {
164 service.modeChangeNotify(node, proactive);
165 } catch (Exception e) {
166 log.error("Failed to notify Subnet change {}",
173 public void startUp() {
174 // Initialize configuration file names
175 subnetFileName = ROOT + "subnets" + this.getContainerName() + ".conf";
176 spanFileName = ROOT + "spanPorts_" + this.getContainerName() + ".conf";
177 switchConfigFileName = ROOT + "switchConfig_" + this.getContainerName()
180 // Instantiate cluster synced variables
185 * Read startup and build database if we have not already gotten the
186 * configurations synced from another node
188 if (subnetsConfigList.isEmpty())
189 loadSubnetConfiguration();
190 if (spanConfigList.isEmpty())
191 loadSpanConfiguration();
192 if (nodeConfigList.isEmpty())
193 loadSwitchConfiguration();
195 MAC = getHardwareMAC();
198 public void shutDown() {
199 destroyCaches(this.getContainerName());
202 @SuppressWarnings("deprecation")
203 private void allocateCaches() {
204 if (this.clusterContainerService == null) {
205 log.warn("un-initialized clusterContainerService, can't create cache");
210 clusterContainerService.createCache(
211 "switchmanager.subnetsConfigList",
212 EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
213 clusterContainerService.createCache("switchmanager.spanConfigList",
214 EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
215 clusterContainerService.createCache("switchmanager.nodeConfigList",
216 EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
217 clusterContainerService.createCache("switchmanager.subnets",
218 EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
219 clusterContainerService.createCache(
220 "switchmanager.configSaveEvent",
221 EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
222 clusterContainerService.createCache("switchmanager.nodeProps",
223 EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
224 clusterContainerService.createCache(
225 "switchmanager.nodeConnectorProps",
226 EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
227 clusterContainerService.createCache(
228 "switchmanager.nodeConnectorNames",
229 EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
230 } catch (CacheConfigException cce) {
231 log.error("\nCache configuration invalid - check cache mode");
232 } catch (CacheExistException ce) {
233 log.error("\nCache already exits - destroy and recreate if needed");
237 @SuppressWarnings({ "unchecked", "deprecation" })
238 private void retrieveCaches() {
239 if (this.clusterContainerService == null) {
240 log.info("un-initialized clusterContainerService, can't create cache");
244 subnetsConfigList = (ConcurrentMap<String, SubnetConfig>) clusterContainerService
245 .getCache("switchmanager.subnetsConfigList");
246 if (subnetsConfigList == null) {
247 log.error("\nFailed to get cache for subnetsConfigList");
250 spanConfigList = (ConcurrentMap<Integer, SpanConfig>) clusterContainerService
251 .getCache("switchmanager.spanConfigList");
252 if (spanConfigList == null) {
253 log.error("\nFailed to get cache for spanConfigList");
256 nodeConfigList = (ConcurrentMap<String, SwitchConfig>) clusterContainerService
257 .getCache("switchmanager.nodeConfigList");
258 if (nodeConfigList == null) {
259 log.error("\nFailed to get cache for nodeConfigList");
262 subnets = (ConcurrentMap<InetAddress, Subnet>) clusterContainerService
263 .getCache("switchmanager.subnets");
264 if (subnets == null) {
265 log.error("\nFailed to get cache for subnets");
268 configSaveEvent = (ConcurrentMap<Long, String>) clusterContainerService
269 .getCache("switchmanager.configSaveEvent");
270 if (configSaveEvent == null) {
271 log.error("\nFailed to get cache for configSaveEvent");
274 nodeProps = (ConcurrentMap<Node, Map<String, Property>>) clusterContainerService
275 .getCache("switchmanager.nodeProps");
276 if (nodeProps == null) {
277 log.error("\nFailed to get cache for nodeProps");
280 nodeConnectorProps = (ConcurrentMap<NodeConnector, Map<String, Property>>) clusterContainerService
281 .getCache("switchmanager.nodeConnectorProps");
282 if (nodeConnectorProps == null) {
283 log.error("\nFailed to get cache for nodeConnectorProps");
286 nodeConnectorNames = (ConcurrentMap<Node, Map<String, NodeConnector>>) clusterContainerService
287 .getCache("switchmanager.nodeConnectorNames");
288 if (nodeConnectorNames == null) {
289 log.error("\nFailed to get cache for nodeConnectorNames");
293 void nonClusterObjectCreate() {
294 subnetsConfigList = new ConcurrentHashMap<String, SubnetConfig>();
295 spanConfigList = new ConcurrentHashMap<Integer, SpanConfig>();
296 nodeConfigList = new ConcurrentHashMap<String, SwitchConfig>();
297 subnets = new ConcurrentHashMap<InetAddress, Subnet>();
298 configSaveEvent = new ConcurrentHashMap<Long, String>();
299 nodeProps = new ConcurrentHashMap<Node, Map<String, Property>>();
300 nodeConnectorProps = new ConcurrentHashMap<NodeConnector, Map<String, Property>>();
301 nodeConnectorNames = new ConcurrentHashMap<Node, Map<String, NodeConnector>>();
304 @SuppressWarnings("deprecation")
305 private void destroyCaches(String container) {
306 if (this.clusterContainerService == null) {
307 log.info("un-initialized clusterContainerService, can't create cache");
311 clusterContainerService.destroyCache("switchmanager.subnetsConfigList");
312 clusterContainerService.destroyCache("switchmanager.spanConfigList");
313 clusterContainerService.destroyCache("switchmanager.nodeConfigList");
314 clusterContainerService.destroyCache("switchmanager.subnets");
315 clusterContainerService.destroyCache("switchmanager.configSaveEvent");
316 clusterContainerService.destroyCache("switchmanager.nodeProps");
317 clusterContainerService
318 .destroyCache("switchmanager.nodeConnectorProps");
319 clusterContainerService
320 .destroyCache("switchmanager.nodeConnectorNames");
321 nonClusterObjectCreate();
324 public List<SubnetConfig> getSubnetsConfigList() {
325 return new ArrayList<SubnetConfig>(subnetsConfigList.values());
329 public SubnetConfig getSubnetConfig(String subnet) {
330 return subnetsConfigList.get(subnet);
333 private List<SpanConfig> getSpanConfigList(Node node) {
334 List<SpanConfig> confList = new ArrayList<SpanConfig>();
335 String nodeId = node.toString();
336 for (SpanConfig conf : spanConfigList.values()) {
337 if (conf.matchNode(nodeId)) {
344 public List<SwitchConfig> getNodeConfigList() {
345 return new ArrayList<SwitchConfig>(nodeConfigList.values());
348 public SwitchConfig getSwitchConfig(String switchId) {
349 return nodeConfigList.get(switchId);
352 public Switch getSwitchByNode(Node node) {
353 Switch sw = new Switch(node);
356 Set<NodeConnector> ncSet = getPhysicalNodeConnectors(node);
357 sw.setNodeConnectors(ncSet);
359 List<NodeConnector> ncList = new ArrayList<NodeConnector>();
360 for (NodeConnector nodeConnector : ncSet) {
361 if (spanNodeConnectors.contains(nodeConnector)) {
362 ncList.add(nodeConnector);
365 sw.addSpanPorts(ncList);
370 public List<Switch> getNetworkDevices() {
371 Set<Node> nodeSet = getNodes();
372 List<Switch> swList = new ArrayList<Switch>();
373 if (nodeSet != null) {
374 for (Node node : nodeSet) {
375 swList.add(getSwitchByNode(node));
382 private void updateConfig(SubnetConfig conf, boolean add) {
384 subnetsConfigList.put(conf.getName(), conf);
386 subnetsConfigList.remove(conf.getName());
390 private void updateDatabase(SubnetConfig conf, boolean add) {
391 Subnet subnet = subnets.get(conf.getIPnum());
393 if (subnet == null) {
394 subnet = new Subnet(conf);
396 // In case of API3 call we may receive the ports along with the
398 if (!conf.isGlobal()) {
399 Set<NodeConnector> sp = conf.getSubnetNodeConnectors();
400 subnet.addNodeConnectors(sp);
402 subnets.put(conf.getIPnum(), subnet);
403 } else { // This is the deletion of the whole subnet
406 subnets.remove(conf.getIPnum());
410 private Status semanticCheck(SubnetConfig conf) {
411 Subnet newSubnet = new Subnet(conf);
412 Set<InetAddress> IPs = subnets.keySet();
414 return new Status(StatusCode.SUCCESS, null);
416 for (InetAddress i : IPs) {
417 Subnet existingSubnet = subnets.get(i);
418 if ((existingSubnet != null)
419 && !existingSubnet.isMutualExclusive(newSubnet)) {
420 return new Status(StatusCode.CONFLICT, null);
423 return new Status(StatusCode.SUCCESS, null);
426 private Status addRemoveSubnet(SubnetConfig conf, boolean add) {
427 // Valid config check
428 if (!conf.isValidConfig()) {
429 String msg = "Invalid Subnet configuration";
431 return new Status(StatusCode.BADREQUEST, msg);
436 if (subnetsConfigList.containsKey(conf.getName())) {
437 return new Status(StatusCode.CONFLICT,
438 "Same subnet config already exists");
441 Status rc = semanticCheck(conf);
442 if (!rc.isSuccess()) {
446 // Update Configuration
447 updateConfig(conf, add);
450 updateDatabase(conf, add);
452 return new Status(StatusCode.SUCCESS, null);
456 * Adds Subnet configured in GUI or API3
458 public Status addSubnet(SubnetConfig conf) {
459 return this.addRemoveSubnet(conf, true);
463 public Status removeSubnet(SubnetConfig conf) {
464 return this.addRemoveSubnet(conf, false);
468 public Status removeSubnet(String name) {
469 SubnetConfig conf = subnetsConfigList.get(name);
471 return new Status(StatusCode.SUCCESS, "Subnet not present");
473 return this.addRemoveSubnet(conf, false);
477 public Status addPortsToSubnet(String name, String switchPorts) {
478 // Update Configuration
479 SubnetConfig conf = subnetsConfigList.get(name);
481 return new Status(StatusCode.NOTFOUND, "Subnet does not exist");
483 if (!conf.isValidSwitchPort(switchPorts)) {
484 return new Status(StatusCode.BADREQUEST, "Invalid switchports");
487 conf.addNodeConnectors(switchPorts);
490 Subnet sub = subnets.get(conf.getIPnum());
491 Set<NodeConnector> sp = conf.getNodeConnectors(switchPorts);
492 sub.addNodeConnectors(sp);
493 return new Status(StatusCode.SUCCESS, null);
497 public Status removePortsFromSubnet(String name, String switchPorts) {
498 // Update Configuration
499 SubnetConfig conf = subnetsConfigList.get(name);
501 return new Status(StatusCode.NOTFOUND, "Subnet does not exist");
503 conf.removeNodeConnectors(switchPorts);
506 Subnet sub = subnets.get(conf.getIPnum());
507 Set<NodeConnector> sp = conf.getNodeConnectors(switchPorts);
508 sub.deleteNodeConnectors(sp);
509 return new Status(StatusCode.SUCCESS, null);
512 public String getContainerName() {
513 if (containerName == null) {
514 return GlobalConstants.DEFAULT.toString();
516 return containerName;
520 public Subnet getSubnetByNetworkAddress(InetAddress networkAddress) {
522 Set<InetAddress> indices = subnets.keySet();
523 for (InetAddress i : indices) {
524 sub = subnets.get(i);
525 if (sub.isSubnetOf(networkAddress)) {
533 public Object readObject(ObjectInputStream ois)
534 throws FileNotFoundException, IOException, ClassNotFoundException {
535 // Perform the class deserialization locally, from inside the package
536 // where the class is defined
537 return ois.readObject();
540 @SuppressWarnings("unchecked")
541 private void loadSubnetConfiguration() {
542 ObjectReader objReader = new ObjectReader();
543 ConcurrentMap<Integer, SubnetConfig> confList = (ConcurrentMap<Integer, SubnetConfig>) objReader
544 .read(this, subnetFileName);
546 if (confList == null) {
550 for (SubnetConfig conf : confList.values()) {
555 @SuppressWarnings("unchecked")
556 private void loadSpanConfiguration() {
557 ObjectReader objReader = new ObjectReader();
558 ConcurrentMap<Integer, SpanConfig> confList = (ConcurrentMap<Integer, SpanConfig>) objReader
559 .read(this, spanFileName);
561 if (confList == null) {
565 for (SpanConfig conf : confList.values()) {
570 @SuppressWarnings("unchecked")
571 private void loadSwitchConfiguration() {
572 ObjectReader objReader = new ObjectReader();
573 ConcurrentMap<String, SwitchConfig> confList = (ConcurrentMap<String, SwitchConfig>) objReader
574 .read(this, switchConfigFileName);
576 if (confList == null) {
580 for (SwitchConfig conf : confList.values()) {
581 updateSwitchConfig(conf);
586 public void updateSwitchConfig(SwitchConfig cfgObject) {
587 boolean modeChange = false;
589 SwitchConfig sc = nodeConfigList.get(cfgObject.getNodeId());
590 if ((sc == null) || !cfgObject.getMode().equals(sc.getMode())) {
594 nodeConfigList.put(cfgObject.getNodeId(), cfgObject);
596 // update default container only
597 if (isDefaultContainer) {
598 String nodeId = cfgObject.getNodeId();
599 Node node = Node.fromString(nodeId);
600 Map<String, Property> propMap;
601 if (nodeProps.get(node) != null) {
602 propMap = nodeProps.get(node);
604 propMap = new HashMap<String, Property>();
606 Property desc = new Description(cfgObject.getNodeDescription());
607 propMap.put(desc.getName(), desc);
608 Property tier = new Tier(Integer.parseInt(cfgObject.getTier()));
609 propMap.put(tier.getName(), tier);
610 addNodeProps(node, propMap);
612 log.info("Set Node {}'s Mode to {}", nodeId,
613 cfgObject.getMode());
616 notifyModeChange(node, cfgObject.isProactive());
619 } catch (Exception e) {
620 log.debug("updateSwitchConfig: {}", e.getMessage());
625 public Status saveSwitchConfig() {
626 // Publish the save config event to the cluster nodes
627 configSaveEvent.put(new Date().getTime(), SAVE);
628 return saveSwitchConfigInternal();
631 public Status saveSwitchConfigInternal() {
632 Status retS = null, retP = null;
633 ObjectWriter objWriter = new ObjectWriter();
635 retS = objWriter.write(new ConcurrentHashMap<String, SubnetConfig>(
636 subnetsConfigList), subnetFileName);
637 retP = objWriter.write(new ConcurrentHashMap<Integer, SpanConfig>(
638 spanConfigList), spanFileName);
639 retS = objWriter.write(new ConcurrentHashMap<String, SwitchConfig>(
640 nodeConfigList), switchConfigFileName);
642 if (retS.equals(retP)) {
643 if (retS.isSuccess()) {
646 return new Status(StatusCode.INTERNALERROR, "Save failed");
649 return new Status(StatusCode.INTERNALERROR, "Partial save failure");
654 public List<SpanConfig> getSpanConfigList() {
655 return new ArrayList<SpanConfig>(spanConfigList.values());
659 public Status addSpanConfig(SpanConfig conf) {
660 // Valid config check
661 if (!conf.isValidConfig()) {
662 String msg = "Invalid Span configuration";
664 return new Status(StatusCode.BADREQUEST, msg);
668 if (spanConfigList.containsKey(conf.hashCode())) {
669 return new Status(StatusCode.CONFLICT, "Same span config exists");
672 // Update database and notify clients
673 addSpanPorts(conf.getNode(), conf.getPortArrayList());
675 // Update configuration
676 spanConfigList.put(conf.hashCode(), conf);
678 return new Status(StatusCode.SUCCESS, null);
682 public Status removeSpanConfig(SpanConfig conf) {
683 removeSpanPorts(conf.getNode(), conf.getPortArrayList());
685 // Update configuration
686 spanConfigList.remove(conf.hashCode());
688 return new Status(StatusCode.SUCCESS, null);
692 public List<NodeConnector> getSpanPorts(Node node) {
693 List<NodeConnector> ncList = new ArrayList<NodeConnector>();
695 for (NodeConnector nodeConnector : spanNodeConnectors) {
696 if (nodeConnector.getNode().equals(node)) {
697 ncList.add(nodeConnector);
704 public void entryCreated(Long key, String cacheName, boolean local) {
708 public void entryUpdated(Long key, String new_value, String cacheName,
709 boolean originLocal) {
710 saveSwitchConfigInternal();
714 public void entryDeleted(Long key, String cacheName, boolean originLocal) {
717 private void addNode(Node node, Set<Property> props) {
718 log.trace("{} added", node);
719 if (nodeProps == null) {
723 Map<String, Property> propMap;
724 if (nodeProps.get(node) != null) {
725 propMap = nodeProps.get(node);
727 propMap = new HashMap<String, Property>();
730 // copy node properties from plugin
732 for (Property prop : props) {
733 propMap.put(prop.getName(), prop);
737 // copy node properties from config
738 boolean proactiveForwarding = false;
739 if (nodeConfigList != null) {
740 String nodeId = node.toString();
741 for (SwitchConfig conf : nodeConfigList.values()) {
742 if (conf.getNodeId().equals(nodeId)) {
743 Property description = new Description(
744 conf.getNodeDescription());
745 propMap.put(description.getName(), description);
746 Property tier = new Tier(Integer.parseInt(conf.getTier()));
747 propMap.put(tier.getName(), tier);
748 proactiveForwarding = conf.isProactive();
753 addNodeProps(node, propMap);
755 // check if span ports are configed
758 // notify node listeners
759 notifyNode(node, UpdateType.ADDED, propMap);
761 // notify proactive mode forwarding
762 if (proactiveForwarding) {
763 notifyModeChange(node, true);
767 private void removeNode(Node node) {
768 log.trace("{} removed", node);
769 if (nodeProps == null)
771 nodeProps.remove(node);
773 // check if span ports need to be cleaned up
774 removeSpanPorts(node);
776 /* notify node listeners */
777 notifyNode(node, UpdateType.REMOVED, null);
780 private void updateNode(Node node, Set<Property> props) {
781 log.trace("{} updated", node);
782 if (nodeProps == null) {
786 Map<String, Property> propMap;
787 if (nodeProps.get(node) != null) {
788 propMap = nodeProps.get(node);
790 propMap = new HashMap<String, Property>();
793 // copy node properties from plugin
795 for (Property prop : props) {
796 propMap.put(prop.getName(), prop);
799 addNodeProps(node, propMap);
801 /* notify node listeners */
802 notifyNode(node, UpdateType.CHANGED, propMap);
806 public void updateNode(Node node, UpdateType type, Set<Property> props) {
809 addNode(node, props);
812 updateNode(node, props);
823 public void updateNodeConnector(NodeConnector nodeConnector,
824 UpdateType type, Set<Property> props) {
825 Node node = nodeConnector.getNode();
826 Map<String, Property> propMap = new HashMap<String, Property>();
828 log.trace("{} {}", nodeConnector, type);
830 if (nodeConnectorProps == null) {
838 for (Property prop : props) {
839 addNodeConnectorProp(nodeConnector, prop);
840 propMap.put(prop.getName(), prop);
843 addNodeConnectorProp(nodeConnector, null);
844 addNodeProps(node, null);
847 // check if span is configed
848 addSpanPort(nodeConnector);
851 removeNodeConnectorAllProps(nodeConnector);
852 removeNodeProps(node);
854 // clean up span config
855 removeSpanPort(nodeConnector);
861 notifyNodeConnector(nodeConnector, type, propMap);
865 public Set<Node> getNodes() {
866 return (nodeProps != null) ? new HashSet<Node>(nodeProps.keySet())
871 * test utility function which assumes all nodes are OF nodes
873 private Node getNode(Long id) {
874 Set<Node> nodes = getNodes();
876 for (Node node : nodes) {
877 if (id.equals((Long) node.getID())) {
886 * Returns a copy of a list of properties for a given node
891 * org.opendaylight.controller.switchmanager.ISwitchManager#getNodeProps
892 * (org.opendaylight.controller.sal.core.Node)
895 public Map<String, Property> getNodeProps(Node node) {
896 if (isDefaultContainer) {
897 Map<String, Property> rv = null;
898 if (this.nodeProps != null) {
899 rv = this.nodeProps.get(node);
901 /* make a copy of it */
902 rv = new HashMap<String, Property>(rv);
907 // get it from default container
908 ISwitchManager defaultSwitchManager = (ISwitchManager) ServiceHelper
909 .getInstance(ISwitchManager.class,
910 GlobalConstants.DEFAULT.toString(), this);
911 return defaultSwitchManager.getNodeProps(node);
916 public Property getNodeProp(Node node, String propName) {
917 Map<String, Property> propMap = getNodeProps(node);
918 return (propMap != null) ? propMap.get(propName) : null;
922 public void setNodeProp(Node node, Property prop) {
923 /* Get a copy of the property map */
924 Map<String, Property> propMap = getNodeProps(node);
928 propMap.put(prop.getName(), prop);
929 this.nodeProps.put(node, propMap);
933 public Status removeNodeProp(Node node, String propName) {
934 Map<String, Property> propMap = getNodeProps(node);
935 if (propMap != null) {
936 propMap.remove(propName);
937 this.nodeProps.put(node, propMap);
939 return new Status(StatusCode.SUCCESS, null);
943 public Status removeNodeAllProps(Node node) {
944 this.nodeProps.remove(node);
945 return new Status(StatusCode.SUCCESS, null);
949 public Set<NodeConnector> getUpNodeConnectors(Node node) {
950 if (nodeConnectorProps == null)
953 Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
954 for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
955 if (((Long) nodeConnector.getNode().getID()).longValue() != (Long) node
958 if (isNodeConnectorEnabled(nodeConnector))
959 nodeConnectorSet.add(nodeConnector);
962 return nodeConnectorSet;
966 public Set<NodeConnector> getNodeConnectors(Node node) {
967 if (nodeConnectorProps == null)
970 Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
971 for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
972 if (((Long) nodeConnector.getNode().getID()).longValue() != (Long) node
975 nodeConnectorSet.add(nodeConnector);
978 return nodeConnectorSet;
982 public Set<NodeConnector> getPhysicalNodeConnectors(Node node) {
983 if (nodeConnectorProps == null)
986 Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
987 for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
988 if (!nodeConnector.getNode().equals(node)
989 || isSpecial(nodeConnector)) {
992 nodeConnectorSet.add(nodeConnector);
995 return nodeConnectorSet;
999 * testing utility function which assumes we are dealing with OF Node
1000 * nodeconnectors only
1002 @SuppressWarnings("unused")
1003 private Set<Long> getEnabledNodeConnectorIds(Node node) {
1004 Set<Long> ids = new HashSet<Long>();
1005 Set<NodeConnector> nodeConnectors = getUpNodeConnectors(node);
1007 if (nodeConnectors != null) {
1008 for (NodeConnector nodeConnector : nodeConnectors) {
1009 ids.add((Long) nodeConnector.getID());
1017 public Map<String, Property> getNodeConnectorProps(
1018 NodeConnector nodeConnector) {
1019 if (isDefaultContainer) {
1020 Map<String, Property> rv = null;
1021 if (this.nodeConnectorProps != null) {
1022 rv = this.nodeConnectorProps.get(nodeConnector);
1024 rv = new HashMap<String, Property>(rv);
1029 // get it from default container
1030 ISwitchManager defaultSwitchManager = (ISwitchManager) ServiceHelper
1031 .getInstance(ISwitchManager.class,
1032 GlobalConstants.DEFAULT.toString(), this);
1033 return defaultSwitchManager.getNodeConnectorProps(nodeConnector);
1038 public Property getNodeConnectorProp(NodeConnector nodeConnector,
1040 Map<String, Property> propMap = getNodeConnectorProps(nodeConnector);
1041 return (propMap != null) ? propMap.get(propName) : null;
1044 private byte[] getHardwareMAC() {
1045 Enumeration<NetworkInterface> nis;
1047 nis = NetworkInterface.getNetworkInterfaces();
1048 } catch (SocketException e1) {
1053 for (; nis.hasMoreElements();) {
1054 NetworkInterface ni = nis.nextElement();
1056 MAC = ni.getHardwareAddress();
1057 } catch (SocketException e) {
1068 public byte[] getControllerMAC() {
1073 public boolean isHostRefreshEnabled() {
1078 public int getHostRetryCount() {
1079 return hostRetryCount;
1083 public NodeConnector getNodeConnector(Node node, String nodeConnectorName) {
1084 if (nodeConnectorNames == null)
1087 Map<String, NodeConnector> map = nodeConnectorNames.get(node);
1091 return map.get(nodeConnectorName);
1095 * Adds a node connector and its property if any
1097 * @param nodeConnector
1098 * {@link org.opendaylight.controller.sal.core.NodeConnector}
1100 * name of {@link org.opendaylight.controller.sal.core.Property}
1101 * @return success or failed reason
1104 public Status addNodeConnectorProp(NodeConnector nodeConnector,
1106 Map<String, Property> propMap = getNodeConnectorProps(nodeConnector);
1108 if (propMap == null) {
1109 propMap = new HashMap<String, Property>();
1112 // Just add the nodeConnector if prop is not available (in a non-default
1115 nodeConnectorProps.put(nodeConnector, propMap);
1116 return new Status(StatusCode.SUCCESS, null);
1119 propMap.put(prop.getName(), prop);
1120 nodeConnectorProps.put(nodeConnector, propMap);
1122 if (prop.getName().equals(Name.NamePropName)) {
1123 if (nodeConnectorNames != null) {
1124 Node node = nodeConnector.getNode();
1125 Map<String, NodeConnector> map = nodeConnectorNames.get(node);
1127 map = new HashMap<String, NodeConnector>();
1130 map.put(((Name) prop).getValue(), nodeConnector);
1131 nodeConnectorNames.put(node, map);
1135 return new Status(StatusCode.SUCCESS, null);
1139 * Removes one property of a node connector
1141 * @param nodeConnector
1142 * {@link org.opendaylight.controller.sal.core.NodeConnector}
1144 * name of {@link org.opendaylight.controller.sal.core.Property}
1145 * @return success or failed reason
1148 public Status removeNodeConnectorProp(NodeConnector nodeConnector,
1150 Map<String, Property> propMap = getNodeConnectorProps(nodeConnector);
1152 if (propMap == null) {
1153 /* Nothing to remove */
1154 return new Status(StatusCode.SUCCESS, null);
1157 propMap.remove(propName);
1158 nodeConnectorProps.put(nodeConnector, propMap);
1160 if (nodeConnectorNames != null) {
1161 Name name = ((Name) getNodeConnectorProp(nodeConnector,
1162 Name.NamePropName));
1164 Node node = nodeConnector.getNode();
1165 Map<String, NodeConnector> map = nodeConnectorNames.get(node);
1167 map.remove(name.getValue());
1168 nodeConnectorNames.put(node, map);
1173 return new Status(StatusCode.SUCCESS, null);
1177 * Removes all the properties of a node connector
1179 * @param nodeConnector
1180 * {@link org.opendaylight.controller.sal.core.NodeConnector}
1181 * @return success or failed reason
1184 public Status removeNodeConnectorAllProps(NodeConnector nodeConnector) {
1185 if (nodeConnectorNames != null) {
1186 Name name = ((Name) getNodeConnectorProp(nodeConnector,
1187 Name.NamePropName));
1189 Node node = nodeConnector.getNode();
1190 Map<String, NodeConnector> map = nodeConnectorNames.get(node);
1192 map.remove(name.getValue());
1193 nodeConnectorNames.put(node, map);
1197 nodeConnectorProps.remove(nodeConnector);
1199 return new Status(StatusCode.SUCCESS, null);
1203 * Function called by the dependency manager when all the required
1204 * dependencies are satisfied
1207 void init(Component c) {
1208 Dictionary<?, ?> props = c.getServiceProperties();
1209 if (props != null) {
1210 this.containerName = (String) props.get("containerName");
1211 log.trace("Running containerName: {}", this.containerName);
1213 // In the Global instance case the containerName is empty
1214 this.containerName = "";
1216 isDefaultContainer = containerName.equals(GlobalConstants.DEFAULT
1223 * Function called by the dependency manager when at least one dependency
1224 * become unsatisfied or when the component is shutting down because for
1225 * example bundle is being stopped.
1233 * Function called by dependency manager after "init ()" is called and after
1234 * the services provided by the class are registered in the service registry
1239 registerWithOSGIConsole();
1243 * Function called after registered the service in OSGi service registry.
1246 // solicit for existing inventories
1251 * Function called by the dependency manager before the services exported by
1252 * the component are unregistered, this will be followed by a "destroy ()"
1259 public void setInventoryService(IInventoryService service) {
1260 log.trace("Got inventory service set request {}", service);
1261 this.inventoryService = service;
1263 // solicit for existing inventories
1267 public void unsetInventoryService(IInventoryService service) {
1268 log.trace("Got a service UNset request");
1269 this.inventoryService = null;
1271 // clear existing inventories
1275 public void setSwitchManagerAware(ISwitchManagerAware service) {
1276 log.trace("Got inventory service set request {}", service);
1277 if (this.switchManagerAware != null) {
1278 this.switchManagerAware.add(service);
1281 // bulk update for newly joined
1282 switchManagerAwareNotify(service);
1285 public void unsetSwitchManagerAware(ISwitchManagerAware service) {
1286 log.trace("Got a service UNset request");
1287 if (this.switchManagerAware != null) {
1288 this.switchManagerAware.remove(service);
1292 public void setInventoryListener(IInventoryListener service) {
1293 log.trace("Got inventory listener set request {}", service);
1294 if (this.inventoryListeners != null) {
1295 this.inventoryListeners.add(service);
1298 // bulk update for newly joined
1299 bulkUpdateService(service);
1302 public void unsetInventoryListener(IInventoryListener service) {
1303 log.trace("Got a service UNset request");
1304 if (this.inventoryListeners != null) {
1305 this.inventoryListeners.remove(service);
1309 public void setSpanAware(ISpanAware service) {
1310 log.trace("Got SpanAware set request {}", service);
1311 if (this.spanAware != null) {
1312 this.spanAware.add(service);
1315 // bulk update for newly joined
1316 spanAwareNotify(service);
1319 public void unsetSpanAware(ISpanAware service) {
1320 log.trace("Got a service UNset request");
1321 if (this.spanAware != null) {
1322 this.spanAware.remove(service);
1326 void setClusterContainerService(IClusterContainerServices s) {
1327 log.trace("Cluster Service set");
1328 this.clusterContainerService = s;
1331 void unsetClusterContainerService(IClusterContainerServices s) {
1332 if (this.clusterContainerService == s) {
1333 log.trace("Cluster Service removed!");
1334 this.clusterContainerService = null;
1338 private void getInventories() {
1339 if (inventoryService == null) {
1340 log.trace("inventory service not avaiable");
1344 nodeProps = this.inventoryService.getNodeProps();
1345 Set<Node> nodeSet = nodeProps.keySet();
1346 if (nodeSet != null) {
1347 for (Node node : nodeSet) {
1348 addNode(node, null);
1352 nodeConnectorProps = inventoryService.getNodeConnectorProps();
1355 private void clearInventories() {
1357 nodeConnectorProps.clear();
1358 nodeConnectorNames.clear();
1359 spanNodeConnectors.clear();
1362 private void notifyNode(Node node, UpdateType type,
1363 Map<String, Property> propMap) {
1364 synchronized (inventoryListeners) {
1365 for (IInventoryListener service : inventoryListeners) {
1366 service.notifyNode(node, type, propMap);
1371 private void notifyNodeConnector(NodeConnector nodeConnector,
1372 UpdateType type, Map<String, Property> propMap) {
1373 synchronized (inventoryListeners) {
1374 for (IInventoryListener service : inventoryListeners) {
1375 service.notifyNodeConnector(nodeConnector, type, propMap);
1381 * For those joined late, bring them up-to-date.
1383 private void switchManagerAwareNotify(ISwitchManagerAware service) {
1384 for (Subnet sub : subnets.values()) {
1385 service.subnetNotify(sub, true);
1388 for (Node node : getNodes()) {
1389 SwitchConfig sc = getSwitchConfig(node.toString());
1390 if ((sc != null) && isDefaultContainer) {
1391 service.modeChangeNotify(node, sc.isProactive());
1396 private void bulkUpdateService(IInventoryListener service) {
1397 for (Node node : getNodes()) {
1398 service.notifyNode(node, UpdateType.ADDED, null);
1401 Map<String, Property> propMap = new HashMap<String, Property>();
1402 propMap.put(State.StatePropName, new State(State.EDGE_UP));
1403 for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
1404 if (isNodeConnectorEnabled(nodeConnector)) {
1405 service.notifyNodeConnector(nodeConnector, UpdateType.ADDED,
1411 private void spanAwareNotify(ISpanAware service) {
1412 for (Node node : getNodes()) {
1413 for (SpanConfig conf : getSpanConfigList(node)) {
1414 service.spanUpdate(node, conf.getPortArrayList(), true);
1419 private void registerWithOSGIConsole() {
1420 BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass())
1421 .getBundleContext();
1422 bundleContext.registerService(CommandProvider.class.getName(), this,
1427 public Boolean isNodeConnectorEnabled(NodeConnector nodeConnector) {
1428 if (nodeConnector == null)
1431 Config config = (Config) getNodeConnectorProp(nodeConnector,
1432 Config.ConfigPropName);
1433 State state = (State) getNodeConnectorProp(nodeConnector,
1434 State.StatePropName);
1435 return ((config != null) && (config.getValue() == Config.ADMIN_UP)
1436 && (state != null) && (state.getValue() == State.EDGE_UP));
1440 public String getHelp() {
1441 StringBuffer help = new StringBuffer();
1442 help.append("---Switch Manager---\n");
1443 help.append("\t pns - Print connected nodes\n");
1444 help.append("\t pncs <node id> - Print node connectors for a given node\n");
1445 help.append("\t pencs <node id> - Print enabled node connectors for a given node\n");
1446 help.append("\t pdm <node id> - Print switch ports in device map\n");
1447 help.append("\t snt <node id> <tier> - Set node tier number\n");
1448 help.append("\t hostRefresh <on/off/?> - Enable/Disable/Query host refresh\n");
1449 help.append("\t hostRetry <count> - Set host retry count\n");
1450 return help.toString();
1453 public void _pns(CommandInterpreter ci) {
1454 ci.println(" Node Type Name Tier");
1455 if (nodeProps == null) {
1458 Set<Node> nodeSet = nodeProps.keySet();
1459 if (nodeSet == null) {
1462 for (Node node : nodeSet) {
1463 Description desc = ((Description) getNodeProp(node,
1464 Description.propertyName));
1465 Tier tier = ((Tier) getNodeProp(node, Tier.TierPropName));
1466 String nodeName = (desc == null) ? "" : desc.getValue();
1467 int tierNum = (tier == null) ? 0 : tier.getValue();
1468 ci.println(node + " " + node.getType() + " "
1469 + nodeName + " " + tierNum);
1471 ci.println("Total number of Nodes: " + nodeSet.size());
1474 public void _pencs(CommandInterpreter ci) {
1475 String st = ci.nextArgument();
1477 ci.println("Please enter node id");
1480 Long id = Long.decode(st);
1482 Node node = NodeCreator.createOFNode(id);
1483 Set<NodeConnector> nodeConnectorSet = getUpNodeConnectors(node);
1484 if (nodeConnectorSet == null) {
1487 for (NodeConnector nodeConnector : nodeConnectorSet) {
1488 if (nodeConnector == null) {
1491 ci.println(nodeConnector);
1493 ci.println("Total number of NodeConnectors: " + nodeConnectorSet.size());
1496 public void _pncs(CommandInterpreter ci) {
1497 String st = ci.nextArgument();
1499 ci.println("Please enter node id");
1502 Long id = Long.decode(st);
1504 ci.println(" NodeConnector BandWidth(Gbps) Admin State");
1505 Node node = NodeCreator.createOFNode(id);
1506 Set<NodeConnector> nodeConnectorSet = getNodeConnectors(node);
1507 if (nodeConnectorSet == null) {
1510 for (NodeConnector nodeConnector : nodeConnectorSet) {
1511 if (nodeConnector == null) {
1514 Map<String, Property> propMap = getNodeConnectorProps(nodeConnector);
1515 Bandwidth bw = (Bandwidth) propMap.get(Bandwidth.BandwidthPropName);
1516 Config config = (Config) propMap.get(Config.ConfigPropName);
1517 State state = (State) propMap.get(State.StatePropName);
1518 String out = nodeConnector + " ";
1519 out += (bw != null) ? bw.getValue() / Math.pow(10, 9) : " ";
1521 out += (config != null) ? config.getValue() : " ";
1523 out += (state != null) ? state.getValue() : " ";
1526 ci.println("Total number of NodeConnectors: " + nodeConnectorSet.size());
1529 public void _pdm(CommandInterpreter ci) {
1530 String st = ci.nextArgument();
1532 ci.println("Please enter node id");
1535 Object id = Long.decode(st);
1536 Switch sw = getSwitchByNode(NodeCreator.createOFNode((Long) id));
1538 ci.println(" NodeConnector Name");
1542 Set<NodeConnector> nodeConnectorSet = sw.getNodeConnectors();
1543 String nodeConnectorName;
1544 if (nodeConnectorSet != null && nodeConnectorSet.size() > 0) {
1545 for (NodeConnector nodeConnector : nodeConnectorSet) {
1546 Map<String, Property> propMap = getNodeConnectorProps(nodeConnector);
1547 nodeConnectorName = (propMap == null) ? null : ((Name) propMap
1548 .get(Name.NamePropName)).getValue();
1549 if (nodeConnectorName != null) {
1550 Node node = nodeConnector.getNode();
1551 if (!node.equals(getNode((Long) id))) {
1552 log.debug("node not match {} {}", node,
1553 getNode((Long) id));
1555 Map<String, NodeConnector> map = nodeConnectorNames
1558 NodeConnector nc = map.get(nodeConnectorName);
1560 log.debug("no nodeConnector named {}",
1562 } else if (!nc.equals(nodeConnector)) {
1563 log.debug("nodeConnector not match {} {}", nc,
1569 ci.println(nodeConnector
1571 + ((nodeConnectorName == null) ? "" : nodeConnectorName)
1572 + "(" + nodeConnector.getID() + ")");
1574 ci.println("Total number of NodeConnectors: "
1575 + nodeConnectorSet.size());
1579 public void _snt(CommandInterpreter ci) {
1580 String st = ci.nextArgument();
1582 ci.println("Please enter node id");
1585 Long id = Long.decode(st);
1587 Node node = NodeCreator.createOFNode(id);
1589 st = ci.nextArgument();
1591 ci.println("Please enter tier number");
1594 Integer tid = Integer.decode(st);
1595 Tier tier = new Tier(tid);
1596 setNodeProp(node, tier);
1599 public void _hostRefresh(CommandInterpreter ci) {
1600 String mode = ci.nextArgument();
1602 ci.println("expecting on/off/?");
1605 if (mode.toLowerCase().equals("on"))
1607 else if (mode.toLowerCase().equals("off"))
1608 hostRefresh = false;
1609 else if (mode.equals("?")) {
1611 ci.println("host refresh is ON");
1613 ci.println("host refresh is OFF");
1615 ci.println("expecting on/off/?");
1619 public void _hostRetry(CommandInterpreter ci) {
1620 String retry = ci.nextArgument();
1621 if (retry == null) {
1622 ci.println("Please enter a valid number. Current retry count is "
1627 hostRetryCount = Integer.parseInt(retry);
1628 } catch (Exception e) {
1629 ci.println("Please enter a valid number");
1635 public byte[] getNodeMAC(Node node) {
1636 if (node.getType().equals(Node.NodeIDType.OPENFLOW)) {
1637 byte[] gmac = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
1638 long dpid = (Long) node.getID();
1640 for (short i = 0; i < 6; i++) {
1641 gmac[5 - i] = (byte) dpid;
1650 public boolean isSpecial(NodeConnector p) {
1651 if (p.getType().equals(NodeConnectorIDType.CONTROLLER)
1652 || p.getType().equals(NodeConnectorIDType.ALL)
1653 || p.getType().equals(NodeConnectorIDType.SWSTACK)
1654 || p.getType().equals(NodeConnectorIDType.HWPATH)) {
1661 * Add span configuration to local cache and notify clients
1663 private void addSpanPorts(Node node, List<NodeConnector> nodeConncetors) {
1664 List<NodeConnector> ncLists = new ArrayList<NodeConnector>();
1666 for (NodeConnector nodeConnector : nodeConncetors) {
1667 if (!spanNodeConnectors.contains(nodeConnector)) {
1668 ncLists.add(nodeConnector);
1672 if (ncLists.size() > 0) {
1673 spanNodeConnectors.addAll(ncLists);
1674 notifySpanPortChange(node, ncLists, true);
1678 private void addSpanPorts(Node node) {
1679 for (SpanConfig conf : getSpanConfigList(node)) {
1680 addSpanPorts(node, conf.getPortArrayList());
1684 private void addSpanPort(NodeConnector nodeConncetor) {
1685 List<NodeConnector> ncLists = new ArrayList<NodeConnector>();
1686 ncLists.add(nodeConncetor);
1687 addSpanPorts(nodeConncetor.getNode(), ncLists);
1691 * Remove span configuration to local cache and notify clients
1693 private void removeSpanPorts(Node node, List<NodeConnector> nodeConncetors) {
1694 List<NodeConnector> ncLists = new ArrayList<NodeConnector>();
1696 for (NodeConnector nodeConnector : nodeConncetors) {
1697 if (!spanNodeConnectors.contains(nodeConnector)) {
1698 ncLists.add(nodeConnector);
1702 if (ncLists.size() > 0) {
1703 spanNodeConnectors.removeAll(ncLists);
1704 notifySpanPortChange(node, ncLists, false);
1708 private void removeSpanPorts(Node node) {
1709 for (SpanConfig conf : getSpanConfigList(node)) {
1710 addSpanPorts(node, conf.getPortArrayList());
1714 private void removeSpanPort(NodeConnector nodeConncetor) {
1715 List<NodeConnector> ncLists = new ArrayList<NodeConnector>();
1716 ncLists.add(nodeConncetor);
1717 removeSpanPorts(nodeConncetor.getNode(), ncLists);
1720 private void addNodeProps(Node node, Map<String, Property> propMap) {
1721 if (propMap == null) {
1722 propMap = new HashMap<String, Property>();
1724 nodeProps.put(node, propMap);
1727 private void removeNodeProps(Node node) {
1728 if (getUpNodeConnectors(node).size() == 0) {
1729 nodeProps.remove(node);
1734 public Status saveConfiguration() {
1735 return saveSwitchConfig();
1739 * Creates a Name/Tier/Bandwidth Property object based on given property
1740 * name and value. Other property types are not supported yet.
1743 * Name of the Property
1745 * Value of the Property
1746 * @return {@link org.opendaylight.controller.sal.core.Property}
1749 public Property createProperty(String propName, String propValue) {
1750 if (propName == null) {
1751 log.debug("propName is null");
1754 if (propValue == null) {
1755 log.debug("propValue is null");
1760 if (propName.equalsIgnoreCase(Description.propertyName)) {
1761 return new Description(propValue);
1762 } else if (propName.equalsIgnoreCase(Tier.TierPropName)) {
1763 int tier = Integer.parseInt(propValue);
1764 return new Tier(tier);
1765 } else if (propName.equalsIgnoreCase(Bandwidth.BandwidthPropName)) {
1766 long bw = Long.parseLong(propValue);
1767 return new Bandwidth(bw);
1769 log.debug("Not able to create {} property", propName);
1771 } catch (Exception e) {
1772 log.debug("createProperty caught exception {}", e.getMessage());
1779 public String getNodeDescription(Node node) {
1780 // Check first if user configured a name
1781 SwitchConfig config = getSwitchConfig(node.toString());
1782 if (config != null) {
1783 String configuredDesc = config.getNodeDescription();
1784 if (configuredDesc != null && !configuredDesc.isEmpty()) {
1785 return configuredDesc;
1789 // No name configured by user, get the node advertised name
1790 Description desc = (Description) getNodeProp(node,
1791 Description.propertyName);
1792 return (desc == null /* || desc.getValue().equalsIgnoreCase("none") */) ? ""