16 package org.openkilda.messaging.model;
18 import static com.google.common.base.MoreObjects.toStringHelper;
24 import com.fasterxml.jackson.annotation.JsonCreator;
25 import com.fasterxml.jackson.annotation.JsonIgnore;
26 import com.fasterxml.jackson.annotation.JsonProperty;
27 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
29 import lombok.Builder;
33 import java.io.Serializable;
34 import java.util.Objects;
42 public class Flow implements Serializable {
46 private static final long serialVersionUID = 1L;
48 private static long MASK_COOKIE_FLAGS = 0x0000_0000_FFFF_FFFFL;
54 private String flowId;
59 @JsonProperty(
"bandwidth")
60 private long bandwidth;
65 @JsonProperty(
"ignore_bandwidth")
66 private boolean ignoreBandwidth;
71 @JsonProperty(
"cookie")
77 @JsonProperty(
"description")
78 private String description;
83 @JsonProperty(
"last_updated")
84 private String lastUpdated;
89 @JsonProperty(
"src_switch")
95 @JsonProperty(
"dst_switch")
101 @JsonProperty(
"src_port")
102 private int sourcePort;
107 @JsonProperty(
"dst_port")
108 private int destinationPort;
113 @JsonProperty(
"src_vlan")
114 private int sourceVlan;
119 @JsonProperty(
"dst_vlan")
120 private int destinationVlan;
125 @JsonProperty(
"meter_id")
131 @JsonProperty(
"transit_vlan")
132 private int transitVlan;
144 @JsonProperty(
"state")
159 this.flowId = flow.getFlowId();
160 this.bandwidth = flow.getBandwidth();
161 this.ignoreBandwidth = flow.isIgnoreBandwidth();
162 this.cookie = flow.getCookie();
163 this.description = flow.getDescription();
164 this.lastUpdated = flow.getLastUpdated();
165 this.sourceSwitch = flow.getSourceSwitch();
166 this.destinationSwitch = flow.getDestinationSwitch();
167 this.sourcePort = flow.getSourcePort();
168 this.destinationPort = flow.getDestinationPort();
169 this.sourceVlan = flow.getSourceVlan();
170 this.destinationVlan = flow.getDestinationVlan();
171 this.transitVlan = flow.getTransitVlan();
172 this.meterId = flow.getMeterId();
173 this.flowPath = flow.getFlowPath();
174 this.state = flow.getState();
200 @JsonProperty(
"bandwidth")
final long bandwidth,
201 @JsonProperty(
"ignore_bandwidth") Boolean ignoreBandwidth,
202 @JsonProperty(
"cookie")
final long cookie,
203 @JsonProperty(
"description")
final String description,
204 @JsonProperty(
"last_updated")
final String lastUpdated,
205 @JsonProperty(
"src_switch")
final SwitchId sourceSwitch,
206 @JsonProperty(
"dst_switch")
final SwitchId destinationSwitch,
207 @JsonProperty(
"src_port")
final int sourcePort,
208 @JsonProperty(
"dst_port")
final int destinationPort,
209 @JsonProperty(
"src_vlan")
final int sourceVlan,
210 @JsonProperty(
"dst_vlan")
final int destinationVlan,
211 @JsonProperty(
"meter_id")
final int meterId,
212 @JsonProperty(
"transit_vlan")
final int transitVlan,
214 @JsonProperty(
"state")
FlowState state) {
215 this.flowId = flowId;
216 this.bandwidth = bandwidth;
218 this.cookie = cookie;
219 this.description = description;
220 this.lastUpdated = lastUpdated;
221 this.sourceSwitch = sourceSwitch;
222 this.destinationSwitch = destinationSwitch;
223 this.sourcePort = sourcePort;
224 this.destinationPort = destinationPort;
225 this.sourceVlan = sourceVlan;
226 this.destinationVlan = destinationVlan;
227 this.transitVlan = transitVlan;
228 this.meterId = meterId;
229 this.flowPath = flowPath;
247 public Flow(String flowId,
long bandwidth,
boolean ignoreBandwidth, String description,
248 SwitchId sourceSwitch,
int sourcePort,
int sourceVlan,
249 SwitchId destinationSwitch,
int destinationPort,
int destinationVlan) {
250 this.flowId = flowId;
251 this.bandwidth = bandwidth;
252 this.ignoreBandwidth = ignoreBandwidth;
253 this.description = description;
254 this.sourceSwitch = sourceSwitch;
255 this.destinationSwitch = destinationSwitch;
256 this.sourcePort = sourcePort;
257 this.destinationPort = destinationPort;
258 this.sourceVlan = sourceVlan;
259 this.destinationVlan = destinationVlan;
268 if (ignoreBandwidth == null) {
269 ignoreBandwidth =
false;
271 this.ignoreBandwidth = ignoreBandwidth;
280 if (sourceSwitch == null || destinationSwitch == null) {
281 return sourceSwitch == null && destinationSwitch == null;
283 return sourceSwitch.
equals(destinationSwitch);
288 return cookie & MASK_COOKIE_FLAGS;
298 boolean isForward = cookieMarkedAsFroward();
299 boolean isReversed = cookieMarkedAsReversed();
302 throw new IllegalArgumentException(
303 "Invalid cookie flags combinations - it mark as forward and reverse flow at same time.");
314 private boolean cookieMarkedAsFroward() {
317 if ((cookie & 0xE000000000000000L) != 0) {
318 isMatch = (cookie & 0x4000000000000000L) != 0;
320 isMatch = (cookie & 0x0080000000000000L) == 0;
326 private boolean cookieMarkedAsReversed() {
328 if ((cookie & 0xE000000000000000L) != 0) {
329 isMatch = (cookie & 0x2000000000000000L) != 0;
331 isMatch = (cookie & 0x0080000000000000L) != 0;
343 return flowPath.
getPath().stream()
344 .anyMatch(
node ->
node.getSwitchId().equals(switchId));
352 if (
this ==
object) {
355 if (
object == null || getClass() !=
object.getClass()) {
360 return Objects.
equals(getFlowId(), flow.getFlowId())
361 && getBandwidth() == flow.getBandwidth()
362 && Objects.
equals(getDescription(), flow.getDescription())
363 && getState() == flow.getState()
364 && Objects.
equals(getSourceSwitch(), flow.getSourceSwitch())
365 && getSourcePort() == flow.getSourcePort()
366 && getSourceVlan() == flow.getSourceVlan()
367 && Objects.
equals(getDestinationSwitch(), flow.getDestinationSwitch())
368 && getDestinationPort() == flow.getDestinationPort()
369 && getDestinationVlan() == flow.getDestinationVlan();
377 return Objects.hash(flowId, bandwidth, description, state,
378 sourceSwitch, sourcePort, sourceVlan, destinationSwitch, destinationPort, destinationVlan);
386 return toStringHelper(
this)
388 .add(
"bandwidth", bandwidth)
389 .add(
"ignore_bandwidth", ignoreBandwidth)
390 .add(
"description", description)
392 .add(
"src_switch", sourceSwitch)
393 .add(
"src_port", sourcePort)
394 .add(
"src_vlan", sourceVlan)
395 .add(
"dst_switch", destinationSwitch)
396 .add(
"dst_port", destinationPort)
397 .add(
"dst_vlan", destinationVlan)
398 .add(
"cookie", cookie)
399 .add(
"transit_vlan", transitVlan)
400 .add(
"meter_id", meterId)
401 .add(
"last_updated", lastUpdated)
void setIgnoreBandwidth(Boolean ignoreBandwidth)
long getFlagglessCookie()
Flow(@JsonProperty(Utils.FLOW_ID) final String flowId, @JsonProperty("bandwidth") final long bandwidth, @JsonProperty("ignore_bandwidth") Boolean ignoreBandwidth, @JsonProperty("cookie") final long cookie, @JsonProperty("description") final String description, @JsonProperty("last_updated") final String lastUpdated, @JsonProperty("src_switch") final SwitchId sourceSwitch, @JsonProperty("dst_switch") final SwitchId destinationSwitch, @JsonProperty("src_port") final int sourcePort, @JsonProperty("dst_port") final int destinationPort, @JsonProperty("src_vlan") final int sourceVlan, @JsonProperty("dst_vlan") final int destinationVlan, @JsonProperty("meter_id") final int meterId, @JsonProperty("transit_vlan") final int transitVlan, @JsonProperty(Utils.FLOW_PATH) final PathInfoData flowPath, @JsonProperty("state") FlowState state)
Flow(String flowId, long bandwidth, boolean ignoreBandwidth, String description, SwitchId sourceSwitch, int sourcePort, int sourceVlan, SwitchId destinationSwitch, int destinationPort, int destinationVlan)
static final String FLOW_PATH
boolean containsSwitchInPath(SwitchId switchId)
List< PathNode > getPath()
boolean isOneSwitchFlow()
static final String FLOW_ID
boolean equals(Object object)