Search in sources :

Example 1 with FlowSet

use of org.openkilda.atdd.staging.helpers.FlowSet in project open-kilda by telstra.

the class FlowManagerImpl method createFlowsWithASwitch.

/**
 * Creates a number of flows with given number of alternate paths and at least 1 a-switch ISL. a-switch ISL
 * will later allow to bring such link down and verify the further flow behavior. <br>
 * Note that unlike some other methods here, the flow(s) will already be created in the system.
 *
 * @param flowsAmount amount of flows to create. Will throw assumption error if unable to find enough flows
 * @param alternatePaths amount of alternate paths that should be available for the created flows
 * @param bandwidth bandwidth for created flows
 * @return map. Key: created flow. Value: list of a-switch isls for flow.
 */
@Override
public Map<FlowPayload, List<TopologyDefinition.Isl>> createFlowsWithASwitch(int flowsAmount, int alternatePaths, int bandwidth) {
    final List<TopologyDefinition.TraffGen> traffGens = topologyDefinition.getActiveTraffGens();
    FlowSet flowSet = new FlowSet();
    boolean foundEnoughFlows = false;
    Map<FlowPayload, List<TopologyDefinition.Isl>> result = new HashMap<>();
    for (TopologyDefinition.TraffGen srcTraffGen : traffGens) {
        for (TopologyDefinition.TraffGen dstTraffGen : traffGens) {
            TopologyDefinition.Switch srcSwitch = srcTraffGen.getSwitchConnected();
            TopologyDefinition.Switch dstSwitch = dstTraffGen.getSwitchConnected();
            if (srcSwitch.getDpId().compareTo(dstSwitch.getDpId()) >= 0) {
                continue;
            }
            // test only bi-directional flow
            List<PathInfoData> forwardPaths = db.getPaths(srcSwitch.getDpId(), dstSwitch.getDpId());
            List<PathInfoData> reversePaths = db.getPaths(dstSwitch.getDpId(), srcSwitch.getDpId());
            boolean hasAlternatePath = forwardPaths.size() > alternatePaths && reversePaths.size() > alternatePaths;
            if (hasAlternatePath) {
                // try creating flow to see the actual path being used
                String flowId = format("%s_%s_%s", srcSwitch.getName(), dstSwitch.getName(), sdf.format(new Date()));
                FlowBuilder builder = flowSet.getFlowBuilder(flowId, srcSwitch, dstSwitch);
                FlowPayload flow = builder.buildInUniqueVlan(srcTraffGen.getSwitchPort(), dstTraffGen.getSwitchPort());
                flow.setMaximumBandwidth(bandwidth);
                northboundService.addFlow(flow);
                List<PathNodePayload> flowPath = northboundService.getFlowPath(flowId).getForwardPath();
                List<TopologyDefinition.Isl> isls = new ArrayList<>();
                for (int i = 1; i < flowPath.size(); i++) {
                    PathNodePayload from = flowPath.get(i - 1);
                    PathNodePayload to = flowPath.get(i);
                    isls.addAll(topologyDefinition.getIslsForActiveSwitches().stream().filter(isl -> ((isl.getSrcSwitch().getDpId().equals(from.getSwitchId()) && isl.getDstSwitch().getDpId().equals(to.getSwitchId())) || (isl.getSrcSwitch().getDpId().equals(to.getSwitchId()) && isl.getDstSwitch().getDpId().equals(from.getSwitchId()))) && isl.getAswitch() != null).collect(Collectors.toList()));
                }
                if (isls.isEmpty()) {
                    // created flow has no aswitch links, doesn't work for us
                    northboundService.deleteFlow(flowId);
                } else {
                    result.put(flow, isls);
                }
                foundEnoughFlows = result.size() == flowsAmount;
            }
            if (foundEnoughFlows) {
                break;
            }
        }
        if (foundEnoughFlows) {
            break;
        }
    }
    if (!foundEnoughFlows) {
        result.keySet().forEach(f -> northboundService.deleteFlow(f.getId()));
    }
    Assume.assumeTrue("Didn't find enough of requested flows. This test cannot be run on given topology. " + "Do you have enough a-switch links in the topology?", foundEnoughFlows);
    return result;
}
Also used : TopologyDefinition(org.openkilda.testing.model.topology.TopologyDefinition) HashMap(java.util.HashMap) FlowSet(org.openkilda.atdd.staging.helpers.FlowSet) ArrayList(java.util.ArrayList) Date(java.util.Date) Switch(org.openkilda.testing.model.topology.TopologyDefinition.Switch) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) FlowBuilder(org.openkilda.atdd.staging.helpers.FlowSet.FlowBuilder) PathNodePayload(org.openkilda.messaging.payload.flow.PathNodePayload) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with FlowSet

