Search in sources :

Example 26 with PathSegment

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

the class RuleManagerImpl method findPathSegmentsForSwitch.

private SwitchPathSegments findPathSegmentsForSwitch(SwitchId switchId, List<PathSegment> pathSegments) {
    SwitchPathSegments result = null;
    for (int i = 1; i < pathSegments.size(); i++) {
        PathSegment firstSegment = pathSegments.get(i - 1);
        PathSegment secondSegment = pathSegments.get(i);
        if (switchId.equals(firstSegment.getDestSwitchId()) && switchId.equals(secondSegment.getSrcSwitchId())) {
            result = new SwitchPathSegments(firstSegment, secondSegment);
            break;
        }
    }
    return result;
}
Also used : PathSegment(org.openkilda.model.PathSegment) FlowEndpoint(org.openkilda.model.FlowEndpoint)

Example 27 with PathSegment

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

the class PingProducer method getIslPort.

private int getIslPort(Flow flow, FlowPath flowPath) {
    List<PathSegment> segments = flowPath.getSegments();
    if (segments.isEmpty()) {
        throw new IllegalArgumentException(format("Path segments not provided, flow_id: %s", flow.getFlowId()));
    }
    PathSegment ingressSegment = segments.get(0);
    if (!ingressSegment.getSrcSwitchId().equals(flowPath.getSrcSwitchId())) {
        throw new IllegalStateException(format("FlowSegment was not found for ingress flow rule, flow_id: %s", flow.getFlowId()));
    }
    return ingressSegment.getSrcPort();
}
Also used : PathSegment(org.openkilda.model.PathSegment)

Example 28 with PathSegment

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

the class SpeakerFlowSegmentRequestBuilderTest method setSegmentsWithTransitSwitches.

private void setSegmentsWithTransitSwitches(FlowPath forward, FlowPath reverse) {
    PathSegment switch1ToSwitch2 = PathSegment.builder().pathId(forward.getPathId()).srcSwitch(forward.getSrcSwitch()).srcPort(12).destSwitch(Switch.builder().switchId(SWITCH_2).build()).destPort(21).build();
    PathSegment switch2ToSwitch3 = PathSegment.builder().pathId(forward.getPathId()).srcSwitch(Switch.builder().switchId(SWITCH_2).build()).srcPort(23).destSwitch(forward.getDestSwitch()).destPort(32).build();
    forward.setSegments(ImmutableList.of(switch1ToSwitch2, switch2ToSwitch3));
    PathSegment switch3ToSwitch2 = PathSegment.builder().pathId(reverse.getPathId()).srcSwitch(reverse.getSrcSwitch()).srcPort(32).destSwitch(Switch.builder().switchId(SWITCH_2).build()).destPort(23).build();
    PathSegment switch2ToSwitch1 = PathSegment.builder().pathId(reverse.getPathId()).srcSwitch(Switch.builder().switchId(SWITCH_2).build()).srcPort(21).destSwitch(reverse.getDestSwitch()).destPort(12).build();
    reverse.setSegments(ImmutableList.of(switch3ToSwitch2, switch2ToSwitch1));
}
Also used : PathSegment(org.openkilda.model.PathSegment)

Example 29 with PathSegment

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

the class TestFlowBuilder method buildFlowPath.

private FlowPath buildFlowPath(Flow flow, Switch srcSwitch, Switch destSwitch, List<Endpoint> transitEndpoints, FlowSegmentCookie cookie, MeterId meterId) {
    PathId pathId = new PathId(UUID.randomUUID().toString());
    List<PathSegment> pathSegments = new ArrayList<>();
    if (!srcSwitch.getSwitchId().equals(destSwitch.getSwitchId())) {
        for (int i = 0; i < transitEndpoints.size() - 1; i += 2) {
            Endpoint first = transitEndpoints.get(i);
            Endpoint second = transitEndpoints.get(i + 1);
            pathSegments.add(PathSegment.builder().pathId(pathId).srcSwitch(first.sw).srcPort(first.port).destSwitch(second.sw).destPort(second.port).bandwidth(flow.getBandwidth()).ignoreBandwidth(flow.isIgnoreBandwidth()).build());
        }
    }
    return FlowPath.builder().pathId(pathId).srcSwitch(srcSwitch).destSwitch(destSwitch).cookie(cookie).meterId(meterId).bandwidth(flow.getBandwidth()).ignoreBandwidth(flow.isIgnoreBandwidth()).segments(pathSegments).build();
}
Also used : PathId(org.openkilda.model.PathId) ArrayList(java.util.ArrayList) PathSegment(org.openkilda.model.PathSegment)

Example 30 with PathSegment

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

the class SpeakerFlowSegmentRequestBuilderTest method verifyCommonTransitRequest.

private TransitFlowSegmentRequest verifyCommonTransitRequest(Flow flow, FlowPath path, SwitchId datapath, FlowSegmentRequest rawRequest) {
    assertThat("Should be egress segment request", rawRequest, instanceOf(TransitFlowSegmentRequest.class));
    TransitFlowSegmentRequest request = (TransitFlowSegmentRequest) rawRequest;
    assertEquals(flow.getFlowId(), request.getFlowId());
    assertEquals(path.getCookie(), request.getCookie());
    assertEquals(SWITCH_2, request.getSwitchId());
    PathSegment ingress = null;
    PathSegment egress = null;
    for (PathSegment segment : path.getSegments()) {
        if (datapath.equals(segment.getDestSwitchId())) {
            ingress = segment;
        } else if (datapath.equals(segment.getSrcSwitchId())) {
            egress = segment;
        }
    }
    assertNotNull(ingress);
    assertNotNull(egress);
    assertEquals(ingress.getDestPort(), (int) request.getIngressIslPort());
    assertEquals(egress.getSrcPort(), (int) request.getEgressIslPort());
    verifyVlanEncapsulation(flow, path, request.getEncapsulation());
    return request;
}
Also used : TransitFlowSegmentRequest(org.openkilda.floodlight.api.request.TransitFlowSegmentRequest) 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