Search in sources :

Example 1 with Session

use of org.openkilda.floodlight.service.session.Session 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 2 with Session

use of org.openkilda.floodlight.service.session.Session in project open-kilda by telstra.

the class MeterRemoveCommand method makeExecutePlan.

@Override
protected CompletableFuture<MeterRemoveReport> makeExecutePlan(SpeakerCommandProcessor commandProcessor) throws Exception {
    ensureSwitchSupportMeters();
    IOFSwitch sw = getSw();
    OFMeterMod meterDeleteMessage = sw.getOFFactory().buildMeterMod().setMeterId(meterId.getValue()).setCommand(OFMeterModCommand.DELETE).build();
    try (Session session = getSessionService().open(messageContext, sw)) {
        return session.write(meterDeleteMessage).thenApply(ignore -> makeSuccessReport());
    }
}
Also used : IOFSwitch(net.floodlightcontroller.core.IOFSwitch) OFMeterMod(org.projectfloodlight.openflow.protocol.OFMeterMod) Session(org.openkilda.floodlight.service.session.Session)

Example 3 with Session

use of org.openkilda.floodlight.service.session.Session 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)

Example 4 with Session

use of org.openkilda.floodlight.service.session.Session in project open-kilda by telstra.

the class IngressFlowSegmentBase method planOfFlowsRemove.

private CompletableFuture<EffectiveIds> planOfFlowsRemove(EffectiveIds effectiveIds) {
    List<OFFlowMod> ofMessages = new ArrayList<>(makeFlowModMessages(effectiveIds));
    List<CompletableFuture<?>> requests = new ArrayList<>(ofMessages.size());
    try (Session session = getSessionService().open(messageContext, getSw())) {
        for (OFFlowMod message : ofMessages) {
            requests.add(session.write(message));
        }
    }
    return CompletableFuture.allOf(requests.toArray(new CompletableFuture<?>[0])).thenApply(ignore -> effectiveIds);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) OFFlowMod(org.projectfloodlight.openflow.protocol.OFFlowMod) Session(org.openkilda.floodlight.service.session.Session)

Example 5 with Session

use of org.openkilda.floodlight.service.session.Session in project open-kilda by telstra.

the class GroupRemoveCommand method makeExecutePlan.

@Override
protected CompletableFuture<GroupRemoveReport> makeExecutePlan(SpeakerCommandProcessor commandProcessor) throws Exception {
    ensureSwitchSupportGroups();
    IOFSwitch sw = getSw();
    OFGroupDelete groupDelete = sw.getOFFactory().buildGroupDelete().setGroup(OFGroup.of(groupId.intValue())).setGroupType(OFGroupType.ALL).build();
    try (Session session = getSessionService().open(messageContext, sw)) {
        return session.write(groupDelete).thenApply(ignore -> makeSuccessReport());
    }
}
Also used : IOFSwitch(net.floodlightcontroller.core.IOFSwitch) OFGroupDelete(org.projectfloodlight.openflow.protocol.OFGroupDelete) Session(org.openkilda.floodlight.service.session.Session)

Aggregations

Session (org.openkilda.floodlight.service.session.Session)6 IOFSwitch (net.floodlightcontroller.core.IOFSwitch)4 ArrayList (java.util.ArrayList)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 MessageContext (org.openkilda.messaging.MessageContext)2 OFFlowMod (org.projectfloodlight.openflow.protocol.OFFlowMod)2 OFMessage (org.projectfloodlight.openflow.protocol.OFMessage)2 Joiner (com.google.common.base.Joiner)1 String.format (java.lang.String.format)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 UUID (java.util.UUID)1 Function.identity (java.util.function.Function.identity)1 Collectors.counting (java.util.stream.Collectors.counting)1 Collectors.groupingBy (java.util.stream.Collectors.groupingBy)1 Builder (lombok.Builder)1 Slf4j (lombok.extern.slf4j.Slf4j)1 KafkaChannel (org.openkilda.floodlight.KafkaChannel)1