Cleanup MatchUtil
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / util / NodeConnectorRefToPortTranslator.java
index 4c71ea59e7ed4510d3c9f4f1996d80539ad4170c..4d00092816ec222ab4435a73cbe0f53a540e3d11 100644 (file)
@@ -1,51 +1,52 @@
-/**
+/*
  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.openflowplugin.impl.util;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
+import java.util.List;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.openflowplugin.api.OFConstants;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.in.port._case.InPort;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.InPortCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.in.port._case.InPort;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketIn;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPort;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import java.math.BigInteger;
-import java.util.List;
-import java.util.Objects;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
 
 /**
  * Created by Tomas Slusny on 23.3.2016.
  */
-public class NodeConnectorRefToPortTranslator {
+public final class NodeConnectorRefToPortTranslator {
+
+    private NodeConnectorRefToPortTranslator() {
+    }
+
     /**
-     * Converts {@link PacketIn} to {@link NodeConnectorRef}
+     * Converts {@link PacketIn} to {@link NodeConnectorRef}.
      * @param packetIn Packet input
      * @param dataPathId Data path id
      * @return packet input converted to node connector reference
      */
     @Nullable
-    public static NodeConnectorRef toNodeConnectorRef(@Nonnull PacketIn packetIn, BigInteger dataPathId) {
+    public static NodeConnectorRef toNodeConnectorRef(@NonNull final PacketIn packetIn, final Uint64 dataPathId) {
         Preconditions.checkNotNull(packetIn);
 
         NodeConnectorRef ref = null;
-        Long port = getPortNoFromPacketIn(packetIn);
+        Uint32 port = getPortNoFromPacketIn(packetIn);
 
         if (port != null) {
             OpenflowVersion version = OpenflowVersion.get(packetIn.getVersion());
@@ -64,14 +65,15 @@ public class NodeConnectorRefToPortTranslator {
      */
     @SuppressWarnings("unchecked")
     @Nullable
-    public static Long fromNodeConnectorRef(@Nonnull NodeConnectorRef nodeConnectorRef, short version) {
+    public static Uint32 fromNodeConnectorRef(@NonNull final NodeConnectorRef nodeConnectorRef, final short version) {
         Preconditions.checkNotNull(nodeConnectorRef);
 
-        Long port = null;
+        Uint32 port = null;
 
-        if (nodeConnectorRef.getValue() instanceof KeyedInstanceIdentifier) {
+        final InstanceIdentifier<?> value = nodeConnectorRef.getValue();
+        if (value instanceof KeyedInstanceIdentifier) {
             KeyedInstanceIdentifier<NodeConnector, NodeConnectorKey> identifier =
-                    (KeyedInstanceIdentifier<NodeConnector, NodeConnectorKey>) nodeConnectorRef.getValue();
+                    (KeyedInstanceIdentifier<NodeConnector, NodeConnectorKey>) value;
 
             OpenflowVersion ofVersion = OpenflowVersion.get(version);
             String nodeConnectorId = identifier.getKey().getId().getValue();
@@ -84,14 +86,14 @@ public class NodeConnectorRefToPortTranslator {
 
     @VisibleForTesting
     @Nullable
-    static Long getPortNoFromPacketIn(@Nonnull PacketIn packetIn) {
+    static Uint32 getPortNoFromPacketIn(@NonNull final PacketIn packetIn) {
         Preconditions.checkNotNull(packetIn);
 
-        Long port = null;
+        Uint32 port = null;
 
-        if (packetIn.getVersion() == OFConstants.OFP_VERSION_1_0 && packetIn.getInPort() != null) {
-            port = packetIn.getInPort().longValue();
-        } else if (packetIn.getVersion() == OFConstants.OFP_VERSION_1_3) {
+        if (packetIn.getVersion().toJava() == OFConstants.OFP_VERSION_1_0 && packetIn.getInPort() != null) {
+            port = Uint32.valueOf(packetIn.getInPort());
+        } else if (packetIn.getVersion().toJava() == OFConstants.OFP_VERSION_1_3) {
             if (packetIn.getMatch() != null && packetIn.getMatch().getMatchEntry() != null) {
                 List<MatchEntry> entries = packetIn.getMatch().getMatchEntry();