use of org.openkilda.messaging.info.meter.MeterEntry 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.MeterEntry 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.MeterEntry in project open-kilda by telstra.
the class YFlowSwitchFlowEntriesBuilder method getMeterEntries.
/**
* Construct a set of {@link MeterEntry} that corresponds to the builder's y-flow.
*/
public Map<SwitchId, Collection<MeterEntry>> getMeterEntries() {
MultiValuedMap<SwitchId, MeterEntry> meterEntries = new ArrayListValuedHashMap<>();
yFlow.getSubFlows().forEach(subFlow -> {
Flow flow = subFlow.getFlow();
SwitchFlowEntriesBuilder builder = new SwitchFlowEntriesBuilder(flow);
builder.getSwitchMeterEntries().forEach(entries -> meterEntries.putAll(entries.getSwitchId(), entries.getMeterEntries()));
FlowPath forwardPath = flow.getForwardPath();
meterEntries.put(flow.getSrcSwitchId(), MeterEntry.builder().meterId(yFlow.getSharedEndpointMeterId().getValue()).rate(forwardPath.getBandwidth()).burstSize(Meter.calculateBurstSize(forwardPath.getBandwidth(), MIN_BURST_SIZE_IN_KBITS, BURST_COEFFICIENT, "")).flags(Meter.getMeterKbpsFlags()).build());
if (!yFlow.getYPoint().equals(flow.getSrcSwitchId())) {
FlowPath reversePath = flow.getReversePath();
meterEntries.put(yFlow.getYPoint(), MeterEntry.builder().meterId(yFlow.getMeterId().getValue()).rate(reversePath.getBandwidth()).burstSize(Meter.calculateBurstSize(reversePath.getBandwidth(), MIN_BURST_SIZE_IN_KBITS, BURST_COEFFICIENT, "")).flags(Meter.getMeterKbpsFlags()).build());
}
if (yFlow.isAllocateProtectedPath() && yFlow.getProtectedPathYPoint() != null && !yFlow.getProtectedPathYPoint().equals(flow.getSrcSwitchId())) {
FlowPath reversePath = flow.getProtectedReversePath();
meterEntries.put(yFlow.getProtectedPathYPoint(), MeterEntry.builder().meterId(yFlow.getProtectedPathMeterId().getValue()).rate(reversePath.getBandwidth()).burstSize(Meter.calculateBurstSize(reversePath.getBandwidth(), MIN_BURST_SIZE_IN_KBITS, BURST_COEFFICIENT, "")).flags(Meter.getMeterKbpsFlags()).build());
}
});
return meterEntries.asMap();
}
use of org.openkilda.messaging.info.meter.MeterEntry in project open-kilda by telstra.
the class YFlowValidationHubServiceTest method shouldValidateAndFailIfSubFlowHasMissingRule.
@Test
public void shouldValidateAndFailIfSubFlowHasMissingRule() throws DuplicateKeyException {
// given
String yFlowId = "test_y_flow_1";
YFlow yFlow = createYFlowViaTransit(yFlowId);
YSubFlow failedSubFlow = yFlow.getSubFlows().stream().findFirst().orElseThrow(IllegalStateException::new);
Flow failedFlow = failedSubFlow.getFlow();
YFlowSwitchFlowEntriesBuilder flowEntriesBuilder = new YFlowSwitchFlowEntriesBuilder(yFlow, persistenceManager.getRepositoryFactory().createTransitVlanRepository(), persistenceManager.getRepositoryFactory().createVxlanRepository());
Map<SwitchId, Collection<FlowEntry>> flowEntries = flowEntriesBuilder.getFlowEntries();
flowEntries.forEach((s, f) -> f.removeIf(entry -> entry.getCookie() == failedFlow.getForwardPath().getCookie().getValue()));
Map<SwitchId, Collection<MeterEntry>> meterEntries = flowEntriesBuilder.getMeterEntries();
Map<SwitchId, Collection<GroupEntry>> groupEntries = flowEntriesBuilder.getGroupEntries();
YFlowValidationHubService service = makeYFlowValidationHubService();
service.handleRequest(yFlow.getYFlowId(), new CommandContext(), yFlow.getYFlowId());
// when
handleSpeakerRequests(service, yFlowId, flowEntries, meterEntries, groupEntries);
// then
YFlowValidationResponse response = getNorthboundResponse(yFlowValidationHubCarrier);
assertFalse(response.isAsExpected());
assertFalse(response.getYFlowValidationResult().isAsExpected());
response.getSubFlowValidationResults().forEach(result -> assertTrue(result.getFlowId().equals(failedFlow.getFlowId()) || result.getAsExpected()));
assertEquals(1, response.getSubFlowValidationResults().stream().filter(r -> !r.getAsExpected()).count());
}
Aggregations