2 * Copyright (c) 2016 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
8 package org.opendaylight.openflowplugin.impl.protocol.serialization.messages;
10 import static org.junit.Assert.assertEquals;
12 import com.google.common.collect.ImmutableMap;
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.UnpooledByteBufAllocator;
15 import org.junit.Test;
16 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
17 import org.opendaylight.openflowjava.protocol.api.util.BinContent;
18 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
19 import org.opendaylight.openflowjava.util.ByteBufUtils;
20 import org.opendaylight.openflowplugin.impl.protocol.serialization.AbstractSerializerTest;
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.flow.types.port.rev130925.PortConfig;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortMessage;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortMessageBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortNumberUni;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumberValues;
30 import org.opendaylight.yangtools.yang.common.Uint32;
31 import org.opendaylight.yangtools.yang.common.Uint8;
33 public class PortMessageSerializerTest extends AbstractSerializerTest {
35 private static final byte PADDING_IN_PORT_MOD_MESSAGE_01 = 4;
36 private static final byte PADDING_IN_PORT_MOD_MESSAGE_02 = 2;
37 private static final byte PADDING_IN_PORT_MOD_MESSAGE_03 = 4;
38 private static final short LENGTH = 40;
39 private static final Uint32 XID = Uint32.valueOf(42);
40 private static final Uint8 VERSION = EncodeConstants.OF_VERSION_1_3;
41 private static final String PORT_NUMBER = OutputPortValues.ALL.toString();
42 private static final Long PORT_NUMBER_VAL = BinContent.intToUnsignedLong(PortNumberValues.ALL.getIntValue());
43 private static final String MAC_ADDRESS = "e9:2a:55:ba:fa:4d";
46 private static final Boolean IS_NOFWD = false;
47 private static final Boolean IS_NOPACKETIN = false;
48 private static final Boolean IS_NORECV = true;
49 private static final Boolean IS_PORTDOWN = false;
52 private static final Boolean IS_AUTOENG = true;
53 private static final Boolean IS_COPPER = false;
54 private static final Boolean IS_FIBER = true;
55 private static final Boolean IS_40GBFD = true;
56 private static final Boolean IS_100GBFD = false;
57 private static final Boolean IS_100MBFD = false;
58 private static final Boolean IS_100MBHD = false;
59 private static final Boolean IS_1GBFD = false;
60 private static final Boolean IS_1GBHD = false;
61 private static final Boolean IS_1TBFD = false;
62 private static final Boolean IS_OTHER = false;
63 private static final Boolean IS_PAUSE = false;
64 private static final Boolean IS_PAUSE_ASYM = false;
65 private static final Boolean IS_10GBFD = false;
66 private static final Boolean IS_10MBFD = false;
67 private static final Boolean IS_10MBHD = false;
69 private static final PortMessage MESSAGE = new PortMessageBuilder()
72 .setPortNumber(new PortNumberUni(PORT_NUMBER))
73 .setConfiguration(new PortConfig(IS_NOFWD, IS_NOPACKETIN, IS_NORECV, IS_PORTDOWN))
74 .setMask(new PortConfig(true, true, true, true))
75 .setAdvertisedFeatures(new PortFeatures(
92 .setHardwareAddress(new MacAddress(MAC_ADDRESS))
95 private PortMessageSerializer serializer;
98 protected void init() {
99 serializer = getRegistry()
100 .getSerializer(new MessageTypeKey<>(EncodeConstants.OF_VERSION_1_3, PortMessage.class));
104 public void testSerialize() {
105 final ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
106 serializer.serialize(MESSAGE, out);
109 assertEquals(out.readByte(), VERSION.byteValue());
110 assertEquals(out.readByte(), serializer.getMessageType());
111 assertEquals(out.readShort(), LENGTH);
112 assertEquals(out.readInt(), XID.intValue());
115 assertEquals(out.readInt(), PORT_NUMBER_VAL.intValue());
116 out.skipBytes(PADDING_IN_PORT_MOD_MESSAGE_01);
117 byte[] address = new byte[6];
118 out.readBytes(address);
119 assertEquals(new MacAddress(MAC_ADDRESS), IetfYangUtil.macAddressFor(address));
120 out.skipBytes(PADDING_IN_PORT_MOD_MESSAGE_02);
123 final int config = ByteBufUtils.fillBitMaskFromMap(ImmutableMap
124 .<Integer, Boolean>builder()
128 .put(6, IS_NOPACKETIN)
131 final int mask = ByteBufUtils.fillBitMaskFromMap(ImmutableMap
132 .<Integer, Boolean>builder()
139 assertEquals(out.readInt(), config);
140 assertEquals(out.readInt(), mask);
143 assertEquals(out.readInt(), ByteBufUtils.fillBitMask(0,
161 out.skipBytes(PADDING_IN_PORT_MOD_MESSAGE_03);
163 assertEquals(out.readableBytes(), 0);