Search in sources :

Example 11 with MessageContext

use of org.openkilda.messaging.MessageContext 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 12 with MessageContext

use of org.openkilda.messaging.MessageContext in project open-kilda by telstra.

the class OfBatchExecutor method executeBatch.

/**
 * Execute current batch of commands.
 */
public void executeBatch() {
    log.debug("Execute batch start (key={})", kafkaKey);
    List<UUID> stageCommandsUuids = holder.getCurrentStage();
    List<OFMessage> ofMessages = new ArrayList<>();
    for (UUID uuid : stageCommandsUuids) {
        log.debug("Start processing UUID: {} (key={})", uuid, kafkaKey);
        if (holder.canExecute(uuid)) {
            BatchData batchData = holder.getByUUid(uuid);
            hasFlows |= batchData.isFlow();
            hasMeters |= batchData.isMeter();
            hasGroups |= batchData.isGroup();
            ofMessages.add(batchData.getMessage());
        } else {
            Map<UUID, String> blockingDependencies = holder.getBlockingDependencies(uuid);
            holder.recordFailedUuid(uuid, "Not all dependencies are satisfied: " + (blockingDependencies.isEmpty() ? "can't execute" : Joiner.on(",").withKeyValueSeparator("=").join(blockingDependencies)));
        }
    }
    List<CompletableFuture<Optional<OFMessage>>> requests = new ArrayList<>();
    try (Session session = sessionService.open(messageContext, iofSwitch)) {
        for (OFMessage message : ofMessages) {
            requests.add(session.write(message).whenComplete((res, ex) -> {
                log.debug("Check responses (key={})", kafkaKey);
                if (ex == null) {
                    res.ifPresent(ofMessage -> {
                        UUID uuid = holder.popAwaitingXid(ofMessage.getXid());
                        if (ofMessage instanceof OFErrorMsg) {
                            OFErrorMsg errorMsg = (OFErrorMsg) ofMessage;
                            holder.recordFailedUuid(uuid, errorMsg.getErrType().toString());
                        }
                    });
                } else {
                    log.error("Received error {}", ex.getMessage(), ex);
                }
            }));
        }
    }
    CompletableFuture.allOf(requests.toArray(new CompletableFuture<?>[0])).thenAccept(ignore -> checkOfResponses());
}
Also used : OfMeterConverter(org.openkilda.floodlight.converter.rulemanager.OfMeterConverter) Session(org.openkilda.floodlight.service.session.Session) SwitchFeature(org.openkilda.model.SwitchFeature) Collectors.counting(java.util.stream.Collectors.counting) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) CompletableFuture(java.util.concurrent.CompletableFuture) IOFSwitch(net.floodlightcontroller.core.IOFSwitch) ArrayList(java.util.ArrayList) OFFlowStatsReply(org.projectfloodlight.openflow.protocol.OFFlowStatsReply) Map(java.util.Map) SessionService(org.openkilda.floodlight.service.session.SessionService) OFMessage(org.projectfloodlight.openflow.protocol.OFMessage) OFErrorMsg(org.projectfloodlight.openflow.protocol.OFErrorMsg) IKafkaProducerService(org.openkilda.floodlight.service.kafka.IKafkaProducerService) MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) OFMeterConfigStatsReply(org.projectfloodlight.openflow.protocol.OFMeterConfigStatsReply) MessageContext(org.openkilda.messaging.MessageContext) Set(java.util.Set) OfFlowConverter(org.openkilda.floodlight.converter.rulemanager.OfFlowConverter) UUID(java.util.UUID) OfGroupConverter(org.openkilda.floodlight.converter.rulemanager.OfGroupConverter) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) String.format(java.lang.String.format) OFGroupDescStatsReply(org.projectfloodlight.openflow.protocol.OFGroupDescStatsReply) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) KafkaUtilityService(org.openkilda.floodlight.service.kafka.KafkaUtilityService) KafkaChannel(org.openkilda.floodlight.KafkaChannel) SwitchId(org.openkilda.model.SwitchId) Builder(lombok.Builder) GroupSpeakerData(org.openkilda.rulemanager.GroupSpeakerData) Function.identity(java.util.function.Function.identity) Optional(java.util.Optional) Joiner(com.google.common.base.Joiner) OFErrorMsg(org.projectfloodlight.openflow.protocol.OFErrorMsg) OFMessage(org.projectfloodlight.openflow.protocol.OFMessage) ArrayList(java.util.ArrayList) CompletableFuture(java.util.concurrent.CompletableFuture) UUID(java.util.UUID) Session(org.openkilda.floodlight.service.session.Session)

Example 13 with MessageContext

use of org.openkilda.messaging.MessageContext 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 14 with MessageContext

use of org.openkilda.messaging.MessageContext in project open-kilda by telstra.

the class RecordHandler method doInstallGroupRequest.

