- Moved network node's MAC computation from switch mgr to InventoryShimService in protocol plugin
- Modified MAC property to only carry network node MAC
- Some automatic coding style changes
- Some static analysis fix
Change-Id:I8481176d3fa3fcc004f642ea865b7be3593bdfc4
Signed-off-by: Alessandro Boch <aboch@cisco.com>
import org.opendaylight.controller.northbound.commons.exception.UnauthorizedException;
import org.opendaylight.controller.northbound.commons.utils.NorthboundUtils;
import org.opendaylight.controller.sal.authorization.Privilege;
-import org.opendaylight.controller.sal.core.MacAddress;
import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.core.NodeConnector;
import org.opendaylight.controller.sal.core.Property;
/**
* The class provides Northbound REST APIs to access the nodes, node connectors
* and their properties.
- *
+ *
*/
@Path("/")
}
/**
- *
+ *
* Retrieve a list of all the nodes and their properties in the network
- *
+ *
* @param containerName
* The container for which we want to retrieve the list
* @return A list of Pair each pair represents a
+ containerName);
}
- ISwitchManager switchManager = (ISwitchManager) getIfSwitchManagerService(containerName);
+ ISwitchManager switchManager = getIfSwitchManagerService(containerName);
if (switchManager == null) {
throw new ServiceUnavailableException("Switch Manager "
+ RestMessages.SERVICEUNAVAILABLE.toString());
return null;
}
- byte[] controllerMac = switchManager.getControllerMAC();
for (Node node : nodes) {
Map<String, Property> propMap = switchManager.getNodeProps(node);
if (propMap == null) {
}
Set<Property> props = new HashSet<Property>(propMap.values());
- byte[] nodeMac = switchManager.getNodeMAC(node);
- Property macAddr = new MacAddress(controllerMac, nodeMac);
- props.add(macAddr);
-
NodeProperties nodeProps = new NodeProperties(node, props);
res.add(nodeProps);
}
/**
* Add a Name/Tier property to a node
- *
+ *
* @param containerName
* Name of the Container
* @param nodeType
}
handleDefaultDisabled(containerName);
- ISwitchManager switchManager = (ISwitchManager) getIfSwitchManagerService(containerName);
+ ISwitchManager switchManager = getIfSwitchManagerService(containerName);
if (switchManager == null) {
throw new ServiceUnavailableException("Switch Manager "
+ RestMessages.SERVICEUNAVAILABLE.toString());
/**
* Delete a property of a node
- *
+ *
* @param containerName
* Name of the Container
* @param nodeType
}
handleDefaultDisabled(containerName);
- ISwitchManager switchManager = (ISwitchManager) getIfSwitchManagerService(containerName);
+ ISwitchManager switchManager = getIfSwitchManagerService(containerName);
if (switchManager == null) {
throw new ServiceUnavailableException("Switch Manager "
+ RestMessages.SERVICEUNAVAILABLE.toString());
}
/**
- *
+ *
* Retrieve a list of all the node connectors and their properties in a
* given node
- *
+ *
* @param containerName
* The container for which we want to retrieve the list
* @param nodeType
+ containerName);
}
- ISwitchManager switchManager = (ISwitchManager) getIfSwitchManagerService(containerName);
+ ISwitchManager switchManager = getIfSwitchManagerService(containerName);
if (switchManager == null) {
throw new ServiceUnavailableException("Switch Manager "
+ RestMessages.SERVICEUNAVAILABLE.toString());
/**
* Add a Name/Bandwidth property to a node connector
- *
+ *
* @param containerName
* Name of the Container
* @param nodeType
handleDefaultDisabled(containerName);
- ISwitchManager switchManager = (ISwitchManager) getIfSwitchManagerService(containerName);
+ ISwitchManager switchManager = getIfSwitchManagerService(containerName);
if (switchManager == null) {
throw new ServiceUnavailableException("Switch Manager "
+ RestMessages.SERVICEUNAVAILABLE.toString());
/**
* Delete a property of a node connector
- *
+ *
* @param containerName
* Name of the Container
* @param nodeType
handleDefaultDisabled(containerName);
- ISwitchManager switchManager = (ISwitchManager) getIfSwitchManagerService(containerName);
+ ISwitchManager switchManager = getIfSwitchManagerService(containerName);
if (switchManager == null) {
throw new ServiceUnavailableException("Switch Manager "
+ RestMessages.SERVICEUNAVAILABLE.toString());
/* *//**
* Retrieve a list of Span ports that were configured previously.
- *
+ *
* @param containerName
* Name of the Container
* @return list of
*/
/*
* @Path("/span-config/{containerName}")
- *
+ *
* @GET
- *
+ *
* @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
- *
+ *
* @StatusCodes( {
- *
+ *
* @ResponseCode(code = 200, condition = "Operation successful"),
- *
+ *
* @ResponseCode(code = 404, condition = "The containerName is not found"),
- *
+ *
* @ResponseCode(code = 503, condition =
* "One or more of Controller Services are unavailable") }) public
* List<SpanConfig> getSpanConfigList(@PathParam("containerName") String
* getIfSwitchManagerService(containerName); if (switchManager == null) {
* throw new ServiceUnavailableException("Switch Manager " +
* RestMessages.SERVICEUNAVAILABLE.toString()); }
- *
+ *
* return switchManager.getSpanConfigList(); }
*//**
* Add a span configuration
- *
+ *
* @param containerName
* Name of the Container
* @param config
*/
/*
* @Path("/span-config/{containerName}")
- *
+ *
* @PUT
- *
+ *
* @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
- *
+ *
* @StatusCodes( {
- *
+ *
* @ResponseCode(code = 200, condition = "Operation successful"),
- *
+ *
* @ResponseCode(code = 404, condition = "The containerName is not found"),
- *
+ *
* @ResponseCode(code = 503, condition =
* "One or more of Controller Services are unavailable") }) public Response
* addSpanConfig(@PathParam("containerName") String containerName,
- *
+ *
* @TypeHint(SubnetConfig.class) JAXBElement<SpanConfig> config) {
* ISwitchManager switchManager = (ISwitchManager)
* getIfSwitchManagerService(containerName); if (switchManager == null) {
* throw new ServiceUnavailableException("Switch Manager " +
* RestMessages.SERVICEUNAVAILABLE.toString()); }
- *
+ *
* String ret = switchManager.addSpanConfig(config.getValue()); if
* (ret.equals(ReturnString.SUCCESS.toString())) { return
* Response.status(Response.Status.CREATED).build(); } throw new
* InternalServerErrorException(ret); }
*//**
* Delete a span configuration
- *
+ *
* @param containerName
* Name of the Container
* @param config
*/
/*
* @Path("/span-config/{containerName}")
- *
+ *
* @DELETE
- *
+ *
* @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
- *
+ *
* @StatusCodes( {
- *
+ *
* @ResponseCode(code = 200, condition = "Operation successful"),
- *
+ *
* @ResponseCode(code = 404, condition = "The containerName is not found"),
- *
+ *
* @ResponseCode(code = 503, condition =
* "One or more of Controller Services are unavailable") }) public Response
* deleteSpanConfig(@PathParam("containerName") String containerName,
- *
+ *
* @TypeHint(SubnetConfig.class) JAXBElement<SpanConfig> config) {
* ISwitchManager switchManager = (ISwitchManager)
* getIfSwitchManagerService(containerName); if (switchManager == null) {
* throw new ServiceUnavailableException("Switch Manager " +
* RestMessages.SERVICEUNAVAILABLE.toString()); }
- *
+ *
* String ret = switchManager.removeSpanConfig(config.getValue()); if
* (ret.equals(ReturnString.SUCCESS.toString())) { return
* Response.ok().build(); } throw new ResourceNotFoundException(ret); }
/**
* Save the current switch configurations
- *
+ *
* @param containerName
* Name of the Container
* @return Response as dictated by the HTTP Response Status code
"User is not authorized to perform this operation on container "
+ containerName);
}
- ISwitchManager switchManager = (ISwitchManager) getIfSwitchManagerService(containerName);
+ ISwitchManager switchManager = getIfSwitchManagerService(containerName);
if (switchManager == null) {
throw new ServiceUnavailableException("Switch Manager "
+ RestMessages.SERVICEUNAVAILABLE.toString());
import org.opendaylight.controller.sal.core.ContainerFlow;
import org.opendaylight.controller.sal.core.Description;
import org.opendaylight.controller.sal.core.IContainerListener;
+import org.opendaylight.controller.sal.core.MacAddress;
import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.core.Node.NodeIDType;
import org.opendaylight.controller.sal.core.NodeConnector;
* The class describes a shim layer that bridges inventory events from Openflow
* core to various listeners. The notifications are filtered based on container
* configurations.
- *
- *
+ *
+ *
*/
public class InventoryServiceShim implements IContainerListener,
IMessageListener, ISwitchStateListener, IStatisticsListener {
protected static final Logger logger = LoggerFactory
.getLogger(InventoryServiceShim.class);
private IController controller = null;
- private ConcurrentMap<String, IInventoryShimInternalListener> inventoryShimInternalListeners = new ConcurrentHashMap<String, IInventoryShimInternalListener>();
- private List<IInventoryShimExternalListener> inventoryShimExternalListeners = new CopyOnWriteArrayList<IInventoryShimExternalListener>();
- private ConcurrentMap<NodeConnector, List<String>> containerMap = new ConcurrentHashMap<NodeConnector, List<String>>();
+ private final ConcurrentMap<String, IInventoryShimInternalListener> inventoryShimInternalListeners = new ConcurrentHashMap<String, IInventoryShimInternalListener>();
+ private final List<IInventoryShimExternalListener> inventoryShimExternalListeners = new CopyOnWriteArrayList<IInventoryShimExternalListener>();
+ private final ConcurrentMap<NodeConnector, List<String>> containerMap = new ConcurrentHashMap<NodeConnector, List<String>>();
void setController(IController s) {
this.controller = s;
/**
* Function called by the dependency manager when all the required
* dependencies are satisfied
- *
+ *
*/
void init() {
this.controller.addMessageListener(OFType.PORT_STATUS, this);
* 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() {
this.controller.removeMessageListener(OFType.PACKET_IN, this);
@Override
public void switchAdded(ISwitch sw) {
- if (sw == null)
+ if (sw == null) {
return;
+ }
// Add all the nodeConnectors of this switch
Map<NodeConnector, Set<Property>> ncProps = InventoryServiceHelper
@Override
public void switchDeleted(ISwitch sw) {
- if (sw == null)
+ if (sw == null) {
return;
+ }
removeNode(sw);
}
Long connectedSinceTime = (connectedSince == null) ? 0 : connectedSince
.getTime();
props.add(new TimeStamp(connectedSinceTime, "connectedSince"));
+ props.add(new MacAddress(deriveMacAddress(sid)));
byte tables = sw.getTables();
Tables t = new Tables(tables);
if (b != null) {
props.add(b);
}
+
// Notify all internal and external listeners
notifyInventoryShimListener(node, type, props);
}
logger.error("{}", e.getMessage());
return;
}
-
+
Set<Property> properties = new HashSet<Property>(1);
Description desc = new Description(
descriptionStats.getDatapathDescription());
properties.add(desc);
-
+
// Notify all internal and external listeners
notifyInventoryShimListener(node, UpdateType.CHANGED, properties);
- }
+ }
+
+ private byte[] deriveMacAddress(long dpid) {
+ byte[] mac = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
-
+ for (short i = 0; i < 6; i++) {
+ mac[5 - i] = (byte) dpid;
+ dpid >>= 8;
+ }
+
+ return mac;
+ }
}
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
/**
- * The class contains the controller MAC address and node MAC address.
- *
- *
+ * The class contains MAC address property.
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
-public class MacAddress extends Property {
+public class MacAddress extends Property implements Cloneable {
private static final long serialVersionUID = 1L;
- @XmlElement
- private byte[] controllerMacAddress;
- @XmlElement
- private byte[] nodeMacAddress;
- public static final String MacPropName = "macAddress";
+ @XmlElement(name="macAddress")
+ private final byte[] address;
+ public static final String name = "macAddress";
/*
* Private constructor used for JAXB mapping
*/
private MacAddress() {
- super(MacPropName);
- this.controllerMacAddress = null;
- this.nodeMacAddress = null;
- }
-
- /**
- * Constructor to create DatalinkAddress property which contains the
- * controller MAC address and node MAC address. The property will be
- * attached to a {@link org.opendaylight.controller.sal.core.Node}.
- *
- * @param controllerMacAddress Data Link Address for the controller
- * @param nodeMacAddress Data Link Address for the node
- *
- * @return the constructed object
- */
- public MacAddress(byte[] controllerMacAddress, byte[] nodeMacAddress) {
- super(MacPropName);
-
- this.controllerMacAddress = controllerMacAddress;
- this.nodeMacAddress = nodeMacAddress;
+ super(name);
+ this.address = null;
}
/**
- * @return the controller MAC address
+ * Constructor to create DatalinkAddress property which contains the MAC
+ * address. The property will be attached to a
+ * {@link org.opendaylight.controller.sal.core.Node}.
+ *
+ *
+ * @param nodeMacAddress
+ * Data Link Address for the node
+ *
+ * @return the constructed object
*/
- public byte[] getControllerMacAddress() {
- return this.controllerMacAddress;
+ public MacAddress(byte[] nodeMacAddress) {
+ super(name);
+ this.address = nodeMacAddress.clone();
}
/**
* @return the node MAC address
*/
- public byte[] getNodeMacAddress() {
- return this.nodeMacAddress;
+ public byte[] getMacAddress() {
+ return this.address.clone();
}
+ @Override
public MacAddress clone() {
- return new MacAddress(this.controllerMacAddress, this.nodeMacAddress);
+ return new MacAddress(this.address);
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
- result = prime * result + Arrays.hashCode(controllerMacAddress);
- result = prime * result + Arrays.hashCode(nodeMacAddress);
+ result = prime * result + Arrays.hashCode(address);
return result;
}
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (!super.equals(obj))
+ }
+ if (!super.equals(obj)) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
MacAddress other = (MacAddress) obj;
- if (!Arrays.equals(controllerMacAddress, other.controllerMacAddress))
- return false;
- if (!Arrays.equals(nodeMacAddress, other.nodeMacAddress))
+ if (!Arrays.equals(address, other.address)) {
return false;
+ }
return true;
}
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
*/
/**
- * Abstract base class for a Property that can be attached to any sal
- * core element
- *
+ * Abstract base class for a Property that can be attached to any sal core
+ * element
*/
@XmlRootElement
@XmlSeeAlso({ Config.class, Name.class, State.class, TimeStamp.class,
- Latency.class, Bandwidth.class, Tier.class, Actions.class,
- AdvertisedBandwidth.class, Buffers.class, Capabilities.class,
- MacAddress.class, PeerBandwidth.class, SupportedBandwidth.class,
- Tables.class })
-abstract public class Property implements Serializable {
+ Latency.class, Bandwidth.class, Tier.class, Actions.class,
+ AdvertisedBandwidth.class, Buffers.class, Capabilities.class,
+ MacAddress.class, PeerBandwidth.class, SupportedBandwidth.class,
+ Tables.class })
+abstract public class Property implements Serializable, Cloneable {
private static final long serialVersionUID = 1L;
- private String name;
+ private final String name;
/**
* Private constructor used for JAXB mapping
/**
* Used to copy the Property in a polymorphic way
*
- *
* @return A clone of this Property
*/
- abstract public Property clone();
+ @Override
+ public abstract Property clone();
@Override
public int hashCode() {
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
Property other = (Property) obj;
if (name == null) {
- if (other.name != null)
+ if (other.name != null) {
return false;
- } else if (!name.equals(other.name))
+ }
+ } else if (!name.equals(other.name)) {
return false;
+ }
return true;
}
private static final long serialVersionUID = 1L;
private byte[] dataLayerAddress;
private Set<NodeConnector> nodeConnectors;
- private List<NodeConnector> spanPorts;
+ private final List<NodeConnector> spanPorts;
private Node node;
/*
this.node = node;
this.nodeConnectors = new HashSet<NodeConnector>();
this.spanPorts = new ArrayList<NodeConnector>(2);
- this.dataLayerAddress = deriveMacAddress();
+ this.dataLayerAddress = null;
}
/**
this.node = node;
}
- private byte[] deriveMacAddress() {
- long dpid = (Long) this.node.getID();
- byte[] mac = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
-
- for (short i = 0; i < 6; i++) {
- mac[5 - i] = (byte) dpid;
- dpid >>= 8;
- }
-
- return mac;
- }
-
public void addSpanPorts(List<NodeConnector> portList) {
for (NodeConnector port : portList) {
spanPorts.add(port);
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
Switch other = (Switch) obj;
- if (!Arrays.equals(dataLayerAddress, other.dataLayerAddress))
+ if (!Arrays.equals(dataLayerAddress, other.dataLayerAddress)) {
return false;
+ }
if (node == null) {
- if (other.node != null)
+ if (other.node != null) {
return false;
- } else if (!node.equals(other.node))
+ }
+ } else if (!node.equals(other.node)) {
return false;
+ }
if (nodeConnectors == null) {
- if (other.nodeConnectors != null)
+ if (other.nodeConnectors != null) {
return false;
- } else if (!nodeConnectors.equals(other.nodeConnectors))
+ }
+ } else if (!nodeConnectors.equals(other.nodeConnectors)) {
return false;
+ }
if (spanPorts == null) {
- if (other.spanPorts != null)
+ if (other.spanPorts != null) {
return false;
- } else if (!spanPorts.equals(other.spanPorts))
+ }
+ } else if (!spanPorts.equals(other.spanPorts)) {
return false;
+ }
return true;
}
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;
* 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);
}
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 (!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()) {
@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()) {
@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);
}
@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);
int tierNum = (tier == null) ? 0 : tier.getValue();
- ci.println(node + " " + node.getType() + " "
- + nodeName + " " + tierNum);
+ ci.println(node + " " + node.getType() + " "
+ + HexEncode.bytesToHexStringFormat(mac.getMacAddress())
+ + " " + 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) nodeProps.get(MacAddress.name);
+ return (mac != null) ? mac.getMacAddress() : null;
}
@Override
-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
public class SwitchManagerImplTest {
- @Test
- public void testSwitchManagerAddRemoveSubnet() {
- SwitchManagerImpl switchmgr = new SwitchManagerImpl();
- switchmgr.nonClusterObjectCreate();
-
- ArrayList<String>portList = new ArrayList<String>();
- portList.add("1/1");
- portList.add("1/2");
- portList.add("1/3");
-
-
- SubnetConfig subnet = new SubnetConfig("subnet", "10.0.0.254/16", portList);
- //System.out.println("*" + switchmgr.addSubnet(subnet) + "*");
- Status addResult = (switchmgr.addSubnet(subnet));
- Assert.assertTrue(addResult.isSuccess());
-
- Status removeResult = (switchmgr.removeSubnet(subnet.getName()));
- Assert.assertTrue(removeResult.isSuccess());
-
- SubnetConfig subnetConfigResult = switchmgr.getSubnetConfig(subnet.getName());
- Assert.assertTrue(subnetConfigResult == null);
-
- }
-
- @Test
- public void testSwitchManagerNodeConnectors() {
- SwitchManagerImpl switchmgr = new SwitchManagerImpl();
- switchmgr.nonClusterObjectCreate();
-
- State state;
- Bandwidth bw;
- Latency l;
-
- NodeConnector[] headnc = new NodeConnector[5];
- NodeConnector[] tailnc = new NodeConnector[5];
-
- Set<Property> props = new HashSet<Property>();
- state = new State(State.EDGE_UP);
- bw = new Bandwidth(Bandwidth.BW100Gbps);
- l = new Latency(Latency.LATENCY100ns);
- props.add(state);
- props.add(bw);
- props.add(l);
-
- for (short i = 1; i < 6; i = (short)(i + 1)) {
-
- headnc[i - 1] = NodeConnectorCreator.createOFNodeConnector(i, NodeCreator.createOFNode((long)i));
- tailnc[i - 1] = NodeConnectorCreator.createOFNodeConnector((short)(i+10), NodeCreator.createOFNode((long)(i+10)));
- switchmgr.updateNode(headnc[i - 1].getNode(), UpdateType.ADDED, props);
- switchmgr.updateNode(tailnc[i - 1].getNode(), UpdateType.ADDED, props);
-
- switchmgr.updateNodeConnector(headnc[i - 1], UpdateType.ADDED, props);
- switchmgr.updateNodeConnector(tailnc[i - 1], UpdateType.ADDED, props);
- }
-
- for (int i = 0; i < 5; i++) {
- Property bwProp = switchmgr.getNodeConnectorProp(headnc[i], Bandwidth.BandwidthPropName);
- Assert.assertTrue(bwProp.equals(bw));
- Property latencyProp = switchmgr.getNodeConnectorProp(tailnc[i], Latency.LatencyPropName);
- Assert.assertEquals(latencyProp, l);
-
- byte[] headNodeMac = switchmgr.getNodeMAC(headnc[i].getNode());
- Assert.assertTrue(headNodeMac[headNodeMac.length - 1] == (byte)(i + 1));
- }
-
- Set<Node> nodes = switchmgr.getNodes();
- for (int i = 0; i < 5; i++) {
- if (nodes.contains(headnc[i].getNode()) == true)
- nodes.remove(headnc[i].getNode());
-
- if (nodes.contains(tailnc[i].getNode()) == true)
- nodes.remove(tailnc[i].getNode());
-
- }
- Assert.assertTrue(nodes.isEmpty());
- }
-
+ @Test
+ public void testSwitchManagerAddRemoveSubnet() {
+ SwitchManagerImpl switchmgr = new SwitchManagerImpl();
+ switchmgr.nonClusterObjectCreate();
+
+ ArrayList<String> portList = new ArrayList<String>();
+ portList.add("1/1");
+ portList.add("1/2");
+ portList.add("1/3");
+
+ SubnetConfig subnet = new SubnetConfig("subnet", "10.0.0.254/16",
+ portList);
+ // System.out.println("*" + switchmgr.addSubnet(subnet) + "*");
+ Status addResult = (switchmgr.addSubnet(subnet));
+ Assert.assertTrue(addResult.isSuccess());
+
+ Status removeResult = (switchmgr.removeSubnet(subnet.getName()));
+ Assert.assertTrue(removeResult.isSuccess());
+
+ SubnetConfig subnetConfigResult = switchmgr.getSubnetConfig(subnet
+ .getName());
+ Assert.assertTrue(subnetConfigResult == null);
+
+ }
+
+ @Test
+ public void testSwitchManagerNodeConnectors() {
+ SwitchManagerImpl switchmgr = new SwitchManagerImpl();
+ switchmgr.nonClusterObjectCreate();
+
+ State state;
+ Bandwidth bw;
+ Latency l;
+
+ NodeConnector[] headnc = new NodeConnector[5];
+ NodeConnector[] tailnc = new NodeConnector[5];
+
+ Set<Property> props = new HashSet<Property>();
+ state = new State(State.EDGE_UP);
+ bw = new Bandwidth(Bandwidth.BW100Gbps);
+ l = new Latency(Latency.LATENCY100ns);
+ props.add(state);
+ props.add(bw);
+ props.add(l);
+
+ for (short i = 1; i < 6; i = (short) (i + 1)) {
+
+ headnc[i - 1] = NodeConnectorCreator.createOFNodeConnector(i,
+ NodeCreator.createOFNode((long) i));
+ tailnc[i - 1] = NodeConnectorCreator
+ .createOFNodeConnector((short) (i + 10),
+ NodeCreator.createOFNode((long) (i + 10)));
+ switchmgr.updateNode(headnc[i - 1].getNode(), UpdateType.ADDED,
+ props);
+ switchmgr.updateNode(tailnc[i - 1].getNode(), UpdateType.ADDED,
+ props);
+
+ switchmgr.updateNodeConnector(headnc[i - 1], UpdateType.ADDED,
+ props);
+ switchmgr.updateNodeConnector(tailnc[i - 1], UpdateType.ADDED,
+ props);
+ }
+
+ for (int i = 0; i < 5; i++) {
+ Property bwProp = switchmgr.getNodeConnectorProp(headnc[i],
+ Bandwidth.BandwidthPropName);
+ Assert.assertTrue(bwProp.equals(bw));
+ Property latencyProp = switchmgr.getNodeConnectorProp(tailnc[i],
+ Latency.LatencyPropName);
+ Assert.assertEquals(latencyProp, l);
+ }
+
+ Set<Node> nodes = switchmgr.getNodes();
+ for (int i = 0; i < 5; i++) {
+ if (nodes.contains(headnc[i].getNode()) == true) {
+ nodes.remove(headnc[i].getNode());
+ }
+
+ if (nodes.contains(tailnc[i].getNode()) == true) {
+ nodes.remove(tailnc[i].getNode());
+ }
+
+ }
+ Assert.assertTrue(nodes.isEmpty());
+ }
+
}