16 package org.openkilda.atdd.staging.helpers;
26 import cucumber.api.Scenario;
27 import org.apache.commons.lang3.StringUtils;
29 import java.util.Objects;
32 private static final String VERSION_12 =
"OF_12";
33 private static final String BROADCAST_FLOW =
"flow-0x8000000000000002";
34 private static final String DROP_FLOW =
"flow-0x8000000000000001";
35 private static final String NON_BROADCAST_FLOW =
"flow-0x8000000000000003";
36 private static final String VERIFICATION_DST =
"08:ed:02:ef:ff:ff";
38 private static final String CONTROLLER_OUTPUT =
"controller";
39 private static final int DPID_LENGTH = 23;
46 boolean result = isValidDefaultFlow(BROADCAST_FLOW, flow, sw.getSwitchId(), scenario);
48 if (!VERSION_12.equals(sw.getOfVersion())) {
50 map.get(NON_BROADCAST_FLOW), sw.getSwitchId(), scenario);
51 result =
result & isValidDropRule(map.get(DROP_FLOW), sw.getSwitchId(), scenario);
57 private static boolean isValidDropRule(
FlowEntry flow,
SwitchId switchId, Scenario scenario) {
59 if (Objects.isNull(flow)) {
60 scenario.write(String.format(
"Switch %s doesn't contain %s flow", switchId, DROP_FLOW));
64 if (flow.getPriority() != 1) {
65 scenario.write(String.format(
"Switch %s has incorrect priority for flow %s", switchId, flow.getCookie()));
69 FlowInstructions instructions = flow.getInstructions();
70 if (Objects.nonNull(instructions.getApplyActions())) {
71 scenario.write(String.format(
"Switch %s has incorrect instructions for flow %s",
72 switchId, flow.getCookie()));
79 private static boolean isValidDefaultFlow(String flowId, FlowEntry flow, SwitchId switchId, Scenario scenario) {
81 if (Objects.isNull(flow)) {
82 scenario.write(String.format(
"Switch %s doesn't contain %s flow", switchId, flowId));
86 FlowInstructions instructions = flow.getInstructions();
87 FlowApplyActions flowActions = instructions.getApplyActions();
88 if (!isValidSetFieldProperty(flowActions.getField(), switchId)) {
89 scenario.write(String.format(
"Switch %s has incorrect set field action for flow %s",
90 switchId, flow.getCookie()));
94 String flowOutput = flowActions.getFlowOutput();
95 if (!CONTROLLER_OUTPUT.equals(flowOutput)) {
96 scenario.write(String.format(
"Switch %s has incorrect output action name for flow %s", switchId,
101 FlowMatchField flowMatch = flow.getMatch();
102 if (BROADCAST_FLOW.equals(flow.getCookie())) {
103 if (!VERIFICATION_DST.equals(flowMatch.getEthDst())) {
104 scenario.write(String.format(
"Switch %s has incorrect verification broadcast packets destination",
108 }
else if (NON_BROADCAST_FLOW.equals(flow.getCookie())) {
109 if (!switchId.toMacAddress().equals(flowMatch.getEthDst())) {
110 scenario.write(String.format(
"Switch %s contains incorrect eth_dst: %s",
111 switchId, flowMatch.getEthDst()));
118 private static boolean isValidSetFieldProperty(String
value, SwitchId switchId) {
119 return StringUtils.startsWith(
value, switchId.toMacAddress());
122 private DefaultFlowsChecker() {
static boolean validateDefaultRules(SwitchEntry sw, FlowEntriesMap map, Scenario scenario)