Search in sources :

Example 91 with Table

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table in project openflowplugin by opendaylight.

the class OF10StatsRequestInputFactoryTest method testTable.

/**
 * Testing OF10StatsRequestInputFactory (Table) for correct serialization.
 */
@Test
public void testTable() throws Exception {
    MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
    builder.setType(MultipartType.OFPMPTABLE);
    builder.setFlags(new MultipartRequestFlags(false));
    MultipartRequestTableCaseBuilder caseBuilder = new MultipartRequestTableCaseBuilder();
    MultipartRequestTableBuilder tableBuilder = new MultipartRequestTableBuilder();
    caseBuilder.setMultipartRequestTable(tableBuilder.build());
    builder.setMultipartRequestBody(caseBuilder.build());
    MultipartRequestInput message = builder.build();
    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    multipartFactory.serialize(message, out);
    BufferHelper.checkHeaderV10(out, (byte) 16, 12);
    Assert.assertEquals("Wrong type", 3, out.readUnsignedShort());
    Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());
    Assert.assertTrue("Unread data", out.readableBytes() == 0);
}
Also used : MultipartRequestInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder) MultipartRequestTableCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableCaseBuilder) MultipartRequestFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags) MultipartRequestTableBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table._case.MultipartRequestTableBuilder) ByteBuf(io.netty.buffer.ByteBuf) MultipartRequestInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput) Test(org.junit.Test)

Example 92 with Table

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table in project openflowplugin by opendaylight.

the class MultipartRequestTableTest method test.

/**
 * Tests {@link MultipartRequestInputFactory} - Table case.
 */
@Test
public void test() throws Exception {
    MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setType(MultipartType.OFPMPTABLE);
    builder.setFlags(new MultipartRequestFlags(false));
    MultipartRequestTableCaseBuilder caseBuilder = new MultipartRequestTableCaseBuilder();
    MultipartRequestTableBuilder tablesBuilder = new MultipartRequestTableBuilder();
    tablesBuilder.setEmpty(true);
    caseBuilder.setMultipartRequestTable(tablesBuilder.build());
    builder.setMultipartRequestBody(caseBuilder.build());
    MultipartRequestInput message = builder.build();
    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    multipartFactory.serialize(message, out);
    BufferHelper.checkHeaderV13(out, (byte) 18, 16);
    Assert.assertEquals("Wrong type", 3, out.readUnsignedShort());
    Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());
    // skip padding
    out.skipBytes(4);
    Assert.assertTrue("Unexpected data", out.readableBytes() == 0);
}
Also used : MultipartRequestInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder) MultipartRequestTableCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableCaseBuilder) MultipartRequestFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags) MultipartRequestTableBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table._case.MultipartRequestTableBuilder) ByteBuf(io.netty.buffer.ByteBuf) MultipartRequestInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput) Test(org.junit.Test)

Example 93 with Table

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table in project openflowplugin by opendaylight.

the class ResubmitCodec method serialize.

@Override
public void serialize(final Action input, final ByteBuf outBuffer) {
    byte table = OFP_TABLE_ALL;
    short inPort = OFP_IN_PORT;
    ActionResubmit action = (ActionResubmit) input.getActionChoice();
    serializeHeader(LENGTH, getSubType(action), outBuffer);
    if (action.getNxActionResubmit().getInPort() != null) {
        inPort = action.getNxActionResubmit().getInPort().shortValue();
    }
    if (action.getNxActionResubmit().getTable() != null) {
        table = action.getNxActionResubmit().getTable().byteValue();
    }
    outBuffer.writeShort(inPort);
    outBuffer.writeByte(table);
    outBuffer.writeZero(PADDING);
}
Also used : ActionResubmit(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionResubmit)

Example 94 with Table

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table in project openflowplugin by opendaylight.

the class MultipartReplyMessageFactoryTest method testFlowBody.

