Search in sources :

Example 6 with SwitchOperationException

use of org.openkilda.floodlight.error.SwitchOperationException in project open-kilda by telstra.

the class RecordHandler method doDumpSwitchPortsDescriptionRequest.

private void doDumpSwitchPortsDescriptionRequest(CommandMessage message) {
    DumpSwitchPortsDescriptionRequest request = (DumpSwitchPortsDescriptionRequest) message.getData();
    final IKafkaProducerService producerService = getKafkaProducer();
    final String replyToTopic = context.getKafkaNorthboundTopic();
    try {
        SwitchId switchId = request.getSwitchId();
        logger.info("Dump ALL ports description for switch {}", switchId);
        SwitchPortsDescription response = getSwitchPortsDescription(switchId);
        InfoMessage infoMessage = new InfoMessage(response, message.getTimestamp(), message.getCorrelationId());
        producerService.sendMessageAndTrack(replyToTopic, infoMessage);
    } catch (SwitchOperationException e) {
        logger.error("Unable to dump switch port descriptions request", e);
        anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription("Unable to dump switch port descriptions request").withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
    }
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) SwitchPortsDescription(org.openkilda.messaging.info.switches.SwitchPortsDescription) IKafkaProducerService(org.openkilda.floodlight.service.kafka.IKafkaProducerService) DumpSwitchPortsDescriptionRequest(org.openkilda.messaging.command.switches.DumpSwitchPortsDescriptionRequest) InfoMessage(org.openkilda.messaging.info.InfoMessage) SwitchId(org.openkilda.model.SwitchId)

Example 7 with SwitchOperationException

use of org.openkilda.floodlight.error.SwitchOperationException in project open-kilda by telstra.

the class RecordHandler method doRemoveIslDefaultRule.

private void doRemoveIslDefaultRule(CommandMessage message) {
    RemoveIslDefaultRulesCommand toRemove = (RemoveIslDefaultRulesCommand) message.getData();
    RemoveIslDefaultRulesResult result = new RemoveIslDefaultRulesResult(toRemove.getSrcSwitch(), toRemove.getSrcPort(), toRemove.getDstSwitch(), toRemove.getDstPort(), true);
    DatapathId dpid = DatapathId.of(toRemove.getSrcSwitch().toLong());
    try {
        context.getSwitchManager().removeMultitableEndpointIslRules(dpid, toRemove.getSrcPort());
        context.getSwitchManager().removeServer42IslRttInputFlow(dpid, toRemove.getSrcPort());
    } catch (SwitchOperationException e) {
        logger.error("Failed to remove isl rules for switch: '{}'", toRemove.getSrcSwitch(), e);
        result.setSuccess(false);
    }
    getKafkaProducer().sendMessageAndTrack(context.getKafkaSwitchManagerTopic(), record.key(), new InfoMessage(result, System.currentTimeMillis(), message.getCorrelationId(), context.getRegion()));
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) RemoveIslDefaultRulesResult(org.openkilda.messaging.info.discovery.RemoveIslDefaultRulesResult) InfoMessage(org.openkilda.messaging.info.InfoMessage) DatapathId(org.projectfloodlight.openflow.types.DatapathId) RemoveIslDefaultRulesCommand(org.openkilda.messaging.payload.switches.RemoveIslDefaultRulesCommand)

Example 8 with SwitchOperationException

use of org.openkilda.floodlight.error.SwitchOperationException in project open-kilda by telstra.

the class RecordHandler method dumpGroupsRequest.

private void dumpGroupsRequest(SwitchId switchId, java.util.function.Consumer<MessageData> sender) {
    try {
        logger.debug("Loading installed groups for switch {}", switchId);
        List<OFGroupDescStatsEntry> ofGroupDescStatsEntries = context.getSwitchManager().dumpGroups(DatapathId.of(switchId.toLong()));
        List<GroupEntry> groups = ofGroupDescStatsEntries.stream().map(OfFlowStatsMapper.INSTANCE::toFlowGroupEntry).collect(Collectors.toList());
        SwitchGroupEntries response = SwitchGroupEntries.builder().switchId(switchId).groupEntries(groups).build();
        sender.accept(response);
    } catch (SwitchOperationException e) {
        logger.error("Dumping of groups on switch '{}' was unsuccessful: {}", switchId, e.getMessage());
        ErrorData errorData = anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription("The switch was not found when requesting a groups dump.").buildData();
        sender.accept(errorData);
    }
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) GroupEntry(org.openkilda.messaging.info.rule.GroupEntry) OfFlowStatsMapper(org.openkilda.floodlight.converter.OfFlowStatsMapper) OFGroupDescStatsEntry(org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry) SwitchGroupEntries(org.openkilda.messaging.info.rule.SwitchGroupEntries) FlowCommandErrorData(org.openkilda.messaging.error.rule.FlowCommandErrorData) ErrorData(org.openkilda.messaging.error.ErrorData)

Example 9 with SwitchOperationException

use of org.openkilda.floodlight.error.SwitchOperationException in project open-kilda by telstra.

the class RecordHandler method doDumpPortDescriptionRequest.

