2 * Copyright (c) 2013 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
10 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
12 import io.netty.buffer.ByteBuf;
14 import org.junit.Assert;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
18 import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey;
19 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
20 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
21 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
22 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;
30 * @author timotej.kubas
31 * @author michal.polkorab
33 public class PortStatusMessageFactoryTest {
35 private OFDeserializer<PortStatusMessage> statusFactory;
38 * Initializes deserializer registry and lookups correct deserializer
41 public void startUp() {
42 DeserializerRegistry registry = new DeserializerRegistryImpl();
44 statusFactory = registry.getDeserializer(
45 new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 12, PortStatusMessage.class));
49 * Testing {@link PortStatusMessageFactory} for correct translation into POJO
53 ByteBuf bb = BufferHelper.buildBuffer("01 " + //reason
54 "00 00 00 00 00 00 00 " + //padding
55 "00 01 02 03 " + //port no
56 "00 00 00 00 " + //padding in ofp_port1
57 "08 00 27 00 B0 EB " + //mac address
58 "00 00 " + //padding in ofp_port2
59 "73 31 2d 65 74 68 31 00 00 00 00 00 00 00 00 00 " + // port name, String "s1-eth1"
60 "00 00 00 41 " + //port config
61 "00 00 00 05 " + //port state
62 "00 00 00 81 " + //current features
63 "00 00 00 A1 " + //advertised features
64 "00 00 00 B1 " + //supported features
65 "00 00 00 81 " + //peer features
66 "00 00 00 81 " + //curr speed
67 "00 00 00 80" //max speed
70 PortStatusMessage builtByFactory = BufferHelper.deserialize(statusFactory, bb);
72 BufferHelper.checkHeaderV13(builtByFactory);
73 Assert.assertEquals("Wrong reason", 0x01, builtByFactory.getReason().getIntValue());
74 Assert.assertEquals("Wrong portNumber", 66051L, builtByFactory.getPortNo().longValue());
75 Assert.assertEquals("Wrong macAddress", new MacAddress("08:00:27:00:B0:EB"), builtByFactory.getHwAddr());
76 Assert.assertEquals("Wrong name", "s1-eth1", builtByFactory.getName());
77 Assert.assertEquals("Wrong portConfig", new PortConfig(false, true, false, true), builtByFactory.getConfig());
78 Assert.assertEquals("Wrong portState", new PortState(false, true, true), builtByFactory.getState());
79 Assert.assertEquals("Wrong currentFeatures", new PortFeatures(false, false, false, false,
80 false, true, false, false, false, true, false, false,
81 false, false, false, false), builtByFactory.getCurrentFeatures());
82 Assert.assertEquals("Wrong advertisedFeatures", new PortFeatures(false, false, false, false,
83 false, true, true, false, false, true, false, false,
84 false, false, false, false), builtByFactory.getAdvertisedFeatures());
85 Assert.assertEquals("Wrong supportedFeatures", new PortFeatures(false, false, false, false,
86 false, true, true, true, false, true, false, false,
87 false, false, false, false), builtByFactory.getSupportedFeatures());
88 Assert.assertEquals("Wrong peerFeatures", new PortFeatures(false, false, false, false,
89 false, true, false, false, false, true, false, false,
90 false, false, false, false), builtByFactory.getPeerFeatures());
91 Assert.assertEquals("Wrong currSpeed", 129L, builtByFactory.getCurrSpeed().longValue());
92 Assert.assertEquals("Wrong maxSpeed", 128L, builtByFactory.getMaxSpeed().longValue());
96 * Testing {@link PortStatusMessageFactory} for correct translation into POJO
99 public void testWithDifferentBitmaps(){
100 ByteBuf bb = BufferHelper.buildBuffer("01 00 00 00 00 00 00 00 " + //reason, padding
101 "00 01 02 03 00 00 00 00 " + //port no, padding
102 "08 00 27 00 B0 EB 00 00 " + //mac address, padding
103 "73 31 2d 65 74 68 31 00 00 00 00 00 00 00 00 00 " + // port name, String "s1-eth1"
104 "00 00 00 24 " + //port config
105 "00 00 00 02 " + //port state
106 "00 00 00 81 00 00 00 A1 " + //current + advertised features
107 "00 00 FF FF 00 00 00 00 " + //supported + peer features
108 "00 00 00 81 00 00 00 80" //curr speed, max speed
110 PortStatusMessage message = BufferHelper.deserialize(statusFactory, bb);
112 Assert.assertEquals("Wrong portConfig", new PortConfig(true, false, true, false), message.getConfig());
113 Assert.assertEquals("Wrong portState", new PortState(true, false, false), message.getState());
114 Assert.assertEquals("Wrong supportedFeatures", new PortFeatures(true, true, true, true,
115 true, true, true, true, true, true, true, true, true, true, true, true),
116 message.getSupportedFeatures());
117 Assert.assertEquals("Wrong peerFeatures", new PortFeatures(false, false, false, false,
118 false, false, false, false, false, false, false, false, false, false,
119 false, false), message.getPeerFeatures());