Search in sources :

Example 16 with CommandData

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

the class RecordHandler method dispatch.

private boolean dispatch(CommandContext commandContext, CommandMessage message) {
    CommandData payload = message.getData();
    for (CommandDispatcher<?> entry : dispatchers) {
        Optional<Command> command = entry.dispatch(commandContext, payload);
        if (!command.isPresent()) {
            continue;
        }
        commandProcessor.process(command.get());
        return true;
    }
    return false;
}
Also used : GroupModifyCommand(org.openkilda.floodlight.command.group.GroupModifyCommand) Command(org.openkilda.floodlight.command.Command) TransitFlowLoopSegmentInstallCommand(org.openkilda.floodlight.command.flow.transit.TransitFlowLoopSegmentInstallCommand) SpeakerCommand(org.openkilda.floodlight.command.SpeakerCommand) InstallIslDefaultRulesCommand(org.openkilda.messaging.payload.switches.InstallIslDefaultRulesCommand) GroupInstallCommand(org.openkilda.floodlight.command.group.GroupInstallCommand) OneSwitchFlowInstallCommand(org.openkilda.floodlight.command.flow.ingress.OneSwitchFlowInstallCommand) OneSwitchMirrorFlowInstallCommand(org.openkilda.floodlight.command.flow.ingress.OneSwitchMirrorFlowInstallCommand) RemoveIslDefaultRulesCommand(org.openkilda.messaging.payload.switches.RemoveIslDefaultRulesCommand) EgressFlowSegmentInstallCommand(org.openkilda.floodlight.command.flow.egress.EgressFlowSegmentInstallCommand) MeterModifyCommand(org.openkilda.floodlight.command.meter.MeterModifyCommand) IngressMirrorFlowSegmentInstallCommand(org.openkilda.floodlight.command.flow.ingress.IngressMirrorFlowSegmentInstallCommand) EgressMirrorFlowSegmentInstallCommand(org.openkilda.floodlight.command.flow.egress.EgressMirrorFlowSegmentInstallCommand) GroupRemoveCommand(org.openkilda.floodlight.command.group.GroupRemoveCommand) FlowSegmentWrapperCommand(org.openkilda.floodlight.command.flow.FlowSegmentWrapperCommand) IngressFlowLoopSegmentInstallCommand(org.openkilda.floodlight.command.flow.ingress.IngressFlowLoopSegmentInstallCommand) IngressFlowSegmentInstallCommand(org.openkilda.floodlight.command.flow.ingress.IngressFlowSegmentInstallCommand) IngressServer42FlowInstallCommand(org.openkilda.floodlight.command.flow.ingress.IngressServer42FlowInstallCommand) TransitFlowSegmentInstallCommand(org.openkilda.floodlight.command.flow.transit.TransitFlowSegmentInstallCommand) NetworkCommandData(org.openkilda.messaging.command.discovery.NetworkCommandData) DiscoverIslCommandData(org.openkilda.messaging.command.discovery.DiscoverIslCommandData) PortsCommandData(org.openkilda.messaging.command.discovery.PortsCommandData) DiscoverPathCommandData(org.openkilda.messaging.command.discovery.DiscoverPathCommandData) CommandData(org.openkilda.messaging.command.CommandData)

Example 17 with CommandData

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

the class FlowResource method installFlow.

/**
 * Installing flow.
 *
 * @param json the json from request.
 * @return json response.
 * @throws JsonProcessingException if response can't be wrote to string.
 */
