2 * Copyright (c) 2015 NetIDE Consortium 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
8 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
10 import io.netty.buffer.ByteBuf;
11 import io.netty.buffer.UnpooledByteBufAllocator;
12 import java.math.BigInteger;
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
17 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
18 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
19 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
20 import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
21 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ControllerRole;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutputBuilder;
25 import org.opendaylight.yangtools.yang.common.Uint64;
28 * Unit tests for RoleReplyMessageFactory.
30 * @author giuseppex.petralia@intel.com
32 public class RoleReplyMessageFactoryTest {
33 private OFSerializer<RoleRequestOutput> factory;
34 private static final byte MESSAGE_TYPE = 25;
35 private static final byte PADDING = 4;
38 public void startUp() {
39 SerializerRegistry registry = new SerializerRegistryImpl();
42 .getSerializer(new MessageTypeKey<>(EncodeConstants.OF_VERSION_1_3, RoleRequestOutput.class));
46 public void testSerialize() throws Exception {
47 RoleRequestOutputBuilder builder = new RoleRequestOutputBuilder();
48 BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
49 builder.setRole(ControllerRole.forValue(0));
50 builder.setGenerationId(Uint64.ONE);
51 RoleRequestOutput message = builder.build();
53 ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
54 factory.serialize(message, serializedBuffer);
55 BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 24);
56 Assert.assertEquals("Wrong role", message.getRole().getIntValue(),
57 ControllerRole.forValue((int) serializedBuffer.readUnsignedInt()).getIntValue());
58 serializedBuffer.skipBytes(PADDING);
59 byte[] genId = new byte[Long.BYTES];
60 serializedBuffer.readBytes(genId);
61 Assert.assertEquals("Wrong generation ID", message.getGenerationId(), Uint64.valueOf(new BigInteger(1, genId)));