Search in sources :

Example 1 with FlowDestAdapter

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);
        }
    }
}
Also used : FlowSourceAdapter(org.openkilda.adapter.FlowSourceAdapter) FlowEndpoint(org.openkilda.model.FlowEndpoint) FlowDestAdapter(org.openkilda.adapter.FlowDestAdapter) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow)

Example 2 with FlowDestAdapter

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;
}
Also used : FlowSourceAdapter(org.openkilda.adapter.FlowSourceAdapter) FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) FlowDestAdapter(org.openkilda.adapter.FlowDestAdapter)

Example 3 with FlowDestAdapter

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);
            }
        }
    }
}
Also used : FlowSourceAdapter(org.openkilda.adapter.FlowSourceAdapter) FlowEndpoint(org.openkilda.model.FlowEndpoint) FlowDestAdapter(org.openkilda.adapter.FlowDestAdapter) SwitchProperties(org.openkilda.model.SwitchProperties) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow)

Example 4 with FlowDestAdapter

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;
}
Also used : FlowSourceAdapter(org.openkilda.adapter.FlowSourceAdapter) FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) FlowDestAdapter(org.openkilda.adapter.FlowDestAdapter)

Example 5 with FlowDestAdapter

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);
}
Also used : FlowSourceAdapter(org.openkilda.adapter.FlowSourceAdapter) FlowEndpoint(org.openkilda.model.FlowEndpoint) NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) FlowDirection(org.openkilda.messaging.model.FlowDirection) FlowDestAdapter(org.openkilda.adapter.FlowDestAdapter) Ping(org.openkilda.messaging.model.Ping) FlowEndpoint(org.openkilda.model.FlowEndpoint) NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) Flow(org.openkilda.model.Flow)

Aggregations

FlowDestAdapter (org.openkilda.adapter.FlowDestAdapter)5 FlowSourceAdapter (org.openkilda.adapter.FlowSourceAdapter)5 Flow (org.openkilda.model.Flow)3 FlowEndpoint (org.openkilda.model.FlowEndpoint)3 FlowRequest (org.openkilda.messaging.command.flow.FlowRequest)2 YFlow (org.openkilda.model.YFlow)2 YSubFlow (org.openkilda.model.YSubFlow)2 RequestedFlow (org.openkilda.wfm.topology.flowhs.model.RequestedFlow)2 FlowDirection (org.openkilda.messaging.model.FlowDirection)1 NetworkEndpoint (org.openkilda.messaging.model.NetworkEndpoint)1 Ping (org.openkilda.messaging.model.Ping)1 SwitchProperties (org.openkilda.model.SwitchProperties)1