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