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
8 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
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.common.types.rev130731.Capabilities;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
24 * Unit tests for FeaturesReplyMessageFactory.
26 * @author michal.polkorab
27 * @author timotej.kubas
29 public class FeaturesReplyMessageFactoryTest {
31 private OFDeserializer<GetFeaturesOutput> featuresFactory;
34 * Initializes deserializer registry and lookups correct deserializer.
37 public void startUp() {
38 DeserializerRegistry registry = new DeserializerRegistryImpl();
40 featuresFactory = registry.getDeserializer(
41 new MessageCodeKey(EncodeConstants.OF_VERSION_1_3, 6, GetFeaturesOutput.class));
45 * Testing {@link FeaturesReplyMessageFactory} for correct translation into POJO.
49 ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 01 00 00 00"
50 + " 00 00 00 00 01 02 03");
51 GetFeaturesOutput builtByFactory = BufferHelper.deserialize(featuresFactory, bb);
53 BufferHelper.checkHeaderV13(builtByFactory);
54 Assert.assertEquals("Wrong datapathId", 0x0001020304050607L, builtByFactory.getDatapathId().longValue());
55 Assert.assertEquals("Wrong buffers", 0x00010203L, builtByFactory.getBuffers().longValue());
56 Assert.assertEquals("Wrong number of tables", 0x01, builtByFactory.getTables().shortValue());
57 Assert.assertEquals("Wrong auxiliaryId", 0x01, builtByFactory.getAuxiliaryId().shortValue());
58 Assert.assertEquals("Wrong capabilities", new Capabilities(false, false, false, false, false, false, false),
59 builtByFactory.getCapabilities());
60 Assert.assertEquals("Wrong reserved", 0x00010203L, builtByFactory.getReserved().longValue());
64 * Testing {@link FeaturesReplyMessageFactory} for correct translation into POJO
68 public void testCapabilities() {
69 ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 01 00 00 00"
70 + " 00 01 6F 00 01 02 03");
71 GetFeaturesOutput builtByFactory = BufferHelper.deserialize(featuresFactory, bb);
73 BufferHelper.checkHeaderV13(builtByFactory);
74 Assert.assertEquals("Wrong capabilities", new Capabilities(true, true, true, true, true, true, true),
75 builtByFactory.getCapabilities());