use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats in project openflowplugin by opendaylight.
the class DeviceFlowRegistryImplTest method setUp.
@Before
public void setUp() throws Exception {
nodeInstanceIdentifier = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(new NodeId(NODE_ID)));
when(dataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction);
deviceFlowRegistry = new DeviceFlowRegistryImpl(OFConstants.OFP_VERSION_1_3, dataBroker, nodeInstanceIdentifier);
final FlowAndStatisticsMapList flowStats = TestFlowHelper.createFlowAndStatisticsMapListBuilder(1).build();
key = FlowRegistryKeyFactory.create(OFConstants.OFP_VERSION_1_3, flowStats);
descriptor = FlowDescriptorFactory.create(key.getTableId(), new FlowId("ut:1"));
Assert.assertEquals(0, deviceFlowRegistry.getAllFlowDescriptors().size());
deviceFlowRegistry.storeDescriptor(key, descriptor);
Assert.assertEquals(1, deviceFlowRegistry.getAllFlowDescriptors().size());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats in project openflowplugin by opendaylight.
the class FlowRegistryKeyFactoryTest method testGetHash.
@Test
public void testGetHash() throws Exception {
FlowsStatisticsUpdate flowStats = FLOWS_STATISTICS_UPDATE_BUILDER.build();
for (FlowAndStatisticsMapList item : flowStats.getFlowAndStatisticsMapList()) {
FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(deviceInfo.getVersion(), item);
FlowRegistryKey lastHash = null;
if (null != lastHash) {
assertNotEquals(lastHash, flowRegistryKey);
} else {
lastHash = flowRegistryKey;
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats 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.FlowStats 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.multipart.reply.flow._case.multipart.reply.flow.FlowStats 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;
}
Aggregations