Integration test, SimpleClient bundle
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / FlowRemovedMessageFactory.java
1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
2 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
3
4 import io.netty.buffer.ByteBuf;
5
6 import java.math.BigInteger;
7
8 import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessageBuilder;
13
14 /**
15  * @author michal.polkorab
16  * @author timotej.kubas
17  */
18 public class FlowRemovedMessageFactory implements OFDeserializer<FlowRemovedMessage> {
19     
20     private static FlowRemovedMessageFactory instance;
21     
22     private FlowRemovedMessageFactory() {
23         // singleton
24     }
25     
26     /**
27      * @return singleton factory
28      */
29     public static synchronized FlowRemovedMessageFactory getInstance(){
30         if(instance == null){
31             instance = new FlowRemovedMessageFactory();
32         }
33         return instance;
34     }
35
36     @Override
37     public FlowRemovedMessage bufferToMessage(ByteBuf rawMessage, short version) {
38         FlowRemovedMessageBuilder builder = new FlowRemovedMessageBuilder();
39         builder.setVersion(version);
40         builder.setXid(rawMessage.readUnsignedInt());
41         byte[] cookie = new byte[Long.SIZE/Byte.SIZE];
42         rawMessage.readBytes(cookie);
43         builder.setCookie(new BigInteger(cookie));
44         builder.setPriority(rawMessage.readUnsignedShort());
45         builder.setReason(FlowRemovedReason.forValue(rawMessage.readUnsignedByte()));
46         builder.setTableId(new TableId((long)rawMessage.readUnsignedByte()));
47         builder.setDurationSec(rawMessage.readUnsignedInt());
48         builder.setDurationNsec(rawMessage.readUnsignedInt());
49         builder.setIdleTimeout(rawMessage.readUnsignedShort());
50         builder.setHardTimeout(rawMessage.readUnsignedShort());
51         byte[] packet_count = new byte[Long.SIZE/Byte.SIZE];
52         rawMessage.readBytes(packet_count);
53         builder.setPacketCount(new BigInteger(packet_count));
54         byte[] byte_count = new byte[Long.SIZE/Byte.SIZE];
55         rawMessage.readBytes(byte_count);
56         builder.setByteCount(new BigInteger(byte_count));
57         return builder.build();
58     }
59 }