Update MRI upstreams for Phosphorus
[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.ArrayList;
12 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;
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         final List<PacketInMask> inMasks = new ArrayList<>();
70         PacketInMaskBuilder maskBuilder;
71         // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER
72         maskBuilder = new PacketInMaskBuilder();
73         List<PacketInReason> reasons = new ArrayList<>();
74         reasons.add(PacketInReason.OFPRNOMATCH);
75         reasons.add(PacketInReason.OFPRACTION);
76         reasons.add(PacketInReason.OFPRINVALIDTTL);
77         maskBuilder.setMask(reasons);
78         inMasks.add(maskBuilder.build());
79         // OFPCR_ROLE_SLAVE
80         maskBuilder = new PacketInMaskBuilder();
81         reasons = new ArrayList<>();
82         maskBuilder.setMask(reasons);
83         inMasks.add(maskBuilder.build());
84         return inMasks;
85     }
86
87     private static List<PortStatusMask> createPortStatusMask() {
88         final List<PortStatusMask> inMasks = new ArrayList<>();
89         PortStatusMaskBuilder maskBuilder;
90         // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER
91         maskBuilder = new PortStatusMaskBuilder();
92         List<PortReason> reasons = new ArrayList<>();
93         reasons.add(PortReason.OFPPRADD);
94         reasons.add(PortReason.OFPPRDELETE);
95         reasons.add(PortReason.OFPPRMODIFY);
96         inMasks.add(maskBuilder.setMask(reasons).build());
97         // OFPCR_ROLE_SLAVE
98         maskBuilder = new PortStatusMaskBuilder();
99         reasons = new ArrayList<>();
100         maskBuilder.setMask(reasons);
101         inMasks.add(maskBuilder.build());
102         return inMasks;
103     }
104
105     private static List<FlowRemovedMask> createFlowRemovedMask() {
106         final List<FlowRemovedMask> inMasks = new ArrayList<>();
107         FlowRemovedMaskBuilder maskBuilder;
108         // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER
109         maskBuilder = new FlowRemovedMaskBuilder();
110         List<FlowRemovedReason> reasons = new ArrayList<>();
111         reasons.add(FlowRemovedReason.OFPRRIDLETIMEOUT);
112         reasons.add(FlowRemovedReason.OFPRRHARDTIMEOUT);
113         reasons.add(FlowRemovedReason.OFPRRDELETE);
114         reasons.add(FlowRemovedReason.OFPRRGROUPDELETE);
115         maskBuilder.setMask(reasons);
116         inMasks.add(maskBuilder.build());
117         // OFPCR_ROLE_SLAVE
118         maskBuilder = new FlowRemovedMaskBuilder();
119         reasons = new ArrayList<>();
120         maskBuilder.setMask(reasons);
121         inMasks.add(maskBuilder.build());
122         return inMasks;
123     }
124 }