Open Kilda Java Documentation
InstallOneSwitchFlow.java
Go to the documentation of this file.
1 /* Copyright 2017 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.messaging.command.flow;
17 
18 import static com.google.common.base.MoreObjects.toStringHelper;
19 import static org.openkilda.messaging.Utils.FLOW_ID;
21 
25 
26 import com.fasterxml.jackson.annotation.JsonCreator;
27 import com.fasterxml.jackson.annotation.JsonInclude;
28 import com.fasterxml.jackson.annotation.JsonProperty;
29 import com.fasterxml.jackson.annotation.JsonPropertyOrder;
30 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
31 
32 import java.util.Objects;
33 
40 @JsonSerialize
41 @JsonInclude(JsonInclude.Include.NON_NULL)
42 @JsonPropertyOrder({
43  TRANSACTION_ID,
44  FLOW_ID,
45  "cookie",
46  "switch_id",
47  "input_port",
48  "output_port",
49  "input_vlan_id",
50  "output_vlan_id",
51  "output_vlan_type",
52  "bandwidth",
53  "meter_id"})
54 public class InstallOneSwitchFlow extends BaseInstallFlow {
58  private static final long serialVersionUID = 1L;
59 
63  @JsonProperty("meter_id")
64  protected Long meterId;
65 
69  @JsonProperty("bandwidth")
70  private Long bandwidth;
71 
75  @JsonProperty("output_vlan_type")
76  private OutputVlanType outputVlanType;
77 
81  @JsonProperty("input_vlan_id")
82  private Integer inputVlanId;
83 
87  @JsonProperty("output_vlan_id")
88  private Integer outputVlanId;
89 
106  @JsonCreator
107  public InstallOneSwitchFlow(@JsonProperty(TRANSACTION_ID) final Long transactionId,
108  @JsonProperty(FLOW_ID) final String id,
109  @JsonProperty("cookie") final Long cookie,
110  @JsonProperty("switch_id") final SwitchId switchId,
111  @JsonProperty("input_port") final Integer inputPort,
112  @JsonProperty("output_port") final Integer outputPort,
113  @JsonProperty("input_vlan_id") final Integer inputVlanId,
114  @JsonProperty("output_vlan_id") final Integer outputVlanId,
115  @JsonProperty("output_vlan_type") final OutputVlanType outputVlanType,
116  @JsonProperty("bandwidth") final Long bandwidth,
117  @JsonProperty("meter_id") final Long meterId) {
118  super(transactionId, id, cookie, switchId, inputPort, outputPort);
119  setInputVlanId(inputVlanId);
120  setOutputVlanId(outputVlanId);
121  setOutputVlanType(outputVlanType);
122  setBandwidth(bandwidth);
123  setMeterId(meterId);
124  }
125 
131  public Long getBandwidth() {
132  return bandwidth;
133  }
134 
140  public void setBandwidth(final Long bandwidth) {
141  if (bandwidth == null) {
142  throw new IllegalArgumentException("need to set bandwidth");
143  } else if (bandwidth < 0L) {
144  throw new IllegalArgumentException("need to set non negative bandwidth");
145  }
146  this.bandwidth = bandwidth;
147  }
148 
155  return outputVlanType;
156  }
157 
163  public void setOutputVlanType(final OutputVlanType outputVlanType) {
164  if (outputVlanType == null) {
165  throw new IllegalArgumentException("need to set output_vlan_type");
166  } else if (!Utils.validateOutputVlanType(outputVlanId, outputVlanType)) {
167  throw new IllegalArgumentException("need to set valid values for output_vlan_id and output_vlan_type");
168  } else {
169  this.outputVlanType = outputVlanType;
170  }
171  }
172 
178  public Integer getInputVlanId() {
179  return inputVlanId;
180  }
181 
187  public void setInputVlanId(final Integer inputVlanId) {
188  if (inputVlanId == null) {
189  this.inputVlanId = 0;
190  } else if (Utils.validateVlanRange(inputVlanId)) {
191  this.inputVlanId = inputVlanId;
192  } else {
193  throw new IllegalArgumentException("need to set valid value for input_vlan_id");
194  }
195  }
196 
202  public Integer getOutputVlanId() {
203  return outputVlanId;
204  }
205 
211  public void setOutputVlanId(final Integer outputVlanId) {
212  if (outputVlanId == null) {
213  this.outputVlanId = 0;
214  } else if (Utils.validateVlanRange(outputVlanId)) {
215  this.outputVlanId = outputVlanId;
216  } else {
217  throw new IllegalArgumentException("need to set valid value for output_vlan_id");
218  }
219  }
220 
226  public Long getMeterId() {
227  return meterId;
228  }
229 
235  public void setMeterId(final Long meterId) {
236  if (meterId == null) {
237  throw new IllegalArgumentException("need to set meterId");
238  } else if (meterId < 0) {
239  throw new IllegalArgumentException("need to set non negative meterId");
240  }
241  this.meterId = meterId;
242  }
243 
247  @Override
248  public String toString() {
249  return toStringHelper(this)
250  .add(TRANSACTION_ID, transactionId)
251  .add(FLOW_ID, id)
252  .add("cookie", cookie)
253  .add("switch_id", switchId)
254  .add("input_port", inputPort)
255  .add("output_port", outputPort)
256  .add("input_vlan_id", inputVlanId)
257  .add("output_vlan_id", outputVlanId)
258  .add("output_vlan_type", outputVlanType)
259  .add("bandwidth", bandwidth)
260  .add("meter_id", meterId)
261  .toString();
262  }
263 
267  @Override
268  public boolean equals(Object object) {
269  if (this == object) {
270  return true;
271  }
272  if (object == null || getClass() != object.getClass()) {
273  return false;
274  }
275 
277  return Objects.equals(getTransactionId(), that.getTransactionId())
278  && Objects.equals(getId(), that.getId())
279  && Objects.equals(getCookie(), that.getCookie())
280  && Objects.equals(getSwitchId(), that.getSwitchId())
281  && Objects.equals(getInputPort(), that.getInputPort())
282  && Objects.equals(getOutputPort(), that.getOutputPort())
283  && Objects.equals(getInputVlanId(), that.getInputVlanId())
284  && Objects.equals(getOutputVlanId(), that.getOutputVlanId())
285  && Objects.equals(getOutputVlanType(), that.getOutputVlanType())
286  && Objects.equals(getBandwidth(), that.getBandwidth())
287  && Objects.equals(getMeterId(), that.getMeterId());
288  }
289 
293  @Override
294  public int hashCode() {
295  return Objects.hash(transactionId, id, cookie, switchId, inputPort, outputPort,
296  inputVlanId, outputVlanId, outputVlanType, bandwidth, meterId);
297  }
298 }
static boolean validateVlanRange(final Integer vlanId)
Definition: Utils.java:108
void setOutputVlanType(final OutputVlanType outputVlanType)
static final String TRANSACTION_ID
Definition: Utils.java:39
static boolean validateOutputVlanType(final Integer outputVlanId, final OutputVlanType outputVlanType)
Definition: Utils.java:119
static final String FLOW_ID
Definition: Utils.java:61