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.protocol.api.util.EncodeConstants;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage;
26 * @author timotej.kubas
27 * @author michal.polkorab
29 public class FlowRemovedMessageFactoryTest {
31 private OFDeserializer<FlowRemovedMessage> flowFactory;
34 * Initializes deserializer registry and lookups correct deserializer
37 public void startUp() {
38 DeserializerRegistry registry = new DeserializerRegistryImpl();
40 flowFactory = registry.getDeserializer(
41 new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 11, FlowRemovedMessage.class));
45 * Testing {@link FlowRemovedMessageFactory} for correct translation into POJO
49 ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 03 02 04 00 00 00 02"
50 + " 00 00 00 05 00 01 00 03 00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07");
51 FlowRemovedMessage builtByFactory = BufferHelper.deserialize(flowFactory, bb);
53 BufferHelper.checkHeaderV13(builtByFactory);
55 Assert.assertTrue(builtByFactory.getCookie().longValue() == 0x0001020304050607L);
56 Assert.assertTrue(builtByFactory.getPriority() == 0x03);
57 Assert.assertEquals("Wrong reason", 0x02, builtByFactory.getReason().getIntValue());
58 Assert.assertEquals("Wrong tableId", new TableId(4L), builtByFactory.getTableId());
59 Assert.assertEquals("Wrong durationSec", 0x02L, builtByFactory.getDurationSec().longValue());
60 Assert.assertEquals("Wrong durationNsec", 0x05L, builtByFactory.getDurationNsec().longValue());
61 Assert.assertEquals("Wrong idleTimeout", 0x01, builtByFactory.getIdleTimeout().intValue());
62 Assert.assertEquals("Wrong hardTimeout", 0x03, builtByFactory.getHardTimeout().intValue());
63 Assert.assertEquals("Wrong packetCount", 0x0001020304050607L, builtByFactory.getPacketCount().longValue());
64 Assert.assertEquals("Wrong byteCount", 0x0001020304050607L, builtByFactory.getByteCount().longValue());