use of org.openkilda.model.PathSegment in project open-kilda by telstra.
the class SimpleSwitchRuleConverter method buildEgressSimpleSwitchRules.
private List<SimpleSwitchRule> buildEgressSimpleSwitchRules(Flow flow, FlowPath flowPath, PathSegment egressSegment, EncapsulationId encapsulationId) {
List<SimpleSwitchRule> rules = new ArrayList<>();
FlowSideAdapter egressAdapter = FlowSideAdapter.makeEgressAdapter(flow, flowPath);
FlowEndpoint endpoint = egressAdapter.getEndpoint();
SimpleSwitchRule rule = SimpleSwitchRule.builder().switchId(flowPath.getDestSwitchId()).outPort(endpoint.getPortNumber()).inPort(egressSegment.getDestPort()).cookie(flowPath.getCookie().getValue()).egressRule(true).build();
if (flow.getEncapsulationType().equals(FlowEncapsulationType.TRANSIT_VLAN)) {
rule.setInVlan(encapsulationId.getEncapsulationId());
rule.setOutVlan(calcVlanSetSequence(Collections.singletonList(encapsulationId.getEncapsulationId()), endpoint.getVlanStack()));
} else if (flow.getEncapsulationType().equals(FlowEncapsulationType.VXLAN)) {
rule.setTunnelId(encapsulationId.getEncapsulationId());
rule.setOutVlan(calcVlanSetSequence(Collections.emptyList(), endpoint.getVlanStack()));
}
if (egressAdapter.isLooped() && !flowPath.isProtected()) {
rules.add(buildTransitLoopRuleForEgressSwitch(rule, flowPath));
}
rules.add(rule);
Optional<FlowMirrorPoints> foundFlowMirrorPoints = flowPath.getFlowMirrorPointsSet().stream().filter(mirrorPoints -> mirrorPoints.getMirrorSwitchId().equals(egressSegment.getDestSwitchId())).findFirst();
if (foundFlowMirrorPoints.isPresent()) {
FlowMirrorPoints flowMirrorPoints = foundFlowMirrorPoints.get();
rules.add(rule.toBuilder().outPort(0).cookie(flowPath.getCookie().toBuilder().mirror(true).build().getValue()).groupId(flowMirrorPoints.getMirrorGroupId().intValue()).groupBuckets(mapGroupBuckets(flowMirrorPoints.getMirrorPaths(), endpoint.getPortNumber(), 0, 0)).build());
}
return rules;
}
use of org.openkilda.model.PathSegment in project open-kilda by telstra.
the class SimpleSwitchRuleConverter method buildTransitAndEgressSimpleSwitchRules.
private List<SimpleSwitchRule> buildTransitAndEgressSimpleSwitchRules(Flow flow, FlowPath flowPath, EncapsulationId encapsulationId) {
List<PathSegment> orderedSegments = flowPath.getSegments().stream().sorted(Comparator.comparingInt(PathSegment::getSeqId)).collect(Collectors.toList());
List<SimpleSwitchRule> rules = new ArrayList<>();
for (int i = 1; i < orderedSegments.size(); i++) {
PathSegment srcPathSegment = orderedSegments.get(i - 1);
PathSegment dstPathSegment = orderedSegments.get(i);
rules.add(buildTransitSimpleSwitchRule(flow, flowPath, srcPathSegment, dstPathSegment, encapsulationId));
}
PathSegment egressSegment = orderedSegments.get(orderedSegments.size() - 1);
if (!egressSegment.getDestSwitchId().equals(flowPath.getDestSwitchId())) {
throw new IllegalStateException(String.format("PathSegment was not found for egress flow rule, flowId: %s", flow.getFlowId()));
}
rules.addAll(buildEgressSimpleSwitchRules(flow, flowPath, egressSegment, encapsulationId));
return rules;
}
use of org.openkilda.model.PathSegment in project open-kilda by telstra.
the class FlowPathMapper method map.
/**
* Convert path's {@link PathSegment} to {@link PathInfoData}.
*/
public PathInfoData map(List<PathSegment> pathSegments) {
PathInfoData result = new PathInfoData();
int seqId = 0;
List<PathNode> nodes = new ArrayList<>();
for (PathSegment pathSegment : pathSegments) {
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 FlowPathMapper method mapToPathNodes.
/**
* Convert {@link FlowPath} to {@link PathNodePayload}.
*/
public List<PathNodePayload> mapToPathNodes(FlowPath flowPath, int inPort, int outPort) {
List<PathNodePayload> resultList = new ArrayList<>();
if (flowPath.getSegments().isEmpty()) {
resultList.add(new PathNodePayload(flowPath.getSrcSwitchId(), inPort, outPort));
} else {
List<PathSegment> pathSegments = flowPath.getSegments();
resultList.add(new PathNodePayload(flowPath.getSrcSwitchId(), inPort, pathSegments.get(0).getSrcPort()));
for (int i = 1; i < pathSegments.size(); i++) {
PathSegment inputNode = pathSegments.get(i - 1);
PathSegment outputNode = pathSegments.get(i);
resultList.add(new PathNodePayload(inputNode.getDestSwitchId(), inputNode.getDestPort(), outputNode.getSrcPort()));
}
resultList.add(new PathNodePayload(flowPath.getDestSwitchId(), pathSegments.get(pathSegments.size() - 1).getDestPort(), outPort));
}
return resultList;
}
use of org.openkilda.model.PathSegment in project open-kilda by telstra.
the class IntersectionComputer method getLongestIntersectionOfSegments.
private static List<PathSegment> getLongestIntersectionOfSegments(List<Iterator<PathSegment>> pathSegments) {
List<PathSegment> result = new ArrayList<>();
// Iterate over the first path's segments and check other paths' segments.
Iterator<PathSegment> firstPathSegmentIterator = pathSegments.get(0);
while (firstPathSegmentIterator.hasNext()) {
PathSegment firstPathSegment = firstPathSegmentIterator.next();
for (Iterator<PathSegment> it : pathSegments.subList(1, pathSegments.size())) {
if (it.hasNext()) {
PathSegment anotherSegment = it.next();
if (!firstPathSegment.getSrcSwitchId().equals(anotherSegment.getSrcSwitchId()) || firstPathSegment.getSrcPort() != anotherSegment.getSrcPort() || !firstPathSegment.getDestSwitchId().equals(anotherSegment.getDestSwitchId()) || firstPathSegment.getDestPort() != anotherSegment.getDestPort()) {
return result;
}
} else {
return result;
}
}
result.add(firstPathSegment);
}
return result;
}
Aggregations