use of org.openkilda.model.YFlow in project open-kilda by telstra.
the class AbstractYFlowTest method createYFlowViaTransit.
protected YFlow createYFlowViaTransit(String yFlowId) {
// Create sub-flows
Flow firstFlow = dummyFactory.makeMainAffinityFlow(firstSharedEndpoint, firstEndpoint, islSharedToTransit, islTransitToFirst);
Flow secondFlow = dummyFactory.makeFlow(secondSharedEndpoint, secondEndpoint, firstFlow.getAffinityGroupId(), islSharedToTransit, islTransitToSecond);
SwitchId yPoint = SWITCH_TRANSIT;
FlowMeter yPointMeter = dummyFactory.makeFlowMeter(yPoint, yFlowId, null);
FlowMeter sharedEndpointMeter = dummyFactory.makeFlowMeter(firstSharedEndpoint.getSwitchId(), yFlowId, null);
YFlow yFlow = YFlow.builder().yFlowId(yFlowId).sharedEndpoint(new SharedEndpoint(firstSharedEndpoint.getSwitchId(), firstSharedEndpoint.getPortNumber())).sharedEndpointMeterId(sharedEndpointMeter.getMeterId()).yPoint(yPoint).meterId(yPointMeter.getMeterId()).status(FlowStatus.UP).build();
yFlow.setSubFlows(Stream.of(firstFlow, secondFlow).map(flow -> YSubFlow.builder().sharedEndpointVlan(flow.getSrcVlan()).sharedEndpointInnerVlan(flow.getSrcInnerVlan()).endpointSwitchId(flow.getDestSwitchId()).endpointPort(flow.getDestPort()).endpointVlan(flow.getDestVlan()).endpointInnerVlan(flow.getDestInnerVlan()).flow(flow).yFlow(yFlow).build()).collect(Collectors.toSet()));
YFlowRepository yFlowRepository = persistenceManager.getRepositoryFactory().createYFlowRepository();
yFlowRepository.add(yFlow);
return yFlow;
}
use of org.openkilda.model.YFlow in project open-kilda by telstra.
the class AbstractYFlowTest method createYFlowWithProtected.
protected YFlow createYFlowWithProtected(String yFlowId) {
dummyFactory.getFlowDefaults().setAllocateProtectedPath(true);
// Create sub-flows
Flow firstFlow = dummyFactory.makeMainAffinityFlowWithProtectedPath(firstSharedEndpoint, firstEndpoint, asList(islSharedToTransit, islTransitToFirst), asList(islSharedToAltTransit, islAltTransitToFirst));
Flow secondFlow = dummyFactory.makeFlowWithProtectedPath(secondSharedEndpoint, secondEndpoint, firstFlow.getAffinityGroupId(), asList(islSharedToTransit, islTransitToSecond), asList(islSharedToAltTransit, islAltTransitToSecond));
YFlow yFlow = YFlow.builder().yFlowId(yFlowId).sharedEndpoint(new SharedEndpoint(firstSharedEndpoint.getSwitchId(), firstSharedEndpoint.getPortNumber())).allocateProtectedPath(true).status(FlowStatus.UP).build();
yFlow.setSubFlows(Stream.of(firstFlow, secondFlow).map(flow -> YSubFlow.builder().sharedEndpointVlan(flow.getSrcVlan()).sharedEndpointInnerVlan(flow.getSrcInnerVlan()).endpointSwitchId(flow.getDestSwitchId()).endpointPort(flow.getDestPort()).endpointVlan(flow.getDestVlan()).endpointInnerVlan(flow.getDestInnerVlan()).flow(flow).yFlow(yFlow).build()).collect(Collectors.toSet()));
YFlowRepository yFlowRepository = persistenceManager.getRepositoryFactory().createYFlowRepository();
yFlowRepository.add(yFlow);
return yFlow;
}
use of org.openkilda.model.YFlow in project open-kilda by telstra.
the class FlowValidator method checkDiverseFlow.
@VisibleForTesting
void checkDiverseFlow(RequestedFlow targetFlow) throws InvalidFlowException {
if (targetFlow.getSrcSwitch().equals(targetFlow.getDestSwitch())) {
throw new InvalidFlowException("Couldn't add one-switch flow into diverse group", ErrorType.PARAMETERS_INVALID);
}
Flow diverseFlow = flowRepository.findById(targetFlow.getDiverseFlowId()).orElse(null);
if (diverseFlow == null) {
YFlow diverseYFlow = yFlowRepository.findById(targetFlow.getDiverseFlowId()).orElseThrow(() -> new InvalidFlowException(format("Failed to find diverse flow id %s", targetFlow.getDiverseFlowId()), ErrorType.PARAMETERS_INVALID));
diverseFlow = diverseYFlow.getSubFlows().stream().map(YSubFlow::getFlow).filter(flow -> flow.getFlowId().equals(flow.getAffinityGroupId())).findFirst().orElseThrow(() -> new InvalidFlowException(format("Failed to find main affinity flow for diverse y-flow id %s", targetFlow.getDiverseFlowId()), ErrorType.INTERNAL_ERROR));
}
if (StringUtils.isNotBlank(diverseFlow.getAffinityGroupId())) {
String diverseFlowId = diverseFlow.getAffinityGroupId();
diverseFlow = flowRepository.findById(diverseFlowId).orElseThrow(() -> new InvalidFlowException(format("Failed to find diverse flow id %s", diverseFlowId), ErrorType.PARAMETERS_INVALID));
Collection<String> affinityFlowIds = flowRepository.findFlowsIdByAffinityGroupId(diverseFlow.getAffinityGroupId()).stream().filter(Objects::nonNull).collect(Collectors.toSet());
if (affinityFlowIds.contains(targetFlow.getAffinityFlowId())) {
throw new InvalidFlowException("Couldn't create diverse group with flow in the same affinity group", ErrorType.PARAMETERS_INVALID);
}
}
if (diverseFlow.isOneSwitchFlow()) {
throw new InvalidFlowException("Couldn't create diverse group with one-switch flow", ErrorType.PARAMETERS_INVALID);
}
}
use of org.openkilda.model.YFlow in project open-kilda by telstra.
the class YFlowRerouteServiceTest method verifyYFlowStatus.
protected YFlow verifyYFlowStatus(String yFlowId, FlowStatus expectedStatus, FlowStatus expectedFirstSubFlowStatus, FlowStatus expectedSecondSubFlowStatus) {
YFlow flow = getYFlow(yFlowId);
assertEquals(expectedStatus, flow.getStatus());
Set<FlowStatus> expectedSubFlowStatuses = Stream.of(expectedFirstSubFlowStatus, expectedSecondSubFlowStatus).collect(Collectors.toSet());
Set<FlowStatus> actualSubFlowStatuses = flow.getSubFlows().stream().map(YSubFlow::getFlow).map(Flow::getStatus).collect(Collectors.toSet());
assertEquals(expectedSubFlowStatuses, actualSubFlowStatuses);
return flow;
}
use of org.openkilda.model.YFlow in project open-kilda by telstra.
the class YFlowValidationHubServiceTest method shouldValidateYFlowSuccessfully.
@Test
public void shouldValidateYFlowSuccessfully() throws DuplicateKeyException {
// given
String yFlowId = "test_y_flow_1";
YFlow yFlow = createYFlowViaTransit(yFlowId);
YFlowSwitchFlowEntriesBuilder flowEntriesBuilder = new YFlowSwitchFlowEntriesBuilder(yFlow, persistenceManager.getRepositoryFactory().createTransitVlanRepository(), persistenceManager.getRepositoryFactory().createVxlanRepository());
Map<SwitchId, Collection<FlowEntry>> flowEntries = flowEntriesBuilder.getFlowEntries();
Map<SwitchId, Collection<MeterEntry>> meterEntries = flowEntriesBuilder.getMeterEntries();
Map<SwitchId, Collection<GroupEntry>> groupEntries = flowEntriesBuilder.getGroupEntries();
YFlowValidationHubService service = makeYFlowValidationHubService();
service.handleRequest(yFlow.getYFlowId(), new CommandContext(), yFlow.getYFlowId());
// when
handleSpeakerRequests(service, yFlowId, flowEntries, meterEntries, groupEntries);
// then
verifyNorthboundSuccessResponse(yFlowValidationHubCarrier);
}
Aggregations