Open Kilda Java Documentation
IslInfoData.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.info.event;
17 
18 import com.fasterxml.jackson.annotation.JsonCreator;
19 import com.fasterxml.jackson.annotation.JsonIgnore;
20 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
21 import com.fasterxml.jackson.annotation.JsonInclude;
22 import com.fasterxml.jackson.annotation.JsonProperty;
23 import lombok.Data;
24 
25 import java.util.List;
26 import java.util.Objects;
27 
31 @Data
32 @JsonInclude(JsonInclude.Include.NON_NULL)
33 @JsonIgnoreProperties(ignoreUnknown = true)
34 public class IslInfoData extends PathInfoData {
38  private static final long serialVersionUID = 1L;
39 
43  @JsonProperty("id")
44  protected final String id;
45 
49  @JsonProperty("speed")
50  private final long speed;
51 
55  @JsonProperty("available_bandwidth")
56  private long availableBandwidth;
57 
61  @JsonProperty("state")
62  protected IslChangeType state;
63 
64  @JsonProperty("time_create")
65  private final Long timeCreateMillis;
66 
67  @JsonProperty("time_modify")
68  private final Long timeModifyMillis;
69 
75  public IslInfoData(IslInfoData that) {
76  this(
77  that.getLatency(),
78  that.getPath(),
79  that.getSpeed(),
80  that.getAvailableBandwidth(),
81  that.getState(),
82  that.getTimeCreateMillis(),
83  that.getTimeModifyMillis());
84  }
85 
91  public IslInfoData(List<PathNode> path, IslChangeType state) {
92  this(-1, path, 0, 0, state, null, null);
93  }
94 
95  public IslInfoData(long latency, List<PathNode> path, long speed, IslChangeType state, long availableBandwidth) {
96  this(latency, path, speed, availableBandwidth, state, null, null);
97  }
98 
99  @JsonCreator
100  public IslInfoData(@JsonProperty("latency_ns") long latency,
101  @JsonProperty("path") List<PathNode> path,
102  @JsonProperty("speed") long speed,
103  @JsonProperty("available_bandwidth") long availableBandwidth,
104  @JsonProperty("state") IslChangeType state,
105  @JsonProperty("time_create") Long timeCreateMillis,
106  @JsonProperty("time_modify") Long timeModifyMillis) {
107  super(latency, path);
108 
109  this.speed = speed;
110  this.availableBandwidth = availableBandwidth;
111  this.state = state;
112  this.timeCreateMillis = timeCreateMillis;
113  this.timeModifyMillis = timeModifyMillis;
114  this.id = String.format("%s_%d", path.get(0).getSwitchId(), path.get(0).getPortNo());
115  }
116 
122  public void setAvailableBandwidth(long availableBandwidth) {
123  this.availableBandwidth = availableBandwidth;
124  }
125 
131  public void setState(IslChangeType state) {
132  this.state = state;
133  }
134 
139  @JsonIgnore
140  public boolean isSelfLooped() {
141  PathNode source = this.getPath().get(0);
142  PathNode destination = this.getPath().get(1);
143  return Objects.equals(source.getSwitchId(), destination.getSwitchId());
144  }
145 
149  @Override
150  public int hashCode() {
151  return Objects.hash(latency, path, speed, availableBandwidth, state);
152  }
153 
157  @Override
158  public boolean equals(Object object) {
159  if (this == object) {
160  return true;
161  }
162  if (object == null || getClass() != object.getClass()) {
163  return false;
164  }
165 
166  IslInfoData that = (IslInfoData) object;
167  return Objects.equals(getLatency(), that.getLatency())
168  && Objects.equals(getPath(), that.getPath())
169  && Objects.equals(getSpeed(), that.getSpeed())
170  && Objects.equals(getAvailableBandwidth(), that.getAvailableBandwidth())
171  && Objects.equals(getState(), that.getState());
172  }
173 }
IslInfoData(long latency, List< PathNode > path, long speed, IslChangeType state, long availableBandwidth)
void setAvailableBandwidth(long availableBandwidth)
IslInfoData(@JsonProperty("latency_ns") long latency, @JsonProperty("path") List< PathNode > path, @JsonProperty("speed") long speed, @JsonProperty("available_bandwidth") long availableBandwidth, @JsonProperty("state") IslChangeType state, @JsonProperty("time_create") Long timeCreateMillis, @JsonProperty("time_modify") Long timeModifyMillis)
source
Definition: nodes.py:53
IslInfoData(List< PathNode > path, IslChangeType state)