Merge "Removed System.out.println()"
[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.EncodeConstants;
17 import org.opendaylight.openflowjava.protocol.impl.util.OF10MatchDeserializer;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason;
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 (OpenFlow v1.0)
24  * @author michal.polkorab
25  */
26 public class OF10FlowRemovedMessageFactory implements OFDeserializer<FlowRemovedMessage> {
27
28     private static final byte PADDING_IN_FLOW_REMOVED_MESSAGE = 1;
29     private static final byte PADDING_IN_FLOW_REMOVED_MESSAGE_2 = 2;
30     
31     
32     private static OF10FlowRemovedMessageFactory instance;
33     
34     private OF10FlowRemovedMessageFactory() {
35         // singleton
36     }
37     
38     /**
39      * @return singleton factory
40      */
41     public static synchronized OF10FlowRemovedMessageFactory getInstance(){
42         if(instance == null){
43             instance = new OF10FlowRemovedMessageFactory();
44         }
45         return instance;
46     }
47
48     @Override
49     public FlowRemovedMessage bufferToMessage(ByteBuf rawMessage, short version) {
50         FlowRemovedMessageBuilder builder = new FlowRemovedMessageBuilder();
51         builder.setVersion(version);
52         builder.setXid(rawMessage.readUnsignedInt());
53         builder.setMatchV10(OF10MatchDeserializer.createMatchV10(rawMessage));
54         byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
55         rawMessage.readBytes(cookie);
56         builder.setCookie(new BigInteger(1, cookie));
57         builder.setPriority(rawMessage.readUnsignedShort());
58         builder.setReason(FlowRemovedReason.forValue(rawMessage.readUnsignedByte()));
59         rawMessage.skipBytes(PADDING_IN_FLOW_REMOVED_MESSAGE);
60         builder.setDurationSec(rawMessage.readUnsignedInt());
61         builder.setDurationNsec(rawMessage.readUnsignedInt());
62         builder.setIdleTimeout(rawMessage.readUnsignedShort());
63         rawMessage.skipBytes(PADDING_IN_FLOW_REMOVED_MESSAGE_2);
64         byte[] packet_count = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
65         rawMessage.readBytes(packet_count);
66         builder.setPacketCount(new BigInteger(1, packet_count));
67         byte[] byte_count = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
68         rawMessage.readBytes(byte_count);
69         builder.setByteCount(new BigInteger(1, byte_count));
70         return builder.build();
71     }
72
73     
74 }