Search in sources :

Example 1 with SimulatorMessage

use of org.openkilda.simulator.messages.simulator.SimulatorMessage in project open-kilda by telstra.

the class SimulatorCommandBolt method doCommand.

protected Map<String, Object> doCommand(Tuple tuple) throws Exception {
    SimulatorMessage message = Utils.MAPPER.readValue(getJson(tuple), SimulatorMessage.class);
    List<Values> values = new ArrayList<>();
    String stream = "";
    if (message instanceof SwitchModMessage) {
        Values value = new Values(((SwitchModMessage) message).getDpid(), message, SimulatorCommands.DO_SWITCH_MOD);
        values.add(value);
        stream = SimulatorTopology.SIMULATOR_COMMAND_STREAM;
    } else if (message instanceof PortModMessage) {
        Values value = new Values(((PortModMessage) message).getDpid(), message, SimulatorCommands.DO_PORT_MOD);
        values.add(value);
        stream = SimulatorTopology.SIMULATOR_COMMAND_STREAM;
    } else if (message instanceof TopologyMessage) {
        stream = SimulatorTopology.SIMULATOR_COMMAND_STREAM;
        values = createTopology((TopologyMessage) message);
    } else if (message instanceof AddLinkCommandMessage) {
        stream = SimulatorTopology.SIMULATOR_COMMAND_STREAM;
        values.add(new Values(((AddLinkCommandMessage) message).getDpid(), message, SimulatorCommands.DO_ADD_LINK));
    } else if (message instanceof AddSwitchCommand) {
        stream = SimulatorTopology.SIMULATOR_COMMAND_STREAM;
        values.add(new Values(((AddSwitchCommand) message).getDpid(), message, SimulatorCommands.DO_ADD_SWITCH));
    } else {
        logger.error("Unknown simulator command received: {}\n{}", message.getClass().getName(), tuple.toString());
    }
    Map<String, Object> map = new HashMap<>();
    if (values.size() > 0) {
        map.put("stream", stream);
        map.put("values", values);
    }
    return map;
}
Also used : HashMap(java.util.HashMap) Values(org.apache.storm.tuple.Values) ArrayList(java.util.ArrayList) SimulatorMessage(org.openkilda.simulator.messages.simulator.SimulatorMessage)

Example 2 with SimulatorMessage

use of org.openkilda.simulator.messages.simulator.SimulatorMessage in project open-kilda by telstra.

the class SpeakerBolt method doSimulatorCommand.

public void doSimulatorCommand(Tuple tuple) throws Exception {
    List<Values> values = new ArrayList<>();
    if (tuple.getFields().contains("command")) {
        String command = tuple.getStringByField("command");
        switch(command) {
            case SimulatorCommands.DO_ADD_SWITCH:
                // TODO: this is an ugly hack...
                if (tuple.getValueByField("data") instanceof AddSwitchCommand) {
                    values = addSwitch((AddSwitchCommand) tuple.getValueByField("data"));
                } else {
                    values = addSwitch((SwitchMessage) tuple.getValueByField("data"));
                }
                break;
            case SimulatorCommands.DO_ADD_LINK:
                values = addLink((AddLinkCommandMessage) tuple.getValueByField("data"));
                break;
            case SimulatorCommands.DO_PORT_MOD:
                values = modPort((PortModMessage) tuple.getValueByField("data"));
                break;
            default:
                logger.error(String.format("Uknown SimulatorCommand %s", command));
        }
    } else {
        SimulatorMessage message = (SimulatorMessage) tuple.getValueByField("data");
        if (message instanceof SwitchModMessage) {
            SwitchModMessage switchModMessage = (SwitchModMessage) message;
            ISwitchImpl sw = getSwitch(switchModMessage.getDpid());
        // sw.mod(switchModMessage.getState());
        } else {
            logger.error("Unkown SimulatorMessage {}", message.getClass().getSimpleName());
        }
    }
    if (values.size() > 0) {
        for (Values value : values) {
            logger.debug("emitting: {}", value);
            collector.emit(SimulatorTopology.KAFKA_BOLT_STREAM, tuple, value);
        }
    }
}
Also used : PortModMessage(org.openkilda.simulator.messages.simulator.command.PortModMessage) AddSwitchCommand(org.openkilda.simulator.messages.simulator.command.AddSwitchCommand) SimulatorMessage(org.openkilda.simulator.messages.simulator.SimulatorMessage) Values(org.apache.storm.tuple.Values) AddLinkCommandMessage(org.openkilda.simulator.messages.simulator.command.AddLinkCommandMessage) SwitchMessage(org.openkilda.simulator.messages.SwitchMessage) SwitchModMessage(org.openkilda.simulator.messages.simulator.command.SwitchModMessage)

Aggregations

Values (org.apache.storm.tuple.Values)2 SimulatorMessage (org.openkilda.simulator.messages.simulator.SimulatorMessage)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 SwitchMessage (org.openkilda.simulator.messages.SwitchMessage)1 AddLinkCommandMessage (org.openkilda.simulator.messages.simulator.command.AddLinkCommandMessage)1 AddSwitchCommand (org.openkilda.simulator.messages.simulator.command.AddSwitchCommand)1 PortModMessage (org.openkilda.simulator.messages.simulator.command.PortModMessage)1 SwitchModMessage (org.openkilda.simulator.messages.simulator.command.SwitchModMessage)1