summaryrefslogtreecommitdiff
path: root/src/main/java/com/lumaserv/bgp/protocol/attribute
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/lumaserv/bgp/protocol/attribute')
-rw-r--r--src/main/java/com/lumaserv/bgp/protocol/attribute/ASPathAttribute.java25
-rw-r--r--src/main/java/com/lumaserv/bgp/protocol/attribute/ExtendedCommuntiesAttribute.java8
-rw-r--r--src/main/java/com/lumaserv/bgp/protocol/attribute/NextHopAttribute.java15
-rw-r--r--src/main/java/com/lumaserv/bgp/protocol/attribute/OriginAttribute.java30
-rw-r--r--src/main/java/com/lumaserv/bgp/protocol/attribute/UnknownAttribute.java3
5 files changed, 79 insertions, 2 deletions
diff --git a/src/main/java/com/lumaserv/bgp/protocol/attribute/ASPathAttribute.java b/src/main/java/com/lumaserv/bgp/protocol/attribute/ASPathAttribute.java
index d6f14ea..6405924 100644
--- a/src/main/java/com/lumaserv/bgp/protocol/attribute/ASPathAttribute.java
+++ b/src/main/java/com/lumaserv/bgp/protocol/attribute/ASPathAttribute.java
@@ -37,6 +37,31 @@ public class ASPathAttribute implements PathAttribute {
public static class Segment {
byte type;
List<Integer> asns = new ArrayList<>();
+
+ public String toString() {
+ StringBuffer buf = new StringBuffer();
+
+ buf.append("(");
+ for(Integer asn : asns) {
+ if (buf.length() > 1)
+ buf.append(" ");
+ buf.append(asn);
+ }
+ buf.append(")");
+ return buf.toString();
+ }
}
+ public String toString() {
+ StringBuffer buf = new StringBuffer();
+
+ buf.append("[");
+ for(Segment segment : segments) {
+ if (buf.length() > 1)
+ buf.append(", ");
+ buf.append(segment);
+ }
+ buf.append("]");
+ return buf.toString();
+ }
}
diff --git a/src/main/java/com/lumaserv/bgp/protocol/attribute/ExtendedCommuntiesAttribute.java b/src/main/java/com/lumaserv/bgp/protocol/attribute/ExtendedCommuntiesAttribute.java
index 759ae60..6909277 100644
--- a/src/main/java/com/lumaserv/bgp/protocol/attribute/ExtendedCommuntiesAttribute.java
+++ b/src/main/java/com/lumaserv/bgp/protocol/attribute/ExtendedCommuntiesAttribute.java
@@ -30,4 +30,12 @@ public class ExtendedCommuntiesAttribute implements PathAttribute {
return new byte[0];
}
+ public String toString() {
+ if (type == 0x03 && subType == 0x0b) {
+ // Color extended community
+ return String.format("color:%d", an);
+ }
+
+ return String.format("%d,%d,%d,%d", type, subType, as, an);
+ }
}
diff --git a/src/main/java/com/lumaserv/bgp/protocol/attribute/NextHopAttribute.java b/src/main/java/com/lumaserv/bgp/protocol/attribute/NextHopAttribute.java
index 14d5367..2146364 100644
--- a/src/main/java/com/lumaserv/bgp/protocol/attribute/NextHopAttribute.java
+++ b/src/main/java/com/lumaserv/bgp/protocol/attribute/NextHopAttribute.java
@@ -1,5 +1,8 @@
package com.lumaserv.bgp.protocol.attribute;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
import lombok.Getter;
import lombok.Setter;
@@ -8,10 +11,16 @@ import lombok.Setter;
public class NextHopAttribute implements PathAttribute {
byte[] address;
+ InetAddress ip;
public NextHopAttribute(byte typeCode, byte[] data) {
this.address = new byte[data.length];
System.arraycopy(data, 0, address, 0, address.length);
+ try {
+ ip = InetAddress.getByAddress(address);
+ } catch (UnknownHostException ex) {
+ // Ignore
+ }
}
public byte getTypeCode() {
@@ -22,4 +31,10 @@ public class NextHopAttribute implements PathAttribute {
return address;
}
+ public String toString() {
+ if (ip != null)
+ return ip.getHostAddress();
+ else
+ return address.toString();
+ }
}
diff --git a/src/main/java/com/lumaserv/bgp/protocol/attribute/OriginAttribute.java b/src/main/java/com/lumaserv/bgp/protocol/attribute/OriginAttribute.java
index 2bf1208..9827bae 100644
--- a/src/main/java/com/lumaserv/bgp/protocol/attribute/OriginAttribute.java
+++ b/src/main/java/com/lumaserv/bgp/protocol/attribute/OriginAttribute.java
@@ -3,14 +3,37 @@ package com.lumaserv.bgp.protocol.attribute;
import lombok.Getter;
import lombok.Setter;
+import java.util.EnumSet;
+
@Getter
@Setter
public class OriginAttribute implements PathAttribute {
- byte origin;
+ @Getter
+ enum Origin {
+ IGP(0),
+ EGP(1),
+ INCOMPLETE(2);
+
+ byte code;
+
+ Origin(int code) {
+ this.code = (byte)code;
+ }
+
+ public static Origin fromByte(byte code) {
+ return EnumSet.allOf(Origin.class)
+ .stream()
+ .filter(e -> e.getCode() == code)
+ .findAny()
+ .orElseThrow(() -> new IllegalArgumentException("unknown origin: " + code));
+ }
+ }
+
+ Origin origin;
public OriginAttribute(byte typeCode, byte[] data) {
- origin = data[0];
+ origin = Origin.fromByte(data[0]);
}
public byte getTypeCode() {
@@ -21,4 +44,7 @@ public class OriginAttribute implements PathAttribute {
return new byte[0];
}
+ public String toString() {
+ return origin.toString();
+ }
}
diff --git a/src/main/java/com/lumaserv/bgp/protocol/attribute/UnknownAttribute.java b/src/main/java/com/lumaserv/bgp/protocol/attribute/UnknownAttribute.java
index 9dbe0f9..69dae2d 100644
--- a/src/main/java/com/lumaserv/bgp/protocol/attribute/UnknownAttribute.java
+++ b/src/main/java/com/lumaserv/bgp/protocol/attribute/UnknownAttribute.java
@@ -20,4 +20,7 @@ public class UnknownAttribute implements PathAttribute {
return typeCode;
}
+ public String toString() {
+ return "Unknown:" + typeCode;
+ }
}