use of org.openkilda.model.MeterConfig 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.MeterConfig 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.MeterConfig in project open-kilda by telstra.
the class SpeakerFlowSegmentRequestBuilderTest method verifyCommonIngressRequest.
private IngressFlowSegmentRequest verifyCommonIngressRequest(Flow flow, FlowPath path, FlowSegmentRequest rawRequest) {
assertThat("Should be egress segment request", rawRequest, instanceOf(IngressFlowSegmentRequest.class));
IngressFlowSegmentRequest request = (IngressFlowSegmentRequest) rawRequest;
assertEquals(flow.getFlowId(), request.getFlowId());
assertEquals(path.getCookie(), request.getCookie());
assertEquals(path.getSegments().get(0).getSrcPort(), (int) request.getIslPort());
if (0 < flow.getBandwidth()) {
MeterConfig config = new MeterConfig(path.getMeterId(), flow.getBandwidth());
assertEquals(config, request.getMeterConfig());
} else {
assertNull(request.getMeterConfig());
}
verifyVlanEncapsulation(flow, path, request.getEncapsulation());
return request;
}
use of org.openkilda.model.MeterConfig in project open-kilda by telstra.
the class MeterInstallCommand method handleOfError.
@Override
public CompletableFuture<Optional<OFMessage>> handleOfError(OFErrorMsg response) {
CompletableFuture<Optional<OFMessage>> future = new CompletableFuture<>();
if (!isInstallConflict(response)) {
future.completeExceptionally(new SwitchErrorResponseException(getSw().getId(), String.format("Can't install meter %s - %s", meterConfig.getId(), response)));
return future;
}
log.info("Meter conflict detected sw:{} meter:{}", getSw().getId(), meterConfig.getId());
MeterVerifyCommand verifyCommand = new MeterVerifyCommand(messageContext, switchId, meterConfig);
propagateFutureResponse(future, commandProcessor.chain(verifyCommand).thenAccept(this::handleMeterVerify).thenApply(ignore -> Optional.empty()));
return future;
}
use of org.openkilda.model.MeterConfig in project open-kilda by telstra.
the class IngressFlowSegmentBase method planOfFlowsInstall.
private CompletableFuture<FlowSegmentReport> planOfFlowsInstall(EffectiveIds effectiveIds) {
MeterId effectiveMeterId = effectiveIds.getMeterId();
MeterConfig meterConfig = getMeterConfig();
if (effectiveMeterId == null && rulesContext != null && !rulesContext.isUpdateMeter() && meterConfig != null) {
effectiveIds.setMeterId(meterConfig.getId());
}
List<OFFlowMod> ofMessages = makeFlowModMessages(effectiveIds);
List<CompletableFuture<Optional<OFMessage>>> writeResults = new ArrayList<>(ofMessages.size());
try (Session session = getSessionService().open(messageContext, getSw())) {
for (OFFlowMod message : ofMessages) {
writeResults.add(session.write(message));
}
}
return CompletableFuture.allOf(writeResults.toArray(new CompletableFuture[0])).thenApply(ignore -> makeSuccessReport());
}
Aggregations