139ea08af1506ebb07736720f05b2b9c0894efe5
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / multipart / MultipartReplyPortDescTest.java
1 /*\r
2  * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 \r
9 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories.multipart;\r
10 \r
11 import io.netty.buffer.ByteBuf;\r
12 \r
13 import org.junit.Assert;\r
14 import org.junit.Test;\r
15 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.MultipartReplyMessageFactory;\r
16 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;\r
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig;\r
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;\r
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState;\r
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;\r
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortDescCase;\r
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.MultipartReplyPortDesc;\r
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.multipart.reply.port.desc.Ports;\r
25 \r
26 /**\r
27  * @author michal.polkorab\r
28  *\r
29  */\r
30 public class MultipartReplyPortDescTest {\r
31 \r
32     private MultipartReplyMessageFactory factory = new MultipartReplyMessageFactory();\r
33 \r
34     /**\r
35      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO\r
36      */\r
37     @Test\r
38     public void testEmptyMultipartReplyPortDesc() {\r
39         ByteBuf bb = BufferHelper.buildBuffer("00 0D 00 00 00 00 00 00");\r
40         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(factory, bb);\r
41 \r
42         BufferHelper.checkHeaderV13(builtByFactory);\r
43         Assert.assertEquals("Wrong type", 13, builtByFactory.getType().getIntValue());\r
44         Assert.assertEquals("Wrong flag", false, builtByFactory.getFlags().isOFPMPFREQMORE());\r
45         MultipartReplyPortDescCase messageCase = (MultipartReplyPortDescCase) builtByFactory.getMultipartReplyBody();\r
46         MultipartReplyPortDesc message = messageCase.getMultipartReplyPortDesc();\r
47         Assert.assertEquals("Wrong table features size", 0, message.getPorts().size());\r
48     }\r
49 \r
50     /**\r
51      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO\r
52      */\r
53     @Test\r
54     public void testMultipartReplyPortDesc() {\r
55         ByteBuf bb = BufferHelper.buildBuffer("00 0D 00 00 00 00 00 00 " +\r
56                                               // first port desc\r
57                                               "00 01 02 03 00 00 00 00 " + // portNo, padding\r
58                                               "08 00 27 00 B0 EB 00 00 " + // mac address, padding\r
59                                               "4F 70 65 6E 64 61 79 6C 69 67 68 74 00 00 00 00 " + // name\r
60                                               "00 00 00 65 " + //port config\r
61                                               "00 00 00 07 " + //port state\r
62                                               "00 00 00 81 " + //current features\r
63                                               "00 00 FF FF " + //advertised features\r
64                                               "00 00 C1 89 " + //supported features\r
65                                               "00 00 C5 8D " + //peer features\r
66                                               "00 00 00 81 " + //curr speed\r
67                                               "00 00 00 80 " + //max speed\r
68                                               // second port desc\r
69                                               "00 00 00 01 00 00 00 00 " + // portNo, padding\r
70                                               "08 00 27 00 B0 EB 00 00 " + // mac address, padding\r
71                                               "4F 70 65 6E 64 61 79 6C 69 67 68 74 00 00 00 00 " + // name\r
72                                               "00 00 00 00 " + //port config\r
73                                               "00 00 00 00 " + //port state\r
74                                               "00 00 00 00 " + //current features\r
75                                               "00 00 00 00 " + //advertised features\r
76                                               "00 00 00 00 " + //supported features\r
77                                               "00 00 00 00 " + //peer features\r
78                                               "00 00 00 05 " + //curr speed\r
79                                               "00 00 00 06" //max speed\r
80                                               );\r
81         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(factory, bb);\r
82 \r
83         BufferHelper.checkHeaderV13(builtByFactory);\r
84         Assert.assertEquals("Wrong type", 13, builtByFactory.getType().getIntValue());\r
85         Assert.assertEquals("Wrong flag", false, builtByFactory.getFlags().isOFPMPFREQMORE());\r
86         MultipartReplyPortDescCase messageCase = (MultipartReplyPortDescCase) builtByFactory.getMultipartReplyBody();\r
87         MultipartReplyPortDesc message = messageCase.getMultipartReplyPortDesc();\r
88         Assert.assertEquals("Wrong port desc size", 2, message.getPorts().size());\r
89         Ports port = message.getPorts().get(0);\r
90         Assert.assertEquals("Wrong portNo", 66051L, port.getPortNo().longValue());\r
91         Assert.assertEquals("Wrong macAddress", new MacAddress("08:00:27:00:B0:EB"), port.getHwAddr());\r
92         Assert.assertEquals("Wrong portName", "Opendaylight", port.getName());\r
93         Assert.assertEquals("Wrong portConfig", new PortConfig(true, true, true, true), port.getConfig());\r
94         Assert.assertEquals("Wrong portState", new PortState(true, true, true), port.getState());\r
95         Assert.assertEquals("Wrong currentFeatures", new PortFeatures(false, false, false, false, false, true,\r
96                 false, false, false, true, false, false, false, false, false, false), port.getCurrentFeatures());\r
97         Assert.assertEquals("Wrong advertisedFeatures",  new PortFeatures(true, true, true, true, true, true,\r
98                 true, true, true, true, true, true, true, true, true, true), port.getAdvertisedFeatures());\r
99         Assert.assertEquals("Wrong supportedFeatures", new PortFeatures(true, true, false, false, false, true,\r
100                 false, false, false, true, false, false, false, false, true, true), port.getSupportedFeatures());\r
101         Assert.assertEquals("Wrong peerFeatures", new PortFeatures(true, true, true, false, false, true, false,\r
102                 false, false, true, false, false, false, true, true, true), port.getPeerFeatures());\r
103         Assert.assertEquals("Wrong currSpeed", 129L, port.getCurrSpeed().longValue());\r
104         Assert.assertEquals("Wrong maxSpeed", 128L, port.getMaxSpeed().longValue());\r
105         port = message.getPorts().get(1);\r
106         Assert.assertEquals("Wrong portNo", 1L, port.getPortNo().longValue());\r
107         Assert.assertEquals("Wrong macAddress", new MacAddress("08:00:27:00:B0:EB"), port.getHwAddr());\r
108         Assert.assertEquals("Wrong portName", "Opendaylight", port.getName());\r
109         Assert.assertEquals("Wrong portConfig", new PortConfig(false, false, false, false), port.getConfig());\r
110         Assert.assertEquals("Wrong portState", new PortState(false, false, false), port.getState());\r
111         Assert.assertEquals("Wrong currentFeatures", new PortFeatures(false, false, false, false, false, false, false,\r
112                 false, false, false, false, false, false, false, false, false), port.getCurrentFeatures());\r
113         Assert.assertEquals("Wrong advertisedFeatures",  new PortFeatures(false, false, false, false, false, false, false,\r
114                 false, false, false, false, false, false, false, false, false), port.getAdvertisedFeatures());\r
115         Assert.assertEquals("Wrong supportedFeatures", new PortFeatures(false, false, false, false, false, false, false,\r
116                 false, false, false, false, false, false, false, false, false), port.getSupportedFeatures());\r
117         Assert.assertEquals("Wrong peerFeatures", new PortFeatures(false, false, false, false, false, false, false,\r
118                 false, false, false, false, false, false, false, false, false), port.getPeerFeatures());\r
119         Assert.assertEquals("Wrong currSpeed", 5L, port.getCurrSpeed().longValue());\r
120         Assert.assertEquals("Wrong maxSpeed", 6L, port.getMaxSpeed().longValue());\r
121     }\r
122 }