2 * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
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
9 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
11 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutputBuilder;
18 * Translates EchoReply messages (both OpenFlow v1.0 and OpenFlow v1.3)
19 * @author michal.polkorab
20 * @author timotej.kubas
22 public class EchoReplyMessageFactory implements OFDeserializer<EchoOutput> {
24 private static EchoReplyMessageFactory instance;
26 private EchoReplyMessageFactory() {
27 // do nothing, just singleton
31 * @return singleton factory
33 public static synchronized EchoReplyMessageFactory getInstance() {
34 if (instance == null) {
35 instance = new EchoReplyMessageFactory();
41 public EchoOutput bufferToMessage(ByteBuf rawMessage, short version) {
42 EchoOutputBuilder builder = new EchoOutputBuilder();
43 builder.setVersion(version);
44 builder.setXid(rawMessage.readUnsignedInt());
45 int remainingBytes = rawMessage.readableBytes();
46 if (remainingBytes > 0) {
47 builder.setData(rawMessage.readBytes(remainingBytes).array());
49 return builder.build();