import org.opendaylight.controller.sal.core.Bandwidth;
import org.opendaylight.controller.sal.core.Config;
import org.opendaylight.controller.sal.core.Description;
+import org.opendaylight.controller.sal.core.MacAddress;
import org.opendaylight.controller.sal.core.Name;
import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.core.NodeConnector;
import org.opendaylight.controller.sal.core.UpdateType;
import org.opendaylight.controller.sal.inventory.IInventoryService;
import org.opendaylight.controller.sal.inventory.IListenInventoryUpdates;
+import org.opendaylight.controller.sal.utils.HexEncode;
import org.opendaylight.controller.sal.utils.StatusCode;
import org.opendaylight.controller.sal.utils.GlobalConstants;
import org.opendaylight.controller.sal.utils.IObjectReader;
-import org.opendaylight.controller.sal.utils.NodeCreator;
import org.opendaylight.controller.sal.utils.ObjectReader;
import org.opendaylight.controller.sal.utils.ObjectWriter;
import org.opendaylight.controller.sal.utils.ServiceHelper;
* are maintained in the default container only.
*/
public class SwitchManagerImpl implements ISwitchManager,
- IConfigurationContainerAware, IObjectReader,
- ICacheUpdateAware<Long, String>, IListenInventoryUpdates,
- CommandProvider {
+IConfigurationContainerAware, IObjectReader,
+ICacheUpdateAware<Long, String>, IListenInventoryUpdates,
+CommandProvider {
private static Logger log = LoggerFactory
.getLogger(SwitchManagerImpl.class);
private static String ROOT = GlobalConstants.STARTUPHOME.toString();
private static final String SAVE = "Save";
private String subnetFileName = null, spanFileName = null,
switchConfigFileName = null;
- private List<NodeConnector> spanNodeConnectors = new CopyOnWriteArrayList<NodeConnector>();
+ private final List<NodeConnector> spanNodeConnectors = new CopyOnWriteArrayList<NodeConnector>();
private ConcurrentMap<InetAddress, Subnet> subnets; // set of Subnets keyed by the InetAddress
private ConcurrentMap<String, SubnetConfig> subnetsConfigList;
private ConcurrentMap<Integer, SpanConfig> spanConfigList;
private ConcurrentMap<NodeConnector, Map<String, Property>> nodeConnectorProps; // properties are maintained in global container only
private ConcurrentMap<Node, Map<String, NodeConnector>> nodeConnectorNames;
private IInventoryService inventoryService;
- private Set<ISwitchManagerAware> switchManagerAware = Collections
+ private final Set<ISwitchManagerAware> switchManagerAware = Collections
.synchronizedSet(new HashSet<ISwitchManagerAware>());
- private Set<IInventoryListener> inventoryListeners = Collections
+ private final Set<IInventoryListener> inventoryListeners = Collections
.synchronizedSet(new HashSet<IInventoryListener>());
- private Set<ISpanAware> spanAware = Collections
+ private final Set<ISpanAware> spanAware = Collections
.synchronizedSet(new HashSet<ISpanAware>());
private byte[] MAC;
private static boolean hostRefresh = true;
public enum ReasonCode {
SUCCESS("Success"), FAILURE("Failure"), INVALID_CONF(
"Invalid Configuration"), EXIST("Entry Already Exist"), CONFLICT(
- "Configuration Conflict with Existing Entry");
+ "Configuration Conflict with Existing Entry");
- private String name;
+ private final String name;
private ReasonCode(String name) {
this.name = name;
}
+ @Override
public String toString() {
return name;
}
* Read startup and build database if we have not already gotten the
* configurations synced from another node
*/
- if (subnetsConfigList.isEmpty())
+ if (subnetsConfigList.isEmpty()) {
loadSubnetConfiguration();
- if (spanConfigList.isEmpty())
+ }
+ if (spanConfigList.isEmpty()) {
loadSpanConfiguration();
- if (nodeConfigList.isEmpty())
+ }
+ if (nodeConfigList.isEmpty()) {
loadSwitchConfiguration();
+ }
MAC = getHardwareMAC();
}
clusterContainerService.destroyCache("switchmanager.configSaveEvent");
clusterContainerService.destroyCache("switchmanager.nodeProps");
clusterContainerService
- .destroyCache("switchmanager.nodeConnectorProps");
+ .destroyCache("switchmanager.nodeConnectorProps");
clusterContainerService
- .destroyCache("switchmanager.nodeConnectorNames");
+ .destroyCache("switchmanager.nodeConnectorNames");
nonClusterObjectCreate();
}
+ @Override
public List<SubnetConfig> getSubnetsConfigList() {
return new ArrayList<SubnetConfig>(subnetsConfigList.values());
}
return new ArrayList<SwitchConfig>(nodeConfigList.values());
}
+ @Override
public SwitchConfig getSwitchConfig(String switchId) {
return nodeConfigList.get(switchId);
}
public Switch getSwitchByNode(Node node) {
Switch sw = new Switch(node);
sw.setNode(node);
-
+ MacAddress mac = (MacAddress) this.getNodeProp(node,
+ MacAddress.name);
+ if (mac != null) {
+ sw.setDataLayerAddress(mac.getMacAddress());
+ }
Set<NodeConnector> ncSet = getPhysicalNodeConnectors(node);
sw.setNodeConnectors(ncSet);
return sw;
}
+ @Override
public List<Switch> getNetworkDevices() {
Set<Node> nodeSet = getNodes();
List<Switch> swList = new ArrayList<Switch>();
}
subnets.put(conf.getIPnum(), subnet);
} else { // This is the deletion of the whole subnet
- if (subnet == null)
+ if (subnet == null) {
return;
+ }
subnets.remove(conf.getIPnum());
}
}
/**
* Adds Subnet configured in GUI or API3
*/
+ @Override
public Status addSubnet(SubnetConfig conf) {
return this.addRemoveSubnet(conf, true);
}
: null;
}
- /*
- * test utility function which assumes all nodes are OF nodes
- */
- private Node getNode(Long id) {
- Set<Node> nodes = getNodes();
- if (nodes != null) {
- for (Node node : nodes) {
- if (id.equals((Long) node.getID())) {
- return node;
- }
- }
- }
- return null;
- }
-
/*
* Returns a copy of a list of properties for a given node
- *
+ *
* (non-Javadoc)
- *
+ *
* @see
* org.opendaylight.controller.switchmanager.ISwitchManager#getNodeProps
* (org.opendaylight.controller.sal.core.Node)
public void setNodeProp(Node node, Property prop) {
/* Get a copy of the property map */
Map<String, Property> propMap = getNodeProps(node);
- if (propMap == null)
+ if (propMap == null) {
return;
+ }
propMap.put(prop.getName(), prop);
this.nodeProps.put(node, propMap);
@Override
public Set<NodeConnector> getUpNodeConnectors(Node node) {
- if (nodeConnectorProps == null)
+ if (nodeConnectorProps == null) {
return null;
+ }
Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
- if (((Long) nodeConnector.getNode().getID()).longValue() != (Long) node
- .getID())
+ if (!nodeConnector.getNode().equals(node)) {
continue;
- if (isNodeConnectorEnabled(nodeConnector))
+ }
+ if (isNodeConnectorEnabled(nodeConnector)) {
nodeConnectorSet.add(nodeConnector);
+ }
}
return nodeConnectorSet;
@Override
public Set<NodeConnector> getNodeConnectors(Node node) {
- if (nodeConnectorProps == null)
+ if (nodeConnectorProps == null) {
return null;
+ }
Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
- if (((Long) nodeConnector.getNode().getID()).longValue() != (Long) node
- .getID())
+ if (!nodeConnector.getNode().equals(node)) {
continue;
+ }
nodeConnectorSet.add(nodeConnector);
}
@Override
public Set<NodeConnector> getPhysicalNodeConnectors(Node node) {
- if (nodeConnectorProps == null)
+ if (nodeConnectorProps == null) {
return null;
+ }
Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
return nodeConnectorSet;
}
- /*
- * testing utility function which assumes we are dealing with OF Node
- * nodeconnectors only
- */
- @SuppressWarnings("unused")
- private Set<Long> getEnabledNodeConnectorIds(Node node) {
- Set<Long> ids = new HashSet<Long>();
- Set<NodeConnector> nodeConnectors = getUpNodeConnectors(node);
-
- if (nodeConnectors != null) {
- for (NodeConnector nodeConnector : nodeConnectors) {
- ids.add((Long) nodeConnector.getID());
- }
- }
-
- return ids;
- }
-
@Override
public Map<String, Property> getNodeConnectorProps(
NodeConnector nodeConnector) {
@Override
public NodeConnector getNodeConnector(Node node, String nodeConnectorName) {
- if (nodeConnectorNames == null)
+ if (nodeConnectorNames == null) {
return null;
+ }
Map<String, NodeConnector> map = nodeConnectorNames.get(node);
- if (map == null)
+ if (map == null) {
return null;
+ }
return map.get(nodeConnectorName);
}
/**
* Adds a node connector and its property if any
- *
+ *
* @param nodeConnector
* {@link org.opendaylight.controller.sal.core.NodeConnector}
* @param propName
/**
* Removes one property of a node connector
- *
+ *
* @param nodeConnector
* {@link org.opendaylight.controller.sal.core.NodeConnector}
* @param propName
/**
* Removes all the properties of a node connector
- *
+ *
* @param nodeConnector
* {@link org.opendaylight.controller.sal.core.NodeConnector}
* @return success or failed reason
/**
* Function called by the dependency manager when all the required
* dependencies are satisfied
- *
+ *
*/
void init(Component c) {
Dictionary<?, ?> props = c.getServiceProperties();
* Function called by the dependency manager when at least one dependency
* become unsatisfied or when the component is shutting down because for
* example bundle is being stopped.
- *
+ *
*/
void destroy() {
shutDown();
/**
* Function called by dependency manager after "init ()" is called and after
* the services provided by the class are registered in the service registry
- *
+ *
*/
void start() {
// OSGI console
* Function called by the dependency manager before the services exported by
* the component are unregistered, this will be followed by a "destroy ()"
* calls
- *
+ *
*/
void stop() {
}
@Override
public Boolean isNodeConnectorEnabled(NodeConnector nodeConnector) {
- if (nodeConnector == null)
+ if (nodeConnector == null) {
return false;
+ }
Config config = (Config) getNodeConnectorProp(nodeConnector,
Config.ConfigPropName);
}
public void _pns(CommandInterpreter ci) {
- ci.println(" Node Type Name Tier");
+ ci.println(" Node Type MAC Name Tier");
if (nodeProps == null) {
return;
}
Description.propertyName));
Tier tier = ((Tier) getNodeProp(node, Tier.TierPropName));
String nodeName = (desc == null) ? "" : desc.getValue();
+ MacAddress mac = (MacAddress) getNodeProp(node,
+ MacAddress.name);
+ String macAddr = (mac == null) ? "" : HexEncode
+ .bytesToHexStringFormat(mac.getMacAddress());
int tierNum = (tier == null) ? 0 : tier.getValue();
- ci.println(node + " " + node.getType() + " "
- + nodeName + " " + tierNum);
+ ci.println(node + " " + node.getType() + " " + macAddr
+ + " " + nodeName + " " + tierNum);
}
ci.println("Total number of Nodes: " + nodeSet.size());
}
ci.println("expecting on/off/?");
return;
}
- if (mode.toLowerCase().equals("on"))
+ if (mode.toLowerCase().equals("on")) {
hostRefresh = true;
- else if (mode.toLowerCase().equals("off"))
+ } else if (mode.toLowerCase().equals("off")) {
hostRefresh = false;
- else if (mode.equals("?")) {
- if (hostRefresh)
+ } else if (mode.equals("?")) {
+ if (hostRefresh) {
ci.println("host refresh is ON");
- else
+ } else {
ci.println("host refresh is OFF");
- } else
+ }
+ } else {
ci.println("expecting on/off/?");
+ }
return;
}
@Override
public byte[] getNodeMAC(Node node) {
- if (node.getType().equals(Node.NodeIDType.OPENFLOW)) {
- byte[] gmac = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- long dpid = (Long) node.getID();
-
- for (short i = 0; i < 6; i++) {
- gmac[5 - i] = (byte) dpid;
- dpid >>= 8;
- }
- return gmac;
- }
- return null;
+ MacAddress mac = (MacAddress) this.getNodeProp(node,
+ MacAddress.name);
+ return (mac != null) ? mac.getMacAddress() : null;
}
@Override
List<NodeConnector> ncLists = new ArrayList<NodeConnector>();
for (NodeConnector nodeConnector : nodeConncetors) {
- if (!spanNodeConnectors.contains(nodeConnector)) {
+ if (spanNodeConnectors.contains(nodeConnector)) {
ncLists.add(nodeConnector);
}
}
/**
* Creates a Name/Tier/Bandwidth Property object based on given property
* name and value. Other property types are not supported yet.
- *
+ *
* @param propName
* Name of the Property
* @param propValue