Search in sources :

Example 31 with PathSegment

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

the class FlowPathBuilder method isSamePath.

/**
 * Check whether the path and flow path represent the same.
 *
 * @param path the path to evaluate.
 * @param flowPath the flow path to evaluate.
 */
public boolean isSamePath(Path path, FlowPath flowPath) {
    if (!path.getSrcSwitchId().equals(flowPath.getSrcSwitchId()) || !path.getDestSwitchId().equals(flowPath.getDestSwitchId()) || path.getSegments().size() != flowPath.getSegments().size()) {
        return false;
    }
    Iterator<Segment> pathIt = path.getSegments().iterator();
    Iterator<PathSegment> flowPathIt = flowPath.getSegments().iterator();
    while (pathIt.hasNext() && flowPathIt.hasNext()) {
        Path.Segment pathSegment = pathIt.next();
        PathSegment flowSegment = flowPathIt.next();
        if (!pathSegment.getSrcSwitchId().equals(flowSegment.getSrcSwitchId()) || !pathSegment.getDestSwitchId().equals(flowSegment.getDestSwitchId()) || pathSegment.getSrcPort() != flowSegment.getSrcPort() || pathSegment.getDestPort() != flowSegment.getDestPort()) {
            return false;
        }
    }
    return true;
}
Also used : FlowPath(org.openkilda.model.FlowPath) Path(org.openkilda.pce.Path) Segment(org.openkilda.pce.Path.Segment) PathSegment(org.openkilda.model.PathSegment) PathSegment(org.openkilda.model.PathSegment) Segment(org.openkilda.pce.Path.Segment)

Example 32 with PathSegment

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

the class FlowPathBuilder method buildPathSegments.

/**
 * Build a path segments using provided path.
 *
 * @param pathId a pathId the segments will be associated with.
 * @param pathForSegments path to be used for the segments.
 * @param bandwidth bandwidth to be used for the segments.
 * @param ignoreBandwidth ignore bandwidth be used for the segments.
 * @param sharedBandwidthGroupId a shared bandwidth group to be set for the segments
 */
public List<PathSegment> buildPathSegments(PathId pathId, Path pathForSegments, long bandwidth, boolean ignoreBandwidth, String sharedBandwidthGroupId) {
    Map<SwitchId, SwitchProperties> switchProperties = getSwitchProperties(pathId);
    List<PathSegment> result = new ArrayList<>();
    for (int i = 0; i < pathForSegments.getSegments().size(); i++) {
        Path.Segment segment = pathForSegments.getSegments().get(i);
        SwitchProperties srcSwitchProperties = switchProperties.get(segment.getSrcSwitchId());
        SwitchProperties dstSwitchProperties = switchProperties.get(segment.getDestSwitchId());
        result.add(PathSegment.builder().seqId(i).pathId(pathId).srcSwitch(Switch.builder().switchId(segment.getSrcSwitchId()).build()).srcPort(segment.getSrcPort()).srcWithMultiTable(srcSwitchProperties.isMultiTable()).destSwitch(Switch.builder().switchId(segment.getDestSwitchId()).build()).destPort(segment.getDestPort()).destWithMultiTable(dstSwitchProperties.isMultiTable()).latency(segment.getLatency()).bandwidth(bandwidth).ignoreBandwidth(ignoreBandwidth).sharedBandwidthGroupId(sharedBandwidthGroupId).build());
    }
    return result;
}
Also used : FlowPath(org.openkilda.model.FlowPath) Path(org.openkilda.pce.Path) ArrayList(java.util.ArrayList) Segment(org.openkilda.pce.Path.Segment) SwitchId(org.openkilda.model.SwitchId) PathSegment(org.openkilda.model.PathSegment) SwitchProperties(org.openkilda.model.SwitchProperties)

Example 33 with PathSegment

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

the class IntersectionComputerTest method shouldCalculateSharedPathWithNoSegments.

@Test
public void shouldCalculateSharedPathWithNoSegments() {
    FlowPath firstPath = FlowPath.builder().pathId(PATH_ID).srcSwitch(makeSwitch(SWITCH_ID_A)).destSwitch(makeSwitch(SWITCH_ID_C)).segments(Lists.newArrayList(buildPathSegment(NEW_PATH_ID, SWITCH_ID_A, SWITCH_ID_D, 1, 1), buildPathSegment(NEW_PATH_ID, SWITCH_ID_D, SWITCH_ID_C, 2, 2))).build();
    FlowPath secondPath = FlowPath.builder().pathId(NEW_PATH_ID).srcSwitch(makeSwitch(SWITCH_ID_A)).destSwitch(makeSwitch(SWITCH_ID_D)).segments(Lists.newArrayList(buildPathSegment(NEW_PATH_ID, SWITCH_ID_A, SWITCH_ID_B, 1, 1), buildPathSegment(NEW_PATH_ID, SWITCH_ID_B, SWITCH_ID_D, 3, 3))).build();
    List<PathSegment> sharedPath = IntersectionComputer.calculatePathIntersectionFromSource(asList(firstPath, secondPath));
    assertEquals(0, sharedPath.size());
}
Also used : PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) Test(org.junit.Test)

Example 34 with PathSegment

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

the class IntersectionComputerTest method shouldCalculateSharedPathWithSingleSegment.

@Test
public void shouldCalculateSharedPathWithSingleSegment() {
    FlowPath firstPath = FlowPath.builder().pathId(PATH_ID).srcSwitch(makeSwitch(SWITCH_ID_A)).destSwitch(makeSwitch(SWITCH_ID_C)).segments(Lists.newArrayList(buildPathSegment(NEW_PATH_ID, SWITCH_ID_A, SWITCH_ID_B, 1, 1), buildPathSegment(NEW_PATH_ID, SWITCH_ID_B, SWITCH_ID_C, 2, 2))).build();
    FlowPath secondPath = FlowPath.builder().pathId(NEW_PATH_ID).srcSwitch(makeSwitch(SWITCH_ID_A)).destSwitch(makeSwitch(SWITCH_ID_D)).segments(Lists.newArrayList(buildPathSegment(NEW_PATH_ID, SWITCH_ID_A, SWITCH_ID_B, 1, 1), buildPathSegment(NEW_PATH_ID, SWITCH_ID_B, SWITCH_ID_D, 3, 3))).build();
    List<PathSegment> sharedPath = IntersectionComputer.calculatePathIntersectionFromSource(asList(firstPath, secondPath));
    assertEquals(1, sharedPath.size());
    PathSegment sharedSegment = sharedPath.get(0);
    assertEquals(SWITCH_ID_A, sharedSegment.getSrcSwitchId());
    assertEquals(SWITCH_ID_B, sharedSegment.getDestSwitchId());
}
Also used : PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) Test(org.junit.Test)

Example 35 with PathSegment

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

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