package com.lumaserv.bgp.protocol.attribute; import java.nio.ByteBuffer; import lombok.Getter; import lombok.Setter; import java.util.EnumSet; @Getter @Setter public class OriginAttribute implements PathAttribute { @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 = Origin.fromByte(data[0]); } public byte getTypeCode() { return 1; } public void build(ByteBuffer b) { b.put(origin); } public String toString() { return origin.toString(); } }