Open Kilda Java Documentation
InstallTransitFlow.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 
24 
25 import com.fasterxml.jackson.annotation.JsonCreator;
26 import com.fasterxml.jackson.annotation.JsonInclude;
27 import com.fasterxml.jackson.annotation.JsonProperty;
28 import com.fasterxml.jackson.annotation.JsonPropertyOrder;
29 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
30 
31 import java.util.Objects;
32 
37 @JsonSerialize
38 @JsonInclude(JsonInclude.Include.NON_NULL)
39 @JsonPropertyOrder({
40  "command",
41  TRANSACTION_ID,
42  FLOW_ID,
43  "cookie",
44  "switch_id",
45  "input_port",
46  "output_port",
47  "transit_vlan_id"})
48 public class InstallTransitFlow extends BaseInstallFlow {
52  private static final long serialVersionUID = 1L;
53 
57  @JsonProperty("transit_vlan_id")
58  protected Integer transitVlanId;
59 
72  @JsonCreator
73  public InstallTransitFlow(@JsonProperty(TRANSACTION_ID) final Long transactionId,
74  @JsonProperty(FLOW_ID) final String id,
75  @JsonProperty("cookie") final Long cookie,
76  @JsonProperty("switch_id") final SwitchId switchId,
77  @JsonProperty("input_port") final Integer inputPort,
78  @JsonProperty("output_port") final Integer outputPort,
79  @JsonProperty("transit_vlan_id") final Integer transitVlanId) {
80  super(transactionId, id, cookie, switchId, inputPort, outputPort);
81  setTransitVlanId(transitVlanId);
82  }
83 
89  public Integer getTransitVlanId() {
90  return transitVlanId;
91  }
92 
98  public void setTransitVlanId(final Integer transitVlanId) {
99  if (transitVlanId == null) {
100  throw new IllegalArgumentException("need to set transit_vlan_id");
101  }
102  if (!Utils.validateVlanRange(transitVlanId) || transitVlanId == 0L) {
103  throw new IllegalArgumentException("need to set valid value for transit_vlan_id");
104  }
105  this.transitVlanId = transitVlanId;
106  }
107 
111  @Override
112  public String toString() {
113  return toStringHelper(this)
114  .add(TRANSACTION_ID, transactionId)
115  .add(FLOW_ID, id)
116  .add("cookie", cookie)
117  .add("switch_id", switchId)
118  .add("input_port", inputPort)
119  .add("output_port", outputPort)
120  .add("transit_vlan_id", transitVlanId)
121  .toString();
122  }
123 
127  @Override
128  public boolean equals(Object object) {
129  if (this == object) {
130  return true;
131  }
132  if (object == null || getClass() != object.getClass()) {
133  return false;
134  }
135 
136  InstallTransitFlow that = (InstallTransitFlow) object;
137  return Objects.equals(getTransactionId(), that.getTransactionId())
138  && Objects.equals(getId(), that.getId())
139  && Objects.equals(getCookie(), that.getCookie())
140  && Objects.equals(getSwitchId(), that.getSwitchId())
141  && Objects.equals(getInputPort(), that.getInputPort())
142  && Objects.equals(getOutputPort(), that.getOutputPort())
143  && Objects.equals(getTransitVlanId(), that.getTransitVlanId());
144  }
145 
149  @Override
150  public int hashCode() {
151  return Objects.hash(transactionId, id, cookie, switchId, inputPort, outputPort, transitVlanId);
152  }
153 }
static boolean validateVlanRange(final Integer vlanId)
Definition: Utils.java:108
static final String TRANSACTION_ID
Definition: Utils.java:39
static final String FLOW_ID
Definition: Utils.java:61