16 package org.openkilda.atdd.staging.service.flowmanager;
18 import static java.lang.String.format;
30 import org.junit.Assume;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.stereotype.Service;
34 import java.text.SimpleDateFormat;
35 import java.util.ArrayList;
36 import java.util.Date;
37 import java.util.HashMap;
38 import java.util.List;
40 import java.util.Random;
42 import java.util.stream.Collectors;
49 private static final SimpleDateFormat sdf =
new SimpleDateFormat(
"ddMMMHHmm");
72 int alternatePaths,
int bandwidth) {
76 boolean foundEnoughFlows =
false;
83 if (srcSwitch.getDpId().compareTo(dstSwitch.getDpId()) >= 0) {
87 List<PathInfoData> forwardPaths = topologyEngineService
88 .getPaths(srcSwitch.getDpId(), dstSwitch.getDpId());
89 List<PathInfoData> reversePaths = topologyEngineService
90 .getPaths(dstSwitch.getDpId(), srcSwitch.getDpId());
91 boolean hasAlternatePath = forwardPaths.size() > alternatePaths && reversePaths.size() > alternatePaths;
92 if (hasAlternatePath) {
94 String flowId =
format(
"%s_%s_%s", srcSwitch.getName(), dstSwitch.getName(),
95 sdf.format(
new Date()));
97 FlowPayload flow = builder.buildInUniqueVlan(srcTraffGen.getSwitchPort(),
98 dstTraffGen.getSwitchPort());
100 northboundService.addFlow(flow);
101 List<PathNodePayload> flowPath = northboundService.getFlowPath(flowId).getForwardPath();
103 for (
int i = 1;
i < flowPath.size();
i++) {
106 isls.addAll(topologyDefinition.getIslsForActiveSwitches().stream().filter(isl ->
107 ((isl.getSrcSwitch().getDpId().equals(from.getSwitchId())
108 && isl.getDstSwitch().getDpId().equals(to.getSwitchId()))
109 || (isl.getSrcSwitch().getDpId().equals(to.getSwitchId())
110 && isl.getDstSwitch().getDpId().equals(from.getSwitchId())))
111 && isl.getAswitch() != null).collect(Collectors.toList()));
113 if (isls.isEmpty()) {
114 northboundService.deleteFlow(flowId);
118 foundEnoughFlows =
result.size() == flowsAmount;
120 if (foundEnoughFlows) {
124 if (foundEnoughFlows) {
128 if (!foundEnoughFlows) {
129 result.keySet().forEach(f -> northboundService.deleteFlow(f.getId()));
131 Assume.assumeTrue(
"Didn't find enough of requested flows. This test cannot be run on given topology. " 132 +
"Do you have enough a-switch links in the topology?", foundEnoughFlows);
147 switches.forEach(srcSwitch ->
148 switches.forEach(dstSwitch -> {
150 if (srcSwitch.getDpId().compareTo(dstSwitch.getDpId()) >= 0) {
155 List<PathInfoData> forwardPath = topologyEngineService
156 .getPaths(srcSwitch.getDpId(), dstSwitch.getDpId());
157 List<PathInfoData> reversePath = topologyEngineService
158 .getPaths(dstSwitch.getDpId(), srcSwitch.getDpId());
159 if (!forwardPath.isEmpty() && !reversePath.isEmpty()) {
160 String flowId =
format(
"%s-%s", srcSwitch.getName(), dstSwitch.getName());
161 flowSet.
addFlow(flowId, srcSwitch, dstSwitch);
166 return flowSet.getFlows();
180 traffGens.forEach(srcTraffGen -> {
182 traffGens.forEach(dstTraffGen -> {
185 if (srcSwitch.getDpId().compareTo(dstSwitch.getDpId()) >= 0) {
189 String flowId =
format(
"%s-%s", srcSwitch.getName(), dstSwitch.getName());
190 flowSet.
addFlow(flowId, srcSwitch, srcTraffGen.getSwitchPort(), dstSwitch, dstTraffGen.getSwitchPort());
199 Random r =
new Random();
200 List<Switch> activeSwitches = topologyDefinition.getActiveSwitches();
201 Switch srcSwitch = activeSwitches.get(r.nextInt(activeSwitches.size()));
202 activeSwitches = activeSwitches.stream()
203 .filter(s -> !s.equals(srcSwitch))
204 .collect(Collectors.toList());
205 Switch dstSwitch = activeSwitches.get(r.nextInt(activeSwitches.size()));
206 String flowId =
format(
"%s-%s-%s", srcSwitch.getName(), dstSwitch.getName(),
207 sdf.format(
new Date()));
Map< FlowPayload, List< TopologyDefinition.Isl > > createFlowsWithASwitch(int flowsAmount, int alternatePaths, int bandwidth)
void setMaximumBandwidth(long maximumBandwidth)
Set< FlowPayload > getFlows()
Set< FlowPayload > allActiveTraffgenFlows()
FlowBuilder getFlowBuilder(String flowId, Switch srcSwitch, Switch destSwitch)
void addFlow(String flowId, Switch srcSwitch, Switch destSwitch)
Set< FlowPayload > allActiveSwitchesFlows()
FlowPayload buildWithAnyPortsInUniqueVlan(String flowId, Switch srcSwitch, Switch destSwitch, int bandwidth)