use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter in project openflowplugin by opendaylight.
the class OpenflowpluginMeterTestCommandProvider method writeMeter.
private void writeMeter(final CommandInterpreter ci, Meter meter, Meter meter1) {
ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
InstanceIdentifier<Meter> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, testNode.getKey()).augmentation(FlowCapableNode.class).child(Meter.class, new MeterKey(meter.getMeterId()));
modification.merge(LogicalDatastoreType.CONFIGURATION, nodeToInstanceId(testNode), testNode, true);
modification.merge(LogicalDatastoreType.CONFIGURATION, path1, meter, true);
InstanceIdentifier<Meter> path2 = InstanceIdentifier.create(Nodes.class).child(Node.class, testNode.getKey()).augmentation(FlowCapableNode.class).child(Meter.class, new MeterKey(meter1.getMeterId()));
modification.merge(LogicalDatastoreType.CONFIGURATION, nodeToInstanceId(testNode), testNode, true);
modification.merge(LogicalDatastoreType.CONFIGURATION, path2, meter1, true);
CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
Futures.addCallback(commitFuture, new FutureCallback<Void>() {
@Override
public void onSuccess(Void notUsed) {
ci.println("Status of Group Data Loaded Transaction: success.");
}
@Override
public void onFailure(Throwable throwable) {
ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter in project openflowplugin by opendaylight.
the class OpenflowpluginStatsTestCommandProvider method _meterStats.
public void _meterStats(CommandInterpreter ci) {
int meterCount = 0;
int meterStatsCount = 0;
NodeMeterStatistics data = null;
List<Node> nodes = getNodes();
for (Node node2 : nodes) {
NodeKey nodeKey = node2.getKey();
InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class);
ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
FlowCapableNode node = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodeRef);
if (node != null) {
if (node.getMeter() != null) {
List<Meter> meters = node.getMeter();
for (Meter meter2 : meters) {
meterCount++;
MeterKey meterKey = meter2.getKey();
InstanceIdentifier<Meter> meterRef = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class).child(Meter.class, meterKey);
Meter meter = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, meterRef);
if (meter != null) {
data = meter.getAugmentation(NodeMeterStatistics.class);
if (null != data) {
meterStatsCount++;
}
}
}
}
}
}
if (meterCount == meterStatsCount) {
LOG.debug("---------------------------meterStats - Success-------------------------------------");
} else {
LOG.debug("----------------------------meterStats - Failed-------------------------------------");
LOG.debug("System fetchs stats data in 50 seconds interval, so pls wait and try again.");
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter in project openflowplugin by opendaylight.
the class OF13InstructionsSerializerTest method test.
/**
* Testing instructions translation.
*/
@Test
public void test() {
final List<Instruction> instructions = new ArrayList<>();
// Goto_table instruction
InstructionBuilder builder = new InstructionBuilder();
GotoTableCaseBuilder gotoCaseBuilder = new GotoTableCaseBuilder();
GotoTableBuilder instructionBuilder = new GotoTableBuilder();
instructionBuilder.setTableId((short) 5);
gotoCaseBuilder.setGotoTable(instructionBuilder.build());
builder.setInstructionChoice(gotoCaseBuilder.build());
instructions.add(builder.build());
// Write_metadata instruction
builder = 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());
builder.setInstructionChoice(metadataCaseBuilder.build());
instructions.add(builder.build());
// Clear_actions instruction
builder = new InstructionBuilder();
builder.setInstructionChoice(new ClearActionsCaseBuilder().build());
instructions.add(builder.build());
// Meter instruction
builder = new InstructionBuilder();
MeterCaseBuilder meterCaseBuilder = new MeterCaseBuilder();
MeterBuilder meterBuilder = new MeterBuilder();
meterBuilder.setMeterId(42L);
meterCaseBuilder.setMeter(meterBuilder.build());
builder.setInstructionChoice(meterCaseBuilder.build());
instructions.add(builder.build());
// Write_actions instruction
builder = 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());
builder.setInstructionChoice(writeActionsCaseBuilder.build());
instructions.add(builder.build());
// Apply_actions instruction
builder = 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());
builder.setInstructionChoice(applyActionsCaseBuilder.build());
instructions.add(builder.build());
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
ListSerializer.serializeList(instructions, TypeKeyMakerFactory.createInstructionKeyMaker(EncodeConstants.OF13_VERSION_ID), registry, out);
Assert.assertEquals("Wrong instruction type", 1, out.readUnsignedShort());
Assert.assertEquals("Wrong instruction length", 8, out.readUnsignedShort());
Assert.assertEquals("Wrong instruction table-id", 5, out.readUnsignedByte());
out.skipBytes(3);
Assert.assertEquals("Wrong instruction type", 2, out.readUnsignedShort());
Assert.assertEquals("Wrong instruction length", 24, out.readUnsignedShort());
out.skipBytes(4);
byte[] actual = new byte[8];
out.readBytes(actual);
Assert.assertEquals("Wrong instruction metadata", "00 01 02 03 04 05 06 07", ByteBufUtils.bytesToHexString(actual));
actual = new byte[8];
out.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, out.readUnsignedShort());
Assert.assertEquals("Wrong instruction length", 8, out.readUnsignedShort());
out.skipBytes(4);
Assert.assertEquals("Wrong instruction type", 6, out.readUnsignedShort());
Assert.assertEquals("Wrong instruction length", 8, out.readUnsignedShort());
Assert.assertEquals("Wrong instruction meter-id", 42, out.readUnsignedInt());
Assert.assertEquals("Wrong instruction type", 3, out.readUnsignedShort());
Assert.assertEquals("Wrong instruction length", 32, out.readUnsignedShort());
out.skipBytes(4);
Assert.assertEquals("Wrong action type", 0, out.readUnsignedShort());
Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort());
Assert.assertEquals("Wrong action type", 45, out.readUnsignedInt());
Assert.assertEquals("Wrong action type", 55, out.readUnsignedShort());
out.skipBytes(6);
Assert.assertEquals("Wrong action type", 23, out.readUnsignedShort());
Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
Assert.assertEquals("Wrong action type", 64, out.readUnsignedByte());
out.skipBytes(3);
Assert.assertEquals("Wrong instruction type", 4, out.readUnsignedShort());
Assert.assertEquals("Wrong instruction length", 24, out.readUnsignedShort());
out.skipBytes(4);
Assert.assertEquals("Wrong action type", 17, out.readUnsignedShort());
Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
Assert.assertEquals("Wrong action ethertype", 14, out.readUnsignedShort());
out.skipBytes(2);
Assert.assertEquals("Wrong action type", 27, out.readUnsignedShort());
Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
out.skipBytes(4);
Assert.assertTrue("Not all data were read", out.readableBytes() == 0);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter in project openflowplugin by opendaylight.
the class FlowConvertorTest method testInstructionsTranslation.
/**
* Tests {@link FlowConvertor#convert(Flow, VersionDatapathIdConvertorData)} }.
*/
@Test
public void testInstructionsTranslation() {
InstructionBuilder instructionBuilder = new InstructionBuilder();
GoToTableCaseBuilder goToCaseBuilder = new GoToTableCaseBuilder();
GoToTableBuilder goToBuilder = new GoToTableBuilder();
goToBuilder.setTableId((short) 1);
goToCaseBuilder.setGoToTable(goToBuilder.build());
instructionBuilder.setInstruction(goToCaseBuilder.build());
instructionBuilder.setOrder(0);
List<Instruction> instructions = new ArrayList<>();
instructions.add(instructionBuilder.build());
instructionBuilder = new InstructionBuilder();
WriteMetadataCaseBuilder metaCaseBuilder = new WriteMetadataCaseBuilder();
WriteMetadataBuilder metaBuilder = new WriteMetadataBuilder();
metaBuilder.setMetadata(new BigInteger("2"));
metaBuilder.setMetadataMask(new BigInteger("3"));
metaCaseBuilder.setWriteMetadata(metaBuilder.build());
instructionBuilder.setInstruction(metaCaseBuilder.build());
instructionBuilder.setOrder(1);
instructions.add(instructionBuilder.build());
instructionBuilder = new InstructionBuilder();
WriteActionsCaseBuilder writeCaseBuilder = new WriteActionsCaseBuilder();
WriteActionsBuilder writeBuilder = new WriteActionsBuilder();
List<Action> actions = new ArrayList<>();
writeBuilder.setAction(actions);
writeCaseBuilder.setWriteActions(writeBuilder.build());
instructionBuilder.setInstruction(writeCaseBuilder.build());
instructionBuilder.setOrder(2);
instructions.add(instructionBuilder.build());
instructionBuilder = new InstructionBuilder();
ApplyActionsCaseBuilder applyCaseBuilder = new ApplyActionsCaseBuilder();
ApplyActionsBuilder applyBuilder = new ApplyActionsBuilder();
actions = new ArrayList<>();
applyBuilder.setAction(actions);
applyCaseBuilder.setApplyActions(applyBuilder.build());
instructionBuilder.setInstruction(applyCaseBuilder.build());
instructionBuilder.setOrder(3);
instructions.add(instructionBuilder.build());
instructionBuilder = new InstructionBuilder();
ClearActionsCaseBuilder clearCaseBuilder = new ClearActionsCaseBuilder();
ClearActionsBuilder clearBuilder = new ClearActionsBuilder();
actions = new ArrayList<>();
clearBuilder.setAction(actions);
clearCaseBuilder.setClearActions(clearBuilder.build());
instructionBuilder.setInstruction(clearCaseBuilder.build());
instructionBuilder.setOrder(4);
instructions.add(instructionBuilder.build());
instructionBuilder = new InstructionBuilder();
MeterCaseBuilder meterCaseBuilder = new MeterCaseBuilder();
MeterBuilder meterBuilder = new MeterBuilder();
meterBuilder.setMeterId(new MeterId(5L));
meterCaseBuilder.setMeter(meterBuilder.build());
instructionBuilder.setInstruction(meterCaseBuilder.build());
instructionBuilder.setOrder(5);
instructions.add(instructionBuilder.build());
InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
instructionsBuilder.setInstruction(instructions);
AddFlowInputBuilder flowBuilder = new AddFlowInputBuilder();
flowBuilder.setInstructions(instructionsBuilder.build());
AddFlowInput flow = flowBuilder.build();
VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_0);
data.setDatapathId(new BigInteger("42"));
List<FlowModInputBuilder> flowMod = convert(flow, data);
Assert.assertEquals("Wrong version", 1, flowMod.get(0).getVersion().intValue());
Assert.assertEquals("Wrong command", FlowModCommand.OFPFCADD, flowMod.get(0).getCommand());
Assert.assertEquals("Wrong instructions size", 6, flowMod.get(0).getInstruction().size());
org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction instruction = flowMod.get(0).getInstruction().get(0);
Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".instruction.rev130731.instruction.grouping.instruction.choice.GotoTableCase", instruction.getInstructionChoice().getImplementedInterface().getName());
GotoTableCase gotoTableCase = (GotoTableCase) instruction.getInstructionChoice();
Assert.assertEquals("Wrong table id", 1, gotoTableCase.getGotoTable().getTableId().intValue());
instruction = flowMod.get(0).getInstruction().get(1);
Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".instruction.rev130731.instruction.grouping.instruction.choice.WriteMetadataCase", instruction.getInstructionChoice().getImplementedInterface().getName());
WriteMetadataCase writeMetadataCase = (WriteMetadataCase) instruction.getInstructionChoice();
Assert.assertArrayEquals("Wrong metadata", new byte[] { 0, 0, 0, 0, 0, 0, 0, 2 }, writeMetadataCase.getWriteMetadata().getMetadata());
Assert.assertArrayEquals("Wrong metadata mask", new byte[] { 0, 0, 0, 0, 0, 0, 0, 3 }, writeMetadataCase.getWriteMetadata().getMetadataMask());
instruction = flowMod.get(0).getInstruction().get(2);
Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".instruction.rev130731.instruction.grouping.instruction.choice.WriteActionsCase", instruction.getInstructionChoice().getImplementedInterface().getName());
WriteActionsCase writeActionsCase = (WriteActionsCase) instruction.getInstructionChoice();
Assert.assertEquals("Wrong actions size", 0, writeActionsCase.getWriteActions().getAction().size());
instruction = flowMod.get(0).getInstruction().get(3);
Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".instruction.rev130731.instruction.grouping.instruction.choice.ApplyActionsCase", instruction.getInstructionChoice().getImplementedInterface().getName());
ApplyActionsCase applyActionsCase = (ApplyActionsCase) instruction.getInstructionChoice();
Assert.assertEquals("Wrong actions size", 0, applyActionsCase.getApplyActions().getAction().size());
instruction = flowMod.get(0).getInstruction().get(4);
Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".instruction.rev130731.instruction.grouping.instruction.choice.ClearActionsCase", instruction.getInstructionChoice().getImplementedInterface().getName());
instruction = flowMod.get(0).getInstruction().get(5);
Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".instruction.rev130731.instruction.grouping.instruction.choice.MeterCase", instruction.getInstructionChoice().getImplementedInterface().getName());
MeterCase meterCase = (MeterCase) instruction.getInstructionChoice();
Assert.assertEquals("Wrong meter id", 5, meterCase.getMeter().getMeterId().intValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter in project openflowplugin by opendaylight.
the class MeterForwarder method removeWithResult.
@Override
public Future<RpcResult<RemoveMeterOutput>> removeWithResult(final InstanceIdentifier<Meter> identifier, final Meter removeDataObj, final InstanceIdentifier<FlowCapableNode> nodeIdent) {
final RemoveMeterInputBuilder builder = new RemoveMeterInputBuilder(removeDataObj);
builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class)));
builder.setMeterRef(new MeterRef(identifier));
builder.setTransactionUri(new Uri(provider.getNewTransactionId()));
return this.provider.getSalMeterService().removeMeter(builder.build());
}
Aggregations