16 package org.openkilda.atdd;
18 import static com.google.common.base.Charsets.UTF_8;
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertNotNull;
21 import static org.junit.Assert.assertTrue;
40 import com.spotify.docker.client.DefaultDockerClient;
41 import com.spotify.docker.client.DockerClient;
42 import com.spotify.docker.client.DockerClient.ListContainersParam;
43 import com.spotify.docker.client.messages.Container;
44 import cucumber.api.java.en.And;
45 import cucumber.api.java.en.Given;
46 import cucumber.api.java.en.Then;
47 import cucumber.api.java.en.When;
48 import org.apache.commons.collections4.CollectionUtils;
49 import org.apache.commons.io.IOUtils;
50 import org.apache.commons.lang.StringUtils;
51 import org.glassfish.jersey.client.ClientConfig;
54 import java.util.concurrent.TimeUnit;
55 import javax.ws.rs.client.Client;
56 import javax.ws.rs.client.ClientBuilder;
57 import javax.ws.rs.core.Response;
62 private static final String WFM_CONTAINER_NAME =
"/wfm";
64 private Container wfmContainer;
65 private DockerClient dockerClient;
71 dockerClient = DefaultDockerClient.fromEnv().build();
72 wfmContainer = dockerClient.listContainers(ListContainersParam.allContainers())
75 container.names().contains(WFM_CONTAINER_NAME))
76 .findFirst().orElseThrow(
77 () ->
new IllegalStateException(
"Can't find wfm container"));
84 @When(
"^storm topologies are restarted$")
87 System.out.println(
"\n=====> Recreate wfm container");
88 dockerClient.restartContainer(wfmContainer.id());
89 dockerClient.waitContainer(wfmContainer.id());
95 @Given(
"^active simple network topology with two switches and flow$")
102 String
topology = IOUtils.toString(this.getClass().getResourceAsStream(
103 "/topologies/simple-topology.json"), UTF_8);
110 10000,
false, flowId, null,
FlowState.
UP.getState());
113 for (
int i = 0;
i < 10; ++
i) {
115 if (response != null) {
118 TimeUnit.SECONDS.sleep(1);
121 assertNotNull(response);
122 response.setLastUpdated(null);
123 assertEquals(flowPayload, response);
126 assertTrue(trafficIsOk(
true));
135 @Then(
"^network topology in the same state$")
139 for (
int i = 0;
i < 6; ++
i) {
141 if (flowStatus != null &&
FlowState.
UP == flowStatus.getStatus()) {
144 TimeUnit.SECONDS.sleep(10);
147 assertNotNull(flowStatus);
148 assertEquals(
FlowState.
UP, flowStatus.getStatus());
155 @And(
"^all storm topologies in the same state$")
161 Set<ImmutablePair<Flow, Flow>> actualCacheBoltFlows = actualSateDumpsFromBolts
163 Set<ImmutablePair<Flow, Flow>> expectedCacheBoltFlows = expectedStateDumpsFromBolts
165 assertTrue(CollectionUtils.isEqualCollection(actualCacheBoltFlows, expectedCacheBoltFlows));
170 assertTrue(CollectionUtils.isEqualCollection(expectedOfeLinkBoltState.
getDiscovery(),
171 actualOfeLinkBoltState.getDiscovery()));
174 @And(
"^traffic flows through flow$")
176 assertTrue(trafficIsOk(
true));
179 private boolean trafficIsOk(
boolean expectedResult)
throws Throwable {
182 if (isTrafficTestsEnabled()) {
183 System.out.println(
"=====> Send traffic");
185 long current = System.currentTimeMillis();
186 Client client = ClientBuilder.newClient(
new ClientConfig());
188 .target(trafficEndpoint)
189 .path(
"/checkflowtraffic")
190 .queryParam(
"srcswitch",
"switch1")
191 .queryParam(
"dstswitch",
"switch2")
192 .queryParam(
"srcport",
"1")
193 .queryParam(
"dstport",
"1")
194 .queryParam(
"srcvlan",
"1000")
195 .queryParam(
"dstvlan",
"1000")
199 System.out.println(String.format(
"======> Response = %s",
result.toString()));
200 System.out.println(String.format(
"======> Send traffic Time: %,.3f", getTimeDuration(current)));
202 return result.getStatus() == 200;
204 return expectedResult;
void reloadStormTopologies()
Set< DiscoveryLink > getDiscovery()
static boolean isTrafficTestsEnabled()
OFELinkBoltState getOfeLinkBoltState()
void trafficFlowsThroughFlow()
Set< ImmutablePair< Flow, Flow > > getFlows()
static FlowIdStatusPayload getFlowStatus(final String flowId)
void allStormTopologiesInTheSameState()
static void cleanupFlows()
static final String trafficEndpoint
static boolean CreateMininetTopology(String json)
DumpStateManager getStateDumpsFromBolts()
static FlowPayload putFlow(final FlowPayload payload)
CacheBoltState getCacheBoltState()
void activeSimpleNetworkTopologyWithTwoSwitchesAndFlow()
static void clearEverything()
void networkTopologyInTheSameState()
static String getFlowName(final String flowId)
static double getTimeDuration(final long current)