Search in sources :

Example 1 with PhysicalPort

use of org.openkilda.model.PhysicalPort in project open-kilda by telstra.

the class ValidateRequestAction method performWithResponse.

@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, FlowMirrorPointCreateContext context, FlowMirrorPointCreateFsm stateMachine) {
    String flowId = stateMachine.getFlowId();
    RequestedFlowMirrorPoint mirrorPoint = context.getMirrorPoint();
    PathId mirrorPathId = new PathId(mirrorPoint.getMirrorPointId());
    stateMachine.setMirrorPathId(mirrorPathId);
    stateMachine.setMirrorSwitchId(mirrorPoint.getMirrorPointSwitchId());
    dashboardLogger.onFlowMirrorPointCreate(flowId, mirrorPoint.getMirrorPointSwitchId(), mirrorPoint.getMirrorPointDirection().toString(), mirrorPoint.getSinkEndpoint().getSwitchId(), mirrorPoint.getSinkEndpoint().getPortNumber(), mirrorPoint.getSinkEndpoint().getOuterVlanId());
    stateMachine.setRequestedFlowMirrorPoint(mirrorPoint);
    Flow flow = transactionManager.doInTransaction(() -> {
        Flow foundFlow = getFlow(flowId);
        if (foundFlow.getStatus() == FlowStatus.IN_PROGRESS) {
            throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Flow %s is in progress now", flowId));
        }
        stateMachine.setFlowStatus(foundFlow.getStatus());
        flowRepository.updateStatus(flowId, FlowStatus.IN_PROGRESS);
        return foundFlow;
    });
    if (!mirrorPoint.getMirrorPointSwitchId().equals(mirrorPoint.getSinkEndpoint().getSwitchId())) {
        throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Invalid sink endpoint switch id: %s. In the current implementation, " + "the sink switch id cannot differ from the mirror point switch id.", mirrorPoint.getSinkEndpoint().getSwitchId()));
    }
    if (!mirrorPoint.getMirrorPointSwitchId().equals(flow.getSrcSwitchId()) && !mirrorPoint.getMirrorPointSwitchId().equals(flow.getDestSwitchId())) {
        throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Invalid mirror point switch id: %s", mirrorPoint.getMirrorPointSwitchId()));
    }
    if (flowMirrorPathRepository.exists(mirrorPathId)) {
        throw new FlowProcessingException(ErrorType.ALREADY_EXISTS, format("Flow mirror point %s already exists", mirrorPathId));
    }
    Optional<PhysicalPort> physicalPort = physicalPortRepository.findBySwitchIdAndPortNumber(mirrorPoint.getSinkEndpoint().getSwitchId(), mirrorPoint.getSinkEndpoint().getPortNumber());
    if (physicalPort.isPresent()) {
        throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Invalid sink port %d on switch %s. This port is part of LAG %d. Please delete LAG port " + "or choose another sink port.", mirrorPoint.getSinkEndpoint().getPortNumber(), mirrorPoint.getSinkEndpoint().getSwitchId(), physicalPort.get().getLagLogicalPort().getLogicalPortNumber()));
    }
    try {
        flowValidator.flowMirrorPointValidate(mirrorPoint);
    } catch (InvalidFlowException e) {
        throw new FlowProcessingException(e.getType(), e.getMessage(), e);
    } catch (UnavailableFlowEndpointException e) {
        throw new FlowProcessingException(ErrorType.DATA_INVALID, e.getMessage(), e);
    }
    stateMachine.saveNewEventToHistory("Flow was validated successfully", FlowEventData.Event.FLOW_MIRROR_POINT_CREATE);
    return Optional.empty();
}
Also used : PathId(org.openkilda.model.PathId) UnavailableFlowEndpointException(org.openkilda.wfm.topology.flowhs.validation.UnavailableFlowEndpointException) RequestedFlowMirrorPoint(org.openkilda.wfm.topology.flowhs.model.RequestedFlowMirrorPoint) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) PhysicalPort(org.openkilda.model.PhysicalPort) InvalidFlowException(org.openkilda.wfm.topology.flowhs.validation.InvalidFlowException) Flow(org.openkilda.model.Flow)

Example 2 with PhysicalPort

use of org.openkilda.model.PhysicalPort 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 3 with PhysicalPort

use of org.openkilda.model.PhysicalPort in project open-kilda by telstra.

the class LagLogicalPortFrame method setPhysicalPorts.

