Search in sources :

Example 1 with SwitchPortStatusData

use of org.openkilda.messaging.info.stats.SwitchPortStatusData in project open-kilda by telstra.

the class RecordHandler method doPortsCommandDataRequest.

private void doPortsCommandDataRequest(Set<SwitchId> scope, PortsCommandData payload, String correlationId) {
    ISwitchManager switchManager = context.getModuleContext().getServiceImpl(ISwitchManager.class);
    try {
        logger.info("Getting ports data. Requester: {}", payload.getRequester());
        Map<DatapathId, IOFSwitch> allSwitchMap = context.getSwitchManager().getAllSwitchMap(true);
        for (Map.Entry<DatapathId, IOFSwitch> entry : allSwitchMap.entrySet()) {
            SwitchId switchId = new SwitchId(entry.getKey().toString());
            if (!scope.contains(switchId)) {
                continue;
            }
            try {
                IOFSwitch sw = entry.getValue();
                Set<PortStatusData> statuses = new HashSet<>();
                for (OFPortDesc portDesc : switchManager.getPhysicalPorts(sw.getId())) {
                    statuses.add(new PortStatusData(portDesc.getPortNo().getPortNumber(), portDesc.isEnabled() ? PortStatus.UP : PortStatus.DOWN));
                }
                SwitchPortStatusData response = SwitchPortStatusData.builder().switchId(switchId).ports(statuses).requester(payload.getRequester()).build();
                InfoMessage infoMessage = new InfoMessage(response, System.currentTimeMillis(), correlationId);
                getKafkaProducer().sendMessageAndTrack(context.getKafkaStatsTopic(), infoMessage);
            } catch (Exception e) {
                logger.error("Could not get port stats data for switch '{}' with error '{}'", switchId, e.getMessage(), e);
            }
        }
    } catch (Exception e) {
        logger.error("Could not get port data for stats '{}'", e.getMessage(), e);
    }
}
Also used : IOFSwitch(net.floodlightcontroller.core.IOFSwitch) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) SwitchPortStatusData(org.openkilda.messaging.info.stats.SwitchPortStatusData) DatapathId(org.projectfloodlight.openflow.types.DatapathId) SwitchId(org.openkilda.model.SwitchId) InvalidMeterIdException(org.openkilda.floodlight.error.InvalidMeterIdException) IOException(java.io.IOException) SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) SwitchNotFoundException(org.openkilda.floodlight.error.SwitchNotFoundException) OfInstallException(org.openkilda.floodlight.error.OfInstallException) FlowCommandException(org.openkilda.floodlight.error.FlowCommandException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) PortStatusData(org.openkilda.messaging.info.stats.PortStatusData) SwitchPortStatusData(org.openkilda.messaging.info.stats.SwitchPortStatusData) OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc) InfoMessage(org.openkilda.messaging.info.InfoMessage) Map(java.util.Map) HashSet(java.util.HashSet)

Example 2 with SwitchPortStatusData

use of org.openkilda.messaging.info.stats.SwitchPortStatusData in project open-kilda by telstra.

the class WfmStatsParseBolt method handleInput.

@Override
public void handleInput(Tuple tuple) {
    if (active) {
        log.debug("Ingoing tuple: {}", tuple);
        Message message = (Message) tuple.getValueByField(MessageKafkaTranslator.FIELD_ID_PAYLOAD);
        try {
            InfoData data = getInfoData(message);
            if (data instanceof SwitchPortStatusData) {
                doParseSwitchPortsData((SwitchPortStatusData) data);
            }
        } catch (MessageException e) {
            log.error("Not an InfoMessage in queue message={}", message);
        }
    }
}
Also used : Message(org.openkilda.messaging.Message) SwitchPortStatusData(org.openkilda.messaging.info.stats.SwitchPortStatusData) MessageException(org.openkilda.wfm.error.MessageException) PortInfoData(org.openkilda.messaging.info.event.PortInfoData) InfoData(org.openkilda.messaging.info.InfoData)

Aggregations

SwitchPortStatusData (org.openkilda.messaging.info.stats.SwitchPortStatusData)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 IOFSwitch (net.floodlightcontroller.core.IOFSwitch)1 FlowCommandException (org.openkilda.floodlight.error.FlowCommandException)1 InvalidMeterIdException (org.openkilda.floodlight.error.InvalidMeterIdException)1 OfInstallException (org.openkilda.floodlight.error.OfInstallException)1 SwitchNotFoundException (org.openkilda.floodlight.error.SwitchNotFoundException)1 SwitchOperationException (org.openkilda.floodlight.error.SwitchOperationException)1 UnsupportedSwitchOperationException (org.openkilda.floodlight.error.UnsupportedSwitchOperationException)1 ISwitchManager (org.openkilda.floodlight.switchmanager.ISwitchManager)1 Message (org.openkilda.messaging.Message)1 InfoData (org.openkilda.messaging.info.InfoData)1 InfoMessage (org.openkilda.messaging.info.InfoMessage)1 PortInfoData (org.openkilda.messaging.info.event.PortInfoData)1 PortStatusData (org.openkilda.messaging.info.stats.PortStatusData)1 SwitchId (org.openkilda.model.SwitchId)1 MessageException (org.openkilda.wfm.error.MessageException)1