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.serialization.factories;
11 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.UnpooledByteBufAllocator;
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.SwitchConfigFlag;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInputBuilder;
27 * Unit tests for SetConfigMessageFactory.
29 * @author timotej.kubas
30 * @author michal.polkorab
32 public class SetConfigMessageFactoryTest {
33 private static final byte MESSAGE_TYPE = 9;
34 private static final int MESSAGE_LENGTH = 12;
35 private SerializerRegistry registry;
36 private OFSerializer<SetConfigInput> setConfigFactory;
39 * Initializes serializer registry and stores correct factory in field.
42 public void startUp() {
43 registry = new SerializerRegistryImpl();
45 setConfigFactory = registry.getSerializer(
46 new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, SetConfigInput.class));
50 * Testing of {@link SetConfigMessageFactory} for correct translation from POJO.
53 public void testSetConfigMessageV13() throws Exception {
54 SetConfigInputBuilder builder = new SetConfigInputBuilder();
55 BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
56 SwitchConfigFlag flag = SwitchConfigFlag.FRAGNORMAL;
57 builder.setFlags(flag);
58 builder.setMissSendLen(10);
59 SetConfigInput message = builder.build();
61 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
62 setConfigFactory.serialize(message, out);
64 BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH);
65 Assert.assertEquals("Wrong flags", SwitchConfigFlag.FRAGNORMAL.getIntValue(), out.readUnsignedShort());
66 Assert.assertEquals("Wrong missSendLen", 10, out.readUnsignedShort());
70 * Testing of {@link SetConfigMessageFactory} for correct translation from POJO.
73 public void testSetConfigMessageV10() throws Exception {
74 SetConfigInputBuilder builder = new SetConfigInputBuilder();
75 BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
76 SwitchConfigFlag flag = SwitchConfigFlag.OFPCFRAGDROP;
77 builder.setFlags(flag);
78 builder.setMissSendLen(85);
79 SetConfigInput message = builder.build();
81 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
82 setConfigFactory.serialize(message, out);
84 BufferHelper.checkHeaderV10(out, MESSAGE_TYPE, MESSAGE_LENGTH);
85 Assert.assertEquals("Wrong flags", SwitchConfigFlag.OFPCFRAGDROP.getIntValue(), out.readUnsignedShort());
86 Assert.assertEquals("Wrong missSendLen", 85, out.readUnsignedShort());