Open Kilda Java Documentation
FlowIgnoreBandwidthTest.java
Go to the documentation of this file.
1 package org.openkilda.atdd;
2 
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotNull;
5 
19 
20 import cucumber.api.java.en.Then;
21 import cucumber.api.java.en.When;
22 import org.junit.Assert;
23 
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27 
29  private final Map<String, String> createdFlows;
30 
32  createdFlows = new HashMap<>();
33  }
34 
35  @Then("^available ISL's bandwidths between ([0-9a-f]{2}(?::[0-9a-f]{2}){7}) "
36  + "and ([0-9a-f]{2}(?::[0-9a-f]{2}){7}) is (\\d+)$")
37  public void availableIslBandwidthsBetweenSwitches(String source, String dest, long expected) {
38  List<LinkDto> islLinks = LinksUtils.dumpLinks();
39 
40  Long actual = null;
41  for (LinkDto link : islLinks) {
42  if (link.getPath().size() != 2) {
43  throw new RuntimeException(
44  String.format("ISL's link path contain %d records, expect 2", link.getPath().size()));
45  }
46  PathDto left = link.getPath().get(0);
47  PathDto right = link.getPath().get(1);
48 
49  if (!new SwitchId(source).equals(left.getSwitchId())) {
50  continue;
51  }
52 
53  if (!new SwitchId(dest).equals(right.getSwitchId())) {
54  continue;
55  }
56 
57  actual = link.getAvailableBandwidth();
58  break;
59  }
60 
61  Assert.assertNotNull(actual);
62  Assert.assertEquals("Actual bandwidth does not match expectations.", expected, (long) actual);
63  System.out.println(String.format("Available bandwidth between %s and %s is %d", source, dest, actual));
64  }
65 
66  @When("^flow ignore bandwidth between ([0-9a-f]{2}(?::[0-9a-f]{2}){7}) "
67  + "and ([0-9a-f]{2}(?::[0-9a-f]{2}){7}) with (\\d+) bandwidth is created$")
68  public void flowIgnoreBandwidthBetweenSwitchesWithBandwidthIsCreated(String source, String dest, int bandwidth)
69  throws InterruptedException {
70  String flowId = FlowUtils.getFlowName("flowId");
71  FlowEndpointPayload sourcePoint = new FlowEndpointPayload(new SwitchId(source), 1, 0);
72  FlowEndpointPayload destPoint = new FlowEndpointPayload(new SwitchId(dest), 2, 0);
73  FlowPayload requestPayload = new FlowPayload(
74  flowId, sourcePoint, destPoint, bandwidth, true, "Flow that ignore ISL bandwidth", null,
75  FlowState.UP.getState());
76 
77  System.out.println(String.format("==> Send flow CREATE request (%s <--> %s)", source, dest));
78  FlowPayload response = FlowUtils.putFlow(requestPayload);
79  Assert.assertNotNull(response);
80  response.setLastUpdated(null);
81 
82  System.out.println(String.format("==> Wait till flow become \"UP\" (%s <--> %s)", source, dest));
84  assertNotNull(status);
85  assertEquals(FlowState.UP, status.getStatus());
86 
87  saveCreatedFlowId(source, dest, flowId);
88  }
89 
90  @Then("^flow between ([0-9a-f]{2}(?::[0-9a-f]{2}){7}) "
91  + "and ([0-9a-f]{2}(?::[0-9a-f]{2}){7}) have ignore_bandwidth flag$")
92  public void flowHaveIgnoreBandwidthFlag(String source, String dest) {
93  String flowId = lookupCreatedFlowId(source, dest);
94  FlowPayload flow = FlowUtils.getFlow(flowId);
95 
96  Assert.assertNotNull("Can\'t locate flow", flow);
97  Assert.assertTrue("Flow's ignore_bandwidth flag is NOT set", flow.isIgnoreBandwidth());
98  }
99 
100  @Then("^flow between ([0-9a-f]{2}(?::[0-9a-f]{2}){7}) "
101  + "and ([0-9a-f]{2}(?::[0-9a-f]{2}){7}) have ignore_bandwidth flag in TE$")
102  public void flowHaveIgnoreBandwidthFlagInTe(String source, String dest) {
103  String flowId = lookupCreatedFlowId(source, dest);
105 
106  Assert.assertNotNull(flowPair);
107  Assert.assertTrue(
108  "Permanent flows storage ignore ignore_bandwidth flag", flowPair.getLeft().isIgnoreBandwidth());
109  Assert.assertTrue(
110  "Permanent flows storage ignore ignore_bandwidth flag", flowPair.getRight().isIgnoreBandwidth());
111  }
112 
113  @When("^drop created flow between ([0-9a-f]{2}(?::[0-9a-f]{2}){7}) and ([0-9a-f]{2}(?::[0-9a-f]{2}){7})$")
114  public void dropCreatedEarlyFlow(String source, String dest) throws FlowOperationException, InterruptedException {
115  String flowId = lookupCreatedFlowId(source, dest);
116 
117  System.out.println(String.format("==> Send flow DELETE request (%s <--> %s)", source, dest));
118  FlowPayload response = FlowUtils.deleteFlow(flowId);
119  assertNotNull(response);
120 
121  System.out.println(String.format("==> Wait till flow become \"DOWN\" (%s <--> %s)", source, dest));
122  FlowUtils.waitFlowDeletion(flowId);
123  }
124 
125  private void saveCreatedFlowId(String source, String dest, String flowId) {
126  createdFlows.put(makeCreatedFlowIdKey(source, dest), flowId);
127  }
128 
129  private String lookupCreatedFlowId(String source, String dest) {
130  String key = makeCreatedFlowIdKey(source, dest);
131  if (!createdFlows.containsKey(key)) {
132  throw new IllegalArgumentException(
133  String.format("There is no known flows between %s and %s", source, dest));
134  }
135  return createdFlows.get(key);
136  }
137 
138  private String makeCreatedFlowIdKey(String source, String dest) {
139  return String.join("<-->", source, dest);
140  }
141 }
void flowIgnoreBandwidthBetweenSwitchesWithBandwidthIsCreated(String source, String dest, int bandwidth)
static FlowPayload deleteFlow(final String flowId)
Definition: FlowUtils.java:238
void flowHaveIgnoreBandwidthFlag(String source, String dest)
void availableIslBandwidthsBetweenSwitches(String source, String dest, long expected)
def status()
Definition: rest.py:593
source
Definition: nodes.py:53
static FlowPayload getFlow(final String flowId)
Definition: FlowUtils.java:126
void dropCreatedEarlyFlow(String source, String dest)
static void waitFlowDeletion(String flowId)
Definition: FlowUtils.java:341
static FlowPayload putFlow(final FlowPayload payload)
Definition: FlowUtils.java:163
void flowHaveIgnoreBandwidthFlagInTe(String source, String dest)
static FlowIdStatusPayload waitFlowStatus(String flowName, FlowState expected)
Definition: FlowUtils.java:325
static String getFlowName(final String flowId)
Definition: FlowUtils.java:595
static ImmutablePair< Flow, Flow > GetFlow(String flowId)