Checkstyle: fix issues and enforce on lisp-proto
[lispflowmapping.git] / mappingservice / lisp-proto / src / main / java / org / opendaylight / lispflowmapping / lisp / util / SourceDestKeyHelper.java
index 8873d217ed603681f4b2a9c04b218b618e07a401..1c1083837ae6c853dbfac546ceb7cb12b48f80f9 100644 (file)
@@ -15,16 +15,24 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
+ * Helper methods for Source/Dest Key type LCAF addresses.
+ *
  * @author Lorand Jakab
  *
  */
 
-public class SourceDestKeyHelper {
-    private final static Logger LOG = LoggerFactory.getLogger(SourceDestKeyHelper.class);
+public final class SourceDestKeyHelper {
+    // Utility class, should not be instantiated
+    private SourceDestKeyHelper() {
+    }
+
+    private static final Logger LOG = LoggerFactory.getLogger(SourceDestKeyHelper.class);
+
     public static Eid getSrc(Eid eid) {
         Address addr = eid.getAddress();
         if (addr instanceof SourceDestKey) {
-            return LispAddressUtil.toEid(eid, ((SourceDestKey)addr).getSourceDestKey().getSource());
+            return LispAddressUtil.asEid(((SourceDestKey) addr).getSourceDestKey().getSource(),
+                    eid.getVirtualNetworkId());
         } else {
             return eid;
         }
@@ -33,18 +41,35 @@ public class SourceDestKeyHelper {
     public static Eid getDst(Eid eid) {
         Address addr = eid.getAddress();
         if (addr instanceof SourceDestKey) {
-            return LispAddressUtil.toEid(eid, ((SourceDestKey)addr).getSourceDestKey().getDest());
+            return LispAddressUtil.asEid(((SourceDestKey) addr).getSourceDestKey().getDest(),
+                    eid.getVirtualNetworkId());
         } else {
             return eid;
         }
     }
 
+    public static Eid getSrcBinary(Eid eid) {
+        if (eid.getAddress() instanceof SourceDestKey) {
+            return LispAddressUtil.asBinaryEid(((SourceDestKey) eid.getAddress()).getSourceDestKey().getSource(),
+                    eid.getVirtualNetworkId());
+        }
+        return eid;
+    }
+
+    public static Eid getDstBinary(Eid eid) {
+        if (eid.getAddress() instanceof SourceDestKey) {
+            return LispAddressUtil.asBinaryEid(((SourceDestKey) eid.getAddress()).getSourceDestKey().getDest(),
+                    eid.getVirtualNetworkId());
+        }
+        return eid;
+    }
+
     public static short getSrcMask(Eid eid) {
         Address addr = eid.getAddress();
         if (!isSrcDst(addr)) {
             return 0;
         }
-        return MaskUtil.getMaskForIpPrefix(((SourceDestKey)addr).getSourceDestKey().getSource());
+        return MaskUtil.getMaskForAddress(((SourceDestKey)addr).getSourceDestKey().getSource());
     }
 
     public static short getDstMask(Eid eid) {
@@ -52,7 +77,7 @@ public class SourceDestKeyHelper {
         if (!isSrcDst(addr)) {
             return 0;
         }
-        return MaskUtil.getMaskForIpPrefix(((SourceDestKey)addr).getSourceDestKey().getDest());
+        return MaskUtil.getMaskForAddress(((SourceDestKey)addr).getSourceDestKey().getDest());
     }
 
     private static boolean isSrcDst(Address addr) {