Search in sources :

Example 11 with FlowAndStatisticsMapList

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowAndStatisticsMapList in project openflowplugin by opendaylight.

the class MultipartReplyMessageDeserializerTest method deserialize.

@Test
public void deserialize() throws Exception {
    ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    buffer.writeByte(TYPE);
    buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    buffer.writeInt(XID);
    buffer.writeShort(MULTIPART_TYPE);
    buffer.writeShort(REQ_MORE);
    buffer.writeZero(PADDING_IN_MULTIPART_REPLY_HEADER);
    buffer.writeShort(ITEM_LENGTH);
    buffer.writeByte(TABLE_ID);
    buffer.writeZero(PADDING_IN_FLOW_STATS_HEADER_01);
    buffer.writeInt(SECOND);
    buffer.writeInt(NANOSECOND);
    buffer.writeShort(PRIORITY);
    buffer.writeShort(IDLE_TIMEOUT);
    buffer.writeShort(HARD_TIMEOUT);
    buffer.writeShort(ByteBufUtils.fillBitMask(0, FLAGS.isSENDFLOWREM(), FLAGS.isCHECKOVERLAP(), FLAGS.isRESETCOUNTS(), FLAGS.isNOPKTCOUNTS(), FLAGS.isNOBYTCOUNTS()));
    buffer.writeZero(PADDING_IN_FLOW_STATS_HEADER_02);
    buffer.writeLong(COOKIE);
    buffer.writeLong(PACKET_COUNT);
    buffer.writeLong(BYTE_COUNT);
    // Match header
    int matchStartIndex = buffer.writerIndex();
    buffer.writeShort(OXM_MATCH_TYPE_CODE);
    int matchLengthIndex = buffer.writerIndex();
    buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    // MplsLabel match
    buffer.writeShort(OxmMatchConstants.OPENFLOW_BASIC_CLASS);
    buffer.writeByte(OxmMatchConstants.MPLS_LABEL << 1);
    buffer.writeByte(EncodeConstants.SIZE_OF_INT_IN_BYTES);
    buffer.writeInt(MPLS_LABEL);
    // Match footer
    int matchLength = buffer.writerIndex() - matchStartIndex;
    buffer.setShort(matchLengthIndex, matchLength);
    int paddingRemainder = matchLength % EncodeConstants.PADDING;
    if (paddingRemainder != 0) {
        buffer.writeZero(EncodeConstants.PADDING - paddingRemainder);
    }
    // Instruction POP PBB header
    int instructionStartIndex = buffer.writerIndex();
    buffer.writeShort(InstructionConstants.APPLY_ACTIONS_TYPE);
    int instructionLengthIndex = buffer.writerIndex();
    buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    buffer.writeZero(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
    // POP PBB action
    buffer.writeShort(ActionConstants.POP_PBB_CODE);
    buffer.writeShort(ActionConstants.GENERAL_ACTION_LENGTH);
    buffer.writeZero(ActionConstants.PADDING_IN_ACTION_HEADER);
    // Count total length of instruction
    buffer.setShort(instructionLengthIndex, buffer.writerIndex() - instructionStartIndex);
    // Deserialize and check everything
    final MultipartReply message = (MultipartReply) getFactory().deserialize(buffer, EncodeConstants.OF13_VERSION_ID);
    final MultipartReplyFlowStats reply = (MultipartReplyFlowStats) message.getMultipartReplyBody();
    assertEquals(XID, message.getXid().intValue());
    final FlowAndStatisticsMapList flowAndStatisticsMapList = reply.getFlowAndStatisticsMapList().get(0);
    assertEquals(TABLE_ID, flowAndStatisticsMapList.getTableId().shortValue());
    assertEquals(SECOND, flowAndStatisticsMapList.getDuration().getSecond().getValue().intValue());
    assertEquals(NANOSECOND, flowAndStatisticsMapList.getDuration().getNanosecond().getValue().intValue());
    assertEquals(PRIORITY, flowAndStatisticsMapList.getPriority().intValue());
    assertEquals(IDLE_TIMEOUT, flowAndStatisticsMapList.getIdleTimeout().intValue());
    assertEquals(HARD_TIMEOUT, flowAndStatisticsMapList.getHardTimeout().intValue());
    assertTrue(flowAndStatisticsMapList.getFlags().equals(FLAGS));
    assertEquals(COOKIE, flowAndStatisticsMapList.getCookie().getValue().longValue());
    assertEquals(BYTE_COUNT, flowAndStatisticsMapList.getByteCount().getValue().longValue());
    assertEquals(PACKET_COUNT, flowAndStatisticsMapList.getPacketCount().getValue().longValue());
    assertEquals(1, flowAndStatisticsMapList.getInstructions().getInstruction().size());
    final Instruction instruction = flowAndStatisticsMapList.getInstructions().getInstruction().get(0).getInstruction();
    assertEquals(ApplyActionsCase.class, instruction.getImplementedInterface());
    final ApplyActionsCase applyActions = ApplyActionsCase.class.cast(instruction);
    assertEquals(1, applyActions.getApplyActions().getAction().size());
    assertEquals(PopPbbActionCase.class, applyActions.getApplyActions().getAction().get(0).getAction().getImplementedInterface());
}
Also used : MultipartReplyFlowStats(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.multipart.reply.multipart.reply.body.MultipartReplyFlowStats) MultipartReply(org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReply) FlowAndStatisticsMapList(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList) ByteBuf(io.netty.buffer.ByteBuf) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction) ApplyActionsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase) Test(org.junit.Test) AbstractDeserializerTest(org.opendaylight.openflowplugin.impl.protocol.deserialization.AbstractDeserializerTest)

