Search in sources :

Example 41 with SwitchProperties

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

the class SwitchRuleServiceImpl method installRules.

@Override
public void installRules(String key, SwitchRulesInstallRequest data) {
    isOperationCompleted = false;
    SwitchId switchId = data.getSwitchId();
    if (!switchRepository.exists(switchId)) {
        ErrorData errorData = new ErrorData(ErrorType.NOT_FOUND, format("Switch %s not found", switchId), "Error when installing switch rules");
        ErrorMessage errorMessage = new ErrorMessage(errorData, System.currentTimeMillis(), key);
        carrier.response(key, errorMessage);
        return;
    }
    Optional<SwitchProperties> switchProperties = switchPropertiesRepository.findBySwitchId(switchId);
    KildaFeatureToggles featureToggles = featureTogglesRepository.getOrDefault();
    boolean server42FlowRttFeatureToggle = featureToggles.getServer42FlowRtt();
    data.setServer42FlowRttFeatureToggle(server42FlowRttFeatureToggle);
    data.setServer42IslRttEnabled(featureToggles.getServer42IslRtt() && switchProperties.map(SwitchProperties::hasServer42IslRttEnabled).orElse(false));
    if (switchProperties.isPresent()) {
        data.setMultiTable(switchProperties.get().isMultiTable());
        data.setSwitchLldp(switchProperties.get().isSwitchLldp());
        data.setSwitchArp(switchProperties.get().isSwitchArp());
        data.setServer42FlowRttSwitchProperty(switchProperties.get().isServer42FlowRtt());
        data.setServer42Port(switchProperties.get().getServer42Port());
        data.setServer42Vlan(switchProperties.get().getServer42Vlan());
        data.setServer42MacAddress(switchProperties.get().getServer42MacAddress());
        Collection<FlowPath> flowPaths = flowPathRepository.findBySrcSwitch(switchId);
        List<Integer> flowPorts = new ArrayList<>();
        Set<Integer> flowLldpPorts = new HashSet<>();
        Set<Integer> flowArpPorts = new HashSet<>();
        Set<Integer> server42FlowPorts = new HashSet<>();
        fillFlowPorts(switchProperties.get(), flowPaths, flowPorts, flowLldpPorts, flowArpPorts, server42FlowPorts, server42FlowRttFeatureToggle && switchProperties.get().isServer42FlowRtt());
        data.setFlowPorts(flowPorts);
        data.setFlowLldpPorts(flowLldpPorts);
        data.setFlowArpPorts(flowArpPorts);
        data.setServer42FlowRttPorts(server42FlowPorts);
        List<Integer> islPorts = islRepository.findBySrcSwitch(switchId).stream().map(isl -> isl.getSrcPort()).collect(Collectors.toList());
        data.setIslPorts(islPorts);
    }
    carrier.sendCommandToSpeaker(key, data);
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowPath(org.openkilda.model.FlowPath) KildaFeatureTogglesRepository(org.openkilda.persistence.repositories.KildaFeatureTogglesRepository) SwitchRulesDeleteRequest(org.openkilda.messaging.command.switches.SwitchRulesDeleteRequest) SwitchRulesInstallRequest(org.openkilda.messaging.command.switches.SwitchRulesInstallRequest) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SwitchRuleService(org.openkilda.wfm.topology.switchmanager.service.SwitchRuleService) KildaFeatureToggles(org.openkilda.model.KildaFeatureToggles) SwitchManagerCarrier(org.openkilda.wfm.topology.switchmanager.service.SwitchManagerCarrier) IslRepository(org.openkilda.persistence.repositories.IslRepository) SwitchProperties(org.openkilda.model.SwitchProperties) ErrorType(org.openkilda.messaging.error.ErrorType) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) SwitchPropertiesRepository(org.openkilda.persistence.repositories.SwitchPropertiesRepository) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) SwitchRulesResponse(org.openkilda.messaging.info.switches.SwitchRulesResponse) Optional(java.util.Optional) ErrorData(org.openkilda.messaging.error.ErrorData) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) ArrayList(java.util.ArrayList) SwitchId(org.openkilda.model.SwitchId) KildaFeatureToggles(org.openkilda.model.KildaFeatureToggles) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) FlowPath(org.openkilda.model.FlowPath) ErrorData(org.openkilda.messaging.error.ErrorData) SwitchProperties(org.openkilda.model.SwitchProperties) HashSet(java.util.HashSet)

