Open Kilda Java Documentation
DiscoveryNode.java
Go to the documentation of this file.
1 package org.openkilda.messaging.model;
2 
3 import com.fasterxml.jackson.annotation.JsonCreator;
4 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
5 import com.fasterxml.jackson.annotation.JsonInclude;
6 import com.fasterxml.jackson.annotation.JsonProperty;
7 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
8 
9 import java.io.Serializable;
10 import java.util.Objects;
11 
12 @JsonSerialize
13 @JsonIgnoreProperties(ignoreUnknown = true)
14 @JsonInclude(JsonInclude.Include.NON_NULL)
15 public class DiscoveryNode implements Serializable {
16 
18  public final static int FORLORN_NEVER = -1;
19 
20  @JsonProperty("switch_id")
21  private final String switchId;
22 
23  @JsonProperty("port_id")
24  private final String portId;
25 
27  @JsonProperty("attempts")
28  private int attempts;
29 
30  @JsonProperty("time_counter")
31  private int timeCounter;
32 
33  @JsonProperty("check_interval")
34  private int checkInterval;
35 
37  @JsonProperty("consecutive_failure")
38  private int consecutiveFailure;
39 
40  @JsonProperty("consecutive_success")
41  private int consecutiveSuccess;
42 
43  @JsonProperty("forlorn_threshold")
44  private int forlornThreshold;
62  @JsonProperty("found_isl")
63  private boolean foundIsl;
64 
70  public DiscoveryNode(String switchId, String portId, int checkInterval, int forlornThreshold) {
71  this.switchId = switchId;
72  this.portId = portId;
73  this.timeCounter = 0;
74  this.checkInterval = checkInterval;
75  this.forlornThreshold = forlornThreshold;
76  this.consecutiveFailure = 0;
77  this.consecutiveSuccess = 0;
78  this.foundIsl = false;
79  }
80 
81  @JsonCreator
82  public DiscoveryNode(@JsonProperty("switch_id") final String switchId,
83  @JsonProperty("port_id") final String portId,
84  @JsonProperty("attempts") final int attempts,
85  @JsonProperty("time_counter") final int timeCounter,
86  @JsonProperty("check_interval") final int checkInterval,
87  @JsonProperty("consecutive_failure") final int consecutiveFailure,
88  @JsonProperty("consecutive_success") final int consecutiveSuccess,
89  @JsonProperty("forlorn_threshold") final int forlornThreshold,
90  @JsonProperty("found_isl") final boolean foundIsl) {
91 
92  this.switchId = switchId;
93  this.portId = portId;
94  this.attempts = attempts;
95  this.timeCounter = timeCounter;
96  this.checkInterval = checkInterval;
97  this.forlornThreshold = forlornThreshold;
98  this.consecutiveFailure = consecutiveFailure;
99  this.consecutiveSuccess = consecutiveSuccess;
100  this.foundIsl = foundIsl;
101  }
102 
103 
104  public void setFoundIsl(boolean foundIsl){
105  this.foundIsl = foundIsl;
106  }
107 
108  public boolean isFoundIsl(){
109  return this.foundIsl;
110  }
111 
117  public void renew() {
118  attempts = 0;
119  timeCounter = 0;
120  }
121 
125  public boolean forlorn() {
126  if (forlornThreshold == FORLORN_NEVER) { // never gonna give a link up.
127  return false;
128  }
129  return consecutiveFailure > forlornThreshold;
130  }
131 
132  public void clearConsecutiveFailure() {
133  consecutiveFailure = 0;
134  }
135 
136  public void clearConsecutiveSuccess() {
137  consecutiveSuccess = 0;
138  }
139 
140  public int getConsecutiveFailure(){
141  return this.consecutiveFailure;
142  }
143 
144  public int getConsecutiveSuccess(){
145  return this.consecutiveSuccess;
146  }
147 
148  public void incConsecutiveFailure() {
149  consecutiveFailure++;
150  }
151 
152  public void incConsecutiveSuccess() {
153  consecutiveSuccess++;
154  }
155 
156  public int getTicks() {
157  return timeCounter;
158  }
159 
160  public void incTick() {
161  timeCounter++;
162  }
163 
164  public void resetTickCounter() {
165  timeCounter = 0;
166  }
167 
172  public boolean maxAttempts(Integer attemptLimit) {
173  return (attemptLimit < attempts);
174  }
175 
176  public void incAttempts() {
177  attempts++;
178  }
179 
180  public int getAttempts() {
181  return attempts;
182  }
183 
184  public boolean timeToCheck() {
185  return timeCounter >= checkInterval;
186  }
187 
188  public String getSwitchId() {
189  return switchId;
190  }
191 
192  public String getPortId() {
193  return portId;
194  }
195 
196  @Override
197  public boolean equals(Object o) {
198  if (this == o) {
199  return true;
200  }
201  if (!(o instanceof DiscoveryNode)) {
202  return false;
203  }
204  DiscoveryNode that = (DiscoveryNode) o;
205  return Objects.equals(getSwitchId(), that.getSwitchId()) &&
206  Objects.equals(getPortId(), that.getPortId());
207  }
208 
209  @Override
210  public int hashCode() {
211  return Objects.hash(getSwitchId(), getPortId());
212  }
213 
214  @Override
215  public String toString() {
216  return "DiscoveryNode{" +
217  "switchId='" + switchId + '\'' +
218  ", portId='" + portId + '\'' +
219  ", attempts=" + attempts +
220  ", consecutiveFailure=" + consecutiveFailure +
221  ", consecutiveSuccess=" + consecutiveSuccess +
222  '}';
223  }
224 }
DiscoveryNode(@JsonProperty("switch_id") final String switchId, @JsonProperty("port_id") final String portId, @JsonProperty("attempts") final int attempts, @JsonProperty("time_counter") final int timeCounter, @JsonProperty("check_interval") final int checkInterval, @JsonProperty("consecutive_failure") final int consecutiveFailure, @JsonProperty("consecutive_success") final int consecutiveSuccess, @JsonProperty("forlorn_threshold") final int forlornThreshold, @JsonProperty("found_isl") final boolean foundIsl)
boolean maxAttempts(Integer attemptLimit)