Open Kilda Java Documentation
TopologyDiscoveryBasicTest.java
Go to the documentation of this file.
1 /* Copyright 2017 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.atdd;
17 
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertTrue;
22 
23 import cucumber.api.java.en.Given;
24 import cucumber.api.java.en.Then;
25 import cucumber.api.java.en.When;
26 import org.glassfish.jersey.client.ClientConfig;
32 
33 import javax.ws.rs.client.Client;
34 import javax.ws.rs.client.ClientBuilder;
35 import javax.ws.rs.core.Response;
36 
38 
39  public long pre_start;
40  public long start;
41  public long finish;
43  public static int pre_start_handicap = 10000; // milliseconds .. how long a deploy should take.
44 
45  protected void deploy_toplogy(ITopology t) throws Throwable {
46  expected = t;
47  String json = TopologyPrinter.toMininetJson(t);
48  pre_start = System.currentTimeMillis();
49  assertTrue(TopologyHelp.CreateMininetTopology(json));
50  start = System.currentTimeMillis();
51  }
52 
53  @Given("^a random linear topology of (\\d+) switches$")
54  public void a_random_linear_topology_of(int numSwitches) throws Throwable {
56  }
57 
58  @Given("^a random tree topology with depth of (\\d+) and fanout of (\\d+)$")
59  public void a_random_full_mesh_topology_of(int depth, int fanout) throws Throwable {
61  }
62 
63  @When("^the controller learns the topology$")
64  public void the_controller_learns_the_topology() throws Throwable {
65  // NB: translateTopoEngTopo includes some heuristics regarding waiting for things
66  // TODO: pass the convergence time to this function, since it is the one that loops
67  // and times out; currently it just has a default time; but should be based on the test.
68  // alternatively, as is currently the case, it keeps going as long as there is change
69  // and/or the expected topology is reached.
72  finish = System.currentTimeMillis();
73  }
74 
75  @Then("^the controller should converge within (\\d+) milliseconds$")
76  public void the_controller_should_converge_within_milliseconds(int delta) throws Throwable {
77  if (!(delta >= (finish - start))){
78  System.out.println(String.format("Failed finish-start convergence: delta_ma:%d, actual:%d", delta, (finish-start)));
79  }
80  assertTrue(delta >= (finish - start));
81  // This next test is a little suspect .. it is unclear how much latency is
82  // introduced through mininet. Hypothetically, if mininet took 1 second per switch,
83  // then I'd expect the delta between start and finish to be real small, 1-2 seconds, even
84  // for a 1000 switches.
85  //
86  // We'll test the pre-start too. This will have to be revisited somehow.
87  // The best test will be for the switches to all exist and reach out simultaneously.
88  delta += pre_start_handicap; // TODO: make handicap a factor of topology size
89  if (!(delta >= (finish - pre_start))){
90  System.out.println(String.format("Failed finish-pre_start convergence test: delta_ma:%d, actual:%d", delta, (finish-pre_start)));
91  }
92  assertTrue(delta >= (finish - pre_start));
93  }
94 
95 
96  @Then("^the topology is not changed")
97  public void validate_topology() throws Throwable {
100  }
101 
102  @When("^send malformed lldp packet$")
103  public void sendMalformedLldpPacket() throws Throwable {
104  System.out.println("=====> Send malformed packet");
105 
106  long current = System.currentTimeMillis();
107  Client client = ClientBuilder.newClient(new ClientConfig());
108  Response result = client
109  .target(trafficEndpoint)
110  .path("/send_malformed_packet")
111  .request()
112  .post(null);
113  System.out.println(String.format("======> Response = %s", result.toString()));
114  System.out.println(String.format("======> Send malformed packet Time: %,.3f", getTimeDuration(current)));
115 
116  assertEquals(200, result.getStatus());
117 
118  }
119 }
static final String toMininetJson(ITopology topo)
static void validateTopos(ITopology expected, ITopology actual)
Definition: TestUtils.java:42
static final Topology buildLinearTopo(int numSwitches)
static boolean CreateMininetTopology(String json)
list result
Definition: plan-d.py:72
static ITopology translateTopoEngTopo(ITopology expected)
Definition: TestUtils.java:116
static final Topology buildTreeTopo(int depth, int fanout)
static double getTimeDuration(final long current)
Definition: FlowUtils.java:605