Search in sources :

Example 56 with PathSegment

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

the class InMemoryPathComputerBaseTest method addPathSegment.

private void addPathSegment(FlowPath flowPath, Switch src, Switch dst, int srcPort, int dstPort) {
    PathSegment ps = PathSegment.builder().pathId(flowPath.getPathId()).srcSwitch(src).destSwitch(dst).srcPort(srcPort).destPort(dstPort).latency(null).build();
    List<PathSegment> segments = new ArrayList<>(flowPath.getSegments());
    segments.add(ps);
    flowPath.setSegments(segments);
}
Also used : ArrayList(java.util.ArrayList) PathSegment(org.openkilda.model.PathSegment)

Example 57 with PathSegment

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

the class RerouteServiceTest method setup.

@Before
public void setup() throws Throwable {
    doAnswer(invocation -> {
        TransactionCallbackWithoutResult<?> arg = invocation.getArgument(0);
        arg.doInTransaction();
        return null;
    }).when(transactionManager).doInTransaction(Mockito.<TransactionCallbackWithoutResult<?>>any());
    doAnswer(invocation -> {
        TransactionCallback<?, ?> arg = invocation.getArgument(0);
        return arg.doInTransaction();
    }).when(transactionManager).doInTransaction(Mockito.<TransactionCallback<?, ?>>any());
    pinnedFlow = Flow.builder().flowId(FLOW_ID).srcSwitch(SWITCH_A).destSwitch(SWITCH_C).pinned(true).build();
    FlowPath pinnedFlowForwardPath = FlowPath.builder().pathId(new PathId("1")).srcSwitch(SWITCH_A).destSwitch(SWITCH_C).cookie(new FlowSegmentCookie(FlowPathDirection.FORWARD, 1)).build();
    List<PathSegment> pinnedFlowForwardSegments = new ArrayList<>();
    pinnedFlowForwardSegments.add(PathSegment.builder().pathId(pinnedFlowForwardPath.getPathId()).srcSwitch(SWITCH_A).srcPort(1).destSwitch(SWITCH_B).destPort(1).build());
    pinnedFlowForwardSegments.add(PathSegment.builder().pathId(pinnedFlowForwardPath.getPathId()).srcSwitch(SWITCH_B).srcPort(2).destSwitch(SWITCH_C).destPort(1).build());
    pinnedFlowForwardPath.setSegments(pinnedFlowForwardSegments);
    FlowPath pinnedFlowReversePath = FlowPath.builder().pathId(new PathId("2")).srcSwitch(SWITCH_C).destSwitch(SWITCH_A).cookie(new FlowSegmentCookie(FlowPathDirection.REVERSE, 2)).build();
    List<PathSegment> pinnedFlowReverseSegments = new ArrayList<>();
    pinnedFlowReverseSegments.add(PathSegment.builder().pathId(pinnedFlowReversePath.getPathId()).srcSwitch(SWITCH_C).srcPort(1).destSwitch(SWITCH_B).destPort(2).build());
    pinnedFlowReverseSegments.add(PathSegment.builder().pathId(pinnedFlowReversePath.getPathId()).srcSwitch(SWITCH_B).srcPort(1).destSwitch(SWITCH_A).destPort(1).build());
    pinnedFlowReversePath.setSegments(pinnedFlowReverseSegments);
    pinnedFlow.setForwardPath(pinnedFlowForwardPath);
    pinnedFlow.setReversePath(pinnedFlowReversePath);
    regularFlow = Flow.builder().flowId(FLOW_ID).srcSwitch(SWITCH_A).destSwitch(SWITCH_C).pinned(false).priority(2).build();
    FlowPath regularFlowForwardPath = FlowPath.builder().pathId(new PathId("3")).srcSwitch(SWITCH_A).destSwitch(SWITCH_C).cookie(new FlowSegmentCookie(FlowPathDirection.FORWARD, 3)).status(FlowPathStatus.ACTIVE).build();
    List<PathSegment> unpinnedFlowForwardSegments = new ArrayList<>();
    unpinnedFlowForwardSegments.add(PathSegment.builder().pathId(regularFlowForwardPath.getPathId()).srcSwitch(SWITCH_A).srcPort(1).destSwitch(SWITCH_B).destPort(1).build());
    unpinnedFlowForwardSegments.add(PathSegment.builder().pathId(regularFlowForwardPath.getPathId()).srcSwitch(SWITCH_B).srcPort(2).destSwitch(SWITCH_C).destPort(1).build());
    regularFlowForwardPath.setSegments(unpinnedFlowForwardSegments);
    FlowPath regularFlowReversePath = FlowPath.builder().pathId(new PathId("4")).srcSwitch(SWITCH_C).destSwitch(SWITCH_A).cookie(new FlowSegmentCookie(FlowPathDirection.REVERSE, 3)).status(FlowPathStatus.ACTIVE).build();
    List<PathSegment> unpinnedFlowReverseSegments = new ArrayList<>();
    unpinnedFlowReverseSegments.add(PathSegment.builder().pathId(regularFlowReversePath.getPathId()).srcSwitch(SWITCH_C).srcPort(1).destSwitch(SWITCH_B).destPort(2).build());
    unpinnedFlowReverseSegments.add(PathSegment.builder().pathId(regularFlowReversePath.getPathId()).srcSwitch(SWITCH_B).srcPort(1).destSwitch(SWITCH_A).destPort(1).build());
    regularFlowReversePath.setSegments(unpinnedFlowReverseSegments);
    regularFlow.setForwardPath(regularFlowForwardPath);
    regularFlow.setReversePath(regularFlowReversePath);
    oneSwitchFlow = Flow.builder().flowId(FLOW_ID).srcSwitch(SWITCH_A).destSwitch(SWITCH_A).build();
    FlowPath oneSwitchFlowForwardPath = FlowPath.builder().pathId(new PathId("5")).srcSwitch(SWITCH_A).destSwitch(SWITCH_A).cookie(new FlowSegmentCookie(FlowPathDirection.FORWARD, 4)).status(FlowPathStatus.ACTIVE).build();
    FlowPath oneSwitchFlowReversePath = FlowPath.builder().pathId(new PathId("6")).srcSwitch(SWITCH_A).destSwitch(SWITCH_A).cookie(new FlowSegmentCookie(FlowPathDirection.REVERSE, 4)).status(FlowPathStatus.ACTIVE).build();
    oneSwitchFlow.setForwardPath(oneSwitchFlowForwardPath);
    oneSwitchFlow.setReversePath(oneSwitchFlowReversePath);
    regularYFlow = YFlow.builder().yFlowId(YFLOW_ID).priority(2).sharedEndpoint(new SharedEndpoint(SWITCH_A.getSwitchId(), 10)).build();
    FlowPath regularYFlowForwardPath = FlowPath.builder().pathId(new PathId("3")).srcSwitch(SWITCH_A).destSwitch(SWITCH_C).cookie(new FlowSegmentCookie(FlowPathDirection.FORWARD, 3)).status(FlowPathStatus.ACTIVE).build();
    regularYFlowForwardPath.setSegments(unpinnedFlowForwardSegments);
    FlowPath regularYFlowReversePath = FlowPath.builder().pathId(new PathId("4")).srcSwitch(SWITCH_C).destSwitch(SWITCH_A).cookie(new FlowSegmentCookie(FlowPathDirection.REVERSE, 3)).status(FlowPathStatus.ACTIVE).build();
    regularYFlowReversePath.setSegments(unpinnedFlowReverseSegments);
    subFlow = Flow.builder().flowId(SUB_YFLOW_ID).srcSwitch(SWITCH_A).destSwitch(SWITCH_C).pinned(false).priority(2).yFlowId(YFLOW_ID).yFlow(regularYFlow).build();
    subFlow.setForwardPath(regularYFlowForwardPath);
    subFlow.setReversePath(regularYFlowReversePath);
    Set<YSubFlow> subFlows = Collections.singleton(YSubFlow.builder().yFlow(regularYFlow).flow(subFlow).build());
    regularYFlow.setSubFlows(subFlows);
}
Also used : PathId(org.openkilda.model.PathId) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) ArrayList(java.util.ArrayList) SharedEndpoint(org.openkilda.model.YFlow.SharedEndpoint) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) YSubFlow(org.openkilda.model.YSubFlow) Before(org.junit.Before)

