Search in sources :

Example 1 with IslImmutableView

use of org.openkilda.persistence.repositories.IslRepository.IslImmutableView in project open-kilda by telstra.

the class AvailableNetworkFactoryTest method shouldBuildAvailableNetworkForFlowWithIgnoreBandwidthPaths.

@Test
public void shouldBuildAvailableNetworkForFlowWithIgnoreBandwidthPaths() throws Exception {
    Flow flow = getFlow(false);
    IslImmutableView isl = getIslView(flow);
    PathId pathId = new PathId("flow-path-id");
    FlowPath flowPath = FlowPath.builder().pathId(pathId).srcSwitch(flow.getSrcSwitch()).destSwitch(flow.getDestSwitch()).ignoreBandwidth(true).build();
    when(config.getNetworkStrategy()).thenReturn("SYMMETRIC_COST");
    when(islRepository.findSymmetricActiveByBandwidthAndEncapsulationType(flow.getBandwidth(), flow.getEncapsulationType())).thenReturn(Collections.singletonList(isl));
    when(flowPathRepository.findById(pathId)).thenReturn(Optional.of(flowPath));
    AvailableNetwork availableNetwork = availableNetworkFactory.getAvailableNetwork(flow, Collections.singletonList(pathId));
    assertAvailableNetworkIsCorrect(isl, availableNetwork);
}
Also used : IslImmutableView(org.openkilda.persistence.repositories.IslRepository.IslImmutableView) PathId(org.openkilda.model.PathId) FlowPath(org.openkilda.model.FlowPath) AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 2 with IslImmutableView

use of org.openkilda.persistence.repositories.IslRepository.IslImmutableView in project open-kilda by telstra.

the class AvailableNetworkFactoryTest method shouldBuildAvailableNetworkUsingSymmetricCostStrategyWithIgnoreBandwidth.

@Test
public void shouldBuildAvailableNetworkUsingSymmetricCostStrategyWithIgnoreBandwidth() throws RecoverableException {
    Flow flow = getFlow(true);
    IslImmutableView isl = getIslView(flow);
    when(config.getNetworkStrategy()).thenReturn("SYMMETRIC_COST");
    when(islRepository.findActiveByEncapsulationType(flow.getEncapsulationType())).thenReturn(Collections.singletonList(isl));
    AvailableNetwork availableNetwork = availableNetworkFactory.getAvailableNetwork(flow, Collections.emptyList());
    assertAvailableNetworkIsCorrect(isl, availableNetwork);
}
Also used : IslImmutableView(org.openkilda.persistence.repositories.IslRepository.IslImmutableView) AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 3 with IslImmutableView

use of org.openkilda.persistence.repositories.IslRepository.IslImmutableView in project open-kilda by telstra.

the class AvailableNetworkFactoryTest method getIslView.

private static IslImmutableView getIslView(Switch srcSwitch, int srcPort, Switch dstSwitch, int dstPort) {
    IslImmutableView isl = mock(IslImmutableView.class);
    when(isl.getSrcSwitchId()).thenReturn(srcSwitch.getSwitchId());
    when(isl.getSrcPort()).thenReturn(srcPort);
    when(isl.getDestSwitchId()).thenReturn(dstSwitch.getSwitchId());
    when(isl.getDestPort()).thenReturn(dstPort);
    when(isl.getCost()).thenReturn(10);
    when(isl.getLatency()).thenReturn(33L);
    when(isl.getAvailableBandwidth()).thenReturn(AVAILABLE_BANDWIDTH);
    when(isl.isUnderMaintenance()).thenReturn(false);
    when(isl.isUnstable()).thenReturn(false);
    return isl;
}
Also used : IslImmutableView(org.openkilda.persistence.repositories.IslRepository.IslImmutableView)

Example 4 with IslImmutableView

use of org.openkilda.persistence.repositories.IslRepository.IslImmutableView in project open-kilda by telstra.

the class AvailableNetworkFactoryTest method shouldBuildAvailableNetworkUsingCostStrategyWithIgnoreBandwidth.

