diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2022-01-31 23:16:31 +0100 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2023-11-13 00:17:57 +0100 |
commit | 88f43944c915be3cb824a8ffa4f2995666b73486 (patch) | |
tree | f38d9c2b7fede5ec46e8df042afa36ce66819110 /src/main/java/com/lumaserv/bgp/protocol/message/BGPOpen.java | |
parent | 9f35136d97673b825fb51c2e1c7067881a3d6820 (diff) |
Implent outgoing BGPUpdate and some attributes
Diffstat (limited to 'src/main/java/com/lumaserv/bgp/protocol/message/BGPOpen.java')
-rw-r--r-- | src/main/java/com/lumaserv/bgp/protocol/message/BGPOpen.java | 66 |
1 files changed, 34 insertions, 32 deletions
diff --git a/src/main/java/com/lumaserv/bgp/protocol/message/BGPOpen.java b/src/main/java/com/lumaserv/bgp/protocol/message/BGPOpen.java index e83b751..37b791b 100644 --- a/src/main/java/com/lumaserv/bgp/protocol/message/BGPOpen.java +++ b/src/main/java/com/lumaserv/bgp/protocol/message/BGPOpen.java @@ -1,52 +1,54 @@ package com.lumaserv.bgp.protocol.message; +import com.lumaserv.bgp.protocol.DataBuilder; + import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import java.nio.ByteBuffer; + @Getter @Setter @NoArgsConstructor -public class BGPOpen { +public class BGPOpen implements DataBuilder { 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); + public BGPOpen(ByteBuffer message) { +System.out.println("BGPOpen pos:" + message.position()); + version = message.get(); + asn = message.getShort() & 0xFFFF; + holdTime = message.getShort() & 0xFFFF; identifier = new byte[4]; +System.out.println("BGPOpen asn:" + asn); + message.get(identifier); } - 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; + public void build(ByteBuffer b) { + b.put(version); + b.put((byte) (asn >> 8)); + b.put((byte) (asn & 0xFF)); + b.put((byte) (holdTime >> 8)); + b.put((byte) (holdTime & 0xFF)); + b.put(identifier); + b.put((byte)14); // Length (0E) + b.put((byte)2); // Parameter Type: capability (02) + b.put((byte)12); // Length (0C) + + b.put((byte)1); // Type: multiprotocol (01) + b.put((byte)4); // Length (04) + b.putShort((short)2); // IPv6 (0002) + b.put((byte)0); // Reserved + b.put((byte)1); // Unicast (01) + + b.put((byte)1); // Type: multiprotocol (01) + b.put((byte)4); // Length (04) + b.putShort((short)1); // IPv4 (0001) + b.put((byte)0); // Reserved + b.put((byte)1); // Unicast (01) } - } |