Search in sources :

Example 81 with TableId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId in project openflowplugin by opendaylight.

the class StatisticsGatheringUtilsTest method testDeleteAllKnownFlows.

@Test
public void testDeleteAllKnownFlows() throws Exception {
    final short tableId = 0;
    final InstanceIdentifier<FlowCapableNode> nodePath = deviceInfo.getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
    final TableBuilder tableDataBld = new TableBuilder();
    tableDataBld.setId(tableId);
    final FlowCapableNodeBuilder flowNodeBuilder = new FlowCapableNodeBuilder();
    flowNodeBuilder.setTable(Collections.singletonList(tableDataBld.build()));
    final Optional<FlowCapableNode> flowNodeOpt = Optional.of(flowNodeBuilder.build());
    final CheckedFuture<Optional<FlowCapableNode>, ReadFailedException> flowNodeFuture = Futures.immediateCheckedFuture(flowNodeOpt);
    when(readTx.read(LogicalDatastoreType.OPERATIONAL, nodePath)).thenReturn(flowNodeFuture);
    StatisticsGatheringUtils.deleteAllKnownFlows(deviceContext, deviceInfo.getNodeInstanceIdentifier().augmentation(FlowCapableNode.class), deviceFlowRegistry);
    verify(deviceContext).isTransactionsEnabled();
    verify(deviceContext).getReadTransaction();
    verify(deviceContext).writeToTransaction(Mockito.eq(LogicalDatastoreType.OPERATIONAL), Mockito.any(), Mockito.any());
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Optional(com.google.common.base.Optional) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) FlowCapableNodeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeBuilder) MultipartReplyTableBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.MultipartReplyTableBuilder) TableBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder) Test(org.junit.Test)

Example 82 with TableId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId in project openflowplugin by opendaylight.

the class PacketReceivedTranslatorTest method createPacketInMessage.

private static PacketInMessage createPacketInMessage(final byte[] data, final long port) {
    final PacketInReason reason = PacketInReason.OFPRACTION;
    MatchEntryBuilder matchEntryBuilder = assembleMatchEntryBld(port);
    MatchBuilder packetInMatchBld = new MatchBuilder().setMatchEntry(Lists.newArrayList(matchEntryBuilder.build()));
    return new PacketInMessageBuilder().setVersion(OFConstants.OFP_VERSION_1_0).setData(data).setReason(reason).setMatch(packetInMatchBld.build()).setVersion(OFConstants.OFP_VERSION_1_3).setCookie(BigInteger.ZERO).setTableId(new TableId(42L)).build();
}
Also used : TableId(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId) PacketInMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder) MatchEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder) PacketInReason(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder)

Example 83 with TableId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId in project openflowplugin by opendaylight.

the class AbstractCompatibleStatServiceTest method testHandleAndNotify.

@Test
public void testHandleAndNotify() throws Exception {
    GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input = new GetAggregateFlowStatisticsFromFlowTableForAllFlowsInputBuilder().setNode(createNodeRef("unitProt:123")).setTableId(new TableId((short) 1)).build();
    rpcResult = RpcResultBuilder.<Object>success(Collections.singletonList(new MultipartReplyMessageBuilder().setVersion(OFConstants.OFP_VERSION_1_3).setMultipartReplyBody(new MultipartReplyAggregateCaseBuilder().setMultipartReplyAggregate(new MultipartReplyAggregateBuilder().setByteCount(BigInteger.valueOf(11L)).setFlowCount(12L).setPacketCount(BigInteger.valueOf(13L)).build()).build()).build())).build();
    AggregatedFlowStatistics aggregatedStats = new AggregatedFlowStatisticsBuilder().setByteCount(new Counter64(BigInteger.valueOf(11L))).setFlowCount(new Counter32(12L)).setPacketCount(new Counter64(BigInteger.valueOf(13L))).build();
    Mockito.when(translator.translate(Matchers.any(MultipartReply.class), Matchers.eq(deviceInfo), Matchers.any())).thenReturn(aggregatedStats);
    ListenableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> resultFuture = service.handleAndNotify(input, notificationPublishService);
    Assert.assertTrue(resultFuture.isDone());
    final RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput> result = resultFuture.get();
    Assert.assertTrue(result.isSuccessful());
    Assert.assertEquals(MultipartType.OFPMPAGGREGATE, requestInput.getValue().getType());
    Mockito.verify(notificationPublishService, Mockito.timeout(500)).offerNotification(Matchers.any(AggregateFlowStatisticsUpdate.class));
}
Also used : TableId(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId) MultipartReply(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput) AggregatedFlowStatistics(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.get.aggregate.flow.statistics.from.flow.table._for.given.match.output.AggregatedFlowStatistics) AggregatedFlowStatisticsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.get.aggregate.flow.statistics.from.flow.table._for.given.match.output.AggregatedFlowStatisticsBuilder) MultipartReplyAggregateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.aggregate._case.MultipartReplyAggregateBuilder) Counter32(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32) Counter64(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64) GetAggregateFlowStatisticsFromFlowTableForAllFlowsInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInputBuilder) MultipartReplyMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder) AggregateFlowStatisticsUpdate(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsUpdate) GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput) MultipartReplyAggregateCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCaseBuilder) Test(org.junit.Test) AbstractStatsServiceTest(org.opendaylight.openflowplugin.impl.statistics.services.AbstractStatsServiceTest)