use of org.openkilda.atdd.staging.helpers.FlowSet in project open-kilda by telstra.

the class FlowManagerImpl method allActiveTraffgenFlows.

/**
 * Returns all available flows for all active traffic generators in the topology. Note that active generator
 * should also be connected to active switch
 */
@Override
public Set<FlowPayload> allActiveTraffgenFlows() {
    FlowSet flowSet = new FlowSet();
    final List<TopologyDefinition.TraffGen> traffGens = topologyDefinition.getActiveTraffGens();
    // check each combination of active traffGens and create a flow definition
    traffGens.forEach(srcTraffGen -> {
        TopologyDefinition.Switch srcSwitch = srcTraffGen.getSwitchConnected();
        traffGens.forEach(dstTraffGen -> {
            TopologyDefinition.Switch dstSwitch = dstTraffGen.getSwitchConnected();
            // skip the same switch flow and reverse combination of switches
            if (srcSwitch.getDpId().compareTo(dstSwitch.getDpId()) >= 0) {
                return;
            }
            String flowId = format("%s-%s", srcSwitch.getName(), dstSwitch.getName());
            flowSet.addFlow(flowId, srcSwitch, srcTraffGen.getSwitchPort(), dstSwitch, dstTraffGen.getSwitchPort());
        });
    });
    return flowSet.getFlows();
}
Also used : Switch(org.openkilda.testing.model.topology.TopologyDefinition.Switch) TopologyDefinition(org.openkilda.testing.model.topology.TopologyDefinition) FlowSet(org.openkilda.atdd.staging.helpers.FlowSet)

Example 3 with FlowSet

use of org.openkilda.atdd.staging.helpers.FlowSet in project open-kilda by telstra.

the class FlowManagerImpl method allActiveSwitchesFlows.

/**
 * Returns all available flows for all 'active' switches in the topology.
 */
@Override
public Set<FlowPayload> allActiveSwitchesFlows() {
    FlowSet flowSet = new FlowSet();
    final List<TopologyDefinition.Switch> switches = topologyDefinition.getActiveSwitches();
    // check each combination of active switches for a path between them and create
    // a flow definition if the path exists
    switches.forEach(srcSwitch -> switches.forEach(dstSwitch -> {
        // skip the same switch flow and reverse combination of switches
        if (srcSwitch.getDpId().compareTo(dstSwitch.getDpId()) >= 0) {
            return;
        }
        // test only bi-directional flow
        List<PathInfoData> forwardPath = db.getPaths(srcSwitch.getDpId(), dstSwitch.getDpId());
        List<PathInfoData> reversePath = db.getPaths(dstSwitch.getDpId(), srcSwitch.getDpId());
        if (!forwardPath.isEmpty() && !reversePath.isEmpty()) {
            String flowId = format("%s-%s", srcSwitch.getName(), dstSwitch.getName());
            flowSet.addFlow(flowId, srcSwitch, dstSwitch);
        }
    }));
    return flowSet.getFlows();
}
Also used : Date(java.util.Date) Database(org.openkilda.testing.service.database.Database) Autowired(org.springframework.beans.factory.annotation.Autowired) SimpleDateFormat(java.text.SimpleDateFormat) Set(java.util.Set) HashMap(java.util.HashMap) Random(java.util.Random) FlowSet(org.openkilda.atdd.staging.helpers.FlowSet) PathNodePayload(org.openkilda.messaging.payload.flow.PathNodePayload) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) Switch(org.openkilda.testing.model.topology.TopologyDefinition.Switch) ArrayList(java.util.ArrayList) FlowBuilder(org.openkilda.atdd.staging.helpers.FlowSet.FlowBuilder) List(java.util.List) NorthboundService(org.openkilda.testing.service.northbound.NorthboundService) Service(org.springframework.stereotype.Service) Locale(java.util.Locale) Map(java.util.Map) Qualifier(org.springframework.beans.factory.annotation.Qualifier) Assume(org.junit.Assume) TopologyDefinition(org.openkilda.testing.model.topology.TopologyDefinition) Switch(org.openkilda.testing.model.topology.TopologyDefinition.Switch) FlowSet(org.openkilda.atdd.staging.helpers.FlowSet) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with FlowSet