Example 42 with SwitchProperties

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

the class SwitchRuleServiceImpl method deleteRules.

@Override
public void deleteRules(String key, SwitchRulesDeleteRequest data) {
    isOperationCompleted = false;
    SwitchId switchId = data.getSwitchId();
    if (!switchRepository.exists(switchId)) {
        ErrorData errorData = new ErrorData(ErrorType.NOT_FOUND, format("Switch %s not found", switchId), "Error when deleting switch rules");
        ErrorMessage errorMessage = new ErrorMessage(errorData, System.currentTimeMillis(), key);
        carrier.response(key, errorMessage);
        return;
    }
    Optional<SwitchProperties> switchProperties = switchPropertiesRepository.findBySwitchId(switchId);
    KildaFeatureToggles featureToggles = featureTogglesRepository.getOrDefault();
    boolean server42FlowRttFeatureToggle = featureToggles.getServer42FlowRtt();
    data.setServer42FlowRttFeatureToggle(server42FlowRttFeatureToggle);
    data.setServer42IslRttEnabled(featureToggles.getServer42IslRtt() && switchProperties.map(SwitchProperties::hasServer42IslRttEnabled).orElse(false));
    if (switchProperties.isPresent()) {
        data.setMultiTable(switchProperties.get().isMultiTable());
        data.setSwitchLldp(switchProperties.get().isSwitchLldp());
        data.setSwitchArp(switchProperties.get().isSwitchArp());
        data.setServer42FlowRttSwitchProperty(switchProperties.get().isServer42FlowRtt());
        data.setServer42Port(switchProperties.get().getServer42Port());
        data.setServer42Vlan(switchProperties.get().getServer42Vlan());
        data.setServer42MacAddress(switchProperties.get().getServer42MacAddress());
        Collection<FlowPath> flowPaths = flowPathRepository.findBySrcSwitch(switchId);
        List<Integer> flowPorts = new ArrayList<>();
        Set<Integer> flowLldpPorts = new HashSet<>();
        Set<Integer> flowArpPorts = new HashSet<>();
        Set<Integer> server42FlowPorts = new HashSet<>();
        fillFlowPorts(switchProperties.get(), flowPaths, flowPorts, flowLldpPorts, flowArpPorts, server42FlowPorts, server42FlowRttFeatureToggle && switchProperties.get().isServer42FlowRtt());
        data.setFlowPorts(flowPorts);
        data.setFlowLldpPorts(flowLldpPorts);
        data.setFlowArpPorts(flowArpPorts);
        data.setServer42FlowRttPorts(server42FlowPorts);
        List<Integer> islPorts = islRepository.findBySrcSwitch(switchId).stream().map(isl -> isl.getSrcPort()).collect(Collectors.toList());
        data.setIslPorts(islPorts);
    }
    carrier.sendCommandToSpeaker(key, data);
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowPath(org.openkilda.model.FlowPath) KildaFeatureTogglesRepository(org.openkilda.persistence.repositories.KildaFeatureTogglesRepository) SwitchRulesDeleteRequest(org.openkilda.messaging.command.switches.SwitchRulesDeleteRequest) SwitchRulesInstallRequest(org.openkilda.messaging.command.switches.SwitchRulesInstallRequest) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SwitchRuleService(org.openkilda.wfm.topology.switchmanager.service.SwitchRuleService) KildaFeatureToggles(org.openkilda.model.KildaFeatureToggles) SwitchManagerCarrier(org.openkilda.wfm.topology.switchmanager.service.SwitchManagerCarrier) IslRepository(org.openkilda.persistence.repositories.IslRepository) SwitchProperties(org.openkilda.model.SwitchProperties) ErrorType(org.openkilda.messaging.error.ErrorType) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) SwitchPropertiesRepository(org.openkilda.persistence.repositories.SwitchPropertiesRepository) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) SwitchRulesResponse(org.openkilda.messaging.info.switches.SwitchRulesResponse) Optional(java.util.Optional) ErrorData(org.openkilda.messaging.error.ErrorData) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) ArrayList(java.util.ArrayList) SwitchId(org.openkilda.model.SwitchId) KildaFeatureToggles(org.openkilda.model.KildaFeatureToggles) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) FlowPath(org.openkilda.model.FlowPath) ErrorData(org.openkilda.messaging.error.ErrorData) SwitchProperties(org.openkilda.model.SwitchProperties) HashSet(java.util.HashSet)

