import java.math.BigInteger;
-import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;
-import org.opendaylight.openflowjava.protocol.impl.util.OF10MatchDeserializer;
+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.oxm.rev150225.match.v10.grouping.MatchV10;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessageBuilder;
* Translates FlowRemoved messages (OpenFlow v1.0)
* @author michal.polkorab
*/
-public class OF10FlowRemovedMessageFactory implements OFDeserializer<FlowRemovedMessage> {
+public class OF10FlowRemovedMessageFactory implements OFDeserializer<FlowRemovedMessage>,
+ DeserializerRegistryInjector {
private static final byte PADDING_IN_FLOW_REMOVED_MESSAGE = 1;
private static final byte PADDING_IN_FLOW_REMOVED_MESSAGE_2 = 2;
-
-
- private static OF10FlowRemovedMessageFactory instance;
-
- private OF10FlowRemovedMessageFactory() {
- // singleton
- }
-
- /**
- * @return singleton factory
- */
- public static synchronized OF10FlowRemovedMessageFactory getInstance(){
- if(instance == null){
- instance = new OF10FlowRemovedMessageFactory();
- }
- return instance;
- }
+ 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.OF10_VERSION_ID);
builder.setXid(rawMessage.readUnsignedInt());
- builder.setMatchV10(OF10MatchDeserializer.createMatchV10(rawMessage));
- byte[] cookie = new byte[Long.SIZE/Byte.SIZE];
+ OFDeserializer<MatchV10> matchDeserializer = registry.getDeserializer(
+ new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, MatchV10.class));
+ builder.setMatchV10(matchDeserializer.deserialize(rawMessage));
+ 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()));
rawMessage.skipBytes(PADDING_IN_FLOW_REMOVED_MESSAGE);
builder.setDurationNsec(rawMessage.readUnsignedInt());
builder.setIdleTimeout(rawMessage.readUnsignedShort());
rawMessage.skipBytes(PADDING_IN_FLOW_REMOVED_MESSAGE_2);
- 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));
+ 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));
return builder.build();
}
-
+ @Override
+ public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) {
+ registry = deserializerRegistry;
+ }
}