Search in sources :

Example 1 with NetworkInfoData

use of org.openkilda.messaging.info.discovery.NetworkInfoData in project open-kilda by telstra.

the class CacheBolt method doWork.

/**
 * {@inheritDoc}
 */
@Override
public void doWork(Tuple tuple) {
    if (CtrlAction.boltHandlerEntrance(this, tuple))
        return;
    logger.trace("State before: {}", state);
    String json = tuple.getString(0);
    String source = tuple.getSourceComponent();
    // TODO: Eliminate the inefficiency introduced through the hack
    try {
        logger.info("Received cache data={}", tuple);
        BaseMessage bm = MAPPER.readValue(json, BaseMessage.class);
        if (bm instanceof InfoMessage) {
            InfoMessage message = (InfoMessage) bm;
            InfoData data = message.getData();
            if (data instanceof NetworkInfoData) {
                logger.debug("Storage content message {}", json);
                handleNetworkDump(data, tuple);
                isReceivedCacheInfo = true;
            } else if (!isReceivedCacheInfo) {
                logger.debug("Cache message fail due bolt not initialized: " + "component={}, stream={}, tuple={}", tuple.getSourceComponent(), tuple.getSourceStreamId(), tuple);
            } else if (data instanceof SwitchInfoData) {
                logger.info("Cache update switch info data: {}", data);
                handleSwitchEvent((SwitchInfoData) data, tuple);
            } else if (data instanceof IslInfoData) {
                logger.info("Cache update isl info data: {}", data);
                handleIslEvent((IslInfoData) data, tuple);
            } else if (data instanceof PortInfoData) {
                logger.info("Cache update port info data: {}", data);
                handlePortEvent((PortInfoData) data, tuple);
            } else if (data instanceof FlowInfoData) {
                logger.info("Cache update flow data: {}", data);
                FlowInfoData flowData = (FlowInfoData) data;
                handleFlowEvent(flowData, tuple);
            } else if (data instanceof NetworkTopologyChange) {
                logger.info("Switch flows reroute request");
                NetworkTopologyChange topologyChange = (NetworkTopologyChange) data;
                handleNetworkTopologyChangeEvent(topologyChange, tuple);
            } else {
                logger.error("Skip undefined info data type {}", json);
            }
        } else {
            logger.error("Skip undefined message type {}", json);
        }
    } catch (CacheException exception) {
        logger.error("Could not process message {}", tuple, exception);
    } catch (IOException exception) {
        logger.error("Could not deserialize message {}", tuple, exception);
    } finally {
        if (isReceivedCacheInfo) {
            outputCollector.ack(tuple);
        } else {
            outputCollector.fail(tuple);
        }
    }
    logger.trace("State after: {}", state);
}
Also used : NetworkInfoData(org.openkilda.messaging.info.discovery.NetworkInfoData) FlowInfoData(org.openkilda.messaging.info.flow.FlowInfoData) BaseMessage(org.openkilda.messaging.BaseMessage) CacheException(org.openkilda.messaging.error.CacheException) InfoMessage(org.openkilda.messaging.info.InfoMessage) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) InfoData(org.openkilda.messaging.info.InfoData) FlowInfoData(org.openkilda.messaging.info.flow.FlowInfoData) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) NetworkInfoData(org.openkilda.messaging.info.discovery.NetworkInfoData) PortInfoData(org.openkilda.messaging.info.event.PortInfoData) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) PortInfoData(org.openkilda.messaging.info.event.PortInfoData) IOException(java.io.IOException) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) NetworkTopologyChange(org.openkilda.messaging.info.event.NetworkTopologyChange)

Example 2 with NetworkInfoData

use of org.openkilda.messaging.info.discovery.NetworkInfoData in project open-kilda by telstra.

the class OFELinkBoltTest method getDumpTuple.

public Tuple getDumpTuple() throws JsonProcessingException {
    NetworkInfoData dump = new NetworkInfoData("test", Collections.emptySet(), Collections.emptySet(), Collections.emptySet(), Collections.emptySet());
    InfoMessage info = new InfoMessage(dump, 0, DEFAULT_CORRELATION_ID, Destination.WFM);
    String request = objectMapper.writeValueAsString(info);
    return new TupleImpl(context, new Values(request), TASK_ID_BOLT, STREAM_ID_INPUT);
}
Also used : NetworkInfoData(org.openkilda.messaging.info.discovery.NetworkInfoData) InfoMessage(org.openkilda.messaging.info.InfoMessage) Values(org.apache.storm.tuple.Values) TupleImpl(org.apache.storm.tuple.TupleImpl)

Example 3 with NetworkInfoData

use of org.openkilda.messaging.info.discovery.NetworkInfoData in project open-kilda by telstra.

the class RecordHandler method doNetworkDump.

/**
 * Create network dump for OFELinkBolt
 *
 * @param message NetworkCommandData
 */