Example 84 with TableId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId in project openflowplugin by opendaylight.

the class FlowModInputMessageFactory method deserialize.

@Override
// FB doesn't recognize Objects.requireNonNull
@SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
public FlowModInput deserialize(ByteBuf rawMessage) {
    Objects.requireNonNull(registry);
    FlowModInputBuilder builder = new FlowModInputBuilder();
    builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
    builder.setXid(rawMessage.readUnsignedInt());
    byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    rawMessage.readBytes(cookie);
    builder.setCookie(new BigInteger(1, cookie));
    final byte[] cookieMask = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    rawMessage.readBytes(cookieMask);
    builder.setCookieMask(new BigInteger(1, cookieMask));
    builder.setTableId(new TableId((long) rawMessage.readUnsignedByte()));
    builder.setCommand(FlowModCommand.forValue(rawMessage.readUnsignedByte()));
    builder.setIdleTimeout(rawMessage.readUnsignedShort());
    builder.setHardTimeout(rawMessage.readUnsignedShort());
    builder.setPriority(rawMessage.readUnsignedShort());
    builder.setBufferId(rawMessage.readUnsignedInt());
    builder.setOutPort(new PortNumber(rawMessage.readUnsignedInt()));
    builder.setOutGroup(rawMessage.readUnsignedInt());
    builder.setFlags(createFlowModFlagsFromBitmap(rawMessage.readUnsignedShort()));
    rawMessage.skipBytes(PADDING);
    OFDeserializer<Match> matchDeserializer = registry.getDeserializer(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Match.class));
    builder.setMatch(matchDeserializer.deserialize(rawMessage));
    CodeKeyMaker keyMaker = CodeKeyMakerFactory.createInstructionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
    List<Instruction> instructions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, rawMessage.readableBytes(), rawMessage, keyMaker, registry);
    builder.setInstruction(instructions);
    return builder.build();
}
Also used : TableId(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId) MessageCodeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey) CodeKeyMaker(org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker) BigInteger(java.math.BigInteger) FlowModInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder) PortNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 85 with TableId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId in project openflowplugin by opendaylight.

the class MultipartReplyMessageFactoryTest method testMultipartReplyTableBody.

/**
 * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO.
 */
@Test
public void testMultipartReplyTableBody() {
    ByteBuf bb = BufferHelper.buildBuffer("00 03 00 01 00 00 00 00 " + // tableId
    "08 " + // pad
    "00 00 00 " + // activeCount
    "00 00 00 10 " + // lookupCount
    "FF 01 01 01 01 01 01 01 " + // matchedCount
    "AF 01 01 01 01 01 01 01");
    MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
    BufferHelper.checkHeaderV13(builtByFactory);
    Assert.assertEquals("Wrong type", 0x03, builtByFactory.getType().getIntValue());
    Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
    MultipartReplyTableCase messageCase = (MultipartReplyTableCase) builtByFactory.getMultipartReplyBody();
    MultipartReplyTable message = messageCase.getMultipartReplyTable();
    Assert.assertEquals("Wrong tableId", 8, message.getTableStats().get(0).getTableId().intValue());
    Assert.assertEquals("Wrong activeCount", 16, message.getTableStats().get(0).getActiveCount().longValue());
    Assert.assertEquals("Wrong lookupCount", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), message.getTableStats().get(0).getLookupCount());
    Assert.assertEquals("Wrong matchedCount", new BigInteger(1, new byte[] { (byte) 0xAF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), message.getTableStats().get(0).getMatchedCount());
}
Also used : MultipartReplyMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage) MultipartReplyTableCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableCase) MultipartReplyTable(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.MultipartReplyTable) BigInteger(java.math.BigInteger) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

BigInteger (java.math.BigInteger)38 Test (org.junit.Test)32 ArrayList (java.util.ArrayList)26 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)17 ByteBuf (io.netty.buffer.ByteBuf)16 FlowBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder)16 FlowId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId)15 FlowKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey)15 TableId (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId)14 TableId (org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId)14 Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction)13 FlowCookie (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie)12 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)12 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)9 FlowModFlags (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags)7 Optional (com.google.common.base.Optional)6 ExecutionException (java.util.concurrent.ExecutionException)5 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)5 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)5 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)5