0326720dac3c0b471bf4c60eb521e267b75f4823
[openflowjava.git] / 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
9 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
10
11 import io.netty.buffer.ByteBuf;
12
13 import java.util.ArrayList;
14 import java.util.List;
15
16 import org.junit.Assert;
17 import org.junit.Test;
18 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncOutput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.FlowRemovedMask;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.FlowRemovedMaskBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMask;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMaskBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMask;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMaskBuilder;
29
30 /**
31  * @author timotej.kubas
32  *
33  */
34 public class GetAsyncReplyMessageFactoryTest {
35     
36
37     /**
38      * Testing {@link GetAsyncReplyMessageFactory} for correct translation into POJO
39      */
40     @Test
41     public void testGetAsyncReplyMessage() {
42         ByteBuf bb = BufferHelper.buildBuffer("00 00 00 06 "+ 
43                                               "00 00 00 05 "+
44                                               "00 00 00 07 "+
45                                               "00 00 00 00 "+
46                                               "00 00 00 03 "+
47                                               "00 00 00 0A");
48         GetAsyncOutput builtByFactory = BufferHelper.decodeV13(GetAsyncReplyMessageFactory.getInstance(), bb);
49
50         BufferHelper.checkHeaderV13(builtByFactory);
51         Assert.assertEquals("Wrong packetInMask",createPacketInMask(), 
52                                                  builtByFactory.getPacketInMask());
53         Assert.assertEquals("Wrong portStatusMask",createPortStatusMask(), 
54                                                    builtByFactory.getPortStatusMask());
55         Assert.assertEquals("Wrong flowRemovedMask",createFlowRemovedMask(), 
56                                                     builtByFactory.getFlowRemovedMask());
57     }
58     
59     private static List<PacketInMask> createPacketInMask() {
60         List<PacketInMask> inMasks = new ArrayList<>();
61         PacketInMaskBuilder maskBuilder;
62         // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER
63         maskBuilder = new PacketInMaskBuilder();
64         List<PacketInReason> reasons = new ArrayList<>();
65         reasons.add(PacketInReason.OFPRACTION);
66         reasons.add(PacketInReason.OFPRINVALIDTTL);
67         maskBuilder.setMask(reasons);
68         inMasks.add(maskBuilder.build());
69         // OFPCR_ROLE_SLAVE
70         maskBuilder = new PacketInMaskBuilder();
71         reasons = new ArrayList<>();
72         reasons.add(PacketInReason.OFPRNOMATCH);
73         reasons.add(PacketInReason.OFPRINVALIDTTL);
74         maskBuilder.setMask(reasons);
75         inMasks.add(maskBuilder.build());
76         return inMasks;
77     }
78     
79     private static List<PortStatusMask> createPortStatusMask() {
80         List<PortStatusMask> inMasks = new ArrayList<>();
81         PortStatusMaskBuilder maskBuilder;
82         // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER
83         maskBuilder = new PortStatusMaskBuilder();
84         List<PortReason> reasons = new ArrayList<>();
85         reasons.add(PortReason.OFPPRADD);
86         reasons.add(PortReason.OFPPRDELETE);
87         reasons.add(PortReason.OFPPRMODIFY);
88         inMasks.add(maskBuilder.setMask(reasons).build());
89         // OFPCR_ROLE_SLAVE
90         maskBuilder = new PortStatusMaskBuilder();
91         reasons = new ArrayList<>();
92         maskBuilder.setMask(reasons);
93         inMasks.add(maskBuilder.build());
94         return inMasks;
95     }
96     
97     private static List<FlowRemovedMask> createFlowRemovedMask() {
98         List<FlowRemovedMask> inMasks = new ArrayList<>();
99         FlowRemovedMaskBuilder maskBuilder;
100         // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER
101         maskBuilder = new FlowRemovedMaskBuilder();
102         List<FlowRemovedReason> reasons = new ArrayList<>();
103         reasons.add(FlowRemovedReason.OFPRRIDLETIMEOUT);
104         reasons.add(FlowRemovedReason.OFPRRHARDTIMEOUT);
105         maskBuilder.setMask(reasons);
106         inMasks.add(maskBuilder.build());
107         // OFPCR_ROLE_SLAVE
108         maskBuilder = new FlowRemovedMaskBuilder();
109         reasons = new ArrayList<>();
110         reasons.add(FlowRemovedReason.OFPRRHARDTIMEOUT);
111         reasons.add(FlowRemovedReason.OFPRRGROUPDELETE);
112         maskBuilder.setMask(reasons);
113         inMasks.add(maskBuilder.build());
114         return inMasks;
115     }
116 }