Bug 2756 - Match model update
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / FlowRemovedMessageFactory.java
index 7df6835cd902277a9512f8f7547c54e2cb817fd2..05ababb3dd6cd1dca0696eb3e0991c21c44f3306 100644 (file)
@@ -12,10 +12,14 @@ import io.netty.buffer.ByteBuf;
 
 import java.math.BigInteger;
 
-import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;
-import org.opendaylight.openflowjava.protocol.impl.util.MatchDeserializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
+import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
+import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessageBuilder;
 
@@ -24,32 +28,19 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
  * @author michal.polkorab
  * @author timotej.kubas
  */
-public class FlowRemovedMessageFactory implements OFDeserializer<FlowRemovedMessage> {
-    
-    private static FlowRemovedMessageFactory instance;
-    
-    private FlowRemovedMessageFactory() {
-        // singleton
-    }
-    
-    /**
-     * @return singleton factory
-     */
-    public static synchronized FlowRemovedMessageFactory getInstance(){
-        if(instance == null){
-            instance = new FlowRemovedMessageFactory();
-        }
-        return instance;
-    }
+public class FlowRemovedMessageFactory implements OFDeserializer<FlowRemovedMessage>,
+        DeserializerRegistryInjector {
+
+    private DeserializerRegistry registry;
 
     @Override
-    public FlowRemovedMessage bufferToMessage(ByteBuf rawMessage, short version) {
+    public FlowRemovedMessage deserialize(ByteBuf rawMessage) {
         FlowRemovedMessageBuilder builder = new FlowRemovedMessageBuilder();
-        builder.setVersion(version);
+        builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
         builder.setXid(rawMessage.readUnsignedInt());
-        byte[] cookie = new byte[Long.SIZE/Byte.SIZE];
+        byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
         rawMessage.readBytes(cookie);
-        builder.setCookie(new BigInteger(cookie));
+        builder.setCookie(new BigInteger(1, cookie));
         builder.setPriority(rawMessage.readUnsignedShort());
         builder.setReason(FlowRemovedReason.forValue(rawMessage.readUnsignedByte()));
         builder.setTableId(new TableId((long)rawMessage.readUnsignedByte()));
@@ -57,13 +48,20 @@ public class FlowRemovedMessageFactory implements OFDeserializer<FlowRemovedMess
         builder.setDurationNsec(rawMessage.readUnsignedInt());
         builder.setIdleTimeout(rawMessage.readUnsignedShort());
         builder.setHardTimeout(rawMessage.readUnsignedShort());
-        byte[] packet_count = new byte[Long.SIZE/Byte.SIZE];
-        rawMessage.readBytes(packet_count);
-        builder.setPacketCount(new BigInteger(packet_count));
-        byte[] byte_count = new byte[Long.SIZE/Byte.SIZE];
-        rawMessage.readBytes(byte_count);
-        builder.setByteCount(new BigInteger(byte_count));
-        builder.setMatch(MatchDeserializer.createMatch(rawMessage));
+        byte[] packetCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
+        rawMessage.readBytes(packetCount);
+        builder.setPacketCount(new BigInteger(1, packetCount));
+        byte[] byteCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
+        rawMessage.readBytes(byteCount);
+        builder.setByteCount(new BigInteger(1, byteCount));
+        OFDeserializer<Match> matchDeserializer = registry.getDeserializer(new MessageCodeKey(
+                EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Match.class));
+        builder.setMatch(matchDeserializer.deserialize(rawMessage));
         return builder.build();
     }
+
+    @Override
+    public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) {
+        registry = deserializerRegistry;
+    }
 }