@Override
public void setPhysicalPorts(List<PhysicalPort> physicalPorts) {
    getElement().edges(Direction.OUT, COMPRISES_PHYSICAL_PORT_EDGE).forEachRemaining(edge -> {
        edge.inVertex().remove();
        edge.remove();
    });
    for (PhysicalPort physicalPort : physicalPorts) {
        PhysicalPort.PhysicalPortData data = physicalPort.getData();
        PhysicalPortFrame frame;
        if (data instanceof PhysicalPortFrame) {
            frame = (PhysicalPortFrame) data;
            // Unlink physical port from the previous owner.
            frame.getElement().edges(Direction.IN, COMPRISES_PHYSICAL_PORT_EDGE).forEachRemaining(Edge::remove);
        } else {
            frame = PhysicalPortFrame.create(getGraph(), data);
        }
        linkOut(frame, COMPRISES_PHYSICAL_PORT_EDGE);
    }
    // force to reload
    this.physicalPorts = null;
}
Also used : PhysicalPort(org.openkilda.model.PhysicalPort) Edge(org.apache.tinkerpop.gremlin.structure.Edge)

Example 4 with PhysicalPort

use of org.openkilda.model.PhysicalPort in project open-kilda by telstra.

the class FermaLagLogicalPortTest method createLogicalPortAndSetPhysicalPortsTest.

@Test
public void createLogicalPortAndSetPhysicalPortsTest() {
    LagLogicalPort logicalPort = createLogicalPort(SWITCH_ID_1, LOGICAL_PORT_NUMBER_1);
    assertEquals(0, lagLogicalPortRepository.findAll().iterator().next().getPhysicalPorts().size());
    PhysicalPort physicalPort1 = createPhysicalPort(SWITCH_ID_1, PHYSICAL_PORT_NUMBER_1, logicalPort);
    PhysicalPort physicalPort2 = createPhysicalPort(SWITCH_ID_1, PHYSICAL_PORT_NUMBER_2, logicalPort);
    logicalPort.setPhysicalPorts(Lists.newArrayList(physicalPort1, physicalPort2));
    List<LagLogicalPort> ports = new ArrayList<>(lagLogicalPortRepository.findAll());
    assertEquals(1, ports.size());
    assertEquals(2, ports.get(0).getPhysicalPorts().size());
    assertEquals(PHYSICAL_PORT_NUMBER_1, ports.get(0).getPhysicalPorts().get(0).getPortNumber());
    assertEquals(PHYSICAL_PORT_NUMBER_2, ports.get(0).getPhysicalPorts().get(1).getPortNumber());
    assertEquals(SWITCH_ID_1, ports.get(0).getPhysicalPorts().get(0).getSwitchId());
    assertEquals(SWITCH_ID_1, ports.get(0).getPhysicalPorts().get(1).getSwitchId());
    assertEquals(logicalPort, ports.get(0).getPhysicalPorts().get(0).getLagLogicalPort());
    assertEquals(logicalPort, ports.get(0).getPhysicalPorts().get(1).getLagLogicalPort());
}
Also used : LagLogicalPort(org.openkilda.model.LagLogicalPort) ArrayList(java.util.ArrayList) PhysicalPort(org.openkilda.model.PhysicalPort) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 5 with PhysicalPort

use of org.openkilda.model.PhysicalPort in project open-kilda by telstra.

the class FermaLagLogicalPortTest method createPhysicalPort.

private PhysicalPort createPhysicalPort(SwitchId switchId, int physicalPortNumber, LagLogicalPort logicalPort) {
    PhysicalPort port = new PhysicalPort(switchId, physicalPortNumber, logicalPort);
    physicalPortRepository.add(port);
    return port;
}
Also used : PhysicalPort(org.openkilda.model.PhysicalPort)

Aggregations

PhysicalPort (org.openkilda.model.PhysicalPort)9 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Flow (org.openkilda.model.Flow)2 LagLogicalPort (org.openkilda.model.LagLogicalPort)2 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)2 Edge (org.apache.tinkerpop.gremlin.structure.Edge)1 FlowEndpoint (org.openkilda.model.FlowEndpoint)1 FlowMirrorPath (org.openkilda.model.FlowMirrorPath)1 FlowMirrorPoints (org.openkilda.model.FlowMirrorPoints)1 IslEndpoint (org.openkilda.model.IslEndpoint)1 PathId (org.openkilda.model.PathId)1 Switch (org.openkilda.model.Switch)1 SwitchFeature (org.openkilda.model.SwitchFeature)1 IllegalSwitchPropertiesException (org.openkilda.wfm.error.IllegalSwitchPropertiesException)1 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)1 RequestedFlowMirrorPoint (org.openkilda.wfm.topology.flowhs.model.RequestedFlowMirrorPoint)1 InvalidFlowException (org.openkilda.wfm.topology.flowhs.validation.InvalidFlowException)1 UnavailableFlowEndpointException (org.openkilda.wfm.topology.flowhs.validation.UnavailableFlowEndpointException)1 InvalidDataException (org.openkilda.wfm.topology.switchmanager.error.InvalidDataException)1