private void doInstallGroupRequest(CommandMessage message) {
    SwitchId switchId = ((InstallGroupRequest) message.getData()).getSwitchId();
    MirrorConfig mirrorConfig = ((InstallGroupRequest) message.getData()).getMirrorConfig();
    FlowTransitEncapsulation encapsulation = ((InstallGroupRequest) message.getData()).getEncapsulation();
    SwitchId egressSwitchId = ((InstallGroupRequest) message.getData()).getEgressSwitchId();
    FlowTransitData flowTransitData = null;
    if (encapsulation != null) {
        flowTransitData = FlowTransitData.builder().ingressSwitchId(switchId).egressSwitchId(egressSwitchId).encapsulation(encapsulation).build();
    }
    logger.debug("Install group '{}' for switch '{}'", mirrorConfig.getGroupId().intValue(), switchId);
    handleSpeakerCommand(new GroupInstallCommand(new MessageContext(message), switchId, mirrorConfig, flowTransitData));
    InstallGroupResponse response = new InstallGroupResponse(switchId, mirrorConfig.getGroupId().intValue());
    String correlationId = message.getCorrelationId();
    InfoMessage infoMessage = new InfoMessage(response, System.currentTimeMillis(), correlationId);
    getKafkaProducer().sendMessageAndTrack(context.getKafkaSwitchManagerTopic(), correlationId, infoMessage);
}
Also used : FlowTransitData(org.openkilda.floodlight.model.FlowTransitData) InstallGroupRequest(org.openkilda.messaging.command.switches.InstallGroupRequest) MirrorConfig(org.openkilda.model.MirrorConfig) InfoMessage(org.openkilda.messaging.info.InfoMessage) InstallGroupResponse(org.openkilda.messaging.info.switches.InstallGroupResponse) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) SwitchId(org.openkilda.model.SwitchId) MessageContext(org.openkilda.messaging.MessageContext) GroupInstallCommand(org.openkilda.floodlight.command.group.GroupInstallCommand)

Example 15 with MessageContext

use of org.openkilda.messaging.MessageContext in project open-kilda by telstra.

the class RecordHandler method doModifyGroupRequest.

private void doModifyGroupRequest(CommandMessage message) {
    SwitchId switchId = ((ModifyGroupRequest) message.getData()).getSwitchId();
    MirrorConfig mirrorConfig = ((ModifyGroupRequest) message.getData()).getMirrorConfig();
    FlowTransitEncapsulation encapsulation = ((ModifyGroupRequest) message.getData()).getEncapsulation();
    SwitchId egressSwitchId = ((ModifyGroupRequest) message.getData()).getEgressSwitchId();
    FlowTransitData flowTransitData = null;
    if (encapsulation != null) {
        flowTransitData = FlowTransitData.builder().ingressSwitchId(switchId).egressSwitchId(egressSwitchId).encapsulation(encapsulation).build();
    }
    logger.debug("Modify group '{}' for switch '{}'", mirrorConfig.getGroupId().intValue(), switchId);
    handleSpeakerCommand(new GroupModifyCommand(new MessageContext(message), switchId, mirrorConfig, flowTransitData));
    ModifyGroupResponse response = new ModifyGroupResponse(switchId, mirrorConfig.getGroupId().intValue());
    String correlationId = message.getCorrelationId();
    InfoMessage infoMessage = new InfoMessage(response, System.currentTimeMillis(), correlationId);
    getKafkaProducer().sendMessageAndTrack(context.getKafkaSwitchManagerTopic(), correlationId, infoMessage);
}
Also used : FlowTransitData(org.openkilda.floodlight.model.FlowTransitData) MirrorConfig(org.openkilda.model.MirrorConfig) InfoMessage(org.openkilda.messaging.info.InfoMessage) ModifyGroupResponse(org.openkilda.messaging.info.switches.ModifyGroupResponse) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) SwitchId(org.openkilda.model.SwitchId) MessageContext(org.openkilda.messaging.MessageContext) GroupModifyCommand(org.openkilda.floodlight.command.group.GroupModifyCommand) ModifyGroupRequest(org.openkilda.messaging.command.switches.ModifyGroupRequest)

Aggregations

MessageContext (org.openkilda.messaging.MessageContext)28 UUID (java.util.UUID)13 FlowSegmentMetadata (org.openkilda.floodlight.model.FlowSegmentMetadata)9 SwitchId (org.openkilda.model.SwitchId)9 ArrayList (java.util.ArrayList)7 Cookie (org.openkilda.model.cookie.Cookie)6 EgressFlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.EgressFlowSegmentRequestFactory)5 InfoMessage (org.openkilda.messaging.info.InfoMessage)5 FlowEndpoint (org.openkilda.model.FlowEndpoint)5 MirrorConfig (org.openkilda.model.MirrorConfig)5 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)5 Session (org.openkilda.floodlight.service.session.Session)4 MeterConfig (org.openkilda.model.MeterConfig)4 MeterId (org.openkilda.model.MeterId)4 List (java.util.List)3 Optional (java.util.Optional)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 EgressMirrorFlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.EgressMirrorFlowSegmentRequestFactory)3 FlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory)3 IngressFlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.IngressFlowSegmentRequestFactory)3