private void doNetworkDump(final CommandMessage message) {
    logger.info("Create network dump");
    NetworkCommandData command = (NetworkCommandData) message.getData();
    Map<DatapathId, IOFSwitch> allSwitchMap = context.getSwitchManager().getAllSwitchMap();
    Set<SwitchInfoData> switchesInfoData = allSwitchMap.values().stream().map(this::buildSwitchInfoData).collect(Collectors.toSet());
    Set<PortInfoData> portsInfoData = allSwitchMap.values().stream().flatMap(sw -> sw.getEnabledPorts().stream().map(port -> new PortInfoData(sw.getId().toString(), port.getPortNo().getPortNumber(), null, PortChangeType.UP)).collect(Collectors.toSet()).stream()).collect(Collectors.toSet());
    NetworkInfoData dump = new NetworkInfoData(command.getRequester(), switchesInfoData, portsInfoData, Collections.emptySet(), Collections.emptySet());
    InfoMessage infoMessage = new InfoMessage(dump, System.currentTimeMillis(), message.getCorrelationId());
    context.getKafkaProducer().postMessage(OUTPUT_DISCO_TOPIC, infoMessage);
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) OFFlowStatsConverter(org.openkilda.floodlight.converter.OFFlowStatsConverter) LoggerFactory(org.slf4j.LoggerFactory) InstallTransitFlow(org.openkilda.messaging.command.flow.InstallTransitFlow) SwitchRulesInstallRequest(org.openkilda.messaging.command.switches.SwitchRulesInstallRequest) SwitchRulesDeleteRequest(org.openkilda.messaging.command.switches.SwitchRulesDeleteRequest) IOFSwitch(net.floodlightcontroller.core.IOFSwitch) SwitchOperationException(org.openkilda.floodlight.switchmanager.SwitchOperationException) CommandMessage(org.openkilda.messaging.command.CommandMessage) PortChangeType(org.openkilda.messaging.info.event.PortChangeType) Arrays.asList(java.util.Arrays.asList) DeleteRulesAction(org.openkilda.messaging.command.switches.DeleteRulesAction) ConnectModeRequest(org.openkilda.messaging.command.switches.ConnectModeRequest) SwitchFlowEntries(org.openkilda.messaging.info.rule.SwitchFlowEntries) OutputVlanType(org.openkilda.messaging.payload.flow.OutputVlanType) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) DiscoverIslCommandData(org.openkilda.messaging.command.discovery.DiscoverIslCommandData) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) InstallMissedFlowsRequest(org.openkilda.messaging.command.switches.InstallMissedFlowsRequest) IOFSwitchConverter(org.openkilda.floodlight.converter.IOFSwitchConverter) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) Collectors(java.util.stream.Collectors) InstallEgressFlow(org.openkilda.messaging.command.flow.InstallEgressFlow) OFPort(org.projectfloodlight.openflow.types.OFPort) DumpRulesRequest(org.openkilda.messaging.command.switches.DumpRulesRequest) Topic(org.openkilda.messaging.Topic) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) MeterPool(org.openkilda.floodlight.switchmanager.MeterPool) InstallIngressFlow(org.openkilda.messaging.command.flow.InstallIngressFlow) CommandData(org.openkilda.messaging.command.CommandData) java.util(java.util) SwitchState(org.openkilda.messaging.info.event.SwitchState) NetworkInfoData(org.openkilda.messaging.info.discovery.NetworkInfoData) BaseInstallFlow(org.openkilda.messaging.command.flow.BaseInstallFlow) OFFlowStatsReply(org.projectfloodlight.openflow.protocol.OFFlowStatsReply) MAPPER(org.openkilda.messaging.Utils.MAPPER) ConnectModeResponse(org.openkilda.messaging.info.switches.ConnectModeResponse) Logger(org.slf4j.Logger) DiscoverPathCommandData(org.openkilda.messaging.command.discovery.DiscoverPathCommandData) NetworkCommandData(org.openkilda.messaging.command.discovery.NetworkCommandData) ErrorType(org.openkilda.messaging.error.ErrorType) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) CommandWithReplyToMessage(org.openkilda.messaging.command.CommandWithReplyToMessage) PortInfoData(org.openkilda.messaging.info.event.PortInfoData) InstallOneSwitchFlow(org.openkilda.messaging.command.flow.InstallOneSwitchFlow) InstallRulesAction(org.openkilda.messaging.command.switches.InstallRulesAction) SwitchRulesResponse(org.openkilda.messaging.info.switches.SwitchRulesResponse) Destination(org.openkilda.messaging.Destination) DatapathId(org.projectfloodlight.openflow.types.DatapathId) ErrorData(org.openkilda.messaging.error.ErrorData) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) IOFSwitch(net.floodlightcontroller.core.IOFSwitch) NetworkInfoData(org.openkilda.messaging.info.discovery.NetworkInfoData) InfoMessage(org.openkilda.messaging.info.InfoMessage) DatapathId(org.projectfloodlight.openflow.types.DatapathId) PortInfoData(org.openkilda.messaging.info.event.PortInfoData) NetworkCommandData(org.openkilda.messaging.command.discovery.NetworkCommandData) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData)

Example 4 with NetworkInfoData

