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.MessageCodeKey;
18 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
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.rev100924.MacAddress;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortStateV10;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;
30 * @author michal.polkorab
33 public class OF10PortStatusMessageFactoryTest {
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.OF10_VERSION_ID, 12, PortStatusMessage.class));
49 * Testing {@link OF10PortStatusMessageFactory} for correct translation into POJO
53 ByteBuf bb = BufferHelper.buildBuffer("00 00 00 00 00 00 00 00 "
54 + "00 10 01 01 05 01 04 02 41 4C 4F 48 41 00 00 00 00 00 00 00 00 00 00 "
55 + "00 00 00 00 15 00 00 01 01 00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88");
56 PortStatusMessage builtByFactory = BufferHelper.deserialize(statusFactory, bb);
58 BufferHelper.checkHeaderV10(builtByFactory);
59 Assert.assertEquals("Wrong reason", PortReason.OFPPRADD, builtByFactory.getReason());
60 Assert.assertEquals("Wrong port - port-no", 16, builtByFactory.getPortNo().intValue());
61 Assert.assertEquals("Wrong builtByFactory - hw-addr", new MacAddress("01:01:05:01:04:02"), builtByFactory.getHwAddr());
62 Assert.assertEquals("Wrong builtByFactory - name", new String("ALOHA"), builtByFactory.getName());
63 Assert.assertEquals("Wrong builtByFactory - config", new PortConfigV10(true, false, false, true, false, false, true),
64 builtByFactory.getConfigV10());
65 Assert.assertEquals("Wrong builtByFactory - state", new PortStateV10(false, true, false, false, false, true, false, false),
66 builtByFactory.getStateV10());
67 Assert.assertEquals("Wrong builtByFactory - curr", new PortFeaturesV10(false, false, false, false, true, true, true,
68 false, false, false, false, false), builtByFactory.getCurrentFeaturesV10());
69 Assert.assertEquals("Wrong builtByFactory - advertised", new PortFeaturesV10(false, false, true, true, false, false,
70 false, false, false, false, true, false), builtByFactory.getAdvertisedFeaturesV10());
71 Assert.assertEquals("Wrong builtByFactory - supbuiltByFactoryed", new PortFeaturesV10(true, true, false, false, false, false,
72 false, true, false, true, false, false), builtByFactory.getSupportedFeaturesV10());
73 Assert.assertEquals("Wrong builtByFactory - peer", new PortFeaturesV10(true, false, false, false, false, false, false,
74 false, true, false, false, true), builtByFactory.getPeerFeaturesV10());