blob: e83b7513bd52da253adb770f5f8d6384444524ee (
plain)
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
|
package com.lumaserv.bgp.protocol.message;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@NoArgsConstructor
public class BGPOpen {
byte version;
int asn;
int holdTime;
byte[] identifier;
public BGPOpen(byte[] message) {
version = message[0];
asn = ((message[1] & 0xFF) << 8) | (message[2] & 0xFF);
holdTime = ((message[3] & 0xFF) << 8) | (message[4] & 0xFF);
identifier = new byte[4];
}
public byte[] build() {
byte[] message = new byte[5 + identifier.length + 1 + 2 + 2 * 6];
message[0] = version;
message[1] = (byte) (asn >> 8);
message[2] = (byte) (asn & 0xFF);
message[3] = (byte) (holdTime >> 8);
message[4] = (byte) (holdTime & 0xFF);
System.arraycopy(identifier, 0, message, 5, identifier.length);
message[5 + identifier.length + 0] = 14; // Length (0E)
message[5 + identifier.length + 1] = 2; // Parameter Type: capability (02)
message[5 + identifier.length + 2] = 12; // Length (0C)
message[5 + identifier.length + 3] = 1; // Type: multiprotocol (01)
message[5 + identifier.length + 4] = 4; // Length (04)
message[5 + identifier.length + 5] = 0; // IPv6 (0002)
message[5 + identifier.length + 6] = 2; //
message[5 + identifier.length + 7] = 0; // Reserved
message[5 + identifier.length + 8] = 1; // Unicast (01)
message[5 + identifier.length + 9] = 1; // Type: multiprotocol (01)
message[5 + identifier.length +10] = 4; // Length (04)
message[5 + identifier.length +11] = 0; // IPv4 (0001)
message[5 + identifier.length +12] = 1; //
message[5 + identifier.length +13] = 0; // Reserved
message[5 + identifier.length +14] = 1; // Unicast (01)
return message;
}
}
|