Add Action deserializers
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / protocol / deserialization / action / OutputActionDeserializerTest.java
1 /*
2  * Copyright (c) 2016 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.openflowplugin.impl.protocol.deserialization.action;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
13
14 import org.junit.Test;
15 import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants;
16 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
17 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputAction;
21
22 import io.netty.buffer.ByteBuf;
23 import io.netty.buffer.UnpooledByteBufAllocator;
24
25 public class OutputActionDeserializerTest extends AbstractActionDeserializerTest {
26
27     @Test
28     public void testDeserialize() throws Exception {
29         final ByteBuf in = UnpooledByteBufAllocator.DEFAULT.buffer();
30         final int portNum = 10;
31         final short maxLength = 24;
32         writeHeader(in);
33         in.writeInt(portNum);
34         in.writeShort(maxLength);
35         in.writeZero(ActionConstants.OUTPUT_PADDING);
36
37         final Action action = deserializeAction(in);
38         assertTrue(OutputActionCase.class.isInstance(action));
39
40         final OutputAction outputAction = OutputActionCase.class.cast(action).getOutputAction();
41         assertEquals(portNum, InventoryDataServiceUtil.portNumberfromNodeConnectorId(
42                     OpenflowVersion.OF13, outputAction.getOutputNodeConnector().getValue()).intValue());
43         assertEquals(maxLength, outputAction.getMaxLength().shortValue());
44         assertEquals(0, in.readableBytes());
45     }
46
47     @Override
48     protected short getType() {
49         return ActionConstants.OUTPUT_CODE;
50     }
51
52     @Override
53     protected short getLength() {
54         return ActionConstants.GENERAL_ACTION_LENGTH;
55     }
56
57 }