Bump upstreams
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / OF10PortModInputMessageFactoryTest.java
1 /*
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. 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.serialization.factories;
9
10 import io.netty.buffer.ByteBuf;
11 import io.netty.buffer.UnpooledByteBufAllocator;
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
17 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
18 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
19 import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
20 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.IetfYangUtil;
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.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.PortNumber;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
28 import org.opendaylight.yangtools.yang.common.Uint32;
29
30 /**
31  * Unit tests for OF10PortModInputMessageFactory.
32  *
33  * @author michal.polkorab
34  */
35 public class OF10PortModInputMessageFactoryTest {
36
37     private SerializerRegistry registry;
38     private OFSerializer<PortModInput> portModFactory;
39
40     /**
41      * Initializes serializer registry and stores correct factory in field.
42      */
43     @Before
44     public void startUp() {
45         registry = new SerializerRegistryImpl();
46         registry.init();
47         portModFactory = registry.getSerializer(
48                 new MessageTypeKey<>(EncodeConstants.OF_VERSION_1_0, PortModInput.class));
49     }
50
51     /**
52      * Testing of {@link OF10PortModInputMessageFactory} for correct translation from POJO.
53      */
54     @Test
55     public void testPortModInput() throws Exception {
56         PortModInputBuilder builder = new PortModInputBuilder();
57         BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
58         builder.setPortNo(new PortNumber(Uint32.valueOf(6633)));
59         builder.setHwAddress(new MacAddress("08:00:27:00:b0:eb"));
60         builder.setConfigV10(new PortConfigV10(true, false, false, true, false, false, true));
61         builder.setMaskV10(new PortConfigV10(false, true, true, false, false, true, false));
62         builder.setAdvertiseV10(new PortFeaturesV10(true, true, false, false, false, false,
63                 false, true, true, false, false, false));
64         PortModInput message = builder.build();
65
66         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
67         portModFactory.serialize(message, out);
68
69         BufferHelper.checkHeaderV10(out, (byte) 15, 32);
70         Assert.assertEquals("Wrong PortNo", message.getPortNo().getValue().longValue(), out.readUnsignedShort());
71         byte[] address = new byte[6];
72         out.readBytes(address);
73         Assert.assertEquals("Wrong MacAddress", message.getHwAddress(), IetfYangUtil.macAddressFor(address));
74         Assert.assertEquals("Wrong config", 21, out.readUnsignedInt());
75         Assert.assertEquals("Wrong mask", 98, out.readUnsignedInt());
76         Assert.assertEquals("Wrong advertise", 652, out.readUnsignedInt());
77         out.skipBytes(4);
78     }
79 }