Merge "Bug-835:Reserve ports should be logical ports"
authorEd Warnicke <eaw@cisco.com>
Thu, 26 Jun 2014 12:16:48 +0000 (12:16 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 26 Jun 2014 12:16:48 +0000 (12:16 +0000)
1  2 
opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/NodeMapping.java

@@@ -7,11 -7,8 +7,8 @@@
   */
  package org.opendaylight.controller.sal.compatibility;
  
- import java.math.BigInteger;
- import java.util.Date;
- import java.util.HashSet;
- import java.util.List;
+ import com.google.common.base.Objects;
+ import com.google.common.base.Preconditions;
  import org.opendaylight.controller.sal.common.util.Arguments;
  import org.opendaylight.controller.sal.core.AdvertisedBandwidth;
  import org.opendaylight.controller.sal.core.Bandwidth;
@@@ -21,7 -18,6 +18,7 @@@ import org.opendaylight.controller.sal.
  import org.opendaylight.controller.sal.core.ConstructionException;
  import org.opendaylight.controller.sal.core.MacAddress;
  import org.opendaylight.controller.sal.core.Name;
 +import org.opendaylight.controller.sal.core.Node.NodeIDType;
  import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
  import org.opendaylight.controller.sal.core.PeerBandwidth;
  import org.opendaylight.controller.sal.core.Property;
@@@ -45,6 -41,7 +42,7 @@@ import org.opendaylight.yang.gen.v1.urn
  import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig;
  import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures;
  import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.flow.capable.port.State;
+ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues;
  import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
  import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
  import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated;
@@@ -58,15 -55,13 +56,17 @@@ import org.opendaylight.yang.gen.v1.urn
  import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
  import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
  
- import com.google.common.base.Objects;
- import com.google.common.base.Preconditions;
+ import java.math.BigInteger;
+ import java.util.Date;
+ import java.util.HashSet;
+ import java.util.List;
  
  public final class NodeMapping {
 -    public final static String MD_SAL_TYPE = "MD_SAL";
 +
 +    /** openflow id prefix */
 +    public static final String OPENFLOW_ID_PREFIX = "openflow:";
 +
 +    public final static String MD_SAL_TYPE = "MD_SAL_DEPRECATED";
  
      private final static Class<Node> NODE_CLASS = Node.class;
  
      }
  
      public static org.opendaylight.controller.sal.core.Node toADNode(final NodeId id) throws ConstructionException {
 -        String aDNodeId = NodeMapping.toADNodeId(id);
 -        return new org.opendaylight.controller.sal.core.Node(NodeMapping.MD_SAL_TYPE, aDNodeId);
 +        Long aDNodeId = openflowFullNodeIdToLong(NodeMapping.toADNodeId(id));
 +        return new org.opendaylight.controller.sal.core.Node(NodeIDType.OPENFLOW, aDNodeId);
 +    }
 +
 +    /**
 +     * @param adNodeId
 +     * @return
 +     */
 +    private static Long openflowFullNodeIdToLong(String adNodeId) {
 +        if (adNodeId == null) {
 +            return null;
 +        }
 +        return Long.valueOf(adNodeId.replaceFirst("^.*:", ""));
      }
  
      public static NodeId toNodeId(final InstanceIdentifier<?> id) {
      }
  
      public static String toADNodeId(final NodeId nodeId) {
 +        if (nodeId == null) {
 +            return null;
 +        }
          return nodeId.getValue();
      }
  
          } else if (ncId.equals(toControllerNodeConnectorId(nodeId))) {
              return NodeConnectorIDType.CONTROLLER;
          }
 -        return MD_SAL_TYPE;
 +        return NodeConnectorIDType.OPENFLOW;
      }
  
      public static Object toADNodeConnectorId(final NodeConnectorId nodeConnectorId, final NodeId nodeId) {
                  nodeConnectorId.equals(toControllerNodeConnectorId(nodeId))) {
              return org.opendaylight.controller.sal.core.NodeConnector.SPECIALNODECONNECTORID;
          }
 -        return nodeConnectorId.getValue();
 +
 +        return (short) Long.valueOf(nodeConnectorId.getValue().replaceFirst("^.*:", "")).longValue();
      }
  
      public static NodeId toAdNodeId(final NodeConnectorId nodeConnectorId) {
      }
  
      public static NodeConnectorId toControllerNodeConnectorId(final NodeId node) {
-         return new NodeConnectorId(node.getValue() + ":" + 4294967293L);
+         return new NodeConnectorId(node.getValue() + ":" + OutputPortValues.CONTROLLER.toString());
      }
  
      public static NodeConnectorId toLocalNodeConnectorId(final NodeId node) {
-         return new NodeConnectorId(node.getValue() + ":" + 4294967294L);
+         return new NodeConnectorId(node.getValue() + ":" + OutputPortValues.LOCAL.toString());
      }
  
      public static NodeConnectorId toNormalNodeConnectorId(final NodeId node) {
-         return new NodeConnectorId(node.getValue() + ":" + 4294967290L);
+         return new NodeConnectorId(node.getValue() + ":" + OutputPortValues.NORMAL.toString());
      }
  
      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));
 +        Preconditions.checkArgument(NodeIDType.OPENFLOW.equals(node.getType()));
 +        final Long nodeId = Arguments.<Long>checkInstanceOf(node.getID(), Long.class);
 +        final NodeKey nodeKey = new NodeKey(new NodeId(OPENFLOW_ID_PREFIX+nodeId));
          final InstanceIdentifier<Node> nodePath = InstanceIdentifier.builder(Nodes.class).child(NODE_CLASS, nodeKey).toInstance();
          return new NodeRef(nodePath);
      }
                  nodeConnectorId = toControllerNodeConnectorId(nodeId);
              }
          } else {
 -            nodeConnectorId = new NodeConnectorId(Arguments.<String>checkInstanceOf(nodeConnector.getID(), String.class));
 +            nodeConnectorId = new NodeConnectorId(OPENFLOW_ID_PREFIX
 +                    + Arguments.<Short>checkInstanceOf(nodeConnector.getID(), Short.class));
          }
          final NodeConnectorKey connectorKey = new NodeConnectorKey(nodeConnectorId);
          final InstanceIdentifier<NodeConnector> path = nodePath.child(NODECONNECTOR_CLASS, connectorKey);
      }
  
      public static MacAddress toADMacAddress(final NodeId id) {
 -        final String nodeId = id.getValue().replaceAll("openflow:", "");
 +        final String nodeId = id.getValue().replaceAll(OPENFLOW_ID_PREFIX, "");
          BigInteger nodeIdRaw = new BigInteger(nodeId);
          long lNodeId = nodeIdRaw.longValue();
          byte[] bytesFromDpid = ToSalConversionsUtils.bytesFromDpid(lNodeId);

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.