1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
\r
2 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
\r
4 import io.netty.buffer.ByteBuf;
\r
5 import io.netty.buffer.UnpooledByteBufAllocator;
\r
6 import junit.framework.Assert;
\r
8 import org.junit.Test;
\r
9 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
\r
10 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
\r
11 import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
\r
12 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
\r
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10;
\r
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;
\r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
\r
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
\r
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
\r
20 * @author michal.polkorab
\r
23 public class OF10PortModInputMessageFactoryTest {
\r
26 * Testing of {@link OF10PortModInputMessageFactory} for correct translation from POJO
\r
27 * @throws Exception
\r
30 public void testPortModInput() throws Exception {
\r
31 PortModInputBuilder builder = new PortModInputBuilder();
\r
32 BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
\r
33 builder.setPortNo(new PortNumber(6633L));
\r
34 builder.setHwAddress(new MacAddress("08:00:27:00:B0:EB"));
\r
35 builder.setConfigV10(new PortConfigV10(true, false, false, true, false, false, true));
\r
36 builder.setMaskV10(new PortConfigV10(false, true, true, false, false, true, false));
\r
37 builder.setAdvertiseV10(new PortFeaturesV10(true, true, false, false, false, false,
\r
38 false, true, true, false, false, false));
\r
39 PortModInput message = builder.build();
\r
41 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
\r
42 OF10PortModInputMessageFactory factory = OF10PortModInputMessageFactory.getInstance();
\r
43 factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);
\r
45 BufferHelper.checkHeaderV10(out, (byte) 15, 32);
\r
46 Assert.assertEquals("Wrong PortNo", message.getPortNo().getValue().longValue(), out.readUnsignedShort());
\r
47 byte[] address = new byte[6];
\r
48 out.readBytes(address);
\r
49 Assert.assertEquals("Wrong MacAddress", message.getHwAddress(),
\r
50 new MacAddress(ByteBufUtils.macAddressToString(address)));
\r
51 Assert.assertEquals("Wrong config", 21, out.readUnsignedInt());
\r
52 Assert.assertEquals("Wrong mask", 98, out.readUnsignedInt());
\r
53 Assert.assertEquals("Wrong advertise", 652, out.readUnsignedInt());
\r