2 * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
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
9 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories.multipart;
11 import io.netty.buffer.ByteBuf;
12 import org.junit.Assert;
13 import org.junit.Test;
14 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.MultipartReplyMessageFactory;
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.rev130715.MacAddress;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortDescCase;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.MultipartReplyPortDesc;
23 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;
26 * Unit tests for MultipartReplyPortDesc.
28 * @author michal.polkorab
30 public class MultipartReplyPortDescTest {
32 private final MultipartReplyMessageFactory factory = new MultipartReplyMessageFactory();
35 * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO.
38 public void testEmptyMultipartReplyPortDesc() {
39 ByteBuf bb = BufferHelper.buildBuffer("00 0D 00 00 00 00 00 00");
40 MultipartReplyMessage builtByFactory = BufferHelper.deserialize(factory, bb);
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.nonnullPorts().size());
51 * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO.
54 public void testMultipartReplyPortDesc() {
55 ByteBuf bb = BufferHelper.buildBuffer("00 0D 00 00 00 00 00 00 " + //
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
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
81 MultipartReplyMessage builtByFactory = BufferHelper.deserialize(factory, bb);
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",
114 new PortFeatures(false, false, false, false, false, false, false,
115 false, false, false, false, false, false, false, false, false), port.getAdvertisedFeatures());
116 Assert.assertEquals("Wrong supportedFeatures", new PortFeatures(false, false, false, false, false, false, false,
117 false, false, false, false, false, false, false, false, false), port.getSupportedFeatures());
118 Assert.assertEquals("Wrong peerFeatures", new PortFeatures(false, false, false, false, false, false, false,
119 false, false, false, false, false, false, false, false, false), port.getPeerFeatures());
120 Assert.assertEquals("Wrong currSpeed", 5L, port.getCurrSpeed().longValue());
121 Assert.assertEquals("Wrong maxSpeed", 6L, port.getMaxSpeed().longValue());