use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase in project openflowplugin by opendaylight.
the class FlowDirectStatisticsServiceTest method testBuildReply.
@Override
public void testBuildReply() throws Exception {
final MultipartReply reply = mock(MultipartReply.class);
final MultipartReplyFlowCase flowCase = mock(MultipartReplyFlowCase.class);
final MultipartReplyFlow flow = mock(MultipartReplyFlow.class);
final FlowStats flowStat = new FlowStatsBuilder().setDurationSec(1L).setDurationNsec(1L).setTableId(TABLE_NO).setByteCount(BigInteger.ONE).setPacketCount(BigInteger.ONE).setFlags(mock(FlowModFlags.class)).setMatch(new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder().setMatchEntry(Collections.emptyList()).build()).build();
final List<FlowStats> flowStats = Collections.singletonList(flowStat);
final List<MultipartReply> input = Collections.singletonList(reply);
when(flow.getFlowStats()).thenReturn(flowStats);
when(flowCase.getMultipartReplyFlow()).thenReturn(flow);
when(reply.getMultipartReplyBody()).thenReturn(flowCase);
final GetFlowStatisticsOutput output = service.buildReply(input, true);
assertTrue(output.getFlowAndStatisticsMapList().size() > 0);
final FlowAndStatisticsMap stats = output.getFlowAndStatisticsMapList().get(0);
assertEquals(stats.getTableId(), TABLE_NO);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase in project openflowplugin by opendaylight.
the class MultipartReplyTranslatorUtil method translateFlow.
private static MultipartReplyFlowStats translateFlow(final MultipartReply msg, final VersionDatapathIdConvertorData data, final ConvertorExecutor convertorExecutor) {
FlowStatsResponseConvertorData flowData = new FlowStatsResponseConvertorData(data.getVersion());
flowData.setDatapathId(data.getDatapathId());
flowData.setMatchPath(MatchPath.FLOWS_STATISTICS_UPDATE_MATCH);
MultipartReplyFlowStatsBuilder message = new MultipartReplyFlowStatsBuilder();
MultipartReplyFlowCase caseBody = (MultipartReplyFlowCase) msg.getMultipartReplyBody();
MultipartReplyFlow replyBody = caseBody.getMultipartReplyFlow();
final Optional<List<FlowAndStatisticsMapList>> flowAndStatisticsMapLists = convertorExecutor.convert(replyBody.getFlowStats(), flowData);
message.setFlowAndStatisticsMapList(flowAndStatisticsMapLists.orElse(Collections.emptyList()));
return message.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase in project openflowplugin by opendaylight.
the class MultipartReplyMessageFactory method serializeFlowBody.
private void serializeFlowBody(final MultipartReplyBody body, final ByteBuf outBuffer, final MultipartReplyMessage message) {
MultipartReplyFlowCase flowCase = (MultipartReplyFlowCase) body;
MultipartReplyFlow flow = flowCase.getMultipartReplyFlow();
for (FlowStats flowStats : flow.getFlowStats()) {
ByteBuf flowStatsBuff = UnpooledByteBufAllocator.DEFAULT.buffer();
flowStatsBuff.writeShort(EncodeConstants.EMPTY_LENGTH);
flowStatsBuff.writeByte((byte) flowStats.getTableId().longValue());
flowStatsBuff.writeZero(FLOW_STATS_PADDING_1);
flowStatsBuff.writeInt(flowStats.getDurationSec().intValue());
flowStatsBuff.writeInt(flowStats.getDurationNsec().intValue());
flowStatsBuff.writeShort(flowStats.getPriority());
flowStatsBuff.writeShort(flowStats.getIdleTimeout());
flowStatsBuff.writeShort(flowStats.getHardTimeout());
flowStatsBuff.writeZero(FLOW_STATS_PADDING_2);
flowStatsBuff.writeLong(flowStats.getCookie().longValue());
flowStatsBuff.writeLong(flowStats.getPacketCount().longValue());
flowStatsBuff.writeLong(flowStats.getByteCount().longValue());
OFSerializer<Match> matchSerializer = registry.<Match, OFSerializer<Match>>getSerializer(new MessageTypeKey<>(message.getVersion(), Match.class));
matchSerializer.serialize(flowStats.getMatch(), flowStatsBuff);
ListSerializer.serializeList(flowStats.getInstruction(), TypeKeyMakerFactory.createInstructionKeyMaker(message.getVersion()), registry, flowStatsBuff);
flowStatsBuff.setShort(FLOW_STATS_LENGTH_INDEX, flowStatsBuff.readableBytes());
outBuffer.writeBytes(flowStatsBuff);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase 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);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase in project openflowplugin by opendaylight.
the class MultipartReplyMessageFactory method setFlow.
private MultipartReplyFlowCase setFlow(final ByteBuf input) {
MultipartReplyFlowCaseBuilder caseBuilder = new MultipartReplyFlowCaseBuilder();
MultipartReplyFlowBuilder flowBuilder = new MultipartReplyFlowBuilder();
List<FlowStats> flowStatsList = new ArrayList<>();
while (input.readableBytes() > 0) {
FlowStatsBuilder flowStatsBuilder = new FlowStatsBuilder();
int flowRecordLength = input.readUnsignedShort();
ByteBuf subInput = input.readSlice(flowRecordLength - EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
flowStatsBuilder.setTableId(subInput.readUnsignedByte());
subInput.skipBytes(PADDING_IN_FLOW_STATS_HEADER_01);
flowStatsBuilder.setDurationSec(subInput.readUnsignedInt());
flowStatsBuilder.setDurationNsec(subInput.readUnsignedInt());
flowStatsBuilder.setPriority(subInput.readUnsignedShort());
flowStatsBuilder.setIdleTimeout(subInput.readUnsignedShort());
flowStatsBuilder.setHardTimeout(subInput.readUnsignedShort());
flowStatsBuilder.setFlags(createFlowModFlagsFromBitmap(subInput.readUnsignedShort()));
subInput.skipBytes(PADDING_IN_FLOW_STATS_HEADER_02);
byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
subInput.readBytes(cookie);
flowStatsBuilder.setCookie(new BigInteger(1, cookie));
byte[] packetCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
subInput.readBytes(packetCount);
flowStatsBuilder.setPacketCount(new BigInteger(1, packetCount));
byte[] byteCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
subInput.readBytes(byteCount);
flowStatsBuilder.setByteCount(new BigInteger(1, byteCount));
OFDeserializer<Match> matchDeserializer = registry.getDeserializer(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Match.class));
flowStatsBuilder.setMatch(matchDeserializer.deserialize(subInput));
CodeKeyMaker keyMaker = CodeKeyMakerFactory.createInstructionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
List<Instruction> instructions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, subInput.readableBytes(), subInput, keyMaker, registry);
flowStatsBuilder.setInstruction(instructions);
flowStatsList.add(flowStatsBuilder.build());
}
flowBuilder.setFlowStats(flowStatsList);
caseBuilder.setMultipartReplyFlow(flowBuilder.build());
return caseBuilder.build();
}
Aggregations