24f15ff1460b329e81e93cab480769d6561c70dd
[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.openflowjava.protocol.impl.util.MatchDeserializer;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessageBuilder;
14
15 /**
16  * Translates FlowRemoved messages
17  * @author michal.polkorab
18  * @author timotej.kubas
19  */
20 public class FlowRemovedMessageFactory implements OFDeserializer<FlowRemovedMessage> {
21     
22     private static FlowRemovedMessageFactory instance;
23     
24     private FlowRemovedMessageFactory() {
25         // singleton
26     }
27     
28     /**
29      * @return singleton factory
30      */
31     public static synchronized FlowRemovedMessageFactory getInstance(){
32         if(instance == null){
33             instance = new FlowRemovedMessageFactory();
34         }
35         return instance;
36     }
37
38     @Override
39     public FlowRemovedMessage bufferToMessage(ByteBuf rawMessage, short version) {
40         FlowRemovedMessageBuilder builder = new FlowRemovedMessageBuilder();
41         builder.setVersion(version);
42         builder.setXid(rawMessage.readUnsignedInt());
43         byte[] cookie = new byte[Long.SIZE/Byte.SIZE];
44         rawMessage.readBytes(cookie);
45         builder.setCookie(new BigInteger(cookie));
46         builder.setPriority(rawMessage.readUnsignedShort());
47         builder.setReason(FlowRemovedReason.forValue(rawMessage.readUnsignedByte()));
48         builder.setTableId(new TableId((long)rawMessage.readUnsignedByte()));
49         builder.setDurationSec(rawMessage.readUnsignedInt());
50         builder.setDurationNsec(rawMessage.readUnsignedInt());
51         builder.setIdleTimeout(rawMessage.readUnsignedShort());
52         builder.setHardTimeout(rawMessage.readUnsignedShort());
53         byte[] packet_count = new byte[Long.SIZE/Byte.SIZE];
54         rawMessage.readBytes(packet_count);
55         builder.setPacketCount(new BigInteger(packet_count));
56         byte[] byte_count = new byte[Long.SIZE/Byte.SIZE];
57         rawMessage.readBytes(byte_count);
58         builder.setByteCount(new BigInteger(byte_count));
59         builder.setMatch(MatchDeserializer.createMatch(rawMessage));
60         return builder.build();
61     }
62 }