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.deserialization.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.util.EncodeConstants;
17 import org.opendaylight.openflowjava.util.ByteBufUtils;
18 import org.opendaylight.openflowplugin.impl.protocol.deserialization.AbstractDeserializerTest;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.IetfYangUtil;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortMessage;
23 public class PortMessageDeserializerTest extends AbstractDeserializerTest {
24 private static final byte PADDING_IN_PORT_MOD_MESSAGE_1 = 4;
25 private static final byte PADDING_IN_PORT_MOD_MESSAGE_2 = 2;
26 private static final byte PADDING_IN_PORT_MOD_MESSAGE_3 = 4;
29 private static final Boolean IS_AUTOENG = true;
30 private static final Boolean IS_COPPER = false;
31 private static final Boolean IS_FIBER = true;
32 private static final Boolean IS_40GBFD = true;
33 private static final Boolean IS_100GBFD = false;
34 private static final Boolean IS_100MBFD = false;
35 private static final Boolean IS_100MBHD = true;
36 private static final Boolean IS_1GBFD = false;
37 private static final Boolean IS_1GBHD = false;
38 private static final Boolean IS_1TBFD = true;
39 private static final Boolean IS_OTHER = true;
40 private static final Boolean IS_PAUSE = false;
41 private static final Boolean IS_PAUSE_ASYM = false;
42 private static final Boolean IS_10GBFD = false;
43 private static final Boolean IS_10MBFD = true;
44 private static final Boolean IS_10MBHD = true;
45 private static final Boolean IS_NOPACKETIN = false;
46 private static final Boolean IS_NOFWD = true;
47 private static final Boolean IS_NORECV = true;
48 private static final Boolean IS_PORTDOWN = true;
49 private static final int PORT = 22;
50 private static final int XID = 42;
51 private static final int TYPE = 16;
52 private static final MacAddress ADDRESS = new MacAddress("00:01:02:03:04:05");
54 private ByteBuf buffer;
57 protected void init() {
58 buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
62 public void deserialize() {
63 buffer.writeByte(TYPE);
64 buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
66 buffer.writeInt(PORT);
67 buffer.writeZero(PADDING_IN_PORT_MOD_MESSAGE_1);
68 buffer.writeBytes(IetfYangUtil.macAddressBytes(ADDRESS));
70 final int config = ByteBufUtils.fillBitMaskFromMap(ImmutableMap
71 .<Integer, Boolean>builder()
75 .put(6, IS_NOPACKETIN)
78 buffer.writeZero(PADDING_IN_PORT_MOD_MESSAGE_2);
79 buffer.writeInt(config); // config
80 buffer.writeInt(config); // config mask
82 buffer.writeInt(ByteBufUtils.fillBitMask(0,
100 buffer.writeZero(PADDING_IN_PORT_MOD_MESSAGE_3);
102 final PortMessage message = (PortMessage) getFactory().deserialize(buffer, EncodeConstants.OF_VERSION_1_3);
104 assertEquals(XID, message.getXid().intValue());
105 assertEquals(PORT, message.getPortNumber().getUint32().intValue());
106 assertEquals(ADDRESS.getValue(), message.getHardwareAddress().getValue());
109 assertEquals(IS_PORTDOWN, message.getConfiguration().getPORTDOWN());
110 assertEquals(IS_NORECV, message.getConfiguration().getNORECV());
111 assertEquals(IS_NOFWD, message.getConfiguration().getNOFWD());
112 assertEquals(IS_NOPACKETIN, message.getConfiguration().getNOPACKETIN());
115 assertEquals(IS_10MBHD, message.getAdvertisedFeatures().getTenMbHd());
116 assertEquals(IS_10MBFD, message.getAdvertisedFeatures().getTenMbHd());
117 assertEquals(IS_100MBHD, message.getAdvertisedFeatures().getHundredMbHd());
118 assertEquals(IS_100MBFD, message.getAdvertisedFeatures().getHundredMbFd());
119 assertEquals(IS_1GBHD, message.getAdvertisedFeatures().getOneGbHd());
120 assertEquals(IS_1GBFD, message.getAdvertisedFeatures().getOneGbFd());
121 assertEquals(IS_10GBFD, message.getAdvertisedFeatures().getTenGbFd());
122 assertEquals(IS_40GBFD, message.getAdvertisedFeatures().getFortyGbFd());
123 assertEquals(IS_100GBFD, message.getAdvertisedFeatures().getHundredGbFd());
124 assertEquals(IS_1TBFD, message.getAdvertisedFeatures().getOneTbFd());
125 assertEquals(IS_OTHER, message.getAdvertisedFeatures().getOther());
126 assertEquals(IS_COPPER, message.getAdvertisedFeatures().getCopper());
127 assertEquals(IS_FIBER, message.getAdvertisedFeatures().getFiber());
128 assertEquals(IS_AUTOENG, message.getAdvertisedFeatures().getAutoeng());
129 assertEquals(IS_PAUSE, message.getAdvertisedFeatures().getPause());
130 assertEquals(IS_PAUSE_ASYM, message.getAdvertisedFeatures().getPauseAsym());
132 assertEquals(buffer.readableBytes(), 0);