@Post("json")
@Put("json")
public String installFlow(String json) throws JsonProcessingException {
    ISwitchManager switchManager = (ISwitchManager) getContext().getAttributes().get(ISwitchManager.class.getCanonicalName());
    Message message;
    try {
        message = MAPPER.readValue(json, Message.class);
    } catch (IOException exception) {
        String messageString = "Received JSON is not valid for TPN";
        logger.error("{}: {}", messageString, json, exception);
        MessageError responseMessage = new MessageError(CorrelationContext.getId(), now(), ErrorType.DATA_INVALID.toString(), messageString, exception.getMessage());
        return MAPPER.writeValueAsString(responseMessage);
    }
    if (!(message instanceof CommandMessage)) {
        String messageString = "Json payload message is not an instance of CommandMessage";
        logger.error("{}: class={}, data={}", messageString, message.getClass().getCanonicalName(), json);
        MessageError responseMessage = new MessageError(CorrelationContext.getId(), now(), ErrorType.DATA_INVALID.toString(), messageString, message.getClass().getCanonicalName());
        return MAPPER.writeValueAsString(responseMessage);
    }
    CommandMessage cmdMessage = (CommandMessage) message;
    CommandData data = cmdMessage.getData();
    if (!(data instanceof BaseInstallFlow)) {
        String messageString = "Json payload data is not an instance of CommandData";
        logger.error("{}: class={}, data={}", messageString, data.getClass().getCanonicalName(), json);
        MessageError responseMessage = new MessageError(CorrelationContext.getId(), now(), ErrorType.DATA_INVALID.toString(), messageString, data.getClass().getCanonicalName());
        return MAPPER.writeValueAsString(responseMessage);
    }
    return MAPPER.writeValueAsString("ok");
}
Also used : ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) MessageError(org.openkilda.messaging.error.MessageError) IOException(java.io.IOException) BaseInstallFlow(org.openkilda.messaging.command.flow.BaseInstallFlow) CommandData(org.openkilda.messaging.command.CommandData) CommandMessage(org.openkilda.messaging.command.CommandMessage) Post(org.restlet.resource.Post) Put(org.restlet.resource.Put)

Example 18 with CommandData

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

the class CommandBolt method processCommand.

protected void processCommand(Tuple tuple) throws Exception {
    CommandMessage command = Utils.MAPPER.readValue(getJson(tuple), CommandMessage.class);
    if (command.getDestination() == Destination.CONTROLLER) {
        CommandData data = command.getData();
        Commands switchCommand;
        String sw;
        if (data instanceof DiscoverIslCommandData) {
            switchCommand = Commands.DO_DISCOVER_ISL_COMMAND;
            sw = ((DiscoverIslCommandData) data).getSwitchId();
        } else if (data instanceof DiscoverPathCommandData) {
            switchCommand = Commands.DO_DISCOVER_PATH_COMMAND;
            sw = ((DiscoverPathCommandData) data).getSrcSwitchId();
        } else if (data instanceof InstallIngressFlow) {
            switchCommand = Commands.DO_INSTALL_INGRESS_FLOW;
            sw = ((InstallIngressFlow) data).getSwitchId();
        } else if (data instanceof InstallEgressFlow) {
            switchCommand = Commands.DO_INSTALL_EGRESS_FLOW;
            sw = ((InstallEgressFlow) data).getSwitchId();
        } else if (data instanceof InstallTransitFlow) {
            switchCommand = Commands.DO_INSTALL_TRANSIT_FLOW;
            sw = ((InstallTransitFlow) data).getSwitchId();
        } else if (data instanceof InstallOneSwitchFlow) {
            switchCommand = Commands.DO_INSTALL_ONESWITCH_FLOW;
            sw = ((InstallOneSwitchFlow) data).getSwitchId();
        } else if (data instanceof RemoveFlow) {
            switchCommand = Commands.DO_DELETE_FLOW;
            sw = ((RemoveFlow) data).getSwitchId();
        } else {
            logger.error("unknown data type: {}", data.toString());
            throw new Exception("Unknown command {}".format(data.getClass().getSimpleName()));
        }
        List<Integer> taskIDs = collector.emit(SimulatorTopology.COMMAND_BOLT_STREAM, tuple, new Values(sw.toLowerCase(), switchCommand.name(), command.getData()));
    // logger.info("{}:  {} - {}", switchCommand.name(), sw, command.getData().toString());
    }
}
Also used : DiscoverIslCommandData(org.openkilda.messaging.command.discovery.DiscoverIslCommandData) Values(org.apache.storm.tuple.Values) CommandMessage(org.openkilda.messaging.command.CommandMessage) Commands(org.openkilda.simulator.classes.Commands) CommandData(org.openkilda.messaging.command.CommandData) DiscoverPathCommandData(org.openkilda.messaging.command.discovery.DiscoverPathCommandData) DiscoverIslCommandData(org.openkilda.messaging.command.discovery.DiscoverIslCommandData) DiscoverPathCommandData(org.openkilda.messaging.command.discovery.DiscoverPathCommandData)