Example 58 with PathSegment

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

the class RerouteServiceTest method testRerouteInactivePinnedFlowsOneFailedSegment.

@Test
public void testRerouteInactivePinnedFlowsOneFailedSegment() throws Throwable {
    pinnedFlow.setStatus(FlowStatus.DOWN);
    for (FlowPath flowPath : pinnedFlow.getPaths()) {
        flowPath.setStatus(FlowPathStatus.INACTIVE);
        for (PathSegment pathSegment : flowPath.getSegments()) {
            if (pathSegment.containsNode(SWITCH_ID_A, PORT)) {
                pathSegment.setFailed(true);
            }
        }
    }
    RepositoryFactory repositoryFactory = mock(RepositoryFactory.class);
    FlowRepository flowRepository = mock(FlowRepository.class);
    when(flowRepository.findInactiveFlows()).thenReturn(Collections.singletonList(pinnedFlow));
    doAnswer(invocation -> {
        FlowStatus status = invocation.getArgument(1);
        pinnedFlow.setStatus(status);
        return null;
    }).when(flowRepository).updateStatusSafe(eq(pinnedFlow), any(), any());
    when(repositoryFactory.createFlowRepository()).thenReturn(flowRepository);
    FlowPathRepository pathRepository = mock(FlowPathRepository.class);
    when(repositoryFactory.createFlowPathRepository()).thenReturn(pathRepository);
    PathSegmentRepository pathSegmentRepository = mock(PathSegmentRepository.class);
    when(repositoryFactory.createPathSegmentRepository()).thenReturn(pathSegmentRepository);
    MessageSender messageSender = mock(MessageSender.class);
    PersistenceManager persistenceManager = mock(PersistenceManager.class);
    when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
    TransactionManager transactionManager = mock(TransactionManager.class);
    doAnswer(invocation -> {
        TransactionCallback<?, ?> arg = invocation.getArgument(0);
        return arg.doInTransaction();
    }).when(transactionManager).doInTransaction(Mockito.<TransactionCallback<?, ?>>any());
    when(persistenceManager.getTransactionManager()).thenReturn(transactionManager);
    RerouteService rerouteService = new RerouteService(persistenceManager);
    rerouteService.rerouteInactiveFlows(messageSender, CORRELATION_ID, REROUTE_INACTIVE_FLOWS_COMMAND);
    assertEquals(FlowStatus.UP, pinnedFlow.getStatus());
    for (FlowPath fp : pinnedFlow.getPaths()) {
        assertEquals(FlowPathStatus.ACTIVE, fp.getStatus());
        for (PathSegment ps : fp.getSegments()) {
            if (ps.containsNode(SWITCH_ID_A, PORT)) {
                assertFalse(ps.isFailed());
            }
        }
    }
}
Also used : FlowRepository(org.openkilda.persistence.repositories.FlowRepository) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) PathSegmentRepository(org.openkilda.persistence.repositories.PathSegmentRepository) PersistenceManager(org.openkilda.persistence.PersistenceManager) MessageSender(org.openkilda.wfm.topology.reroute.bolts.MessageSender) TransactionManager(org.openkilda.persistence.tx.TransactionManager) PathSegment(org.openkilda.model.PathSegment) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) FlowPath(org.openkilda.model.FlowPath) FlowStatus(org.openkilda.model.FlowStatus) Test(org.junit.Test)

