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
9 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
11 import io.netty.buffer.ByteBuf;
13 import java.util.ArrayList;
14 import java.util.List;
16 import org.junit.Assert;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
20 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
21 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
22 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
23 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
24 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncOutput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.FlowRemovedMask;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.FlowRemovedMaskBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMask;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMaskBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMask;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMaskBuilder;
37 * @author timotej.kubas
40 public class GetAsyncReplyMessageFactoryTest {
42 private OFDeserializer<GetAsyncOutput> asyncFactory;
45 * Initializes deserializer registry and lookups correct deserializer
48 public void startUp() {
49 DeserializerRegistry registry = new DeserializerRegistryImpl();
51 asyncFactory = registry.getDeserializer(
52 new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 27, GetAsyncOutput.class));
56 * Testing {@link GetAsyncReplyMessageFactory} for correct translation into POJO
59 public void testGetAsyncReplyMessage() {
60 ByteBuf bb = BufferHelper.buildBuffer("00 00 00 07 "+
66 GetAsyncOutput builtByFactory = BufferHelper.deserialize(asyncFactory, bb);
68 BufferHelper.checkHeaderV13(builtByFactory);
69 Assert.assertEquals("Wrong packetInMask",createPacketInMask(), builtByFactory.getPacketInMask());
70 Assert.assertEquals("Wrong portStatusMask",createPortStatusMask(), builtByFactory.getPortStatusMask());
71 Assert.assertEquals("Wrong flowRemovedMask",createFlowRemovedMask(), builtByFactory.getFlowRemovedMask());
74 private static List<PacketInMask> createPacketInMask() {
75 List<PacketInMask> inMasks = new ArrayList<>();
76 PacketInMaskBuilder maskBuilder;
77 // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER
78 maskBuilder = new PacketInMaskBuilder();
79 List<PacketInReason> reasons = new ArrayList<>();
80 reasons.add(PacketInReason.OFPRNOMATCH);
81 reasons.add(PacketInReason.OFPRACTION);
82 reasons.add(PacketInReason.OFPRINVALIDTTL);
83 maskBuilder.setMask(reasons);
84 inMasks.add(maskBuilder.build());
86 maskBuilder = new PacketInMaskBuilder();
87 reasons = new ArrayList<>();
88 maskBuilder.setMask(reasons);
89 inMasks.add(maskBuilder.build());
93 private static List<PortStatusMask> createPortStatusMask() {
94 List<PortStatusMask> inMasks = new ArrayList<>();
95 PortStatusMaskBuilder maskBuilder;
96 // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER
97 maskBuilder = new PortStatusMaskBuilder();
98 List<PortReason> reasons = new ArrayList<>();
99 reasons.add(PortReason.OFPPRADD);
100 reasons.add(PortReason.OFPPRDELETE);
101 reasons.add(PortReason.OFPPRMODIFY);
102 inMasks.add(maskBuilder.setMask(reasons).build());
104 maskBuilder = new PortStatusMaskBuilder();
105 reasons = new ArrayList<>();
106 maskBuilder.setMask(reasons);
107 inMasks.add(maskBuilder.build());
111 private static List<FlowRemovedMask> createFlowRemovedMask() {
112 List<FlowRemovedMask> inMasks = new ArrayList<>();
113 FlowRemovedMaskBuilder maskBuilder;
114 // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER
115 maskBuilder = new FlowRemovedMaskBuilder();
116 List<FlowRemovedReason> reasons = new ArrayList<>();
117 reasons.add(FlowRemovedReason.OFPRRIDLETIMEOUT);
118 reasons.add(FlowRemovedReason.OFPRRHARDTIMEOUT);
119 reasons.add(FlowRemovedReason.OFPRRDELETE);
120 reasons.add(FlowRemovedReason.OFPRRGROUPDELETE);
121 maskBuilder.setMask(reasons);
122 inMasks.add(maskBuilder.build());
124 maskBuilder = new FlowRemovedMaskBuilder();
125 reasons = new ArrayList<>();
126 maskBuilder.setMask(reasons);
127 inMasks.add(maskBuilder.build());