Search in sources :

Example 1 with PortStatusData

use of org.openkilda.messaging.info.stats.PortStatusData 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)

Aggregations

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 InfoMessage (org.openkilda.messaging.info.InfoMessage)1 PortStatusData (org.openkilda.messaging.info.stats.PortStatusData)1 SwitchPortStatusData (org.openkilda.messaging.info.stats.SwitchPortStatusData)1 SwitchId (org.openkilda.model.SwitchId)1 OFPortDesc (org.projectfloodlight.openflow.protocol.OFPortDesc)1 DatapathId (org.projectfloodlight.openflow.types.DatapathId)1