Example 59 with PathSegment

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

the class RuleManagerImpl method buildFlowRulesForSwitch.

/**
 * Builds command data only for switches present in the map. Silently skips all others.
 */
private List<SpeakerData> buildFlowRulesForSwitch(SwitchId switchId, FlowPath flowPath, DataAdapter adapter) {
    List<SpeakerData> result = new ArrayList<>();
    Flow flow = adapter.getFlow(flowPath.getPathId());
    Switch sw = adapter.getSwitch(switchId);
    PathId oppositePathId = flow.getOppositePathId(flowPath.getPathId()).orElse(null);
    FlowTransitEncapsulation encapsulation = adapter.getTransitEncapsulation(flowPath.getPathId(), oppositePathId);
    if (switchId.equals(flowPath.getSrcSwitchId()) && !flow.isProtectedPath(flowPath.getPathId())) {
        // TODO filter out equal shared rules from the result list
        result.addAll(buildIngressCommands(sw, flowPath, flow, encapsulation, new HashSet<>(), adapter.getSwitchProperties(switchId), adapter.getFeatureToggles()));
    }
    if (!flowPath.isOneSwitchFlow()) {
        if (switchId.equals(flowPath.getDestSwitchId())) {
            result.addAll(buildEgressCommands(sw, flowPath, flow, encapsulation));
        }
        for (int i = 1; i < flowPath.getSegments().size(); i++) {
            PathSegment firstSegment = flowPath.getSegments().get(i - 1);
            PathSegment secondSegment = flowPath.getSegments().get(i);
            if (switchId.equals(firstSegment.getDestSwitchId()) && switchId.equals(secondSegment.getSrcSwitchId())) {
                result.addAll(buildTransitCommands(sw, flowPath, encapsulation, firstSegment, secondSegment));
                break;
            }
        }
        if (flow.isLooped() && sw.getSwitchId().equals(flow.getLoopSwitchId()) && !flow.isProtectedPath(flowPath.getPathId())) {
            result.addAll(buildTransitLoopCommands(sw, flowPath, flow, encapsulation));
        }
    }
    return result;
}
Also used : PathId(org.openkilda.model.PathId) Switch(org.openkilda.model.Switch) ArrayList(java.util.ArrayList) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) PathSegment(org.openkilda.model.PathSegment) FlowEndpoint(org.openkilda.model.FlowEndpoint) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) HashSet(java.util.HashSet)

Example 60 with PathSegment

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

the class EgressRuleGenerator method generateCommands.

@Override
public List<SpeakerData> generateCommands(Switch sw) {
    if (flowPath.isOneSwitchFlow() || flowPath.getSegments().isEmpty()) {
        return new ArrayList<>();
    }
    PathSegment lastSegment = flowPath.getSegments().get(flowPath.getSegments().size() - 1);
    FlowEndpoint endpoint = checkAndBuildEgressEndpoint(flow, flowPath, sw.getSwitchId());
    return Lists.newArrayList(buildEgressCommand(sw, lastSegment.getDestPort(), endpoint));
}
Also used : FlowEndpoint(org.openkilda.model.FlowEndpoint) 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