use of org.openkilda.messaging.info.meter.SwitchMeterEntries 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.SwitchMeterEntries 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.SwitchMeterEntries in project open-kilda by telstra.
the class YFlowValidationService method validateYFlowResources.
/**
* Validate y-flow.
*/
public YFlowDiscrepancyDto validateYFlowResources(String yFlowId, List<SwitchFlowEntries> actualSwitchFlowEntries, List<SwitchMeterEntries> actualSwitchMeterEntries) throws FlowNotFoundException, SwitchNotFoundException {
Map<SwitchId, List<SimpleSwitchRule>> actualRules = new HashMap<>();
for (SwitchFlowEntries switchRulesEntries : actualSwitchFlowEntries) {
SwitchMeterEntries switchMeters = actualSwitchMeterEntries.stream().filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())).findFirst().orElse(null);
List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter.convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters, null);
actualRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules);
}
YFlow yFlow = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowNotFoundException(yFlowId));
List<SimpleSwitchRule> expectedRules = new ArrayList<>();
for (YSubFlow subFlow : yFlow.getSubFlows()) {
Flow flow = subFlow.getFlow();
expectedRules.addAll(buildSimpleSwitchRules(flow, yFlow.getSharedEndpoint().getSwitchId(), yFlow.getSharedEndpointMeterId(), flow.getForwardPathId(), flow.getReversePathId(), yFlow.getYPoint(), yFlow.getMeterId()));
if (flow.isAllocateProtectedPath()) {
if (flow.getProtectedForwardPathId() != null && flow.getProtectedReversePathId() != null) {
expectedRules.addAll(buildSimpleSwitchRules(flow, yFlow.getSharedEndpoint().getSwitchId(), yFlow.getSharedEndpointMeterId(), flow.getProtectedForwardPathId(), flow.getProtectedReversePathId(), yFlow.getProtectedPathYPoint(), yFlow.getProtectedPathMeterId()));
} else {
log.warn("Sub-flow {} of y-flow {} has no expected protected paths", flow.getFlowId(), yFlowId);
}
}
}
List<PathDiscrepancyEntity> discrepancies = new ArrayList<>();
for (SimpleSwitchRule simpleRule : expectedRules) {
discrepancies.addAll(simpleSwitchRuleComparator.findDiscrepancy(simpleRule, actualRules.get(simpleRule.getSwitchId())));
}
return YFlowDiscrepancyDto.builder().discrepancies(discrepancies).asExpected(discrepancies.isEmpty()).build();
}
use of org.openkilda.messaging.info.meter.SwitchMeterEntries in project open-kilda by telstra.
the class RecordHandler method doModifyMeterRequest.
private void doModifyMeterRequest(CommandMessage message) {
MeterModifyCommandRequest request = (MeterModifyCommandRequest) message.getData();
final IKafkaProducerService producerService = getKafkaProducer();
String replyToTopic = context.getKafkaNbWorkerTopic();
SwitchId switchId = request.getSwitchId();
DatapathId datapathId = DatapathId.of(switchId.toLong());
long meterId = request.getMeterId();
ISwitchManager switchManager = context.getSwitchManager();
try {
switchManager.modifyMeterForFlow(datapathId, meterId, request.getBandwidth());
MeterEntry meterEntry = OfMeterConverter.toMeterEntry(switchManager.dumpMeterById(datapathId, meterId));
SwitchMeterEntries response = SwitchMeterEntries.builder().switchId(switchId).meterEntries(ImmutableList.of(meterEntry)).build();
InfoMessage infoMessage = new InfoMessage(response, message.getTimestamp(), message.getCorrelationId());
producerService.sendMessageAndTrack(replyToTopic, message.getCorrelationId(), infoMessage);
} catch (UnsupportedSwitchOperationException e) {
String messageString = String.format("Not supported: %s", new SwitchId(e.getDpId().getLong()));
logger.error(messageString, e);
anError(ErrorType.PARAMETERS_INVALID).withMessage(e.getMessage()).withDescription(messageString).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
} catch (SwitchNotFoundException e) {
logger.error("Update switch meters is unsuccessful. Switch {} not found", new SwitchId(e.getDpId().getLong()));
anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription(new SwitchId(e.getDpId().getLong()).toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
} catch (SwitchOperationException e) {
String messageString = "Unable to update meter";
logger.error(messageString, e);
anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription(messageString).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
}
}
use of org.openkilda.messaging.info.meter.SwitchMeterEntries in project open-kilda by telstra.
the class FlowValidationFsm method receivedMeters.
protected void receivedMeters(State from, State to, Event event, Object context) {
SwitchMeterEntries switchMeterEntries = (SwitchMeterEntries) context;
log.info("Switch meters received for switch {}", switchMeterEntries.getSwitchId());
receivedMeters.add(switchMeterEntries);
awaitingMeters--;
checkOfCompleteDataCollection();
}
Aggregations