Search in sources :

Example 11 with FlowEndpoint

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();
}
Also used : FlowEndpoint(org.openkilda.model.FlowEndpoint) SubFlowSharedEndpointEncapsulation(org.openkilda.messaging.command.yflow.SubFlowSharedEndpointEncapsulation) YSubFlow(org.openkilda.model.YSubFlow) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow)

Example 12 with FlowEndpoint

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);
        }
    }
}
Also used : FlowEndpoint(org.openkilda.model.FlowEndpoint) PhysicalPort(org.openkilda.model.PhysicalPort)

Example 13 with FlowEndpoint

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);
    }
}
Also used : FlowEndpoint(org.openkilda.model.FlowEndpoint) FlowMirrorPath(org.openkilda.model.FlowMirrorPath)

Example 14 with FlowEndpoint

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);
    }
}
Also used : FlowEndpoint(org.openkilda.model.FlowEndpoint) SwitchId(org.openkilda.model.SwitchId) SwitchProperties(org.openkilda.model.SwitchProperties)

Example 15 with FlowEndpoint

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);
        }
    }
}
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)

Aggregations

FlowEndpoint (org.openkilda.model.FlowEndpoint)105 Test (org.junit.Test)26 Flow (org.openkilda.model.Flow)22 ArrayList (java.util.ArrayList)15 RoutingMetadata (org.openkilda.floodlight.utils.metadata.RoutingMetadata)12 YFlow (org.openkilda.model.YFlow)11 FlowPath (org.openkilda.model.FlowPath)10 FlowSpeakerData (org.openkilda.rulemanager.FlowSpeakerData)9 SpeakerData (org.openkilda.rulemanager.SpeakerData)9 SwitchId (org.openkilda.model.SwitchId)8 YSubFlow (org.openkilda.model.YSubFlow)8 HashSet (java.util.HashSet)7 FlowSideAdapter (org.openkilda.adapter.FlowSideAdapter)7 FlowSourceAdapter (org.openkilda.adapter.FlowSourceAdapter)7 IngressFlowSegmentInstallCommand (org.openkilda.floodlight.command.flow.ingress.IngressFlowSegmentInstallCommand)7 EffectiveIds (org.openkilda.floodlight.model.EffectiveIds)7 FlowSegmentWrapperCommand (org.openkilda.floodlight.command.flow.FlowSegmentWrapperCommand)6 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)6 OFFlowAdd (org.projectfloodlight.openflow.protocol.OFFlowAdd)6 MessageContext (org.openkilda.messaging.MessageContext)5