Example 43 with SwitchProperties

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

the class ResourceAllocationAction method allocate.

@Override
protected void allocate(FlowMirrorPointCreateFsm stateMachine) throws RecoverableException, UnroutableFlowException, ResourceAllocationException {
    RequestedFlowMirrorPoint mirrorPoint = stateMachine.getRequestedFlowMirrorPoint();
    transactionManager.doInTransaction(() -> {
        Flow flow = getFlow(mirrorPoint.getFlowId());
        FlowPath flowPath = getFlowPath(mirrorPoint, flow);
        stateMachine.setFlowPathId(flowPath.getPathId());
        Optional<FlowMirrorPoints> foundFlowMirrorPoints = flowMirrorPointsRepository.findByPathIdAndSwitchId(flowPath.getPathId(), mirrorPoint.getMirrorPointSwitchId());
        FlowMirrorPoints flowMirrorPoints;
        if (foundFlowMirrorPoints.isPresent()) {
            flowMirrorPoints = foundFlowMirrorPoints.get();
        } else {
            flowMirrorPoints = createFlowMirrorPoints(mirrorPoint, flowPath);
            stateMachine.setAddNewGroup(true);
        }
        Switch sinkSwitch = switchRepository.findById(mirrorPoint.getSinkEndpoint().getSwitchId()).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Switch %s not found", mirrorPoint.getSinkEndpoint().getSwitchId())));
        stateMachine.setUnmaskedCookie(resourcesManager.getAllocatedCookie(flow.getFlowId()));
        FlowSegmentCookie cookie = FlowSegmentCookie.builder().flowEffectiveId(stateMachine.getUnmaskedCookie()).mirror(true).build();
        SwitchProperties switchProperties = getSwitchProperties(sinkSwitch.getSwitchId());
        boolean dstWithMultiTable = switchProperties != null ? switchProperties.isMultiTable() : kildaConfigurationRepository.getOrDefault().getUseMultiTable();
        FlowMirrorPath flowMirrorPath = FlowMirrorPath.builder().pathId(stateMachine.getMirrorPathId()).mirrorSwitch(flowMirrorPoints.getMirrorSwitch()).egressSwitch(sinkSwitch).egressPort(mirrorPoint.getSinkEndpoint().getPortNumber()).egressOuterVlan(mirrorPoint.getSinkEndpoint().getOuterVlanId()).egressInnerVlan(mirrorPoint.getSinkEndpoint().getInnerVlanId()).cookie(cookie).bandwidth(flow.getBandwidth()).ignoreBandwidth(flow.isIgnoreBandwidth()).status(FlowPathStatus.IN_PROGRESS).egressWithMultiTable(dstWithMultiTable).build();
        flowMirrorPathRepository.add(flowMirrorPath);
        flowMirrorPoints.addPaths(flowMirrorPath);
    // TODO: add path allocation in case when src switch is not equal to dst switch
    });
    stateMachine.saveActionToHistory("New mirror path was created", format("The flow mirror path %s was created (with allocated resources)", stateMachine.getMirrorPathId()));
}
Also used : FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) RequestedFlowMirrorPoint(org.openkilda.wfm.topology.flowhs.model.RequestedFlowMirrorPoint) Switch(org.openkilda.model.Switch) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) FlowPath(org.openkilda.model.FlowPath) SwitchProperties(org.openkilda.model.SwitchProperties) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) Flow(org.openkilda.model.Flow)

