use of org.openkilda.model.FlowEndpoint in project open-kilda by telstra.
the class YFlowMapper method toSubFlowDto.
/**
* Map {@link YSubFlow} to {@link SubFlowDto}.
*/
public SubFlowDto toSubFlowDto(YSubFlow subFlow) {
SubFlowSharedEndpointEncapsulation sharedEndpoint = SubFlowSharedEndpointEncapsulation.builder().vlanId(subFlow.getSharedEndpointVlan()).innerVlanId(subFlow.getSharedEndpointInnerVlan()).build();
FlowEndpoint endpoint = FlowEndpoint.builder().switchId(subFlow.getEndpointSwitchId()).portNumber(subFlow.getEndpointPort()).outerVlanId(subFlow.getEndpointVlan()).innerVlanId(subFlow.getEndpointInnerVlan()).build();
Optional<Flow> flow = Optional.ofNullable(subFlow.getFlow());
return SubFlowDto.builder().flowId(subFlow.getSubFlowId()).endpoint(endpoint).sharedEndpoint(sharedEndpoint).status(flow.map(Flow::getStatus).orElse(null)).description(flow.map(Flow::getDescription).orElse(null)).timeCreate(flow.map(Flow::getTimeCreate).orElse(null)).timeUpdate(flow.map(Flow::getTimeModify).orElse(null)).build();
}
use of org.openkilda.model.FlowEndpoint in project open-kilda by telstra.
the class FlowValidator method checkFlowForLagPortConflict.
private void checkFlowForLagPortConflict(RequestedFlow requestedFlow) throws InvalidFlowException {
FlowEndpoint source = RequestedFlowMapper.INSTANCE.mapSource(requestedFlow);
FlowEndpoint destination = RequestedFlowMapper.INSTANCE.mapDest(requestedFlow);
for (FlowEndpoint endpoint : new FlowEndpoint[] { source, destination }) {
Optional<PhysicalPort> physicalPort = physicalPortRepository.findBySwitchIdAndPortNumber(endpoint.getSwitchId(), endpoint.getPortNumber());
if (physicalPort.isPresent()) {
String message = format("Port %d on switch %s is used as part of LAG port %d", endpoint.getPortNumber(), endpoint.getSwitchId(), physicalPort.get().getLagLogicalPort().getLogicalPortNumber());
throw new InvalidFlowException(message, ErrorType.PARAMETERS_INVALID);
}
}
}
use of org.openkilda.model.FlowEndpoint in project open-kilda by telstra.
the class FlowValidator method checkFlowForSinkEndpointConflicts.
private void checkFlowForSinkEndpointConflicts(EndpointDescriptor descriptor) throws InvalidFlowException {
FlowEndpoint endpoint = descriptor.getEndpoint();
Optional<FlowMirrorPath> foundFlowMirrorPath = flowMirrorPathRepository.findByEgressEndpoint(endpoint.getSwitchId(), endpoint.getPortNumber(), endpoint.getOuterVlanId(), endpoint.getInnerVlanId());
if (foundFlowMirrorPath.isPresent()) {
FlowMirrorPath flowMirrorPath = foundFlowMirrorPath.get();
String errorMessage = format("Requested endpoint '%s' conflicts " + "with existing flow mirror point '%s'.", descriptor.getEndpoint(), flowMirrorPath.getPathId());
throw new InvalidFlowException(errorMessage, ErrorType.ALREADY_EXISTS);
}
}
use of org.openkilda.model.FlowEndpoint 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);
}
}
use of org.openkilda.model.FlowEndpoint in project open-kilda by telstra.
the class FlowValidator method checkFlowForFlowConflicts.
/**
* Checks a flow for endpoints' conflicts.
*
* @throws InvalidFlowException is thrown in a case when flow endpoints conflict with existing flows.
*/
private void checkFlowForFlowConflicts(String flowId, EndpointDescriptor descriptor, Set<String> bulkUpdateFlowIds) throws InvalidFlowException {
final FlowEndpoint endpoint = descriptor.getEndpoint();
for (Flow entry : flowRepository.findByEndpoint(endpoint.getSwitchId(), endpoint.getPortNumber())) {
if (flowId != null && (flowId.equals(entry.getFlowId()) || bulkUpdateFlowIds.contains(entry.getFlowId()))) {
continue;
}
FlowEndpoint source = new FlowSourceAdapter(entry).getEndpoint();
FlowEndpoint destination = new FlowDestAdapter(entry).getEndpoint();
EndpointDescriptor conflict = null;
if (endpoint.isSwitchPortVlanEquals(source)) {
conflict = EndpointDescriptor.makeSource(source);
} else if (endpoint.isSwitchPortVlanEquals(destination)) {
conflict = EndpointDescriptor.makeDestination(destination);
}
if (conflict != null) {
String errorMessage = format("Requested flow '%s' conflicts with existing flow '%s'. " + "Details: requested flow '%s' %s: %s, " + "existing flow '%s' %s: %s", flowId, entry.getFlowId(), flowId, descriptor.getName(), endpoint, entry.getFlowId(), conflict.getName(), conflict.getEndpoint());
throw new InvalidFlowException(errorMessage, ErrorType.ALREADY_EXISTS);
}
}
}
Aggregations