1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
\r
2 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
\r
4 import io.netty.buffer.ByteBuf;
\r
5 import io.netty.buffer.UnpooledByteBufAllocator;
\r
7 import java.math.BigInteger;
\r
9 import org.junit.Assert;
\r
10 import org.junit.Test;
\r
11 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;
\r
12 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
\r
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModCommand;
\r
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags;
\r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
\r
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;
\r
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;
\r
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
\r
21 * @author timotej.kubas
\r
22 * @author michal.polkorab
\r
24 public class FlowModInputMessageFactoryTest {
\r
25 private static final byte PADDING_IN_FLOW_MOD_MESSAGE = 2;
\r
27 * @throws Exception
\r
28 * Testing of {@link FlowModInputMessageFactory} for correct translation from POJO
\r
31 public void testFlowModInputMessageFactory() throws Exception {
\r
32 FlowModInputBuilder builder = new FlowModInputBuilder();
\r
33 BufferHelper.setupHeader(builder);
\r
34 byte[] cookie = new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01};
\r
35 builder.setCookie(new BigInteger(cookie));
\r
36 byte[] cookieMask = new byte[]{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
\r
37 builder.setCookieMask(new BigInteger(cookieMask));
\r
38 builder.setTableId(new TableId(65L));
\r
39 builder.setCommand(FlowModCommand.forValue(2));
\r
40 builder.setIdleTimeout(12);
\r
41 builder.setHardTimeout(0);
\r
42 builder.setPriority(126);
\r
43 builder.setOutPort(new PortNumber(4422L));
\r
44 builder.setOutGroup(98L);
\r
45 builder.setFlags(new FlowModFlags(true, false, true, false, true));
\r
46 FlowModInput message = builder.build();
\r
48 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
\r
49 FlowModInputMessageFactory factory = FlowModInputMessageFactory.getInstance();
\r
50 factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
\r
52 BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength());
\r
53 Assert.assertEquals("Wrong cookie", message.getCookie().longValue(), out.readLong());
\r
54 Assert.assertEquals("Wrong cookieMask", message.getCookieMask().longValue(), out.readLong());
\r
55 Assert.assertEquals("Wrong tableId", message.getTableId().getValue().intValue(), out.readByte());
\r
56 Assert.assertEquals("Wrong command", message.getCommand().getIntValue(), out.readByte());
\r
57 Assert.assertEquals("Wrong idleTimeOut", message.getIdleTimeout().intValue(), out.readShort());
\r
58 Assert.assertEquals("Wrong hardTimeOut", message.getHardTimeout().intValue(), out.readShort());
\r
59 Assert.assertEquals("Wrong priority", message.getPriority().intValue(), out.readShort());
\r
60 Assert.assertEquals("Wrong outPort", message.getOutPort().getValue().intValue(), out.readUnsignedInt());
\r
61 Assert.assertEquals("Wrong outGroup", message.getOutGroup().intValue(), out.readUnsignedInt());
\r
62 Assert.assertEquals("Wrong flags", message.getFlags(), createFlowModFalgsFromBitmap(out.readShort()));
\r
63 out.skipBytes(PADDING_IN_FLOW_MOD_MESSAGE);
\r
64 // TODO implementation of match structure
\r
65 // TODO implementation of instructions
\r
68 private static FlowModFlags createFlowModFalgsFromBitmap(short input){
\r
69 final Boolean _oFPFFSENDFLOWREM = (input & (1 << 0)) > 0;
\r
70 final Boolean _oFPFFCHECKOVERLAP = (input & (1 << 1)) > 0;
\r
71 final Boolean _oFPFFRESETCOUNTS = (input & (1 << 2)) > 0;
\r
72 final Boolean _oFPFFNOPKTCOUNTS = (input & (1 << 3)) > 0;
\r
73 final Boolean _oFPFFNOBYTCOUNTS = (input & (1 << 4)) > 0;
\r
74 return new FlowModFlags(_oFPFFCHECKOVERLAP, _oFPFFNOBYTCOUNTS, _oFPFFNOPKTCOUNTS, _oFPFFRESETCOUNTS, _oFPFFSENDFLOWREM);
\r