Use ByteBuf.readRetainedSlice()
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / OF10FlowRemovedMessageFactoryTest.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 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
9
10 import io.netty.buffer.ByteBuf;
11 import org.junit.Assert;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
16 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
17 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
18 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
19 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage;
21
22 /**
23  * Unit tests for OF10FlowRemovedMessageFactory.
24  *
25  * @author michal.polkorab
26  */
27 public class OF10FlowRemovedMessageFactoryTest {
28
29     private OFDeserializer<FlowRemovedMessage> flowFactory;
30
31     /**
32      * Initializes deserializer registry and lookups correct deserializer.
33      */
34     @Before
35     public void startUp() {
36         DeserializerRegistry registry = new DeserializerRegistryImpl();
37         registry.init();
38         flowFactory = registry.getDeserializer(
39                 new MessageCodeKey(EncodeConstants.OF_VERSION_1_0, 11, FlowRemovedMessage.class));
40     }
41
42     /**
43      * Testing {@link OF10FlowRemovedMessageFactory} for correct translation into POJO.
44      */
45     @Test
46     public void test() {
47         ByteBuf bb = BufferHelper.buildBuffer("00 24 08 D1 00 20 AA BB CC DD EE FF "
48                 + "AA BB CC DD EE FF 00 05 10 00 00 08 07 06 00 00 10 11 12 13 01 02 03 04 "//36
49                 + "50 50 20 20 "// match
50                 + "00 01 02 03 04 05 06 07 00 03 01 00 00 00 00 02 "
51                 + "00 00 00 05 00 08 00 00 00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07");//41
52         FlowRemovedMessage builtByFactory = BufferHelper.deserialize(flowFactory, bb);
53
54         BufferHelper.checkHeaderV10(builtByFactory);
55         Assert.assertEquals("Wrong cookie", 0x0001020304050607L, builtByFactory.getCookie().longValue());
56         Assert.assertEquals("Wrong priority", 0x03, builtByFactory.getPriority().intValue());
57         Assert.assertEquals("Wrong reason", 0x01, builtByFactory.getReason().getIntValue());
58         Assert.assertEquals("Wrong durationSec", 0x00000002L, builtByFactory.getDurationSec().longValue());
59         Assert.assertEquals("Wrong durationNsec", 0x00000005L, builtByFactory.getDurationNsec().longValue());
60         Assert.assertEquals("Wrong idleTimeout", 0x08, builtByFactory.getIdleTimeout().intValue());
61         Assert.assertEquals("Wrong packetCount", 0x0001020304050607L, builtByFactory.getPacketCount().longValue());
62         Assert.assertEquals("Wrong byteCount", 0x0001020304050607L, builtByFactory.getByteCount().longValue());
63     }
64
65 }