Example 12 with FlowAndStatisticsMapList

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowAndStatisticsMapList in project openflowplugin by opendaylight.

the class AbstractFlowDirectStatisticsService method generateFlowId.

/**
 * Get flow ID from #{@link org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry} or
 * create alien ID.
 * @param flowStatistics flow statistics
 * @return generated flow ID
 */
protected FlowId generateFlowId(FlowAndStatisticsMapList flowStatistics) {
    final FlowStatisticsDataBuilder flowStatisticsDataBld = new FlowStatisticsDataBuilder().setFlowStatistics(new FlowStatisticsBuilder(flowStatistics).build());
    final FlowBuilder flowBuilder = new FlowBuilder(flowStatistics).addAugmentation(FlowStatisticsData.class, flowStatisticsDataBld.build());
    final FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(getVersion(), flowBuilder.build());
    getDeviceRegistry().getDeviceFlowRegistry().store(flowRegistryKey);
    return getDeviceRegistry().getDeviceFlowRegistry().retrieveDescriptor(flowRegistryKey).getFlowId();
}
Also used : FlowStatisticsDataBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsDataBuilder) FlowStatisticsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.statistics.FlowStatisticsBuilder) FlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder) FlowRegistryKey(org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey)

Example 13 with FlowAndStatisticsMapList

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowAndStatisticsMapList in project openflowplugin by opendaylight.

the class FlowDirectStatisticsServiceTest method testStoreStatistics.

@Override
public void testStoreStatistics() throws Exception {
    final FlowAndStatisticsMapList stat = mock(FlowAndStatisticsMapList.class);
    when(stat.getTableId()).thenReturn(TABLE_NO);
    when(stat.getMatch()).thenReturn(new MatchBuilder().build());
    final List<FlowAndStatisticsMapList> stats = Collections.singletonList(stat);
    final GetFlowStatisticsOutput output = mock(GetFlowStatisticsOutput.class);
    when(output.getFlowAndStatisticsMapList()).thenReturn(stats);
    multipartWriterProvider.lookup(MultipartType.OFPMPFLOW).get().write(output, true);
    verify(deviceContext).writeToTransactionWithParentsSlow(eq(LogicalDatastoreType.OPERATIONAL), any(), any());
}
Also used : FlowAndStatisticsMapList(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList) GetFlowStatisticsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)

Example 14 with FlowAndStatisticsMapList

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowAndStatisticsMapList in project openflowplugin by opendaylight.

