package org.opendaylight.controller.sal.core;
import java.io.Serializable;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.opendaylight.controller.sal.utils.INodeConnectorFactory;
+import org.opendaylight.controller.sal.utils.ServiceHelper;
/**
* Describe a generic network element attachment points,
*/
public static class NodeConnectorIDType {
private static final
- ConcurrentHashMap<String, ImmutablePair<Class, String>> compatibleType =
- new ConcurrentHashMap<String, ImmutablePair<Class, String>>();
+ ConcurrentHashMap<String, ImmutablePair<Class<? extends Object>, String>> compatibleType =
+ new ConcurrentHashMap<String, ImmutablePair<Class<? extends Object>, String>>();
/**
- * Represent a special port pointing toward the controller,
- * this is to send data packets toward the controller from
- * data plane.
+ * Represents the OFPP_CONTROLLER reserved port to forward a
+ * packet to the controller, this is to send data packets
+ * to the controller from the data plane triggering
+ * a packet_in event.
*/
public static String CONTROLLER = "CTRL";
/**
- * Special port describing ALL the ports in the system,
- * should be used for flooding like mechanism but better
- * to be carefull with it
+ * Represents the OFPP_ALL reserved OF port
+ * to forward to ALL the ports in the system ,
+ * should be used for flooding like mechanism to
+ * be used cautiously to avoid excessive flooding.
*/
public static String ALL = "ALL";
/**
- * Describe the local networking stack of the node
- * on which the packet is destined. Yet another special port
+ * Represents the OFPP_LOCAL reserved OF port
+ * to access the local networking stack of the node
+ * of which the packet is destined. Typically used for
+ * inband OF communications channel.
*/
public static String SWSTACK = "SW";
/**
- * Describe a special destination that invoke the
- * traditional HW forwarding on platforms that has this
- * provision.
+ * Describes OFPP_Normal reserved port destination that invokes
+ * the traditional native L2/L3 HW normal forwarding functionality
+ * if supported on the forwarding element.
*/
public static String HWPATH = "HW";
public static String OPENFLOW = "OF";
// for Unit Testing coverage
static {
compatibleType.put(CONTROLLER,
- new ImmutablePair(Short.class, null));
+ new ImmutablePair<Class<? extends Object>, String>(Short.class, null));
compatibleType.put(ALL,
- new ImmutablePair(Short.class, null));
+ new ImmutablePair<Class<? extends Object>, String>(Short.class, null));
compatibleType.put(SWSTACK,
- new ImmutablePair(Short.class, null));
+ new ImmutablePair<Class<? extends Object>, String>(Short.class, null));
compatibleType.put(HWPATH,
- new ImmutablePair(Short.class, null));
+ new ImmutablePair<Class<? extends Object>, String>(Short.class, null));
compatibleType.put(OPENFLOW,
- new ImmutablePair(Short.class,
+ new ImmutablePair<Class<? extends Object>, String>(Short.class,
Node.NodeIDType.OPENFLOW));
compatibleType.put(PCEP,
- new ImmutablePair(Integer.class,
+ new ImmutablePair<Class<? extends Object>, String>(Integer.class,
Node.NodeIDType.PCEP));
compatibleType.put(ONEPK,
- new ImmutablePair(String.class,
+ new ImmutablePair<Class<? extends Object>, String>(String.class,
Node.NodeIDType.ONEPK));
compatibleType.put(OPENFLOW2PCEP,
- new ImmutablePair(Short.class,
+ new ImmutablePair<Class<? extends Object>, String>(Short.class,
Node.NodeIDType.OPENFLOW));
compatibleType.put(OPENFLOW2ONEPK,
- new ImmutablePair(Short.class,
+ new ImmutablePair<Class<? extends Object>, String>(Short.class,
Node.NodeIDType.OPENFLOW));
compatibleType.put(PCEP2OPENFLOW,
- new ImmutablePair(Integer.class,
+ new ImmutablePair<Class<? extends Object>, String>(Integer.class,
Node.NodeIDType.PCEP));
compatibleType.put(PCEP2ONEPK,
- new ImmutablePair(Integer.class,
+ new ImmutablePair<Class<? extends Object>, String>(Integer.class,
Node.NodeIDType.PCEP));
compatibleType.put(ONEPK2OPENFLOW,
- new ImmutablePair(String.class,
+ new ImmutablePair<Class<? extends Object>, String>(String.class,
Node.NodeIDType.ONEPK));
compatibleType.put(ONEPK2PCEP,
- new ImmutablePair(String.class,
+ new ImmutablePair<Class<? extends Object>, String>(String.class,
Node.NodeIDType.ONEPK));
compatibleType.put(PRODUCTION,
- new ImmutablePair(String.class,
+ new ImmutablePair<Class<? extends Object>, String>(String.class,
Node.NodeIDType.PRODUCTION));
}
* @return true if registered, false otherwise
*/
public static boolean registerIDType(String type,
- Class compatibleID,
+ Class<? extends Object> compatibleID,
String compatibleNode) {
if (compatibleType.get(type) != null) {
return false;
} else {
- compatibleType.put(type, new ImmutablePair(compatibleID,
+ compatibleType.put(type, new ImmutablePair<Class<? extends Object>, String>(compatibleID,
compatibleNode));
return true;
}
*
* @return the NodeConnectorType of this object
*/
- @XmlAttribute(name = "type")
+ @XmlElement(name = "type")
public String getType() {
return this.nodeConnectorType;
}
}
}
- /**
+ /**
* Private setter for nodeConnectorType to be called by JAXB not by anyone
* else, NodeConnector is immutable
- *
+ *
* @param type of node to be set
*/
+ @SuppressWarnings("unused")
private void setType(String type) {
this.nodeConnectorType = type;
if (this.nodeConnectorIDString != null) {
*
* @return the NodeConnector ID of this object in String format
*/
- @XmlAttribute(name = "id")
+ @XmlElement(name = "id")
public String getNodeConnectorIDString() {
return this.nodeConnectorID.toString();
}
- /**
+ /**
* private setter to be used by JAXB
- *
+ *
* @param nodeConnectorIDString String representation for NodeConnectorID
*/
+ @SuppressWarnings("unused")
private void setNodeConnectorIDString(String IDStr) {
this.nodeConnectorIDString = IDStr;
if (this.nodeConnectorType != null) {
@Override
public int hashCode() {
- return new HashCodeBuilder(63389, 4951)
- .append(nodeConnectorType)
- .append(nodeConnectorID)
- .append(nodeConnectorNode)
- .hashCode();
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((nodeConnectorID == null) ? 0 : nodeConnectorID.hashCode());
+ result = prime
+ * result
+ + ((nodeConnectorNode == null) ? 0 : nodeConnectorNode
+ .hashCode());
+ result = prime
+ * result
+ + ((nodeConnectorType == null) ? 0 : nodeConnectorType
+ .hashCode());
+ return result;
}
@Override
public boolean equals(Object obj) {
- if (obj == null) { return false; }
- if (obj == this) { return true; }
- if (obj.getClass() != getClass()) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ NodeConnector other = (NodeConnector) obj;
+ if (nodeConnectorID == null) {
+ if (other.nodeConnectorID != null) {
+ return false;
+ }
+ } else if (!nodeConnectorID.equals(other.nodeConnectorID)) {
+ return false;
+ }
+ if (nodeConnectorNode == null) {
+ if (other.nodeConnectorNode != null) {
+ return false;
+ }
+ } else if (!nodeConnectorNode.equals(other.nodeConnectorNode)) {
return false;
}
- NodeConnector rhs = (NodeConnector)obj;
- return new EqualsBuilder()
- .append(this.getType(), rhs.getType())
- .append(this.getID(), rhs.getID())
- .append(this.getNode(), rhs.getNode())
- .isEquals();
+ if (nodeConnectorType == null) {
+ if (other.nodeConnectorType != null) {
+ return false;
+ }
+ } else if (!nodeConnectorType.equals(other.nodeConnectorType)) {
+ return false;
+ }
+ return true;
}
@Override
.equals(NodeConnectorIDType.SWSTACK) ||
this.nodeConnectorType
.equals(NodeConnectorIDType.HWPATH)) {
- return this.nodeConnectorType.toString();
+ return this.nodeConnectorType;
} else {
- return this.nodeConnectorType.toString() + "|"
+ return this.nodeConnectorType + "|"
+ this.nodeConnectorID.toString();
}
}
*
* @param str String to be parsed in a NodeConnector
*
- * @return the NodeConnector if parse is succesfull, null otherwise
+ * @return the NodeConnector if parse is successful, null otherwise
*/
public static NodeConnector fromString(String str) {
if (str == null) {
}
/**
- * return a NodeConnector from a string not containing explicitely
+ * return a set of NodeConnector from a collection of string
+ *
+ * @param stringCollection Collection of String object to be parsed as a NodeConnector
+ *
+ * @return the Set of unique NodeConnector objects if parse is successful, empty Set otherwise
+ */
+ public static Set<NodeConnector> fromString(Collection<String> stringCollection) {
+ Set<NodeConnector> set = new HashSet<NodeConnector>();
+ if (stringCollection != null) {
+
+ for (String str : stringCollection) {
+ NodeConnector nodeConnector = NodeConnector.fromString(str);
+ if (nodeConnector != null) {
+ set.add(nodeConnector);
+ }
+ }
+ }
+ return set;
+ }
+
+ /**
+ * return a NodeConnector from a string not containing explicitly
* the Node portion which has to be supplied as parameter
*
* @param str String to be parsed in a NodeConnector
* @param n Node to which the NodeConnector is attached
*
- * @return the NodeConnector if parse is succesfull, null otherwise
+ * @return the NodeConnector if parse is successful, null otherwise
*/
public static NodeConnector fromStringNoNode(String str, Node n) {
if (str == null) {
/**
* return a NodeConnector from a pair (type, ID) in string format
- * not containing explicitely the Node portion which has to be
+ * not containing explicitly the Node portion which has to be
* supplied as parameter
*
* @param typeStr type String to be parsed in a NodeConnector
* @param IDStr ID String portion to be parsed in a NodeConnector
* @param n Node to which the NodeConnector is attached
*
- * @return the NodeConnector if parse is succesfull, null otherwise
+ * @return the NodeConnector if parse is successful, null otherwise
*/
public static NodeConnector fromStringNoNode(String typeStr, String IDStr,
Node n) {
return null;
}
} else {
- // Lookup via OSGi service registry
+ //Use INodeConnectorFactory to create a NodeConnector of registered type.
+ //The protocol plugin being used depends on typeStr.
+ INodeConnectorFactory f = (INodeConnectorFactory) ServiceHelper
+ .getGlobalInstance(INodeConnectorFactory.class, new NodeConnector(), "(protocolName="+typeStr+")");
+ if(f==null) {
+ return null;
+ }
+ return f.fromStringNoNode(typeStr, IDStr, n);
}
- return null;
}
}