use of org.openkilda.messaging.info.meter.SwitchMeterUnsupported in project open-kilda by telstra.
the class OnReceivedYFlowResourcesAction method perform.
@Override
public void perform(State from, State to, Event event, YFlowValidationContext context, YFlowValidationFsm stateMachine) {
MessageData data = context.getSpeakerResponse();
if (data instanceof SwitchFlowEntries) {
SwitchFlowEntries switchFlowEntries = (SwitchFlowEntries) data;
log.info("Switch rules received for switch {}", switchFlowEntries.getSwitchId());
stateMachine.getReceivedRules().add(switchFlowEntries);
stateMachine.setAwaitingRules(stateMachine.getAwaitingRules() - 1);
checkOfCompleteDataCollection(stateMachine);
} else if (data instanceof SwitchMeterEntries) {
SwitchMeterEntries switchMeterEntries = (SwitchMeterEntries) data;
log.info("Switch meters received for switch {}", switchMeterEntries.getSwitchId());
stateMachine.getReceivedMeters().add(switchMeterEntries);
stateMachine.setAwaitingMeters(stateMachine.getAwaitingMeters() - 1);
checkOfCompleteDataCollection(stateMachine);
} else if (data instanceof SwitchMeterUnsupported) {
SwitchMeterUnsupported meterUnsupported = (SwitchMeterUnsupported) data;
log.info("Meters unsupported for switch {}", meterUnsupported.getSwitchId());
stateMachine.getReceivedMeters().add(SwitchMeterEntries.builder().switchId(meterUnsupported.getSwitchId()).meterEntries(Collections.emptyList()).build());
stateMachine.setAwaitingMeters(stateMachine.getAwaitingMeters() - 1);
checkOfCompleteDataCollection(stateMachine);
} else if (data instanceof ErrorData) {
ErrorData errorData = (ErrorData) data;
String errorMessage = format("%s : %s", errorData.getErrorMessage(), errorData.getErrorDescription());
stateMachine.fireError(errorMessage);
} else {
String errorMessage = format("Unhandled message : %s", data);
stateMachine.fireError(errorMessage);
}
}
use of org.openkilda.messaging.info.meter.SwitchMeterUnsupported in project open-kilda by telstra.
the class FlowValidationHubService method handleAsyncResponse.
/**
* Handles async response from worker.
*
* @param key command identifier.
*/
public void handleAsyncResponse(@NonNull String key, @NonNull MessageData data) throws UnknownKeyException {
log.debug("Received command response {}", data);
FlowValidationFsm fsm = fsmRegister.getFsmByKey(key).orElseThrow(() -> new UnknownKeyException(key));
if (data instanceof SwitchFlowEntries) {
fsmExecutor.fire(fsm, Event.RULES_RECEIVED, data);
} else if (data instanceof SwitchMeterEntries) {
fsmExecutor.fire(fsm, Event.METERS_RECEIVED, data);
} else if (data instanceof SwitchMeterUnsupported) {
SwitchMeterUnsupported meterUnsupported = (SwitchMeterUnsupported) data;
log.info("Key: {}; Meters unsupported for switch '{};", key, meterUnsupported.getSwitchId());
fsmExecutor.fire(fsm, Event.METERS_RECEIVED, SwitchMeterEntries.builder().switchId(meterUnsupported.getSwitchId()).meterEntries(Collections.emptyList()).build());
} else if (data instanceof SwitchGroupEntries) {
fsmExecutor.fire(fsm, Event.GROUPS_RECEIVED, data);
} else if (data instanceof ErrorData) {
fsmExecutor.fire(fsm, Event.ERROR, data);
} else {
log.warn("Key: {}; Unhandled message {}", key, data);
}
removeIfFinished(fsm, key);
}
use of org.openkilda.messaging.info.meter.SwitchMeterUnsupported in project open-kilda by telstra.
the class SwitchServiceImpl method getMeters.
@Override
public CompletableFuture<SwitchMeterEntries> getMeters(SwitchId switchId) {
String requestId = RequestCorrelationId.getId();
CommandMessage dumpCommand = new CommandMessage(new DumpMetersRequest(switchId), System.currentTimeMillis(), requestId);
return messagingChannel.sendAndGet(floodlightTopic, dumpCommand).thenApply(infoData -> {
if (infoData instanceof SwitchMeterEntries) {
return (SwitchMeterEntries) infoData;
} else if (infoData instanceof SwitchMeterUnsupported) {
return SwitchMeterEntries.builder().switchId(switchId).build();
} else {
throw new IllegalArgumentException("Unhandled meters response for switch " + switchId);
}
});
}
use of org.openkilda.messaging.info.meter.SwitchMeterUnsupported 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.messaging.info.meter.SwitchMeterUnsupported 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);
}
}
Aggregations