Search in sources :

Example 91 with Switch

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

the class SwitchValidateFsm method emitRequests.

public void emitRequests(SwitchValidateState from, SwitchValidateState to, SwitchValidateEvent event, SwitchValidateContext context) {
    try {
        SwitchId switchId = getSwitchId();
        log.info("The switch validate process for {} has been started (key={})", switchId, key);
        // FIXME(surabujin): not reliable check - corresponding error from speaker is much more better
        Optional<Switch> sw = switchRepository.findById(switchId);
        if (!sw.isPresent()) {
            throw new SwitchNotFoundException(switchId);
        }
        requestSwitchOfFlows();
        requestSwitchOfGroups();
        if (sw.get().getFeatures().contains(LAG)) {
            // at this moment Kilda validated only LAG logical ports
            Optional<String> ipAddress = sw.map(Switch::getSocketAddress).map(IpSocketAddress::getAddress);
            if (ipAddress.isPresent()) {
                requestLogicalPorts(ipAddress.get());
            } else {
                log.warn("Unable to get IP address of switch {} to get LAGs", switchId);
            }
        }
        if (request.isProcessMeters()) {
            requestSwitchMeters();
        }
    } catch (Exception ex) {
        log.error("Failure in emitRequests", ex);
        throw ex;
    }
}
Also used : Switch(org.openkilda.model.Switch) SwitchId(org.openkilda.model.SwitchId) SwitchNotFoundException(org.openkilda.wfm.topology.switchmanager.error.SwitchNotFoundException) IpSocketAddress(org.openkilda.model.IpSocketAddress) SwitchManagerException(org.openkilda.wfm.topology.switchmanager.error.SwitchManagerException) SwitchNotFoundException(org.openkilda.wfm.topology.switchmanager.error.SwitchNotFoundException)

Example 92 with Switch

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

the class SwitchMapperTest method testSwitchToSwitchDto.

@Test
public void testSwitchToSwitchDto() {
    Switch sw = getSwitch();
    SwitchDto switchDto = switchMapper.toSwitchDto(sw);
    assertEquals(sw.getSwitchId(), switchDto.getSwitchId());
    assertEquals("127.0.0.1", switchDto.getAddress());
    assertEquals(sw.getSocketAddress().getPort(), switchDto.getPort());
    assertEquals(sw.getHostname(), switchDto.getHostname());
    assertEquals(sw.getDescription(), switchDto.getDescription());
    assertEquals(switchMapper.convertStatus(sw.getStatus()), switchDto.getState());
    assertEquals(sw.isUnderMaintenance(), switchDto.isUnderMaintenance());
    assertEquals(sw.getOfVersion(), switchDto.getOfVersion());
    assertEquals(sw.getOfDescriptionManufacturer(), switchDto.getManufacturer());
    assertEquals(sw.getOfDescriptionHardware(), switchDto.getHardware());
    assertEquals(sw.getOfDescriptionSoftware(), switchDto.getSoftware());
    assertEquals(sw.getOfDescriptionSerialNumber(), switchDto.getSerialNumber());
    assertEquals(sw.getPop(), switchDto.getPop());
    assertEquals((Double) sw.getLatitude(), switchDto.getLocation().getLatitude());
    assertEquals((Double) sw.getLongitude(), switchDto.getLocation().getLongitude());
    assertEquals(sw.getStreet(), switchDto.getLocation().getStreet());
    assertEquals(sw.getCity(), switchDto.getLocation().getCity());
    assertEquals(sw.getCountry(), switchDto.getLocation().getCountry());
}
Also used : Switch(org.openkilda.model.Switch) SwitchDto(org.openkilda.northbound.dto.v1.switches.SwitchDto) Test(org.junit.Test)

Example 93 with Switch

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

the class SwitchMapperTest method testSwitchToSwitchDtoV2.

@Test
public void testSwitchToSwitchDtoV2() {
    Switch sw = getSwitch();
    SwitchDtoV2 switchDto = switchMapper.map(sw);
    assertEquals(sw.getSwitchId(), switchDto.getSwitchId());
    assertEquals("127.0.0.1", switchDto.getAddress());
    assertEquals(sw.getSocketAddress().getPort(), switchDto.getPort());
    assertEquals(sw.getHostname(), switchDto.getHostname());
    assertEquals(sw.getDescription(), switchDto.getDescription());
    assertEquals(switchMapper.convertStatus(sw.getStatus()), switchDto.getState());
    assertEquals(sw.isUnderMaintenance(), switchDto.isUnderMaintenance());
    assertEquals(sw.getOfVersion(), switchDto.getOfVersion());
    assertEquals(sw.getOfDescriptionManufacturer(), switchDto.getManufacturer());
    assertEquals(sw.getOfDescriptionHardware(), switchDto.getHardware());
    assertEquals(sw.getOfDescriptionSoftware(), switchDto.getSoftware());
    assertEquals(sw.getOfDescriptionSerialNumber(), switchDto.getSerialNumber());
    assertEquals(sw.getPop(), switchDto.getPop());
    assertEquals((Double) sw.getLatitude(), switchDto.getLocation().getLatitude());
    assertEquals((Double) sw.getLongitude(), switchDto.getLocation().getLongitude());
    assertEquals(sw.getStreet(), switchDto.getLocation().getStreet());
    assertEquals(sw.getCity(), switchDto.getLocation().getCity());
    assertEquals(sw.getCountry(), switchDto.getLocation().getCountry());
}
Also used : Switch(org.openkilda.model.Switch) SwitchDtoV2(org.openkilda.northbound.dto.v2.switches.SwitchDtoV2) Test(org.junit.Test)

