use of org.openkilda.model.MeterId in project open-kilda by telstra.
the class OfInstructionsConverterTest method convertToRuleManagerInstructionsTest.
@Test
public void convertToRuleManagerInstructionsTest() {
OFFactory factory = new OFFactoryVer13();
List<OFInstruction> instructions = new ArrayList<>();
instructions.add(factory.instructions().gotoTable(TableId.of(1)));
instructions.add(factory.instructions().meter(2));
instructions.add(factory.instructions().writeMetadata(U64.of(123), U64.of(234)));
List<OFAction> actions = buildActions(factory);
instructions.add(factory.instructions().applyActions(actions));
Instructions actual = OfInstructionsConverter.INSTANCE.convertToRuleManagerInstructions(instructions);
assertEquals(OfTable.PRE_INGRESS, actual.getGoToTable());
assertEquals(new MeterId(2), actual.getGoToMeter());
assertEquals(new OfMetadata(123, 234), actual.getWriteMetadata());
assertEquals(12, actual.getApplyActions().size());
List<Action> expectedActions = buildActions();
assertTrue(actual.getApplyActions().containsAll(expectedActions));
}
use of org.openkilda.model.MeterId in project open-kilda by telstra.
the class MeterVerifyCommandTest method shouldVerifyInaccurateMeterBurst.
@Test
public void shouldVerifyInaccurateMeterBurst() throws Exception {
MeterConfig validConfig = new MeterConfig(new MeterId(1), (long) (100 / 1.05));
MeterVerifyCommand command1 = new MeterVerifyCommand(new MessageContext(), mapSwitchId(dpId), validConfig);
switchFeaturesSetup(sw, SwitchFeature.METERS, SwitchFeature.INACCURATE_METER);
SettableFuture<List<OFMeterConfigStatsReply>> statsReplyProxy = setupMeterConfigStatsReply();
// for command2
setupMeterConfigStatsReply();
replayAll();
CompletableFuture<MeterVerifyReport> result = command1.execute(commandProcessor);
// make one more command with altered config, to produce meter config flags/bands
MeterConfig invalidConfig = new MeterConfig(validConfig.getId(), validConfig.getBandwidth() + 1);
MeterVerifyCommand command2 = new MeterVerifyCommand(command1.getMessageContext(), command1.getSwitchId(), invalidConfig);
// must be executed, for let .setup() method to initialize all dependencies
command2.execute(commandProcessor);
OFMeterConfig reply = sw.getOFFactory().buildMeterConfig().setMeterId(validConfig.getId().getValue()).setFlags(command2.makeMeterFlags()).setEntries(command2.makeMeterBands()).build();
statsReplyProxy.set(wrapMeterStatsReply(reply));
verifySuccessCompletion(result);
}
use of org.openkilda.model.MeterId in project open-kilda by telstra.
the class OneSwitchFlowCommandJsonTest method makeRequest.
@Override
protected OneSwitchFlowRequest makeRequest() {
SwitchId swId = new SwitchId(1);
OneSwitchFlowRequestFactory factory = new OneSwitchFlowRequestFactory(new MessageContext(), new FlowSegmentMetadata("single-switch-flow-install-request", new Cookie(2), false), new FlowEndpoint(swId, 3, 4), new MeterConfig(new MeterId(6), 7000), new FlowEndpoint(swId, 8, 9), RulesContext.builder().build(), MirrorConfig.builder().build());
return makeRequest(factory);
}
use of org.openkilda.model.MeterId in project open-kilda by telstra.
the class AllocateYFlowResourcesAction method allocateMeter.
@SneakyThrows
protected MeterId allocateMeter(String yFlowId, SwitchId switchId) throws ResourceAllocationException {
MeterId meterId = transactionManager.doInTransaction(resourceAllocationRetryPolicy, () -> resourcesManager.allocateMeter(yFlowId, switchId));
log.debug("Meter {} has been allocated for y-flow {}", meterId, yFlowId);
return meterId;
}
use of org.openkilda.model.MeterId in project open-kilda by telstra.
the class AllocateYFlowResourcesAction method allocateMeterAsEndpointResources.
private EndpointResources allocateMeterAsEndpointResources(String yFlowId, SwitchId switchId, long bandwidth) throws ResourceAllocationException {
MeterId meterId = null;
if (bandwidth > 0L) {
log.debug("Allocating resources for y-flow {}", yFlowId);
meterId = allocateMeter(yFlowId, switchId);
} else {
log.debug("Meter is not required for y-flow {}", yFlowId);
}
return EndpointResources.builder().endpoint(switchId).meterId(meterId).build();
}
Aggregations