Search in sources :

Example 1 with EncapsulationId

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;
}
Also used : SimpleSwitchRule(org.openkilda.wfm.share.utils.rule.validation.SimpleSwitchRule) EncapsulationId(org.openkilda.model.EncapsulationId) ArrayList(java.util.ArrayList) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath)

Example 2 with EncapsulationId

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;
}
Also used : PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) Flow(org.openkilda.model.Flow) SwitchFlowEntries(org.openkilda.messaging.info.rule.SwitchFlowEntries) FlowSideAdapter(org.openkilda.adapter.FlowSideAdapter) SwitchGroupEntries(org.openkilda.messaging.info.rule.SwitchGroupEntries) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) FlowEndpoint(org.openkilda.model.FlowEndpoint) SimpleGroupBucket(org.openkilda.wfm.share.utils.rule.validation.SimpleSwitchRule.SimpleGroupBucket) Iterator(java.util.Iterator) GroupBucket(org.openkilda.messaging.info.rule.GroupBucket) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) SimpleSwitchRuleBuilder(org.openkilda.wfm.share.utils.rule.validation.SimpleSwitchRule.SimpleSwitchRuleBuilder) Collection(java.util.Collection) GroupEntry(org.openkilda.messaging.info.rule.GroupEntry) Collectors(java.util.stream.Collectors) SwitchMeterEntries(org.openkilda.messaging.info.meter.SwitchMeterEntries) FlowApplyActions(org.openkilda.messaging.info.rule.FlowApplyActions) Objects(java.util.Objects) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) FlowSetFieldAction(org.openkilda.messaging.info.rule.FlowSetFieldAction) NumberUtils(org.apache.commons.lang3.math.NumberUtils) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) Optional(java.util.Optional) Meter(org.openkilda.model.Meter) Comparator(java.util.Comparator) Collections(java.util.Collections) EncapsulationId(org.openkilda.model.EncapsulationId) FlowEndpoint(org.openkilda.model.FlowEndpoint) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) FlowSideAdapter(org.openkilda.adapter.FlowSideAdapter) PathSegment(org.openkilda.model.PathSegment) FlowEndpoint(org.openkilda.model.FlowEndpoint)

Example 3 with EncapsulationId

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;
}
Also used : PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) Flow(org.openkilda.model.Flow) SwitchFlowEntries(org.openkilda.messaging.info.rule.SwitchFlowEntries) FlowSideAdapter(org.openkilda.adapter.FlowSideAdapter) SwitchGroupEntries(org.openkilda.messaging.info.rule.SwitchGroupEntries) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) FlowEndpoint(org.openkilda.model.FlowEndpoint) SimpleGroupBucket(org.openkilda.wfm.share.utils.rule.validation.SimpleSwitchRule.SimpleGroupBucket) Iterator(java.util.Iterator) GroupBucket(org.openkilda.messaging.info.rule.GroupBucket) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) SimpleSwitchRuleBuilder(org.openkilda.wfm.share.utils.rule.validation.SimpleSwitchRule.SimpleSwitchRuleBuilder) Collection(java.util.Collection) GroupEntry(org.openkilda.messaging.info.rule.GroupEntry) Collectors(java.util.stream.Collectors) SwitchMeterEntries(org.openkilda.messaging.info.meter.SwitchMeterEntries) FlowApplyActions(org.openkilda.messaging.info.rule.FlowApplyActions) Objects(java.util.Objects) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) FlowSetFieldAction(org.openkilda.messaging.info.rule.FlowSetFieldAction) NumberUtils(org.apache.commons.lang3.math.NumberUtils) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) Optional(java.util.Optional) Meter(org.openkilda.model.Meter) Comparator(java.util.Comparator) Collections(java.util.Collections) EncapsulationId(org.openkilda.model.EncapsulationId) FlowEndpoint(org.openkilda.model.FlowEndpoint) ArrayList(java.util.ArrayList) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) FlowSideAdapter(org.openkilda.adapter.FlowSideAdapter)

Aggregations

ArrayList (java.util.ArrayList)3 EncapsulationId (org.openkilda.model.EncapsulationId)3 FlowPath (org.openkilda.model.FlowPath)3 PathSegment (org.openkilda.model.PathSegment)3 Lists (com.google.common.collect.Lists)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Comparator (java.util.Comparator)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 NumberUtils (org.apache.commons.lang3.math.NumberUtils)2 FlowSideAdapter (org.openkilda.adapter.FlowSideAdapter)2 SwitchMeterEntries (org.openkilda.messaging.info.meter.SwitchMeterEntries)2 FlowApplyActions (org.openkilda.messaging.info.rule.FlowApplyActions)2 FlowEntry (org.openkilda.messaging.info.rule.FlowEntry)2 FlowSetFieldAction (org.openkilda.messaging.info.rule.FlowSetFieldAction)2 GroupBucket (org.openkilda.messaging.info.rule.GroupBucket)2