diff options
Diffstat (limited to 'src/main/java/com/lumaserv/bgp/protocol/attribute/OriginAttribute.java')
-rw-r--r-- | src/main/java/com/lumaserv/bgp/protocol/attribute/OriginAttribute.java | 30 |
1 files changed, 28 insertions, 2 deletions
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(); + } } |