Open Kilda Java Documentation
FlowEndpointPayload.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.payload.flow;
17 
21 
22 import com.fasterxml.jackson.annotation.JsonCreator;
23 import com.fasterxml.jackson.annotation.JsonInclude;
24 import com.fasterxml.jackson.annotation.JsonProperty;
25 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
26 import com.google.common.base.MoreObjects;
27 import org.apache.commons.lang3.builder.EqualsBuilder;
28 
29 import java.util.Objects;
30 
36 @JsonSerialize
37 @JsonInclude(JsonInclude.Include.NON_NULL)
38 public class FlowEndpointPayload extends NetworkEndpoint {
42  private static final long serialVersionUID = 1L;
43 
47  @JsonProperty("vlan-id")
48  private Integer vlanId;
49 
57  @JsonCreator
58  public FlowEndpointPayload(@JsonProperty("switch-id") SwitchId switchId,
59  @JsonProperty("port-id") Integer portId,
60  @JsonProperty("vlan-id") Integer vlanId) {
61  super(switchId, portId);
62  setVlanId(vlanId);
63  }
64 
70  public Integer getVlanId() {
71  return vlanId;
72  }
73 
79  public void setVlanId(Integer vlanId) {
80  if (vlanId == null) {
81  this.vlanId = 0;
82  } else if (Utils.validateVlanRange(vlanId)) {
83  this.vlanId = vlanId;
84  } else {
85  throw new IllegalArgumentException("need to set valid value for vlan id");
86  }
87  }
88 
92  @Override
93  public boolean equals(Object obj) {
94  if (this == obj) {
95  return true;
96  }
97  if (obj == null || getClass() != obj.getClass()) {
98  return false;
99  }
101  return new EqualsBuilder()
102  .appendSuper(super.equals(obj))
103  .append(vlanId, that.vlanId)
104  .isEquals();
105  }
106 
110  @Override
111  public int hashCode() {
112  return Objects.hash(getSwitchDpId(), getPortId(), vlanId);
113  }
114 
118  @Override
119  public String toString() {
120  return MoreObjects.toStringHelper(this)
121  .add("switch-id", getSwitchDpId())
122  .add("port-id", getPortId())
123  .add("vlan-id", vlanId)
124  .toString();
125  }
126 }
static boolean validateVlanRange(final Integer vlanId)
Definition: Utils.java:108
FlowEndpointPayload(@JsonProperty("switch-id") SwitchId switchId, @JsonProperty("port-id") Integer portId, @JsonProperty("vlan-id") Integer vlanId)