use of org.openkilda.model.PathSegment in project open-kilda by telstra.
the class FlowPathBuilder method isSamePath.
/**
* Check whether the path and flow path represent the same.
*
* @param path the path to evaluate.
* @param flowPath the flow path to evaluate.
*/
public boolean isSamePath(Path path, FlowPath flowPath) {
if (!path.getSrcSwitchId().equals(flowPath.getSrcSwitchId()) || !path.getDestSwitchId().equals(flowPath.getDestSwitchId()) || path.getSegments().size() != flowPath.getSegments().size()) {
return false;
}
Iterator<Segment> pathIt = path.getSegments().iterator();
Iterator<PathSegment> flowPathIt = flowPath.getSegments().iterator();
while (pathIt.hasNext() && flowPathIt.hasNext()) {
Path.Segment pathSegment = pathIt.next();
PathSegment flowSegment = flowPathIt.next();
if (!pathSegment.getSrcSwitchId().equals(flowSegment.getSrcSwitchId()) || !pathSegment.getDestSwitchId().equals(flowSegment.getDestSwitchId()) || pathSegment.getSrcPort() != flowSegment.getSrcPort() || pathSegment.getDestPort() != flowSegment.getDestPort()) {
return false;
}
}
return true;
}
use of org.openkilda.model.PathSegment in project open-kilda by telstra.
the class FlowPathBuilder method buildPathSegments.
/**
* Build a path segments using provided path.
*
* @param pathId a pathId the segments will be associated with.
* @param pathForSegments path to be used for the segments.
* @param bandwidth bandwidth to be used for the segments.
* @param ignoreBandwidth ignore bandwidth be used for the segments.
* @param sharedBandwidthGroupId a shared bandwidth group to be set for the segments
*/
public List<PathSegment> buildPathSegments(PathId pathId, Path pathForSegments, long bandwidth, boolean ignoreBandwidth, String sharedBandwidthGroupId) {
Map<SwitchId, SwitchProperties> switchProperties = getSwitchProperties(pathId);
List<PathSegment> result = new ArrayList<>();
for (int i = 0; i < pathForSegments.getSegments().size(); i++) {
Path.Segment segment = pathForSegments.getSegments().get(i);
SwitchProperties srcSwitchProperties = switchProperties.get(segment.getSrcSwitchId());
SwitchProperties dstSwitchProperties = switchProperties.get(segment.getDestSwitchId());
result.add(PathSegment.builder().seqId(i).pathId(pathId).srcSwitch(Switch.builder().switchId(segment.getSrcSwitchId()).build()).srcPort(segment.getSrcPort()).srcWithMultiTable(srcSwitchProperties.isMultiTable()).destSwitch(Switch.builder().switchId(segment.getDestSwitchId()).build()).destPort(segment.getDestPort()).destWithMultiTable(dstSwitchProperties.isMultiTable()).latency(segment.getLatency()).bandwidth(bandwidth).ignoreBandwidth(ignoreBandwidth).sharedBandwidthGroupId(sharedBandwidthGroupId).build());
}
return result;
}
use of org.openkilda.model.PathSegment in project open-kilda by telstra.
the class IntersectionComputerTest method shouldCalculateSharedPathWithNoSegments.
@Test
public void shouldCalculateSharedPathWithNoSegments() {
FlowPath firstPath = FlowPath.builder().pathId(PATH_ID).srcSwitch(makeSwitch(SWITCH_ID_A)).destSwitch(makeSwitch(SWITCH_ID_C)).segments(Lists.newArrayList(buildPathSegment(NEW_PATH_ID, SWITCH_ID_A, SWITCH_ID_D, 1, 1), buildPathSegment(NEW_PATH_ID, SWITCH_ID_D, SWITCH_ID_C, 2, 2))).build();
FlowPath secondPath = FlowPath.builder().pathId(NEW_PATH_ID).srcSwitch(makeSwitch(SWITCH_ID_A)).destSwitch(makeSwitch(SWITCH_ID_D)).segments(Lists.newArrayList(buildPathSegment(NEW_PATH_ID, SWITCH_ID_A, SWITCH_ID_B, 1, 1), buildPathSegment(NEW_PATH_ID, SWITCH_ID_B, SWITCH_ID_D, 3, 3))).build();
List<PathSegment> sharedPath = IntersectionComputer.calculatePathIntersectionFromSource(asList(firstPath, secondPath));
assertEquals(0, sharedPath.size());
}
use of org.openkilda.model.PathSegment in project open-kilda by telstra.
the class IntersectionComputerTest method shouldCalculateSharedPathWithSingleSegment.
@Test
public void shouldCalculateSharedPathWithSingleSegment() {
FlowPath firstPath = FlowPath.builder().pathId(PATH_ID).srcSwitch(makeSwitch(SWITCH_ID_A)).destSwitch(makeSwitch(SWITCH_ID_C)).segments(Lists.newArrayList(buildPathSegment(NEW_PATH_ID, SWITCH_ID_A, SWITCH_ID_B, 1, 1), buildPathSegment(NEW_PATH_ID, SWITCH_ID_B, SWITCH_ID_C, 2, 2))).build();
FlowPath secondPath = FlowPath.builder().pathId(NEW_PATH_ID).srcSwitch(makeSwitch(SWITCH_ID_A)).destSwitch(makeSwitch(SWITCH_ID_D)).segments(Lists.newArrayList(buildPathSegment(NEW_PATH_ID, SWITCH_ID_A, SWITCH_ID_B, 1, 1), buildPathSegment(NEW_PATH_ID, SWITCH_ID_B, SWITCH_ID_D, 3, 3))).build();
List<PathSegment> sharedPath = IntersectionComputer.calculatePathIntersectionFromSource(asList(firstPath, secondPath));
assertEquals(1, sharedPath.size());
PathSegment sharedSegment = sharedPath.get(0);
assertEquals(SWITCH_ID_A, sharedSegment.getSrcSwitchId());
assertEquals(SWITCH_ID_B, sharedSegment.getDestSwitchId());
}
use of org.openkilda.model.PathSegment in project open-kilda by telstra.
the class SimpleSwitchRuleConverter method buildIngressSimpleSwitchRules.
/**
* Build ingress rules ({@link SimpleSwitchRule}) for provided {@link FlowPath}.
*/
public List<SimpleSwitchRule> buildIngressSimpleSwitchRules(Flow flow, FlowPath flowPath, EncapsulationId encapsulationId, long flowMeterMinBurstSizeInKbits, double flowMeterBurstCoefficient) {
boolean forward = flow.isForward(flowPath);
int inPort = forward ? flow.getSrcPort() : flow.getDestPort();
int outPort = forward ? flow.getDestPort() : flow.getSrcPort();
SimpleSwitchRule rule = SimpleSwitchRule.builder().switchId(flowPath.getSrcSwitchId()).cookie(flowPath.getCookie().getValue()).inPort(inPort).meterId(flowPath.getMeterId() != null ? flowPath.getMeterId().getValue() : null).meterRate(flow.getBandwidth()).meterBurstSize(Meter.calculateBurstSize(flow.getBandwidth(), flowMeterMinBurstSizeInKbits, flowMeterBurstCoefficient, flowPath.getSrcSwitch().getDescription())).meterFlags(Meter.getMeterKbpsFlags()).ingressRule(true).build();
FlowSideAdapter ingress = FlowSideAdapter.makeIngressAdapter(flow, flowPath);
FlowEndpoint endpoint = ingress.getEndpoint();
if (flowPath.isSrcWithMultiTable()) {
// in multi-table mode actual ingress rule will match port+inner_vlan+metadata(outer_vlan)
if (FlowEndpoint.isVlanIdSet(endpoint.getInnerVlanId())) {
rule.setInVlan(endpoint.getInnerVlanId());
}
} else {
rule.setInVlan(endpoint.getOuterVlanId());
}
int transitVlan = 0;
int vni = 0;
if (flow.isOneSwitchFlow()) {
FlowEndpoint egressEndpoint = FlowSideAdapter.makeEgressAdapter(flow, flowPath).getEndpoint();
rule.setOutPort(outPort);
rule.setOutVlan(calcVlanSetSequence(ingress, flowPath, egressEndpoint.getVlanStack()));
} else {
PathSegment ingressSegment = flowPath.getSegments().stream().filter(segment -> segment.getSrcSwitchId().equals(flowPath.getSrcSwitchId())).findAny().orElseThrow(() -> new IllegalStateException(String.format("PathSegment was not found for ingress flow rule, flowId: %s", flow.getFlowId())));
outPort = ingressSegment.getSrcPort();
rule.setOutPort(outPort);
if (flow.getEncapsulationType().equals(FlowEncapsulationType.TRANSIT_VLAN)) {
transitVlan = encapsulationId.getEncapsulationId();
rule.setOutVlan(calcVlanSetSequence(ingress, flowPath, Collections.singletonList(transitVlan)));
} else if (flow.getEncapsulationType().equals(FlowEncapsulationType.VXLAN)) {
vni = encapsulationId.getEncapsulationId();
rule.setTunnelId(vni);
}
}
List<SimpleSwitchRule> rules = Lists.newArrayList(rule);
if (ingress.isLooped() && !flowPath.isProtected()) {
rules.add(buildIngressLoopSimpleSwitchRule(rule, flowPath, ingress));
}
Optional<FlowMirrorPoints> foundFlowMirrorPoints = flowPath.getFlowMirrorPointsSet().stream().filter(mirrorPoints -> mirrorPoints.getMirrorSwitchId().equals(flowPath.getSrcSwitchId())).findFirst();
if (foundFlowMirrorPoints.isPresent()) {
FlowMirrorPoints flowMirrorPoints = foundFlowMirrorPoints.get();
SimpleSwitchRule mirrorRule = rule.toBuilder().outPort(0).tunnelId(0).cookie(flowPath.getCookie().toBuilder().mirror(true).build().getValue()).groupId(flowMirrorPoints.getMirrorGroupId().intValue()).groupBuckets(mapGroupBuckets(flowMirrorPoints.getMirrorPaths(), outPort, transitVlan, vni)).build();
if (!flow.isOneSwitchFlow()) {
mirrorRule.setOutVlan(Collections.emptyList());
}
rules.add(mirrorRule);
}
return rules;
}
Aggregations