use of org.openkilda.model.FlowPath in project open-kilda by telstra.
the class YFlowReadService method getYFlowPaths.
/**
* Gets y-flow paths.
*/
public YFlowPathsResponse getYFlowPaths(@NonNull String yFlowId) throws FlowNotFoundException {
return transactionManager.doInTransaction(getReadOperationRetryPolicy(), () -> {
Set<YSubFlow> subFlows = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowNotFoundException(yFlowId)).getSubFlows();
Set<FlowPath> mainPaths = new HashSet<>();
Set<FlowPath> protectedPaths = new HashSet<>();
for (YSubFlow subFlow : subFlows) {
Flow flow = subFlow.getFlow();
mainPaths.add(flow.getForwardPath());
if (flow.isAllocateProtectedPath() && flow.getProtectedForwardPath() != null) {
protectedPaths.add(flow.getProtectedForwardPath());
}
}
List<PathSegment> sharedPathSegments = IntersectionComputer.calculatePathIntersectionFromSource(mainPaths);
PathInfoData sharedPath = FlowPathMapper.INSTANCE.map(sharedPathSegments);
PathInfoData sharedProtectedPath;
// At least 2 paths required to calculate Y-point.
if (protectedPaths.size() < 2) {
sharedProtectedPath = new PathInfoData();
} else {
List<PathSegment> pathSegments = IntersectionComputer.calculatePathIntersectionFromSource(protectedPaths);
sharedProtectedPath = FlowPathMapper.INSTANCE.map(pathSegments);
}
List<SubFlowPathDto> subFlowPathDtos = mainPaths.stream().map(flowPath -> new SubFlowPathDto(flowPath.getFlowId(), FlowPathMapper.INSTANCE.map(flowPath))).collect(Collectors.toList());
List<SubFlowPathDto> subFlowProtectedPathDtos = protectedPaths.stream().map(flowPath -> new SubFlowPathDto(flowPath.getFlowId(), FlowPathMapper.INSTANCE.map(flowPath))).collect(Collectors.toList());
return new YFlowPathsResponse(sharedPath, subFlowPathDtos, sharedProtectedPath, subFlowProtectedPathDtos);
});
}
use of org.openkilda.model.FlowPath in project open-kilda by telstra.
the class YFlowValidationService method buildSimpleSwitchRules.
private List<SimpleSwitchRule> buildSimpleSwitchRules(Flow subFlow, SwitchId sharedEndpoint, MeterId sharedMeterId, PathId forwardId, PathId reverseId, SwitchId yPoint, MeterId yMeterId) {
EncapsulationId encapsulationId = flowResourcesManager.getEncapsulationResources(forwardId, reverseId, subFlow.getEncapsulationType()).map(EncapsulationResources::getEncapsulation).orElseThrow(() -> new IllegalStateException(String.format("Encapsulation id was not found, pathId: %s", forwardId)));
FlowPath forward = subFlow.getPath(forwardId).orElseThrow(() -> new IllegalStateException(String.format("Path was not found, pathId: %s", forwardId)));
FlowPath reverse = subFlow.getPath(reverseId).orElseThrow(() -> new IllegalStateException(String.format("Path was not found, pathId: %s", reverseId)));
if (reverse.getSrcSwitchId().equals(sharedEndpoint)) {
FlowPath tmp = reverse;
reverse = forward;
forward = tmp;
}
Collection<SimpleSwitchRule> ingressRules = simpleSwitchRuleConverter.buildIngressSimpleSwitchRules(subFlow, forward, encapsulationId, flowMeterMinBurstSizeInKbits, flowMeterBurstCoefficient);
// TODO: apply shared endpoint y-flow cookie flags & sharedMeterId
List<SimpleSwitchRule> result = new ArrayList<>(ingressRules);
List<PathSegment> orderedSegments = reverse.getSegments().stream().sorted(Comparator.comparingInt(PathSegment::getSeqId)).collect(Collectors.toList());
for (int i = 1; i < orderedSegments.size(); i++) {
PathSegment srcPathSegment = orderedSegments.get(i - 1);
PathSegment dstPathSegment = orderedSegments.get(i);
if (dstPathSegment.getSrcSwitch().equals(yPoint)) {
SimpleSwitchRule yPointTransitRules = simpleSwitchRuleConverter.buildTransitSimpleSwitchRule(subFlow, reverse, srcPathSegment, dstPathSegment, encapsulationId);
// TODO: apply shared endpoint y-flow cookie flags & yMeterId
result.add(yPointTransitRules);
break;
}
}
return result;
}
use of org.openkilda.model.FlowPath in project open-kilda by telstra.
the class SwitchFlowEntriesBuilder method getSwitchMeterEntries.
/**
* Construct a list of {@link SwitchMeterEntries} that corresponds to the builder's flow.
*/
public List<SwitchMeterEntries> getSwitchMeterEntries() {
List<SwitchMeterEntries> switchMeterEntries = new ArrayList<>();
FlowPath forwardPath = flow.getForwardPath();
switchMeterEntries.add(SwitchMeterEntries.builder().switchId(flow.getSrcSwitchId()).meterEntries(Collections.singletonList(MeterEntry.builder().meterId(forwardPath.getMeterId().getValue()).rate(forwardPath.getBandwidth()).burstSize(Meter.calculateBurstSize(forwardPath.getBandwidth(), MIN_BURST_SIZE_IN_KBITS, BURST_COEFFICIENT, "")).flags(Meter.getMeterKbpsFlags()).build())).build());
FlowPath reversePath = flow.getReversePath();
switchMeterEntries.add(SwitchMeterEntries.builder().switchId(flow.getDestSwitchId()).meterEntries(Collections.singletonList(MeterEntry.builder().meterId(reversePath.getMeterId().getValue()).rate(reversePath.getBandwidth()).burstSize(Meter.calculateBurstSize(reversePath.getBandwidth(), MIN_BURST_SIZE_IN_KBITS, BURST_COEFFICIENT, "")).flags(Meter.getMeterKbpsFlags()).build())).build());
FlowPath protectedForwardPath = flow.getProtectedForwardPath();
if (protectedForwardPath != null) {
switchMeterEntries.add(SwitchMeterEntries.builder().switchId(flow.getSrcSwitchId()).meterEntries(Collections.singletonList(MeterEntry.builder().meterId(protectedForwardPath.getMeterId().getValue()).rate(protectedForwardPath.getBandwidth()).burstSize(Meter.calculateBurstSize(protectedForwardPath.getBandwidth(), MIN_BURST_SIZE_IN_KBITS, BURST_COEFFICIENT, "")).flags(Meter.getMeterKbpsFlags()).build())).build());
}
FlowPath protectedReversePath = flow.getProtectedReversePath();
if (protectedReversePath != null) {
switchMeterEntries.add(SwitchMeterEntries.builder().switchId(flow.getDestSwitchId()).meterEntries(Collections.singletonList(MeterEntry.builder().meterId(protectedReversePath.getMeterId().getValue()).rate(protectedReversePath.getBandwidth()).burstSize(Meter.calculateBurstSize(protectedReversePath.getBandwidth(), MIN_BURST_SIZE_IN_KBITS, BURST_COEFFICIENT, "")).flags(Meter.getMeterKbpsFlags()).build())).build());
}
return switchMeterEntries;
}
use of org.openkilda.model.FlowPath in project open-kilda by telstra.
the class FlowDeleteServiceTest method shouldCompleteDeleteOnErrorDuringResourceDeallocation.
@Test
public void shouldCompleteDeleteOnErrorDuringResourceDeallocation() throws DuplicateKeyException, UnknownKeyException {
Flow target = makeFlow();
FlowPath forwardPath = target.getForwardPath();
Assert.assertNotNull(forwardPath);
doThrow(new RuntimeException(injectedErrorMessage)).when(flowResourcesManager).deallocatePathResources(MockitoHamcrest.argThat(Matchers.hasProperty("forward", Matchers.<PathResources>hasProperty("pathId", is(forwardPath.getPathId())))));
FlowDeleteService service = makeService();
service.handleRequest(dummyRequestKey, commandContext, target.getFlowId());
verifyFlowStatus(target.getFlowId(), FlowStatus.IN_PROGRESS);
verifyNorthboundSuccessResponse(carrier);
produceSpeakerResponses(service);
// 4 flow rules + 4 mirror rules
verify(carrier, times(8)).sendSpeakerRequest(any());
verifyFlowIsMissing(target);
}
use of org.openkilda.model.FlowPath in project open-kilda by telstra.
the class FlowValidationTestBase method buildFlow.
protected void buildFlow(FlowEncapsulationType flowEncapsulationType, String endpointSwitchManufacturer) {
Switch switchA = Switch.builder().switchId(TEST_SWITCH_ID_A).description("").build();
switchRepository.add(switchA);
switchA.setOfDescriptionManufacturer(endpointSwitchManufacturer);
Switch switchB = Switch.builder().switchId(TEST_SWITCH_ID_B).description("").build();
switchRepository.add(switchB);
Switch switchC = Switch.builder().switchId(TEST_SWITCH_ID_C).description("").build();
switchRepository.add(switchC);
Switch switchE = Switch.builder().switchId(TEST_SWITCH_ID_E).description("").build();
switchRepository.add(switchE);
Flow flow = Flow.builder().flowId(TEST_FLOW_ID_A).srcSwitch(switchA).srcPort(FLOW_A_SRC_PORT).srcVlan(FLOW_A_SRC_VLAN).destSwitch(switchC).destPort(FLOW_A_DST_PORT).destVlan(FLOW_A_DST_VLAN).allocateProtectedPath(true).encapsulationType(flowEncapsulationType).bandwidth(FLOW_A_BANDWIDTH).status(FlowStatus.UP).build();
FlowPath forwardFlowPath = FlowPath.builder().pathId(FLOW_A_FORWARD_PATH_ID).cookie(new FlowSegmentCookie(FLOW_A_FORWARD_COOKIE)).meterId(new MeterId(FLOW_A_FORWARD_METER_ID)).srcSwitch(switchA).destSwitch(switchC).bandwidth(FLOW_A_BANDWIDTH).status(FlowPathStatus.ACTIVE).build();
flow.setForwardPath(forwardFlowPath);
PathSegment forwardSegmentA = PathSegment.builder().pathId(forwardFlowPath.getPathId()).srcSwitch(switchA).srcPort(FLOW_A_SEGMENT_A_SRC_PORT).destSwitch(switchB).destPort(FLOW_A_SEGMENT_A_DST_PORT).build();
PathSegment forwardSegmentB = PathSegment.builder().pathId(forwardFlowPath.getPathId()).srcSwitch(switchB).srcPort(FLOW_A_SEGMENT_B_SRC_PORT).destSwitch(switchC).destPort(FLOW_A_SEGMENT_B_DST_PORT).build();
forwardFlowPath.setSegments(Lists.newArrayList(forwardSegmentA, forwardSegmentB));
FlowPath forwardProtectedFlowPath = FlowPath.builder().pathId(FLOW_A_FORWARD_PATH_ID_PROTECTED).cookie(new FlowSegmentCookie(FLOW_A_FORWARD_COOKIE_PROTECTED)).meterId(new MeterId(FLOW_A_FORWARD_METER_ID_PROTECTED)).srcSwitch(switchA).destSwitch(switchC).bandwidth(FLOW_A_BANDWIDTH).status(FlowPathStatus.ACTIVE).build();
flow.setProtectedForwardPath(forwardProtectedFlowPath);
PathSegment forwardProtectedSegmentA = PathSegment.builder().pathId(forwardProtectedFlowPath.getPathId()).srcSwitch(switchA).srcPort(FLOW_A_SEGMENT_A_SRC_PORT_PROTECTED).destSwitch(switchE).destPort(FLOW_A_SEGMENT_A_DST_PORT_PROTECTED).build();
PathSegment forwardProtectedSegmentB = PathSegment.builder().pathId(forwardProtectedFlowPath.getPathId()).srcSwitch(switchE).srcPort(FLOW_A_SEGMENT_B_SRC_PORT_PROTECTED).destSwitch(switchC).destPort(FLOW_A_SEGMENT_B_DST_PORT_PROTECTED).build();
forwardProtectedFlowPath.setSegments(Lists.newArrayList(forwardProtectedSegmentA, forwardProtectedSegmentB));
FlowPath reverseFlowPath = FlowPath.builder().pathId(FLOW_A_REVERSE_PATH_ID).cookie(new FlowSegmentCookie(FLOW_A_REVERSE_COOKIE)).meterId(new MeterId(FLOW_A_REVERSE_METER_ID)).srcSwitch(switchC).destSwitch(switchA).bandwidth(FLOW_A_BANDWIDTH).status(FlowPathStatus.ACTIVE).build();
flow.setReversePath(reverseFlowPath);
PathSegment reverseSegmentA = PathSegment.builder().pathId(reverseFlowPath.getPathId()).srcSwitch(switchC).srcPort(FLOW_A_SEGMENT_B_DST_PORT).destSwitch(switchB).destPort(FLOW_A_SEGMENT_B_SRC_PORT).build();
PathSegment reverseSegmentB = PathSegment.builder().pathId(reverseFlowPath.getPathId()).srcSwitch(switchB).srcPort(FLOW_A_SEGMENT_A_DST_PORT).destSwitch(switchA).destPort(FLOW_A_SEGMENT_A_SRC_PORT).build();
reverseFlowPath.setSegments(Lists.newArrayList(reverseSegmentA, reverseSegmentB));
FlowPath reverseProtectedFlowPath = FlowPath.builder().pathId(FLOW_A_REVERSE_PATH_ID_PROTECTED).cookie(new FlowSegmentCookie(FLOW_A_REVERSE_COOKIE_PROTECTED)).meterId(new MeterId(FLOW_A_REVERSE_METER_ID_PROTECTED)).srcSwitch(switchC).destSwitch(switchA).bandwidth(FLOW_A_BANDWIDTH).status(FlowPathStatus.ACTIVE).build();
flow.setProtectedReversePath(reverseProtectedFlowPath);
PathSegment reverseProtectedSegmentA = PathSegment.builder().pathId(reverseProtectedFlowPath.getPathId()).srcSwitch(switchC).srcPort(FLOW_A_SEGMENT_B_DST_PORT_PROTECTED).destSwitch(switchE).destPort(FLOW_A_SEGMENT_B_SRC_PORT_PROTECTED).build();
PathSegment reverseProtectedSegmentB = PathSegment.builder().pathId(reverseProtectedFlowPath.getPathId()).srcSwitch(switchE).srcPort(FLOW_A_SEGMENT_A_DST_PORT_PROTECTED).destSwitch(switchA).destPort(FLOW_A_SEGMENT_A_SRC_PORT_PROTECTED).build();
reverseProtectedFlowPath.setSegments(Lists.newArrayList(reverseProtectedSegmentA, reverseProtectedSegmentB));
flowRepository.add(flow);
}
Aggregations