Extend openflow-protocol-impl serialization
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / OF10PacketOutInputMessageFactoryTest.java
1 /*
2  * Copyright (c) 2015 NetIDE Consortium 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 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
9
10 import io.netty.buffer.ByteBuf;
11 import java.util.ArrayList;
12 import java.util.List;
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
17 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
18 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
19 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
20 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
21 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
22 import org.opendaylight.openflowjava.util.ByteBufUtils;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.StripVlanCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputActionBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;
30
31 /**
32  * @author giuseppex.petralia@intel.com
33  *
34  */
35 public class OF10PacketOutInputMessageFactoryTest {
36     private OFDeserializer<PacketOutInput> factory;
37
38     @Before
39     public void startUp() {
40         DeserializerRegistry desRegistry = new DeserializerRegistryImpl();
41         desRegistry.init();
42         factory = desRegistry
43                 .getDeserializer(new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 13, PacketOutInput.class));
44     }
45
46     @Test
47     public void test() {
48         ByteBuf bb = BufferHelper.buildBuffer("00 00 01 00 01 01 00 10 00 00 00 08 "
49                 + "00 2a 00 32 00 03 00 08 00 00 00 00 00 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14");
50
51         PacketOutInput deserializedMessage = BufferHelper.deserialize(factory, bb);
52         BufferHelper.checkHeaderV10(deserializedMessage);
53         Assert.assertEquals("Wrong bufferId ", 256L, deserializedMessage.getBufferId().longValue());
54         Assert.assertEquals("Wrong inPort ", new PortNumber(257L), deserializedMessage.getInPort());
55         Assert.assertEquals("Wrong action ", createActionList().get(0), deserializedMessage.getAction().get(0));
56         Assert.assertEquals("Wrong action ", createActionList().get(1), deserializedMessage.getAction().get(1));
57         Assert.assertArrayEquals("Wrong data ",
58                 ByteBufUtils.hexStringToBytes("00 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14"),
59                 deserializedMessage.getData());
60     }
61
62     private static List<Action> createActionList() {
63         List<Action> actions = new ArrayList<>();
64         ActionBuilder actionBuilder = new ActionBuilder();
65         OutputActionCaseBuilder caseBuilder = new OutputActionCaseBuilder();
66         OutputActionBuilder outputBuilder = new OutputActionBuilder();
67         outputBuilder.setPort(new PortNumber(42L));
68         outputBuilder.setMaxLength(50);
69         caseBuilder.setOutputAction(outputBuilder.build());
70         actionBuilder.setActionChoice(caseBuilder.build());
71         actions.add(actionBuilder.build());
72         actionBuilder = new ActionBuilder();
73         actionBuilder.setActionChoice(new StripVlanCaseBuilder().build());
74         actions.add(actionBuilder.build());
75         return actions;
76     }
77 }