Example 94 with Switch

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

the class PersistenceDataAdapterTest method shouldProvideCorrectSwitchProperties.

@Test
public void shouldProvideCorrectSwitchProperties() {
    Set<SwitchId> switchIds = Sets.newHashSet(SWITCH_ID_1, SWITCH_ID_2);
    Switch sw1 = buildSwitch(SWITCH_ID_1, Collections.emptySet());
    SwitchProperties switchProperties1 = buildSwitchProperties(sw1, false);
    Switch sw2 = buildSwitch(SWITCH_ID_2, Collections.emptySet());
    SwitchProperties switchProperties2 = buildSwitchProperties(sw2, true);
    Map<SwitchId, SwitchProperties> switchProperties = new HashMap<>();
    switchProperties.put(SWITCH_ID_1, switchProperties1);
    switchProperties.put(SWITCH_ID_2, switchProperties2);
    when(switchPropertiesRepository.findBySwitchIds(switchIds)).thenReturn(switchProperties);
    adapter = PersistenceDataAdapter.builder().switchIds(switchIds).persistenceManager(persistenceManager).build();
    assertEquals(switchProperties1, adapter.getSwitchProperties(SWITCH_ID_1));
    assertEquals(switchProperties2, adapter.getSwitchProperties(SWITCH_ID_2));
    verify(switchPropertiesRepository).findBySwitchIds(switchIds);
    verifyNoMoreInteractions(switchPropertiesRepository);
}
Also used : Utils.buildSwitch(org.openkilda.rulemanager.Utils.buildSwitch) Switch(org.openkilda.model.Switch) HashMap(java.util.HashMap) SwitchId(org.openkilda.model.SwitchId) Utils.buildSwitchProperties(org.openkilda.rulemanager.Utils.buildSwitchProperties) SwitchProperties(org.openkilda.model.SwitchProperties) Test(org.junit.Test)

Example 95 with Switch

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

the class RuleManagerImpl method buildRulesForFlowPath.

@Override
public List<SpeakerData> buildRulesForFlowPath(FlowPath flowPath, boolean filterOutUsedSharedRules, DataAdapter adapter) {
    List<SpeakerData> result = new ArrayList<>();
    Flow flow = adapter.getFlow(flowPath.getPathId());
    PathId oppositePathId = flow.getOppositePathId(flowPath.getPathId()).orElse(null);
    FlowTransitEncapsulation encapsulation = adapter.getTransitEncapsulation(flowPath.getPathId(), oppositePathId);
    if (!flow.isProtectedPath(flowPath.getPathId())) {
        Set<FlowSideAdapter> overlappingAdapters = new HashSet<>();
        if (filterOutUsedSharedRules) {
            overlappingAdapters = getOverlappingMultiTableIngressAdapters(flowPath, adapter);
        }
        buildIngressCommands(adapter.getSwitch(flowPath.getSrcSwitchId()), flowPath, flow, encapsulation, overlappingAdapters, adapter.getSwitchProperties(flowPath.getSrcSwitchId()), adapter.getFeatureToggles());
    }
    if (flowPath.isOneSwitchFlow()) {
        return result;
    }
    result.addAll(buildEgressCommands(adapter.getSwitch(flowPath.getDestSwitchId()), flowPath, flow, encapsulation));
    for (int i = 1; i < flowPath.getSegments().size(); i++) {
        PathSegment firstSegment = flowPath.getSegments().get(i - 1);
        PathSegment secondSegment = flowPath.getSegments().get(i);
        result.addAll(buildTransitCommands(adapter.getSwitch(firstSegment.getDestSwitchId()), flowPath, encapsulation, firstSegment, secondSegment));
    }
    if (flow.isLooped()) {
        Switch loopedSwitch = adapter.getSwitch(flow.getLoopSwitchId());
        result.addAll(buildTransitLoopCommands(loopedSwitch, flowPath, flow, encapsulation));
    }
    return postProcessCommands(result);
}
Also used : PathId(org.openkilda.model.PathId) Switch(org.openkilda.model.Switch) ArrayList(java.util.ArrayList) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) FlowSideAdapter(org.openkilda.adapter.FlowSideAdapter) PathSegment(org.openkilda.model.PathSegment) FlowEndpoint(org.openkilda.model.FlowEndpoint) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) HashSet(java.util.HashSet)

Aggregations

Switch (org.openkilda.model.Switch)230 Test (org.junit.Test)126 Flow (org.openkilda.model.Flow)68 SwitchId (org.openkilda.model.SwitchId)67 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)46 FlowPath (org.openkilda.model.FlowPath)34 PathId (org.openkilda.model.PathId)32 Utils.buildSwitch (org.openkilda.rulemanager.Utils.buildSwitch)32 PathComputer (org.openkilda.pce.PathComputer)28 GetPathsResult (org.openkilda.pce.GetPathsResult)23 List (java.util.List)22 SwitchProperties (org.openkilda.model.SwitchProperties)21 FlowSpeakerData (org.openkilda.rulemanager.FlowSpeakerData)20 SpeakerData (org.openkilda.rulemanager.SpeakerData)19 String.format (java.lang.String.format)17 Set (java.util.Set)17 Isl (org.openkilda.model.Isl)15 HashSet (java.util.HashSet)14 ArrayList (java.util.ArrayList)13 Collections (java.util.Collections)13