Search in sources :

Example 11 with FlowMirrorPoints

use of org.openkilda.model.FlowMirrorPoints in project open-kilda by telstra.

the class EgressMirrorRuleGeneratorTest method buildMirrorPoints.

private static FlowMirrorPoints buildMirrorPoints(Switch sw) {
    FlowMirrorPoints mirrorPoints = FlowMirrorPoints.builder().mirrorSwitch(sw).mirrorGroup(MirrorGroup.builder().flowId(FLOW_ID).pathId(PATH_ID).groupId(GROUP_ID).switchId(SWITCH_ID_2).mirrorDirection(MirrorDirection.EGRESS).mirrorGroupType(MirrorGroupType.TRAFFIC_INTEGRITY).build()).build();
    mirrorPoints.addPaths(FlowMirrorPath.builder().mirrorSwitch(SWITCH_2).egressSwitch(SWITCH_2).pathId(PATH_ID).egressPort(MIRROR_PORT).egressOuterVlan(MIRROR_VLAN).build());
    return mirrorPoints;
}
Also used : FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints)

Example 12 with FlowMirrorPoints

use of org.openkilda.model.FlowMirrorPoints in project open-kilda by telstra.

the class IngressMirrorRuleGeneratorTest method buildMirrorPoints.

private static FlowMirrorPoints buildMirrorPoints(Switch sw) {
    FlowMirrorPoints mirrorPoints = FlowMirrorPoints.builder().mirrorSwitch(sw).mirrorGroup(MirrorGroup.builder().flowId(FLOW_ID).pathId(PATH_ID).groupId(GROUP_ID).switchId(SWITCH_ID_1).mirrorDirection(MirrorDirection.EGRESS).mirrorGroupType(MirrorGroupType.TRAFFIC_INTEGRITY).build()).build();
    mirrorPoints.addPaths(FlowMirrorPath.builder().mirrorSwitch(SWITCH_1).egressSwitch(SWITCH_1).pathId(PATH_ID).egressPort(MIRROR_PORT).egressOuterVlan(MIRROR_VLAN).build());
    return mirrorPoints;
}
Also used : FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints)

Example 13 with FlowMirrorPoints

use of org.openkilda.model.FlowMirrorPoints in project open-kilda by telstra.

the class IngressMirrorRuleGenerator method generateCommands.

@Override
public List<SpeakerData> generateCommands(Switch sw) {
    List<SpeakerData> result = new ArrayList<>();
    FlowMirrorPoints mirrorPoints = flowPath.getFlowMirrorPointsSet().stream().filter(points -> sw.getSwitchId().equals(points.getMirrorSwitchId())).findFirst().orElse(null);
    if (mirrorPoints == null) {
        return result;
    }
    FlowEndpoint ingressEndpoint = checkAndBuildIngressEndpoint(flow, flowPath, sw.getSwitchId());
    FlowSpeakerData ingressCommand = buildFlowIngressCommand(sw, ingressEndpoint, mirrorPoints.getMirrorGroupId());
    result.add(ingressCommand);
    SpeakerData groupCommand = buildGroup(sw, mirrorPoints);
    result.add(groupCommand);
    ingressCommand.getDependsOn().add(groupCommand.getUuid());
    if (sharedMeterCommandUuid != null) {
        ingressCommand.getDependsOn().add(sharedMeterCommandUuid);
    }
    return result;
}
Also used : FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) FlowEndpoint(org.openkilda.model.FlowEndpoint) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) SpeakerData(org.openkilda.rulemanager.SpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) GroupSpeakerData(org.openkilda.rulemanager.GroupSpeakerData)

Example 14 with FlowMirrorPoints

use of org.openkilda.model.FlowMirrorPoints 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 15 with FlowMirrorPoints

use of org.openkilda.model.FlowMirrorPoints 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

FlowMirrorPoints (org.openkilda.model.FlowMirrorPoints)26 Flow (org.openkilda.model.Flow)11 PathId (org.openkilda.model.PathId)10 FlowMirrorPath (org.openkilda.model.FlowMirrorPath)7 FlowPath (org.openkilda.model.FlowPath)7 SwitchId (org.openkilda.model.SwitchId)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Switch (org.openkilda.model.Switch)6 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)6 FlowEndpoint (org.openkilda.model.FlowEndpoint)5 PathSegment (org.openkilda.model.PathSegment)5 List (java.util.List)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 MirrorGroup (org.openkilda.model.MirrorGroup)4 Collections (java.util.Collections)3 Iterator (java.util.Iterator)3 FlowSideAdapter (org.openkilda.adapter.FlowSideAdapter)3 GroupId (org.openkilda.model.GroupId)3