Use YANG java files instead of the old model TELSDN-474 #close
[lispflowmapping.git] / mappingservice / implementation / src / main / java / org / opendaylight / lispflowmapping / implementation / serializer / address / LispMACAddressSerializer.java
index 42af5a54e45b482ceb606a3d35a1938b5c4ba08e..66c0d71abddca8512fd3ebc3e383a783e59e9886 100644 (file)
@@ -2,40 +2,52 @@ package org.opendaylight.lispflowmapping.implementation.serializer.address;
 
 import java.nio.ByteBuffer;
 
-import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
-import org.opendaylight.lispflowmapping.type.lisp.address.LispMACAddress;
+import javax.xml.bind.DatatypeConverter;
 
-public class LispMACAddressSerializer extends LispAddressSerializer{
-       
-       private static final LispMACAddressSerializer INSTANCE = new LispMACAddressSerializer();
+import org.apache.tomcat.util.buf.HexUtils;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.LispAFIAddress;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.LispMacAddress;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.lispaddresscontainer.address.MacBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
 
-       // Private constructor prevents instantiation from other classes
-       private LispMACAddressSerializer() {
-       }
+public class LispMACAddressSerializer extends LispAddressSerializer {
 
-       public static LispMACAddressSerializer getInstance() {
-               return INSTANCE;
-       }
+    private static final LispMACAddressSerializer INSTANCE = new LispMACAddressSerializer();
 
+    // Private constructor prevents instantiation from other classes
+    private LispMACAddressSerializer() {
+    }
 
-       @Override
-    public int getAddressSize(LispAddress lispAddress) {
-               return Length.MAC;
+    public static LispMACAddressSerializer getInstance() {
+        return INSTANCE;
     }
-       
-       @Override
-       protected LispMACAddress deserializeData(ByteBuffer buffer) {
-               byte[] macBuffer = new byte[6];
-               buffer.get(macBuffer);
-        return new LispMACAddress(macBuffer);
+
+    @Override
+    public int getAddressSize(LispAFIAddress lispAddress) {
+        return Length.MAC;
     }
 
     @Override
-    protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
-       LispMACAddress lispMACAddress = (LispMACAddress)lispAddress;
-        buffer.put(lispMACAddress.getMAC());
+    protected LispMacAddress deserializeData(ByteBuffer buffer) {
+        byte[] macBuffer = new byte[6];
+        buffer.get(macBuffer);
+        StringBuilder sb = new StringBuilder(17);
+        for (byte b : macBuffer) {
+            if (sb.length() > 0)
+                sb.append(':');
+            sb.append(String.format("%02x", b));
+        }
+        return new MacBuilder().setMacAddress(new MacAddress(sb.toString())).setAfi((short) 16389).build();
     }
-    
+
+    @Override
+    protected void serializeData(ByteBuffer buffer, LispAFIAddress lispAddress) {
+        LispMacAddress lispMACAddress = (LispMacAddress) lispAddress;
+        String macString = lispMACAddress.getMacAddress().getValue();
+        macString = macString.replaceAll(":", "");
+        buffer.put(DatatypeConverter.parseHexBinary(macString));
+    }
+
     private interface Length {
         int MAC = 6;
     }