use of org.openkilda.model.Switch in project open-kilda by telstra.
the class ResourceAllocationAction method createFlowMirrorPoints.
private FlowMirrorPoints createFlowMirrorPoints(RequestedFlowMirrorPoint mirrorPoint, FlowPath flowPath) throws ResourceAllocationException {
Switch mirrorSwitch = switchRepository.findById(mirrorPoint.getMirrorPointSwitchId()).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Switch %s not found", mirrorPoint.getMirrorPointSwitchId())));
MirrorDirection direction = mirrorPoint.getMirrorPointSwitchId().equals(flowPath.getSrcSwitchId()) ? MirrorDirection.INGRESS : MirrorDirection.EGRESS;
MirrorGroup mirrorGroup = resourcesManager.getAllocatedMirrorGroup(mirrorPoint.getMirrorPointSwitchId(), mirrorPoint.getFlowId(), flowPath.getPathId(), MirrorGroupType.TRAFFIC_INTEGRITY, direction);
FlowMirrorPoints flowMirrorPoints = FlowMirrorPoints.builder().mirrorSwitch(mirrorSwitch).mirrorGroup(mirrorGroup).build();
flowMirrorPointsRepository.add(flowMirrorPoints);
flowPath.addFlowMirrorPoints(flowMirrorPoints);
return flowMirrorPoints;
}
use of org.openkilda.model.Switch in project open-kilda by telstra.
the class UpdateFlowAction method updateFlow.
private RequestedFlow updateFlow(Flow flow, RequestedFlow targetFlow) {
if (targetFlow.getDiverseFlowId() != null) {
if (targetFlow.getDiverseFlowId().isEmpty()) {
flow.setDiverseGroupId(null);
} else {
flow.setDiverseGroupId(getOrCreateDiverseFlowGroupId(targetFlow.getDiverseFlowId()));
}
} else if (targetFlow.isAllocateProtectedPath()) {
if (flow.getDiverseGroupId() == null) {
flow.setDiverseGroupId(getOrCreateDiverseFlowGroupId(flow.getFlowId()));
}
}
if (targetFlow.getAffinityFlowId() != null) {
if (targetFlow.getAffinityFlowId().isEmpty()) {
flow.setAffinityGroupId(null);
} else {
flow.setAffinityGroupId(getOrCreateAffinityFlowGroupId(targetFlow.getAffinityFlowId()));
}
}
Switch srcSwitch = switchRepository.findById(targetFlow.getSrcSwitch()).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Switch %s not found", targetFlow.getSrcSwitch())));
flow.setSrcSwitch(srcSwitch);
flow.setSrcPort(targetFlow.getSrcPort());
flow.setSrcVlan(targetFlow.getSrcVlan());
flow.setSrcInnerVlan(targetFlow.getSrcInnerVlan());
DetectConnectedDevices.DetectConnectedDevicesBuilder detectConnectedDevices = flow.getDetectConnectedDevices().toBuilder();
detectConnectedDevices.srcLldp(targetFlow.getDetectConnectedDevices().isSrcLldp());
detectConnectedDevices.srcArp(targetFlow.getDetectConnectedDevices().isSrcArp());
Switch destSwitch = switchRepository.findById(targetFlow.getDestSwitch()).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Switch %s not found", targetFlow.getDestSwitch())));
flow.setDestSwitch(destSwitch);
flow.setDestPort(targetFlow.getDestPort());
flow.setDestVlan(targetFlow.getDestVlan());
flow.setDestInnerVlan(targetFlow.getDestInnerVlan());
detectConnectedDevices.dstLldp(targetFlow.getDetectConnectedDevices().isDstLldp());
detectConnectedDevices.dstArp(targetFlow.getDetectConnectedDevices().isDstArp());
flow.setDetectConnectedDevices(detectConnectedDevices.build());
if (targetFlow.getPriority() != null) {
flow.setPriority(targetFlow.getPriority());
}
flow.setPinned(targetFlow.isPinned());
flow.setAllocateProtectedPath(targetFlow.isAllocateProtectedPath());
if (targetFlow.getDescription() != null) {
flow.setDescription(targetFlow.getDescription());
}
flow.setBandwidth(targetFlow.getBandwidth());
flow.setIgnoreBandwidth(targetFlow.isIgnoreBandwidth());
flow.setStrictBandwidth(targetFlow.isStrictBandwidth());
if (targetFlow.getMaxLatency() != null) {
flow.setMaxLatency(targetFlow.getMaxLatency());
}
if (targetFlow.getMaxLatencyTier2() != null) {
flow.setMaxLatencyTier2(targetFlow.getMaxLatencyTier2());
}
flow.setPeriodicPings(targetFlow.isPeriodicPings());
if (targetFlow.getFlowEncapsulationType() != null) {
flow.setEncapsulationType(targetFlow.getFlowEncapsulationType());
} else {
targetFlow.setFlowEncapsulationType(flow.getEncapsulationType());
}
if (targetFlow.getPathComputationStrategy() != null) {
flow.setPathComputationStrategy(targetFlow.getPathComputationStrategy());
flow.setTargetPathComputationStrategy(null);
} else {
if (flow.getTargetPathComputationStrategy() != null) {
targetFlow.setPathComputationStrategy(flow.getTargetPathComputationStrategy());
flow.setPathComputationStrategy(flow.getTargetPathComputationStrategy());
flow.setTargetPathComputationStrategy(null);
} else {
targetFlow.setPathComputationStrategy(flow.getPathComputationStrategy());
}
}
flow.setLoopSwitchId(targetFlow.getLoopSwitchId());
return targetFlow;
}
use of org.openkilda.model.Switch 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.Switch in project open-kilda by telstra.
the class FlowValidator method validateQinQonWB.
@VisibleForTesting
void validateQinQonWB(RequestedFlow requestedFlow) throws UnavailableFlowEndpointException, InvalidFlowException {
final FlowEndpoint source = RequestedFlowMapper.INSTANCE.mapSource(requestedFlow);
final FlowEndpoint destination = RequestedFlowMapper.INSTANCE.mapDest(requestedFlow);
if (source.getInnerVlanId() != 0) {
Switch srcSwitch = switchRepository.findById(source.getSwitchId()).orElseThrow(() -> new UnavailableFlowEndpointException(format("Endpoint switch not found %s", source.getSwitchId())));
if (Switch.isNoviflowESwitch(srcSwitch.getOfDescriptionManufacturer(), srcSwitch.getOfDescriptionHardware())) {
String message = format("QinQ feature is temporary disabled for WB-series switch '%s'", srcSwitch.getSwitchId());
throw new InvalidFlowException(message, ErrorType.PARAMETERS_INVALID);
}
}
if (destination.getInnerVlanId() != 0) {
Switch destSwitch = switchRepository.findById(destination.getSwitchId()).orElseThrow(() -> new UnavailableFlowEndpointException(format("Endpoint switch not found %s", destination.getSwitchId())));
if (Switch.isNoviflowESwitch(destSwitch.getOfDescriptionManufacturer(), destSwitch.getOfDescriptionHardware())) {
String message = format("QinQ feature is temporary disabled for WB-series switch '%s'", destSwitch.getSwitchId());
throw new InvalidFlowException(message, ErrorType.PARAMETERS_INVALID);
}
}
}
use of org.openkilda.model.Switch 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