use of org.openkilda.floodlight.error.SwitchOperationException 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.SwitchOperationException 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.SwitchOperationException in project open-kilda by telstra.
the class RecordHandler method processDeleteFlow.
private List<Long> processDeleteFlow(RemoveFlow command, DatapathId dpid) throws SwitchOperationException {
logger.info("Deleting flow {} from switch {}", command.getId(), dpid);
if (command.isCleanUpIngress()) {
context.getSwitchManager().removeIntermediateIngressRule(dpid, command.getCriteria().getInPort());
}
if (command.isCleanUpIngressLldp()) {
context.getSwitchManager().removeLldpInputCustomerFlow(dpid, command.getCriteria().getInPort());
}
if (command.isCleanUpIngressArp()) {
context.getSwitchManager().removeArpInputCustomerFlow(dpid, command.getCriteria().getInPort());
}
DeleteRulesCriteria criteria = Optional.ofNullable(command.getCriteria()).orElseGet(() -> DeleteRulesCriteria.builder().cookie(command.getCookie()).build());
ISwitchManager switchManager = context.getSwitchManager();
List<Long> cookiesOfRemovedRules = switchManager.deleteRulesByCriteria(dpid, command.isMultiTable(), command.getRuleType(), criteria);
if (cookiesOfRemovedRules.isEmpty()) {
logger.warn("No rules were removed by criteria {} for flow {} from switch {}", criteria, command.getId(), dpid);
}
Long meterId = command.getMeterId();
if (meterId != null) {
try {
switchManager.deleteMeter(dpid, meterId);
} catch (UnsupportedOperationException e) {
logger.info("Skip meter {} deletion from switch {}: {}", meterId, dpid, e.getMessage());
} catch (SwitchOperationException e) {
logger.error("Failed to delete meter {} from switch {}: {}", meterId, dpid, e.getMessage());
}
}
return cookiesOfRemovedRules;
}
use of org.openkilda.floodlight.error.SwitchOperationException in project open-kilda by telstra.
the class RecordHandler method processDumpRulesRequest.
private void processDumpRulesRequest(SwitchId switchId, java.util.function.Consumer<MessageData> sender) {
try {
logger.debug("Loading installed rules for switch {}", switchId);
List<OFFlowStatsEntry> flowEntries = context.getSwitchManager().dumpFlowTable(DatapathId.of(switchId.toLong()));
List<FlowEntry> flows = flowEntries.stream().map(OfFlowStatsMapper.INSTANCE::toFlowEntry).collect(Collectors.toList());
SwitchFlowEntries response = SwitchFlowEntries.builder().switchId(switchId).flowEntries(flows).build();
sender.accept(response);
} catch (SwitchOperationException e) {
logger.error("Dumping of rules on switch '{}' was unsuccessful: {}", switchId, e.getMessage());
ErrorData errorData = anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription("The switch was not found when requesting a rules dump.").buildData();
sender.accept(errorData);
}
}
use of org.openkilda.floodlight.error.SwitchOperationException in project open-kilda by telstra.
the class RecordHandler method doDeleteMeter.
private void doDeleteMeter(CommandMessage message, String replyToTopic) {
DeleteMeterRequest request = (DeleteMeterRequest) message.getData();
logger.info("Deleting meter '{}'. Switch: '{}'", request.getMeterId(), request.getSwitchId());
final IKafkaProducerService producerService = getKafkaProducer();
try {
DatapathId dpid = DatapathId.of(request.getSwitchId().toLong());
context.getSwitchManager().deleteMeter(dpid, request.getMeterId());
boolean deleted = context.getSwitchManager().dumpMeters(dpid).stream().noneMatch(config -> config.getMeterId() == request.getMeterId());
DeleteMeterResponse response = new DeleteMeterResponse(deleted);
InfoMessage infoMessage = new InfoMessage(response, System.currentTimeMillis(), message.getCorrelationId());
producerService.sendMessageAndTrack(replyToTopic, message.getCorrelationId(), infoMessage);
} catch (SwitchOperationException e) {
logger.error("Deleting meter '{}' from switch '{}' was unsuccessful: {}", request.getMeterId(), request.getSwitchId(), e.getMessage());
anError(ErrorType.DATA_INVALID).withMessage(e.getMessage()).withDescription(request.getSwitchId().toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
}
}
Aggregations