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.Test;
16 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
17 import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.SwitchConfigFlag;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInputBuilder;
23 * @author timotej.kubas
24 * @author michal.polkorab
26 public class SetConfigMessageFactoryTest {
27 private static final byte MESSAGE_TYPE = 9;
28 private static final int MESSAGE_LENGTH = 12;
31 * Testing of {@link SetConfigMessageFactory} for correct translation from POJO
35 public void testSetConfigMessageV13() throws Exception {
36 SetConfigInputBuilder builder = new SetConfigInputBuilder();
37 BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
38 SwitchConfigFlag flag = SwitchConfigFlag.FRAGNORMAL;
39 builder.setFlags(flag);
40 builder.setMissSendLen(10);
41 SetConfigInput message = builder.build();
43 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
44 SetConfigMessageFactory factory = SetConfigMessageFactory.getInstance();
45 factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);
47 BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH);
48 Assert.assertEquals("Wrong flags", SwitchConfigFlag.FRAGNORMAL.getIntValue(), out.readUnsignedShort());
49 Assert.assertEquals("Wrong missSendLen", 10, out.readUnsignedShort());
53 * Testing of {@link SetConfigMessageFactory} for correct translation from POJO
57 public void testSetConfigMessageV10() throws Exception {
58 SetConfigInputBuilder builder = new SetConfigInputBuilder();
59 BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
60 SwitchConfigFlag flag = SwitchConfigFlag.OFPCFRAGDROP;
61 builder.setFlags(flag);
62 builder.setMissSendLen(85);
63 SetConfigInput message = builder.build();
65 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
66 SetConfigMessageFactory factory = SetConfigMessageFactory.getInstance();
67 factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);
69 BufferHelper.checkHeaderV10(out, MESSAGE_TYPE, MESSAGE_LENGTH);
70 Assert.assertEquals("Wrong flags", SwitchConfigFlag.OFPCFRAGDROP.getIntValue(), out.readUnsignedShort());
71 Assert.assertEquals("Wrong missSendLen", 85, out.readUnsignedShort());