Search in sources :

Example 36 with SwitchProperties

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

the class FlowPathBuilder method buildFlowPath.

/**
 * Build a flow path entity for the flow using provided resources and segments.
 *
 * @param flow a flow the flow path will be associated with.
 * @param pathResources resources to be used for the flow path.
 * @param pathLatency path to be used for the flow path.
 * @param segments segments to be used for the flow path.
 * @param cookie cookie to be used for the flow path.
 * @param forceToIgnoreBandwidth force path to ignore bandwidth.
 * @param sharedBandwidthGroupId a shared bandwidth group to be set for the path
 */
public FlowPath buildFlowPath(Flow flow, PathResources pathResources, long pathLatency, SwitchId srcSwitchId, SwitchId destSwitchId, List<PathSegment> segments, FlowSegmentCookie cookie, boolean forceToIgnoreBandwidth, String sharedBandwidthGroupId) {
    Map<SwitchId, Switch> switches = new HashMap<>();
    switches.put(flow.getSrcSwitchId(), flow.getSrcSwitch());
    switches.put(flow.getDestSwitchId(), flow.getDestSwitch());
    Switch srcSwitch = switches.get(srcSwitchId);
    if (srcSwitch == null) {
        throw new IllegalArgumentException(format("Path %s has different end-point %s than flow %s", pathResources.getPathId(), srcSwitchId, flow.getFlowId()));
    }
    Switch destSwitch = switches.get(destSwitchId);
    if (destSwitch == null) {
        throw new IllegalArgumentException(format("Path %s has different end-point %s than flow %s", pathResources.getPathId(), destSwitchId, flow.getFlowId()));
    }
    Map<SwitchId, SwitchProperties> switchProperties = getSwitchProperties(pathResources.getPathId());
    boolean srcWithMultiTable = switchProperties.get(srcSwitch.getSwitchId()) != null ? switchProperties.get(srcSwitch.getSwitchId()).isMultiTable() : kildaConfigurationRepository.getOrDefault().getUseMultiTable();
    boolean dstWithMultiTable = switchProperties.get(destSwitch.getSwitchId()) != null ? switchProperties.get(destSwitch.getSwitchId()).isMultiTable() : kildaConfigurationRepository.getOrDefault().getUseMultiTable();
    return FlowPath.builder().pathId(pathResources.getPathId()).srcSwitch(srcSwitch).destSwitch(destSwitch).meterId(pathResources.getMeterId()).cookie(cookie).bandwidth(flow.getBandwidth()).ignoreBandwidth(flow.isIgnoreBandwidth() || forceToIgnoreBandwidth).latency(pathLatency).segments(segments).srcWithMultiTable(srcWithMultiTable).destWithMultiTable(dstWithMultiTable).sharedBandwidthGroupId(sharedBandwidthGroupId).build();
}
Also used : Switch(org.openkilda.model.Switch) HashMap(java.util.HashMap) SwitchId(org.openkilda.model.SwitchId) SwitchProperties(org.openkilda.model.SwitchProperties)

Example 37 with SwitchProperties

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

the class FlowValidatorTest method checkForEncapsulationTypeRequirementNullTypesTest.

@Test(expected = InvalidFlowException.class)
public void checkForEncapsulationTypeRequirementNullTypesTest() throws InvalidFlowException {
    SwitchProperties properties = SwitchProperties.builder().supportedTransitEncapsulation(null).build();
    flowValidator.checkForEncapsulationTypeRequirement(SRC_ENDPOINT, properties, TRANSIT_VLAN);
}
Also used : SwitchProperties(org.openkilda.model.SwitchProperties) Test(org.junit.Test)

Example 38 with SwitchProperties

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

the class FlowValidatorTest method checkForEncapsulationTypeRequirementEmptyTypesTest.

@Test(expected = InvalidFlowException.class)
public void checkForEncapsulationTypeRequirementEmptyTypesTest() throws InvalidFlowException {
    SwitchProperties properties = SwitchProperties.builder().supportedTransitEncapsulation(new HashSet<>()).build();
    flowValidator.checkForEncapsulationTypeRequirement(SRC_ENDPOINT, properties, TRANSIT_VLAN);
}
Also used : SwitchProperties(org.openkilda.model.SwitchProperties) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 39 with SwitchProperties

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

