-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBFDmessage.java
More file actions
368 lines (338 loc) · 9.26 KB
/
BFDmessage.java
File metadata and controls
368 lines (338 loc) · 9.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
package bfd.fsm;
import java.util.BitSet;
/**
* This class can be used to generate or modify a BFD packet
*
* @author angelos
*/
public class BFDmessage {
BitSet BFDmsg=new BitSet(192);
public void BFDmessage(){
BFDmsg.set(0, 191, false);
}
public void setBFDmessage(BitSet bitset){
BFDmsg=bitset;
}
public BitSet getBFDMessage(){
return BFDmsg;
}
void setVersion(int version){
if (version==1){
BFDmsg.set(2);
}
else{
System.out.println("Unsupported Version");
System.out.println(" Version was not set");
return;
}
System.out.println("Version set");
}
BitSet getVersion(){
return BFDmsg.get(0,3);
}
void setDiag(int diag){
if (diag==0){
BFDmsg.set(3,8,false);
}
else if (diag==1){
BFDmsg.set(7,true);
}
else if (diag==2){
BFDmsg.set(6,true);
}
else if (diag==3){
BFDmsg.set(6,true);
BFDmsg.set(7,true);
}
else if (diag==4){
BFDmsg.set(5,true);
}
else if (diag==5){
BFDmsg.set(5,true);
BFDmsg.set(7,true);
}
else if (diag==6){
BFDmsg.set(5,true);
BFDmsg.set(6,true);
}
else if (diag==7){
BFDmsg.set(5,true);
BFDmsg.set(6,true);
BFDmsg.set(7,true);
}
else if (diag==8){
BFDmsg.set(4,true);
}
else {
System.out.println("Unsupported Diagnostic");
System.out.println("Diagnostic was not set");
return;
}
System.out.println("Diagnostics set");
}
BitSet getDiag(){
return BFDmsg.get(3,8);
}
void setState(int sta){
if (sta==0){
BFDmsg.set(8,false);
BFDmsg.set(9,false);
}
else if (sta==1){
BFDmsg.set(8,false);
BFDmsg.set(9,true);
}
else if (sta==2){
BFDmsg.set(8,true);
BFDmsg.set(9,false);
}
else if (sta==3){
BFDmsg.set(8,true);
BFDmsg.set(9,true);
}
else {
System.out.println("Unsupported State");
System.out.println("State was not set");
return;
}
System.out.println("State set");
}
BitSet getState(){
return BFDmsg.get(8,10);
}
void setPoll(int poll){
if (poll==0){
BFDmsg.set(10,false);
}
else if (poll==1){
BFDmsg.set(10,true);
}
System.out.println("Poll set");
}
boolean getPoll(){
return BFDmsg.get(10);
}
void setFinal(int F){
if (F==0){
BFDmsg.set(11,false);
}
else if (F==1){
BFDmsg.set(11,true);
}
System.out.println("Final set");
}
boolean getFinal(){
return BFDmsg.get(11);
}
void setControlPlaneIndependent(int C){
if (C==0){
BFDmsg.set(12,false);
}
else if (C==1){
BFDmsg.set(12,true);
}
System.out.println("Control Plane Independent set");
}
boolean getControlPlaneIndpendent(){
return BFDmsg.get(12);
}
void setAuthenticationPresent(int A){
if (A==0){
BFDmsg.set(13,false);
}
else if (A==1){
BFDmsg.set(13,true);
System.out.println("Warning!! Authentication is not supported yet");
}
System.out.println("Authentication set");
}
boolean getAuthenticationPresent(){
return BFDmsg.get(13);
}
void setDemand(int D){
if (D==0){
BFDmsg.set(14,false);
}
else if (D==1){
BFDmsg.set(14,true);
}
System.out.println("Demand set");
}
boolean getDemand(){
return BFDmsg.get(14);
}
void setMultipoint(int M){
if (M==0){
BFDmsg.set(15,false);
}
else if (M==1){
BFDmsg.set(15,true);
}
System.out.println("Multipoint set");
}
boolean getMultipoint(){
return BFDmsg.get(15);
}
void setDetectMult(int dm){
String str=Integer.toBinaryString(dm);
while (str.length()<8){
str="0"+str;
}
if (str.length()>8){
System.out.println("Warning!!! Detect Multipoint value will cause an overflow");
return;
}
for (int i=0;i<str.length();i++){
if (Character.getNumericValue(str.charAt(i))==0){
BFDmsg.set(16+i,false);
}
else {
BFDmsg.set(16+i,true);
}
}
System.out.println("Detect Multipoint set");
}
BitSet getDetectMult(){
return BFDmsg.get(16,24);
}
void setLength(int L){
String str=Integer.toBinaryString(L);
while (str.length()<8){
str="0"+str;
}
if (str.length()>8){
System.out.println("Warning!!! Length value will cause an overflow");
return;
}
for (int i=0;i<str.length();i++){
if (Character.getNumericValue(str.charAt(i))==0){
BFDmsg.set(24+i,false);
}
else {
BFDmsg.set(24+i,true);
}
}
System.out.println("Length set");
}
BitSet getLength(){
return BFDmsg.get(24,32);
}
void setMyDiscriminator(int myd){
String str=Integer.toBinaryString(myd);
if (myd==0){
System.out.println("Warning!!! Discriminator values must be nonZero");
return;
}
while (str.length()<32){
str="0"+str;
}
if (str.length()>32){
System.out.println("Warning!!! My Discriminator value will cause an overflow");
return;
}
for (int i=0;i<str.length();i++){
if (Character.getNumericValue(str.charAt(i))==0){
BFDmsg.set(32+i,false);
}
else {
BFDmsg.set(32+i,true);
}
}
System.out.println("My discriminator set");
}
BitSet getMyDiscriminator(){
return BFDmsg.get(32, 64);
}
void setYourDiscriminator(int yd){
String str=Integer.toBinaryString(yd);
if (yd==0){
System.out.println("Warning!!! Discriminator values must be nonZero");
return;
}
while (str.length()<32){
str="0"+str;
}
if (str.length()>32){
System.out.println("Warning!!! My Discriminator value will cause an overflow");
return;
}
for (int i=0;i<str.length();i++){
if (Character.getNumericValue(str.charAt(i))==0){
BFDmsg.set(64+i,false);
}
else {
BFDmsg.set(64+i,true);
}
}
System.out.println("Your discriminator set");
}
BitSet getYourDiscriminator(){
return BFDmsg.get(64, 96);
}
void setDesiredMinTxInterval(int interval){
String str=Integer.toBinaryString(interval);
while (str.length()<32){
str="0"+str;
}
if (str.length()>32){
System.out.println("Warning!!! Desired Min Tx Interval value will cause an overflow");
return;
}
for (int i=0;i<str.length();i++){
if (Character.getNumericValue(str.charAt(i))==0){
BFDmsg.set(96+i,false);
}
else {
BFDmsg.set(96+i,true);
}
}
System.out.println("Desired Min Tx Interval set");
}
BitSet getDesiredMinTxInterval(){
return BFDmsg.get(96,128);
}
void setRequiredMinRxInterval(int interval){
String str=Integer.toBinaryString(interval);
while (str.length()<32){
str="0"+str;
}
if (str.length()>32){
System.out.println("Warning!!! Required Min Rx Interval value will cause an overflow");
return;
}
for (int i=0;i<str.length();i++){
if (Character.getNumericValue(str.charAt(i))==0){
BFDmsg.set(128+i,false);
}
else {
BFDmsg.set(128+i,true);
}
}
System.out.println("Required Min Rx Interval set");
}
BitSet getRequiredMinRxInterval(){
return BFDmsg.get(128,160);
}
void setRequiredMinEchoRxInterval(int interval){
String str=Integer.toBinaryString(interval);
while (str.length()<32){
str="0"+str;
}
if (str.length()>32){
System.out.println("Warning!!! Required Echo Min Rx Interval value will cause an overflow");
return;
}
for (int i=0;i<str.length();i++){
if (Character.getNumericValue(str.charAt(i))==0){
BFDmsg.set(160+i,false);
}
else {
BFDmsg.set(160+i,true);
}
}
System.out.println("Required Echo Min Rx Interval set");
}
BitSet getRequiredMinEchoRxInterval(){
return BFDmsg.get(160,192);
}
}