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;
12 import java.util.ArrayList;
13 import java.util.List;
14 import org.junit.Assert;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
18 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
19 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
20 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
21 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
22 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncOutput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.FlowRemovedMask;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.FlowRemovedMaskBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMask;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMaskBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMask;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMaskBuilder;
35 * Unit tests for GetAsyncReplyMessageFactory.
37 * @author timotej.kubas
39 public class GetAsyncReplyMessageFactoryTest {
41 private OFDeserializer<GetAsyncOutput> asyncFactory;
44 * Initializes deserializer registry and lookups correct deserializer.
47 public void startUp() {
48 DeserializerRegistry registry = new DeserializerRegistryImpl();
50 asyncFactory = registry.getDeserializer(
51 new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 27, GetAsyncOutput.class));
55 * Testing {@link GetAsyncReplyMessageFactory} for correct translation into POJO.
58 public void testGetAsyncReplyMessage() {
59 ByteBuf bb = BufferHelper.buildBuffer(
60 "00 00 00 07 " + "00 00 00 00 " + "00 00 00 07 " + "00 00 00 00 " + "00 00 00 0F " + "00 00 00 00");
61 GetAsyncOutput builtByFactory = BufferHelper.deserialize(asyncFactory, bb);
63 BufferHelper.checkHeaderV13(builtByFactory);
64 Assert.assertEquals("Wrong packetInMask",createPacketInMask(), builtByFactory.getPacketInMask());
65 Assert.assertEquals("Wrong portStatusMask",createPortStatusMask(), builtByFactory.getPortStatusMask());
66 Assert.assertEquals("Wrong flowRemovedMask",createFlowRemovedMask(), builtByFactory.getFlowRemovedMask());
69 private static List<PacketInMask> createPacketInMask() {
70 final List<PacketInMask> inMasks = new ArrayList<>();
71 PacketInMaskBuilder maskBuilder;
72 // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER
73 maskBuilder = new PacketInMaskBuilder();
74 List<PacketInReason> reasons = new ArrayList<>();
75 reasons.add(PacketInReason.OFPRNOMATCH);
76 reasons.add(PacketInReason.OFPRACTION);
77 reasons.add(PacketInReason.OFPRINVALIDTTL);
78 maskBuilder.setMask(reasons);
79 inMasks.add(maskBuilder.build());
81 maskBuilder = new PacketInMaskBuilder();
82 reasons = new ArrayList<>();
83 maskBuilder.setMask(reasons);
84 inMasks.add(maskBuilder.build());
88 private static List<PortStatusMask> createPortStatusMask() {
89 final List<PortStatusMask> inMasks = new ArrayList<>();
90 PortStatusMaskBuilder maskBuilder;
91 // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER
92 maskBuilder = new PortStatusMaskBuilder();
93 List<PortReason> reasons = new ArrayList<>();
94 reasons.add(PortReason.OFPPRADD);
95 reasons.add(PortReason.OFPPRDELETE);
96 reasons.add(PortReason.OFPPRMODIFY);
97 inMasks.add(maskBuilder.setMask(reasons).build());
99 maskBuilder = new PortStatusMaskBuilder();
100 reasons = new ArrayList<>();
101 maskBuilder.setMask(reasons);
102 inMasks.add(maskBuilder.build());
106 private static List<FlowRemovedMask> createFlowRemovedMask() {
107 final List<FlowRemovedMask> inMasks = new ArrayList<>();
108 FlowRemovedMaskBuilder maskBuilder;
109 // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER
110 maskBuilder = new FlowRemovedMaskBuilder();
111 List<FlowRemovedReason> reasons = new ArrayList<>();
112 reasons.add(FlowRemovedReason.OFPRRIDLETIMEOUT);
113 reasons.add(FlowRemovedReason.OFPRRHARDTIMEOUT);
114 reasons.add(FlowRemovedReason.OFPRRDELETE);
115 reasons.add(FlowRemovedReason.OFPRRGROUPDELETE);
116 maskBuilder.setMask(reasons);
117 inMasks.add(maskBuilder.build());
119 maskBuilder = new FlowRemovedMaskBuilder();
120 reasons = new ArrayList<>();
121 maskBuilder.setMask(reasons);
122 inMasks.add(maskBuilder.build());