summaryrefslogtreecommitdiff
path: root/src/main/java/com/lumaserv/bgp/protocol/attribute/OriginAttribute.java
blob: 9827baec1539d7bf593698d1677f8b4c8f76262b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.lumaserv.bgp.protocol.attribute;

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 byte[] build() {
        return new byte[0];
    }

    public String toString() {
        return origin.toString();
    }
}