@Test
public void shouldBuildAvailableNetworkUsingCostStrategyWithIgnoreBandwidth() throws RecoverableException {
    Flow flow = getFlow(true);
    IslImmutableView isl = getIslView(flow);
    when(config.getNetworkStrategy()).thenReturn("COST");
    when(islRepository.findActiveByEncapsulationType(flow.getEncapsulationType())).thenReturn(Collections.singletonList(isl));
    AvailableNetwork availableNetwork = availableNetworkFactory.getAvailableNetwork(flow, Collections.emptyList());
    assertAvailableNetworkIsCorrect(isl, availableNetwork);
}
Also used : IslImmutableView(org.openkilda.persistence.repositories.IslRepository.IslImmutableView) AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 5 with IslImmutableView

use of org.openkilda.persistence.repositories.IslRepository.IslImmutableView in project open-kilda by telstra.

the class AvailableNetworkFactoryTest method shouldIncreaseDiversityGroupUseCounter.

@Test
public void shouldIncreaseDiversityGroupUseCounter() throws RecoverableException {
    // Topology:
    // A----B----C     Already created flow: B-D
    // |          Requested flow: A-B-C
    // D
    // there is no ISL B-D because we assume that is has no enough bandwidth
    List<IslImmutableView> isls = new ArrayList<>();
    isls.addAll(getBidirectionalIsls(switchA, 1, switchB, 2));
    isls.addAll(getBidirectionalIsls(switchB, 3, switchC, 4));
    FlowPath forwardPath = FlowPath.builder().srcSwitch(switchB).destSwitch(switchD).pathId(FORWARD_PATH_ID).segments(Collections.singletonList(PathSegment.builder().pathId(FORWARD_PATH_ID).srcSwitch(switchB).srcPort(SRC_PORT).destSwitch(switchD).destPort(DEST_PORT).build())).build();
    when(flowPathRepository.findById(FORWARD_PATH_ID)).thenReturn(java.util.Optional.of(forwardPath));
    FlowPath reversePath = FlowPath.builder().srcSwitch(switchD).destSwitch(switchB).pathId(REVERSE_PATH_ID).segments(Collections.singletonList(PathSegment.builder().pathId(REVERSE_PATH_ID).srcSwitch(switchD).srcPort(DEST_PORT).destSwitch(switchB).destPort(SRC_PORT).build())).build();
    when(flowPathRepository.findById(REVERSE_PATH_ID)).thenReturn(java.util.Optional.of(reversePath));
    Flow flow = getFlow(false);
    flow.setSrcSwitch(switchA);
    flow.setDestSwitch(switchC);
    flow.setDiverseGroupId(DIVERSE_GROUP_ID);
    flow.setForwardPathId(new PathId("forward_path_id"));
    flow.setReversePathId(new PathId("reverse_path_id"));
    when(config.getNetworkStrategy()).thenReturn(BuildStrategy.COST.name());
    when(islRepository.findActiveByBandwidthAndEncapsulationType(flow.getBandwidth(), flow.getEncapsulationType())).thenReturn(isls);
    when(flowPathRepository.findPathIdsByFlowDiverseGroupId(DIVERSE_GROUP_ID)).thenReturn(Lists.newArrayList(FORWARD_PATH_ID, REVERSE_PATH_ID));
    AvailableNetwork availableNetwork = availableNetworkFactory.getAvailableNetwork(flow, Collections.emptyList());
    assertEquals(2, availableNetwork.getSwitch(switchB.getSwitchId()).getDiversityGroupUseCounter());
}
Also used : IslImmutableView(org.openkilda.persistence.repositories.IslRepository.IslImmutableView) PathId(org.openkilda.model.PathId) ArrayList(java.util.ArrayList) FlowPath(org.openkilda.model.FlowPath) AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Aggregations

IslImmutableView (org.openkilda.persistence.repositories.IslRepository.IslImmutableView)10 Test (org.junit.Test)9 Flow (org.openkilda.model.Flow)8 AvailableNetwork (org.openkilda.pce.impl.AvailableNetwork)6 FlowPath (org.openkilda.model.FlowPath)3 PathId (org.openkilda.model.PathId)3 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)3 Isl (org.openkilda.model.Isl)2 Lists (com.google.common.collect.Lists)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 AssertionFailedError (junit.framework.AssertionFailedError)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Matchers (org.hamcrest.Matchers)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertTrue (org.junit.Assert.assertTrue)1