Search in sources :

Example 1 with MeterConfig

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);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) MessageContext(org.openkilda.messaging.MessageContext) OFMeterConfig(org.projectfloodlight.openflow.protocol.OFMeterConfig) MeterConfig(org.openkilda.model.MeterConfig) OFMeterConfig(org.projectfloodlight.openflow.protocol.OFMeterConfig) MeterId(org.openkilda.model.MeterId) Test(org.junit.Test) AbstractSpeakerCommandTest(org.openkilda.floodlight.command.AbstractSpeakerCommandTest)

Example 2 with MeterConfig

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);
}
Also used : Cookie(org.openkilda.model.cookie.Cookie) FlowEndpoint(org.openkilda.model.FlowEndpoint) OneSwitchFlowRequestFactory(org.openkilda.floodlight.api.request.factory.OneSwitchFlowRequestFactory) SwitchId(org.openkilda.model.SwitchId) MessageContext(org.openkilda.messaging.MessageContext) MeterConfig(org.openkilda.model.MeterConfig) FlowSegmentMetadata(org.openkilda.floodlight.model.FlowSegmentMetadata) MeterId(org.openkilda.model.MeterId)

Example 3 with MeterConfig

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;
}
Also used : IngressFlowSegmentRequest(org.openkilda.floodlight.api.request.IngressFlowSegmentRequest) MeterConfig(org.openkilda.model.MeterConfig)

Example 4 with MeterConfig

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;
}
Also used : SwitchMissingMeterException(org.openkilda.floodlight.error.SwitchMissingMeterException) OFMeterModFailedErrorMsg(org.projectfloodlight.openflow.protocol.errormsg.OFMeterModFailedErrorMsg) Getter(lombok.Getter) InvalidMeterIdException(org.openkilda.floodlight.error.InvalidMeterIdException) Session(org.openkilda.floodlight.service.session.Session) OFMeterModFailedCode(org.projectfloodlight.openflow.protocol.OFMeterModFailedCode) MessageContext(org.openkilda.messaging.MessageContext) CompletableFuture(java.util.concurrent.CompletableFuture) SwitchIncorrectMeterException(org.openkilda.floodlight.error.SwitchIncorrectMeterException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) MeterId(org.openkilda.model.MeterId) SwitchId(org.openkilda.model.SwitchId) SpeakerCommandProcessor(org.openkilda.floodlight.command.SpeakerCommandProcessor) OFMeterMod(org.projectfloodlight.openflow.protocol.OFMeterMod) MeterConfig(org.openkilda.model.MeterConfig) OFMessage(org.projectfloodlight.openflow.protocol.OFMessage) Optional(java.util.Optional) OFErrorMsg(org.projectfloodlight.openflow.protocol.OFErrorMsg) IOfErrorResponseHandler(org.openkilda.floodlight.command.IOfErrorResponseHandler) SwitchErrorResponseException(org.openkilda.floodlight.error.SwitchErrorResponseException) SwitchMeterConflictException(org.openkilda.floodlight.error.SwitchMeterConflictException) CompletableFuture(java.util.concurrent.CompletableFuture) Optional(java.util.Optional) SwitchErrorResponseException(org.openkilda.floodlight.error.SwitchErrorResponseException)

Example 5 with MeterConfig

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());
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) OFMessage(org.projectfloodlight.openflow.protocol.OFMessage) ArrayList(java.util.ArrayList) MeterConfig(org.openkilda.model.MeterConfig) OFFlowMod(org.projectfloodlight.openflow.protocol.OFFlowMod) MeterId(org.openkilda.model.MeterId) Session(org.openkilda.floodlight.service.session.Session)

Aggregations

MeterConfig (org.openkilda.model.MeterConfig)12 OFMeterConfig (org.projectfloodlight.openflow.protocol.OFMeterConfig)8 MeterId (org.openkilda.model.MeterId)6 MessageContext (org.openkilda.messaging.MessageContext)5 FlowEndpoint (org.openkilda.model.FlowEndpoint)5 ArrayList (java.util.ArrayList)4 FlowSegmentWrapperCommand (org.openkilda.floodlight.command.flow.FlowSegmentWrapperCommand)4 RulesContext (org.openkilda.floodlight.model.RulesContext)4 ImmutableList (com.google.common.collect.ImmutableList)3 List (java.util.List)3 Test (org.junit.Test)3 AbstractSpeakerCommandTest (org.openkilda.floodlight.command.AbstractSpeakerCommandTest)3 SwitchId (org.openkilda.model.SwitchId)3 CompletableFuture (java.util.concurrent.CompletableFuture)2 Session (org.openkilda.floodlight.service.session.Session)2 OFMessage (org.projectfloodlight.openflow.protocol.OFMessage)2 Optional (java.util.Optional)1 Getter (lombok.Getter)1 IngressFlowSegmentRequest (org.openkilda.floodlight.api.request.IngressFlowSegmentRequest)1 OneSwitchFlowRequestFactory (org.openkilda.floodlight.api.request.factory.OneSwitchFlowRequestFactory)1