Search in sources :

Example 21 with SwitchProperties

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

the class PersistenceDataAdapterTest method shouldKeepMultitableForFlowInSwitchProperties.

@Test
public void shouldKeepMultitableForFlowInSwitchProperties() {
    Set<SwitchId> switchIds = Sets.newHashSet(SWITCH_ID_1, SWITCH_ID_2);
    Switch sw1 = buildSwitch(SWITCH_ID_1, singleton(SwitchFeature.MULTI_TABLE));
    SwitchProperties switchProperties1 = buildSwitchProperties(sw1, false);
    Switch sw2 = buildSwitch(SWITCH_ID_2, singleton(SwitchFeature.MULTI_TABLE));
    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);
    when(flowRepository.findByEndpointSwitchWithMultiTableSupport(SWITCH_ID_1)).thenReturn(singleton(mock(Flow.class)));
    adapter = PersistenceDataAdapter.builder().switchIds(switchIds).persistenceManager(persistenceManager).keepMultitableForFlow(true).build();
    assertTrue(adapter.getSwitchProperties(SWITCH_ID_1).isMultiTable());
    assertTrue(adapter.getSwitchProperties(SWITCH_ID_2).isMultiTable());
}
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 22 with SwitchProperties

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

the class FlowPathBuilder method buildPathSegments.

/**
 * Build a path segments using provided path.
 *
 * @param pathId a pathId the segments will be associated with.
 * @param pathForSegments path to be used for the segments.
 * @param bandwidth bandwidth to be used for the segments.
 * @param ignoreBandwidth ignore bandwidth be used for the segments.
 * @param sharedBandwidthGroupId a shared bandwidth group to be set for the segments
 */
public List<PathSegment> buildPathSegments(PathId pathId, Path pathForSegments, long bandwidth, boolean ignoreBandwidth, String sharedBandwidthGroupId) {
    Map<SwitchId, SwitchProperties> switchProperties = getSwitchProperties(pathId);
    List<PathSegment> result = new ArrayList<>();
    for (int i = 0; i < pathForSegments.getSegments().size(); i++) {
        Path.Segment segment = pathForSegments.getSegments().get(i);
        SwitchProperties srcSwitchProperties = switchProperties.get(segment.getSrcSwitchId());
        SwitchProperties dstSwitchProperties = switchProperties.get(segment.getDestSwitchId());
        result.add(PathSegment.builder().seqId(i).pathId(pathId).srcSwitch(Switch.builder().switchId(segment.getSrcSwitchId()).build()).srcPort(segment.getSrcPort()).srcWithMultiTable(srcSwitchProperties.isMultiTable()).destSwitch(Switch.builder().switchId(segment.getDestSwitchId()).build()).destPort(segment.getDestPort()).destWithMultiTable(dstSwitchProperties.isMultiTable()).latency(segment.getLatency()).bandwidth(bandwidth).ignoreBandwidth(ignoreBandwidth).sharedBandwidthGroupId(sharedBandwidthGroupId).build());
    }
    return result;
}
Also used : FlowPath(org.openkilda.model.FlowPath) Path(org.openkilda.pce.Path) ArrayList(java.util.ArrayList) Segment(org.openkilda.pce.Path.Segment) SwitchId(org.openkilda.model.SwitchId) PathSegment(org.openkilda.model.PathSegment) SwitchProperties(org.openkilda.model.SwitchProperties)

Example 23 with SwitchProperties

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

the class BaseResourceAllocationAction method updateSwitchRelatedFlowProperties.

private void updateSwitchRelatedFlowProperties(Flow flow) {
    Map<SwitchId, SwitchProperties> switchProperties = LazyMap.lazyMap(new HashMap<>(), switchId -> switchPropertiesRepository.findBySwitchId(switchId).orElse(null));
    DetectConnectedDevices.DetectConnectedDevicesBuilder detectConnectedDevices = flow.getDetectConnectedDevices().toBuilder();
    SwitchProperties srcSwitchProps = switchProperties.get(flow.getSrcSwitchId());
    if (srcSwitchProps != null) {
        detectConnectedDevices.srcSwitchLldp(srcSwitchProps.isSwitchLldp());
        detectConnectedDevices.srcSwitchArp(srcSwitchProps.isSwitchArp());
    }
    SwitchProperties destSwitchProps = switchProperties.get(flow.getDestSwitchId());
    if (destSwitchProps != null) {
        switchProperties.put(flow.getDestSwitchId(), destSwitchProps);
        detectConnectedDevices.dstSwitchLldp(destSwitchProps.isSwitchLldp());
        detectConnectedDevices.dstSwitchArp(destSwitchProps.isSwitchArp());
    }
    flow.setDetectConnectedDevices(detectConnectedDevices.build());
}
Also used : SwitchId(org.openkilda.model.SwitchId) DetectConnectedDevices(org.openkilda.model.DetectConnectedDevices) SwitchProperties(org.openkilda.model.SwitchProperties)

Example 24 with SwitchProperties

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

the class BaseFlowRuleRemovalAction method buildSpeakerContextForRemovalIngressAndShared.

