Search in sources :

Example 1 with FlowEndpointPayload

use of org.openkilda.messaging.payload.flow.FlowEndpointPayload in project open-kilda by telstra.

the class FlowServiceImplTest method updateFlow.

@Test
public void updateFlow() throws Exception {
    long updatedBandwidth = 20000L;
    FlowEndpointPayload firstEndpoint = new FlowEndpointPayload(srcSwitchId, 10, 100);
    FlowEndpointPayload secondEndpoint = new FlowEndpointPayload(dstSwitchId, 20, 100);
    FlowPayload flowPayload = new FlowPayload(flowId, 0L, secondEndpoint, firstEndpoint, 10000L, "", "", OutputVlanType.NONE);
    FlowPayload newFlowPayload = new FlowPayload(flowId, 0L, secondEndpoint, firstEndpoint, updatedBandwidth, "", "", OutputVlanType.NONE);
    flowService.createFlow(flowPayload, DEFAULT_CORRELATION_ID);
    flowService.updateFlow(newFlowPayload, DEFAULT_CORRELATION_ID);
    Set<Flow> flows = flowRepository.findByFlowId(flowId);
    assertNotNull(flows);
    assertFalse(flows.isEmpty());
    assertEquals(2, flows.size());
    for (Flow flow : flowRepository.findAll()) {
        assertEquals(flowId, flow.getFlowId());
        assertEquals(updatedBandwidth, flow.getBandwidth());
    }
}
Also used : FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) FlowEndpointPayload(org.openkilda.messaging.payload.flow.FlowEndpointPayload) Flow(org.openkilda.topology.domain.Flow) Test(org.junit.Test)

Example 2 with FlowEndpointPayload

use of org.openkilda.messaging.payload.flow.FlowEndpointPayload in project open-kilda by telstra.

the class FlowIgnoreBandwidthTest method flowIgnoreBandwidthBetweenSwitchesWithBandwidthIsCreated.

@When("^flow ignore bandwidth between ([0-9a-f]{2}(?::[0-9a-f]{2}){7}) and ([0-9a-f]{2}(?::[0-9a-f]{2}){7}) with (\\d+) bandwidth is created$")
public void flowIgnoreBandwidthBetweenSwitchesWithBandwidthIsCreated(String source, String dest, int bandwidth) throws InterruptedException {
    String flowId = FlowUtils.getFlowName("flowId");
    FlowEndpointPayload sourcePoint = new FlowEndpointPayload(source, 1, 0);
    FlowEndpointPayload destPoint = new FlowEndpointPayload(dest, 2, 0);
    FlowPayload requestPayload = new FlowPayload(flowId, sourcePoint, destPoint, bandwidth, true, "Flow that ignore ISL bandwidth", null);
    System.out.println(String.format("==> Send flow CREATE request (%s <--> %s)", source, dest));
    FlowPayload response = FlowUtils.putFlow(requestPayload);
    Assert.assertNotNull(response);
    response.setLastUpdated(null);
    System.out.println(String.format("==> Wait till flow become \"UP\" (%s <--> %s)", source, dest));
    FlowIdStatusPayload status = FlowUtils.waitFlowStatus(flowId, FlowState.UP);
    assertNotNull(status);
    assertEquals(FlowState.UP, status.getStatus());
    saveCreatedFlowId(source, dest, flowId);
}
Also used : FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) FlowIdStatusPayload(org.openkilda.messaging.payload.flow.FlowIdStatusPayload) FlowEndpointPayload(org.openkilda.messaging.payload.flow.FlowEndpointPayload) When(cucumber.api.java.en.When)

Example 3 with FlowEndpointPayload

use of org.openkilda.messaging.payload.flow.FlowEndpointPayload in project open-kilda by telstra.

the class FlowServiceImplTest method deleteFlow.

@Test
public void deleteFlow() throws Exception {
    FlowEndpointPayload firstEndpoint = new FlowEndpointPayload(srcSwitchId, 10, 100);
    FlowEndpointPayload secondEndpoint = new FlowEndpointPayload(dstSwitchId, 20, 100);
    FlowPayload flowPayload = new FlowPayload(flowId, 0L, secondEndpoint, firstEndpoint, 10000L, "", "", OutputVlanType.NONE);
    FlowIdStatusPayload flowIdStatusPayload = new FlowIdStatusPayload(flowId);
    flowService.createFlow(flowPayload, DEFAULT_CORRELATION_ID);
    flowService.deleteFlow(flowIdStatusPayload, DEFAULT_CORRELATION_ID);
    Set<Flow> flows = flowRepository.findByFlowId(flowId);
    assertNotNull(flows);
    assertTrue(flows.isEmpty());
}
Also used : FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) FlowIdStatusPayload(org.openkilda.messaging.payload.flow.FlowIdStatusPayload) FlowEndpointPayload(org.openkilda.messaging.payload.flow.FlowEndpointPayload) Flow(org.openkilda.topology.domain.Flow) Test(org.junit.Test)

