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, props: {}", node, props);
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) {
772 nodeProps.remove(node);
774 // check if span ports need to be cleaned up
775 removeSpanPorts(node);
777 /* notify node listeners */
778 notifyNode(node, UpdateType.REMOVED, null);
781 private void updateNode(Node node, Set<Property> props) {
782 log.trace("{} updated, props: {}", node, props);
783 if (nodeProps == null || !nodeProps.containsKey(node) ||
784 props == null || props.isEmpty()) {
788 Map<String, Property> propMap;
789 if (nodeProps.get(node) != null) {
790 propMap = nodeProps.get(node);
792 propMap = new HashMap<String, Property>();
795 // copy node properties from plugin
797 for (Property prop : props) {
798 propMap.put(prop.getName(), prop);
801 addNodeProps(node, propMap);
803 /* notify node listeners */
804 notifyNode(node, UpdateType.CHANGED, propMap);
808 public void updateNode(Node node, UpdateType type, Set<Property> props) {
811 addNode(node, props);
814 updateNode(node, props);
825 public void updateNodeConnector(NodeConnector nodeConnector,
826 UpdateType type, Set<Property> props) {
827 Node node = nodeConnector.getNode();
828 Map<String, Property> propMap = new HashMap<String, Property>();
830 log.trace("{} {}", nodeConnector, type);
832 if (nodeConnectorProps == null) {
840 for (Property prop : props) {
841 addNodeConnectorProp(nodeConnector, prop);
842 propMap.put(prop.getName(), prop);
845 addNodeConnectorProp(nodeConnector, null);
846 addNodeProps(node, null);
849 // check if span is configed
850 addSpanPort(nodeConnector);
853 removeNodeConnectorAllProps(nodeConnector);
854 removeNodeProps(node);
856 // clean up span config
857 removeSpanPort(nodeConnector);
863 notifyNodeConnector(nodeConnector, type, propMap);
867 public Set<Node> getNodes() {
868 return (nodeProps != null) ? new HashSet<Node>(nodeProps.keySet())
873 * test utility function which assumes all nodes are OF nodes
875 private Node getNode(Long id) {
876 Set<Node> nodes = getNodes();
878 for (Node node : nodes) {
879 if (id.equals((Long) node.getID())) {
888 * Returns a copy of a list of properties for a given node
893 * org.opendaylight.controller.switchmanager.ISwitchManager#getNodeProps
894 * (org.opendaylight.controller.sal.core.Node)
897 public Map<String, Property> getNodeProps(Node node) {
898 if (isDefaultContainer) {
899 Map<String, Property> rv = null;
900 if (this.nodeProps != null) {
901 rv = this.nodeProps.get(node);
903 /* make a copy of it */
904 rv = new HashMap<String, Property>(rv);
909 // get it from default container
910 ISwitchManager defaultSwitchManager = (ISwitchManager) ServiceHelper
911 .getInstance(ISwitchManager.class,
912 GlobalConstants.DEFAULT.toString(), this);
913 return defaultSwitchManager.getNodeProps(node);
918 public Property getNodeProp(Node node, String propName) {
919 Map<String, Property> propMap = getNodeProps(node);
920 return (propMap != null) ? propMap.get(propName) : null;
924 public void setNodeProp(Node node, Property prop) {
925 /* Get a copy of the property map */
926 Map<String, Property> propMap = getNodeProps(node);
930 propMap.put(prop.getName(), prop);
931 this.nodeProps.put(node, propMap);
935 public Status removeNodeProp(Node node, String propName) {
936 Map<String, Property> propMap = getNodeProps(node);
937 if (propMap != null) {
938 propMap.remove(propName);
939 this.nodeProps.put(node, propMap);
941 return new Status(StatusCode.SUCCESS, null);
945 public Status removeNodeAllProps(Node node) {
946 this.nodeProps.remove(node);
947 return new Status(StatusCode.SUCCESS, null);
951 public Set<NodeConnector> getUpNodeConnectors(Node node) {
952 if (nodeConnectorProps == null)
955 Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
956 for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
957 if (((Long) nodeConnector.getNode().getID()).longValue() != (Long) node
960 if (isNodeConnectorEnabled(nodeConnector))
961 nodeConnectorSet.add(nodeConnector);
964 return nodeConnectorSet;
968 public Set<NodeConnector> getNodeConnectors(Node node) {
969 if (nodeConnectorProps == null)
972 Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
973 for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
974 if (((Long) nodeConnector.getNode().getID()).longValue() != (Long) node
977 nodeConnectorSet.add(nodeConnector);
980 return nodeConnectorSet;
984 public Set<NodeConnector> getPhysicalNodeConnectors(Node node) {
985 if (nodeConnectorProps == null)
988 Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
989 for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
990 if (!nodeConnector.getNode().equals(node)
991 || isSpecial(nodeConnector)) {
994 nodeConnectorSet.add(nodeConnector);
997 return nodeConnectorSet;
1001 * testing utility function which assumes we are dealing with OF Node
1002 * nodeconnectors only
1004 @SuppressWarnings("unused")
1005 private Set<Long> getEnabledNodeConnectorIds(Node node) {
1006 Set<Long> ids = new HashSet<Long>();
1007 Set<NodeConnector> nodeConnectors = getUpNodeConnectors(node);
1009 if (nodeConnectors != null) {
1010 for (NodeConnector nodeConnector : nodeConnectors) {
1011 ids.add((Long) nodeConnector.getID());
1019 public Map<String, Property> getNodeConnectorProps(
1020 NodeConnector nodeConnector) {
1021 if (isDefaultContainer) {
1022 Map<String, Property> rv = null;
1023 if (this.nodeConnectorProps != null) {
1024 rv = this.nodeConnectorProps.get(nodeConnector);
1026 rv = new HashMap<String, Property>(rv);
1031 // get it from default container
1032 ISwitchManager defaultSwitchManager = (ISwitchManager) ServiceHelper
1033 .getInstance(ISwitchManager.class,
1034 GlobalConstants.DEFAULT.toString(), this);
1035 return defaultSwitchManager.getNodeConnectorProps(nodeConnector);
1040 public Property getNodeConnectorProp(NodeConnector nodeConnector,
1042 Map<String, Property> propMap = getNodeConnectorProps(nodeConnector);
1043 return (propMap != null) ? propMap.get(propName) : null;
1046 private byte[] getHardwareMAC() {
1047 Enumeration<NetworkInterface> nis;
1049 nis = NetworkInterface.getNetworkInterfaces();
1050 } catch (SocketException e1) {
1055 for (; nis.hasMoreElements();) {
1056 NetworkInterface ni = nis.nextElement();
1058 MAC = ni.getHardwareAddress();
1059 } catch (SocketException e) {
1070 public byte[] getControllerMAC() {
1075 public boolean isHostRefreshEnabled() {
1080 public int getHostRetryCount() {
1081 return hostRetryCount;
1085 public NodeConnector getNodeConnector(Node node, String nodeConnectorName) {
1086 if (nodeConnectorNames == null)
1089 Map<String, NodeConnector> map = nodeConnectorNames.get(node);
1093 return map.get(nodeConnectorName);
1097 * Adds a node connector and its property if any
1099 * @param nodeConnector
1100 * {@link org.opendaylight.controller.sal.core.NodeConnector}
1102 * name of {@link org.opendaylight.controller.sal.core.Property}
1103 * @return success or failed reason
1106 public Status addNodeConnectorProp(NodeConnector nodeConnector,
1108 Map<String, Property> propMap = getNodeConnectorProps(nodeConnector);
1110 if (propMap == null) {
1111 propMap = new HashMap<String, Property>();
1114 // Just add the nodeConnector if prop is not available (in a non-default
1117 nodeConnectorProps.put(nodeConnector, propMap);
1118 return new Status(StatusCode.SUCCESS, null);
1121 propMap.put(prop.getName(), prop);
1122 nodeConnectorProps.put(nodeConnector, propMap);
1124 if (prop.getName().equals(Name.NamePropName)) {
1125 if (nodeConnectorNames != null) {
1126 Node node = nodeConnector.getNode();
1127 Map<String, NodeConnector> map = nodeConnectorNames.get(node);
1129 map = new HashMap<String, NodeConnector>();
1132 map.put(((Name) prop).getValue(), nodeConnector);
1133 nodeConnectorNames.put(node, map);
1137 return new Status(StatusCode.SUCCESS, null);
1141 * Removes one property of a node connector
1143 * @param nodeConnector
1144 * {@link org.opendaylight.controller.sal.core.NodeConnector}
1146 * name of {@link org.opendaylight.controller.sal.core.Property}
1147 * @return success or failed reason
1150 public Status removeNodeConnectorProp(NodeConnector nodeConnector,
1152 Map<String, Property> propMap = getNodeConnectorProps(nodeConnector);
1154 if (propMap == null) {
1155 /* Nothing to remove */
1156 return new Status(StatusCode.SUCCESS, null);
1159 propMap.remove(propName);
1160 nodeConnectorProps.put(nodeConnector, propMap);
1162 if (nodeConnectorNames != null) {
1163 Name name = ((Name) getNodeConnectorProp(nodeConnector,
1164 Name.NamePropName));
1166 Node node = nodeConnector.getNode();
1167 Map<String, NodeConnector> map = nodeConnectorNames.get(node);
1169 map.remove(name.getValue());
1170 nodeConnectorNames.put(node, map);
1175 return new Status(StatusCode.SUCCESS, null);
1179 * Removes all the properties of a node connector
1181 * @param nodeConnector
1182 * {@link org.opendaylight.controller.sal.core.NodeConnector}
1183 * @return success or failed reason
1186 public Status removeNodeConnectorAllProps(NodeConnector nodeConnector) {
1187 if (nodeConnectorNames != null) {
1188 Name name = ((Name) getNodeConnectorProp(nodeConnector,
1189 Name.NamePropName));
1191 Node node = nodeConnector.getNode();
1192 Map<String, NodeConnector> map = nodeConnectorNames.get(node);
1194 map.remove(name.getValue());
1195 nodeConnectorNames.put(node, map);
1199 nodeConnectorProps.remove(nodeConnector);
1201 return new Status(StatusCode.SUCCESS, null);
1205 * Function called by the dependency manager when all the required
1206 * dependencies are satisfied
1209 void init(Component c) {
1210 Dictionary<?, ?> props = c.getServiceProperties();
1211 if (props != null) {
1212 this.containerName = (String) props.get("containerName");
1213 log.trace("Running containerName: {}", this.containerName);
1215 // In the Global instance case the containerName is empty
1216 this.containerName = "";
1218 isDefaultContainer = containerName.equals(GlobalConstants.DEFAULT
1225 * Function called by the dependency manager when at least one dependency
1226 * become unsatisfied or when the component is shutting down because for
1227 * example bundle is being stopped.
1235 * Function called by dependency manager after "init ()" is called and after
1236 * the services provided by the class are registered in the service registry
1241 registerWithOSGIConsole();
1245 * Function called after registered the service in OSGi service registry.
1248 // solicit for existing inventories
1253 * Function called by the dependency manager before the services exported by
1254 * the component are unregistered, this will be followed by a "destroy ()"
1261 public void setInventoryService(IInventoryService service) {
1262 log.trace("Got inventory service set request {}", service);
1263 this.inventoryService = service;
1265 // solicit for existing inventories
1269 public void unsetInventoryService(IInventoryService service) {
1270 log.trace("Got a service UNset request");
1271 this.inventoryService = null;
1273 // clear existing inventories
1277 public void setSwitchManagerAware(ISwitchManagerAware service) {
1278 log.trace("Got inventory service set request {}", service);
1279 if (this.switchManagerAware != null) {
1280 this.switchManagerAware.add(service);
1283 // bulk update for newly joined
1284 switchManagerAwareNotify(service);
1287 public void unsetSwitchManagerAware(ISwitchManagerAware service) {
1288 log.trace("Got a service UNset request");
1289 if (this.switchManagerAware != null) {
1290 this.switchManagerAware.remove(service);
1294 public void setInventoryListener(IInventoryListener service) {
1295 log.trace("Got inventory listener set request {}", service);
1296 if (this.inventoryListeners != null) {
1297 this.inventoryListeners.add(service);
1300 // bulk update for newly joined
1301 bulkUpdateService(service);
1304 public void unsetInventoryListener(IInventoryListener service) {
1305 log.trace("Got a service UNset request");
1306 if (this.inventoryListeners != null) {
1307 this.inventoryListeners.remove(service);
1311 public void setSpanAware(ISpanAware service) {
1312 log.trace("Got SpanAware set request {}", service);
1313 if (this.spanAware != null) {
1314 this.spanAware.add(service);
1317 // bulk update for newly joined
1318 spanAwareNotify(service);
1321 public void unsetSpanAware(ISpanAware service) {
1322 log.trace("Got a service UNset request");
1323 if (this.spanAware != null) {
1324 this.spanAware.remove(service);
1328 void setClusterContainerService(IClusterContainerServices s) {
1329 log.trace("Cluster Service set");
1330 this.clusterContainerService = s;
1333 void unsetClusterContainerService(IClusterContainerServices s) {
1334 if (this.clusterContainerService == s) {
1335 log.trace("Cluster Service removed!");
1336 this.clusterContainerService = null;
1340 private void getInventories() {
1341 if (inventoryService == null) {
1342 log.trace("inventory service not avaiable");
1346 nodeProps = this.inventoryService.getNodeProps();
1347 Set<Node> nodeSet = nodeProps.keySet();
1348 if (nodeSet != null) {
1349 for (Node node : nodeSet) {
1350 addNode(node, null);
1354 nodeConnectorProps = inventoryService.getNodeConnectorProps();
1357 private void clearInventories() {
1359 nodeConnectorProps.clear();
1360 nodeConnectorNames.clear();
1361 spanNodeConnectors.clear();
1364 private void notifyNode(Node node, UpdateType type,
1365 Map<String, Property> propMap) {
1366 synchronized (inventoryListeners) {
1367 for (IInventoryListener service : inventoryListeners) {
1368 service.notifyNode(node, type, propMap);
1373 private void notifyNodeConnector(NodeConnector nodeConnector,
1374 UpdateType type, Map<String, Property> propMap) {
1375 synchronized (inventoryListeners) {
1376 for (IInventoryListener service : inventoryListeners) {
1377 service.notifyNodeConnector(nodeConnector, type, propMap);
1383 * For those joined late, bring them up-to-date.
1385 private void switchManagerAwareNotify(ISwitchManagerAware service) {
1386 for (Subnet sub : subnets.values()) {
1387 service.subnetNotify(sub, true);
1390 for (Node node : getNodes()) {
1391 SwitchConfig sc = getSwitchConfig(node.toString());
1392 if ((sc != null) && isDefaultContainer) {
1393 service.modeChangeNotify(node, sc.isProactive());
1398 private void bulkUpdateService(IInventoryListener service) {
1399 for (Node node : getNodes()) {
1400 service.notifyNode(node, UpdateType.ADDED, null);
1403 Map<String, Property> propMap = new HashMap<String, Property>();
1404 propMap.put(State.StatePropName, new State(State.EDGE_UP));
1405 for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
1406 if (isNodeConnectorEnabled(nodeConnector)) {
1407 service.notifyNodeConnector(nodeConnector, UpdateType.ADDED,
1413 private void spanAwareNotify(ISpanAware service) {
1414 for (Node node : getNodes()) {
1415 for (SpanConfig conf : getSpanConfigList(node)) {
1416 service.spanUpdate(node, conf.getPortArrayList(), true);
1421 private void registerWithOSGIConsole() {
1422 BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass())
1423 .getBundleContext();
1424 bundleContext.registerService(CommandProvider.class.getName(), this,
1429 public Boolean isNodeConnectorEnabled(NodeConnector nodeConnector) {
1430 if (nodeConnector == null)
1433 Config config = (Config) getNodeConnectorProp(nodeConnector,
1434 Config.ConfigPropName);
1435 State state = (State) getNodeConnectorProp(nodeConnector,
1436 State.StatePropName);
1437 return ((config != null) && (config.getValue() == Config.ADMIN_UP)
1438 && (state != null) && (state.getValue() == State.EDGE_UP));
1442 public String getHelp() {
1443 StringBuffer help = new StringBuffer();
1444 help.append("---Switch Manager---\n");
1445 help.append("\t pns - Print connected nodes\n");
1446 help.append("\t pncs <node id> - Print node connectors for a given node\n");
1447 help.append("\t pencs <node id> - Print enabled node connectors for a given node\n");
1448 help.append("\t pdm <node id> - Print switch ports in device map\n");
1449 help.append("\t snt <node id> <tier> - Set node tier number\n");
1450 help.append("\t hostRefresh <on/off/?> - Enable/Disable/Query host refresh\n");
1451 help.append("\t hostRetry <count> - Set host retry count\n");
1452 return help.toString();
1455 public void _pns(CommandInterpreter ci) {
1456 ci.println(" Node Type Name Tier");
1457 if (nodeProps == null) {
1460 Set<Node> nodeSet = nodeProps.keySet();
1461 if (nodeSet == null) {
1464 for (Node node : nodeSet) {
1465 Description desc = ((Description) getNodeProp(node,
1466 Description.propertyName));
1467 Tier tier = ((Tier) getNodeProp(node, Tier.TierPropName));
1468 String nodeName = (desc == null) ? "" : desc.getValue();
1469 int tierNum = (tier == null) ? 0 : tier.getValue();
1470 ci.println(node + " " + node.getType() + " "
1471 + nodeName + " " + tierNum);
1473 ci.println("Total number of Nodes: " + nodeSet.size());
1476 public void _pencs(CommandInterpreter ci) {
1477 String st = ci.nextArgument();
1479 ci.println("Please enter node id");
1483 Node node = Node.fromString(st);
1485 ci.println("Please enter node id");
1489 Set<NodeConnector> nodeConnectorSet = getUpNodeConnectors(node);
1490 if (nodeConnectorSet == null) {
1493 for (NodeConnector nodeConnector : nodeConnectorSet) {
1494 if (nodeConnector == null) {
1497 ci.println(nodeConnector);
1499 ci.println("Total number of NodeConnectors: " + nodeConnectorSet.size());
1502 public void _pncs(CommandInterpreter ci) {
1503 String st = ci.nextArgument();
1505 ci.println("Please enter node id");
1509 Node node = Node.fromString(st);
1511 ci.println("Please enter node id");
1515 ci.println(" NodeConnector BandWidth(Gbps) Admin State");
1516 Set<NodeConnector> nodeConnectorSet = getNodeConnectors(node);
1517 if (nodeConnectorSet == null) {
1520 for (NodeConnector nodeConnector : nodeConnectorSet) {
1521 if (nodeConnector == null) {
1524 Map<String, Property> propMap = getNodeConnectorProps(nodeConnector);
1525 Bandwidth bw = (Bandwidth) propMap.get(Bandwidth.BandwidthPropName);
1526 Config config = (Config) propMap.get(Config.ConfigPropName);
1527 State state = (State) propMap.get(State.StatePropName);
1528 String out = nodeConnector + " ";
1529 out += (bw != null) ? bw.getValue() / Math.pow(10, 9) : " ";
1531 out += (config != null) ? config.getValue() : " ";
1533 out += (state != null) ? state.getValue() : " ";
1536 ci.println("Total number of NodeConnectors: " + nodeConnectorSet.size());
1539 public void _pdm(CommandInterpreter ci) {
1540 String st = ci.nextArgument();
1542 ci.println("Please enter node id");
1546 Node node = Node.fromString(st);
1548 ci.println("Please enter node id");
1552 Switch sw = getSwitchByNode(node);
1554 ci.println(" NodeConnector Name");
1558 Set<NodeConnector> nodeConnectorSet = sw.getNodeConnectors();
1559 String nodeConnectorName;
1560 if (nodeConnectorSet != null && nodeConnectorSet.size() > 0) {
1561 for (NodeConnector nodeConnector : nodeConnectorSet) {
1562 Map<String, Property> propMap = getNodeConnectorProps(nodeConnector);
1563 nodeConnectorName = (propMap == null) ? null : ((Name) propMap
1564 .get(Name.NamePropName)).getValue();
1565 if (nodeConnectorName != null) {
1566 Node nd = nodeConnector.getNode();
1567 if (!nd.equals(node)) {
1568 log.debug("node not match {} {}", nd, node);
1570 Map<String, NodeConnector> map = nodeConnectorNames
1573 NodeConnector nc = map.get(nodeConnectorName);
1575 log.debug("no nodeConnector named {}",
1577 } else if (!nc.equals(nodeConnector)) {
1578 log.debug("nodeConnector not match {} {}", nc,
1584 ci.println(nodeConnector
1586 + ((nodeConnectorName == null) ? "" : nodeConnectorName)
1587 + "(" + nodeConnector.getID() + ")");
1589 ci.println("Total number of NodeConnectors: "
1590 + nodeConnectorSet.size());
1594 public void _snt(CommandInterpreter ci) {
1595 String st = ci.nextArgument();
1597 ci.println("Please enter node id");
1601 Node node = Node.fromString(st);
1603 ci.println("Please enter node id");
1607 st = ci.nextArgument();
1609 ci.println("Please enter tier number");
1612 Integer tid = Integer.decode(st);
1613 Tier tier = new Tier(tid);
1614 setNodeProp(node, tier);
1617 public void _hostRefresh(CommandInterpreter ci) {
1618 String mode = ci.nextArgument();
1620 ci.println("expecting on/off/?");
1623 if (mode.toLowerCase().equals("on"))
1625 else if (mode.toLowerCase().equals("off"))
1626 hostRefresh = false;
1627 else if (mode.equals("?")) {
1629 ci.println("host refresh is ON");
1631 ci.println("host refresh is OFF");
1633 ci.println("expecting on/off/?");
1637 public void _hostRetry(CommandInterpreter ci) {
1638 String retry = ci.nextArgument();
1639 if (retry == null) {
1640 ci.println("Please enter a valid number. Current retry count is "
1645 hostRetryCount = Integer.parseInt(retry);
1646 } catch (Exception e) {
1647 ci.println("Please enter a valid number");
1653 public byte[] getNodeMAC(Node node) {
1654 if (node.getType().equals(Node.NodeIDType.OPENFLOW)) {
1655 byte[] gmac = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
1656 long dpid = (Long) node.getID();
1658 for (short i = 0; i < 6; i++) {
1659 gmac[5 - i] = (byte) dpid;
1668 public boolean isSpecial(NodeConnector p) {
1669 if (p.getType().equals(NodeConnectorIDType.CONTROLLER)
1670 || p.getType().equals(NodeConnectorIDType.ALL)
1671 || p.getType().equals(NodeConnectorIDType.SWSTACK)
1672 || p.getType().equals(NodeConnectorIDType.HWPATH)) {
1679 * Add span configuration to local cache and notify clients
1681 private void addSpanPorts(Node node, List<NodeConnector> nodeConncetors) {
1682 List<NodeConnector> ncLists = new ArrayList<NodeConnector>();
1684 for (NodeConnector nodeConnector : nodeConncetors) {
1685 if (!spanNodeConnectors.contains(nodeConnector)) {
1686 ncLists.add(nodeConnector);
1690 if (ncLists.size() > 0) {
1691 spanNodeConnectors.addAll(ncLists);
1692 notifySpanPortChange(node, ncLists, true);
1696 private void addSpanPorts(Node node) {
1697 for (SpanConfig conf : getSpanConfigList(node)) {
1698 addSpanPorts(node, conf.getPortArrayList());
1702 private void addSpanPort(NodeConnector nodeConncetor) {
1703 List<NodeConnector> ncLists = new ArrayList<NodeConnector>();
1704 ncLists.add(nodeConncetor);
1705 addSpanPorts(nodeConncetor.getNode(), ncLists);
1709 * Remove span configuration to local cache and notify clients
1711 private void removeSpanPorts(Node node, List<NodeConnector> nodeConncetors) {
1712 List<NodeConnector> ncLists = new ArrayList<NodeConnector>();
1714 for (NodeConnector nodeConnector : nodeConncetors) {
1715 if (!spanNodeConnectors.contains(nodeConnector)) {
1716 ncLists.add(nodeConnector);
1720 if (ncLists.size() > 0) {
1721 spanNodeConnectors.removeAll(ncLists);
1722 notifySpanPortChange(node, ncLists, false);
1726 private void removeSpanPorts(Node node) {
1727 for (SpanConfig conf : getSpanConfigList(node)) {
1728 addSpanPorts(node, conf.getPortArrayList());
1732 private void removeSpanPort(NodeConnector nodeConncetor) {
1733 List<NodeConnector> ncLists = new ArrayList<NodeConnector>();
1734 ncLists.add(nodeConncetor);
1735 removeSpanPorts(nodeConncetor.getNode(), ncLists);
1738 private void addNodeProps(Node node, Map<String, Property> propMap) {
1739 if (propMap == null) {
1740 propMap = new HashMap<String, Property>();
1742 nodeProps.put(node, propMap);
1745 private void removeNodeProps(Node node) {
1746 if (getUpNodeConnectors(node).size() == 0) {
1747 nodeProps.remove(node);
1752 public Status saveConfiguration() {
1753 return saveSwitchConfig();
1757 * Creates a Name/Tier/Bandwidth Property object based on given property
1758 * name and value. Other property types are not supported yet.
1761 * Name of the Property
1763 * Value of the Property
1764 * @return {@link org.opendaylight.controller.sal.core.Property}
1767 public Property createProperty(String propName, String propValue) {
1768 if (propName == null) {
1769 log.debug("propName is null");
1772 if (propValue == null) {
1773 log.debug("propValue is null");
1778 if (propName.equalsIgnoreCase(Description.propertyName)) {
1779 return new Description(propValue);
1780 } else if (propName.equalsIgnoreCase(Tier.TierPropName)) {
1781 int tier = Integer.parseInt(propValue);
1782 return new Tier(tier);
1783 } else if (propName.equalsIgnoreCase(Bandwidth.BandwidthPropName)) {
1784 long bw = Long.parseLong(propValue);
1785 return new Bandwidth(bw);
1787 log.debug("Not able to create {} property", propName);
1789 } catch (Exception e) {
1790 log.debug("createProperty caught exception {}", e.getMessage());
1797 public String getNodeDescription(Node node) {
1798 // Check first if user configured a name
1799 SwitchConfig config = getSwitchConfig(node.toString());
1800 if (config != null) {
1801 String configuredDesc = config.getNodeDescription();
1802 if (configuredDesc != null && !configuredDesc.isEmpty()) {
1803 return configuredDesc;
1807 // No name configured by user, get the node advertised name
1808 Description desc = (Description) getNodeProp(node,
1809 Description.propertyName);
1810 return (desc == null /* || desc.getValue().equalsIgnoreCase("none") */) ? ""