Search in sources :

Example 6 with PhysicalPort

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

the class FermaPhysicalPortTest method removePhysicalTest.

@Test
public void removePhysicalTest() {
    PhysicalPort physicalPort1 = createPhysicalPort(SWITCH_ID_1, PHYSICAL_PORT_NUMBER_1, logicalPort1);
    PhysicalPort physicalPort2 = createPhysicalPort(SWITCH_ID_1, PHYSICAL_PORT_NUMBER_2, logicalPort1);
    assertEquals(2, physicalPortRepository.findAll().size());
    transactionManager.doInTransaction(() -> physicalPortRepository.remove(physicalPort1));
    List<PhysicalPort> ports = new ArrayList<>(physicalPortRepository.findAll());
    assertEquals(1, ports.size());
    assertEquals(PHYSICAL_PORT_NUMBER_2, ports.get(0).getPortNumber());
    transactionManager.doInTransaction(() -> physicalPortRepository.remove(physicalPort2));
    assertEquals(0, physicalPortRepository.findAll().size());
}
Also used : ArrayList(java.util.ArrayList) PhysicalPort(org.openkilda.model.PhysicalPort) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 7 with PhysicalPort

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

the class SwitchOperationsService method validateSwitchProperties.

private void validateSwitchProperties(SwitchId switchId, SwitchProperties updatedSwitchProperties) {
    if (!updatedSwitchProperties.isMultiTable()) {
        String propertyErrorMessage = "Illegal switch properties combination for switch %s. '%s' property " + "can be set to 'true' only if 'multiTable' property is 'true'.";
        if (updatedSwitchProperties.isSwitchLldp()) {
            throw new IllegalSwitchPropertiesException(format(propertyErrorMessage, switchId, "switchLldp"));
        }
        if (updatedSwitchProperties.isSwitchArp()) {
            throw new IllegalSwitchPropertiesException(format(propertyErrorMessage, switchId, "switchArp"));
        }
        List<String> flowsWitchEnabledLldp = flowRepository.findByEndpointSwitchWithEnabledLldp(switchId).stream().map(Flow::getFlowId).collect(Collectors.toList());
        if (!flowsWitchEnabledLldp.isEmpty()) {
            throw new IllegalSwitchPropertiesException(format("Illegal switch properties combination for switch %s. " + "Detect Connected Devices feature is turn on for following flows [%s]. " + "For correct work of this feature switch property 'multiTable' must be set to 'true' " + "Please disable detecting of connected devices via LLDP for each flow before set " + "'multiTable' property to 'false'", switchId, String.join(", ", flowsWitchEnabledLldp)));
        }
        List<String> flowsWithEnabledArp = flowRepository.findByEndpointSwitchWithEnabledArp(switchId).stream().map(Flow::getFlowId).collect(Collectors.toList());
        if (!flowsWithEnabledArp.isEmpty()) {
            throw new IllegalSwitchPropertiesException(format("Illegal switch properties combination for switch %s. " + "Detect Connected Devices feature via ARP is turn on for following flows [%s]. " + "For correct work of this feature switch property 'multiTable' must be set to 'true' " + "Please disable detecting of connected devices via ARP for each flow before set " + "'multiTable' property to 'false'", switchId, String.join(", ", flowsWithEnabledArp)));
        }
    }
    if (updatedSwitchProperties.getServer42Port() != null) {
        Optional<PhysicalPort> physicalPort = physicalPortRepository.findBySwitchIdAndPortNumber(switchId, updatedSwitchProperties.getServer42Port());
        if (physicalPort.isPresent()) {
            throw new IllegalSwitchPropertiesException(format("Illegal server42 port '%d' on switch %s. This port is part of LAG '%d'. Please " + "delete LAG port or choose another server42 port.", updatedSwitchProperties.getServer42Port(), switchId, physicalPort.get().getLagLogicalPort().getLogicalPortNumber()));
        }
    }
    if (updatedSwitchProperties.isServer42FlowRtt()) {
        String errorMessage = "Illegal switch properties combination for switch %s. To enable property " + "'server42_flow_rtt' you need to specify valid property '%s'";
        if (updatedSwitchProperties.getServer42Port() == null) {
            throw new IllegalSwitchPropertiesException(format(errorMessage, switchId, "server42_port"));
        }
        if (updatedSwitchProperties.getServer42MacAddress() == null) {
            throw new IllegalSwitchPropertiesException(format(errorMessage, switchId, "server42_mac_address"));
        }
        if (updatedSwitchProperties.getServer42Vlan() == null) {
            throw new IllegalSwitchPropertiesException(format(errorMessage, switchId, "server42_vlan"));
        }
    }
    if (updatedSwitchProperties.getServer42IslRtt() == RttState.ENABLED) {
        String errorMessage = "Illegal switch properties combination for switch %s. To enable property " + "'server42_isl_rtt' you need to specify valid property '%s'";
        if (updatedSwitchProperties.getServer42Port() == null) {
            throw new IllegalSwitchPropertiesException(format(errorMessage, switchId, "server42_port"));
        }
        if (updatedSwitchProperties.getServer42MacAddress() == null) {
            throw new IllegalSwitchPropertiesException(format(errorMessage, switchId, "server42_mac_address"));
        }
        if (updatedSwitchProperties.getServer42Vlan() == null) {
            throw new IllegalSwitchPropertiesException(format(errorMessage, switchId, "server42_vlan"));
        }
    }
    Collection<FlowMirrorPoints> flowMirrorPoints = flowMirrorPointsRepository.findBySwitchId(switchId);
    if (!flowMirrorPoints.isEmpty() && (updatedSwitchProperties.isSwitchLldp() || updatedSwitchProperties.isSwitchArp())) {
        throw new IllegalSwitchPropertiesException(format("Flow mirror point is created on the switch %s, " + "switchLldp or switchArp can not be set to true.", switchId));
    }
    if (updatedSwitchProperties.getServer42Port() != null) {
        String errorMessage = "SwitchId '%s' and port '%d' belong to the %s endpoint. " + "Cannot specify port '%d' as port for server 42.";
        int server42port = updatedSwitchProperties.getServer42Port();
        Collection<Flow> flows = flowRepository.findByEndpoint(switchId, server42port);
        if (!flows.isEmpty()) {
            throw new IllegalSwitchPropertiesException(format(errorMessage, switchId, server42port, "flow", server42port));
        }
        Collection<FlowMirrorPath> flowMirrorPaths = flowMirrorPathRepository.findByEgressSwitchIdAndPort(switchId, server42port);
        if (!flowMirrorPaths.isEmpty()) {
            throw new IllegalSwitchPropertiesException(format(errorMessage, switchId, server42port, "flow mirror path", server42port));
        }
    }
}
Also used : IllegalSwitchPropertiesException(org.openkilda.wfm.error.IllegalSwitchPropertiesException) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) PhysicalPort(org.openkilda.model.PhysicalPort) IslEndpoint(org.openkilda.model.IslEndpoint) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) Flow(org.openkilda.model.Flow)