the class FlowRegistryKeyFactoryTest method testEquals.

@Test
public void testEquals() throws Exception {
    FlowsStatisticsUpdate flowStats = FLOWS_STATISTICS_UPDATE_BUILDER.build();
    HashSet<FlowRegistryKey> flowRegistryKeys = new HashSet<>();
    for (FlowAndStatisticsMapList item : flowStats.getFlowAndStatisticsMapList()) {
        final FlowRegistryKey key1 = FlowRegistryKeyFactory.create(deviceInfo.getVersion(), item);
        final FlowRegistryKey key2 = FlowRegistryKeyFactory.create(deviceInfo.getVersion(), item);
        flowRegistryKeys.add(key1);
        flowRegistryKeys.add(key1);
        flowRegistryKeys.add(key2);
    }
    assertEquals(3, flowRegistryKeys.size());
}
Also used : FlowsStatisticsUpdate(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate) FlowRegistryKey(org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey) FlowAndStatisticsMapList(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 15 with FlowAndStatisticsMapList

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowAndStatisticsMapList in project openflowplugin by opendaylight.

the class FlowRegistryKeyFactoryTest method testEqualsNegative.

@Test
public void testEqualsNegative() throws Exception {
    final FlowAndStatisticsMapList flowStatisticsMapList1 = TestFlowHelper.createFlowAndStatisticsMapListBuilder(1).build();
    final FlowRegistryKey key1 = FlowRegistryKeyFactory.create(deviceInfo.getVersion(), flowStatisticsMapList1);
    FlowRegistryKey key2;
    FlowAndStatisticsMapListBuilder flowStatisticsMapListBld2;
    // different priority
    flowStatisticsMapListBld2 = new FlowAndStatisticsMapListBuilder(flowStatisticsMapList1);
    flowStatisticsMapListBld2.setPriority(flowStatisticsMapListBld2.getPriority() + 1);
    key2 = FlowRegistryKeyFactory.create(deviceInfo.getVersion(), flowStatisticsMapListBld2.build());
    Assert.assertFalse(key1.equals(key2));
    // different match
    flowStatisticsMapListBld2 = new FlowAndStatisticsMapListBuilder(flowStatisticsMapList1);
    flowStatisticsMapListBld2.setMatch(new MatchBuilder().build());
    key2 = FlowRegistryKeyFactory.create(deviceInfo.getVersion(), flowStatisticsMapListBld2.build());
    Assert.assertFalse(key1.equals(key2));
    // different tableId
    flowStatisticsMapListBld2 = new FlowAndStatisticsMapListBuilder(flowStatisticsMapList1);
    flowStatisticsMapListBld2.setTableId((short) (flowStatisticsMapListBld2.getTableId() + 1));
    key2 = FlowRegistryKeyFactory.create(deviceInfo.getVersion(), flowStatisticsMapListBld2.build());
    Assert.assertFalse(key1.equals(key2));
    Assert.assertFalse(key1.equals(null));
}
Also used : FlowAndStatisticsMapListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListBuilder) FlowRegistryKey(org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey) FlowAndStatisticsMapList(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) Ipv4MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder) Test(org.junit.Test)

Aggregations

FlowAndStatisticsMapList (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList)19 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 FlowRegistryKey (org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey)6 GetFlowStatisticsOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput)5 FlowAndStatisticsMapListBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListBuilder)5 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)5 List (java.util.List)4 ByteBuf (io.netty.buffer.ByteBuf)3 BigInteger (java.math.BigInteger)3 MultipartReplyFlowCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase)3 MultipartReplyFlow (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlow)3 Counter32 (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32)2 Counter64 (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64)2 GetFlowStatisticsOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutputBuilder)2 FlowId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId)2 FlowBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder)2 FlowStatisticsDataBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsDataBuilder)2 FlowStatisticsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.statistics.FlowStatisticsBuilder)2 MultipartReplyFlowStats (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.multipart.reply.multipart.reply.body.MultipartReplyFlowStats)2