1 package org.opendaylight.controller.sal.compatibility
3 import org.opendaylight.controller.sal.core.Node
4 import org.opendaylight.controller.sal.core.NodeConnector
5 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey
6 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem
8 import static com.google.common.base.Preconditions.*;
9 import static extension org.opendaylight.controller.sal.common.util.Arguments.*;
11 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey
15 import org.opendaylight.controller.sal.core.ConstructionException
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorUpdated
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures
22 import org.opendaylight.controller.sal.core.Bandwidth
23 import org.opendaylight.controller.sal.core.AdvertisedBandwidth
24 import org.opendaylight.controller.sal.core.SupportedBandwidth
25 import org.opendaylight.controller.sal.core.PeerBandwidth
26 import org.opendaylight.controller.sal.core.Name
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig
28 import org.opendaylight.controller.sal.core.Config
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.flow.capable.port.State
31 public class NodeMapping {
33 public static val MD_SAL_TYPE = "MD_SAL";
34 private static val NODE_CLASS = org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
35 private static val NODECONNECTOR_CLASS = org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
38 throw new UnsupportedOperationException("Utility class. Instantiation is not allowed.");
41 public static def toADNode(InstanceIdentifier<?> node) throws ConstructionException {
43 checkNotNull(node.getPath());
44 checkArgument(node.getPath().size() >= 2);
45 val arg = node.getPath().get(1);
46 val item = arg.checkInstanceOf(IdentifiableItem);
47 val nodeKey = item.getKey().checkInstanceOf(NodeKey);
48 return new Node(MD_SAL_TYPE, nodeKey.id.toADNodeId);
51 public static def toADNodeId(NodeId nodeId) {
57 public static def toADNodeConnector(NodeConnectorRef source) throws ConstructionException {
59 val InstanceIdentifier<?> path = checkNotNull(source.getValue());
60 val node = path.toADNode();
61 checkArgument(path.path.size() >= 3);
62 val arg = path.getPath().get(2);
63 val item = arg.checkInstanceOf(IdentifiableItem);
64 val connectorKey = item.getKey().checkInstanceOf(NodeConnectorKey);
65 return new NodeConnector(MD_SAL_TYPE, connectorKey.id.toADNodeConnectorId, node);
68 public static def toADNodeConnectorId(NodeConnectorId nodeConnectorId) {
69 return nodeConnectorId.value
72 public static def toNodeRef(Node node) {
73 checkArgument(MD_SAL_TYPE.equals(node.getType()));
74 var nodeId = node.ID.checkInstanceOf(String)
75 val nodeKey = new NodeKey(new NodeId(nodeId));
76 val nodePath = InstanceIdentifier.builder().node(Nodes).child(NODE_CLASS, nodeKey).toInstance();
77 return new NodeRef(nodePath);
80 public static def toNodeConnectorRef(NodeConnector nodeConnector) {
81 val node = nodeConnector.node.toNodeRef();
82 val nodePath = node.getValue() as InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node>
83 var nodeConnectorId = nodeConnector.ID.checkInstanceOf(String)
84 val connectorKey = new NodeConnectorKey(new NodeConnectorId(nodeConnectorId));
85 val path = InstanceIdentifier.builder(nodePath).child(NODECONNECTOR_CLASS, connectorKey).toInstance();
86 return new NodeConnectorRef(path);
89 public static def toADNode(NodeRef node) throws ConstructionException {
90 return toADNode(node.getValue());
93 public static def toADNodeConnectorProperties(NodeConnectorUpdated nc) {
94 val props = new java.util.HashSet<org.opendaylight.controller.sal.core.Property>();
95 val fcncu = nc.getAugmentation(FlowCapableNodeConnectorUpdated)
97 if(fcncu.currentFeature != null && fcncu.currentFeature.toAdBandwidth != null) {
98 props.add(fcncu.currentFeature.toAdBandwidth)
100 if(fcncu.advertisedFeatures != null && fcncu.advertisedFeatures.toAdAdvertizedBandwidth != null) {
101 props.add(fcncu.advertisedFeatures.toAdAdvertizedBandwidth)
103 if(fcncu.supported != null && fcncu.supported.toAdSupportedBandwidth != null) {
104 props.add(fcncu.supported.toAdSupportedBandwidth)
106 if(fcncu.peerFeatures != null && fcncu.peerFeatures.toAdPeerBandwidth != null) {
107 props.add(fcncu.peerFeatures.toAdPeerBandwidth)
109 if(fcncu.name != null && fcncu.name.toAdName != null) {
110 props.add(fcncu.name.toAdName)
112 if(fcncu.configuration != null && fcncu.configuration.toAdConfig != null) {
113 props.add(fcncu.configuration.toAdConfig)
115 if(fcncu.state != null && fcncu.state.toAdState != null) {
116 props.add(fcncu.state.toAdState)
122 public static def toAdName(String name) {
123 return new Name(name)
126 public static def toAdConfig(PortConfig pc) {
129 config = new Config(Config.ADMIN_DOWN)
131 config = new Config(Config.ADMIN_UP)
136 public static def toAdState(State s) {
137 var org.opendaylight.controller.sal.core.State state
139 state = new org.opendaylight.controller.sal.core.State(org.opendaylight.controller.sal.core.State.EDGE_DOWN)
141 state = new org.opendaylight.controller.sal.core.State(org.opendaylight.controller.sal.core.State.EDGE_UP)
146 public static def toAdBandwidth(PortFeatures pf) {
147 var Bandwidth bw = null
148 if (pf.is_10mbHd || pf.is_10mbFd ) {
149 bw= new Bandwidth(Bandwidth.BW10Mbps)
150 } else if (pf.is_100mbHd || pf.is_100mbFd ) {
151 bw= new Bandwidth(Bandwidth.BW100Mbps)
152 } else if (pf.is_1gbHd || pf.is_1gbFd ) {
153 bw= new Bandwidth(Bandwidth.BW1Gbps)
154 } else if (pf.is_1gbFd ) {
155 bw= new Bandwidth(Bandwidth.BW10Gbps)
156 } else if ( pf.is_10gbFd ) {
157 bw= new Bandwidth(Bandwidth.BW10Gbps)
158 } else if ( pf.is_40gbFd ) {
159 bw= new Bandwidth(Bandwidth.BW40Gbps)
160 } else if ( pf.is_100gbFd ) {
161 bw= new Bandwidth(Bandwidth.BW100Gbps)
162 } else if ( pf.is_1tbFd ) {
163 bw= new Bandwidth(Bandwidth.BW1Tbps)
168 public static def toAdAdvertizedBandwidth(PortFeatures pf) {
169 var AdvertisedBandwidth abw
170 val bw = pf.toAdBandwidth
172 abw = new AdvertisedBandwidth(bw.value)
177 public static def toAdSupportedBandwidth(PortFeatures pf) {
178 var SupportedBandwidth sbw
179 val bw = pf.toAdBandwidth
181 sbw = new SupportedBandwidth(bw.value)
186 public static def toAdPeerBandwidth(PortFeatures pf) {
187 var PeerBandwidth pbw
188 val bw = pf.toAdBandwidth
190 pbw = new PeerBandwidth(bw.value)