use of org.openkilda.model.PathSegment in project open-kilda by telstra.
the class RerouteServiceTest method testRerouteInactivePinnedFlowsTwoFailedSegments.
@Test
public void testRerouteInactivePinnedFlowsTwoFailedSegments() {
pinnedFlow.setStatus(FlowStatus.DOWN);
for (FlowPath flowPath : pinnedFlow.getPaths()) {
flowPath.setStatus(FlowPathStatus.INACTIVE);
for (PathSegment pathSegment : flowPath.getSegments()) {
pathSegment.setFailed(true);
}
}
RepositoryFactory repositoryFactory = mock(RepositoryFactory.class);
FlowRepository flowRepository = mock(FlowRepository.class);
when(flowRepository.findInactiveFlows()).thenReturn(Collections.singletonList(pinnedFlow));
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);
when(persistenceManager.getTransactionManager()).thenReturn(transactionManager);
RerouteService rerouteService = new RerouteService(persistenceManager);
rerouteService.rerouteInactiveFlows(messageSender, CORRELATION_ID, REROUTE_INACTIVE_FLOWS_COMMAND);
verify(pathRepository, times(0)).updateStatus(any(), any());
assertTrue(FlowStatus.DOWN.equals(pinnedFlow.getStatus()));
for (FlowPath fp : pinnedFlow.getPaths()) {
assertTrue(FlowPathStatus.INACTIVE.equals(fp.getStatus()));
for (PathSegment ps : fp.getSegments()) {
if (ps.containsNode(SWITCH_ID_A, PORT)) {
assertFalse(ps.isFailed());
} else {
assertTrue(ps.isFailed());
}
}
}
}
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) {
List<PathNodePayload> resultList = new ArrayList<>();
Flow flow = flowPath.getFlow();
FlowEndpoint ingress = FlowSideAdapter.makeIngressAdapter(flow, flowPath).getEndpoint();
FlowEndpoint egress = FlowSideAdapter.makeEgressAdapter(flow, flowPath).getEndpoint();
List<PathSegment> pathSegments = flowPath.getSegments();
Iterator<PathSegment> leftIter = pathSegments.iterator();
Iterator<PathSegment> rightIter = pathSegments.iterator();
if (!rightIter.hasNext()) {
resultList.add(new PathNodePayload(flowPath.getSrcSwitchId(), ingress.getPortNumber(), egress.getPortNumber()));
} else {
PathSegment left;
PathSegment right = rightIter.next();
resultList.add(new PathNodePayload(ingress.getSwitchId(), ingress.getPortNumber(), right.getSrcPort()));
while (rightIter.hasNext()) {
left = leftIter.next();
right = rightIter.next();
resultList.add(new PathNodePayload(left.getDestSwitchId(), left.getDestPort(), right.getSrcPort()));
}
resultList.add(new PathNodePayload(egress.getSwitchId(), right.getDestPort(), egress.getPortNumber()));
}
return resultList;
}
use of org.openkilda.model.PathSegment in project open-kilda by telstra.
the class FlowPathMapper method map.
/**
* Convert {@link FlowPath} to {@link PathInfoData}.
*/
public PathInfoData map(FlowPath path) {
PathInfoData result = new PathInfoData();
if (path != null) {
result.setLatency(path.getLatency());
int seqId = 0;
List<PathNode> nodes = new ArrayList<>();
for (PathSegment pathSegment : path.getSegments()) {
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;
}
use of org.openkilda.model.PathSegment in project open-kilda by telstra.
the class SpeakerFlowSegmentRequestBuilder method makePathRequests.
@SuppressWarnings("squid:S00107")
private List<FlowSegmentRequestFactory> makePathRequests(@NonNull Flow flow, @NonNull FlowPath path, CommandContext context, FlowTransitEncapsulation encapsulation, boolean doIngress, boolean doTransit, boolean doEgress, RulesContext rulesContext, MirrorContext mirrorContext) {
final FlowSideAdapter ingressSide = FlowSideAdapter.makeIngressAdapter(flow, path);
final FlowSideAdapter egressSide = FlowSideAdapter.makeEgressAdapter(flow, path);
final List<FlowSegmentRequestFactory> requests = new ArrayList<>();
PathSegment lastSegment = null;
for (PathSegment segment : path.getSegments()) {
if (lastSegment == null) {
if (doIngress) {
requests.addAll(makeIngressSegmentRequests(context, path, encapsulation, ingressSide, segment, egressSide, rulesContext, mirrorContext));
if (ingressLoopRuleRequired(flow, ingressSide)) {
requests.addAll(makeLoopRequests(context, path, encapsulation, ingressSide, egressSide, segment));
}
}
} else {
if (doTransit) {
requests.add(makeTransitSegmentRequest(context, path, encapsulation, lastSegment, segment));
}
}
lastSegment = segment;
}
if (lastSegment != null) {
if (doEgress) {
requests.addAll(makeEgressSegmentRequests(context, path, encapsulation, lastSegment, egressSide, ingressSide, mirrorContext));
}
} else if (flow.isOneSwitchFlow()) {
// one switch flow (path without path segments)
requests.addAll(makeOneSwitchRequest(context, path, ingressSide, egressSide, rulesContext, mirrorContext));
if (singleSwitchLoopRuleRequired(flow)) {
requests.add(makeSingleSwitchIngressLoopRequest(context, path, ingressSide));
}
}
return requests;
}
use of org.openkilda.model.PathSegment in project open-kilda by telstra.
the class IntersectionComputer method calculatePathIntersectionFromSource.
/**
* Calculates intersection (shared part) among the paths starting from the source endpoint.
*
* @param paths the paths to examine.
* @return the overlapping path segments.
*/
public static List<PathSegment> calculatePathIntersectionFromSource(Collection<FlowPath> paths) {
if (paths.size() < 2) {
throw new IllegalArgumentException("At least 2 paths must be provided");
}
SwitchId source = null;
for (FlowPath path : paths) {
List<PathSegment> segments = path.getSegments();
if (segments.isEmpty()) {
throw new IllegalArgumentException("All paths mustn't be empty");
}
// Check that all paths have the same source.
if (source == null) {
source = segments.get(0).getSrcSwitchId();
} else if (!segments.get(0).getSrcSwitchId().equals(source)) {
throw new IllegalArgumentException("All paths must have the same source endpoint");
}
}
// Gather iterators of all paths' segments.
List<Iterator<PathSegment>> pathSegmentIterators = paths.stream().map(FlowPath::getSegments).map(List::iterator).collect(Collectors.toList());
return getLongestIntersectionOfSegments(pathSegmentIterators);
}
Aggregations