Search in sources :

Example 6 with SwitchMeterEntries

use of org.openkilda.messaging.info.meter.SwitchMeterEntries in project open-kilda by telstra.

the class SwitchServiceImpl method getMeters.

@Override
public CompletableFuture<SwitchMeterEntries> getMeters(SwitchId switchId) {
    String requestId = RequestCorrelationId.getId();
    CommandMessage dumpCommand = new CommandMessage(new DumpMetersRequest(switchId), System.currentTimeMillis(), requestId);
    return messagingChannel.sendAndGet(floodlightTopic, dumpCommand).thenApply(infoData -> {
        if (infoData instanceof SwitchMeterEntries) {
            return (SwitchMeterEntries) infoData;
        } else if (infoData instanceof SwitchMeterUnsupported) {
            return SwitchMeterEntries.builder().switchId(switchId).build();
        } else {
            throw new IllegalArgumentException("Unhandled meters response for switch " + switchId);
        }
    });
}
Also used : SwitchMeterUnsupported(org.openkilda.messaging.info.meter.SwitchMeterUnsupported) SwitchMeterEntries(org.openkilda.messaging.info.meter.SwitchMeterEntries) DumpMetersRequest(org.openkilda.messaging.command.switches.DumpMetersRequest) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 7 with SwitchMeterEntries

use of org.openkilda.messaging.info.meter.SwitchMeterEntries in project open-kilda by telstra.

the class RecordHandler method dumpMeters.

private void dumpMeters(SwitchId switchId, java.util.function.Consumer<MessageData> sender) {
    try {
        logger.debug("Get all meters for switch {}", switchId);
        ISwitchManager switchManager = context.getSwitchManager();
        List<OFMeterConfig> meterEntries = switchManager.dumpMeters(DatapathId.of(switchId.toLong()));
        List<MeterEntry> meters = meterEntries.stream().map(OfMeterConverter::toMeterEntry).collect(Collectors.toList());
        SwitchMeterEntries response = SwitchMeterEntries.builder().switchId(switchId).meterEntries(meters).build();
        sender.accept(response);
    } catch (UnsupportedSwitchOperationException e) {
        logger.info("Meters not supported: {}", switchId);
        sender.accept(new SwitchMeterUnsupported(switchId));
    } catch (SwitchNotFoundException e) {
        logger.info("Dumping switch meters is unsuccessful. Switch {} not found", switchId);
        ErrorData errorData = anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription(switchId.toString()).buildData();
        sender.accept(errorData);
    } catch (SwitchOperationException e) {
        logger.error("Unable to dump meters", e);
        ErrorData errorData = anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription("Unable to dump meters").buildData();
        sender.accept(errorData);
    }
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) MeterEntry(org.openkilda.messaging.info.meter.MeterEntry) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) SwitchMeterUnsupported(org.openkilda.messaging.info.meter.SwitchMeterUnsupported) SwitchMeterEntries(org.openkilda.messaging.info.meter.SwitchMeterEntries) OFMeterConfig(org.projectfloodlight.openflow.protocol.OFMeterConfig) SwitchNotFoundException(org.openkilda.floodlight.error.SwitchNotFoundException) FlowCommandErrorData(org.openkilda.messaging.error.rule.FlowCommandErrorData) ErrorData(org.openkilda.messaging.error.ErrorData)

Example 8 with SwitchMeterEntries

use of org.openkilda.messaging.info.meter.SwitchMeterEntries in project open-kilda by telstra.

the class YFlowValidationService method validateYFlowResources.

/**
 * Validate y-flow.
 */
public YFlowDiscrepancyDto validateYFlowResources(String yFlowId, List<SwitchFlowEntries> actualSwitchFlowEntries, List<SwitchMeterEntries> actualSwitchMeterEntries) throws FlowNotFoundException, SwitchNotFoundException {
    Map<SwitchId, List<SimpleSwitchRule>> actualRules = new HashMap<>();
    for (SwitchFlowEntries switchRulesEntries : actualSwitchFlowEntries) {
        SwitchMeterEntries switchMeters = actualSwitchMeterEntries.stream().filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())).findFirst().orElse(null);
        List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter.convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters, null);
        actualRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules);
    }
    YFlow yFlow = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowNotFoundException(yFlowId));
    List<SimpleSwitchRule> expectedRules = new ArrayList<>();
    for (YSubFlow subFlow : yFlow.getSubFlows()) {
        Flow flow = subFlow.getFlow();
        expectedRules.addAll(buildSimpleSwitchRules(flow, yFlow.getSharedEndpoint().getSwitchId(), yFlow.getSharedEndpointMeterId(), flow.getForwardPathId(), flow.getReversePathId(), yFlow.getYPoint(), yFlow.getMeterId()));
        if (flow.isAllocateProtectedPath()) {
            if (flow.getProtectedForwardPathId() != null && flow.getProtectedReversePathId() != null) {
                expectedRules.addAll(buildSimpleSwitchRules(flow, yFlow.getSharedEndpoint().getSwitchId(), yFlow.getSharedEndpointMeterId(), flow.getProtectedForwardPathId(), flow.getProtectedReversePathId(), yFlow.getProtectedPathYPoint(), yFlow.getProtectedPathMeterId()));
            } else {
                log.warn("Sub-flow {} of y-flow {} has no expected protected paths", flow.getFlowId(), yFlowId);
            }
        }
    }
    List<PathDiscrepancyEntity> discrepancies = new ArrayList<>();
    for (SimpleSwitchRule simpleRule : expectedRules) {
        discrepancies.addAll(simpleSwitchRuleComparator.findDiscrepancy(simpleRule, actualRules.get(simpleRule.getSwitchId())));
    }
    return YFlowDiscrepancyDto.builder().discrepancies(discrepancies).asExpected(discrepancies.isEmpty()).build();
}
Also used : YFlow(org.openkilda.model.YFlow) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) SwitchFlowEntries(org.openkilda.messaging.info.rule.SwitchFlowEntries) HashMap(java.util.HashMap) SwitchMeterEntries(org.openkilda.messaging.info.meter.SwitchMeterEntries) ArrayList(java.util.ArrayList) PathDiscrepancyEntity(org.openkilda.messaging.info.flow.PathDiscrepancyEntity) SwitchId(org.openkilda.model.SwitchId) YSubFlow(org.openkilda.model.YSubFlow) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow) SimpleSwitchRule(org.openkilda.wfm.share.utils.rule.validation.SimpleSwitchRule) ArrayList(java.util.ArrayList) List(java.util.List)

