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