use of org.openkilda.model.EncapsulationId in project open-kilda by telstra.
the class YFlowValidationService method buildSimpleSwitchRules.
private List<SimpleSwitchRule> buildSimpleSwitchRules(Flow subFlow, SwitchId sharedEndpoint, MeterId sharedMeterId, PathId forwardId, PathId reverseId, SwitchId yPoint, MeterId yMeterId) {
EncapsulationId encapsulationId = flowResourcesManager.getEncapsulationResources(forwardId, reverseId, subFlow.getEncapsulationType()).map(EncapsulationResources::getEncapsulation).orElseThrow(() -> new IllegalStateException(String.format("Encapsulation id was not found, pathId: %s", forwardId)));
FlowPath forward = subFlow.getPath(forwardId).orElseThrow(() -> new IllegalStateException(String.format("Path was not found, pathId: %s", forwardId)));
FlowPath reverse = subFlow.getPath(reverseId).orElseThrow(() -> new IllegalStateException(String.format("Path was not found, pathId: %s", reverseId)));
if (reverse.getSrcSwitchId().equals(sharedEndpoint)) {
FlowPath tmp = reverse;
reverse = forward;
forward = tmp;
}
Collection<SimpleSwitchRule> ingressRules = simpleSwitchRuleConverter.buildIngressSimpleSwitchRules(subFlow, forward, encapsulationId, flowMeterMinBurstSizeInKbits, flowMeterBurstCoefficient);
// TODO: apply shared endpoint y-flow cookie flags & sharedMeterId
List<SimpleSwitchRule> result = new ArrayList<>(ingressRules);
List<PathSegment> orderedSegments = reverse.getSegments().stream().sorted(Comparator.comparingInt(PathSegment::getSeqId)).collect(Collectors.toList());
for (int i = 1; i < orderedSegments.size(); i++) {
PathSegment srcPathSegment = orderedSegments.get(i - 1);
PathSegment dstPathSegment = orderedSegments.get(i);
if (dstPathSegment.getSrcSwitch().equals(yPoint)) {
SimpleSwitchRule yPointTransitRules = simpleSwitchRuleConverter.buildTransitSimpleSwitchRule(subFlow, reverse, srcPathSegment, dstPathSegment, encapsulationId);
// TODO: apply shared endpoint y-flow cookie flags & yMeterId
result.add(yPointTransitRules);
break;
}
}
return result;
}
use of org.openkilda.model.EncapsulationId in project open-kilda by telstra.
the class SimpleSwitchRuleConverter method buildIngressSimpleSwitchRules.
/**
* Build ingress rules ({@link SimpleSwitchRule}) for provided {@link FlowPath}.
*/
public List<SimpleSwitchRule> buildIngressSimpleSwitchRules(Flow flow, FlowPath flowPath, EncapsulationId encapsulationId, long flowMeterMinBurstSizeInKbits, double flowMeterBurstCoefficient) {
boolean forward = flow.isForward(flowPath);
int inPort = forward ? flow.getSrcPort() : flow.getDestPort();
int outPort = forward ? flow.getDestPort() : flow.getSrcPort();
SimpleSwitchRule rule = SimpleSwitchRule.builder().switchId(flowPath.getSrcSwitchId()).cookie(flowPath.getCookie().getValue()).inPort(inPort).meterId(flowPath.getMeterId() != null ? flowPath.getMeterId().getValue() : null).meterRate(flow.getBandwidth()).meterBurstSize(Meter.calculateBurstSize(flow.getBandwidth(), flowMeterMinBurstSizeInKbits, flowMeterBurstCoefficient, flowPath.getSrcSwitch().getDescription())).meterFlags(Meter.getMeterKbpsFlags()).ingressRule(true).build();
FlowSideAdapter ingress = FlowSideAdapter.makeIngressAdapter(flow, flowPath);
FlowEndpoint endpoint = ingress.getEndpoint();
if (flowPath.isSrcWithMultiTable()) {
// in multi-table mode actual ingress rule will match port+inner_vlan+metadata(outer_vlan)
if (FlowEndpoint.isVlanIdSet(endpoint.getInnerVlanId())) {
rule.setInVlan(endpoint.getInnerVlanId());
}
} else {
rule.setInVlan(endpoint.getOuterVlanId());
}
int transitVlan = 0;
int vni = 0;
if (flow.isOneSwitchFlow()) {
FlowEndpoint egressEndpoint = FlowSideAdapter.makeEgressAdapter(flow, flowPath).getEndpoint();
rule.setOutPort(outPort);
rule.setOutVlan(calcVlanSetSequence(ingress, flowPath, egressEndpoint.getVlanStack()));
} else {
PathSegment ingressSegment = flowPath.getSegments().stream().filter(segment -> segment.getSrcSwitchId().equals(flowPath.getSrcSwitchId())).findAny().orElseThrow(() -> new IllegalStateException(String.format("PathSegment was not found for ingress flow rule, flowId: %s", flow.getFlowId())));
outPort = ingressSegment.getSrcPort();
rule.setOutPort(outPort);
if (flow.getEncapsulationType().equals(FlowEncapsulationType.TRANSIT_VLAN)) {
transitVlan = encapsulationId.getEncapsulationId();
rule.setOutVlan(calcVlanSetSequence(ingress, flowPath, Collections.singletonList(transitVlan)));
} else if (flow.getEncapsulationType().equals(FlowEncapsulationType.VXLAN)) {
vni = encapsulationId.getEncapsulationId();
rule.setTunnelId(vni);
}
}
List<SimpleSwitchRule> rules = Lists.newArrayList(rule);
if (ingress.isLooped() && !flowPath.isProtected()) {
rules.add(buildIngressLoopSimpleSwitchRule(rule, flowPath, ingress));
}
Optional<FlowMirrorPoints> foundFlowMirrorPoints = flowPath.getFlowMirrorPointsSet().stream().filter(mirrorPoints -> mirrorPoints.getMirrorSwitchId().equals(flowPath.getSrcSwitchId())).findFirst();
if (foundFlowMirrorPoints.isPresent()) {
FlowMirrorPoints flowMirrorPoints = foundFlowMirrorPoints.get();
SimpleSwitchRule mirrorRule = rule.toBuilder().outPort(0).tunnelId(0).cookie(flowPath.getCookie().toBuilder().mirror(true).build().getValue()).groupId(flowMirrorPoints.getMirrorGroupId().intValue()).groupBuckets(mapGroupBuckets(flowMirrorPoints.getMirrorPaths(), outPort, transitVlan, vni)).build();
if (!flow.isOneSwitchFlow()) {
mirrorRule.setOutVlan(Collections.emptyList());
}
rules.add(mirrorRule);
}
return rules;
}
use of org.openkilda.model.EncapsulationId in project open-kilda by telstra.
the class SimpleSwitchRuleConverter method buildEgressSimpleSwitchRules.
private List<SimpleSwitchRule> buildEgressSimpleSwitchRules(Flow flow, FlowPath flowPath, PathSegment egressSegment, EncapsulationId encapsulationId) {
List<SimpleSwitchRule> rules = new ArrayList<>();
FlowSideAdapter egressAdapter = FlowSideAdapter.makeEgressAdapter(flow, flowPath);
FlowEndpoint endpoint = egressAdapter.getEndpoint();
SimpleSwitchRule rule = SimpleSwitchRule.builder().switchId(flowPath.getDestSwitchId()).outPort(endpoint.getPortNumber()).inPort(egressSegment.getDestPort()).cookie(flowPath.getCookie().getValue()).egressRule(true).build();
if (flow.getEncapsulationType().equals(FlowEncapsulationType.TRANSIT_VLAN)) {
rule.setInVlan(encapsulationId.getEncapsulationId());
rule.setOutVlan(calcVlanSetSequence(Collections.singletonList(encapsulationId.getEncapsulationId()), endpoint.getVlanStack()));
} else if (flow.getEncapsulationType().equals(FlowEncapsulationType.VXLAN)) {
rule.setTunnelId(encapsulationId.getEncapsulationId());
rule.setOutVlan(calcVlanSetSequence(Collections.emptyList(), endpoint.getVlanStack()));
}
if (egressAdapter.isLooped() && !flowPath.isProtected()) {
rules.add(buildTransitLoopRuleForEgressSwitch(rule, flowPath));
}
rules.add(rule);
Optional<FlowMirrorPoints> foundFlowMirrorPoints = flowPath.getFlowMirrorPointsSet().stream().filter(mirrorPoints -> mirrorPoints.getMirrorSwitchId().equals(egressSegment.getDestSwitchId())).findFirst();
if (foundFlowMirrorPoints.isPresent()) {
FlowMirrorPoints flowMirrorPoints = foundFlowMirrorPoints.get();
rules.add(rule.toBuilder().outPort(0).cookie(flowPath.getCookie().toBuilder().mirror(true).build().getValue()).groupId(flowMirrorPoints.getMirrorGroupId().intValue()).groupBuckets(mapGroupBuckets(flowMirrorPoints.getMirrorPaths(), endpoint.getPortNumber(), 0, 0)).build());
}
return rules;
}
Aggregations