Search in sources :

Example 1 with FlowBuilder

use of org.openkilda.atdd.staging.helpers.FlowSet.FlowBuilder 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)

Aggregations

ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 FlowSet (org.openkilda.atdd.staging.helpers.FlowSet)1 FlowBuilder (org.openkilda.atdd.staging.helpers.FlowSet.FlowBuilder)1 PathInfoData (org.openkilda.messaging.info.event.PathInfoData)1 FlowPayload (org.openkilda.messaging.payload.flow.FlowPayload)1 PathNodePayload (org.openkilda.messaging.payload.flow.PathNodePayload)1 TopologyDefinition (org.openkilda.testing.model.topology.TopologyDefinition)1 Switch (org.openkilda.testing.model.topology.TopologyDefinition.Switch)1