Bump MRI upstreams
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / GetAsyncReplyMessageFactoryTest.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 java.util.List;
12 import java.util.Set;
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;
32
33 /**
34  * Unit tests for GetAsyncReplyMessageFactory.
35  *
36  * @author timotej.kubas
37  */
38 public class GetAsyncReplyMessageFactoryTest {
39
40     private OFDeserializer<GetAsyncOutput> asyncFactory;
41
42     /**
43      * Initializes deserializer registry and lookups correct deserializer.
44      */
45     @Before
46     public void startUp() {
47         DeserializerRegistry registry = new DeserializerRegistryImpl();
48         registry.init();
49         asyncFactory = registry.getDeserializer(
50                 new MessageCodeKey(EncodeConstants.OF_VERSION_1_3, 27, GetAsyncOutput.class));
51     }
52
53     /**
54      * Testing {@link GetAsyncReplyMessageFactory} for correct translation into POJO.
55      */
56     @Test
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);
61
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());
66     }
67
68     private static List<PacketInMask> createPacketInMask() {
69         return List.of(
70             // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER
71             new PacketInMaskBuilder()
72                 .setMask(Set.of(PacketInReason.OFPRNOMATCH, PacketInReason.OFPRACTION, PacketInReason.OFPRINVALIDTTL))
73                 .build(),
74             // OFPCR_ROLE_SLAVE
75             new PacketInMaskBuilder().setMask(Set.of()).build());
76     }
77
78     private static List<PortStatusMask> createPortStatusMask() {
79         return List.of(
80             // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER
81             new PortStatusMaskBuilder()
82                 .setMask(Set.of(PortReason.OFPPRADD, PortReason.OFPPRDELETE, PortReason.OFPPRMODIFY))
83                 .build(),
84             // OFPCR_ROLE_SLAVE
85             new PortStatusMaskBuilder().setMask(Set.of()).build());
86     }
87
88     private static List<FlowRemovedMask> createFlowRemovedMask() {
89         return List.of(
90             // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER
91             new FlowRemovedMaskBuilder()
92                 .setMask(Set.of(
93                     FlowRemovedReason.OFPRRIDLETIMEOUT,
94                     FlowRemovedReason.OFPRRHARDTIMEOUT,
95                     FlowRemovedReason.OFPRRDELETE,
96                     FlowRemovedReason.OFPRRGROUPDELETE))
97                 .build(),
98             // OFPCR_ROLE_SLAVE
99             new FlowRemovedMaskBuilder().setMask(Set.of()).build());
100     }
101 }