use of org.openkilda.atdd.staging.helpers.FlowSet in project open-kilda by telstra.

the class FlowManagerImpl method randomFlow.

@Override
public FlowPayload randomFlow() {
    FlowSet flowSet = new FlowSet();
    Random r = new Random();
    List<Switch> activeSwitches = topologyDefinition.getActiveSwitches();
    Switch srcSwitch = activeSwitches.get(r.nextInt(activeSwitches.size()));
    activeSwitches = activeSwitches.stream().filter(s -> !s.equals(srcSwitch)).collect(Collectors.toList());
    Switch dstSwitch = activeSwitches.get(r.nextInt(activeSwitches.size()));
    String flowId = format("%s-%s-%s", srcSwitch.getName(), dstSwitch.getName(), sdf.format(new Date()));
    return flowSet.buildWithAnyPortsInUniqueVlan(flowId, srcSwitch, dstSwitch, 1000);
}
Also used : Random(java.util.Random) Switch(org.openkilda.testing.model.topology.TopologyDefinition.Switch) FlowSet(org.openkilda.atdd.staging.helpers.FlowSet) Date(java.util.Date)

Example 5 with FlowSet

use of org.openkilda.atdd.staging.helpers.FlowSet in project open-kilda by telstra.

the class FlowSteps method createFlowBetween.

@And("^create flow between '(.*)' and '(.*)' and alias it as '(.*)'$")
public void createFlowBetween(String srcAlias, String dstAlias, String flowAlias) {
    Switch srcSwitch = topologyUnderTest.getAliasedObject(srcAlias);
    Switch dstSwitch = topologyUnderTest.getAliasedObject(dstAlias);
    FlowPayload flow = new FlowSet().buildWithAnyPortsInUniqueVlan("auto" + getTimestamp(), srcSwitch, dstSwitch, 1000);
    northboundService.addFlow(flow);
    topologyUnderTest.addAlias(flowAlias, flow);
}
Also used : FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) Switch(org.openkilda.testing.model.topology.TopologyDefinition.Switch) FlowSet(org.openkilda.atdd.staging.helpers.FlowSet) And(cucumber.api.java.en.And)

Aggregations

FlowSet (org.openkilda.atdd.staging.helpers.FlowSet)5 Switch (org.openkilda.testing.model.topology.TopologyDefinition.Switch)5 Date (java.util.Date)3 FlowPayload (org.openkilda.messaging.payload.flow.FlowPayload)3 TopologyDefinition (org.openkilda.testing.model.topology.TopologyDefinition)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Random (java.util.Random)2 FlowBuilder (org.openkilda.atdd.staging.helpers.FlowSet.FlowBuilder)2 PathInfoData (org.openkilda.messaging.info.event.PathInfoData)2 PathNodePayload (org.openkilda.messaging.payload.flow.PathNodePayload)2 And (cucumber.api.java.en.And)1 String.format (java.lang.String.format)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Assume (org.junit.Assume)1