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.serialization.factories;
11 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.UnpooledByteBufAllocator;
14 import java.util.ArrayList;
15 import java.util.List;
17 import org.junit.Assert;
18 import org.junit.Test;
19 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;
20 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
21 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
22 import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
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.SetAsyncInput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncInputBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.FlowRemovedMask;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.FlowRemovedMaskBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMask;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMaskBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMask;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMaskBuilder;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
38 * @author timotej.kubas
39 * @author michal.polkorab
41 public class SetAsyncInputMessageFactoryTest {
42 private static final Logger LOGGER = LoggerFactory
43 .getLogger(SetAsyncInputMessageFactoryTest.class);
46 * Testing of {@link SetAsyncInputMessageFactory} for correct translation from POJO
49 public void testSetAsyncInputMessage() throws Exception {
50 SetAsyncInputBuilder builder = new SetAsyncInputBuilder();
51 BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
52 builder.setPacketInMask(createPacketInMask());
53 builder.setPortStatusMask(createPortStatusMask());
54 builder.setFlowRemovedMask(createFlowRemowedMask());
55 SetAsyncInput message = builder.build();
57 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
58 SetAsyncInputMessageFactory factory = SetAsyncInputMessageFactory.getInstance();
59 factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
60 LOGGER.debug("<< " + ByteBufUtils.byteBufToHexString(out));
61 BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));
62 Assert.assertEquals("Wrong packetInMask", 5, out.readUnsignedInt());
63 Assert.assertEquals("Wrong packetInMask", 7, out.readUnsignedInt());
64 Assert.assertEquals("Wrong portStatusMask", 6, out.readUnsignedInt());
65 Assert.assertEquals("Wrong portStatusMask", 0, out.readUnsignedInt());
66 Assert.assertEquals("Wrong flowRemovedMask", 10, out.readUnsignedInt());
67 Assert.assertEquals("Wrong flowRemovedMask", 5, out.readUnsignedInt());
71 private static List<PacketInMask> createPacketInMask() {
72 List<PacketInMask> masks = new ArrayList<>();
73 PacketInMaskBuilder builder;
74 // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER
75 builder = new PacketInMaskBuilder();
76 List<PacketInReason> packetInReasonList = new ArrayList<>();
77 packetInReasonList.add(PacketInReason.OFPRNOMATCH);
78 packetInReasonList.add(PacketInReason.OFPRINVALIDTTL);
79 builder.setMask(packetInReasonList);
80 masks.add(builder.build());
82 builder = new PacketInMaskBuilder();
83 packetInReasonList = new ArrayList<>();
84 packetInReasonList.add(PacketInReason.OFPRNOMATCH);
85 packetInReasonList.add(PacketInReason.OFPRACTION);
86 packetInReasonList.add(PacketInReason.OFPRINVALIDTTL);
87 builder.setMask(packetInReasonList);
88 masks.add(builder.build());
92 private static List<PortStatusMask> createPortStatusMask() {
93 List<PortStatusMask> masks = new ArrayList<>();
94 PortStatusMaskBuilder builder;
95 builder = new PortStatusMaskBuilder();
96 // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER
97 List<PortReason> portReasonList = new ArrayList<>();
98 portReasonList.add(PortReason.OFPPRDELETE);
99 portReasonList.add(PortReason.OFPPRMODIFY);
100 builder.setMask(portReasonList);
101 masks.add(builder.build());
103 builder = new PortStatusMaskBuilder();
104 portReasonList = new ArrayList<>();
105 builder.setMask(portReasonList);
106 masks.add(builder.build());
110 private static List<FlowRemovedMask> createFlowRemowedMask() {
111 List<FlowRemovedMask> masks = new ArrayList<>();
112 FlowRemovedMaskBuilder builder;
113 // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER
114 builder = new FlowRemovedMaskBuilder();
115 List<FlowRemovedReason> flowRemovedReasonList = new ArrayList<>();
116 flowRemovedReasonList.add(FlowRemovedReason.OFPRRHARDTIMEOUT);
117 flowRemovedReasonList.add(FlowRemovedReason.OFPRRGROUPDELETE);
118 builder.setMask(flowRemovedReasonList);
119 masks.add(builder.build());
121 builder = new FlowRemovedMaskBuilder();
122 flowRemovedReasonList = new ArrayList<>();
123 flowRemovedReasonList.add(FlowRemovedReason.OFPRRIDLETIMEOUT);
124 flowRemovedReasonList.add(FlowRemovedReason.OFPRRDELETE);
125 builder.setMask(flowRemovedReasonList);
126 masks.add(builder.build());