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());
89 System.out.println(masks.size());
93 private static List<PortStatusMask> createPortStatusMask() {
94 List<PortStatusMask> masks = new ArrayList<>();
95 PortStatusMaskBuilder builder;
96 builder = new PortStatusMaskBuilder();
97 // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER
98 List<PortReason> portReasonList = new ArrayList<>();
99 portReasonList.add(PortReason.OFPPRDELETE);
100 portReasonList.add(PortReason.OFPPRMODIFY);
101 builder.setMask(portReasonList);
102 masks.add(builder.build());
104 builder = new PortStatusMaskBuilder();
105 portReasonList = new ArrayList<>();
106 builder.setMask(portReasonList);
107 masks.add(builder.build());
111 private static List<FlowRemovedMask> createFlowRemowedMask() {
112 List<FlowRemovedMask> masks = new ArrayList<>();
113 FlowRemovedMaskBuilder builder;
114 // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER
115 builder = new FlowRemovedMaskBuilder();
116 List<FlowRemovedReason> flowRemovedReasonList = new ArrayList<>();
117 flowRemovedReasonList.add(FlowRemovedReason.OFPRRHARDTIMEOUT);
118 flowRemovedReasonList.add(FlowRemovedReason.OFPRRGROUPDELETE);
119 builder.setMask(flowRemovedReasonList);
120 masks.add(builder.build());
122 builder = new FlowRemovedMaskBuilder();
123 flowRemovedReasonList = new ArrayList<>();
124 flowRemovedReasonList.add(FlowRemovedReason.OFPRRIDLETIMEOUT);
125 flowRemovedReasonList.add(FlowRemovedReason.OFPRRDELETE);
126 builder.setMask(flowRemovedReasonList);
127 masks.add(builder.build());