Search in sources :

Example 36 with PathSegment

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

Example 37 with PathSegment

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

the class SimpleSwitchRuleConverter method buildTransitAndEgressSimpleSwitchRules.

private List<SimpleSwitchRule> buildTransitAndEgressSimpleSwitchRules(Flow flow, FlowPath flowPath, EncapsulationId encapsulationId) {
    List<PathSegment> orderedSegments = flowPath.getSegments().stream().sorted(Comparator.comparingInt(PathSegment::getSeqId)).collect(Collectors.toList());
    List<SimpleSwitchRule> rules = new ArrayList<>();
    for (int i = 1; i < orderedSegments.size(); i++) {
        PathSegment srcPathSegment = orderedSegments.get(i - 1);
        PathSegment dstPathSegment = orderedSegments.get(i);
        rules.add(buildTransitSimpleSwitchRule(flow, flowPath, srcPathSegment, dstPathSegment, encapsulationId));
    }
    PathSegment egressSegment = orderedSegments.get(orderedSegments.size() - 1);
    if (!egressSegment.getDestSwitchId().equals(flowPath.getDestSwitchId())) {
        throw new IllegalStateException(String.format("PathSegment was not found for egress flow rule, flowId: %s", flow.getFlowId()));
    }
    rules.addAll(buildEgressSimpleSwitchRules(flow, flowPath, egressSegment, encapsulationId));
    return rules;
}
Also used : ArrayList(java.util.ArrayList) PathSegment(org.openkilda.model.PathSegment) FlowEndpoint(org.openkilda.model.FlowEndpoint)

Example 38 with PathSegment

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

the class FlowPathMapper method map.

/**
 * Convert path's {@link PathSegment} to {@link PathInfoData}.
 */
public PathInfoData map(List<PathSegment> pathSegments) {
    PathInfoData result = new PathInfoData();
    int seqId = 0;
    List<PathNode> nodes = new ArrayList<>();
    for (PathSegment pathSegment : pathSegments) {
        nodes.add(new PathNode(pathSegment.getSrcSwitchId(), pathSegment.getSrcPort(), seqId++, pathSegment.getLatency()));
        nodes.add(new PathNode(pathSegment.getDestSwitchId(), pathSegment.getDestPort(), seqId++));
    }
    result.setPath(nodes);
    return result;
}
Also used : PathInfoData(org.openkilda.messaging.info.event.PathInfoData) ArrayList(java.util.ArrayList) PathSegment(org.openkilda.model.PathSegment) PathNode(org.openkilda.messaging.info.event.PathNode) FlowEndpoint(org.openkilda.model.FlowEndpoint)

Example 39 with PathSegment

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

the class FlowPathMapper method mapToPathNodes.

/**
 * Convert {@link FlowPath} to {@link PathNodePayload}.
 */
public List<PathNodePayload> mapToPathNodes(FlowPath flowPath, int inPort, int outPort) {
    List<PathNodePayload> resultList = new ArrayList<>();
    if (flowPath.getSegments().isEmpty()) {
        resultList.add(new PathNodePayload(flowPath.getSrcSwitchId(), inPort, outPort));
    } else {
        List<PathSegment> pathSegments = flowPath.getSegments();
        resultList.add(new PathNodePayload(flowPath.getSrcSwitchId(), inPort, pathSegments.get(0).getSrcPort()));
        for (int i = 1; i < pathSegments.size(); i++) {
            PathSegment inputNode = pathSegments.get(i - 1);
            PathSegment outputNode = pathSegments.get(i);
            resultList.add(new PathNodePayload(inputNode.getDestSwitchId(), inputNode.getDestPort(), outputNode.getSrcPort()));
        }
        resultList.add(new PathNodePayload(flowPath.getDestSwitchId(), pathSegments.get(pathSegments.size() - 1).getDestPort(), outPort));
    }
    return resultList;
}
Also used : PathNodePayload(org.openkilda.messaging.payload.flow.PathNodePayload) ArrayList(java.util.ArrayList) PathSegment(org.openkilda.model.PathSegment) FlowEndpoint(org.openkilda.model.FlowEndpoint)

Example 40 with PathSegment

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

the class IntersectionComputer method getLongestIntersectionOfSegments.

private static List<PathSegment> getLongestIntersectionOfSegments(List<Iterator<PathSegment>> pathSegments) {
    List<PathSegment> result = new ArrayList<>();
    // Iterate over the first path's segments and check other paths' segments.
    Iterator<PathSegment> firstPathSegmentIterator = pathSegments.get(0);
    while (firstPathSegmentIterator.hasNext()) {
        PathSegment firstPathSegment = firstPathSegmentIterator.next();
        for (Iterator<PathSegment> it : pathSegments.subList(1, pathSegments.size())) {
            if (it.hasNext()) {
                PathSegment anotherSegment = it.next();
                if (!firstPathSegment.getSrcSwitchId().equals(anotherSegment.getSrcSwitchId()) || firstPathSegment.getSrcPort() != anotherSegment.getSrcPort() || !firstPathSegment.getDestSwitchId().equals(anotherSegment.getDestSwitchId()) || firstPathSegment.getDestPort() != anotherSegment.getDestPort()) {
                    return result;
                }
            } else {
                return result;
            }
        }
        result.add(firstPathSegment);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) PathSegment(org.openkilda.model.PathSegment)

Aggregations

PathSegment (org.openkilda.model.PathSegment)73 FlowPath (org.openkilda.model.FlowPath)40 ArrayList (java.util.ArrayList)28 Flow (org.openkilda.model.Flow)26 PathId (org.openkilda.model.PathId)24 SwitchId (org.openkilda.model.SwitchId)18 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)17 FlowEndpoint (org.openkilda.model.FlowEndpoint)12 Test (org.junit.Test)11 List (java.util.List)9 MeterId (org.openkilda.model.MeterId)9 Switch (org.openkilda.model.Switch)9 YFlow (org.openkilda.model.YFlow)8 PersistenceManager (org.openkilda.persistence.PersistenceManager)7 Optional (java.util.Optional)6 Slf4j (lombok.extern.slf4j.Slf4j)6 VisibleForTesting (com.google.common.annotations.VisibleForTesting)5 Set (java.util.Set)5 Collectors (java.util.stream.Collectors)5 PathInfoData (org.openkilda.messaging.info.event.PathInfoData)5