use of org.openkilda.messaging.info.rule.SwitchFlowEntries in project open-kilda by telstra.
the class RecordHandler method doDumpRulesRequest.
private void doDumpRulesRequest(final CommandMessage message) {
DumpRulesRequest request = (DumpRulesRequest) message.getData();
final String switchId = request.getSwitchId();
logger.debug("Loading installed rules for switch {}", switchId);
OFFlowStatsReply reply = context.getSwitchManager().dumpFlowTable(DatapathId.of(switchId));
List<FlowEntry> flows = reply.getEntries().stream().map(OFFlowStatsConverter::toFlowEntry).collect(Collectors.toList());
SwitchFlowEntries response = SwitchFlowEntries.builder().switchId(switchId).flowEntries(flows).build();
InfoMessage infoMessage = new InfoMessage(response, message.getTimestamp(), message.getCorrelationId());
context.getKafkaProducer().postMessage(TOPO_ENG_TOPIC, infoMessage);
}
use of org.openkilda.messaging.info.rule.SwitchFlowEntries 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.rule.SwitchFlowEntries 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.messaging.info.rule.SwitchFlowEntries 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.rule.SwitchFlowEntries in project open-kilda by telstra.
the class FlowValidationService method validateFlow.
/**
* Validate flow.
*/
public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries, List<SwitchGroupEntries> switchGroupEntries) throws FlowNotFoundException, SwitchNotFoundException {
Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>();
int rulesCount = 0;
int metersCount = 0;
for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) {
SwitchMeterEntries switchMeters = switchMeterEntries.stream().filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())).findFirst().orElse(null);
SwitchGroupEntries switchGroup = switchGroupEntries.stream().filter(groupEntries -> switchRulesEntries.getSwitchId().equals(groupEntries.getSwitchId())).findFirst().orElse(null);
List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter.convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters, switchGroup);
switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules);
rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()).map(List::size).orElse(0);
metersCount += Optional.ofNullable(switchMeters).map(SwitchMeterEntries::getMeterEntries).map(List::size).orElse(0);
}
Optional<Flow> foundFlow = flowRepository.findById(flowId);
if (!foundFlow.isPresent()) {
throw new FlowNotFoundException(flowId);
}
Flow flow = foundFlow.get();
if (flow.getForwardPath() == null) {
throw new InvalidPathException(flowId, "Forward path was not returned.");
}
if (flow.getReversePath() == null) {
throw new InvalidPathException(flowId, "Reverse path was not returned.");
}
List<FlowValidationResponse> flowValidationResponse = new ArrayList<>();
List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath());
flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount));
List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath());
flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount));
if (flow.getProtectedForwardPath() != null) {
List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath());
flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount));
}
if (flow.getProtectedReversePath() != null) {
List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath());
flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount));
}
return flowValidationResponse;
}
Aggregations