Open Kilda Java Documentation
InstallEgressFlow.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(value = {
43  "command",
44  TRANSACTION_ID,
45  FLOW_ID,
46  "cookie",
47  "switch_id",
48  "input_port",
49  "output_port",
50  "transit_vlan_id",
51  "output_vlan_id",
52  "output_vlan_type"})
53 public class InstallEgressFlow extends InstallTransitFlow {
57  private static final long serialVersionUID = 1L;
58 
62  @JsonProperty("output_vlan_type")
63  protected OutputVlanType outputVlanType;
64 
68  @JsonProperty("output_vlan_id")
69  protected Integer outputVlanId;
70 
85  @JsonCreator
86  public InstallEgressFlow(@JsonProperty(TRANSACTION_ID) final Long transactionId,
87  @JsonProperty(FLOW_ID) final String id,
88  @JsonProperty("cookie") final Long cookie,
89  @JsonProperty("switch_id") final SwitchId switchId,
90  @JsonProperty("input_port") final Integer inputPort,
91  @JsonProperty("output_port") final Integer outputPort,
92  @JsonProperty("transit_vlan_id") final Integer transitVlanId,
93  @JsonProperty("output_vlan_id") final Integer outputVlanId,
94  @JsonProperty("output_vlan_type") final OutputVlanType outputVlanType) {
95  super(transactionId, id, cookie, switchId, inputPort, outputPort, transitVlanId);
96  setOutputVlanId(outputVlanId);
97  setOutputVlanType(outputVlanType);
98  }
99 
106  return outputVlanType;
107  }
108 
114  public void setOutputVlanType(final OutputVlanType outputVlanType) {
115  if (outputVlanType == null) {
116  throw new IllegalArgumentException("need to set output_vlan_type");
117  } else if (!Utils.validateOutputVlanType(outputVlanId, outputVlanType)) {
118  throw new IllegalArgumentException("need to set valid values for output_vlan_id and output_vlan_type");
119  } else {
120  this.outputVlanType = outputVlanType;
121  }
122  }
123 
129  public Integer getOutputVlanId() {
130  return outputVlanId;
131  }
132 
138  public void setOutputVlanId(final Integer outputVlanId) {
139  if (outputVlanId == null) {
140  this.outputVlanId = 0;
141  } else if (Utils.validateVlanRange(outputVlanId)) {
142  this.outputVlanId = outputVlanId;
143  } else {
144  throw new IllegalArgumentException("need to set valid value for output_vlan_id");
145  }
146  }
147 
151  @Override
152  public String toString() {
153  return toStringHelper(this)
154  .add(TRANSACTION_ID, transactionId)
155  .add(FLOW_ID, id)
156  .add("cookie", cookie)
157  .add("switch_id", switchId)
158  .add("input_port", inputPort)
159  .add("output_port", outputPort)
160  .add("transit_vlan_id", transitVlanId)
161  .add("output_vlan_id", outputVlanId)
162  .add("output_vlan_type", outputVlanType)
163  .toString();
164  }
165 
169  @Override
170  public boolean equals(Object object) {
171  if (this == object) {
172  return true;
173  }
174  if (object == null || getClass() != object.getClass()) {
175  return false;
176  }
177 
178  InstallEgressFlow that = (InstallEgressFlow) object;
179  return Objects.equals(getTransactionId(), that.getTransactionId())
180  && Objects.equals(getId(), that.getId())
181  && Objects.equals(getCookie(), that.getCookie())
182  && Objects.equals(getSwitchId(), that.getSwitchId())
183  && Objects.equals(getInputPort(), that.getInputPort())
184  && Objects.equals(getOutputPort(), that.getOutputPort())
185  && Objects.equals(getTransitVlanId(), that.getTransitVlanId())
186  && Objects.equals(getOutputVlanId(), that.getOutputVlanId())
187  && Objects.equals(getOutputVlanType(), that.getOutputVlanType());
188  }
189 
193  @Override
194  public int hashCode() {
195  return Objects.hash(transactionId, id, cookie, switchId, inputPort, outputPort,
196  transitVlanId, outputVlanType, outputVlanId);
197  }
198 }
static boolean validateVlanRange(final Integer vlanId)
Definition: Utils.java:108
value
Definition: nodes.py:62
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