16 package org.openkilda.wfm.topology.flow.validation;
18 import static java.lang.String.format;
23 import com.google.common.annotations.VisibleForTesting;
25 import java.util.Optional;
36 this.flowCache = flowCache;
47 checkFlowForEndpointConflicts(flow);
52 if (flow.getBandwidth() < 0) {
54 format(
"The flow '%s' has invalid bandwidth %d provided.",
56 flow.getBandwidth()));
67 void checkFlowForEndpointConflicts(Flow requestedFlow)
throws FlowValidationException {
69 Set<Flow> conflictsOnSource;
70 if (requestedFlow.getSourceVlan() == 0) {
72 requestedFlow.getSourceSwitch(),
73 requestedFlow.getSourcePort());
76 requestedFlow.getSourceSwitch(),
77 requestedFlow.getSourcePort(),
78 requestedFlow.getSourceVlan());
81 Optional<Flow> conflictedFlow = conflictsOnSource.stream()
82 .filter(flow -> !flow.getFlowId().equals(requestedFlow.getFlowId()))
84 if (conflictedFlow.isPresent()) {
85 throw new FlowValidationException(
86 format(
"The port %d on the switch '%s' has already occupied by the flow '%s'.",
87 requestedFlow.getSourcePort(),
88 requestedFlow.getSourceSwitch(),
89 conflictedFlow.get().getFlowId()));
93 Set<Flow> conflictsOnDest;
94 if (requestedFlow.getDestinationVlan() == 0) {
96 requestedFlow.getDestinationSwitch(),
97 requestedFlow.getDestinationPort());
100 requestedFlow.getDestinationSwitch(),
101 requestedFlow.getDestinationPort(),
102 requestedFlow.getDestinationVlan());
105 conflictedFlow = conflictsOnDest.stream()
106 .filter(flow -> !flow.getFlowId().equals(requestedFlow.getFlowId()))
108 if (conflictedFlow.isPresent()) {
109 throw new FlowValidationException(
110 format(
"The port %d on the switch '%s' has already occupied by the flow '%s'.",
111 requestedFlow.getDestinationPort(),
112 requestedFlow.getDestinationSwitch(),
113 conflictedFlow.get().getFlowId()));
Set< Flow > getFlowsForEndpoint(SwitchId switchId, int port)
FlowValidator(FlowCache flowCache)