3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.controller.switchmanager.internal;
12 import java.io.FileNotFoundException;
13 import java.io.IOException;
14 import java.io.ObjectInputStream;
15 import java.net.InetAddress;
16 import java.net.NetworkInterface;
17 import java.net.SocketException;
18 import java.util.ArrayList;
19 import java.util.Collections;
20 import java.util.Date;
21 import java.util.Dictionary;
22 import java.util.EnumSet;
23 import java.util.Enumeration;
24 import java.util.HashMap;
25 import java.util.HashSet;
26 import java.util.List;
29 import java.util.concurrent.ConcurrentHashMap;
30 import java.util.concurrent.ConcurrentMap;
31 import java.util.concurrent.CopyOnWriteArrayList;
33 import org.apache.felix.dm.Component;
34 import org.eclipse.osgi.framework.console.CommandInterpreter;
35 import org.eclipse.osgi.framework.console.CommandProvider;
36 import org.opendaylight.controller.clustering.services.CacheConfigException;
37 import org.opendaylight.controller.clustering.services.CacheExistException;
38 import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
39 import org.opendaylight.controller.clustering.services.IClusterContainerServices;
40 import org.opendaylight.controller.clustering.services.IClusterServices;
41 import org.opendaylight.controller.configuration.IConfigurationContainerAware;
42 import org.opendaylight.controller.sal.core.Bandwidth;
43 import org.opendaylight.controller.sal.core.Config;
44 import org.opendaylight.controller.sal.core.Description;
45 import org.opendaylight.controller.sal.core.Name;
46 import org.opendaylight.controller.sal.core.Node;
47 import org.opendaylight.controller.sal.core.NodeConnector;
48 import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
49 import org.opendaylight.controller.sal.core.Property;
50 import org.opendaylight.controller.sal.core.State;
51 import org.opendaylight.controller.sal.core.Tier;
52 import org.opendaylight.controller.sal.core.UpdateType;
53 import org.opendaylight.controller.sal.inventory.IInventoryService;
54 import org.opendaylight.controller.sal.inventory.IListenInventoryUpdates;
55 import org.opendaylight.controller.sal.utils.StatusCode;
56 import org.opendaylight.controller.sal.utils.GlobalConstants;
57 import org.opendaylight.controller.sal.utils.IObjectReader;
58 import org.opendaylight.controller.sal.utils.NodeCreator;
59 import org.opendaylight.controller.sal.utils.ObjectReader;
60 import org.opendaylight.controller.sal.utils.ObjectWriter;
61 import org.opendaylight.controller.sal.utils.ServiceHelper;
62 import org.opendaylight.controller.sal.utils.Status;
63 import org.opendaylight.controller.switchmanager.IInventoryListener;
64 import org.opendaylight.controller.switchmanager.ISpanAware;
65 import org.opendaylight.controller.switchmanager.ISwitchManager;
66 import org.opendaylight.controller.switchmanager.ISwitchManagerAware;
67 import org.opendaylight.controller.switchmanager.SpanConfig;
68 import org.opendaylight.controller.switchmanager.Subnet;
69 import org.opendaylight.controller.switchmanager.SubnetConfig;
70 import org.opendaylight.controller.switchmanager.Switch;
71 import org.opendaylight.controller.switchmanager.SwitchConfig;
72 import org.osgi.framework.BundleContext;
73 import org.osgi.framework.FrameworkUtil;
74 import org.slf4j.Logger;
75 import org.slf4j.LoggerFactory;
78 * The class describes SwitchManager which is the central repository of all the
79 * inventory data including nodes, node connectors, properties attached, Layer3
80 * configurations, Span configurations, node configurations, network device
81 * representations viewed by Controller Web applications. One SwitchManager
82 * instance per container of the network. All the node/nodeConnector properties
83 * are maintained in the default container only.
85 public class SwitchManagerImpl implements ISwitchManager,
86 IConfigurationContainerAware, IObjectReader,
87 ICacheUpdateAware<Long, String>, IListenInventoryUpdates,
89 private static Logger log = LoggerFactory
90 .getLogger(SwitchManagerImpl.class);
91 private static String ROOT = GlobalConstants.STARTUPHOME.toString();
92 private static final String SAVE = "Save";
93 private String subnetFileName = null, spanFileName = null,
94 switchConfigFileName = null;
95 private List<NodeConnector> spanNodeConnectors = new CopyOnWriteArrayList<NodeConnector>();
96 private ConcurrentMap<InetAddress, Subnet> subnets; // set of Subnets keyed by the InetAddress
97 private ConcurrentMap<String, SubnetConfig> subnetsConfigList;
98 private ConcurrentMap<Integer, SpanConfig> spanConfigList;
99 private ConcurrentMap<String, SwitchConfig> nodeConfigList; // manually configured parameters for the node, like name and tier
100 private ConcurrentMap<Long, String> configSaveEvent;
101 private ConcurrentMap<Node, Map<String, Property>> nodeProps; // properties are maintained in default container only
102 private ConcurrentMap<NodeConnector, Map<String, Property>> nodeConnectorProps; // properties are maintained in default container only
103 private ConcurrentMap<Node, Map<String, NodeConnector>> nodeConnectorNames;
104 private IInventoryService inventoryService;
105 private Set<ISwitchManagerAware> switchManagerAware = Collections
106 .synchronizedSet(new HashSet<ISwitchManagerAware>());
107 private Set<IInventoryListener> inventoryListeners = Collections
108 .synchronizedSet(new HashSet<IInventoryListener>());
109 private Set<ISpanAware> spanAware = Collections
110 .synchronizedSet(new HashSet<ISpanAware>());
112 private static boolean hostRefresh = true;
113 private int hostRetryCount = 5;
114 private IClusterContainerServices clusterContainerService = null;
115 private String containerName = null;
116 private boolean isDefaultContainer = true;
118 public enum ReasonCode {
119 SUCCESS("Success"), FAILURE("Failure"), INVALID_CONF(
120 "Invalid Configuration"), EXIST("Entry Already Exist"), CONFLICT(
121 "Configuration Conflict with Existing Entry");
125 private ReasonCode(String name) {
129 public String toString() {
134 public void notifySubnetChange(Subnet sub, boolean add) {
135 synchronized (switchManagerAware) {
136 for (Object subAware : switchManagerAware) {
138 ((ISwitchManagerAware) subAware).subnetNotify(sub, add);
139 } catch (Exception e) {
140 log.error("Failed to notify Subnet change", e);
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", e);
159 private void notifyModeChange(Node node, boolean proactive) {
160 synchronized (switchManagerAware) {
161 for (ISwitchManagerAware service : switchManagerAware) {
163 service.modeChangeNotify(node, proactive);
164 } catch (Exception e) {
165 log.error("Failed to notify Subnet change", e);
171 public void startUp() {
172 // Initialize configuration file names
173 subnetFileName = ROOT + "subnets" + this.getContainerName() + ".conf";
174 spanFileName = ROOT + "spanPorts_" + this.getContainerName() + ".conf";
175 switchConfigFileName = ROOT + "switchConfig_" + this.getContainerName()
178 // Instantiate cluster synced variables
183 * Read startup and build database if we have not already gotten the
184 * configurations synced from another node
186 if (subnetsConfigList.isEmpty())
187 loadSubnetConfiguration();
188 if (spanConfigList.isEmpty())
189 loadSpanConfiguration();
190 if (nodeConfigList.isEmpty())
191 loadSwitchConfiguration();
193 MAC = getHardwareMAC();
196 public void shutDown() {
197 destroyCaches(this.getContainerName());
200 @SuppressWarnings("deprecation")
201 private void allocateCaches() {
202 if (this.clusterContainerService == null) {
203 log.info("un-initialized clusterContainerService, can't create cache");
208 clusterContainerService.createCache(
209 "switchmanager.subnetsConfigList", EnumSet
210 .of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
211 clusterContainerService.createCache("switchmanager.spanConfigList",
212 EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
213 clusterContainerService.createCache("switchmanager.nodeConfigList",
214 EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
215 clusterContainerService.createCache("switchmanager.subnets",
216 EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
217 clusterContainerService.createCache(
218 "switchmanager.configSaveEvent", EnumSet
219 .of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
220 clusterContainerService.createCache("switchmanager.nodeProps",
221 EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
222 clusterContainerService.createCache(
223 "switchmanager.nodeConnectorProps", EnumSet
224 .of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
225 clusterContainerService.createCache(
226 "switchmanager.nodeConnectorNames", EnumSet
227 .of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
228 } catch (CacheConfigException cce) {
229 log.error("\nCache configuration invalid - check cache mode");
230 } catch (CacheExistException ce) {
231 log.error("\nCache already exits - destroy and recreate if needed");
235 @SuppressWarnings({ "unchecked", "deprecation" })
236 private void retrieveCaches() {
237 if (this.clusterContainerService == null) {
239 .info("un-initialized clusterContainerService, can't create cache");
243 subnetsConfigList = (ConcurrentMap<String, SubnetConfig>) clusterContainerService
244 .getCache("switchmanager.subnetsConfigList");
245 if (subnetsConfigList == null) {
246 log.error("\nFailed to get cache for subnetsConfigList");
249 spanConfigList = (ConcurrentMap<Integer, SpanConfig>) clusterContainerService
250 .getCache("switchmanager.spanConfigList");
251 if (spanConfigList == null) {
252 log.error("\nFailed to get cache for spanConfigList");
255 nodeConfigList = (ConcurrentMap<String, SwitchConfig>) clusterContainerService
256 .getCache("switchmanager.nodeConfigList");
257 if (nodeConfigList == null) {
258 log.error("\nFailed to get cache for nodeConfigList");
261 subnets = (ConcurrentMap<InetAddress, Subnet>) clusterContainerService
262 .getCache("switchmanager.subnets");
263 if (subnets == null) {
264 log.error("\nFailed to get cache for subnets");
267 configSaveEvent = (ConcurrentMap<Long, String>) clusterContainerService
268 .getCache("switchmanager.configSaveEvent");
269 if (configSaveEvent == null) {
270 log.error("\nFailed to get cache for configSaveEvent");
273 nodeProps = (ConcurrentMap<Node, Map<String, Property>>) clusterContainerService
274 .getCache("switchmanager.nodeProps");
275 if (nodeProps == null) {
276 log.error("\nFailed to get cache for nodeProps");
279 nodeConnectorProps = (ConcurrentMap<NodeConnector, Map<String, Property>>) clusterContainerService
280 .getCache("switchmanager.nodeConnectorProps");
281 if (nodeConnectorProps == null) {
282 log.error("\nFailed to get cache for nodeConnectorProps");
285 nodeConnectorNames = (ConcurrentMap<Node, Map<String, NodeConnector>>) clusterContainerService
286 .getCache("switchmanager.nodeConnectorNames");
287 if (nodeConnectorNames == null) {
288 log.error("\nFailed to get cache for nodeConnectorNames");
292 void nonClusterObjectCreate() {
293 subnetsConfigList = new ConcurrentHashMap<String, SubnetConfig>();
294 spanConfigList = new ConcurrentHashMap<Integer, SpanConfig>();
295 nodeConfigList = new ConcurrentHashMap<String, SwitchConfig>();
296 subnets = new ConcurrentHashMap<InetAddress, Subnet>();
297 configSaveEvent = new ConcurrentHashMap<Long, String>();
298 nodeProps = new ConcurrentHashMap<Node, Map<String, Property>>();
299 nodeConnectorProps = new ConcurrentHashMap<NodeConnector, Map<String, Property>>();
300 nodeConnectorNames = new ConcurrentHashMap<Node, Map<String, NodeConnector>>();
303 @SuppressWarnings("deprecation")
304 private void destroyCaches(String container) {
305 if (this.clusterContainerService == null) {
307 .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, cfgObject
616 notifyModeChange(node, cfgObject.isProactive());
619 } catch (Exception e) {
620 log.debug("updateSwitchConfig: {}", e);
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(conf.getNodeDescription());
744 propMap.put(description.getName(), description);
745 Property tier = new Tier(Integer.parseInt(conf.getTier()));
746 propMap.put(tier.getName(), tier);
747 proactiveForwarding = conf.isProactive();
752 addNodeProps(node, propMap);
754 // check if span ports are configed
757 // notify node listeners
758 notifyNode(node, UpdateType.ADDED, propMap);
760 // notify proactive mode forwarding
761 if (proactiveForwarding) {
762 notifyModeChange(node, true);
766 private void removeNode(Node node) {
767 log.trace("{} removed", node);
768 if (nodeProps == null)
770 nodeProps.remove(node);
772 // check if span ports need to be cleaned up
773 removeSpanPorts(node);
775 /* notify node listeners */
776 notifyNode(node, UpdateType.REMOVED, null);
779 private void updateNode(Node node, Set<Property> props) {
780 log.trace("{} updated", node);
781 if (nodeProps == null) {
785 Map<String, Property> propMap;
786 if (nodeProps.get(node) != null) {
787 propMap = nodeProps.get(node);
789 propMap = new HashMap<String, Property>();
792 // copy node properties from plugin
794 for (Property prop : props) {
795 propMap.put(prop.getName(), prop);
798 addNodeProps(node, propMap);
800 /* notify node listeners */
801 notifyNode(node, UpdateType.CHANGED, propMap);
805 public void updateNode(Node node, UpdateType type, Set<Property> props) {
808 addNode(node, props);
811 updateNode(node, props);
822 public void updateNodeConnector(NodeConnector nodeConnector,
823 UpdateType type, Set<Property> props) {
824 Node node = nodeConnector.getNode();
825 Map<String, Property> propMap = new HashMap<String, Property>();
827 log.trace("{} {}", nodeConnector, type);
829 if (nodeConnectorProps == null) {
837 for (Property prop : props) {
838 addNodeConnectorProp(nodeConnector, prop);
839 propMap.put(prop.getName(), prop);
842 addNodeConnectorProp(nodeConnector, null);
843 addNodeProps(node, null);
846 // check if span is configed
847 addSpanPort(nodeConnector);
850 removeNodeConnectorAllProps(nodeConnector);
851 removeNodeProps(node);
853 // clean up span config
854 removeSpanPort(nodeConnector);
860 notifyNodeConnector(nodeConnector, type, propMap);
864 public Set<Node> getNodes() {
865 return (nodeProps != null) ? new HashSet<Node>(nodeProps.keySet())
870 * test utility function which assumes all nodes are OF nodes
872 private Node getNode(Long id) {
873 Set<Node> nodes = getNodes();
875 for (Node node : nodes) {
876 if (id.equals((Long)node.getID())) {
885 * Returns a copy of a list of properties for a given node
888 * @see org.opendaylight.controller.switchmanager.ISwitchManager#getNodeProps(org.opendaylight.controller.sal.core.Node)
891 public Map<String, Property> getNodeProps(Node node) {
892 if (isDefaultContainer) {
893 Map<String, Property> rv = null;
894 if (this.nodeProps != null) {
895 rv = this.nodeProps.get(node);
897 /* make a copy of it */
898 rv = new HashMap<String, Property>(rv);
903 // get it from default container
904 ISwitchManager defaultSwitchManager = (ISwitchManager) ServiceHelper
905 .getInstance(ISwitchManager.class, GlobalConstants.DEFAULT
907 return defaultSwitchManager.getNodeProps(node);
912 public Property getNodeProp(Node node, String propName) {
913 Map<String, Property> propMap = getNodeProps(node);
914 return (propMap != null) ? propMap.get(propName) : null;
918 public void setNodeProp(Node node, Property prop) {
919 /* Get a copy of the property map */
920 Map<String, Property> propMap = getNodeProps(node);
924 propMap.put(prop.getName(), prop);
925 this.nodeProps.put(node, propMap);
929 public Status removeNodeProp(Node node, String propName) {
930 Map<String, Property> propMap = getNodeProps(node);
931 if (propMap != null) {
932 propMap.remove(propName);
933 this.nodeProps.put(node, propMap);
935 return new Status(StatusCode.SUCCESS, null);
939 public Status removeNodeAllProps(Node node) {
940 this.nodeProps.remove(node);
941 return new Status(StatusCode.SUCCESS, null);
945 public Set<NodeConnector> getUpNodeConnectors(Node node) {
946 if (nodeConnectorProps == null)
949 Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
950 for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
951 if (((Long) nodeConnector.getNode().getID())
952 .longValue() != (Long) node.getID())
954 if (isNodeConnectorEnabled(nodeConnector))
955 nodeConnectorSet.add(nodeConnector);
958 return nodeConnectorSet;
962 public Set<NodeConnector> getNodeConnectors(Node node) {
963 if (nodeConnectorProps == null)
966 Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
967 for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
968 if (((Long) nodeConnector.getNode().getID())
969 .longValue() != (Long) node.getID())
971 nodeConnectorSet.add(nodeConnector);
974 return nodeConnectorSet;
978 public Set<NodeConnector> getPhysicalNodeConnectors(Node node) {
979 if (nodeConnectorProps == null)
982 Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
983 for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
984 if (!nodeConnector.getNode().equals(node)
985 || isSpecial(nodeConnector)) {
988 nodeConnectorSet.add(nodeConnector);
991 return nodeConnectorSet;
995 * testing utility function which assumes we are dealing with OF Node nodeconnectors only
997 @SuppressWarnings("unused")
998 private Set<Long> getEnabledNodeConnectorIds(Node node) {
999 Set<Long> ids = new HashSet<Long>();
1000 Set<NodeConnector> nodeConnectors = getUpNodeConnectors(node);
1002 if (nodeConnectors != null) {
1003 for (NodeConnector nodeConnector : nodeConnectors) {
1004 ids.add((Long) nodeConnector.getID());
1012 public Map<String, Property> getNodeConnectorProps(
1013 NodeConnector nodeConnector) {
1014 if (isDefaultContainer) {
1015 Map<String, Property> rv = null;
1016 if (this.nodeConnectorProps != null) {
1017 rv = this.nodeConnectorProps.get(nodeConnector);
1019 rv = new HashMap<String, Property>(rv);
1024 // get it from default container
1025 ISwitchManager defaultSwitchManager = (ISwitchManager) ServiceHelper
1026 .getInstance(ISwitchManager.class, GlobalConstants.DEFAULT
1028 return defaultSwitchManager.getNodeConnectorProps(nodeConnector);
1033 public Property getNodeConnectorProp(NodeConnector nodeConnector,
1035 Map<String, Property> propMap = getNodeConnectorProps(nodeConnector);
1036 return (propMap != null) ? propMap.get(propName) : null;
1039 private byte[] getHardwareMAC() {
1040 Enumeration<NetworkInterface> nis;
1042 nis = NetworkInterface.getNetworkInterfaces();
1043 } catch (SocketException e1) {
1044 e1.printStackTrace();
1048 for (; nis.hasMoreElements();) {
1049 NetworkInterface ni = nis.nextElement();
1051 MAC = ni.getHardwareAddress();
1052 } catch (SocketException e) {
1053 e.printStackTrace();
1063 public byte[] getControllerMAC() {
1068 public boolean isHostRefreshEnabled() {
1073 public int getHostRetryCount() {
1074 return hostRetryCount;
1078 public NodeConnector getNodeConnector(Node node, String nodeConnectorName) {
1079 if (nodeConnectorNames == null)
1082 Map<String, NodeConnector> map = nodeConnectorNames.get(node);
1086 return map.get(nodeConnectorName);
1090 * Adds a node connector and its property if any
1092 * @param nodeConnector {@link org.opendaylight.controller.sal.core.NodeConnector}
1093 * @param propName name of {@link org.opendaylight.controller.sal.core.Property}
1094 * @return success or failed reason
1097 public Status addNodeConnectorProp(NodeConnector nodeConnector, Property prop) {
1098 Map<String, Property> propMap = getNodeConnectorProps(nodeConnector);
1100 if (propMap == null) {
1101 propMap = new HashMap<String, Property>();
1104 // Just add the nodeConnector if prop is not available (in a non-default container)
1106 nodeConnectorProps.put(nodeConnector, propMap);
1107 return new Status(StatusCode.SUCCESS, null);
1110 propMap.put(prop.getName(), prop);
1111 nodeConnectorProps.put(nodeConnector, propMap);
1113 if (prop.getName().equals(Name.NamePropName)) {
1114 if (nodeConnectorNames != null) {
1115 Node node = nodeConnector.getNode();
1116 Map<String, NodeConnector> map = nodeConnectorNames.get(node);
1118 map = new HashMap<String, NodeConnector>();
1121 map.put(((Name) prop).getValue(), nodeConnector);
1122 nodeConnectorNames.put(node, map);
1126 return new Status(StatusCode.SUCCESS, null);
1130 * Removes one property of a node connector
1132 * @param nodeConnector {@link org.opendaylight.controller.sal.core.NodeConnector}
1133 * @param propName name of {@link org.opendaylight.controller.sal.core.Property}
1134 * @return success or failed reason
1137 public Status removeNodeConnectorProp(NodeConnector nodeConnector, String propName) {
1138 Map<String, Property> propMap = getNodeConnectorProps(nodeConnector);
1140 if (propMap == null) {
1141 /* Nothing to remove */
1142 return new Status(StatusCode.SUCCESS, null);
1145 propMap.remove(propName);
1146 nodeConnectorProps.put(nodeConnector, propMap);
1148 if (nodeConnectorNames != null) {
1149 Name name = ((Name) getNodeConnectorProp(nodeConnector,
1150 Name.NamePropName));
1152 Node node = nodeConnector.getNode();
1153 Map<String, NodeConnector> map = nodeConnectorNames.get(node);
1155 map.remove(name.getValue());
1156 nodeConnectorNames.put(node, map);
1161 return new Status(StatusCode.SUCCESS, null);
1165 * Removes all the properties of a node connector
1167 * @param nodeConnector {@link org.opendaylight.controller.sal.core.NodeConnector}
1168 * @return success or failed reason
1171 public Status removeNodeConnectorAllProps(NodeConnector nodeConnector) {
1172 if (nodeConnectorNames != null) {
1173 Name name = ((Name) getNodeConnectorProp(nodeConnector,
1174 Name.NamePropName));
1176 Node node = nodeConnector.getNode();
1177 Map<String, NodeConnector> map = nodeConnectorNames.get(node);
1179 map.remove(name.getValue());
1180 nodeConnectorNames.put(node, map);
1184 nodeConnectorProps.remove(nodeConnector);
1186 return new Status(StatusCode.SUCCESS, null);
1190 * Function called by the dependency manager when all the required
1191 * dependencies are satisfied
1194 void init(Component c) {
1195 Dictionary<?, ?> props = c.getServiceProperties();
1196 if (props != null) {
1197 this.containerName = (String) props.get("containerName");
1198 log.trace("Running containerName:" + this.containerName);
1200 // In the Global instance case the containerName is empty
1201 this.containerName = "";
1203 isDefaultContainer = containerName.equals(GlobalConstants.DEFAULT
1210 * Function called by the dependency manager when at least one
1211 * dependency become unsatisfied or when the component is shutting
1212 * down because for example bundle is being stopped.
1220 * Function called by dependency manager after "init ()" is called
1221 * and after the services provided by the class are registered in
1222 * the service registry
1227 registerWithOSGIConsole();
1231 * Function called after registered the
1232 * service in OSGi service registry.
1235 // solicit for existing inventories
1240 * Function called by the dependency manager before the services
1241 * exported by the component are unregistered, this will be
1242 * followed by a "destroy ()" calls
1248 public void setInventoryService(IInventoryService service) {
1249 log.trace("Got inventory service set request {}", service);
1250 this.inventoryService = service;
1252 // solicit for existing inventories
1256 public void unsetInventoryService(IInventoryService service) {
1257 log.trace("Got a service UNset request");
1258 this.inventoryService = null;
1260 // clear existing inventories
1264 public void setSwitchManagerAware(ISwitchManagerAware service) {
1265 log.trace("Got inventory service set request {}", service);
1266 if (this.switchManagerAware != null) {
1267 this.switchManagerAware.add(service);
1270 // bulk update for newly joined
1271 switchManagerAwareNotify(service);
1274 public void unsetSwitchManagerAware(ISwitchManagerAware service) {
1275 log.trace("Got a service UNset request");
1276 if (this.switchManagerAware != null) {
1277 this.switchManagerAware.remove(service);
1281 public void setInventoryListener(IInventoryListener service) {
1282 log.trace("Got inventory listener set request {}", service);
1283 if (this.inventoryListeners != null) {
1284 this.inventoryListeners.add(service);
1287 // bulk update for newly joined
1288 bulkUpdateService(service);
1291 public void unsetInventoryListener(IInventoryListener service) {
1292 log.trace("Got a service UNset request");
1293 if (this.inventoryListeners != null) {
1294 this.inventoryListeners.remove(service);
1298 public void setSpanAware(ISpanAware service) {
1299 log.trace("Got SpanAware set request {}", service);
1300 if (this.spanAware != null) {
1301 this.spanAware.add(service);
1304 // bulk update for newly joined
1305 spanAwareNotify(service);
1308 public void unsetSpanAware(ISpanAware service) {
1309 log.trace("Got a service UNset request");
1310 if (this.spanAware != null) {
1311 this.spanAware.remove(service);
1315 void setClusterContainerService(IClusterContainerServices s) {
1316 log.trace("Cluster Service set");
1317 this.clusterContainerService = s;
1320 void unsetClusterContainerService(IClusterContainerServices s) {
1321 if (this.clusterContainerService == s) {
1322 log.trace("Cluster Service removed!");
1323 this.clusterContainerService = null;
1327 private void getInventories() {
1328 if (inventoryService == null) {
1329 log.trace("inventory service not avaiable");
1333 nodeProps = this.inventoryService.getNodeProps();
1334 Set<Node> nodeSet = nodeProps.keySet();
1335 if (nodeSet != null) {
1336 for (Node node : nodeSet) {
1337 addNode(node, null);
1341 nodeConnectorProps = inventoryService.getNodeConnectorProps();
1344 private void clearInventories() {
1346 nodeConnectorProps.clear();
1347 nodeConnectorNames.clear();
1348 spanNodeConnectors.clear();
1351 private void notifyNode(Node node, UpdateType type,
1352 Map<String, Property> propMap) {
1353 synchronized (inventoryListeners) {
1354 for (IInventoryListener service : inventoryListeners) {
1355 service.notifyNode(node, type, propMap);
1360 private void notifyNodeConnector(NodeConnector nodeConnector,
1361 UpdateType type, Map<String, Property> propMap) {
1362 synchronized (inventoryListeners) {
1363 for (IInventoryListener service : inventoryListeners) {
1364 service.notifyNodeConnector(nodeConnector, type, propMap);
1370 * For those joined late, bring them up-to-date.
1372 private void switchManagerAwareNotify(ISwitchManagerAware service) {
1373 for (Subnet sub : subnets.values()) {
1374 service.subnetNotify(sub, true);
1377 for (Node node : getNodes()) {
1378 SwitchConfig sc = getSwitchConfig(node.toString());
1379 if ((sc != null) && isDefaultContainer) {
1380 service.modeChangeNotify(node, sc.isProactive());
1385 private void bulkUpdateService(IInventoryListener service) {
1386 for (Node node : getNodes()) {
1387 service.notifyNode(node, UpdateType.ADDED, null);
1390 Map<String, Property> propMap = new HashMap<String, Property>();
1391 propMap.put(State.StatePropName, new State(State.EDGE_UP));
1392 for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
1393 if (isNodeConnectorEnabled(nodeConnector)) {
1394 service.notifyNodeConnector(nodeConnector, UpdateType.ADDED,
1400 private void spanAwareNotify(ISpanAware service) {
1401 for (Node node : getNodes()) {
1402 for (SpanConfig conf : getSpanConfigList(node)) {
1403 service.spanUpdate(node, conf.getPortArrayList(), true);
1408 private void registerWithOSGIConsole() {
1409 BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass())
1410 .getBundleContext();
1411 bundleContext.registerService(CommandProvider.class.getName(), this,
1416 public Boolean isNodeConnectorEnabled(NodeConnector nodeConnector) {
1417 if (nodeConnector == null)
1420 Config config = (Config) getNodeConnectorProp(nodeConnector,
1421 Config.ConfigPropName);
1422 State state = (State) getNodeConnectorProp(nodeConnector,
1423 State.StatePropName);
1424 return ((config != null) && (config.getValue() == Config.ADMIN_UP)
1425 && (state != null) && (state.getValue() == State.EDGE_UP));
1429 public String getHelp() {
1430 StringBuffer help = new StringBuffer();
1431 help.append("---Switch Manager---\n");
1432 help.append("\t pns - Print connected nodes\n");
1434 .append("\t pncs <node id> - Print node connectors for a given node\n");
1436 .append("\t pencs <node id> - Print enabled node connectors for a given node\n");
1438 .append("\t pdm <node id> - Print switch ports in device map\n");
1439 help.append("\t snt <node id> <tier> - Set node tier number\n");
1441 .append("\t hostRefresh <on/off/?> - Enable/Disable/Query host refresh\n");
1442 help.append("\t hostRetry <count> - Set host retry count\n");
1443 return help.toString();
1446 public void _pns(CommandInterpreter ci) {
1448 .println(" Node Type Name Tier");
1449 if (nodeProps == null) {
1452 Set<Node> nodeSet = nodeProps.keySet();
1453 if (nodeSet == null) {
1456 for (Node node : nodeSet) {
1457 Description desc = ((Description) getNodeProp(node, Description.propertyName));
1458 Tier tier = ((Tier) getNodeProp(node, Tier.TierPropName));
1459 String nodeName = (desc == null) ? "" : desc.getValue();
1460 int tierNum = (tier == null) ? 0 : tier.getValue();
1461 ci.println(node + " " + node.getType()
1462 + " " + nodeName + " " + tierNum);
1466 public void _pencs(CommandInterpreter ci) {
1467 String st = ci.nextArgument();
1469 ci.println("Please enter node id");
1472 Long id = Long.decode(st);
1474 Node node = NodeCreator.createOFNode(id);
1475 Set<NodeConnector> nodeConnectorSet = getUpNodeConnectors(node);
1476 if (nodeConnectorSet == null) {
1479 for (NodeConnector nodeConnector : nodeConnectorSet) {
1480 if (nodeConnector == null) {
1483 ci.println(nodeConnector);
1487 public void _pncs(CommandInterpreter ci) {
1488 String st = ci.nextArgument();
1490 ci.println("Please enter node id");
1493 Long id = Long.decode(st);
1495 ci.println(" NodeConnector BandWidth(Gbps) Admin State");
1496 Node node = NodeCreator.createOFNode(id);
1497 Set<NodeConnector> nodeConnectorSet = getNodeConnectors(node);
1498 if (nodeConnectorSet == null) {
1501 for (NodeConnector nodeConnector : nodeConnectorSet) {
1502 if (nodeConnector == null) {
1505 Map<String, Property> propMap = getNodeConnectorProps(nodeConnector);
1506 Bandwidth bw = (Bandwidth) propMap.get(Bandwidth.BandwidthPropName);
1507 Config config = (Config) propMap.get(Config.ConfigPropName);
1508 State state = (State) propMap.get(State.StatePropName);
1509 String out = nodeConnector + " ";
1510 out += (bw != null) ? bw.getValue() / Math.pow(10, 9) : " ";
1512 out += (config != null) ? config.getValue() : " ";
1514 out += (state != null) ? state.getValue() : " ";
1519 public void _pdm(CommandInterpreter ci) {
1520 String st = ci.nextArgument();
1522 ci.println("Please enter node id");
1525 Object id = Long.decode(st);
1526 Switch sw = getSwitchByNode(NodeCreator.createOFNode((Long) id));
1529 .println(" NodeConnector Name");
1533 Set<NodeConnector> nodeConnectorSet = sw.getNodeConnectors();
1534 String nodeConnectorName;
1535 if (nodeConnectorSet != null && nodeConnectorSet.size() > 0) {
1536 for (NodeConnector nodeConnector : nodeConnectorSet) {
1537 Map<String, Property> propMap = getNodeConnectorProps(nodeConnector);
1538 nodeConnectorName = (propMap == null) ? null : ((Name) propMap
1539 .get(Name.NamePropName)).getValue();
1540 if (nodeConnectorName != null) {
1541 Node node = nodeConnector.getNode();
1542 if (!node.equals(getNode((Long) id))) {
1543 log.debug("node not match {} {}", node,
1544 getNode((Long) id));
1546 Map<String, NodeConnector> map = nodeConnectorNames
1549 NodeConnector nc = map.get(nodeConnectorName);
1551 log.debug("no nodeConnector named {}",
1553 } else if (!nc.equals(nodeConnector)) {
1554 log.debug("nodeConnector not match {} {}", nc,
1561 .println(nodeConnector
1563 + ((nodeConnectorName == null) ? ""
1564 : nodeConnectorName) + "("
1565 + nodeConnector.getID() + ")");
1570 public void _snt(CommandInterpreter ci) {
1571 String st = ci.nextArgument();
1573 ci.println("Please enter node id");
1576 Long id = Long.decode(st);
1578 Node node = NodeCreator.createOFNode(id);
1580 st = ci.nextArgument();
1582 ci.println("Please enter tier number");
1585 Integer tid = Integer.decode(st);
1586 Tier tier = new Tier(tid);
1587 setNodeProp(node, tier);
1590 public void _hostRefresh(CommandInterpreter ci) {
1591 String mode = ci.nextArgument();
1593 ci.println("expecting on/off/?");
1596 if (mode.toLowerCase().equals("on"))
1598 else if (mode.toLowerCase().equals("off"))
1599 hostRefresh = false;
1600 else if (mode.equals("?")) {
1602 ci.println("host refresh is ON");
1604 ci.println("host refresh is OFF");
1606 ci.println("expecting on/off/?");
1610 public void _hostRetry(CommandInterpreter ci) {
1611 String retry = ci.nextArgument();
1612 if (retry == null) {
1613 ci.println("Please enter a valid number. Current retry count is "
1618 hostRetryCount = Integer.parseInt(retry);
1619 } catch (Exception e) {
1620 ci.println("Please enter a valid number");
1626 public byte[] getNodeMAC(Node node) {
1627 if (node.getType().equals(Node.NodeIDType.OPENFLOW)) {
1628 byte[] gmac = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
1629 long dpid = (Long) node.getID();
1631 for (short i = 0; i < 6; i++) {
1632 gmac[5 - i] = (byte) dpid;
1641 public boolean isSpecial(NodeConnector p) {
1642 if (p.getType().equals(NodeConnectorIDType.CONTROLLER) ||
1643 p.getType().equals(NodeConnectorIDType.ALL) ||
1644 p.getType().equals(NodeConnectorIDType.SWSTACK) ||
1645 p.getType().equals(NodeConnectorIDType.HWPATH)) {
1652 * Add span configuration to local cache and notify clients
1654 private void addSpanPorts(Node node, List<NodeConnector> nodeConncetors) {
1655 List<NodeConnector> ncLists = new ArrayList<NodeConnector>();
1657 for (NodeConnector nodeConnector : nodeConncetors) {
1658 if (!spanNodeConnectors.contains(nodeConnector)) {
1659 ncLists.add(nodeConnector);
1663 if (ncLists.size() > 0) {
1664 spanNodeConnectors.addAll(ncLists);
1665 notifySpanPortChange(node, ncLists, true);
1669 private void addSpanPorts(Node node) {
1670 for (SpanConfig conf : getSpanConfigList(node)) {
1671 addSpanPorts(node, conf.getPortArrayList());
1675 private void addSpanPort(NodeConnector nodeConncetor) {
1676 List<NodeConnector> ncLists = new ArrayList<NodeConnector>();
1677 ncLists.add(nodeConncetor);
1678 addSpanPorts(nodeConncetor.getNode(), ncLists);
1682 * Remove span configuration to local cache and notify clients
1684 private void removeSpanPorts(Node node, List<NodeConnector> nodeConncetors) {
1685 List<NodeConnector> ncLists = new ArrayList<NodeConnector>();
1687 for (NodeConnector nodeConnector : nodeConncetors) {
1688 if (!spanNodeConnectors.contains(nodeConnector)) {
1689 ncLists.add(nodeConnector);
1693 if (ncLists.size() > 0) {
1694 spanNodeConnectors.removeAll(ncLists);
1695 notifySpanPortChange(node, ncLists, false);
1699 private void removeSpanPorts(Node node) {
1700 for (SpanConfig conf : getSpanConfigList(node)) {
1701 addSpanPorts(node, conf.getPortArrayList());
1705 private void removeSpanPort(NodeConnector nodeConncetor) {
1706 List<NodeConnector> ncLists = new ArrayList<NodeConnector>();
1707 ncLists.add(nodeConncetor);
1708 removeSpanPorts(nodeConncetor.getNode(), ncLists);
1711 private void addNodeProps(Node node, Map<String, Property> propMap) {
1712 if (propMap == null) {
1713 propMap = new HashMap<String, Property>();
1715 nodeProps.put(node, propMap);
1718 private void removeNodeProps(Node node) {
1719 if (getUpNodeConnectors(node).size() == 0) {
1720 nodeProps.remove(node);
1725 public Status saveConfiguration() {
1726 return saveSwitchConfig();
1730 * Creates a Name/Tier/Bandwidth Property object based on given property
1731 * name and value. Other property types are not supported yet.
1733 * @param propName Name of the Property
1734 * @param propValue Value of the Property
1735 * @return {@link org.opendaylight.controller.sal.core.Property}
1738 public Property createProperty(String propName, String propValue) {
1739 if (propName == null) {
1740 log.debug("propName is null");
1743 if (propValue == null) {
1744 log.debug("propValue is null");
1749 if (propName.equalsIgnoreCase(Description.propertyName)) {
1750 return new Description(propValue);
1751 } else if (propName.equalsIgnoreCase(Tier.TierPropName)) {
1752 int tier = Integer.parseInt(propValue);
1753 return new Tier(tier);
1754 } else if (propName.equalsIgnoreCase(Bandwidth.BandwidthPropName)) {
1755 long bw = Long.parseLong(propValue);
1756 return new Bandwidth(bw);
1758 log.debug("Not able to create {} property", propName);
1760 } catch (Exception e) {
1761 log.debug(e.getMessage());
1768 public String getNodeDescription(Node node) {
1769 // Check first if user configured a name
1770 SwitchConfig config = getSwitchConfig(node.getNodeIDString());
1771 if (config != null) {
1772 String configuredDesc = config.getNodeDescription();
1773 if (configuredDesc != null && !configuredDesc.isEmpty()) {
1774 return configuredDesc;
1778 // No name configured by user, get the node advertised name
1779 Description desc = (Description) getNodeProp(node, Description.propertyName);
1780 return (desc == null /*|| desc.getValue().equalsIgnoreCase("none")*/) ?
1781 "" : desc.getValue();