-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidityCheck.java
More file actions
67 lines (63 loc) · 1.81 KB
/
ValidityCheck.java
File metadata and controls
67 lines (63 loc) · 1.81 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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package bfd.fsm;
import java.util.BitSet;
/**
* This class can be used to Validate a BFD message after it has arrived to
* the client
*
* @author angelos
*/
public class ValidityCheck {
public boolean ValidityCheck( BFDmessage msg,SessionHandler sh){
if (convert(msg.getVersion())!=1){
return false;
}
if (msg.getAuthenticationPresent()){
if (convert(msg.getLength())<26){
return false;
}
}
else{
if (convert(msg.getLength())<24){
return false;
}
}
//Add step here ENCAPSULATION PROTOCOL
if (convert(msg.getDetectMult())==0){
return false;
}
if (msg.getMultipoint()){
return false;
}
if (convert(msg.getMyDiscriminator())==0){
return false;
}
if (convert(msg.getYourDiscriminator())!=0){
//Select session here
}
else{
if ((convert(msg.getState())!=0)&&(convert(msg.getState())!=1)){
return false;
}
}
if (msg.getAuthenticationPresent()){
return false;
}
return true;
}
public static int convert(BitSet bits) {
int value = 0;
int j=0;
for (int i = bits.length()-1; i >=0 ; --i) {
if (bits.get(i)){
value=value+ (int)Math.pow(2, j);
}
j++;
}
return value;
}
}