Remove trailing whitespace
[openflowjava.git] / 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
9 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
10
11 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.UnpooledByteBufAllocator;
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
17 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
18 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
19 import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
20 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
21 import org.opendaylight.openflowjava.util.ByteBufUtils;
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.PortConfigV10;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
29
30 /**
31  * @author michal.polkorab
32  *
33  */
34 public class OF10PortModInputMessageFactoryTest {
35
36     private SerializerRegistry registry;
37     private OFSerializer<PortModInput> portModFactory;
38
39     /**
40      * Initializes serializer registry and stores correct factory in field
41      */
42     @Before
43     public void startUp() {
44         registry = new SerializerRegistryImpl();
45         registry.init();
46         portModFactory = registry.getSerializer(
47                 new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, PortModInput.class));
48     }
49
50     /**
51      * Testing of {@link OF10PortModInputMessageFactory} for correct translation from POJO
52      * @throws Exception
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(6633L));
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(),
74                 new MacAddress(ByteBufUtils.macAddressToString(address)));
75         Assert.assertEquals("Wrong config", 21, out.readUnsignedInt());
76         Assert.assertEquals("Wrong mask", 98, out.readUnsignedInt());
77         Assert.assertEquals("Wrong advertise", 652, out.readUnsignedInt());
78         out.skipBytes(4);
79     }
80
81 }