Search in sources :

Example 46 with Flow

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

the class FlowServiceImpl method rerouteFlow.

/**
 * {@inheritDoc}
 */
@Override
public FlowPathPayload rerouteFlow(String flowId, String correlationId) {
    Flow flow = new Flow();
    flow.setFlowId(flowId);
    FlowRerouteRequest data = new FlowRerouteRequest(flow, FlowOperation.UPDATE);
    CommandMessage command = new CommandMessage(data, System.currentTimeMillis(), correlationId, Destination.WFM);
    messageConsumer.clear();
    messageProducer.send(topic, command);
    Message message = (Message) messageConsumer.poll(correlationId);
    logger.debug("Got response {}", message);
    FlowPathResponse response = (FlowPathResponse) validateInfoMessage(command, message, correlationId);
    return Converter.buildFlowPathPayloadByFlowPath(flowId, response.getPayload());
}
Also used : FlowPathResponse(org.openkilda.messaging.info.flow.FlowPathResponse) InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) Flow(org.openkilda.messaging.model.Flow) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 47 with Flow

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

the class FlowCache method getFlowLinkedEndpoint.

/**
 * Gets flow linked with specified switch id.
 *
 * @param flow     flow
 * @param switchId switch id
 * @return second endpoint if specified switch id one of the flows endpoint, otherwise null
 */
private String getFlowLinkedEndpoint(ImmutablePair<Flow, Flow> flow, String switchId) {
    Flow forward = flow.getLeft();
    Flow reverse = flow.getRight();
    String linkedSwitch = null;
    if (forward.getSourceSwitch().equals(switchId) && reverse.getDestinationSwitch().equals(switchId)) {
        linkedSwitch = forward.getDestinationSwitch();
    } else if (forward.getDestinationSwitch().equals(switchId) && reverse.getSourceSwitch().equals(switchId)) {
        linkedSwitch = forward.getSourceSwitch();
    }
    return linkedSwitch;
}
Also used : Flow(org.openkilda.messaging.model.Flow)

Example 48 with Flow

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

the class FlowCacheTest method makeFlow.

private Flow makeFlow(String id, SwitchInfoData source, SwitchInfoData dest, int bandwidth) {
    Flow flow = new Flow();
    flow.setFlowId(id);
    flow.setSourceSwitch(source.getSwitchId());
    flow.setDestinationSwitch(dest.getSwitchId());
    flow.setBandwidth(bandwidth);
    return flow;
}
Also used : Flow(org.openkilda.messaging.model.Flow)

Example 49 with Flow

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

the class FlowCrudSteps method eachFlowCanNotBeReadFromTopologyEngine.

@And("^each flow can not be read from TopologyEngine$")
public void eachFlowCanNotBeReadFromTopologyEngine() {
    for (FlowPayload flow : flows) {
        ImmutablePair<Flow, Flow> result = Failsafe.with(retryPolicy.abortIf(Objects::isNull)).get(() -> topologyEngineService.getFlow(flow.getId()));
        assertNull(format("The flow '%s' exists.", flow.getId()), result);
    }
}
Also used : FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) Objects(java.util.Objects) Flow(org.openkilda.messaging.model.Flow) And(cucumber.api.java.en.And)

Example 50 with Flow

use of org.openkilda.messaging.model.Flow 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

Flow (org.openkilda.messaging.model.Flow)54 InfoMessage (org.openkilda.messaging.info.InfoMessage)23 Values (org.apache.storm.tuple.Values)14 PathInfoData (org.openkilda.messaging.info.event.PathInfoData)14 InstallOneSwitchFlow (org.openkilda.messaging.command.flow.InstallOneSwitchFlow)13 RemoveFlow (org.openkilda.messaging.command.flow.RemoveFlow)13 Test (org.junit.Test)12 CommandMessage (org.openkilda.messaging.command.CommandMessage)8 ImmutablePair (org.openkilda.messaging.model.ImmutablePair)8 AbstractStormTest (org.openkilda.wfm.AbstractStormTest)8 FlowResponse (org.openkilda.messaging.info.flow.FlowResponse)6 Then (cucumber.api.java.en.Then)5 FlowIdStatusPayload (org.openkilda.messaging.payload.flow.FlowIdStatusPayload)5 UnroutablePathException (org.openkilda.pce.provider.UnroutablePathException)5 Driver (org.neo4j.driver.v1.Driver)4 MessageException (org.openkilda.messaging.error.MessageException)4 FlowPayload (org.openkilda.messaging.payload.flow.FlowPayload)4 And (cucumber.api.java.en.And)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3