use of org.openkilda.model.SwitchId in project open-kilda by telstra.
the class OnSubFlowAllocatedAction method buildRerouteResponseMessage.
private Message buildRerouteResponseMessage(YFlowRerouteFsm stateMachine) {
String yFlowId = stateMachine.getYFlowId();
List<Long> oldFlowPathCookies = stateMachine.getOldYFlowPathCookies();
List<FlowPath> flowPaths = transactionManager.doInTransaction(() -> {
YFlow yflow = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Y-flow %s not found", yFlowId)));
SwitchId sharedSwitchId = yflow.getSharedEndpoint().getSwitchId();
List<FlowPath> paths = new ArrayList<>();
for (YSubFlow subFlow : yflow.getSubFlows()) {
Flow flow = subFlow.getFlow();
FlowPath flowPath = flow.getPaths().stream().filter(path -> sharedSwitchId.equals(path.getSrcSwitchId()) && !path.isProtected() && !oldFlowPathCookies.contains(path.getCookie().getValue())).findFirst().orElse(sharedSwitchId.equals(flow.getForwardPath().getSrcSwitchId()) ? flow.getForwardPath() : flow.getReversePath());
paths.add(flowPath);
}
return paths;
});
List<PathSegment> sharedPathSegments = IntersectionComputer.calculatePathIntersectionFromSource(flowPaths);
PathInfoData sharedPath = FlowPathMapper.INSTANCE.map(sharedPathSegments);
List<SubFlowPathDto> subFlowPathDtos = flowPaths.stream().map(flowPath -> new SubFlowPathDto(flowPath.getFlowId(), FlowPathMapper.INSTANCE.map(flowPath))).sorted(Comparator.comparing(SubFlowPathDto::getFlowId)).collect(Collectors.toList());
PathInfoData oldSharedPath = stateMachine.getOldSharedPath();
List<SubFlowPathDto> oldSubFlowPathDtos = stateMachine.getOldSubFlowPathDtos();
YFlowRerouteResponse response = new YFlowRerouteResponse(sharedPath, subFlowPathDtos, !(sharedPath.equals(oldSharedPath) && subFlowPathDtos.equals(oldSubFlowPathDtos)));
CommandContext commandContext = stateMachine.getCommandContext();
return new InfoMessage(response, commandContext.getCreateTime(), commandContext.getCorrelationId());
}
use of org.openkilda.model.SwitchId in project open-kilda by telstra.
the class YFlowSwitchFlowEntriesBuilder method getGroupEntries.
/**
* Construct a set of {@link GroupEntry} that corresponds to the builder's y-flow.
*/
public Map<SwitchId, Collection<GroupEntry>> getGroupEntries() {
MultiValuedMap<SwitchId, GroupEntry> groupEntries = new ArrayListValuedHashMap<>();
yFlow.getSubFlows().forEach(subFlow -> {
Flow flow = subFlow.getFlow();
SwitchFlowEntriesBuilder builder = new SwitchFlowEntriesBuilder(flow);
builder.getSwitchGroupEntries().forEach(entries -> groupEntries.putAll(entries.getSwitchId(), entries.getGroupEntries()));
});
return groupEntries.asMap();
}
use of org.openkilda.model.SwitchId 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.SwitchId in project open-kilda by telstra.
the class FlowValidator method checkSwitchesSupportLldpAndArpIfNeeded.
/**
* Ensure switches support LLDP/ARP.
*
* @param requestedFlow a flow to be validated.
*/
// TODO: switch to per endpoint based strategy (same as other enpoint related checks)
@VisibleForTesting
void checkSwitchesSupportLldpAndArpIfNeeded(RequestedFlow requestedFlow) throws InvalidFlowException {
SwitchId sourceId = requestedFlow.getSrcSwitch();
SwitchId destinationId = requestedFlow.getDestSwitch();
List<String> errorMessages = new ArrayList<>();
if (requestedFlow.getDetectConnectedDevices().isSrcLldp() || requestedFlow.getDetectConnectedDevices().isSrcArp()) {
validateMultiTableProperty(sourceId, errorMessages);
}
if (requestedFlow.getDetectConnectedDevices().isDstLldp() || requestedFlow.getDetectConnectedDevices().isDstArp()) {
validateMultiTableProperty(destinationId, errorMessages);
}
if (!errorMessages.isEmpty()) {
throw new InvalidFlowException(String.join(" ", errorMessages), ErrorType.DATA_INVALID);
}
}
use of org.openkilda.model.SwitchId in project open-kilda by telstra.
the class FlowValidator method baseFlowValidate.
private void baseFlowValidate(RequestedFlow flow, Set<String> bulkUpdateFlowIds) throws InvalidFlowException, UnavailableFlowEndpointException {
final FlowEndpoint source = RequestedFlowMapper.INSTANCE.mapSource(flow);
final FlowEndpoint destination = RequestedFlowMapper.INSTANCE.mapDest(flow);
checkOneSwitchFlowConflict(source, destination);
checkSwitchesExistsAndActive(flow.getSrcSwitch(), flow.getDestSwitch());
for (EndpointDescriptor descriptor : new EndpointDescriptor[] { EndpointDescriptor.makeSource(source), EndpointDescriptor.makeDestination(destination) }) {
SwitchId switchId = descriptor.endpoint.getSwitchId();
SwitchProperties properties = switchPropertiesRepository.findBySwitchId(switchId).orElseThrow(() -> new InvalidFlowException(format("Couldn't get switch properties for %s switch %s.", descriptor.name, switchId), ErrorType.DATA_INVALID));
// skip encapsulation type check for one switch flow
if (!source.getSwitchId().equals(destination.getSwitchId())) {
checkForEncapsulationTypeRequirement(descriptor, properties, flow.getFlowEncapsulationType());
}
checkForMultiTableRequirement(descriptor, properties);
checkFlowForIslConflicts(descriptor);
checkFlowForFlowConflicts(flow.getFlowId(), descriptor, bulkUpdateFlowIds);
checkFlowForSinkEndpointConflicts(descriptor);
checkFlowForMirrorEndpointConflicts(flow.getFlowId(), descriptor);
checkFlowForServer42Conflicts(descriptor, properties);
}
}
Aggregations