1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
\r
2 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
\r
4 import io.netty.buffer.ByteBuf;
\r
6 import org.junit.Assert;
\r
7 import org.junit.Test;
\r
8 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
\r
9 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
\r
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionTypeV10;
\r
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.CapabilitiesV10;
\r
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10;
\r
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;
\r
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortStateV10;
\r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
\r
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPort;
\r
19 * @author michal.polkorab
\r
22 public class OF10FeaturesReplyMessageFactoryTest {
\r
25 * Testing {@link OF10FeaturesReplyMessageFactory} for correct translation into POJO
\r
28 public void test() {
\r
29 ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 "
\r
30 + "00 00 00 8B 00 00 03 B5 "
\r
31 + "00 10 01 01 05 01 04 02 41 4C 4F 48 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 00 00 01 01 "
\r
32 + "00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88");
\r
33 GetFeaturesOutput builtByFactory = BufferHelper.decodeV10(
\r
34 OF10FeaturesReplyMessageFactory.getInstance(), bb);
\r
36 BufferHelper.checkHeaderV10(builtByFactory);
\r
37 Assert.assertEquals("Wrong datapathId", 0x0001020304050607L, builtByFactory.getDatapathId().longValue());
\r
38 Assert.assertEquals("Wrong n-buffers", 0x00010203L, builtByFactory.getBuffers().longValue());
\r
39 Assert.assertEquals("Wrong n-tables", 0x01, builtByFactory.getTables().shortValue());
\r
40 Assert.assertEquals("Wrong capabilities", new CapabilitiesV10(true, true, false, false, false, false, true, true),
\r
41 builtByFactory.getCapabilitiesV10());
\r
42 Assert.assertEquals("Wrong actions", new ActionTypeV10(false, true, true, true, true, false, true,
\r
43 false, true, true, false, false, false), builtByFactory.getActionsV10());
\r
44 PhyPort port = builtByFactory.getPhyPort().get(0);
\r
45 Assert.assertEquals("Wrong port - port-no", 16, port.getPortNo().intValue());
\r
46 Assert.assertEquals("Wrong port - hw-addr", new MacAddress("01:01:05:01:04:02"), port.getHwAddr());
\r
47 Assert.assertEquals("Wrong port - name", new String("ALOHA"), port.getName());
\r
48 Assert.assertEquals("Wrong port - config", new PortConfigV10(true, false, false, true, false, false, true),
\r
49 port.getConfigV10());
\r
50 Assert.assertEquals("Wrong port - state", new PortStateV10(false, true, false, false, false, true, false, false),
\r
51 port.getStateV10());
\r
52 Assert.assertEquals("Wrong port - curr", new PortFeaturesV10(false, false, false, false, true, true, true,
\r
53 false, false, false, false, false), port.getCurrentFeaturesV10());
\r
54 Assert.assertEquals("Wrong port - advertised", new PortFeaturesV10(false, false, true, true, false, false,
\r
55 false, false, false, false, true, false), port.getAdvertisedFeaturesV10());
\r
56 Assert.assertEquals("Wrong port - supported", new PortFeaturesV10(true, true, false, false, false, false,
\r
57 false, true, false, true, false, false), port.getSupportedFeaturesV10());
\r
58 Assert.assertEquals("Wrong port - peer", new PortFeaturesV10(true, false, false, false, false, false, false,
\r
59 false, true, false, false, true), port.getPeerFeaturesV10());
\r
63 * Testing {@link OF10FeaturesReplyMessageFactory} for correct translation into POJO
\r
66 public void testWithNoPortsSet() {
\r
67 ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 "
\r
68 + "00 00 00 8B 00 00 03 B5 "
\r
69 + "00 10 01 01 05 01 04 02 41 4C 4F 48 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 00 00 01 01 "
\r
70 + "00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88 "
\r
71 + "00 10 01 01 05 01 04 02 41 4C 4F 48 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 00 00 01 01 "
\r
72 + "00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88 ");
\r
73 GetFeaturesOutput builtByFactory = BufferHelper.decodeV10(
\r
74 OF10FeaturesReplyMessageFactory.getInstance(), bb);
\r
76 BufferHelper.checkHeaderV10(builtByFactory);
\r
77 Assert.assertEquals("Wrong ports size", 2, builtByFactory.getPhyPort().size());
\r
81 * Testing {@link OF10FeaturesReplyMessageFactory} for correct translation into POJO
\r
84 public void testWithTwoPortsSet() {
\r
85 ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 "
\r
86 + "00 00 00 8B 00 00 03 B5");
\r
87 GetFeaturesOutput builtByFactory = BufferHelper.decodeV10(
\r
88 OF10FeaturesReplyMessageFactory.getInstance(), bb);
\r
90 BufferHelper.checkHeaderV10(builtByFactory);
\r
91 Assert.assertEquals("Wrong ports size", 0, builtByFactory.getPhyPort().size());
\r