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);
}
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);
}
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());
}
}
}
}
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;
}
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));
}
Aggregations