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 java.util.List;
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.OFDeserializer;
18 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
19 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
20 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
21 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason;
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.PortReason;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncOutput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.FlowRemovedMask;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.FlowRemovedMaskBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMask;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMaskBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMask;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMaskBuilder;
34 * Unit tests for GetAsyncReplyMessageFactory.
36 * @author timotej.kubas
38 public class GetAsyncReplyMessageFactoryTest {
40 private OFDeserializer<GetAsyncOutput> asyncFactory;
43 * Initializes deserializer registry and lookups correct deserializer.
46 public void startUp() {
47 DeserializerRegistry registry = new DeserializerRegistryImpl();
49 asyncFactory = registry.getDeserializer(
50 new MessageCodeKey(EncodeConstants.OF_VERSION_1_3, 27, GetAsyncOutput.class));
54 * Testing {@link GetAsyncReplyMessageFactory} for correct translation into POJO.
57 public void testGetAsyncReplyMessage() {
58 ByteBuf bb = BufferHelper.buildBuffer(
59 "00 00 00 07 " + "00 00 00 00 " + "00 00 00 07 " + "00 00 00 00 " + "00 00 00 0F " + "00 00 00 00");
60 GetAsyncOutput builtByFactory = BufferHelper.deserialize(asyncFactory, bb);
62 BufferHelper.checkHeaderV13(builtByFactory);
63 Assert.assertEquals("Wrong packetInMask", createPacketInMask(), builtByFactory.getPacketInMask());
64 Assert.assertEquals("Wrong portStatusMask", createPortStatusMask(), builtByFactory.getPortStatusMask());
65 Assert.assertEquals("Wrong flowRemovedMask", createFlowRemovedMask(), builtByFactory.getFlowRemovedMask());
68 private static List<PacketInMask> createPacketInMask() {
70 // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER
71 new PacketInMaskBuilder()
72 .setMask(Set.of(PacketInReason.OFPRNOMATCH, PacketInReason.OFPRACTION, PacketInReason.OFPRINVALIDTTL))
75 new PacketInMaskBuilder().setMask(Set.of()).build());
78 private static List<PortStatusMask> createPortStatusMask() {
80 // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER
81 new PortStatusMaskBuilder()
82 .setMask(Set.of(PortReason.OFPPRADD, PortReason.OFPPRDELETE, PortReason.OFPPRMODIFY))
85 new PortStatusMaskBuilder().setMask(Set.of()).build());
88 private static List<FlowRemovedMask> createFlowRemovedMask() {
90 // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER
91 new FlowRemovedMaskBuilder()
93 FlowRemovedReason.OFPRRIDLETIMEOUT,
94 FlowRemovedReason.OFPRRHARDTIMEOUT,
95 FlowRemovedReason.OFPRRDELETE,
96 FlowRemovedReason.OFPRRGROUPDELETE))
99 new FlowRemovedMaskBuilder().setMask(Set.of()).build());