Update MRI projects for Aluminium
[openflowplugin.git] / openflowjava / 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 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
17 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
18 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
19 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
20 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionTypeV10;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.CapabilitiesV10;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortStateV10;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPort;
29
30 /**
31  * Unit tests for OF10FeaturesReplyMessageFactory.
32  *
33  * @author michal.polkorab
34  */
35 public class OF10FeaturesReplyMessageFactoryTest {
36
37     private OFDeserializer<GetFeaturesOutput> featuresFactory;
38
39     /**
40      * Initializes deserializer registry and lookups correct deserializer.
41      */
42     @Before
43     public void startUp() {
44         DeserializerRegistry registry = new DeserializerRegistryImpl();
45         registry.init();
46         featuresFactory = registry.getDeserializer(
47                 new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 6, GetFeaturesOutput.class));
48     }
49
50     /**
51      * Testing {@link OF10FeaturesReplyMessageFactory} for correct translation into POJO.
52      */
53     @Test
54     public void test() {
55         ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 "
56                 + "00 00 00 FF 00 00 0F FF "
57                 + "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 7F 00 00 02 00 "
58                 + "00 00 0F FF 00 00 00 00 00 00 03 0C 00 00 08 88");
59         GetFeaturesOutput builtByFactory = BufferHelper.deserialize(featuresFactory, bb);
60
61         BufferHelper.checkHeaderV10(builtByFactory);
62         Assert.assertEquals("Wrong datapathId", 0x0001020304050607L, builtByFactory.getDatapathId().longValue());
63         Assert.assertEquals("Wrong n-buffers", 0x00010203L, builtByFactory.getBuffers().longValue());
64         Assert.assertEquals("Wrong n-tables", 0x01, builtByFactory.getTables().shortValue());
65         Assert.assertEquals("Wrong capabilities", new CapabilitiesV10(true, true, true, true, true, true, true, true),
66                 builtByFactory.getCapabilitiesV10());
67         Assert.assertEquals("Wrong actions", new ActionTypeV10(true, true, true, true, true, true, true,
68                 true, true, true, true, true, false), builtByFactory.getActionsV10());
69         PhyPort port = builtByFactory.getPhyPort().get(0);
70         Assert.assertEquals("Wrong port - port-no", 16, port.getPortNo().intValue());
71         Assert.assertEquals("Wrong port - hw-addr", new MacAddress("01:01:05:01:04:02"), port.getHwAddr());
72         Assert.assertEquals("Wrong port - name", new String("ALOHA"), port.getName());
73         Assert.assertEquals("Wrong port - config", new PortConfigV10(true, true, true, true, true, true, true),
74                 port.getConfigV10());
75         Assert.assertEquals("Wrong port - state",  new PortStateV10(false, false, false, false, true,
76                 false, true, false),
77                 port.getStateV10());
78         Assert.assertEquals("Wrong port - curr", new PortFeaturesV10(true, true, true, true, true, true, true,
79                 true, true, true, true, true), port.getCurrentFeaturesV10());
80         Assert.assertEquals("Wrong port - advertised", new PortFeaturesV10(false, false, false, false, false, false,
81                 false, false, false, false, false, false), port.getAdvertisedFeaturesV10());
82         Assert.assertEquals("Wrong port - supported", new PortFeaturesV10(true, true, false, false, false, false,
83                 false, true, false, true, false, false), port.getSupportedFeaturesV10());
84         Assert.assertEquals("Wrong port - peer", new PortFeaturesV10(true, false, false, false, false, false, false,
85                 false, true, false, false, true), port.getPeerFeaturesV10());
86     }
87
88     /**
89      * Testing {@link OF10FeaturesReplyMessageFactory} for correct translation into POJO.
90      */
91     @Test
92     public void testWithTwoPortsSet() {
93         ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 "
94                 + "00 00 00 8B 00 00 03 B5 "
95                 + "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 00 00 00 07 01 "
96                 + "00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88 "
97                 + "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 00 00 "
98                 + "00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88");
99         GetFeaturesOutput builtByFactory = BufferHelper.deserialize(featuresFactory, bb);
100
101         BufferHelper.checkHeaderV10(builtByFactory);
102         Assert.assertEquals("Wrong ports size", 2, builtByFactory.getPhyPort().size());
103         PhyPort port = builtByFactory.getPhyPort().get(0);
104         Assert.assertEquals("Wrong port - port-no", 16, port.getPortNo().intValue());
105         Assert.assertEquals("Wrong port - hw-addr", new MacAddress("01:01:05:01:04:02"), port.getHwAddr());
106         Assert.assertEquals("Wrong port - name", new String("ALOHA"), port.getName());
107         Assert.assertEquals("Wrong port - config", new PortConfigV10(false, false, false, false, false, false, false),
108                 port.getConfigV10());
109         Assert.assertEquals("Wrong port - state",  new PortStateV10(false, true, false, true, true, true, false, true),
110                 port.getStateV10());
111         port = builtByFactory.getPhyPort().get(1);
112         Assert.assertEquals("Wrong port - state",
113                 new PortStateV10(false, false, false, false, false, false, true, false), port.getStateV10());
114     }
115
116     /**
117      * Testing {@link OF10FeaturesReplyMessageFactory} for correct translation into POJO.
118      */
119     @Test
120     public void testWithNoPortsSet() {
121         ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 "
122                 + "00 00 00 00 00 00 00 00");
123         GetFeaturesOutput builtByFactory = BufferHelper.deserialize(featuresFactory, bb);
124
125         BufferHelper.checkHeaderV10(builtByFactory);
126         Assert.assertEquals("Wrong capabilities",
127                 new CapabilitiesV10(false, false, false, false, false, false, false, false),
128                 builtByFactory.getCapabilitiesV10());
129         Assert.assertEquals("Wrong actions", new ActionTypeV10(false, false, false, false, false, false, false,
130                 false, false, false, false, false, false), builtByFactory.getActionsV10());
131         Assert.assertEquals("Wrong ports size", 0, builtByFactory.nonnullPhyPort().size());
132     }
133 }