Example 44 with SwitchProperties

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

the class FermaSwitchPropertiesRepositoryTest method shouldCreateSwitchPropertiesWithRelation.

@Test
public void shouldCreateSwitchPropertiesWithRelation() {
    Switch origSwitch = Switch.builder().switchId(TEST_SWITCH_ID).description("Some description").build();
    switchRepository.add(origSwitch);
    SwitchProperties switchProperties = SwitchProperties.builder().switchObj(origSwitch).supportedTransitEncapsulation(SwitchProperties.DEFAULT_FLOW_ENCAPSULATION_TYPES).build();
    switchPropertiesRepository.add(switchProperties);
    List<SwitchProperties> switchPropertiesResult = new ArrayList<>(switchPropertiesRepository.findAll());
    assertEquals(1, switchPropertiesResult.size());
    assertNotNull(switchPropertiesResult.get(0).getSwitchObj());
}
Also used : Switch(org.openkilda.model.Switch) ArrayList(java.util.ArrayList) SwitchProperties(org.openkilda.model.SwitchProperties) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 45 with SwitchProperties

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

the class FermaSwitchPropertiesRepositoryTest method shouldCreatePropertiesWithServer42Props.

@Test
public void shouldCreatePropertiesWithServer42Props() {
    Switch origSwitch = Switch.builder().switchId(TEST_SWITCH_ID).description("Some description").build();
    switchRepository.add(origSwitch);
    SwitchProperties switchProperties = SwitchProperties.builder().switchObj(origSwitch).server42FlowRtt(true).server42Port(SERVER_42_PORT).server42Vlan(SERVER_42_VLAN).server42MacAddress(SERVER_42_MAC_ADDRESS).supportedTransitEncapsulation(SwitchProperties.DEFAULT_FLOW_ENCAPSULATION_TYPES).build();
    switchPropertiesRepository.add(switchProperties);
    Optional<SwitchProperties> switchPropertiesOptional = switchPropertiesRepository.findBySwitchId(TEST_SWITCH_ID);
    assertTrue(switchPropertiesOptional.isPresent());
    assertTrue(switchPropertiesOptional.get().isServer42FlowRtt());
    assertEquals(SERVER_42_PORT, switchPropertiesOptional.get().getServer42Port());
    assertEquals(SERVER_42_VLAN, switchPropertiesOptional.get().getServer42Vlan());
    assertEquals(SERVER_42_MAC_ADDRESS, switchPropertiesOptional.get().getServer42MacAddress());
}
Also used : Switch(org.openkilda.model.Switch) SwitchProperties(org.openkilda.model.SwitchProperties) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Aggregations

SwitchProperties (org.openkilda.model.SwitchProperties)45 Switch (org.openkilda.model.Switch)19 SwitchId (org.openkilda.model.SwitchId)19 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 List (java.util.List)8 Set (java.util.Set)7 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)7 KildaFeatureToggles (org.openkilda.model.KildaFeatureToggles)6 Utils.buildSwitch (org.openkilda.rulemanager.Utils.buildSwitch)6 Utils.buildSwitchProperties (org.openkilda.rulemanager.Utils.buildSwitchProperties)6 Sets (com.google.common.collect.Sets)5 Map (java.util.Map)5 Before (org.junit.Before)5 Collections (java.util.Collections)4 Assert.assertEquals (org.junit.Assert.assertEquals)4 Assert.assertTrue (org.junit.Assert.assertTrue)4 Mockito.mock (org.mockito.Mockito.mock)4