Extend openflow-protocol-impl serialization
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / PortModInputMessageFactoryTest.java
1 /*
2  * Copyright (c) 2015 NetIDE Consortium 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 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
9
10 import io.netty.buffer.ByteBuf;
11 import org.junit.Assert;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
16 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
17 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
18 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
19 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
25
26 /**
27  * @author giuseppex.petralia@intel.com
28  *
29  */
30 public class PortModInputMessageFactoryTest {
31     private OFDeserializer<PortModInput> factory;
32
33     @Before
34     public void startUp() throws Exception {
35         DeserializerRegistry desRegistry = new DeserializerRegistryImpl();
36         desRegistry.init();
37         factory = desRegistry
38                 .getDeserializer(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 16, PortModInput.class));
39     }
40
41     @Test
42     public void test() throws Exception {
43         ByteBuf bb = BufferHelper.buildBuffer(
44                 "00 00 00 09 00 00 00 00 08 00 27 00 " + "b0 eb 00 00 00 00 00 24 00 00 00 41 00 00 01 10 00 00 00 00");
45         PortModInput deserializedMessage = BufferHelper.deserialize(factory, bb);
46         BufferHelper.checkHeaderV13(deserializedMessage);
47
48         // Test Message
49         Assert.assertEquals("Wrong port", new PortNumber(9L), deserializedMessage.getPortNo());
50         Assert.assertEquals("Wrong hwAddr", new MacAddress("08:00:27:00:B0:EB"), deserializedMessage.getHwAddress());
51         Assert.assertEquals("Wrong config", new PortConfig(true, false, true, false), deserializedMessage.getConfig());
52         Assert.assertEquals("Wrong mask", new PortConfig(false, true, false, true), deserializedMessage.getMask());
53         Assert.assertEquals("Wrong advertise", new PortFeatures(true, false, false, false, false, false, false, true,
54                 false, false, false, false, false, false, false, false), deserializedMessage.getAdvertise());
55
56     }
57
58 }