the class CommandBuilderImpl method buildCommandsToReinstallRules.

@Override
public List<ReinstallDefaultFlowForSwitchManagerRequest> buildCommandsToReinstallRules(SwitchId switchId, List<Long> reinstallRulesCookies) {
    SwitchProperties properties = getSwitchProperties(switchId);
    List<ReinstallDefaultFlowForSwitchManagerRequest> commands = new ArrayList<>();
    for (Long cookie : reinstallRulesCookies) {
        if (isDefaultRuleWithSpecialRequirements(cookie)) {
            commands.add(new ReinstallServer42FlowForSwitchManagerRequest(switchId, cookie, properties.getServer42MacAddress(), properties.getServer42Vlan(), properties.getServer42Port()));
        } else {
            commands.add(new ReinstallDefaultFlowForSwitchManagerRequest(switchId, cookie));
        }
    }
    return commands;
}
Also used : ReinstallDefaultFlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.ReinstallDefaultFlowForSwitchManagerRequest) ArrayList(java.util.ArrayList) SwitchProperties(org.openkilda.model.SwitchProperties) ReinstallServer42FlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.ReinstallServer42FlowForSwitchManagerRequest)

Example 40 with SwitchProperties

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

the class CommandBuilderImpl method buildInstallSpecialDefaultRuleCommands.

/**
 * Some default rules require additional properties to be installed. This method creates commands for such rules.
 */
private List<BaseInstallFlow> buildInstallSpecialDefaultRuleCommands(SwitchId switchId, List<Long> switchRules) {
    SwitchProperties properties = getSwitchProperties(switchId);
    List<BaseInstallFlow> commands = new ArrayList<>();
    for (Long cookie : switchRules) {
        InstallServer42FlowBuilder command = InstallServer42Flow.builder().transactionId(transactionIdGenerator.generate()).cookie(cookie).switchId(switchId).multiTable(properties.isMultiTable()).inputPort(0).outputPort(0).server42Vlan(properties.getServer42Vlan()).server42MacAddress(properties.getServer42MacAddress());
        if (cookie == SERVER_42_FLOW_RTT_OUTPUT_VLAN_COOKIE) {
            commands.add(command.id("SWMANAGER_SERVER_42_FLOW_RTT_OUTPUT_VLAN_RULE_INSTALL").outputPort(properties.getServer42Port()).build());
        } else if (cookie == SERVER_42_FLOW_RTT_OUTPUT_VXLAN_COOKIE) {
            commands.add(command.id("SWMANAGER_SERVER_42_FLOW_RTT_OUTPUT_VXLAN_RULE_INSTALL").outputPort(properties.getServer42Port()).build());
        } else if (new PortColourCookie(cookie).getType() == CookieType.SERVER_42_FLOW_RTT_INPUT) {
            commands.add(command.id("SWMANAGER_SERVER_42_FLOW_RTT_INPUT_RULE_INSTALL").inputPort(properties.getServer42Port()).build());
        } else if (cookie == SERVER_42_ISL_RTT_OUTPUT_COOKIE) {
            commands.add(command.id("SWMANAGER_SERVER_42_ISL_RTT_OUTPUT_RULE_INSTALL").outputPort(properties.getServer42Port()).build());
        } else if (new PortColourCookie(cookie).getType() == CookieType.SERVER_42_ISL_RTT_INPUT) {
            commands.add(command.id("SWMANAGER_SERVER_42_ISL_RTT_INPUT_RULE_INSTALL").inputPort(properties.getServer42Port()).build());
        } else {
            log.warn("Got request for installation of unknown rule {} on switch {}", cookie, switchId);
        }
    }
    return commands;
}
Also used : ArrayList(java.util.ArrayList) BaseInstallFlow(org.openkilda.messaging.command.flow.BaseInstallFlow) InstallServer42FlowBuilder(org.openkilda.messaging.command.flow.InstallServer42Flow.InstallServer42FlowBuilder) SwitchProperties(org.openkilda.model.SwitchProperties) PortColourCookie(org.openkilda.model.cookie.PortColourCookie)

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