summaryrefslogtreecommitdiff
path: root/src/main/java/com/lumaserv/bgp
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2023-03-07 00:50:13 +0100
committerMikael Magnusson <mikma@users.sourceforge.net>2023-11-11 23:59:40 +0100
commit1bddeae21e60e49469912e033286d98ff6546bea (patch)
treefd78624395206dd1164c8cf3f0d95c41152a1720 /src/main/java/com/lumaserv/bgp
parent91cb8c9aa089a57a03250088ef62030daf508880 (diff)
Implement MPReachableNLRIAttribute.build()
Diffstat (limited to 'src/main/java/com/lumaserv/bgp')
-rw-r--r--src/main/java/com/lumaserv/bgp/protocol/attribute/MPReachableNLRIAttribute.java26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/main/java/com/lumaserv/bgp/protocol/attribute/MPReachableNLRIAttribute.java b/src/main/java/com/lumaserv/bgp/protocol/attribute/MPReachableNLRIAttribute.java
index a02f5c2..1c0a475 100644
--- a/src/main/java/com/lumaserv/bgp/protocol/attribute/MPReachableNLRIAttribute.java
+++ b/src/main/java/com/lumaserv/bgp/protocol/attribute/MPReachableNLRIAttribute.java
@@ -7,6 +7,7 @@ import java.util.ArrayList;
import java.util.Collection;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
import com.lumaserv.bgp.protocol.AFI;
@@ -15,6 +16,7 @@ import com.lumaserv.bgp.protocol.IPPrefix;
import com.lumaserv.bgp.protocol.SAFI;
@Getter
+@NoArgsConstructor
@Setter
public class MPReachableNLRIAttribute implements PathAttribute {
@@ -60,8 +62,28 @@ public class MPReachableNLRIAttribute implements PathAttribute {
}
public byte[] build() {
- // FIXME
- return null;
+ int nhLen = nextHop.getAddress().length;
+ int len = 4 + nhLen + 1;
+ for (IPPrefix prefix : nlriPrefixes) {
+ len += 1 + (int)Math.ceil(prefix.getLength() / 8d);
+ }
+ byte[] data = new byte[len];
+ data[0] = (byte)((afi.getValue() >> 8) & 0xff);
+ data[1] = (byte)(afi.getValue() & 0xff);
+ data[2] = (byte)safi.getValue();
+ data[3] = (byte)nhLen;
+ System.arraycopy(nextHop.getAddress(), 0, data, 4, nhLen);
+ int offset = 4 + nhLen;
+ data[offset] = 0;
+ offset++;
+ for (IPPrefix prefix : nlriPrefixes) {
+ data[offset] = (byte)prefix.getLength();
+ offset++;
+ int addressLen = (int)Math.ceil(prefix.getLength() / 8d);
+ System.arraycopy(prefix.getAddress(), 0, data, offset, addressLen);
+ offset += addressLen;
+ }
+ return data;
}
public String toString() {