diff options
-rw-r--r-- | src/main/java/com/lumaserv/bgp/protocol/attribute/MPReachableNLRIAttribute.java | 26 |
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() { |