import org.opendaylight.controller.sal.core.MacAddress
import java.util.Date
import org.opendaylight.controller.sal.core.TimeStamp
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowNodeConnector
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowNode
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector
public class NodeMapping {
public static val MD_SAL_TYPE = "MD_SAL";
private static val NODE_CLASS = org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
- private static val NODECONNECTOR_CLASS = org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
-
+ private static val NODECONNECTOR_CLASS = org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.
+ NodeConnector;
private new() {
throw new UnsupportedOperationException("Utility class. Instantiation is not allowed.");
}
public static def toADNode(InstanceIdentifier<?> node) throws ConstructionException {
- return new Node(MD_SAL_TYPE, node.toNodeId.toADNodeId);
+ return node.toNodeId.toADNode
}
-
+
+ public static def toADNode(NodeId id) {
+ return new Node(MD_SAL_TYPE, id.toADNodeId);
+ }
+
public static def toNodeId(InstanceIdentifier<?> node) {
checkNotNull(node);
checkNotNull(node.getPath());
val nodeKey = item.getKey().checkInstanceOf(NodeKey);
return nodeKey.id
}
-
+
public static def toADNodeId(NodeId nodeId) {
checkNotNull(nodeId);
return nodeId.value
}
-
public static def toADNodeConnector(NodeConnectorRef source) throws ConstructionException {
checkNotNull(source);
val InstanceIdentifier<?> path = checkNotNull(source.getValue());
- val node = path.toADNode();
checkArgument(path.path.size() >= 3);
val arg = path.getPath().get(2);
val item = arg.checkInstanceOf(IdentifiableItem);
val connectorKey = item.getKey().checkInstanceOf(NodeConnectorKey);
- return new NodeConnector(connectorKey.id.toNodeConnectorType(path.toNodeId), connectorKey.id.toADNodeConnectorId(path.toNodeId), node);
+ return connectorKey.id.toADNodeConnector(path.toNodeId)
}
- public static def toNodeConnectorType(NodeConnectorId ncId,NodeId nodeId) {
+ public static def toADNodeConnector(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId ncid,
+ org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId nid) {
+ return new NodeConnector(ncid.toNodeConnectorType(nid),
+ ncid.toADNodeConnectorId(nid), nid.toADNode);
+ }
+
+ public static def toNodeConnectorType(NodeConnectorId ncId, NodeId nodeId) {
if (ncId.equals(nodeId.toLocalNodeConnectorId)) {
return NodeConnector.NodeConnectorIDType.SWSTACK
} else if (ncId.equals(nodeId.toNormalNodeConnectorId)) {
return NodeConnector.NodeConnectorIDType.HWPATH
- } else if (ncId.equals(nodeId.toControllerNodeConnectorId)){
+ } else if (ncId.equals(nodeId.toControllerNodeConnectorId)) {
return NodeConnector.NodeConnectorIDType.CONTROLLER
}
return MD_SAL_TYPE
}
-
- public static def toADNodeConnectorId(NodeConnectorId nodeConnectorId,NodeId nodeId) {
- if(nodeConnectorId.equals(nodeId.toLocalNodeConnectorId) ||
- nodeConnectorId.equals(nodeId.toNormalNodeConnectorId) ||
- nodeConnectorId.equals(nodeId.toControllerNodeConnectorId)
- ) {
+
+ public static def toADNodeConnectorId(NodeConnectorId nodeConnectorId, NodeId nodeId) {
+ if (nodeConnectorId.equals(nodeId.toLocalNodeConnectorId) ||
+ nodeConnectorId.equals(nodeId.toNormalNodeConnectorId) ||
+ nodeConnectorId.equals(nodeId.toControllerNodeConnectorId)) {
return NodeConnector.SPECIALNODECONNECTORID
}
return nodeConnectorId.value
}
-
- public static def toControllerNodeConnectorId(NodeId node) {
+
+ public static def toControllerNodeConnectorId(NodeId node) {
return new NodeConnectorId(node.value + ":" + 4294967293L)
}
- public static def toLocalNodeConnectorId(NodeId node) {
+
+ public static def toLocalNodeConnectorId(NodeId node) {
return new NodeConnectorId(node.value + ":" + 4294967294L)
}
- public static def toNormalNodeConnectorId(NodeId node) {
+
+ public static def toNormalNodeConnectorId(NodeId node) {
return new NodeConnectorId(node.value + ":" + 4294967290L)
}
-
+
public static def toNodeRef(Node node) {
checkArgument(MD_SAL_TYPE.equals(node.getType()));
var nodeId = node.ID.checkInstanceOf(String)
val nodePath = InstanceIdentifier.builder().node(Nodes).child(NODE_CLASS, nodeKey).toInstance();
return new NodeRef(nodePath);
}
-
+
public static def toNodeConnectorRef(NodeConnector nodeConnector) {
val node = nodeConnector.node.toNodeRef();
val nodePath = node.getValue() as InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node>
var NodeConnectorId nodeConnectorId
- if(nodeConnector.ID.equals(NodeConnector.SPECIALNODECONNECTORID)){
- if(nodeConnector.type.equals(NodeConnector.NodeConnectorIDType.SWSTACK)) {
+ if (nodeConnector.ID.equals(NodeConnector.SPECIALNODECONNECTORID)) {
+ if (nodeConnector.type.equals(NodeConnector.NodeConnectorIDType.SWSTACK)) {
nodeConnectorId = nodePath.toNodeId.toLocalNodeConnectorId
} else if (nodeConnector.type.equals(NodeConnector.NodeConnectorIDType.HWPATH)) {
nodeConnectorId = nodePath.toNodeId.toNormalNodeConnectorId
} else if (nodeConnector.type.equals(NodeConnector.NodeConnectorIDType.CONTROLLER)) {
nodeConnectorId = nodePath.toNodeId.toControllerNodeConnectorId
- }
+ }
} else {
- nodeConnectorId = new NodeConnectorId(nodeConnector.ID.checkInstanceOf(String))
+ nodeConnectorId = new NodeConnectorId(nodeConnector.ID.checkInstanceOf(String))
}
val connectorKey = new NodeConnectorKey(nodeConnectorId);
val path = InstanceIdentifier.builder(nodePath).child(NODECONNECTOR_CLASS, connectorKey).toInstance();
public static def toADNode(NodeRef node) throws ConstructionException {
return toADNode(node.getValue());
}
-
+
public static def toADNodeConnectorProperties(NodeConnectorUpdated nc) {
- val props = new HashSet<org.opendaylight.controller.sal.core.Property>();
val fcncu = nc.getAugmentation(FlowCapableNodeConnectorUpdated)
- if(fcncu != null) {
- if(fcncu.currentFeature != null && fcncu.currentFeature.toAdBandwidth != null) {
+ if (fcncu != null) {
+ return fcncu.toADNodeConnectorProperties
+ }
+ return new HashSet<org.opendaylight.controller.sal.core.Property>();
+ }
+
+ public static def toADNodeConnectorProperties(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector nc) {
+ val fcnc = nc.getAugmentation(FlowCapableNodeConnector)
+ if (fcnc != null) {
+ return fcnc.toADNodeConnectorProperties
+ }
+ return new HashSet<org.opendaylight.controller.sal.core.Property>();
+ }
+
+ public static def toADNodeConnectorProperties(FlowNodeConnector fcncu) {
+ val props = new HashSet<org.opendaylight.controller.sal.core.Property>();
+ if (fcncu != null) {
+ if (fcncu.currentFeature != null && fcncu.currentFeature.toAdBandwidth != null) {
props.add(fcncu.currentFeature.toAdBandwidth)
}
- if(fcncu.advertisedFeatures != null && fcncu.advertisedFeatures.toAdAdvertizedBandwidth != null) {
+ if (fcncu.advertisedFeatures != null && fcncu.advertisedFeatures.toAdAdvertizedBandwidth != null) {
props.add(fcncu.advertisedFeatures.toAdAdvertizedBandwidth)
}
- if(fcncu.supported != null && fcncu.supported.toAdSupportedBandwidth != null) {
+ if (fcncu.supported != null && fcncu.supported.toAdSupportedBandwidth != null) {
props.add(fcncu.supported.toAdSupportedBandwidth)
}
- if(fcncu.peerFeatures != null && fcncu.peerFeatures.toAdPeerBandwidth != null) {
+ if (fcncu.peerFeatures != null && fcncu.peerFeatures.toAdPeerBandwidth != null) {
props.add(fcncu.peerFeatures.toAdPeerBandwidth)
}
- if(fcncu.name != null && fcncu.name.toAdName != null) {
+ if (fcncu.name != null && fcncu.name.toAdName != null) {
props.add(fcncu.name.toAdName)
}
- if(fcncu.configuration != null && fcncu.configuration.toAdConfig != null) {
+ if (fcncu.configuration != null && fcncu.configuration.toAdConfig != null) {
props.add(fcncu.configuration.toAdConfig)
}
- if(fcncu.state != null && fcncu.state.toAdState != null) {
+ if (fcncu.state != null && fcncu.state.toAdState != null) {
props.add(fcncu.state.toAdState)
}
}
return props
}
-
+
public static def toAdName(String name) {
return new Name(name)
- }
-
+ }
+
public static def toAdConfig(PortConfig pc) {
var Config config;
- if(pc.PORTDOWN){
+ if (pc.PORTDOWN) {
config = new Config(Config.ADMIN_DOWN)
} else {
config = new Config(Config.ADMIN_UP)
}
return config
}
-
+
public static def toAdState(State s) {
var org.opendaylight.controller.sal.core.State state
- if(s.linkDown) {
+ if (s.linkDown) {
state = new org.opendaylight.controller.sal.core.State(org.opendaylight.controller.sal.core.State.EDGE_DOWN)
} else {
state = new org.opendaylight.controller.sal.core.State(org.opendaylight.controller.sal.core.State.EDGE_UP)
}
return state
}
-
+
public static def toAdBandwidth(PortFeatures pf) {
var Bandwidth bw = null
- if (pf.is_10mbHd || pf.is_10mbFd ) {
- bw= new Bandwidth(Bandwidth.BW10Mbps)
- } else if (pf.is_100mbHd || pf.is_100mbFd ) {
- bw= new Bandwidth(Bandwidth.BW100Mbps)
- } else if (pf.is_1gbHd || pf.is_1gbFd ) {
- bw= new Bandwidth(Bandwidth.BW1Gbps)
- } else if (pf.is_1gbFd ) {
- bw= new Bandwidth(Bandwidth.BW10Gbps)
- } else if ( pf.is_10gbFd ) {
- bw= new Bandwidth(Bandwidth.BW10Gbps)
- } else if ( pf.is_40gbFd ) {
- bw= new Bandwidth(Bandwidth.BW40Gbps)
- } else if ( pf.is_100gbFd ) {
- bw= new Bandwidth(Bandwidth.BW100Gbps)
- } else if ( pf.is_1tbFd ) {
- bw= new Bandwidth(Bandwidth.BW1Tbps)
- }
+ if (pf.isTenMbHd || pf.isTenMbFd) {
+ bw = new Bandwidth(Bandwidth.BW10Mbps)
+ } else if (pf.isHundredMbHd || pf.isHundredMbFd) {
+ bw = new Bandwidth(Bandwidth.BW100Mbps)
+ } else if (pf.isOneGbHd || pf.isOneGbFd) {
+ bw = new Bandwidth(Bandwidth.BW1Gbps)
+ } else if (pf.isOneGbFd) {
+ bw = new Bandwidth(Bandwidth.BW10Gbps)
+ } else if (pf.isTenGbFd) {
+ bw = new Bandwidth(Bandwidth.BW10Gbps)
+ } else if (pf.isFortyGbFd) {
+ bw = new Bandwidth(Bandwidth.BW40Gbps)
+ } else if (pf.isHundredGbFd) {
+ bw = new Bandwidth(Bandwidth.BW100Gbps)
+ } else if (pf.isOneTbFd) {
+ bw = new Bandwidth(Bandwidth.BW1Tbps)
+ }
return bw;
}
-
+
public static def toAdAdvertizedBandwidth(PortFeatures pf) {
var AdvertisedBandwidth abw
val bw = pf.toAdBandwidth
- if(bw != null) {
+ if (bw != null) {
abw = new AdvertisedBandwidth(bw.value)
}
return abw
}
-
+
public static def toAdSupportedBandwidth(PortFeatures pf) {
var SupportedBandwidth sbw
val bw = pf.toAdBandwidth
- if(bw != null ) {
+ if (bw != null) {
sbw = new SupportedBandwidth(bw.value)
}
return sbw
}
-
+
public static def toAdPeerBandwidth(PortFeatures pf) {
var PeerBandwidth pbw
val bw = pf.toAdBandwidth
- if(bw != null) {
+ if (bw != null) {
pbw = new PeerBandwidth(bw.value)
}
return pbw
}
-
+
public static def toADNodeProperties(NodeUpdated nu) {
+ val fcnu = nu.getAugmentation(FlowCapableNodeUpdated)
+ if (fcnu != null) {
+ return fcnu.toADNodeProperties(nu.id)
+ }
+ return new HashSet<org.opendaylight.controller.sal.core.Property>();
+
+ }
+
+ public static def toADNodeProperties(FlowNode fcnu, NodeId id) {
val props = new HashSet<org.opendaylight.controller.sal.core.Property>();
- val fcnu = nu.getAugmentation(FlowCapableNodeUpdated)
- if(fcnu != null) {
- props.add(toADTimestamp)
- // props.add(fcnu.supportedActions.toADActions) - TODO
- if(nu.id != null) {
- props.add(nu.id.toADMacAddress)
- }
- if(fcnu.switchFeatures != null) {
- if(fcnu.switchFeatures.maxTables != null) {
- props.add(fcnu.switchFeatures.maxTables.toADTables)
- }
- if(fcnu.switchFeatures.capabilities != null) {
+ if (fcnu != null) {
+ props.add(toADTimestamp)
+
+ // props.add(fcnu.supportedActions.toADActions) - TODO
+ if (id != null) {
+ props.add(id.toADMacAddress)
+ }
+ if (fcnu.switchFeatures != null) {
+ if (fcnu.switchFeatures.maxTables != null) {
+ props.add(fcnu.switchFeatures.maxTables.toADTables)
+ }
+ if (fcnu.switchFeatures.capabilities != null) {
props.add(fcnu.switchFeatures.capabilities.toADCapabiliities)
- }
- if(fcnu.switchFeatures.maxBuffers != null) {
+ }
+ if (fcnu.switchFeatures.maxBuffers != null) {
props.add(fcnu.switchFeatures.maxBuffers.toADBuffers)
- }
- }
- }
- return props;
-
+ }
+ }
+ }
+ return props;
}
-
+
public static def toADTimestamp() {
val date = new Date();
- val timestamp = new TimeStamp(date.time,"connectedSince")
+ val timestamp = new TimeStamp(date.time, "connectedSince")
return timestamp;
}
-
+
public static def toADMacAddress(NodeId id) {
- return new MacAddress(Long.parseLong(id.value.replaceAll("openflow:","")).longValue.bytesFromDpid)
+ return new MacAddress(Long.parseLong(id.value.replaceAll("openflow:", "")).longValue.bytesFromDpid)
}
-
+
public static def toADTables(Short tables) {
return new Tables(tables.byteValue)
}
-
+
public static def toADCapabiliities(List<Class<? extends FeatureCapability>> capabilities) {
var int b
- for(capability : capabilities) {
- if(capability.equals(FlowFeatureCapabilityFlowStats)) {
+ for (capability : capabilities) {
+ if (capability.equals(FlowFeatureCapabilityFlowStats)) {
b = Capabilities.CapabilitiesType.FLOW_STATS_CAPABILITY.value.bitwiseOr(b)
} else if (capability.equals(FlowFeatureCapabilityTableStats)) {
b = Capabilities.CapabilitiesType.TABLE_STATS_CAPABILITY.value.bitwiseOr(b)
}
return new Capabilities(b)
}
-
+
public static def toADBuffers(Long buffers) {
return new Buffers(buffers.intValue)
}
-
+
}