Search in sources :

Example 26 with SwitchOperationException

use of org.openkilda.floodlight.error.SwitchOperationException in project open-kilda by telstra.

the class SwitchTrackingService method dumpAllSwitchesAction.

private void dumpAllSwitchesAction(String dumpId) {
    Collection<IOFSwitch> iofSwitches = switchManager.getAllSwitchMap(true).values();
    for (IOFSwitch sw : iofSwitches) {
        NetworkDumpSwitchData payload = null;
        try {
            payload = new NetworkDumpSwitchData(buildSwitch(sw), dumpId, sw.getControllerRole() != OFControllerRole.ROLE_SLAVE);
            emitDiscoveryEvent(sw.getId(), payload);
        } catch (SwitchOperationException e) {
            log.error("Exclude {} from dump switches response - {}", sw.getId(), e.getMessage(), e);
        }
    }
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) IOFSwitch(net.floodlightcontroller.core.IOFSwitch) NetworkDumpSwitchData(org.openkilda.messaging.info.discovery.NetworkDumpSwitchData)

Example 27 with SwitchOperationException

use of org.openkilda.floodlight.error.SwitchOperationException in project open-kilda by telstra.

the class BfdCommand method call.

@Override
public Command call() throws Exception {
    try {
        IOFSwitch sw = switchManager.lookupSwitch(target);
        validate(sw);
        try (Session session = sessionService.open(new MessageContext(getContext().getCorrelationId()), sw)) {
            handle(session);
        }
    } catch (SwitchOperationException e) {
        handleError(e);
        // early error response
        sendResponse();
    }
    return null;
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) IOFSwitch(net.floodlightcontroller.core.IOFSwitch) MessageContext(org.openkilda.messaging.MessageContext) Session(org.openkilda.floodlight.service.session.Session)

Example 28 with SwitchOperationException

use of org.openkilda.floodlight.error.SwitchOperationException in project open-kilda by telstra.

the class MetersResource method getMeters.

// FIXME(surabujin): is it used anywhere?
/**
 * Gets meters.
 * @return the map of meters.
 */
@Get("json")
@SuppressWarnings("unchecked")
public Map<Long, Object> getMeters() {
    Map<Long, Object> response = new HashMap<>();
    String switchId = (String) this.getRequestAttributes().get("switch_id");
    logger.debug("Get meters for switch: {}", switchId);
    ISwitchManager switchManager = (ISwitchManager) getContext().getAttributes().get(ISwitchManager.class.getCanonicalName());
    try {
        List<OFMeterConfig> meters = switchManager.dumpMeters(DatapathId.of(switchId));
        if (meters != null) {
            logger.debug("Meters from switch {} received: {}", switchId, meters.size());
            for (OFMeterConfig entry : meters) {
                response.put(entry.getMeterId(), entry);
            }
        }
    } catch (UnsupportedSwitchOperationException ex) {
        String messageString = "Not supported";
        logger.error("{}: {}", messageString, switchId, ex);
        MessageError responseMessage = new MessageError(CorrelationContext.getId(), System.currentTimeMillis(), ErrorType.PARAMETERS_INVALID.toString(), messageString, ex.getMessage());
        response.putAll(MAPPER.convertValue(responseMessage, Map.class));
        getResponse().setStatus(Status.SERVER_ERROR_NOT_IMPLEMENTED);
    } catch (IllegalArgumentException | SwitchOperationException exception) {
        String messageString = "No such switch";
        logger.error("{}: {}", messageString, switchId, exception);
        MessageError responseMessage = new MessageError(CorrelationContext.getId(), System.currentTimeMillis(), ErrorType.PARAMETERS_INVALID.toString(), messageString, exception.getMessage());
        response.putAll(MAPPER.convertValue(responseMessage, Map.class));
        getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
    }
    return response;
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) HashMap(java.util.HashMap) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) MessageError(org.openkilda.messaging.error.MessageError) OFMeterConfig(org.projectfloodlight.openflow.protocol.OFMeterConfig) Get(org.restlet.resource.Get)

Aggregations

SwitchOperationException (org.openkilda.floodlight.error.SwitchOperationException)28 UnsupportedSwitchOperationException (org.openkilda.floodlight.error.UnsupportedSwitchOperationException)25 IKafkaProducerService (org.openkilda.floodlight.service.kafka.IKafkaProducerService)13 InfoMessage (org.openkilda.messaging.info.InfoMessage)13 DatapathId (org.projectfloodlight.openflow.types.DatapathId)13 ErrorData (org.openkilda.messaging.error.ErrorData)9 SwitchNotFoundException (org.openkilda.floodlight.error.SwitchNotFoundException)8 ISwitchManager (org.openkilda.floodlight.switchmanager.ISwitchManager)8 SwitchId (org.openkilda.model.SwitchId)8 ArrayList (java.util.ArrayList)7 IOFSwitch (net.floodlightcontroller.core.IOFSwitch)7 OFMeterConfig (org.projectfloodlight.openflow.protocol.OFMeterConfig)7 HashSet (java.util.HashSet)6 DeleteRulesCriteria (org.openkilda.messaging.command.switches.DeleteRulesCriteria)6 OFGroupDescStatsEntry (org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry)6 VisibleForTesting (com.google.common.annotations.VisibleForTesting)5 ImmutableList (com.google.common.collect.ImmutableList)5 List (java.util.List)5 Objects (java.util.Objects)5 String.format (java.lang.String.format)4