16 package org.openkilda.atdd;
18 import static org.hamcrest.Matchers.empty;
19 import static org.hamcrest.Matchers.hasItems;
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertNotNull;
22 import static org.junit.Assert.assertThat;
23 import static org.junit.Assert.assertTrue;
40 import cucumber.api.java.en.Given;
41 import cucumber.api.java.en.Then;
42 import cucumber.api.java.en.When;
44 import java.util.Arrays;
45 import java.util.List;
46 import java.util.stream.Collectors;
50 private static final List<PathNodePayload> expectedForwardFlowPath = Arrays.asList(
54 private static final List<PathNodePayload> expectedReverseFlowPath = Arrays.asList(
59 @Then(
"^path of flow (\\w+) could be read$")
64 assertNotNull(payload);
66 assertEquals(flowName, payload.getId());
67 assertEquals(expectedForwardFlowPath, payload.getForwardPath());
68 assertEquals(expectedReverseFlowPath, payload.getReversePath());
71 @Then(
"^status of flow (\\w+) could be read$")
76 assertNotNull(payload);
78 assertEquals(flowName, payload.getId());
79 assertEquals(expectedFlowStatus, payload.getStatus());
82 @Then(
"^flows dump contains (\\d+) flows$")
86 flows.forEach(flow -> System.out.println(flow.getId()));
87 assertEquals(flowCount, flows.size());
90 @Given(
"^health check$")
92 assertEquals(200, getHealthCheck());
95 @Then(
"^flow (\\w+) in (\\w+) state$")
96 public
void flowState(String flowId, String state) throws Throwable {
100 assertNotNull(payload);
101 assertEquals(flowName, payload.getId());
102 assertEquals(
flowState, payload.getStatus());
105 @Then(
"^delete all non-default rules request on ([\\w:]+) switch is successful with (\\d+) rules deleted$")
108 assertNotNull(cookies);
109 assertEquals(deletedFlowsCount, cookies.size());
110 cookies.forEach(cookie -> System.out.println(cookie));
113 @Then(
"^delete all rules request on (.*) switch is successful with (\\d+) rules deleted$")
116 assertNotNull(cookies);
117 assertEquals(deletedFlowsCount, cookies.size());
118 cookies.forEach(cookie -> System.out.println(cookie));
121 @Then(
"^delete rules request by (\\d+) in-port on (.*) switch is successful with (\\d+) rules deleted$")
124 assertNotNull(cookies);
125 assertEquals(deletedFlowsCount, cookies.size());
126 cookies.forEach(cookie -> System.out.println(cookie));
129 @Then(
"^delete rules request by (\\d+) in-port and (\\d+) " 130 +
"in-vlan on (.*) switch is successful with (\\d+) rules deleted$")
133 assertNotNull(cookies);
134 assertEquals(deletedFlowsCount, cookies.size());
135 cookies.forEach(cookie -> System.out.println(cookie));
138 @Then(
"^delete rules request by (\\d+) in-vlan on (.*) switch is successful with (\\d+) rules deleted$")
141 assertNotNull(cookies);
142 assertEquals(deletedFlowsCount, cookies.size());
143 cookies.forEach(cookie -> System.out.println(cookie));
146 @Then(
"^delete rules request by (\\d+) out-port on (.*) switch is successful with (\\d+) rules deleted$")
149 assertNotNull(cookies);
150 assertEquals(deletedFlowsCount, cookies.size());
151 cookies.forEach(cookie -> System.out.println(cookie));
154 @Then(
"^synchronize flow cache is successful with (\\d+) dropped flows$")
157 assertNotNull(results);
158 assertEquals(droppedFlowsCount, results.getDroppedFlows().size());
161 @Then(
"^invalidate flow cache is successful with (\\d+) dropped flows$")
164 assertNotNull(results);
165 assertEquals(droppedFlowsCount, results.getDroppedFlows().size());
168 @When(
"^flow (\\w+) could be deleted from DB$")
176 @Then(
"^validation of rules on ([\\w:]+) switch is successful with no discrepancies$")
180 assertNotNull(validateResult);
181 assertThat(
"The switch has excessive rules.", validateResult.getExcessRules(), empty());
182 assertThat(
"The switch has missing rules.", validateResult.getMissingRules(), empty());
185 @Then(
"^validation of rules on ([\\w:]+) switch has passed and (\\d+) rules are missing$")
189 assertNotNull(validateResult);
190 assertEquals(
"Switch doesn't have expected missing rules.", missingRulesCount,
191 validateResult.getMissingRules().size());
192 assertThat(
"The switch has excessive rules.", validateResult.getExcessRules(), empty());
195 @Then(
"^validation of rules on ([\\w:]+) switch has passed and (\\d+) excessive rules are present$")
199 assertNotNull(validateResult);
200 assertEquals(
"Switch doesn't have expected excessive rules.", excessiveRulesCount,
201 validateResult.getExcessRules().size());
202 assertThat(
"The switch has missing rules.", validateResult.getMissingRules(), empty());
205 @Then(
"^synchronization of rules on ([\\w:]+) switch is successful with (\\d+) rules installed$")
209 assertNotNull(validateResult);
210 assertEquals(
"Switch doesn't have expected installed rules.", installedRulesCount,
211 validateResult.getInstalledRules().size());
214 @Then(
"^([\\w,]+) rules are installed on ([\\w:]+) switch$")
217 assertNotNull(actualRules);
218 List<String> actualRuleCookies = actualRules.stream()
219 .map(entry -> Long.toHexString(entry.getCookie()))
220 .collect(Collectors.toList());
222 assertThat(
"Switch doesn't contain expected rules.", actualRuleCookies, hasItems(ruleCookies.split(
",")));
225 @Then(
"No rules installed on ([\\w:]+) switch$")
229 assertNotNull(actualRules);
230 assertTrue(
"Switch contains rules, but expect to have none.", actualRules.isEmpty());
void flowState(String flowId, String state)
void checkThatRulesAreInstalled(String ruleCookies, String switchId)
static boolean deleteFlowViaTe(final String flowId)
void deleteFlowFromDbViaTe(final String flowName)
static List< FlowPayload > getFlowDump()
void validateSwitchRules(String switchId)
void checkThatNoRulesAreInstalled(String switchId)
void deleteRulesByInPortVlan(int inPort, int inVlan, String switchId, int deletedFlowsCount)
void synchronizeSwitchWithInstalledRules(String switchId, int installedRulesCount)
void validateSwitchWithExcessiveRules(String switchId, int excessiveRulesCount)
void invalidateFlowCache(final int droppedFlowsCount)
void synchronizeFlowCache(final int droppedFlowsCount)
void checkFlowStatus(final String flowId)
void deleteRulesByInPort(int inPort, String switchId, int deletedFlowsCount)
void checkFlowPath(final String flowId)
static List< FlowEntry > dumpSwitchRules(String switchId)
static FlowPathPayload getFlowPath(final String flowId)
void validateSwitchWithMissingRules(String switchId, int missingRulesCount)
static List< Long > deleteSwitchRules(String switchId, DeleteRulesAction deleteAction)
static FlowCacheSyncResults invalidateFlowCache()
void deleteAllNonDefaultRules(String switchId, int deletedFlowsCount)
void deleteRulesByInVlan(int inVlan, String switchId, int deletedFlowsCount)
static int getHealthCheck()
static FlowCacheSyncResults syncFlowCache()
static RulesSyncResult synchronizeSwitchRules(String switchId)
void checkDumpFlows(final int flowCount)
static FlowIdStatusPayload waitFlowStatus(String flowName, FlowState expected)
static String getFlowName(final String flowId)
void deleteAllDefaultRules(String switchId, int deletedFlowsCount)
void deleteRulesByOutPort(int outPort, String switchId, int deletedFlowsCount)
static RulesValidationResult validateSwitchRules(String switchId)