use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStatsBuilder 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.multipart.reply.flow._case.multipart.reply.flow.FlowStatsBuilder in project openflowplugin by opendaylight.
the class MultipartReplyMessageFactoryTest method createFlowStats.
private static List<FlowStats> createFlowStats() {
FlowStatsBuilder builder = new FlowStatsBuilder();
builder.setTableId((short) 1);
builder.setDurationSec(1L);
builder.setDurationNsec(1L);
builder.setPriority(1);
builder.setIdleTimeout(1);
builder.setHardTimeout(1);
builder.setCookie(BigInteger.valueOf(1234L));
builder.setPacketCount(BigInteger.valueOf(1234L));
builder.setByteCount(BigInteger.valueOf(1234L));
MatchBuilder matchBuilder = new MatchBuilder();
matchBuilder.setType(OxmMatchType.class);
final List<MatchEntry> entries = new ArrayList<>();
MatchEntryBuilder entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(InPhyPort.class);
entriesBuilder.setHasMask(false);
InPhyPortCaseBuilder inPhyPortCaseBuilder = new InPhyPortCaseBuilder();
InPhyPortBuilder inPhyPortBuilder = new InPhyPortBuilder();
inPhyPortBuilder.setPortNumber(new PortNumber(42L));
inPhyPortCaseBuilder.setInPhyPort(inPhyPortBuilder.build());
entriesBuilder.setMatchEntryValue(inPhyPortCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(IpEcn.class);
entriesBuilder.setHasMask(false);
IpEcnCaseBuilder ipEcnCaseBuilder = new IpEcnCaseBuilder();
IpEcnBuilder ipEcnBuilder = new IpEcnBuilder();
ipEcnBuilder.setEcn((short) 4);
ipEcnCaseBuilder.setIpEcn(ipEcnBuilder.build());
entriesBuilder.setMatchEntryValue(ipEcnCaseBuilder.build());
entries.add(entriesBuilder.build());
matchBuilder.setMatchEntry(entries);
builder.setMatch(matchBuilder.build());
final List<Instruction> instructions = new ArrayList<>();
// Goto_table instruction
InstructionBuilder builderInstruction = new InstructionBuilder();
GotoTableCaseBuilder gotoCaseBuilder = new GotoTableCaseBuilder();
GotoTableBuilder instructionBuilder = new GotoTableBuilder();
instructionBuilder.setTableId((short) 5);
gotoCaseBuilder.setGotoTable(instructionBuilder.build());
builderInstruction.setInstructionChoice(gotoCaseBuilder.build());
instructions.add(builderInstruction.build());
// Write_metadata instruction
builderInstruction = new InstructionBuilder();
WriteMetadataCaseBuilder metadataCaseBuilder = new WriteMetadataCaseBuilder();
WriteMetadataBuilder metadataBuilder = new WriteMetadataBuilder();
metadataBuilder.setMetadata(ByteBufUtils.hexStringToBytes("00 01 02 03 04 05 06 07"));
metadataBuilder.setMetadataMask(ByteBufUtils.hexStringToBytes("07 06 05 04 03 02 01 00"));
metadataCaseBuilder.setWriteMetadata(metadataBuilder.build());
builderInstruction.setInstructionChoice(metadataCaseBuilder.build());
instructions.add(builderInstruction.build());
// Clear_actions instruction
builderInstruction = new InstructionBuilder();
builderInstruction.setInstructionChoice(new ClearActionsCaseBuilder().build());
instructions.add(builderInstruction.build());
// Meter instruction
builderInstruction = new InstructionBuilder();
MeterCaseBuilder meterCaseBuilder = new MeterCaseBuilder();
MeterBuilder meterBuilder = new MeterBuilder();
meterBuilder.setMeterId(42L);
meterCaseBuilder.setMeter(meterBuilder.build());
builderInstruction.setInstructionChoice(meterCaseBuilder.build());
instructions.add(builderInstruction.build());
// Write_actions instruction
builderInstruction = new InstructionBuilder();
final WriteActionsCaseBuilder writeActionsCaseBuilder = new WriteActionsCaseBuilder();
final WriteActionsBuilder writeActionsBuilder = new WriteActionsBuilder();
OutputActionCaseBuilder caseBuilder = new OutputActionCaseBuilder();
OutputActionBuilder outputBuilder = new OutputActionBuilder();
outputBuilder.setPort(new PortNumber(45L));
outputBuilder.setMaxLength(55);
caseBuilder.setOutputAction(outputBuilder.build());
ActionBuilder actionBuilder = new ActionBuilder();
actionBuilder.setActionChoice(caseBuilder.build());
List<Action> actions = new ArrayList<>();
actions.add(actionBuilder.build());
actionBuilder = new ActionBuilder();
SetNwTtlCaseBuilder ttlCaseBuilder = new SetNwTtlCaseBuilder();
SetNwTtlActionBuilder ttlActionBuilder = new SetNwTtlActionBuilder();
ttlActionBuilder.setNwTtl((short) 64);
ttlCaseBuilder.setSetNwTtlAction(ttlActionBuilder.build());
actionBuilder.setActionChoice(ttlCaseBuilder.build());
actions.add(actionBuilder.build());
writeActionsBuilder.setAction(actions);
writeActionsCaseBuilder.setWriteActions(writeActionsBuilder.build());
builderInstruction.setInstructionChoice(writeActionsCaseBuilder.build());
instructions.add(builderInstruction.build());
// Apply_actions instruction
builderInstruction = new InstructionBuilder();
final ApplyActionsCaseBuilder applyActionsCaseBuilder = new ApplyActionsCaseBuilder();
final ApplyActionsBuilder applyActionsBuilder = new ApplyActionsBuilder();
actions = new ArrayList<>();
actionBuilder = new ActionBuilder();
PushVlanCaseBuilder vlanCaseBuilder = new PushVlanCaseBuilder();
PushVlanActionBuilder vlanBuilder = new PushVlanActionBuilder();
vlanBuilder.setEthertype(new EtherType(new EtherType(14)));
vlanCaseBuilder.setPushVlanAction(vlanBuilder.build());
actionBuilder.setActionChoice(vlanCaseBuilder.build());
actions.add(actionBuilder.build());
actionBuilder = new ActionBuilder();
actionBuilder.setActionChoice(new PopPbbCaseBuilder().build());
actions.add(actionBuilder.build());
applyActionsBuilder.setAction(actions);
applyActionsCaseBuilder.setApplyActions(applyActionsBuilder.build());
builderInstruction.setInstructionChoice(applyActionsCaseBuilder.build());
instructions.add(builderInstruction.build());
builder.setInstruction(instructions);
List<FlowStats> list = new ArrayList<>();
list.add(builder.build());
return list;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStatsBuilder in project openflowplugin by opendaylight.
the class OF10StatsReplyMessageFactoryTest method createFlowStats.
private static List<FlowStats> createFlowStats() {
FlowStatsBuilder builder = new FlowStatsBuilder();
builder.setTableId((short) 1);
MatchV10Builder matchBuilder = new MatchV10Builder();
matchBuilder.setWildcards(new FlowWildcardsV10(true, true, true, true, true, true, true, true, true, true));
matchBuilder.setNwSrcMask((short) 0);
matchBuilder.setNwDstMask((short) 0);
matchBuilder.setInPort(58);
matchBuilder.setDlSrc(new MacAddress("01:01:01:01:01:01"));
matchBuilder.setDlDst(new MacAddress("ff:ff:ff:ff:ff:ff"));
matchBuilder.setDlVlan(18);
matchBuilder.setDlVlanPcp((short) 5);
matchBuilder.setDlType(42);
matchBuilder.setNwTos((short) 4);
matchBuilder.setNwProto((short) 7);
matchBuilder.setNwSrc(new Ipv4Address("8.8.8.8"));
matchBuilder.setNwDst(new Ipv4Address("16.16.16.16"));
matchBuilder.setTpSrc(6653);
matchBuilder.setTpDst(6633);
builder.setMatchV10(matchBuilder.build());
builder.setDurationSec(1L);
builder.setDurationNsec(2L);
builder.setPriority(1);
builder.setIdleTimeout(1);
builder.setHardTimeout(1);
builder.setCookie(BigInteger.valueOf(1234L));
builder.setPacketCount(BigInteger.valueOf(1234L));
builder.setByteCount(BigInteger.valueOf(1234L));
final List<Action> actions = new ArrayList<>();
final ActionBuilder actionBuilder = new ActionBuilder();
OutputActionCaseBuilder caseBuilder = new OutputActionCaseBuilder();
OutputActionBuilder outputBuilder = new OutputActionBuilder();
outputBuilder.setPort(new PortNumber(42L));
outputBuilder.setMaxLength(50);
caseBuilder.setOutputAction(outputBuilder.build());
actionBuilder.setActionChoice(caseBuilder.build());
actions.add(actionBuilder.build());
builder.setAction(actions);
List<FlowStats> list = new ArrayList<>();
list.add(builder.build());
return list;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStatsBuilder 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();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStatsBuilder in project openflowplugin by opendaylight.
the class OF10StatsReplyMessageFactory method setFlow.
private MultipartReplyFlowCase setFlow(ByteBuf input) {
MultipartReplyFlowCaseBuilder caseBuilder = new MultipartReplyFlowCaseBuilder();
MultipartReplyFlowBuilder flowBuilder = new MultipartReplyFlowBuilder();
List<FlowStats> flowStatsList = new ArrayList<>();
while (input.readableBytes() > 0) {
FlowStatsBuilder flowStatsBuilder = new FlowStatsBuilder();
final int length = input.readUnsignedShort();
flowStatsBuilder.setTableId(input.readUnsignedByte());
input.skipBytes(PADDING_IN_FLOW_STATS_HEADER);
OFDeserializer<MatchV10> matchDeserializer = registry.getDeserializer(new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, MatchV10.class));
flowStatsBuilder.setMatchV10(matchDeserializer.deserialize(input));
flowStatsBuilder.setDurationSec(input.readUnsignedInt());
flowStatsBuilder.setDurationNsec(input.readUnsignedInt());
flowStatsBuilder.setPriority(input.readUnsignedShort());
flowStatsBuilder.setIdleTimeout(input.readUnsignedShort());
flowStatsBuilder.setHardTimeout(input.readUnsignedShort());
input.skipBytes(PADDING_IN_FLOW_STATS_HEADER_02);
byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(cookie);
flowStatsBuilder.setCookie(new BigInteger(1, cookie));
byte[] packetCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(packetCount);
flowStatsBuilder.setPacketCount(new BigInteger(1, packetCount));
byte[] byteCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(byteCount);
flowStatsBuilder.setByteCount(new BigInteger(1, byteCount));
CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF10_VERSION_ID);
List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF10_VERSION_ID, length - LENGTH_OF_FLOW_STATS, input, keyMaker, registry);
flowStatsBuilder.setAction(actions);
flowStatsList.add(flowStatsBuilder.build());
}
flowBuilder.setFlowStats(flowStatsList);
caseBuilder.setMultipartReplyFlow(flowBuilder.build());
return caseBuilder.build();
}
Aggregations