-@SuppressWarnings("all")
-public class NodeMapping {
- public final static String MD_SAL_TYPE = "MD_SAL";
-
- private final static Class<Node> NODE_CLASS = Node.class;
-
- private final static Class<NodeConnector> NODECONNECTOR_CLASS = NodeConnector.class;
-
- private NodeMapping() {
- throw new UnsupportedOperationException("Utility class. Instantiation is not allowed.");
- }
-
- public static org.opendaylight.controller.sal.core.Node toADNode(final InstanceIdentifier<? extends Object> node) throws ConstructionException {
- NodeId nodeId = NodeMapping.toNodeId(node);
- return NodeMapping.toADNode(nodeId);
- }
-
- public static org.opendaylight.controller.sal.core.Node toADNode(final NodeId id) {
- try {
- String aDNodeId = NodeMapping.toADNodeId(id);
- return new org.opendaylight.controller.sal.core.Node(NodeMapping.MD_SAL_TYPE, aDNodeId);
- } catch (Throwable e) {
- throw Exceptions.sneakyThrow(e);
- }
- }
-
- public static NodeId toNodeId(final InstanceIdentifier<? extends Object> node) {
- Preconditions.<InstanceIdentifier<? extends Object>>checkNotNull(node);
- List<PathArgument> path = node.getPath();
- Preconditions.<List<PathArgument>>checkNotNull(path);
- int size = path.size();
- Preconditions.checkArgument(size >= 2);
- final PathArgument arg = path.get(1);
- final IdentifiableItem item = Arguments.<IdentifiableItem>checkInstanceOf(arg, IdentifiableItem.class);
- Identifier key = item.getKey();
- final NodeKey nodeKey = Arguments.<NodeKey>checkInstanceOf(key, NodeKey.class);
- return nodeKey.getId();
- }
-
- public static String toADNodeId(final NodeId nodeId) {
- Preconditions.<NodeId>checkNotNull(nodeId);
- return nodeId.getValue();
- }
-
- public static org.opendaylight.controller.sal.core.NodeConnector toADNodeConnector(final NodeConnectorRef source) throws ConstructionException {
- Preconditions.<NodeConnectorRef>checkNotNull(source);
- final InstanceIdentifier<?> path = Preconditions.<InstanceIdentifier<? extends Object>>checkNotNull(source.getValue());
- Preconditions.checkArgument(path.getPath().size() >= 3);
- final PathArgument arg = path.getPath().get(2);
- final IdentifiableItem item = Arguments.<IdentifiableItem>checkInstanceOf(arg,IdentifiableItem.class);
- final NodeConnectorKey connectorKey = Arguments.<NodeConnectorKey>checkInstanceOf(item.getKey(), NodeConnectorKey.class);
- return NodeMapping.toADNodeConnector(connectorKey.getId(), NodeMapping.toNodeId(path));
- }
-
- public static org.opendaylight.controller.sal.core.NodeConnector toADNodeConnector(final NodeConnectorId ncid, final NodeId nid) {
- try {
- String nodeConnectorType = NodeMapping.toNodeConnectorType(ncid, nid);
- Object aDNodeConnectorId = NodeMapping.toADNodeConnectorId(ncid, nid);
- org.opendaylight.controller.sal.core.Node aDNode = NodeMapping.toADNode(nid);
- return new org.opendaylight.controller.sal.core.NodeConnector(nodeConnectorType, aDNodeConnectorId, aDNode);
- } catch (Throwable e) {
- throw Exceptions.sneakyThrow(e);
- }
- }
-
- public static String toNodeConnectorType(final NodeConnectorId ncId, final NodeId nodeId) {
- if (ncId.equals(toLocalNodeConnectorId(nodeId))) {
- return NodeConnectorIDType.SWSTACK;
- } else if (ncId.equals(toNormalNodeConnectorId(nodeId))) {
- return NodeConnectorIDType.HWPATH;
- } else if (ncId.equals(toControllerNodeConnectorId(nodeId))) {
- return NodeConnectorIDType.CONTROLLER;
- }
- return MD_SAL_TYPE;
- }
-
- public static Object toADNodeConnectorId(final NodeConnectorId nodeConnectorId, final NodeId nodeId) {
- if (nodeConnectorId.equals(toLocalNodeConnectorId(nodeId)) ||
- nodeConnectorId.equals(toNormalNodeConnectorId(nodeId)) ||
- nodeConnectorId.equals(toControllerNodeConnectorId(nodeId))) {
- return org.opendaylight.controller.sal.core.NodeConnector.SPECIALNODECONNECTORID;
- }
- return nodeConnectorId.getValue();
- }
-
- public static NodeConnectorId toControllerNodeConnectorId(final NodeId node) {
- return new NodeConnectorId(node.getValue() + ":" + 4294967293L);
- }
-
- public static NodeConnectorId toLocalNodeConnectorId(final NodeId node) {
- return new NodeConnectorId(node.getValue() + ":" + 4294967294L);
- }
-
- public static NodeConnectorId toNormalNodeConnectorId(final NodeId node) {
- return new NodeConnectorId(node.getValue() + ":" + 4294967290L);
- }
-
- public static NodeRef toNodeRef(final org.opendaylight.controller.sal.core.Node node) {
- Preconditions.checkArgument(MD_SAL_TYPE.equals(node.getType()));
- final String nodeId = Arguments.<String>checkInstanceOf(node.getID(), String.class);
- final NodeKey nodeKey = new NodeKey(new NodeId(nodeId));
- final InstanceIdentifier<Node> nodePath = InstanceIdentifier.builder(Nodes.class).child(NODE_CLASS, nodeKey).toInstance();
- return new NodeRef(nodePath);
- }
-
- public static NodeConnectorRef toNodeConnectorRef(final org.opendaylight.controller.sal.core.NodeConnector nodeConnector) {
-
- final NodeRef node = NodeMapping.toNodeRef(nodeConnector.getNode());
- final InstanceIdentifier<Node> nodePath = ((InstanceIdentifier<Node>) node.getValue());
- NodeConnectorId nodeConnectorId = null;
-
- if (nodeConnector.getID().equals(org.opendaylight.controller.sal.core.NodeConnector.SPECIALNODECONNECTORID)) {
- final NodeId nodeId = toNodeId(nodePath);
- final String nodeConnectorType = nodeConnector.getType();
- if (nodeConnectorType.equals(NodeConnectorIDType.SWSTACK)) {
- nodeConnectorId = toLocalNodeConnectorId(nodeId);
- } else if (nodeConnectorType.equals(NodeConnectorIDType.HWPATH)) {
- nodeConnectorId = toNormalNodeConnectorId(nodeId);
- } else if (nodeConnectorType.equals(NodeConnectorIDType.CONTROLLER)) {
- nodeConnectorId = toControllerNodeConnectorId(nodeId);