BGP协议格式记录
[toc]
BGP协议主体格式
BGP
协议主要由Header
和BGP Message Types
组成
Message Header Format
Header
结构为Marker
(16字节)、Length
(2字节)、Type
(1字节)组成
=> RFC4271 Sec 4.1
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+ +
| |
+ +
| Marker |
+ +
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Length | Type |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Type
存在以下状态:
1 - OPEN
2 - UPDATE
3 - NOTIFICATION
4 - KEEPALIVE
5 - ROUTE-REFRESH
6 - DYNAMIC CAPABILITY
P.S Type: 5 - ROUTE-REFRESH
出自 RFC2918 Sec 3.Type: 6 - DYNAMIC CAPABILITY
出自 draft-ietf-idr-dynamic-cap-16 Sec 3.
OPEN Message Format
Open
结构为Version
(1字节)、My Autonomous System
(2字节)、Hold Time
(2字节)、BGP Identifier
(4字节,BGP IP
)、Optional Parameters Length
(1字节)、Optional Parameters
(变长)
=> RFC4271 Sec 4.2
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+
| Version |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| My Autonomous System |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Hold Time |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| BGP Identifier |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Opt Parm Len |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| Optional Parameters (variable) |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
0 1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-...
| Parm. Type | Parm. Length | Parameter Value (variable)
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-...
Optional Parameters
内部结构为1个或多个<Parameter Type, Parameter Length, Parameter Value>
三元组(1字节,1字节,x字节)
This field contains a list of optional parameters, in which each parameter is encoded as a <Parameter Type, Parameter Length, Parameter Value> triplet.
Parameter Type
可以为Reserved
(Parameter Type 0
)、Authentication (deprecated)
(Parameter Type 1
)、Capability Codes
(Parameter Type 2
)
最常用的还是Capability Codes
,其内部格式为1个或多个<Capability Code, Capability Length, Capability Value>
三元组
=> RFC3392 Sec 4.
+------------------------------+
| Capability Code (1 octet) |
+------------------------------+
| Capability Length (1 octet) |
+------------------------------+
| Capability Value (variable) |
+------------------------------+
其中Capability-Code
可为如下的值
整个结构如下
graph LR
X(Optional Parameters)--> T1(Opt Param tuple)
T1(Opt Param tuple)--> A("Parameter Type(if Capability Codes)")
T1(Opt Param tuple)--> B(Parameter Length)
T1(Opt Param tuple)--> C(Parameter Value)
C(Parameter Value)--> CT1(Cap Code tuple)
CT1(Cap Code tuple)--> CTA(Capability Code)
CT1(Cap Code tuple)--> CTB(Capability Length)
CT1(Cap Code tuple)--> CTC(Capability Value)
C(Parameter Value)--> CT2(...)
X(Optional Parameters)--> T2(...)
(1) Multiprotocol Extensions for BGP-4
Capability Code
字段为1Capability Length
字段为变长Capability Value
如下:Address Family Identifier
(2字节)、Reserved
(1字节,默认为0)、Subsequent Address Family Identifier
(1字节)
0 7 15 23 31
+-------+-------+-------+-------+
| AFI | Res. | SAFI |
+-------+-------+-------+-------+
(2) Route Refresh Capability for BGP-4
Capability Code
字段为2Capability Length
字段为0
=> RFC2918 Sec 2.
(3) Outbound Route Filtering Capability
Capability Code
字段为3Capability Length
字段为变长Capability Value
字段为一个或者多个如下结构
+--------------------------------------------------+
| Address Family Identifier (2 octets) |
+--------------------------------------------------+
| Reserved (1 octet) |
+--------------------------------------------------+
| Subsequent Address Family Identifier (1 octet) |
+--------------------------------------------------+
| Number of ORFs (1 octet) |
+--------------------------------------------------+
| ORF Type (1 octet) |
+--------------------------------------------------+
| Send/Receive (1 octet) |
+--------------------------------------------------+
| ... |
+--------------------------------------------------+
| ORF Type (1 octet) |
+--------------------------------------------------+
| Send/Receive (1 octet) |
+--------------------------------------------------+
其中Send/Receive
值只能为1、2、3
=> RFC5291 Sec 5.
(4) Multiple routes to a destination capability (deprecated)
Capability Code
字段为4
但是被弃用
=> RFC8277 Sec 6.
(5) Extended Next Hop Encoding
Capability Code
字段为5Capability Length
字段为变长
+-----------------------------------------------------+
| NLRI AFI - 1 (2 octets) |
+-----------------------------------------------------+
| NLRI SAFI - 1 (2 octets) |
+-----------------------------------------------------+
| Nexthop AFI - 1 (2 octets) |
+-----------------------------------------------------+
| ..... |
+-----------------------------------------------------+
| NLRI AFI - N (2 octets) |
+-----------------------------------------------------+
| NLRI SAFI - N (2 octets) |
+-----------------------------------------------------+
| Nexthop AFI - N (2 octets) |
+-----------------------------------------------------+
(6) BGP Extended Message
Capability Code
字段为6Capability Length
字段为0
=> RFC8654 Sec 3.
(7) BGPsec Capability
Capability Code
字段为7Capability Length
字段为3Capability Value
字段如下
0 1 2 3 4 5 6 7
+---------------------------------------+
| Version | Dir | Unassigned |
+---------------------------------------+
| |
+------ AFI -----+
| |
+---------------------------------------+
(8) Multiple Labels Capability
Capability Code
字段为8Capability Length
字段为变长Capability Value
字段为一个或多个<AFI, SAFI, Count>
三元组
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| AFI | SAFI | Count ~
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
~ AFI | SAFI | Count |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
(9) BGP Role
Capability Code
字段为9Capability Length
字段为1Capability Value
字段如下
Value Role name (for the local AS)
0 Provider
1 RS
2 RS-Client
3 Customer
4 Peer (i.e., Lateral Peer)
5-255 Unassigned
(64) Graceful Restart Capability
Capability Code
字段为64Capability Length
字段为变长Capability Value
字段为ReStart Flags
、Restart Time in seconds
和一个或多个<AFI, SAFI, Flags for Address Family>
三元组
+--------------------------------------------------+
| Restart Flags (4 bits) |
+--------------------------------------------------+
| Restart Time in seconds (12 bits) |
+--------------------------------------------------+
| Address Family Identifier (16 bits) |
+--------------------------------------------------+
| Subsequent Address Family Identifier (8 bits) |
+--------------------------------------------------+
| Flags for Address Family (8 bits) |
+--------------------------------------------------+
| ... |
+--------------------------------------------------+
| Address Family Identifier (16 bits) |
+--------------------------------------------------+
| Subsequent Address Family Identifier (8 bits) |
+--------------------------------------------------+
| Flags for Address Family (8 bits) |
+--------------------------------------------------+
Restart Flags:
0 1 2 3
+-+-+-+-+
|R|Resv.|
+-+-+-+-+
Flags for Address Family:
0 1 2 3 4 5 6 7
+-+-+-+-+-+-+-+-+
|F| Reserved |
+-+-+-+-+-+-+-+-+
(65) Support for 4-octet AS number capability
Capability Code
字段为65Capability Length
字段为4Capability Value
字段为4字节的AS number
=> RFC6793 Sec 3.
(67) Support for Dynamic Capability (capability specific)
Capability Code
字段为67Capability Length
字段为变长Capability Value
字段是一串capability codes
,每个一字节
The Capability Value field consists of a list of capability codes (one-octet for each) that specify the capabilities that MAY be revised dynamically by the remote speaker.
=> draft-ietf-idr-dynamic-cap-16 Sec 2.
(68) Multisession BGP Capability
Capability Code
字段为68Capability Length
字段为变长Capability Value
字段是一个Flags
(G
+Reserved
)和0个或多个capability codes
用于区别不同的组
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|G| Reserved | Session Id ~
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
=> draft-ietf-idr-bgp-multisession-07 Sec 4.
(69) ADD-PATH Capability
Capability Code
字段为69Capability Length
字段为变长Capability Value
字段为一个或多个<AFI, SAFI, Send/Receive>
三元组
+------------------------------------------------+
| Address Family Identifier (2 octets) |
+------------------------------------------------+
| Subsequent Address Family Identifier (1 octet) |
+------------------------------------------------+
| Send/Receive (1 octet) |
+------------------------------------------------+
(70) Enhanced Route Refresh Capability
Capability Code
字段为70Capability Length
字段为0
=> RFC7313 Sec 3.1.
(71) Long-Lived Graceful Restart (LLGR) Capability
Capability Code
字段为71Capability Length
字段为变长Capability Value
字段为0个或多个<AFI, SAFI, Flags, Long-lived Stale Time>
四元组
+--------------------------------------------------+
| Address Family Identifier (16 bits) |
+--------------------------------------------------+
| Subsequent Address Family Identifier (8 bits) |
+--------------------------------------------------+
| Flags for Address Family (8 bits) |
+--------------------------------------------------+
| Long-lived Stale Time (24 bits) |
+--------------------------------------------------+
| ... |
+--------------------------------------------------+
| Address Family Identifier (16 bits) |
+--------------------------------------------------+
| Subsequent Address Family Identifier (8 bits) |
+--------------------------------------------------+
| Flags for Address Family (8 bits) |
+--------------------------------------------------+
| Long-lived Stale Time (24 bits) |
+--------------------------------------------------+
=> RFC-ietf-idr-long-lived-gr-06 Sec 3.1
(72) Routing Policy Distribution
Capability Code
字段为72Capability Length
字段为变长Capability Value
字段为1个或多个<AFI, SAFI, Send/Receive>
三元组
+--------------------------------------------------+
| Address Family Identifier (2 octets) |
+--------------------------------------------------+
| Subsequent Address Family Identifier (1 octet) |
+--------------------------------------------------+
| Send/Receive (1 octet) |
+--------------------------------------------------+
=> draft-ietf-idr-rpd-04 Sec 4.3
(128) Prestandard Route Refresh (deprecated)
同 (2) Route Refresh Capability for BGP-4
(130) Prestandard Outbound Route Filtering (deprecated)
同 (3) Outbound Route Filtering Capability
UPDATE Message Format
UPDATE Message
主要用来构建描述各种自治域的关系图,用于向peer
通告共享公共路径属性的可行路由或者撤回多个不可行路由
update
结构为Withdrawn Routes Length
(2字节)、Withdrawn Routes
(变长)、Total Path Attribute Length
(2字节)、Path Attributes
(变长,其长度值为前一个字段)、Network Layer Reachability Information
(变长,其长度值为Header
长度减去Total Path Attribute Length
)
+-----------------------------------------------------+
| Withdrawn Routes Length (2 octets) |
+-----------------------------------------------------+
| Withdrawn Routes (variable) |
+-----------------------------------------------------+
| Total Path Attribute Length (2 octets) |
+-----------------------------------------------------+
| Path Attributes (variable) |
+-----------------------------------------------------+
| Network Layer Reachability Information (variable) |
+-----------------------------------------------------+
Withdrawn Routes
中是一些IP address prefix
,每个IP address prefix
都是<length, prefix>
的二元组
+---------------------------+
| Length (1 octet) |
+---------------------------+
| Prefix (variable) |
+---------------------------+
每个Path Attributes
都是一组<attribute type, attribute length, attribute value>
三元组
Attribute Type
是二个字节的字段。Attr. Flags
、Attr. Type Code
均一个字节
0 1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Attr. Flags |Attr. Type Code|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Attr. Flags
每个bits
的0/1
均有不同的含义,例如第四个bit
(bit 3
)表示是否是一个Extended
长度的比特位,如果为0,则Attribute Length
是1个字节,如果为1,则是2个字节
Attr. Type Code
值如下
整个结构如下
graph LR
X(Path Attributes)--> T1(tuple)
T1(tuple)--> A(attribute type)
A-->A1(Attr. Flags)
A-->A2(Attr. Type Code)
T1(tuple)--> B(attribute length)
T1(tuple)--> C(attribute value)
X(Path Attributes)--> T2(...)
(1) ORIGIN
Type Code
为1Attribute Len
为1Attribute Value
可以为IGP(0)
,EGP(1)
,INCOMPLETE(2)
(2) AS_PATH
Type Code
为2Attribute Len
为变长Attribute Value
为一组AS path segments
,每一个AS path segments
表示为<path segment type(1字节), path segment length(1字节), path segment value(变长)>
三元组,
path segment type
可以为AS_SET(1)
,AS_SEQUENCE(2)
path segment length
为ASes
的个数(不是path segment value
的字节长度)path segment value
为一个或多个AS
编号,每个编号2个字节
整个结构如下
graph LR
X(Attribute Value)--> T1(AS path segments)
T1(AS path segments)--> A(path segment type)
T1(AS path segments)--> B(path segment length)
T1(AS path segments)--> C(path segment value)
C(path segment value)--> C1(AS number)
C(path segment value)--> C2(...)
X(Path Attributes)--> T2(...)
(3) NEXT_HOP
Type Code
为3Attribute Len
为4Attribute Value
为IP address
(4) MULTI_EXIT_DISC
Type Code
为4Attribute Len
为4Attribute Value
为4个字节的无符号整数,用于区别邻居自治域的入口点
(5) LOCAL_PREF
Type Code
为5Attribute Len
为4Attribute Value
为4个字节的无符号整数,用于通知内部对等节点,广告路由的偏好程度(不是很理解)
(6) ATOMIC_AGGREGATE
Type Code
为6Attribute Len
为0
(7) AGGREGATOR
Type Code
为7Attribute Len
为6(某些实现下为8,即AS number(4字节)
)Attribute Value
为the last AS number(2字节)
,the IP address(4字节)
(8) COMMUNITIES
Type Code
为8Attribute Len
为变长Attribute Value
为一组4字节的community
(9) ORIGINATOR_ID
Type Code
为9Attribute Len
为4Attribute Value
为本地自治域的BGP Identifier
ORIGINATOR_ID
和CLUSTER_LIST
一起是防止路由环路的
(10) CLUSTER_LIST
Type Code
为10Attribute Len
为变长Attribute Value
为一组4字节的CLUSTER_ID
(14) MP_REACH_NLRI
Type Code
为14Attribute Len
为变长Attribute Value
为AFI(2字节)
、SAFI(1字节)
、Length of Next Hop Network Address(1字节)
、Network Address of Next Hop(变长)
、Reserved(1字节)
、NLRI(变长)
Network Address of Next Hop
和NLRI
均由<AFI, SAFI>
标识
+---------------------------------------------------------+
| Address Family Identifier (2 octets) |
+---------------------------------------------------------+
| Subsequent Address Family Identifier (1 octet) |
+---------------------------------------------------------+
| Length of Next Hop Network Address (1 octet) |
+---------------------------------------------------------+
| Network Address of Next Hop (variable) |
+---------------------------------------------------------+
| Reserved (1 octet) |
+---------------------------------------------------------+
| Network Layer Reachability Information (variable) |
+---------------------------------------------------------+
(15) MP_UNREACH_NLRI
Type Code
为15Attribute Len
为变长Attribute Value
为AFI(2字节)
、SAFI(1字节)
、Withdrawn Routes(变长)
+---------------------------------------------------------+
| Address Family Identifier (2 octets) |
+---------------------------------------------------------+
| Subsequent Address Family Identifier (1 octet) |
+---------------------------------------------------------+
| Withdrawn Routes (variable) |
+---------------------------------------------------------+
Withdrawn Routes
由<AFI, SAFI>
标识
(16) EXTENDED COMMUNITIES
Type Code
为16Attribute Len
为变长Attribute Value
为一系列extended communities
,每个Extended Community
均是8个字节的如下结构
如果是Regular type
,则是1个字节,如果是Extended type
,则是2个字节
- Type Field : 1 or 2 octets
- Value Field : Remaining octets
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type high | Type low(*) | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Value |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
(17) AS4_PATH
Type Code
为17Attribute Len
为4Attribute Value
为4字节的AS4_PATH
(18) AS4_AGGREGATOR
Type Code
为18Attribute Len
为8Attribute Value
为the last AS number(4字节)
,the IP address(4字节)
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!