Copyright update
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / OF10FlowRemovedMessageFactory.java
1 /*
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
10
11 import io.netty.buffer.ByteBuf;
12
13 import java.math.BigInteger;
14
15 import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;
16 import org.opendaylight.openflowjava.protocol.impl.util.OF10MatchDeserializer;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessageBuilder;
20
21 /**
22  * Translates FlowRemoved messages (OpenFlow v1.0)
23  * @author michal.polkorab
24  */
25 public class OF10FlowRemovedMessageFactory implements OFDeserializer<FlowRemovedMessage> {
26
27     private static final byte PADDING_IN_FLOW_REMOVED_MESSAGE = 1;
28     private static final byte PADDING_IN_FLOW_REMOVED_MESSAGE_2 = 2;
29     
30     
31     private static OF10FlowRemovedMessageFactory instance;
32     
33     private OF10FlowRemovedMessageFactory() {
34         // singleton
35     }
36     
37     /**
38      * @return singleton factory
39      */
40     public static synchronized OF10FlowRemovedMessageFactory getInstance(){
41         if(instance == null){
42             instance = new OF10FlowRemovedMessageFactory();
43         }
44         return instance;
45     }
46
47     @Override
48     public FlowRemovedMessage bufferToMessage(ByteBuf rawMessage, short version) {
49         FlowRemovedMessageBuilder builder = new FlowRemovedMessageBuilder();
50         builder.setVersion(version);
51         builder.setXid(rawMessage.readUnsignedInt());
52         builder.setMatchV10(OF10MatchDeserializer.createMatchV10(rawMessage));
53         byte[] cookie = new byte[Long.SIZE/Byte.SIZE];
54         rawMessage.readBytes(cookie);
55         builder.setCookie(new BigInteger(cookie));
56         builder.setPriority(rawMessage.readUnsignedShort());
57         builder.setReason(FlowRemovedReason.forValue(rawMessage.readUnsignedByte()));
58         rawMessage.skipBytes(PADDING_IN_FLOW_REMOVED_MESSAGE);
59         builder.setDurationSec(rawMessage.readUnsignedInt());
60         builder.setDurationNsec(rawMessage.readUnsignedInt());
61         builder.setIdleTimeout(rawMessage.readUnsignedShort());
62         rawMessage.skipBytes(PADDING_IN_FLOW_REMOVED_MESSAGE_2);
63         byte[] packet_count = new byte[Long.SIZE/Byte.SIZE];
64         rawMessage.readBytes(packet_count);
65         builder.setPacketCount(new BigInteger(packet_count));
66         byte[] byte_count = new byte[Long.SIZE/Byte.SIZE];
67         rawMessage.readBytes(byte_count);
68         builder.setByteCount(new BigInteger(byte_count));
69         return builder.build();
70     }
71
72     
73 }