2 * Copyright (c) 2016 Cisco Systems, Inc. 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
9 package org.opendaylight.openflowjava.nx.codec.action;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
15 import io.netty.buffer.ByteBuf;
16 import io.netty.buffer.ByteBufAllocator;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.opendaylight.openflowjava.nx.api.NiciraConstants;
20 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
23 public class AbstractActionCodecTest {
26 private ByteBuf buffer;
27 private byte[] bytes = new byte[10];
29 private final int msgLength = 10;
30 private final byte subType = 5;
35 buffer = ByteBufAllocator.DEFAULT.buffer();
40 public void serializeHeaderTest() {
41 AbstractActionCodec.serializeHeader(msgLength, subType, buffer);
42 assertEquals(EncodeConstants.EXPERIMENTER_VALUE, buffer.readUnsignedShort());
43 assertEquals(msgLength, buffer.readUnsignedShort());
44 assertEquals(NiciraConstants.NX_VENDOR_ID.intValue(), buffer.readUnsignedInt());
45 assertEquals(subType, buffer.readUnsignedShort());
49 public void deserializeHeaderTest() {
50 buffer.writeBytes(bytes);
51 int readerIndex = buffer.readerIndex();
52 ActionBuilder actionBuilder = AbstractActionCodec.deserializeHeader(buffer);
53 assertNotNull(actionBuilder);
54 assertEquals(NiciraConstants.NX_VENDOR_ID, actionBuilder.getExperimenterId().getValue());
55 assertTrue(buffer.readerIndex() - readerIndex == 10);