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