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 java.math.BigInteger;
15 import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ControllerRole;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutputBuilder;
21 * Translates RoleReply messages
22 * @author timotej.kubas
23 * @author michal.polkorab
25 public class RoleReplyMessageFactory implements OFDeserializer<RoleRequestOutput>{
26 private static RoleReplyMessageFactory instance;
27 private static final byte PADDING_IN_ROLE_REPLY_HEADER = 4;
29 private RoleReplyMessageFactory() {
35 * @return singleton factory
37 public static synchronized RoleReplyMessageFactory getInstance(){
39 instance = new RoleReplyMessageFactory();
45 public RoleRequestOutput bufferToMessage(ByteBuf rawMessage, short version) {
46 RoleRequestOutputBuilder builder = new RoleRequestOutputBuilder();
47 builder.setVersion(version);
48 builder.setXid(rawMessage.readUnsignedInt());
49 builder.setRole(ControllerRole.forValue((int) rawMessage.readUnsignedInt()));
50 rawMessage.skipBytes(PADDING_IN_ROLE_REPLY_HEADER);
51 byte[] generationID = new byte[8];
52 rawMessage.readBytes(generationID);
53 builder.setGenerationId(new BigInteger(1, generationID));
54 return builder.build();