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;
14 import org.junit.Assert;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
18 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
19 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
20 import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
21 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
22 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.SwitchConfigFlag;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInputBuilder;
28 * @author timotej.kubas
29 * @author michal.polkorab
31 public class SetConfigMessageFactoryTest {
32 private static final byte MESSAGE_TYPE = 9;
33 private static final int MESSAGE_LENGTH = 12;
34 private SerializerRegistry registry;
35 private OFSerializer<SetConfigInput> setConfigFactory;
38 * Initializes serializer registry and stores correct factory in field
41 public void startUp() {
42 registry = new SerializerRegistryImpl();
44 setConfigFactory = registry.getSerializer(
45 new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, SetConfigInput.class));
49 * 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
74 public void testSetConfigMessageV10() throws Exception {
75 SetConfigInputBuilder builder = new SetConfigInputBuilder();
76 BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
77 SwitchConfigFlag flag = SwitchConfigFlag.OFPCFRAGDROP;
78 builder.setFlags(flag);
79 builder.setMissSendLen(85);
80 SetConfigInput message = builder.build();
82 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
83 setConfigFactory.serialize(message, out);
85 BufferHelper.checkHeaderV10(out, MESSAGE_TYPE, MESSAGE_LENGTH);
86 Assert.assertEquals("Wrong flags", SwitchConfigFlag.OFPCFRAGDROP.getIntValue(), out.readUnsignedShort());
87 Assert.assertEquals("Wrong missSendLen", 85, out.readUnsignedShort());