2 * Copyright (c) 2015 NetIDE Consortium 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.openflowjava.protocol.impl.deserialization.factories;
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.PopVlanCaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushVlanCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.push.vlan._case.PushVlanActionBuilder;
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.EtherType;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;
33 * @author giuseppex.petralia@intel.com
36 public class PacketOutInputMessageFactoryTest {
37 private OFDeserializer<PacketOutInput> factory;
40 public void startUp() {
41 DeserializerRegistry registry = new DeserializerRegistryImpl();
44 .getDeserializer(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 13, PacketOutInput.class));
50 ByteBuf bb = BufferHelper.buildBuffer(
51 "00 00 01 00 00 00 01 00 00 28 00 00 00 00 00 00 00 11 00 08 00 19 00 00 00 12 00 08 00 00 00 00 00 12 "
52 + "00 08 00 00 00 00 00 12 00 08 00 00 00 00 00 12 00 08 00 00 00 00 00 00 01 02 03 04 05 06 07 08 09 10 "
54 PacketOutInput deserializedMessage = BufferHelper.deserialize(factory, bb);
55 BufferHelper.checkHeaderV13(deserializedMessage);
57 Assert.assertEquals("Wrong buffer Id", 256L, deserializedMessage.getBufferId().longValue());
58 Assert.assertEquals("Wrong In Port", new PortNumber(256L), deserializedMessage.getInPort());
59 Assert.assertEquals("Wrong Numbers of actions", createAction(), deserializedMessage.getAction());
60 byte[] data = ByteBufUtils.hexStringToBytes("00 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14");
61 Assert.assertArrayEquals("Wrong data", data, deserializedMessage.getData());
64 private List<Action> createAction() {
65 List<Action> actions = new ArrayList<>();
66 ActionBuilder actionBuilder = new ActionBuilder();
67 PushVlanCaseBuilder pushVlanCaseBuilder = new PushVlanCaseBuilder();
68 PushVlanActionBuilder pushVlanBuilder = new PushVlanActionBuilder();
69 pushVlanBuilder.setEthertype(new EtherType(new EtherType(25)));
70 pushVlanCaseBuilder.setPushVlanAction(pushVlanBuilder.build());
71 actionBuilder.setActionChoice(pushVlanCaseBuilder.build());
72 actions.add(actionBuilder.build());
73 actionBuilder = new ActionBuilder();
74 actionBuilder.setActionChoice(new PopVlanCaseBuilder().build());
75 actions.add(actionBuilder.build());
76 actionBuilder = new ActionBuilder();
77 actionBuilder.setActionChoice(new PopVlanCaseBuilder().build());
78 actions.add(actionBuilder.build());
79 actionBuilder = new ActionBuilder();
80 actionBuilder.setActionChoice(new PopVlanCaseBuilder().build());
81 actions.add(actionBuilder.build());
82 actionBuilder = new ActionBuilder();
83 actionBuilder.setActionChoice(new PopVlanCaseBuilder().build());
84 actions.add(actionBuilder.build());