use of org.openkilda.model.FlowEndpoint in project open-kilda by telstra.
the class BaseFlowRuleRemovalAction method buildSpeakerContextForRemovalIngressAndShared.
protected SpeakerRequestBuildContext buildSpeakerContextForRemovalIngressAndShared(RequestedFlow oldFlow, RequestedFlow newFlow, boolean removeMeters) {
SwitchProperties srcSwitchProperties = getSwitchProperties(oldFlow.getSrcSwitch());
boolean server42FlowRttToggle = isServer42FlowRttFeatureToggle();
boolean srcServer42FlowRtt = srcSwitchProperties.isServer42FlowRtt() && server42FlowRttToggle;
FlowEndpoint oldIngress = new FlowEndpoint(oldFlow.getSrcSwitch(), oldFlow.getSrcPort(), oldFlow.getSrcVlan(), oldFlow.getSrcInnerVlan());
FlowEndpoint oldEgress = new FlowEndpoint(oldFlow.getDestSwitch(), oldFlow.getDestPort(), oldFlow.getDestVlan(), oldFlow.getDestInnerVlan());
FlowEndpoint newIngress = new FlowEndpoint(newFlow.getSrcSwitch(), newFlow.getSrcPort(), newFlow.getSrcVlan(), newFlow.getSrcInnerVlan());
FlowEndpoint newEgress = new FlowEndpoint(newFlow.getDestSwitch(), newFlow.getDestPort(), newFlow.getDestVlan(), newFlow.getDestInnerVlan());
PathContext forwardPathContext = PathContext.builder().removeCustomerPortRule(removeForwardCustomerPortSharedCatchRule(oldFlow, newFlow)).removeCustomerPortLldpRule(removeForwardSharedLldpRule(oldFlow, newFlow)).removeCustomerPortArpRule(removeForwardSharedArpRule(oldFlow, newFlow)).removeOuterVlanMatchSharedRule(removeOuterVlanMatchSharedRule(oldFlow.getFlowId(), oldIngress, newIngress)).removeServer42InputRule(removeForwardSharedServer42InputRule(oldFlow, newFlow, srcServer42FlowRtt)).removeServer42IngressRule(srcServer42FlowRtt).updateMeter(removeMeters).removeServer42OuterVlanMatchSharedRule(srcServer42FlowRtt && removeServer42OuterVlanMatchSharedRule(oldFlow, oldIngress, newIngress)).server42Port(srcSwitchProperties.getServer42Port()).server42MacAddress(srcSwitchProperties.getServer42MacAddress()).build();
SwitchProperties dstSwitchProperties = getSwitchProperties(oldFlow.getDestSwitch());
boolean dstServer42FlowRtt = dstSwitchProperties.isServer42FlowRtt() && server42FlowRttToggle;
PathContext reversePathContext = PathContext.builder().removeCustomerPortRule(removeReverseCustomerPortSharedCatchRule(oldFlow, newFlow)).removeCustomerPortLldpRule(removeReverseSharedLldpRule(oldFlow, newFlow)).removeCustomerPortArpRule(removeReverseSharedArpRule(oldFlow, newFlow)).removeOuterVlanMatchSharedRule(removeOuterVlanMatchSharedRule(oldFlow.getFlowId(), oldEgress, newEgress)).removeServer42InputRule(removeReverseSharedServer42InputRule(oldFlow, newFlow, dstServer42FlowRtt)).removeServer42IngressRule(dstServer42FlowRtt).updateMeter(removeMeters).removeServer42OuterVlanMatchSharedRule(dstServer42FlowRtt && removeServer42OuterVlanMatchSharedRule(oldFlow, oldEgress, newEgress)).server42Port(dstSwitchProperties.getServer42Port()).server42MacAddress(dstSwitchProperties.getServer42MacAddress()).build();
return SpeakerRequestBuildContext.builder().forward(forwardPathContext).reverse(reversePathContext).build();
}
use of org.openkilda.model.FlowEndpoint in project open-kilda by telstra.
the class YFlowUpdateService method handlePartialUpdateRequest.
/**
* Handles request for y-flow patch updating.
*
* @param key command identifier.
* @param request request data.
*/
public void handlePartialUpdateRequest(@NonNull String key, @NonNull CommandContext commandContext, @NonNull YFlowPartialUpdateRequest request) throws DuplicateKeyException {
YFlowRequest target;
if (request.getYFlowId() != null) {
YFlow yFlow = yFlowRepository.findById(request.getYFlowId()).orElse(null);
target = YFlowRequestMapper.INSTANCE.toYFlowRequest(yFlow);
} else {
throw new FlowProcessingException(ErrorType.REQUEST_INVALID, "Need to specify the y-flow id");
}
if (target == null) {
throw new FlowProcessingException(ErrorType.NOT_FOUND, format("Y-flow was not found by the specified y-flow id: %s", request.getYFlowId()));
}
if (request.getSharedEndpoint() != null) {
if (target.getSharedEndpoint() == null) {
target.setSharedEndpoint(new FlowEndpoint(request.getSharedEndpoint().getSwitchId(), request.getSharedEndpoint().getPortNumber()));
} else {
SwitchId switchId = Optional.ofNullable(request.getSharedEndpoint().getSwitchId()).orElse(target.getSharedEndpoint().getSwitchId());
int portNumber = Optional.ofNullable(request.getSharedEndpoint().getPortNumber()).orElse(target.getSharedEndpoint().getPortNumber());
target.setSharedEndpoint(new FlowEndpoint(switchId, portNumber));
}
}
Optional.ofNullable(request.getMaximumBandwidth()).ifPresent(target::setMaximumBandwidth);
Optional.ofNullable(request.getPathComputationStrategy()).ifPresent(target::setPathComputationStrategy);
Optional.ofNullable(request.getEncapsulationType()).ifPresent(target::setEncapsulationType);
Optional.ofNullable(request.getMaxLatency()).ifPresent(target::setMaxLatency);
Optional.ofNullable(request.getMaxLatencyTier2()).ifPresent(target::setMaxLatencyTier2);
Optional.ofNullable(request.getIgnoreBandwidth()).ifPresent(target::setIgnoreBandwidth);
Optional.ofNullable(request.getPeriodicPings()).ifPresent(target::setPeriodicPings);
Optional.ofNullable(request.getPinned()).ifPresent(target::setPinned);
Optional.ofNullable(request.getPriority()).ifPresent(target::setPriority);
Optional.ofNullable(request.getStrictBandwidth()).ifPresent(target::setStrictBandwidth);
Optional.ofNullable(request.getDescription()).ifPresent(target::setDescription);
Optional.ofNullable(request.getAllocateProtectedPath()).ifPresent(target::setAllocateProtectedPath);
Optional.ofNullable(request.getDiverseFlowId()).ifPresent(target::setDiverseFlowId);
if (request.getSubFlows() != null && !request.getSubFlows().isEmpty()) {
Map<String, SubFlowDto> stringSubFlowDtoMap;
if (target.getSubFlows() != null) {
stringSubFlowDtoMap = target.getSubFlows().stream().collect(Collectors.toMap(SubFlowDto::getFlowId, Function.identity()));
} else {
throw new FlowProcessingException(ErrorType.INTERNAL_ERROR, format("Sub-flows for y-flow %s not found", target.getYFlowId()));
}
List<SubFlowDto> subFlows = new ArrayList<>();
for (SubFlowPartialUpdateDto subFlowPartialUpdate : request.getSubFlows()) {
SubFlowDto subFlow = stringSubFlowDtoMap.get(subFlowPartialUpdate.getFlowId());
if (subFlow != null) {
if (subFlowPartialUpdate.getEndpoint() != null) {
if (subFlow.getEndpoint() == null) {
subFlow.setEndpoint(new FlowEndpoint(subFlowPartialUpdate.getEndpoint().getSwitchId(), subFlowPartialUpdate.getEndpoint().getPortNumber(), subFlowPartialUpdate.getEndpoint().getVlanId(), subFlowPartialUpdate.getEndpoint().getInnerVlanId()));
} else {
SwitchId switchId = Optional.ofNullable(subFlowPartialUpdate.getEndpoint().getSwitchId()).orElse(subFlow.getEndpoint().getSwitchId());
int portNumber = Optional.ofNullable(subFlowPartialUpdate.getEndpoint().getPortNumber()).orElse(subFlow.getEndpoint().getPortNumber());
int vlanId = Optional.ofNullable(subFlowPartialUpdate.getEndpoint().getVlanId()).orElse(subFlow.getEndpoint().getOuterVlanId());
int innerVlanId = Optional.ofNullable(subFlowPartialUpdate.getEndpoint().getInnerVlanId()).orElse(subFlow.getEndpoint().getInnerVlanId());
subFlow.setEndpoint(new FlowEndpoint(switchId, portNumber, vlanId, innerVlanId));
}
}
if (subFlowPartialUpdate.getSharedEndpoint() != null) {
if (subFlow.getSharedEndpoint() == null) {
subFlow.setSharedEndpoint(new SubFlowSharedEndpointEncapsulation(subFlowPartialUpdate.getSharedEndpoint().getVlanId(), subFlowPartialUpdate.getSharedEndpoint().getInnerVlanId()));
} else {
int vlanId = Optional.ofNullable(subFlowPartialUpdate.getSharedEndpoint().getVlanId()).orElse(subFlow.getSharedEndpoint().getVlanId());
int innerVlanId = Optional.ofNullable(subFlowPartialUpdate.getSharedEndpoint().getInnerVlanId()).orElse(subFlow.getSharedEndpoint().getInnerVlanId());
subFlow.setSharedEndpoint(new SubFlowSharedEndpointEncapsulation(vlanId, innerVlanId));
}
}
Optional.ofNullable(subFlowPartialUpdate.getDescription()).ifPresent(subFlow::setDescription);
subFlows.add(subFlow);
} else {
throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("There is no sub-flows with sub-flow id: %s", subFlowPartialUpdate.getFlowId()));
}
}
target.setSubFlows(subFlows);
}
target.setType(Type.UPDATE);
handleRequest(key, commandContext, target);
}
use of org.openkilda.model.FlowEndpoint in project open-kilda by telstra.
the class FlowValidator method checkForConnectedDevisesConflict.
private void checkForConnectedDevisesConflict(String flowId, SwitchId switchId) throws InvalidFlowException {
SwitchProperties properties = switchPropertiesRepository.findBySwitchId(switchId).orElseThrow(() -> new InvalidFlowException(format("Couldn't get switch properties for switch %s.", switchId), ErrorType.DATA_INVALID));
if (properties.isSwitchLldp() || properties.isSwitchArp()) {
String errorMessage = format("Connected devices feature is active on the switch %s, " + "flow mirror point cannot be created on this switch.", switchId);
throw new InvalidFlowException(errorMessage, ErrorType.PARAMETERS_INVALID);
}
Optional<Flow> foundFlow = flowRepository.findById(flowId);
if (foundFlow.isPresent()) {
Flow flow = foundFlow.get();
FlowEndpoint source = new FlowSourceAdapter(flow).getEndpoint();
FlowEndpoint destination = new FlowDestAdapter(flow).getEndpoint();
if (switchId.equals(source.getSwitchId())) {
if (source.isTrackLldpConnectedDevices() || source.isTrackArpConnectedDevices()) {
String errorMessage = format("Connected devices feature is active on the flow %s for endpoint %s, " + "flow mirror point cannot be created this flow", flow.getFlowId(), source);
throw new InvalidFlowException(errorMessage, ErrorType.PARAMETERS_INVALID);
}
} else {
if (destination.isTrackLldpConnectedDevices() || destination.isTrackArpConnectedDevices()) {
String errorMessage = format("Connected devices feature is active on the flow %s for endpoint %s, " + "flow mirror point cannot be created this flow", flow.getFlowId(), destination);
throw new InvalidFlowException(errorMessage, ErrorType.PARAMETERS_INVALID);
}
}
}
}
use of org.openkilda.model.FlowEndpoint in project open-kilda by telstra.
the class FlowValidator method checkForEqualsEndpoints.
/**
* Check for equals endpoints.
*
* @param firstFlow a first flow.
* @param secondFlow a second flow.
*/
@VisibleForTesting
void checkForEqualsEndpoints(RequestedFlow firstFlow, RequestedFlow secondFlow) throws InvalidFlowException {
String message = "New requested endpoint for '%s' conflicts with existing endpoint for '%s'";
Set<FlowEndpoint> firstFlowEndpoints = validateFlowEqualsEndpoints(firstFlow, message);
Set<FlowEndpoint> secondFlowEndpoints = validateFlowEqualsEndpoints(secondFlow, message);
for (FlowEndpoint endpoint : secondFlowEndpoints) {
if (firstFlowEndpoints.contains(endpoint)) {
message = String.format(message, secondFlow.getFlowId(), firstFlow.getFlowId());
throw new InvalidFlowException(message, ErrorType.DATA_INVALID);
}
}
}
use of org.openkilda.model.FlowEndpoint in project open-kilda by telstra.
the class FlowValidator method checkFlowForMirrorEndpointConflicts.
private void checkFlowForMirrorEndpointConflicts(String flowId, EndpointDescriptor descriptor) throws InvalidFlowException {
FlowEndpoint endpoint = descriptor.getEndpoint();
Optional<Flow> foundFlow = flowRepository.findById(flowId);
if (foundFlow.isPresent()) {
Flow flow = foundFlow.get();
Optional<FlowMirrorPoints> flowMirrorPointsForward = flowMirrorPointsRepository.findByPathIdAndSwitchId(flow.getForwardPathId(), endpoint.getSwitchId());
Optional<FlowMirrorPoints> flowMirrorPointsReverse = flowMirrorPointsRepository.findByPathIdAndSwitchId(flow.getReversePathId(), endpoint.getSwitchId());
if ((flowMirrorPointsForward.isPresent() || flowMirrorPointsReverse.isPresent()) && (endpoint.isTrackLldpConnectedDevices() || endpoint.isTrackArpConnectedDevices())) {
String errorMessage = format("Flow mirror point is created for the flow %s, " + "lldp or arp can not be set to true.", flowId);
throw new InvalidFlowException(errorMessage, ErrorType.PARAMETERS_INVALID);
}
}
}
Aggregations