Search in sources :

Example 1 with SwitchMessage

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

the class SimulatorCommandBolt method createTopology.

private List<Values> createTopology(TopologyMessage topology) {
    List<SwitchMessage> switches = topology.getSwitches();
    List<Values> values = new ArrayList<>();
    for (SwitchMessage sw : switches) {
        // Need to pre-pend 00:00 as DPID as returned by OpenflowJ has 8 octets
        values.add(new Values(String.format("00:00:%s", sw.getDpid()).toLowerCase(), sw, SimulatorCommands.DO_ADD_SWITCH));
        logger.info("Add Switch: {}", sw.getDpid());
    }
    return values;
}
Also used : Values(org.apache.storm.tuple.Values) ArrayList(java.util.ArrayList) SwitchMessage(org.openkilda.simulator.messages.SwitchMessage)

Example 2 with SwitchMessage

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

the class SpeakerBolt method doCommand.

public void doCommand(Tuple tuple) throws Exception {
    String command = tuple.getStringByField(TupleFields.COMMAND.name());
    List<Values> values = new ArrayList<>();
    if (command.equals(SimulatorCommands.DO_ADD_SWITCH)) {
        values = addSwitch((SwitchMessage) tuple.getValueByField(TupleFields.DATA.name()));
        if (values.size() > 0) {
            for (Values value : values) {
                logger.debug("emitting: {}", value);
                collector.emit(SimulatorTopology.KAFKA_BOLT_STREAM, tuple, value);
            }
        }
        return;
    } else if (command.equals(Commands.DO_DISCOVER_ISL_P2_COMMAND.name())) {
        discoverIslPartTwo(tuple, (IslInfoData) tuple.getValueByField(TupleFields.DATA.name()));
        return;
    }
    CommandData data = (CommandData) tuple.getValueByField(TupleFields.DATA.name());
    if (command.equals(Commands.DO_DELETE_FLOW.name())) {
    } else if (command.equals(Commands.DO_DISCOVER_ISL_COMMAND.name())) {
        discoverIsl(tuple, (DiscoverIslCommandData) data);
    } else if (command.equals(Commands.DO_DISCOVER_PATH_COMMAND.name())) {
    } else if (command.equals(Commands.DO_INSTALL_EGRESS_FLOW.name())) {
    } else if (command.equals(Commands.DO_INSTALL_INGRESS_FLOW.name())) {
    } else if (command.equals(Commands.DO_INSTALL_ONESWITCH_FLOW.name())) {
    } else if (command.equals(Commands.DO_INSTALL_TRANSIT_FLOW.name())) {
    } else {
        logger.error("Unknown switch command: {}".format(command));
        return;
    }
    if (values.size() > 0) {
        for (Values value : values) {
            logger.debug("emitting: {}", value);
            collector.emit(SimulatorTopology.KAFKA_BOLT_STREAM, tuple, value);
        }
    }
}
Also used : DiscoverIslCommandData(org.openkilda.messaging.command.discovery.DiscoverIslCommandData) Values(org.apache.storm.tuple.Values) SwitchMessage(org.openkilda.simulator.messages.SwitchMessage) CommandData(org.openkilda.messaging.command.CommandData) DiscoverIslCommandData(org.openkilda.messaging.command.discovery.DiscoverIslCommandData)

Example 3 with SwitchMessage

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

the class SpeakerBoltTest method setUp.

@Before
public void setUp() throws Exception {
    mapper = new ObjectMapper();
    speakerBolt = new SpeakerBolt();
    speakerBolt.prepare(null, null, null);
    link = new LinkMessage(linkLatency, localLinkPort, peerSwitch, peerPort);
    links.add(link);
    switchMessage = new SwitchMessage(dpid, numOfPorts, links);
}
Also used : LinkMessage(org.openkilda.simulator.messages.LinkMessage) SwitchMessage(org.openkilda.simulator.messages.SwitchMessage) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 4 with SwitchMessage

use of org.openkilda.simulator.messages.SwitchMessage 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

SwitchMessage (org.openkilda.simulator.messages.SwitchMessage)4 Values (org.apache.storm.tuple.Values)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 CommandData (org.openkilda.messaging.command.CommandData)1 DiscoverIslCommandData (org.openkilda.messaging.command.discovery.DiscoverIslCommandData)1 LinkMessage (org.openkilda.simulator.messages.LinkMessage)1 SimulatorMessage (org.openkilda.simulator.messages.simulator.SimulatorMessage)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