Example 4 with FlowEndpointPayload

use of org.openkilda.messaging.payload.flow.FlowEndpointPayload in project open-kilda by telstra.

the class FlowServiceImplTest method createFlow.

@Test
public void createFlow() throws Exception {
    FlowEndpointPayload firstEndpoint = new FlowEndpointPayload(srcSwitchId, DIRECT_INCOMING_PORT, INPUT_VLAN_ID);
    FlowEndpointPayload secondEndpoint = new FlowEndpointPayload(dstSwitchId, DIRECT_OUTGOING_PORT, OUTPUT_VLAN_ID);
    FlowPayload flowPayload = new FlowPayload(flowId, 0L, firstEndpoint, secondEndpoint, 10000L, "", "", OutputVlanType.NONE);
    flowService.createFlow(flowPayload, DEFAULT_CORRELATION_ID);
    Set<Flow> flows = flowRepository.findByFlowId(flowId);
    assertNotNull(flows);
    assertFalse(flows.isEmpty());
    assertEquals(2, flows.size());
}
Also used : FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) FlowEndpointPayload(org.openkilda.messaging.payload.flow.FlowEndpointPayload) Flow(org.openkilda.topology.domain.Flow) Test(org.junit.Test)

Example 5 with FlowEndpointPayload

use of org.openkilda.messaging.payload.flow.FlowEndpointPayload in project open-kilda by telstra.

the class FlowCrudSteps method buildFlow.

