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
9 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
11 import io.netty.buffer.ByteBuf;
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
17 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
18 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
19 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
20 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
21 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionTypeV10;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.CapabilitiesV10;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortStateV10;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPort;
32 * @author michal.polkorab
35 public class OF10FeaturesReplyMessageFactoryTest {
37 private OFDeserializer<GetFeaturesOutput> featuresFactory;
40 * Initializes deserializer registry and lookups correct deserializer
43 public void startUp() {
44 DeserializerRegistry registry = new DeserializerRegistryImpl();
46 featuresFactory = registry.getDeserializer(
47 new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 6, GetFeaturesOutput.class));
51 * Testing {@link OF10FeaturesReplyMessageFactory} for correct translation into POJO
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);
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),
75 Assert.assertEquals("Wrong port - state", new PortStateV10(false, false, false, false, true, false, true, false),
77 Assert.assertEquals("Wrong port - curr", new PortFeaturesV10(true, true, true, true, true, true, true,
78 true, true, true, true, true), port.getCurrentFeaturesV10());
79 Assert.assertEquals("Wrong port - advertised", new PortFeaturesV10(false, false, false, false, false, false,
80 false, false, false, false, false, false), port.getAdvertisedFeaturesV10());
81 Assert.assertEquals("Wrong port - supported", new PortFeaturesV10(true, true, false, false, false, false,
82 false, true, false, true, false, false), port.getSupportedFeaturesV10());
83 Assert.assertEquals("Wrong port - peer", new PortFeaturesV10(true, false, false, false, false, false, false,
84 false, true, false, false, true), port.getPeerFeaturesV10());
88 * Testing {@link OF10FeaturesReplyMessageFactory} for correct translation into POJO
91 public void testWithTwoPortsSet() {
92 ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 "
93 + "00 00 00 8B 00 00 03 B5 "
94 + "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 "
95 + "00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88 "
96 + "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 "
97 + "00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88");
98 GetFeaturesOutput builtByFactory = BufferHelper.deserialize(featuresFactory, bb);
100 BufferHelper.checkHeaderV10(builtByFactory);
101 Assert.assertEquals("Wrong ports size", 2, builtByFactory.getPhyPort().size());
102 PhyPort port = builtByFactory.getPhyPort().get(0);
103 Assert.assertEquals("Wrong port - port-no", 16, port.getPortNo().intValue());
104 Assert.assertEquals("Wrong port - hw-addr", new MacAddress("01:01:05:01:04:02"), port.getHwAddr());
105 Assert.assertEquals("Wrong port - name", new String("ALOHA"), port.getName());
106 Assert.assertEquals("Wrong port - config", new PortConfigV10(false, false, false, false, false, false, false),
107 port.getConfigV10());
108 Assert.assertEquals("Wrong port - state", new PortStateV10(false, true, false, true, true, true, false, true),
110 port = builtByFactory.getPhyPort().get(1);
111 Assert.assertEquals("Wrong port - state", new PortStateV10(false, false, false, false, false, false, true, false),
116 * Testing {@link OF10FeaturesReplyMessageFactory} for correct translation into POJO
119 public void testWithNoPortsSet() {
120 ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 "
121 + "00 00 00 00 00 00 00 00");
122 GetFeaturesOutput builtByFactory = BufferHelper.deserialize(featuresFactory, bb);
124 BufferHelper.checkHeaderV10(builtByFactory);
125 Assert.assertEquals("Wrong capabilities", new CapabilitiesV10(false, false, false, false, false, false, false, false),
126 builtByFactory.getCapabilitiesV10());
127 Assert.assertEquals("Wrong actions", new ActionTypeV10(false, false, false, false, false, false, false,
128 false, false, false, false, false, false), builtByFactory.getActionsV10());
129 Assert.assertEquals("Wrong ports size", 0, builtByFactory.getPhyPort().size());