protected SpeakerRequestBuildContext buildSpeakerContextForRemovalIngressAndShared(RequestedFlow oldFlow, RequestedFlow newFlow, boolean removeMeters) {
    SwitchProperties srcSwitchProperties = getSwitchProperties(oldFlow.getSrcSwitch());
    boolean server42FlowRttToggle = isServer42FlowRttFeatureToggle();
    boolean srcServer42FlowRtt = srcSwitchProperties.isServer42FlowRtt() && server42FlowRttToggle;
    FlowEndpoint oldIngress = new FlowEndpoint(oldFlow.getSrcSwitch(), oldFlow.getSrcPort(), oldFlow.getSrcVlan(), oldFlow.getSrcInnerVlan());
    FlowEndpoint oldEgress = new FlowEndpoint(oldFlow.getDestSwitch(), oldFlow.getDestPort(), oldFlow.getDestVlan(), oldFlow.getDestInnerVlan());
    FlowEndpoint newIngress = new FlowEndpoint(newFlow.getSrcSwitch(), newFlow.getSrcPort(), newFlow.getSrcVlan(), newFlow.getSrcInnerVlan());
    FlowEndpoint newEgress = new FlowEndpoint(newFlow.getDestSwitch(), newFlow.getDestPort(), newFlow.getDestVlan(), newFlow.getDestInnerVlan());
    PathContext forwardPathContext = PathContext.builder().removeCustomerPortRule(removeForwardCustomerPortSharedCatchRule(oldFlow, newFlow)).removeCustomerPortLldpRule(removeForwardSharedLldpRule(oldFlow, newFlow)).removeCustomerPortArpRule(removeForwardSharedArpRule(oldFlow, newFlow)).removeOuterVlanMatchSharedRule(removeOuterVlanMatchSharedRule(oldFlow.getFlowId(), oldIngress, newIngress)).removeServer42InputRule(removeForwardSharedServer42InputRule(oldFlow, newFlow, srcServer42FlowRtt)).removeServer42IngressRule(srcServer42FlowRtt).updateMeter(removeMeters).removeServer42OuterVlanMatchSharedRule(srcServer42FlowRtt && removeServer42OuterVlanMatchSharedRule(oldFlow, oldIngress, newIngress)).server42Port(srcSwitchProperties.getServer42Port()).server42MacAddress(srcSwitchProperties.getServer42MacAddress()).build();
    SwitchProperties dstSwitchProperties = getSwitchProperties(oldFlow.getDestSwitch());
    boolean dstServer42FlowRtt = dstSwitchProperties.isServer42FlowRtt() && server42FlowRttToggle;
    PathContext reversePathContext = PathContext.builder().removeCustomerPortRule(removeReverseCustomerPortSharedCatchRule(oldFlow, newFlow)).removeCustomerPortLldpRule(removeReverseSharedLldpRule(oldFlow, newFlow)).removeCustomerPortArpRule(removeReverseSharedArpRule(oldFlow, newFlow)).removeOuterVlanMatchSharedRule(removeOuterVlanMatchSharedRule(oldFlow.getFlowId(), oldEgress, newEgress)).removeServer42InputRule(removeReverseSharedServer42InputRule(oldFlow, newFlow, dstServer42FlowRtt)).removeServer42IngressRule(dstServer42FlowRtt).updateMeter(removeMeters).removeServer42OuterVlanMatchSharedRule(dstServer42FlowRtt && removeServer42OuterVlanMatchSharedRule(oldFlow, oldEgress, newEgress)).server42Port(dstSwitchProperties.getServer42Port()).server42MacAddress(dstSwitchProperties.getServer42MacAddress()).build();
    return SpeakerRequestBuildContext.builder().forward(forwardPathContext).reverse(reversePathContext).build();
}
Also used : PathContext(org.openkilda.wfm.share.model.SpeakerRequestBuildContext.PathContext) FlowEndpoint(org.openkilda.model.FlowEndpoint) SwitchProperties(org.openkilda.model.SwitchProperties)

Example 25 with SwitchProperties

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

the class FlowValidator method checkForConnectedDevisesConflict.

private void checkForConnectedDevisesConflict(String flowId, SwitchId switchId) throws InvalidFlowException {
    SwitchProperties properties = switchPropertiesRepository.findBySwitchId(switchId).orElseThrow(() -> new InvalidFlowException(format("Couldn't get switch properties for switch %s.", switchId), ErrorType.DATA_INVALID));
    if (properties.isSwitchLldp() || properties.isSwitchArp()) {
        String errorMessage = format("Connected devices feature is active on the switch %s, " + "flow mirror point cannot be created on this switch.", switchId);
        throw new InvalidFlowException(errorMessage, ErrorType.PARAMETERS_INVALID);
    }
    Optional<Flow> foundFlow = flowRepository.findById(flowId);
    if (foundFlow.isPresent()) {
        Flow flow = foundFlow.get();
        FlowEndpoint source = new FlowSourceAdapter(flow).getEndpoint();
        FlowEndpoint destination = new FlowDestAdapter(flow).getEndpoint();
        if (switchId.equals(source.getSwitchId())) {
            if (source.isTrackLldpConnectedDevices() || source.isTrackArpConnectedDevices()) {
                String errorMessage = format("Connected devices feature is active on the flow %s for endpoint %s, " + "flow mirror point cannot be created this flow", flow.getFlowId(), source);
                throw new InvalidFlowException(errorMessage, ErrorType.PARAMETERS_INVALID);
            }
        } else {
            if (destination.isTrackLldpConnectedDevices() || destination.isTrackArpConnectedDevices()) {
                String errorMessage = format("Connected devices feature is active on the flow %s for endpoint %s, " + "flow mirror point cannot be created this flow", flow.getFlowId(), destination);
                throw new InvalidFlowException(errorMessage, ErrorType.PARAMETERS_INVALID);
            }
        }
    }
}
Also used : FlowSourceAdapter(org.openkilda.adapter.FlowSourceAdapter) FlowEndpoint(org.openkilda.model.FlowEndpoint) FlowDestAdapter(org.openkilda.adapter.FlowDestAdapter) SwitchProperties(org.openkilda.model.SwitchProperties) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow)

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