private static void testFlowBody(MultipartReplyBody body, ByteBuf output) {
    MultipartReplyFlowCase flowCase = (MultipartReplyFlowCase) body;
    MultipartReplyFlow flow = flowCase.getMultipartReplyFlow();
    FlowStats flowStats = flow.getFlowStats().get(0);
    Assert.assertEquals("Wrong length", 176, output.readShort());
    Assert.assertEquals("Wrong Table ID", flowStats.getTableId().intValue(), output.readUnsignedByte());
    output.skipBytes(1);
    Assert.assertEquals("Wrong duration sec", flowStats.getDurationSec().intValue(), output.readInt());
    Assert.assertEquals("Wrong duration nsec", flowStats.getDurationNsec().intValue(), output.readInt());
    Assert.assertEquals("Wrong priority", flowStats.getPriority().intValue(), output.readShort());
    Assert.assertEquals("Wrong idle timeout", flowStats.getIdleTimeout().intValue(), output.readShort());
    Assert.assertEquals("Wrong hard timeout", flowStats.getHardTimeout().intValue(), output.readShort());
    output.skipBytes(6);
    Assert.assertEquals("Wrong cookie", flowStats.getCookie().longValue(), output.readLong());
    Assert.assertEquals("Wrong Packet count", flowStats.getPacketCount().longValue(), output.readLong());
    Assert.assertEquals("Wrong Byte count", flowStats.getByteCount().longValue(), output.readLong());
    Assert.assertEquals("Wrong match type", 1, output.readUnsignedShort());
    output.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    Assert.assertEquals("Wrong oxm class", 0x8000, output.readUnsignedShort());
    short fieldAndMask = output.readUnsignedByte();
    Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1);
    Assert.assertEquals("Wrong oxm field", 1, fieldAndMask >> 1);
    output.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
    Assert.assertEquals("Wrong oxm value", 42, output.readUnsignedInt());
    Assert.assertEquals("Wrong oxm class", 0x8000, output.readUnsignedShort());
    fieldAndMask = output.readUnsignedByte();
    Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1);
    Assert.assertEquals("Wrong oxm field", 9, fieldAndMask >> 1);
    output.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
    Assert.assertEquals("Wrong oxm value", 4, output.readUnsignedByte());
    output.skipBytes(7);
    Assert.assertEquals("Wrong instruction type", 1, output.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 8, output.readUnsignedShort());
    Assert.assertEquals("Wrong instruction table-id", 5, output.readUnsignedByte());
    output.skipBytes(3);
    Assert.assertEquals("Wrong instruction type", 2, output.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 24, output.readUnsignedShort());
    output.skipBytes(4);
    byte[] actual = new byte[8];
    output.readBytes(actual);
    Assert.assertEquals("Wrong instruction metadata", "00 01 02 03 04 05 06 07", ByteBufUtils.bytesToHexString(actual));
    actual = new byte[8];
    output.readBytes(actual);
    Assert.assertEquals("Wrong instruction metadata-mask", "07 06 05 04 03 02 01 00", ByteBufUtils.bytesToHexString(actual));
    Assert.assertEquals("Wrong instruction type", 5, output.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 8, output.readUnsignedShort());
    output.skipBytes(4);
    Assert.assertEquals("Wrong instruction type", 6, output.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 8, output.readUnsignedShort());
    Assert.assertEquals("Wrong instruction meter-id", 42, output.readUnsignedInt());
    Assert.assertEquals("Wrong instruction type", 3, output.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 32, output.readUnsignedShort());
    output.skipBytes(4);
    Assert.assertEquals("Wrong action type", 0, output.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 16, output.readUnsignedShort());
    Assert.assertEquals("Wrong action type", 45, output.readUnsignedInt());
    Assert.assertEquals("Wrong action type", 55, output.readUnsignedShort());
    output.skipBytes(6);
    Assert.assertEquals("Wrong action type", 23, output.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, output.readUnsignedShort());
    Assert.assertEquals("Wrong action type", 64, output.readUnsignedByte());
    output.skipBytes(3);
    Assert.assertEquals("Wrong instruction type", 4, output.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 24, output.readUnsignedShort());
    output.skipBytes(4);
    Assert.assertEquals("Wrong action type", 17, output.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, output.readUnsignedShort());
    Assert.assertEquals("Wrong action ethertype", 14, output.readUnsignedShort());
    output.skipBytes(2);
    Assert.assertEquals("Wrong action type", 27, output.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, output.readUnsignedShort());
    output.skipBytes(4);
    Assert.assertTrue("Not all data were read", output.readableBytes() == 0);
}
Also used : FlowStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats) MultipartReplyFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlow) MultipartReplyFlowCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase)

Example 95 with Table

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table in project openflowplugin by opendaylight.

the class OF10StatsReplyMessageFactoryTest method testTableBodySerialize.

@Test
public void testTableBodySerialize() throws Exception {
    MultipartReplyMessageBuilder builder;
    builder = new MultipartReplyMessageBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
    builder.setFlags(new MultipartRequestFlags(true));
    builder.setType(MultipartType.forValue(3));
    MultipartReplyTableCaseBuilder tableCase = new MultipartReplyTableCaseBuilder();
    MultipartReplyTableBuilder table = new MultipartReplyTableBuilder();
    table.setTableStats(createTableStats());
    tableCase.setMultipartReplyTable(table.build());
    builder.setMultipartReplyBody(tableCase.build());
    MultipartReplyMessage message = builder.build();
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    factory.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 60);
    Assert.assertEquals("Wrong type", MultipartType.OFPMPTABLE.getIntValue(), serializedBuffer.readShort());
    Assert.assertEquals("Wrong flags", message.getFlags(), createMultipartRequestFlags(serializedBuffer.readShort()));
    Assert.assertEquals("Wrong table id", 1, serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(3);
    Assert.assertEquals("Wrong name", "Table name", ByteBufUtils.decodeNullTerminatedString(serializedBuffer, 16));
    Assert.assertEquals("Wrong wildcards", 3145983, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong max entries", 1L, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong active count", 1L, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong lookup count", 1234L, serializedBuffer.readLong());
    Assert.assertEquals("Wrong matched count", 1234L, serializedBuffer.readLong());
}
Also used : MultipartReplyMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage) MultipartReplyTableBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.MultipartReplyTableBuilder) MultipartReplyMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder) MultipartRequestFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags) ByteBuf(io.netty.buffer.ByteBuf) MultipartReplyTableCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableCaseBuilder) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)71 BigInteger (java.math.BigInteger)63 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)51 Test (org.junit.Test)38 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)27 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)27 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)26 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)25 List (java.util.List)25 Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction)25 Table (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table)23 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)22 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)22 FlowId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId)20 ByteBuf (io.netty.buffer.ByteBuf)18 FlowBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder)18 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)17 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)17 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)17 FlowKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey)17