6a3a35f07f8306c2b842c6767e9b7e7c62ddd41f
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / PacketInMessageFactoryTest.java
1 /*
2  * Copyright (c) 2013 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.openflowjava.protocol.impl.deserialization.factories;
10
11 import io.netty.buffer.ByteBuf;
12
13 import org.junit.Assert;
14 import org.junit.Test;
15 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
16 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 /**
24  * @author timotej.kubas
25  *
26  */
27 public class PacketInMessageFactoryTest {
28
29     private static final Logger LOGGER = LoggerFactory
30             .getLogger(PacketInMessageFactoryTest.class);
31     
32     /**
33      * Testing {@link PacketInMessageFactory} for correct translation into POJO
34      */
35     @Test
36     public void test(){
37         ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 01 02 01 04 00 01 02 03 04 05 06 07 00 01 00 0C"
38                 + " 80 00 02 04 00 00 00 01 00 00 00 00 00 00 01 02 03 04");
39         PacketInMessage builtByFactory = BufferHelper.decodeV13(PacketInMessageFactory.getInstance(), bb); 
40         
41         BufferHelper.checkHeaderV13(builtByFactory);
42         
43         Assert.assertEquals("Wrong bufferID", 0x00010203L, builtByFactory.getBufferId().longValue());
44         Assert.assertEquals("Wrong totalLength", 0x0102, builtByFactory.getTotalLen().intValue());
45         Assert.assertEquals("Wrong reason", PacketInReason.OFPRACTION, builtByFactory.getReason());
46         Assert.assertEquals("Wrong tableID", new TableId(4L), builtByFactory.getTableId());
47         Assert.assertEquals("Wrong cookie", 0x0001020304050607L, builtByFactory.getCookie().longValue());
48         Assert.assertArrayEquals("Wrong data", ByteBufUtils.hexStringToBytes("01 02 03 04"), builtByFactory.getData());
49     }
50 }