use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList in project openflowplugin by opendaylight.
the class MultipartReplyTranslatorTest method testTranslateFlow.
@Test
public void testTranslateFlow() {
DeviceContext mockedDeviceContext = mock(DeviceContext.class);
MultipartReplyMessage multipartReplyMessage = prepareMocks(mockedDeviceContext, prepareMultipartReplyFlow(), MultipartType.OFPMPFLOW);
DataContainer result = MultipartReplyTranslatorUtil.translate(multipartReplyMessage, mockedDeviceContext.getDeviceInfo(), CONVERTOR_MANAGER, mockedDeviceContext.oook()).get();
DataContainer dataObject = validateOutput(result);
assertTrue(dataObject instanceof FlowAndStatisticsMapList);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.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());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList in project openflowplugin by opendaylight.
the class MultipartReplyFlowStatsDeserializer method deserialize.
@Override
public MultipartReplyBody deserialize(ByteBuf message) {
final MultipartReplyFlowStatsBuilder builder = new MultipartReplyFlowStatsBuilder();
final List<FlowAndStatisticsMapList> items = new ArrayList<>();
while (message.readableBytes() > 0) {
final FlowAndStatisticsMapListBuilder itemBuilder = new FlowAndStatisticsMapListBuilder();
final int itemLength = message.readUnsignedShort();
final ByteBuf itemMessage = message.readSlice(itemLength - EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
itemBuilder.setTableId(itemMessage.readUnsignedByte());
itemMessage.skipBytes(PADDING_IN_FLOW_STATS_HEADER_01);
itemBuilder.setDuration(new DurationBuilder().setSecond(new Counter32(itemMessage.readUnsignedInt())).setNanosecond(new Counter32(itemMessage.readUnsignedInt())).build()).setPriority(itemMessage.readUnsignedShort()).setIdleTimeout(itemMessage.readUnsignedShort()).setHardTimeout(itemMessage.readUnsignedShort()).setFlags(createFlowModFlagsFromBitmap(itemMessage.readUnsignedShort()));
itemMessage.skipBytes(PADDING_IN_FLOW_STATS_HEADER_02);
final byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
itemMessage.readBytes(cookie);
final byte[] packetCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
itemMessage.readBytes(packetCount);
final byte[] byteCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
itemMessage.readBytes(byteCount);
itemBuilder.setCookie(new FlowCookie(new BigInteger(1, cookie))).setCookieMask(new FlowCookie(OFConstants.DEFAULT_COOKIE_MASK)).setPacketCount(new Counter64(new BigInteger(1, packetCount))).setByteCount(new Counter64(new BigInteger(1, byteCount)));
final OFDeserializer<Match> matchDeserializer = Preconditions.checkNotNull(registry).getDeserializer(MATCH_KEY);
itemBuilder.setMatch(MatchUtil.transformMatch(matchDeserializer.deserialize(itemMessage), org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match.class));
final int length = itemMessage.readableBytes();
if (length > 0) {
final List<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction> instructions = new ArrayList<>();
final int startIndex = itemMessage.readerIndex();
int offset = 0;
while (itemMessage.readerIndex() - startIndex < length) {
instructions.add(new InstructionBuilder().setKey(new InstructionKey(offset)).setOrder(offset).setInstruction(InstructionUtil.readInstruction(EncodeConstants.OF13_VERSION_ID, itemMessage, registry)).build());
offset++;
}
itemBuilder.setInstructions(new InstructionsBuilder().setInstruction(instructions).build());
}
items.add(itemBuilder.build());
}
return builder.setFlowAndStatisticsMapList(items).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList in project openflowplugin by opendaylight.
the class FlowStatisticsToNotificationTransformer method transformToNotification.
/**
* Transform to notification.
*
* @param mpResult raw multipart response from device
* @param deviceInfo device state
* @param ofVersion device version
* @param emulatedTxId emulated transaction Id
* @param convertorExecutor convertor executor
* @return notification containing flow stats
*/
public static FlowsStatisticsUpdate transformToNotification(final List<MultipartReply> mpResult, final DeviceInfo deviceInfo, final OpenflowVersion ofVersion, final TransactionId emulatedTxId, final ConvertorExecutor convertorExecutor) {
final FlowStatsResponseConvertorData data = new FlowStatsResponseConvertorData(ofVersion.getVersion());
data.setDatapathId(deviceInfo.getDatapathId());
data.setMatchPath(MatchPath.FLOWS_STATISTICS_UPDATE_MATCH);
final FlowsStatisticsUpdateBuilder notification = new FlowsStatisticsUpdateBuilder();
final List<FlowAndStatisticsMapList> statsList = new ArrayList<>();
notification.setId(deviceInfo.getNodeId());
notification.setFlowAndStatisticsMapList(statsList);
notification.setMoreReplies(Boolean.FALSE);
notification.setTransactionId(emulatedTxId);
for (MultipartReply mpRawReply : mpResult) {
Preconditions.checkArgument(MultipartType.OFPMPFLOW.equals(mpRawReply.getType()));
MultipartReplyFlowCase caseBody = (MultipartReplyFlowCase) mpRawReply.getMultipartReplyBody();
MultipartReplyFlow replyBody = caseBody.getMultipartReplyFlow();
final Optional<List<FlowAndStatisticsMapList>> outStatsItem = convertorExecutor.convert(replyBody.getFlowStats(), data);
outStatsItem.ifPresent(statsList::addAll);
}
return notification.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList in project openflowplugin by opendaylight.
the class FlowDirectStatisticsService method buildReply.
@Override
protected GetFlowStatisticsOutput buildReply(List<MultipartReply> input, boolean success) {
final List<FlowAndStatisticsMapList> statsList = new ArrayList<>();
if (success) {
for (final MultipartReply mpReply : input) {
final MultipartReplyFlowCase caseBody = (MultipartReplyFlowCase) mpReply.getMultipartReplyBody();
final MultipartReplyFlow replyBody = caseBody.getMultipartReplyFlow();
final Optional<List<FlowAndStatisticsMapList>> statsListPart = getConvertorExecutor().convert(replyBody.getFlowStats(), data);
statsListPart.ifPresent(flowAndStatisticsMapLists -> {
for (final FlowAndStatisticsMapList part : flowAndStatisticsMapLists) {
final FlowId flowId = new FlowId(generateFlowId(part).getValue());
statsList.add(new FlowAndStatisticsMapListBuilder(part).setKey(new FlowAndStatisticsMapListKey(flowId)).setFlowId(flowId).build());
}
});
}
}
return new GetFlowStatisticsOutputBuilder().setFlowAndStatisticsMapList(statsList).build();
}
Aggregations