Example 19 with CommandData

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

the class CacheWarmingService method getFlowCommands.

public List<CommandData> getFlowCommands(String switchId) {
    List<CommandData> result = new ArrayList<>();
    predefinedFlows.stream().filter(flow -> switchId.equals(flow.getLeft().getSourceSwitch())).forEach(pair -> {
        CommandData command = getFlowCommandIfNeeded(pair.getLeft());
        if (Objects.nonNull(command)) {
            result.add(command);
        }
    });
    return result;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) CommandData(org.openkilda.messaging.command.CommandData) Flow(org.openkilda.messaging.model.Flow) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) ImmutablePair(org.openkilda.messaging.model.ImmutablePair) PortInfoData(org.openkilda.messaging.info.event.PortInfoData) FlowCache(org.openkilda.pce.cache.FlowCache) PathNode(org.openkilda.messaging.info.event.PathNode) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Objects(java.util.Objects) List(java.util.List) Logger(org.apache.logging.log4j.Logger) MutablePair(org.apache.commons.lang3.tuple.MutablePair) FlowCreateRequest(org.openkilda.messaging.command.flow.FlowCreateRequest) PortChangeType(org.openkilda.messaging.info.event.PortChangeType) NetworkCache(org.openkilda.pce.cache.NetworkCache) FlowState(org.openkilda.messaging.payload.flow.FlowState) LogManager(org.apache.logging.log4j.LogManager) ArrayList(java.util.ArrayList) CommandData(org.openkilda.messaging.command.CommandData)

Example 20 with CommandData

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

the class CacheWarmingService method getFlowCommandIfNeeded.

private CommandData getFlowCommandIfNeeded(Flow flow) {
    CommandData request = null;
    if (flow.getState() == FlowState.CACHED && isFlowSwitchesUp(flow)) {
        request = new FlowCreateRequest(flow);
        LOGGER.info("Created flow create request for flowId {}", flow.getFlowId());
        predefinedFlows.stream().filter(item -> item.getLeft().equals(flow)).findFirst().ifPresent(pair -> pair.setRight(CachedFlowState.CREATED));
    }
    return request;
}
Also used : FlowCreateRequest(org.openkilda.messaging.command.flow.FlowCreateRequest) CommandData(org.openkilda.messaging.command.CommandData)

Aggregations

CommandData (org.openkilda.messaging.command.CommandData)35 CommandMessage (org.openkilda.messaging.command.CommandMessage)14 Values (org.apache.storm.tuple.Values)12 Message (org.openkilda.messaging.Message)11 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)11 InfoData (org.openkilda.messaging.info.InfoData)7 Test (org.junit.Test)6 InfoMessage (org.openkilda.messaging.info.InfoMessage)6 DiscoverIslCommandData (org.openkilda.messaging.command.discovery.DiscoverIslCommandData)5 DumpGroupsForFlowHsRequest (org.openkilda.messaging.command.switches.DumpGroupsForFlowHsRequest)5 DumpMetersForFlowHsRequest (org.openkilda.messaging.command.switches.DumpMetersForFlowHsRequest)5 DumpRulesForFlowHsRequest (org.openkilda.messaging.command.switches.DumpRulesForFlowHsRequest)5 SwitchId (org.openkilda.model.SwitchId)5 IOException (java.io.IOException)4 List (java.util.List)4 DiscoverPathCommandData (org.openkilda.messaging.command.discovery.DiscoverPathCommandData)4 FlowCreateRequest (org.openkilda.messaging.command.flow.FlowCreateRequest)4 ErrorData (org.openkilda.messaging.error.ErrorData)4 NetworkCommandData (org.openkilda.messaging.command.discovery.NetworkCommandData)3 BaseInstallFlow (org.openkilda.messaging.command.flow.BaseInstallFlow)3