use of org.openkilda.floodlight.error.SwitchNotFoundException in project open-kilda by telstra.
the class RecordHandler method dumpMeters.
private void dumpMeters(SwitchId switchId, java.util.function.Consumer<MessageData> sender) {
try {
logger.debug("Get all meters for switch {}", switchId);
ISwitchManager switchManager = context.getSwitchManager();
List<OFMeterConfig> meterEntries = switchManager.dumpMeters(DatapathId.of(switchId.toLong()));
List<MeterEntry> meters = meterEntries.stream().map(OfMeterConverter::toMeterEntry).collect(Collectors.toList());
SwitchMeterEntries response = SwitchMeterEntries.builder().switchId(switchId).meterEntries(meters).build();
sender.accept(response);
} catch (UnsupportedSwitchOperationException e) {
logger.info("Meters not supported: {}", switchId);
sender.accept(new SwitchMeterUnsupported(switchId));
} catch (SwitchNotFoundException e) {
logger.info("Dumping switch meters is unsuccessful. Switch {} not found", switchId);
ErrorData errorData = anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription(switchId.toString()).buildData();
sender.accept(errorData);
} catch (SwitchOperationException e) {
logger.error("Unable to dump meters", e);
ErrorData errorData = anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription("Unable to dump meters").buildData();
sender.accept(errorData);
}
}
use of org.openkilda.floodlight.error.SwitchNotFoundException in project open-kilda by telstra.
the class RecordHandler method dumpRuleManagerMeters.
private void dumpRuleManagerMeters(SwitchId switchId, java.util.function.Consumer<MessageData> sender) {
try {
logger.debug("Get all meters for switch {}", switchId);
ISwitchManager switchManager = context.getSwitchManager();
DatapathId datapathId = DatapathId.of(switchId.toLong());
List<OFMeterConfig> meterEntries = switchManager.dumpMeters(datapathId);
IOFSwitch iofSwitch = switchManager.lookupSwitch(datapathId);
boolean inaccurate = featureDetectorService.detectSwitch(iofSwitch).contains(SwitchFeature.INACCURATE_METER);
List<MeterSpeakerData> meters = meterEntries.stream().map(entry -> org.openkilda.floodlight.converter.rulemanager.OfMeterConverter.INSTANCE.convertToMeterSpeakerData(entry, inaccurate)).collect(Collectors.toList());
MeterDumpResponse response = MeterDumpResponse.builder().switchId(switchId).meterSpeakerData(meters).build();
sender.accept(response);
} catch (UnsupportedSwitchOperationException e) {
logger.info("Meters not supported: {}", switchId);
sender.accept(new SwitchMeterUnsupported(switchId));
} catch (SwitchNotFoundException e) {
logger.info("Dumping switch meters is unsuccessful. Switch {} not found", switchId);
ErrorData errorData = anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription(switchId.toString()).buildData();
sender.accept(errorData);
} catch (SwitchOperationException e) {
logger.error("Unable to dump meters", e);
ErrorData errorData = anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription("Unable to dump meters").buildData();
sender.accept(errorData);
}
}
use of org.openkilda.floodlight.error.SwitchNotFoundException in project open-kilda by telstra.
the class SpeakerCommand method setup.
protected void setup(FloodlightModuleContext moduleContext) throws Exception {
IOFSwitchService ofSwitchManager = moduleContext.getServiceImpl(IOFSwitchService.class);
sessionService = moduleContext.getServiceImpl(SessionService.class);
DatapathId dpId = DatapathId.of(switchId.toLong());
sw = ofSwitchManager.getActiveSwitch(dpId);
if (sw == null) {
throw new SwitchNotFoundException(dpId);
}
}
use of org.openkilda.floodlight.error.SwitchNotFoundException in project open-kilda by telstra.
the class FlowSegmentReport method assembleResponse.
private SpeakerResponse assembleResponse() {
FlowErrorResponseBuilder errorResponse = makeErrorTemplate();
try {
raiseError();
return makeSuccessReply();
} catch (SwitchNotFoundException e) {
errorResponse.errorCode(ErrorCode.SWITCH_UNAVAILABLE);
} catch (SessionErrorResponseException e) {
decodeError(errorResponse, e.getErrorResponse());
} catch (SwitchMissingFlowsException e) {
errorResponse.errorCode(ErrorCode.MISSING_OF_FLOWS);
errorResponse.description(e.getMessage());
} catch (SwitchOperationException e) {
errorResponse.errorCode(ErrorCode.UNKNOWN);
errorResponse.description(e.getMessage());
} catch (Exception e) {
log.error(String.format("Unhandled exception while processing command %s", command), e);
errorResponse.errorCode(ErrorCode.UNKNOWN);
}
FlowErrorResponse response = errorResponse.build();
log.error("Command {} have failed - {} {}", command, response.getErrorCode(), response.getDescription());
return response;
}
use of org.openkilda.floodlight.error.SwitchNotFoundException in project open-kilda by telstra.
the class SwitchManager method dumpMeterById.
/**
* {@inheritDoc}
*/
@Override
public OFMeterConfig dumpMeterById(final DatapathId dpid, final long meterId) throws SwitchOperationException {
OFMeterConfig meterConfig = null;
IOFSwitch sw = lookupSwitch(dpid);
if (sw == null) {
throw new IllegalArgumentException(format("Switch %s was not found", dpid));
}
verifySwitchSupportsMeters(sw);
OFFactory ofFactory = sw.getOFFactory();
OFMeterConfigStatsRequest meterRequest = ofFactory.buildMeterConfigStatsRequest().setMeterId(meterId).build();
try {
ListenableFuture<List<OFMeterConfigStatsReply>> future = sw.writeStatsRequest(meterRequest);
List<OFMeterConfigStatsReply> values = future.get(10, TimeUnit.SECONDS);
if (values != null) {
List<OFMeterConfig> result = values.stream().map(OFMeterConfigStatsReply::getEntries).flatMap(List::stream).collect(toList());
meterConfig = result.size() >= 1 ? result.get(0) : null;
}
} catch (ExecutionException | TimeoutException e) {
logger.error("Could not get meter config stats for {}.", dpid, e);
} catch (InterruptedException e) {
logger.error("Could not get meter config stats for {}.", dpid, e);
Thread.currentThread().interrupt();
throw new SwitchNotFoundException(dpid);
}
return meterConfig;
}
Aggregations