summaryrefslogtreecommitdiff
path: root/src/main/java/com/lumaserv/bgp/protocol/attribute/ExtendedCommuntiesAttribute.java
blob: 69092774cd8cd2c9154bbef70dded181dfc554b8 (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
package com.lumaserv.bgp.protocol.attribute;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class ExtendedCommuntiesAttribute implements PathAttribute {

    byte type;
    byte subType;
    int as;
    int an;

    public ExtendedCommuntiesAttribute(byte typeCode, byte[] data) {
        type = data[0];
        subType = data[1];
        as = ((data[2] & 0xFF) << 24) |
                ((data[3] & 0xFF) << 16) |
                ((data[4] & 0xFF) << 8) |
                (data[5] & 0xFF);
        an = ((data[6] & 0xFF) << 8) | (data[7] & 0xFF);
    }

    public byte getTypeCode() {
        return 16;
    }

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