use of org.openkilda.messaging.info.flow.PathDiscrepancyEntity in project open-kilda by telstra.
the class FlowValidationService method compare.
private FlowValidationResponse compare(Map<SwitchId, List<SimpleSwitchRule>> rulesPerSwitch, List<SimpleSwitchRule> rulesFromDb, String flowId, int totalSwitchRules, int metersCount) throws SwitchNotFoundException {
List<PathDiscrepancyEntity> discrepancies = new ArrayList<>();
List<Long> pktCounts = new ArrayList<>();
List<Long> byteCounts = new ArrayList<>();
boolean ingressMirrorFlowIsPresent = false;
boolean egressMirrorFlowIsPresent = false;
for (SimpleSwitchRule simpleRule : rulesFromDb) {
discrepancies.addAll(simpleSwitchRuleComparator.findDiscrepancy(simpleRule, rulesPerSwitch.get(simpleRule.getSwitchId()), pktCounts, byteCounts));
if (new FlowSegmentCookie(simpleRule.getCookie()).isMirror() && simpleRule.isIngressRule()) {
ingressMirrorFlowIsPresent = true;
}
if (new FlowSegmentCookie(simpleRule.getCookie()).isMirror() && simpleRule.isEgressRule()) {
egressMirrorFlowIsPresent = true;
}
}
int flowMetersCount = (int) rulesFromDb.stream().filter(rule -> rule.getMeterId() != null).count();
return FlowValidationResponse.builder().flowId(flowId).discrepancies(discrepancies).asExpected(discrepancies.isEmpty()).pktCounts(pktCounts).byteCounts(byteCounts).flowRulesTotal(rulesFromDb.size()).switchRulesTotal(totalSwitchRules).flowMetersTotal(flowMetersCount).switchMetersTotal(metersCount).ingressMirrorFlowIsPresent(ingressMirrorFlowIsPresent).egressMirrorFlowIsPresent(egressMirrorFlowIsPresent).build();
}
use of org.openkilda.messaging.info.flow.PathDiscrepancyEntity 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.flow.PathDiscrepancyEntity in project open-kilda by telstra.
the class SimpleSwitchRuleComparator method findDiscrepancy.
/**
* Compare expected and actual rules and gather discrepancy list.
*/
public List<PathDiscrepancyEntity> findDiscrepancy(SimpleSwitchRule expected, List<SimpleSwitchRule> actual, List<Long> pktCounts, List<Long> byteCounts) throws SwitchNotFoundException {
List<PathDiscrepancyEntity> discrepancies = new ArrayList<>();
SimpleSwitchRule matched = findMatched(expected, actual);
if (matched == null) {
discrepancies.add(new PathDiscrepancyEntity(String.valueOf(expected), "all", String.valueOf(expected), ""));
pktCounts.add(-1L);
byteCounts.add(-1L);
} else {
discrepancies.addAll(getRuleDiscrepancies(expected, matched));
pktCounts.add(matched.getPktCount());
byteCounts.add(matched.getByteCount());
}
return discrepancies;
}
use of org.openkilda.messaging.info.flow.PathDiscrepancyEntity in project open-kilda by telstra.
the class SimpleSwitchRuleComparator method getRuleDiscrepancies.
private List<PathDiscrepancyEntity> getRuleDiscrepancies(SimpleSwitchRule expected, SimpleSwitchRule matched) throws SwitchNotFoundException {
List<PathDiscrepancyEntity> discrepancies = new ArrayList<>();
if (matched.getCookie() != expected.getCookie()) {
discrepancies.add(new PathDiscrepancyEntity(expected.toString(), "cookie", String.valueOf(expected.getCookie()), String.valueOf(matched.getCookie())));
}
if (matched.getInPort() != expected.getInPort()) {
discrepancies.add(new PathDiscrepancyEntity(expected.toString(), "inPort", String.valueOf(expected.getInPort()), String.valueOf(matched.getInPort())));
}
if (matched.getInVlan() != expected.getInVlan()) {
discrepancies.add(new PathDiscrepancyEntity(expected.toString(), "inVlan", String.valueOf(expected.getInVlan()), String.valueOf(matched.getInVlan())));
}
if (matched.getTunnelId() != expected.getTunnelId()) {
discrepancies.add(new PathDiscrepancyEntity(expected.toString(), "tunnelId", String.valueOf(expected.getTunnelId()), String.valueOf(matched.getTunnelId())));
}
if (matched.getOutPort() != expected.getOutPort()) {
discrepancies.add(new PathDiscrepancyEntity(expected.toString(), "outPort", String.valueOf(expected.getOutPort()), String.valueOf(matched.getOutPort())));
}
if (!Objects.equals(matched.getOutVlan(), expected.getOutVlan())) {
discrepancies.add(new PathDiscrepancyEntity(expected.toString(), "outVlan", String.valueOf(expected.getOutVlan()), String.valueOf(matched.getOutVlan())));
}
// meters on OF_12 switches are not supported, so skip them.
if ((matched.getVersion() == null || matched.getVersion().compareTo("OF_12") > 0) && !(matched.getMeterId() == null && expected.getMeterId() == null)) {
if (!Objects.equals(matched.getMeterId(), expected.getMeterId())) {
discrepancies.add(new PathDiscrepancyEntity(expected.toString(), "meterId", String.valueOf(expected.getMeterId()), String.valueOf(matched.getMeterId())));
} else {
Switch sw = switchRepository.findById(expected.getSwitchId()).orElseThrow(() -> new SwitchNotFoundException(expected.getSwitchId()));
boolean isESwitch = Switch.isNoviflowESwitch(sw.getOfDescriptionManufacturer(), sw.getOfDescriptionHardware());
if (!equalsRate(matched.getMeterRate(), expected.getMeterRate(), isESwitch)) {
discrepancies.add(new PathDiscrepancyEntity(expected.toString(), "meterRate", String.valueOf(expected.getMeterRate()), String.valueOf(matched.getMeterRate())));
}
if (!equalsBurstSize(matched.getMeterBurstSize(), expected.getMeterBurstSize(), isESwitch)) {
discrepancies.add(new PathDiscrepancyEntity(expected.toString(), "meterBurstSize", String.valueOf(expected.getMeterBurstSize()), String.valueOf(matched.getMeterBurstSize())));
}
if (!Arrays.equals(matched.getMeterFlags(), expected.getMeterFlags())) {
discrepancies.add(new PathDiscrepancyEntity(expected.toString(), "meterFlags", Arrays.toString(expected.getMeterFlags()), Arrays.toString(matched.getMeterFlags())));
}
}
}
if (matched.getGroupId() != expected.getGroupId()) {
discrepancies.add(new PathDiscrepancyEntity(expected.toString(), "groupId", String.valueOf(expected.getGroupId()), String.valueOf(matched.getGroupId())));
}
if (!Objects.equals(matched.getGroupBuckets(), expected.getGroupBuckets())) {
discrepancies.add(new PathDiscrepancyEntity(expected.toString(), "groupBuckets", String.valueOf(expected.getGroupBuckets()), String.valueOf(matched.getGroupBuckets())));
}
return discrepancies;
}
Aggregations