use of org.openkilda.messaging.info.discovery.NetworkInfoData in project open-kilda by telstra.

the class CacheBolt method handleNetworkDump.

private void handleNetworkDump(InfoData info, Tuple tuple) {
    if (info instanceof NetworkInfoData) {
        NetworkInfoData data = (NetworkInfoData) info;
        logger.info("Fill network state {}", data);
        data.getSwitches().forEach(networkCache::createOrUpdateSwitch);
        data.getIsls().forEach(networkCache::createOrUpdateIsl);
        logger.info("Load flows {}", data.getFlows().size());
        data.getFlows().forEach(flowCache::putFlow);
        logger.info("Loaded flows {}", flowCache);
        emitRestoreCommands(data.getFlows(), tuple);
        logger.info("Flows restore commands sent");
    } else {
        logger.warn("Incorrect network state {}", info);
    }
}
Also used : NetworkInfoData(org.openkilda.messaging.info.discovery.NetworkInfoData)

Example 5 with NetworkInfoData

use of org.openkilda.messaging.info.discovery.NetworkInfoData in project open-kilda by telstra.

the class OFELinkBolt method doWork.

@Override
protected void doWork(Tuple tuple) {
    if (CtrlAction.boltHandlerEntrance(this, tuple))
        return;
    // 
    // (crimi) - commenting out the filter code until we re-evaluate the design. Also, this code
    // should probably be embedded in "handleIslEvent"
    // /*
    // * Check whether ISL Filter needs to be engaged.
    // */
    // String source = tuple.getSourceComponent();
    // if (source.equals(OFEventWFMTopology.SPOUT_ID_INPUT)) {
    // PopulateIslFilterAction action = new PopulateIslFilterAction(this, tuple, islFilter);
    // action.run();
    // return;
    // }
    String json = tuple.getString(0);
    try {
        BaseMessage bm = MAPPER.readValue(json, BaseMessage.class);
        watchDog.reset();
        if (bm instanceof InfoMessage) {
            InfoData data = ((InfoMessage) bm).getData();
            if (data instanceof NetworkInfoData) {
                handleNetworkDump(tuple, (NetworkInfoData) data);
                isReceivedCacheInfo = true;
            } else if (!isReceivedCacheInfo) {
                logger.debug("Bolt is not initialized mark tuple as fail");
            } else if (data instanceof SwitchInfoData) {
                handleSwitchEvent(tuple, (SwitchInfoData) data);
                passToTopologyEngine(tuple);
            } else if (data instanceof PortInfoData) {
                handlePortEvent(tuple, (PortInfoData) data);
                passToTopologyEngine(tuple);
            } else if (data instanceof IslInfoData) {
                handleIslEvent(tuple, (IslInfoData) data);
            } else {
                logger.warn("Unknown InfoData type={}", data);
            }
        } else if (bm instanceof HeartBeat) {
            logger.debug("Got speaker's heart beat");
        }
    } catch (IOException e) {
        // All messages should be derived from BaseMessage .. so an exception here
        // means that we found something that isn't. If this criteria changes, then
        // change the logger level.
        logger.error("Unknown Message type={}", json);
    } finally {
        // We mark as fail all tuples while bolt is not initialized
        if (isReceivedCacheInfo) {
            collector.ack(tuple);
        } else {
            collector.fail(tuple);
        }
    }
}
Also used : HeartBeat(org.openkilda.messaging.HeartBeat) NetworkInfoData(org.openkilda.messaging.info.discovery.NetworkInfoData) BaseMessage(org.openkilda.messaging.BaseMessage) InfoMessage(org.openkilda.messaging.info.InfoMessage) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) NetworkInfoData(org.openkilda.messaging.info.discovery.NetworkInfoData) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) PortInfoData(org.openkilda.messaging.info.event.PortInfoData) InfoData(org.openkilda.messaging.info.InfoData) PortInfoData(org.openkilda.messaging.info.event.PortInfoData) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) IOException(java.io.IOException) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData)

Aggregations

NetworkInfoData (org.openkilda.messaging.info.discovery.NetworkInfoData)8 InfoMessage (org.openkilda.messaging.info.InfoMessage)7 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)5 PortInfoData (org.openkilda.messaging.info.event.PortInfoData)4 Test (org.junit.Test)3 IOException (java.io.IOException)2 TupleImpl (org.apache.storm.tuple.TupleImpl)2 Values (org.apache.storm.tuple.Values)2 BaseMessage (org.openkilda.messaging.BaseMessage)2 CommandMessage (org.openkilda.messaging.command.CommandMessage)2 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)2 AbstractStormTest (org.openkilda.wfm.AbstractStormTest)2 java.util (java.util)1 Arrays.asList (java.util.Arrays.asList)1 Collectors (java.util.stream.Collectors)1 IOFSwitch (net.floodlightcontroller.core.IOFSwitch)1 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)1 Config (org.apache.storm.Config)1 StormTopology (org.apache.storm.generated.StormTopology)1 Tuple (org.apache.storm.tuple.Tuple)1