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

public interface PathAttribute {

    byte getTypeCode();
    byte[] build();

    static PathAttribute from(byte typeCode, byte[] data) {
        switch (typeCode & 0xFF) {
            case 1:
                return new OriginAttribute(typeCode, data);
            case 2:
                return new ASPathAttribute(typeCode, data);
            case 3:
                return new NextHopAttribute(typeCode, data);
            case 6:
                return new AtomicAggregateAttribute(typeCode, data);
            case 7:
                return new AggregatorAttribute(typeCode, data);
            case 8:
                return new CommunitiesAttribute(typeCode, data);
            case 16:
                return new ExtendedCommuntiesAttribute(typeCode, data);
            case 17:
                return new AS4PathAttribute(typeCode, data);
            case 18:
                return new AS4AggregatorAttribute(typeCode, data);
            case 21:
                return new ASPathLimitAttribute(typeCode, data);
            case 32:
                return new LargeCommunityAttribute(typeCode, data);
            case 255:
                return new DevelopmentAttribute(typeCode, data);
        }
        return new UnknownAttribute(typeCode, data);
    }

}