2 * Copyright (c) 2013 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
9 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
11 import io.netty.buffer.ByteBuf;
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.MessageCodeKey;
18 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
19 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
20 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
21 import org.opendaylight.openflowjava.util.ByteBufUtils;
22 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;
28 * @author timotej.kubas
31 public class PacketInMessageFactoryTest {
33 private OFDeserializer<PacketInMessage> packetInFactory;
36 * Initializes deserializer registry and lookups correct deserializer
39 public void startUp() {
40 DeserializerRegistry registry = new DeserializerRegistryImpl();
42 packetInFactory = registry.getDeserializer(
43 new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 10, PacketInMessage.class));
47 * Testing {@link PacketInMessageFactory} for correct translation into POJO
51 ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 01 02 01 04 00 01 02 03 04 05 06 07 00 01 00 0C"
52 + " 80 00 02 04 00 00 00 01 00 00 00 00 00 00 01 02 03 04");
53 PacketInMessage builtByFactory = BufferHelper.deserialize(packetInFactory, bb);
55 BufferHelper.checkHeaderV13(builtByFactory);
57 Assert.assertEquals("Wrong bufferID", 0x00010203L, builtByFactory.getBufferId().longValue());
58 Assert.assertEquals("Wrong totalLength", 0x0102, builtByFactory.getTotalLen().intValue());
59 Assert.assertEquals("Wrong reason", PacketInReason.OFPRACTION, builtByFactory.getReason());
60 Assert.assertEquals("Wrong tableID", new TableId(4L), builtByFactory.getTableId());
61 Assert.assertEquals("Wrong cookie", 0x0001020304050607L, builtByFactory.getCookie().longValue());
62 Assert.assertArrayEquals("Wrong data", ByteBufUtils.hexStringToBytes("01 02 03 04"), builtByFactory.getData());