Search in sources :

Example 1 with IKafkaProducerService

use of org.openkilda.floodlight.service.kafka.IKafkaProducerService in project open-kilda by telstra.

the class RecordHandler method doDeleteMeter.

private void doDeleteMeter(CommandMessage message, String replyToTopic) {
    DeleteMeterRequest request = (DeleteMeterRequest) message.getData();
    logger.info("Deleting meter '{}'. Switch: '{}'", request.getMeterId(), request.getSwitchId());
    final IKafkaProducerService producerService = getKafkaProducer();
    try {
        DatapathId dpid = DatapathId.of(request.getSwitchId().toLong());
        context.getSwitchManager().deleteMeter(dpid, request.getMeterId());
        boolean deleted = context.getSwitchManager().dumpMeters(dpid).stream().noneMatch(config -> config.getMeterId() == request.getMeterId());
        DeleteMeterResponse response = new DeleteMeterResponse(deleted);
        InfoMessage infoMessage = new InfoMessage(response, System.currentTimeMillis(), message.getCorrelationId());
        producerService.sendMessageAndTrack(replyToTopic, message.getCorrelationId(), infoMessage);
    } catch (SwitchOperationException e) {
        logger.error("Deleting meter '{}' from switch '{}' was unsuccessful: {}", request.getMeterId(), request.getSwitchId(), e.getMessage());
        anError(ErrorType.DATA_INVALID).withMessage(e.getMessage()).withDescription(request.getSwitchId().toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
    }
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) IKafkaProducerService(org.openkilda.floodlight.service.kafka.IKafkaProducerService) InfoMessage(org.openkilda.messaging.info.InfoMessage) DeleteMeterResponse(org.openkilda.messaging.info.switches.DeleteMeterResponse) DatapathId(org.projectfloodlight.openflow.types.DatapathId) DeleteMeterRequest(org.openkilda.messaging.command.flow.DeleteMeterRequest)

Example 2 with IKafkaProducerService

use of org.openkilda.floodlight.service.kafka.IKafkaProducerService 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 3 with IKafkaProducerService

use of org.openkilda.floodlight.service.kafka.IKafkaProducerService in project open-kilda by telstra.

the class RecordHandler method doModifyFlowMeterForSwitchManager.

private void doModifyFlowMeterForSwitchManager(CommandMessage message) {
    ModifyFlowMeterForSwitchManagerRequest request = (ModifyFlowMeterForSwitchManagerRequest) message.getData();
    IKafkaProducerService producerService = getKafkaProducer();
    long meterId = request.getMeterId();
    SwitchId switchId = request.getSwitchId();
    MeterConfig meterConfig = new MeterConfig(new MeterId(request.getMeterId()), request.getRate());
    logger.info("Modifying flow meter {} on Switch {}", meterId, switchId);
    handleSpeakerCommand(new MeterModifyCommand(new MessageContext(message), switchId, meterConfig));
    InfoMessage response = new InfoMessage(new ModifyMeterResponse(switchId, request.getMeterId()), System.currentTimeMillis(), message.getCorrelationId());
    producerService.sendMessageAndTrack(context.getKafkaSwitchManagerTopic(), message.getCorrelationId(), response);
}
Also used : MeterModifyCommand(org.openkilda.floodlight.command.meter.MeterModifyCommand) ModifyMeterResponse(org.openkilda.messaging.info.switches.ModifyMeterResponse) IKafkaProducerService(org.openkilda.floodlight.service.kafka.IKafkaProducerService) InfoMessage(org.openkilda.messaging.info.InfoMessage) SwitchId(org.openkilda.model.SwitchId) MessageContext(org.openkilda.messaging.MessageContext) OFMeterConfig(org.projectfloodlight.openflow.protocol.OFMeterConfig) MeterConfig(org.openkilda.model.MeterConfig) ModifyFlowMeterForSwitchManagerRequest(org.openkilda.messaging.command.flow.ModifyFlowMeterForSwitchManagerRequest) MeterId(org.openkilda.model.MeterId)

Example 4 with IKafkaProducerService

use of org.openkilda.floodlight.service.kafka.IKafkaProducerService 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 5 with IKafkaProducerService

use of org.openkilda.floodlight.service.kafka.IKafkaProducerService in project open-kilda by telstra.

the class SpeakerCommandProcessor method handleResult.

private void handleResult(SpeakerCommandRemoteReport report, String kafkaKey) {
    KafkaUtilityService kafkaUtil = moduleContext.getServiceImpl(KafkaUtilityService.class);
    IKafkaProducerService kafkaProducer = moduleContext.getServiceImpl(IKafkaProducerService.class);
    report.reply(kafkaUtil.getKafkaChannel(), kafkaProducer, kafkaKey);
}
Also used : IKafkaProducerService(org.openkilda.floodlight.service.kafka.IKafkaProducerService) KafkaUtilityService(org.openkilda.floodlight.service.kafka.KafkaUtilityService)

Aggregations

IKafkaProducerService (org.openkilda.floodlight.service.kafka.IKafkaProducerService)12 InfoMessage (org.openkilda.messaging.info.InfoMessage)11 UnsupportedSwitchOperationException (org.openkilda.floodlight.error.UnsupportedSwitchOperationException)10 SwitchOperationException (org.openkilda.floodlight.error.SwitchOperationException)9 DatapathId (org.projectfloodlight.openflow.types.DatapathId)8 SwitchId (org.openkilda.model.SwitchId)6 ISwitchManager (org.openkilda.floodlight.switchmanager.ISwitchManager)4 SwitchNotFoundException (org.openkilda.floodlight.error.SwitchNotFoundException)3 ArrayList (java.util.ArrayList)2 ModifyMeterResponse (org.openkilda.messaging.info.switches.ModifyMeterResponse)2 SwitchPortsDescription (org.openkilda.messaging.info.switches.SwitchPortsDescription)2 SwitchRulesResponse (org.openkilda.messaging.info.switches.SwitchRulesResponse)2 FlowEndpoint (org.openkilda.model.FlowEndpoint)2 MacAddress (org.openkilda.model.MacAddress)2 HashSet (java.util.HashSet)1 Objects (java.util.Objects)1 MeterModifyCommand (org.openkilda.floodlight.command.meter.MeterModifyCommand)1 InvalidMeterIdException (org.openkilda.floodlight.error.InvalidMeterIdException)1 OfInstallException (org.openkilda.floodlight.error.OfInstallException)1 KafkaUtilityService (org.openkilda.floodlight.service.kafka.KafkaUtilityService)1