private FlowPayload buildFlow(String flowId, Switch srcSwitch, Switch destSwitch) {
    // Take the switch vlan ranges as the base
    RangeSet<Integer> srcRangeSet = TreeRangeSet.create();
    srcSwitch.getOutPorts().forEach(port -> srcRangeSet.addAll(port.getVlanRange()));
    RangeSet<Integer> destRangeSet = TreeRangeSet.create();
    destSwitch.getOutPorts().forEach(port -> destRangeSet.addAll(port.getVlanRange()));
    // Exclude already allocated vlans
    srcRangeSet.removeAll(allocatedVlans);
    destRangeSet.removeAll(allocatedVlans);
    if (srcRangeSet.isEmpty() || destRangeSet.isEmpty()) {
        LOGGER.warn("Unable to define a flow between {} and {} as no vlan available.", srcSwitch, destSwitch);
        return null;
    }
    // Calculate intersection of the ranges
    RangeSet<Integer> interRangeSet = TreeRangeSet.create(srcRangeSet);
    interRangeSet.removeAll(destRangeSet.complement());
    // Same vlan for source and destination
    final Optional<Integer> sameVlan = interRangeSet.asRanges().stream().flatMap(range -> ContiguousSet.create(range, DiscreteDomain.integers()).stream()).findFirst();
    int srcVlan;
    int destVlan;
    if (sameVlan.isPresent()) {
        srcVlan = sameVlan.get();
        destVlan = sameVlan.get();
    } else {
        // Cross vlan flow
        Optional<Integer> srcVlanOpt = srcRangeSet.asRanges().stream().flatMap(range -> ContiguousSet.create(range, DiscreteDomain.integers()).stream()).findFirst();
        if (!srcVlanOpt.isPresent()) {
            LOGGER.warn("Unable to allocate a vlan for the switch {}.", srcSwitch);
            return null;
        }
        srcVlan = srcVlanOpt.get();
        Optional<Integer> destVlanOpt = destRangeSet.asRanges().stream().flatMap(range -> ContiguousSet.create(range, DiscreteDomain.integers()).stream()).findFirst();
        if (!destVlanOpt.isPresent()) {
            LOGGER.warn("Unable to allocate a vlan for the switch {}.", destSwitch);
            return null;
        }
        destVlan = destVlanOpt.get();
    }
    boolean sameSwitchFlow = srcSwitch.getDpId().equals(destSwitch.getDpId());
    Optional<OutPort> srcPort = srcSwitch.getOutPorts().stream().filter(p -> p.getVlanRange().contains(srcVlan)).findFirst();
    int srcPortId = srcPort.orElseThrow(() -> new IllegalStateException("Unable to allocate a port in found vlan.")).getPort();
    Optional<OutPort> destPort = destSwitch.getOutPorts().stream().filter(p -> p.getVlanRange().contains(destVlan)).filter(p -> !sameSwitchFlow || p.getPort() != srcPortId).findFirst();
    if (!destPort.isPresent()) {
        if (sameSwitchFlow) {
            LOGGER.warn("Unable to define a same switch flow for {} as no ports available.", srcSwitch);
            return null;
        } else {
            throw new IllegalStateException("Unable to allocate a port in found vlan.");
        }
    }
    // Record used vlan to archive uniqueness
    allocatedVlans.add(Range.singleton(srcVlan));
    allocatedVlans.add(Range.singleton(destVlan));
    FlowEndpointPayload srcEndpoint = new FlowEndpointPayload(srcSwitch.getDpId(), srcPortId, srcVlan);
    FlowEndpointPayload destEndpoint = new FlowEndpointPayload(destSwitch.getDpId(), destPort.get().getPort(), destVlan);
    return new FlowPayload(flowId, srcEndpoint, destEndpoint, 1, false, flowId, null);
}
Also used : RangeSet(com.google.common.collect.RangeSet) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) Assert.assertThat(org.junit.Assert.assertThat) Given(cucumber.api.java.en.Given) NorthboundService(org.openkilda.atdd.staging.service.northbound.NorthboundService) FloodlightService(org.openkilda.atdd.staging.service.floodlight.FloodlightService) Then(cucumber.api.java.en.Then) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) Matchers.reflectEquals(com.nitorcreations.Matchers.reflectEquals) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) ImmutablePair(org.openkilda.messaging.model.ImmutablePair) Collections.emptyList(java.util.Collections.emptyList) Range(com.google.common.collect.Range) TopologyChecker(org.openkilda.atdd.staging.steps.helpers.TopologyChecker) FlowEndpointPayload(org.openkilda.messaging.payload.flow.FlowEndpointPayload) RetryPolicy(net.jodah.failsafe.RetryPolicy) UUID(java.util.UUID) String.format(java.lang.String.format) Objects(java.util.Objects) List(java.util.List) TopologyEngineService(org.openkilda.atdd.staging.service.topology.TopologyEngineService) Assert.assertFalse(org.junit.Assert.assertFalse) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) ContiguousSet(com.google.common.collect.ContiguousSet) Switch(org.openkilda.atdd.staging.model.topology.TopologyDefinition.Switch) TreeRangeSet(com.google.common.collect.TreeRangeSet) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) FlowIdStatusPayload(org.openkilda.messaging.payload.flow.FlowIdStatusPayload) DiscreteDomain(com.google.common.collect.DiscreteDomain) And(cucumber.api.java.en.And) Flow(org.openkilda.messaging.model.Flow) Logger(org.slf4j.Logger) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Failsafe(net.jodah.failsafe.Failsafe) TimeUnit(java.util.concurrent.TimeUnit) Collectors.toList(java.util.stream.Collectors.toList) Assert.assertNull(org.junit.Assert.assertNull) OutPort(org.openkilda.atdd.staging.model.topology.TopologyDefinition.OutPort) En(cucumber.api.java8.En) FlowState(org.openkilda.messaging.payload.flow.FlowState) VisibleForTesting(com.google.common.annotations.VisibleForTesting) When(cucumber.api.java.en.When) TopologyDefinition(org.openkilda.atdd.staging.model.topology.TopologyDefinition) FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) OutPort(org.openkilda.atdd.staging.model.topology.TopologyDefinition.OutPort) FlowEndpointPayload(org.openkilda.messaging.payload.flow.FlowEndpointPayload)

Aggregations

FlowEndpointPayload (org.openkilda.messaging.payload.flow.FlowEndpointPayload)9 FlowPayload (org.openkilda.messaging.payload.flow.FlowPayload)9 When (cucumber.api.java.en.When)5 Test (org.junit.Test)3 FlowIdStatusPayload (org.openkilda.messaging.payload.flow.FlowIdStatusPayload)3 Flow (org.openkilda.topology.domain.Flow)3 Given (cucumber.api.java.en.Given)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ContiguousSet (com.google.common.collect.ContiguousSet)1 DiscreteDomain (com.google.common.collect.DiscreteDomain)1 Range (com.google.common.collect.Range)1 RangeSet (com.google.common.collect.RangeSet)1 TreeRangeSet (com.google.common.collect.TreeRangeSet)1 Matchers.reflectEquals (com.nitorcreations.Matchers.reflectEquals)1 And (cucumber.api.java.en.And)1 Then (cucumber.api.java.en.Then)1 En (cucumber.api.java8.En)1 String.format (java.lang.String.format)1 Collections.emptyList (java.util.Collections.emptyList)1 List (java.util.List)1