Open Kilda Java Documentation
ClearTablesTest.java
Go to the documentation of this file.
1 package org.openkilda.atdd.floodlight;
2 
3 import static com.google.common.base.Charsets.UTF_8;
4 import static org.junit.Assert.assertTrue;
5 
14 
15 import cucumber.api.java.en.Given;
16 import cucumber.api.java.en.Then;
17 import cucumber.api.java.en.When;
18 import org.apache.commons.io.IOUtils;
19 import org.junit.Assert;
20 
21 import java.util.List;
22 import javax.ws.rs.ProcessingException;
23 
24 public class ClearTablesTest {
25  private static final String SWITCH_DPID = "00:01:00:00:00:00:00:01";
26  private static final String ETHERNET_DEST_ADDRESS = "01:23:45:67:89:0a";
27 
28  private final ControllerUtils controllerUtils;
29 
30  public ClearTablesTest() throws Exception {
31  controllerUtils = new ControllerUtils();
32  }
33 
34  @Given("^started floodlight container")
35  public void givenStartedContainer() throws Exception {
37  }
38 
39  @Given("^created simple topology from two switches")
40  public void createTopology() throws Exception {
41  String topology =
42  IOUtils.toString(this.getClass().getResourceAsStream("/topologies/simple-topology.json"), UTF_8);
44  }
45 
46  @Given("^added custom flow rules")
47  public void addRules() throws Exception {
48  StaticFlowEntry flow = new StaticFlowEntry("reboot-survive-flow", SWITCH_DPID)
49  .withCookie(0xf0000001L)
50  .withInPort("1")
51  .withEthDest(ETHERNET_DEST_ADDRESS)
52  .withAction("drop");
53  controllerUtils.addStaticFlow(flow);
54  }
55 
56  @When("^floodlight controller is restarted")
57  public void restartFloodlight() throws Exception {
58  controllerUtils.restart();
59  }
60 
61  @Then("^flow rules should not be cleared up")
63  DpIdEntriesList staticEntries = controllerUtils.listStaticEntries();
64 
65  // All rules(static) must be dropped during controller restart
66  Assert.assertEquals(staticEntries.size(), 0);
67 
68  // It is possible that controllerUtils.listCoreFlows call is done before switch is connected to FloodLight. In
69  // this case we will catch DpIdNotFoundException. So we had to make several attempts to get the list of flows
70  // from target switch.
71  int i = 0;
72  List<CoreFlowEntry> flows = null;
73  while (i++ < 5) {
74  try {
75  flows = controllerUtils.listCoreFlows(SWITCH_DPID);
76  break;
77  } catch (DpIdNotFoundException e) {
78  try {
79  Thread.sleep(500);
80  } catch (InterruptedException ignored) { }
81  }
82  }
83  if (flows == null) {
84  throw new ProcessingException("Can't reads flows list from FloodLight");
85  }
86 
87  boolean isFlowSurvived = false;
88  for (CoreFlowEntry entry : flows) {
89  if (!entry.match.ethDest.equals(ETHERNET_DEST_ADDRESS)) {
90  continue;
91  }
92 
93  isFlowSurvived = true;
94  break;
95  }
96 
97  assertTrue("The test flow didn't survive controller reboot", isFlowSurvived);
98  }
99 }
StaticFlowEntry withEthDest(String ethDest)
List< CoreFlowEntry > listCoreFlows(String dpId)
StaticFlowEntry withAction(String action)
StaticFlowEntry withCookie(Long cookie)
static boolean CreateMininetTopology(String json)
StaticFlowEntry withInPort(String inPort)