summaryrefslogtreecommitdiff
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-03-07 01:30:52 +0100
commit36b26041e82845ca95da4826f36d7b543df22b90 (patch)
tree5a63f0ae9631f34279bead29afb8d40e57d17a3e
parent9e4782d04850cda00b5fa2c2c48cf0fbb621ef31 (diff)
Implement MPReachableNLRIAttribute.build()active-old
-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() {