use of org.openkilda.adapter.FlowDestAdapter 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);
}
}
}
use of org.openkilda.adapter.FlowDestAdapter in project open-kilda by telstra.
the class RequestedFlowMapper method toFlowRequest.
/**
* Convert {@link Flow} to {@link FlowRequest}.
*/
public FlowRequest toFlowRequest(@NonNull Flow flow) {
FlowRequest request = generatedMap(flow);
request.setSource(new FlowSourceAdapter(flow).getEndpoint());
request.setDestination(new FlowDestAdapter(flow).getEndpoint());
if (flow.getPathComputationStrategy() != null) {
request.setPathComputationStrategy(flow.getPathComputationStrategy().toString().toLowerCase());
}
return request;
}
use of org.openkilda.adapter.FlowDestAdapter 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.adapter.FlowDestAdapter in project open-kilda by telstra.
the class RequestedFlowMapper method toFlowRequest.
/**
* Convert {@link Flow} to {@link FlowRequest}.
*/
public FlowRequest toFlowRequest(Flow flow) {
FlowRequest request = generatedMap(flow);
request.setSource(new FlowSourceAdapter(flow).getEndpoint());
request.setDestination(new FlowDestAdapter(flow).getEndpoint());
return request;
}
use of org.openkilda.adapter.FlowDestAdapter in project open-kilda by telstra.
the class PingProducer method buildPing.
private Ping buildPing(PingContext pingContext, FlowDirection direction) {
Flow flow = pingContext.getFlow();
FlowEndpoint ingress;
FlowEndpoint egress;
int islPort;
if (FlowDirection.FORWARD == direction) {
ingress = new FlowSourceAdapter(flow).getEndpoint();
egress = new FlowDestAdapter(flow).getEndpoint();
islPort = getIslPort(flow, flow.getForwardPath());
} else if (FlowDirection.REVERSE == direction) {
ingress = new FlowDestAdapter(flow).getEndpoint();
egress = new FlowSourceAdapter(flow).getEndpoint();
islPort = getIslPort(flow, flow.getReversePath());
} else {
throw new IllegalArgumentException(String.format("Unexpected %s value: %s", FlowDirection.class.getCanonicalName(), direction));
}
return new Ping(new NetworkEndpoint(ingress.getSwitchId(), ingress.getPortNumber()), new NetworkEndpoint(egress.getSwitchId(), egress.getPortNumber()), pingContext.getTransitEncapsulation(), islPort);
}
Aggregations