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