Example 9 with SwitchMeterEntries

use of org.openkilda.messaging.info.meter.SwitchMeterEntries in project open-kilda by telstra.

the class RecordHandler method doModifyMeterRequest.

private void doModifyMeterRequest(CommandMessage message) {
    MeterModifyCommandRequest request = (MeterModifyCommandRequest) message.getData();
    final IKafkaProducerService producerService = getKafkaProducer();
    String replyToTopic = context.getKafkaNbWorkerTopic();
    SwitchId switchId = request.getSwitchId();
    DatapathId datapathId = DatapathId.of(switchId.toLong());
    long meterId = request.getMeterId();
    ISwitchManager switchManager = context.getSwitchManager();
    try {
        switchManager.modifyMeterForFlow(datapathId, meterId, request.getBandwidth());
        MeterEntry meterEntry = OfMeterConverter.toMeterEntry(switchManager.dumpMeterById(datapathId, meterId));
        SwitchMeterEntries response = SwitchMeterEntries.builder().switchId(switchId).meterEntries(ImmutableList.of(meterEntry)).build();
        InfoMessage infoMessage = new InfoMessage(response, message.getTimestamp(), message.getCorrelationId());
        producerService.sendMessageAndTrack(replyToTopic, message.getCorrelationId(), infoMessage);
    } catch (UnsupportedSwitchOperationException e) {
        String messageString = String.format("Not supported: %s", new SwitchId(e.getDpId().getLong()));
        logger.error(messageString, e);
        anError(ErrorType.PARAMETERS_INVALID).withMessage(e.getMessage()).withDescription(messageString).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
    } catch (SwitchNotFoundException e) {
        logger.error("Update switch meters is unsuccessful. Switch {} not found", new SwitchId(e.getDpId().getLong()));
        anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription(new SwitchId(e.getDpId().getLong()).toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
    } catch (SwitchOperationException e) {
        String messageString = "Unable to update meter";
        logger.error(messageString, e);
        anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription(messageString).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
    }
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) SwitchMeterEntries(org.openkilda.messaging.info.meter.SwitchMeterEntries) SwitchId(org.openkilda.model.SwitchId) DatapathId(org.projectfloodlight.openflow.types.DatapathId) SwitchNotFoundException(org.openkilda.floodlight.error.SwitchNotFoundException) MeterEntry(org.openkilda.messaging.info.meter.MeterEntry) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) IKafkaProducerService(org.openkilda.floodlight.service.kafka.IKafkaProducerService) InfoMessage(org.openkilda.messaging.info.InfoMessage) MeterModifyCommandRequest(org.openkilda.messaging.command.flow.MeterModifyCommandRequest)

Example 10 with SwitchMeterEntries

use of org.openkilda.messaging.info.meter.SwitchMeterEntries in project open-kilda by telstra.

the class FlowValidationFsm method receivedMeters.

protected void receivedMeters(State from, State to, Event event, Object context) {
    SwitchMeterEntries switchMeterEntries = (SwitchMeterEntries) context;
    log.info("Switch meters received for switch {}", switchMeterEntries.getSwitchId());
    receivedMeters.add(switchMeterEntries);
    awaitingMeters--;
    checkOfCompleteDataCollection();
}
Also used : SwitchMeterEntries(org.openkilda.messaging.info.meter.SwitchMeterEntries)

Aggregations

SwitchMeterEntries (org.openkilda.messaging.info.meter.SwitchMeterEntries)13 SwitchFlowEntries (org.openkilda.messaging.info.rule.SwitchFlowEntries)6 SwitchId (org.openkilda.model.SwitchId)5 List (java.util.List)4 SwitchMeterUnsupported (org.openkilda.messaging.info.meter.SwitchMeterUnsupported)4 SwitchGroupEntries (org.openkilda.messaging.info.rule.SwitchGroupEntries)4 ArrayList (java.util.ArrayList)3 ErrorData (org.openkilda.messaging.error.ErrorData)3 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)3 InfoData (org.openkilda.messaging.info.InfoData)3 FlowNotFoundException (org.openkilda.wfm.error.FlowNotFoundException)3 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 SwitchNotFoundException (org.openkilda.floodlight.error.SwitchNotFoundException)2 SwitchOperationException (org.openkilda.floodlight.error.SwitchOperationException)2 UnsupportedSwitchOperationException (org.openkilda.floodlight.error.UnsupportedSwitchOperationException)2 ISwitchManager (org.openkilda.floodlight.switchmanager.ISwitchManager)2 Message (org.openkilda.messaging.Message)2 CommandData (org.openkilda.messaging.command.CommandData)2 FlowValidationRequest (org.openkilda.messaging.command.flow.FlowValidationRequest)2