private void doDumpPortDescriptionRequest(CommandMessage message) {
    DumpPortDescriptionRequest request = (DumpPortDescriptionRequest) message.getData();
    final IKafkaProducerService producerService = getKafkaProducer();
    final String replyToTopic = context.getKafkaNorthboundTopic();
    try {
        SwitchId switchId = request.getSwitchId();
        logger.info("Get port {}_{} description", switchId, request.getPortNumber());
        SwitchPortsDescription switchPortsDescription = getSwitchPortsDescription(switchId);
        int port = request.getPortNumber();
        PortDescription response = switchPortsDescription.getPortsDescription().stream().filter(x -> x.getPortNumber() == port).findFirst().orElseThrow(() -> new SwitchOperationException(DatapathId.of(switchId.toLong()), format("Port %s_%d does not exists.", switchId, port)));
        InfoMessage infoMessage = new InfoMessage(response, message.getTimestamp(), message.getCorrelationId());
        producerService.sendMessageAndTrack(replyToTopic, infoMessage);
    } catch (SwitchOperationException e) {
        logger.error("Unable to dump port description request", e);
        anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription("Unable to dump port description request").withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
    }
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) SwitchPortsDescription(org.openkilda.messaging.info.switches.SwitchPortsDescription) IKafkaProducerService(org.openkilda.floodlight.service.kafka.IKafkaProducerService) InfoMessage(org.openkilda.messaging.info.InfoMessage) DumpPortDescriptionRequest(org.openkilda.messaging.command.switches.DumpPortDescriptionRequest) PortDescription(org.openkilda.messaging.info.switches.PortDescription) SwitchId(org.openkilda.model.SwitchId) FlowEndpoint(org.openkilda.model.FlowEndpoint)

Example 10 with SwitchOperationException

use of org.openkilda.floodlight.error.SwitchOperationException in project open-kilda by telstra.

the class FlowSegmentReport method assembleResponse.

private SpeakerResponse assembleResponse() {
    FlowErrorResponseBuilder errorResponse = makeErrorTemplate();
    try {
        raiseError();
        return makeSuccessReply();
    } catch (SwitchNotFoundException e) {
        errorResponse.errorCode(ErrorCode.SWITCH_UNAVAILABLE);
    } catch (SessionErrorResponseException e) {
        decodeError(errorResponse, e.getErrorResponse());
    } catch (SwitchMissingFlowsException e) {
        errorResponse.errorCode(ErrorCode.MISSING_OF_FLOWS);
        errorResponse.description(e.getMessage());
    } catch (SwitchOperationException e) {
        errorResponse.errorCode(ErrorCode.UNKNOWN);
        errorResponse.description(e.getMessage());
    } catch (Exception e) {
        log.error(String.format("Unhandled exception while processing command %s", command), e);
        errorResponse.errorCode(ErrorCode.UNKNOWN);
    }
    FlowErrorResponse response = errorResponse.build();
    log.error("Command {} have failed - {} {}", command, response.getErrorCode(), response.getDescription());
    return response;
}
Also used : SwitchMissingFlowsException(org.openkilda.floodlight.error.SwitchMissingFlowsException) SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) FlowErrorResponse(org.openkilda.floodlight.flow.response.FlowErrorResponse) FlowErrorResponseBuilder(org.openkilda.floodlight.flow.response.FlowErrorResponse.FlowErrorResponseBuilder) SwitchNotFoundException(org.openkilda.floodlight.error.SwitchNotFoundException) SessionErrorResponseException(org.openkilda.floodlight.error.SessionErrorResponseException) SessionErrorResponseException(org.openkilda.floodlight.error.SessionErrorResponseException) SwitchMissingFlowsException(org.openkilda.floodlight.error.SwitchMissingFlowsException) SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) SwitchNotFoundException(org.openkilda.floodlight.error.SwitchNotFoundException)

Aggregations

SwitchOperationException (org.openkilda.floodlight.error.SwitchOperationException)28 UnsupportedSwitchOperationException (org.openkilda.floodlight.error.UnsupportedSwitchOperationException)25 IKafkaProducerService (org.openkilda.floodlight.service.kafka.IKafkaProducerService)13 InfoMessage (org.openkilda.messaging.info.InfoMessage)13 DatapathId (org.projectfloodlight.openflow.types.DatapathId)13 ErrorData (org.openkilda.messaging.error.ErrorData)9 SwitchNotFoundException (org.openkilda.floodlight.error.SwitchNotFoundException)8 ISwitchManager (org.openkilda.floodlight.switchmanager.ISwitchManager)8 SwitchId (org.openkilda.model.SwitchId)8 ArrayList (java.util.ArrayList)7 IOFSwitch (net.floodlightcontroller.core.IOFSwitch)7 OFMeterConfig (org.projectfloodlight.openflow.protocol.OFMeterConfig)7 HashSet (java.util.HashSet)6 DeleteRulesCriteria (org.openkilda.messaging.command.switches.DeleteRulesCriteria)6 OFGroupDescStatsEntry (org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry)6 VisibleForTesting (com.google.common.annotations.VisibleForTesting)5 ImmutableList (com.google.common.collect.ImmutableList)5 List (java.util.List)5 Objects (java.util.Objects)5 String.format (java.lang.String.format)4