cefb7f1a9ebbeded0a5d51c1c2a8ea37b59ccef8
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / OF10HelloMessageFactory.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 org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessageBuilder;
16
17 /**
18  * Translates Hello messages (OpenFlow v1.0)
19  * @author michal.polkorab
20  */
21 public class OF10HelloMessageFactory implements OFDeserializer<HelloMessage> {
22     
23 private static OF10HelloMessageFactory instance;
24     
25     private OF10HelloMessageFactory() {
26         // do nothing, just singleton
27     }
28     
29     /**
30      * @return singleton factory
31      */
32     public static synchronized OF10HelloMessageFactory getInstance() {
33         if (instance == null) {
34             instance = new OF10HelloMessageFactory();
35         }
36         return instance;
37     }
38     
39     @Override
40     public HelloMessage bufferToMessage(ByteBuf rawMessage, short version) {
41         HelloMessageBuilder builder = new HelloMessageBuilder();
42         builder.setVersion(version);
43         builder.setXid(rawMessage.readUnsignedInt());
44         if (rawMessage.readableBytes() > 0) {
45             rawMessage.skipBytes(rawMessage.readableBytes());
46         }
47         return builder.build();
48     }
49
50 }