Open Kilda Java Documentation
InstallIngressFlow.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 
41 @JsonSerialize
42 @JsonInclude(JsonInclude.Include.NON_NULL)
43 @JsonPropertyOrder({
44  "command",
45  TRANSACTION_ID,
46  FLOW_ID,
47  "cookie",
48  "switch_id",
49  "input_port",
50  "output_port",
51  "input_vlan_id",
52  "transit_vlan_id",
53  "output_vlan_type",
54  "bandwidth",
55  "meter_id"})
56 public class InstallIngressFlow extends InstallTransitFlow {
60  private static final long serialVersionUID = 1L;
61 
65  @JsonProperty("bandwidth")
66  protected Long bandwidth;
67 
71  @JsonProperty("input_vlan_id")
72  protected Integer inputVlanId;
73 
77  @JsonProperty("output_vlan_type")
78  protected OutputVlanType outputVlanType;
79 
83  @JsonProperty("meter_id")
84  protected Long meterId;
85 
102  @JsonCreator
103  public InstallIngressFlow(@JsonProperty(TRANSACTION_ID) final Long transactionId,
104  @JsonProperty(FLOW_ID) final String id,
105  @JsonProperty("cookie") final Long cookie,
106  @JsonProperty("switch_id") final SwitchId switchId,
107  @JsonProperty("input_port") final Integer inputPort,
108  @JsonProperty("output_port") final Integer outputPort,
109  @JsonProperty("input_vlan_id") final Integer inputVlanId,
110  @JsonProperty("transit_vlan_id") final Integer transitVlanId,
111  @JsonProperty("output_vlan_type") final OutputVlanType outputVlanType,
112  @JsonProperty("bandwidth") final Long bandwidth,
113  @JsonProperty("meter_id") final Long meterId) {
114  super(transactionId, id, cookie, switchId, inputPort, outputPort, transitVlanId);
115  setInputVlanId(inputVlanId);
116  setOutputVlanType(outputVlanType);
117  setBandwidth(bandwidth);
118  setMeterId(meterId);
119  }
120 
127  return outputVlanType;
128  }
129 
135  public void setOutputVlanType(final OutputVlanType outputVlanType) {
136  if (outputVlanType == null) {
137  throw new IllegalArgumentException("need to set output_vlan_type");
138  } else if (!Utils.validateInputVlanType(inputVlanId, outputVlanType)) {
139  throw new IllegalArgumentException("need to set valid values for input_vlan_id and output_vlan_type");
140  } else {
141  this.outputVlanType = outputVlanType;
142  }
143  }
144 
150  public Long getBandwidth() {
151  return bandwidth;
152  }
153 
159  public void setBandwidth(final Long bandwidth) {
160  if (bandwidth == null) {
161  throw new IllegalArgumentException("need to set bandwidth");
162  } else if (bandwidth < 0L) {
163  throw new IllegalArgumentException("need to set non negative bandwidth");
164  }
165  this.bandwidth = bandwidth;
166  }
167 
173  public Integer getInputVlanId() {
174  return inputVlanId;
175  }
176 
182  public void setInputVlanId(final Integer inputVlanId) {
183  if (inputVlanId == null) {
184  this.inputVlanId = 0;
185  } else if (Utils.validateVlanRange(inputVlanId)) {
186  this.inputVlanId = inputVlanId;
187  } else {
188  throw new IllegalArgumentException("need to set valid value for input_vlan_id");
189  }
190  }
191 
197  public Long getMeterId() {
198  return meterId;
199  }
200 
206  public void setMeterId(final Long meterId) {
207  if (meterId == null) {
208  throw new IllegalArgumentException("need to set meter_id");
209  } else if (meterId < 0L) {
210  throw new IllegalArgumentException("need to set non negative meter_id");
211  }
212  this.meterId = meterId;
213  }
214 
218  @Override
219  public String toString() {
220  return toStringHelper(this)
221  .add(TRANSACTION_ID, transactionId)
222  .add(FLOW_ID, id)
223  .add("cookie", cookie)
224  .add("switch_id", switchId)
225  .add("input_port", inputPort)
226  .add("output_port", outputPort)
227  .add("input_vlan_id", inputVlanId)
228  .add("transit_vlan_id", transitVlanId)
229  .add("output_vlan_type", outputVlanType)
230  .add("bandwidth", bandwidth)
231  .add("meter_id", meterId)
232  .toString();
233  }
234 
238  @Override
239  public boolean equals(Object object) {
240  if (this == object) {
241  return true;
242  }
243  if (object == null || getClass() != object.getClass()) {
244  return false;
245  }
246 
247  InstallIngressFlow that = (InstallIngressFlow) object;
248  return Objects.equals(getTransactionId(), that.getTransactionId())
249  && Objects.equals(getId(), that.getId())
250  && Objects.equals(getCookie(), that.getCookie())
251  && Objects.equals(getSwitchId(), that.getSwitchId())
252  && Objects.equals(getInputPort(), that.getInputPort())
253  && Objects.equals(getOutputPort(), that.getOutputPort())
254  && Objects.equals(getInputVlanId(), that.getInputVlanId())
255  && Objects.equals(getOutputPort(), that.getOutputPort())
256  && Objects.equals(getOutputVlanType(), that.getOutputVlanType())
257  && Objects.equals(getBandwidth(), that.getBandwidth())
258  && Objects.equals(getMeterId(), that.getMeterId());
259  }
260 
264  @Override
265  public int hashCode() {
266  return Objects.hash(transactionId, id, cookie, switchId, inputPort, outputPort,
267  inputVlanId, transitVlanId, outputVlanType, bandwidth, meterId);
268  }
269 }
static boolean validateVlanRange(final Integer vlanId)
Definition: Utils.java:108
static final String TRANSACTION_ID
Definition: Utils.java:39
void setOutputVlanType(final OutputVlanType outputVlanType)
static final String FLOW_ID
Definition: Utils.java:61
static boolean validateInputVlanType(final Integer inputVlanId, final OutputVlanType outputVlanType)
Definition: Utils.java:132