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

import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

public class AS4PathAttribute implements PathAttribute {

    List<Segment> segments = new ArrayList<>();

    public AS4PathAttribute(byte typeCode, byte[] data) {
        int offset = 0;
        while (offset < data.length) {
            Segment segment = new Segment().setType(data[offset]);
            byte length = data[offset + 1];
            for(int i=0; i<length; i++)
                segment.asns.add(
                        ((data[offset + 2 + (i * 4)] & 0xFF) << 24) |
                        ((data[offset + 3 + (i * 4)] & 0xFF) << 16) |
                        ((data[offset + 4 + (i * 4)] & 0xFF) << 8) |
                        (data[offset + 5 + (i * 4)] & 0xFF)
                );
            offset += 2 + (length * 4);
            segments.add(segment);
        }
    }

    public byte getTypeCode() {
        return 17;
    }

    public byte[] build() {
        return new byte[0];
    }

    @Getter
    @Setter
    public static class Segment {
        byte type;
        List<Integer> asns = new ArrayList<>();
    }

}