Example 8 with PhysicalPort

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

the class LagPortOperationService method createTransaction.

private LagLogicalPort createTransaction(SwitchId switchId, Set<Integer> targetPorts) {
    // locate switch first to produce correct error if switch is missing
    Switch sw = querySwitch(switchId);
    if (!isSwitchLagCapable(sw)) {
        throw new InvalidDataException(format("Switch %s doesn't support LAG.", sw.getSwitchId()));
    }
    Set<SwitchFeature> features = sw.getFeatures();
    for (Integer portNumber : targetPorts) {
        validatePhysicalPort(switchId, features, portNumber);
    }
    ensureNoLagCollisions(switchId, targetPorts);
    LagLogicalPort port = queryPoolManager(switchId).allocate();
    port.setPhysicalPorts(targetPorts.stream().map(portNumber -> new PhysicalPort(switchId, portNumber, port)).collect(Collectors.toList()));
    log.info("Adding new LAG logical port entry into DB: {}", port);
    lagLogicalPortRepository.add(port);
    return port;
}
Also used : Switch(org.openkilda.model.Switch) LagLogicalPort(org.openkilda.model.LagLogicalPort) InvalidDataException(org.openkilda.wfm.topology.switchmanager.error.InvalidDataException) PhysicalPort(org.openkilda.model.PhysicalPort) SwitchFeature(org.openkilda.model.SwitchFeature)

Example 9 with PhysicalPort

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

the class FermaPhysicalPortTest 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