« Back
in BGP 路由 思科 read.

BGP neighbor + update-source 实验(1)

实验拓扑:

实验基本配置: 
R1
interface Loopback0
 ip address 1.1.1.1 255.255.255.255
!
interface Serial1/1
 ip address 10.1.12.1 255.255.255.0
 no sh
!
router ospf 1
 router-id 1.1.1.1
network 1.1.1.1 0.0.0.0 area 0
 network 10.1.12.0 0.0.0.255 area 0
!
R2
interface Loopback0
 ip address 2.2.2.2 255.255.255.255
!
interface Serial1/0
 ip address 10.1.12.2 255.255.255.0
 serial restart-delay 0
!
router ospf 1
 router-id 2.2.2.2
 network 2.2.2.2 0.0.0.0 area 0
 network 10.1.12.0 0.0.0.255 area 0
!

1.  R1R2通过物理口建立BGP邻居,更新源默认为物理口.
R1   BGP配置:
R1#sh run | b r b
router bgp 1
 bgp router-id 1.1.1.1
 bgp log-neighbor-changes
 neighbor 10.1.12.2 remote-as 1
!
R2   BGP配置:
R2#sh run | b r b
router bgp 1
 bgp router-id 2.2.2.2
 bgp log-neighbor-changes
 neighbor 10.1.12.1 remote-as 1
!
R1上开启Debug命令(以下皆同):
debug ip tcp transactions
debug ip bgp

实验现象:
R1#clear ip bgp *
R1#
00:11:48: BGP: 10.1.12.2 went from Established to Idle
00:11:48: %BGP-5-ADJCHANGE: neighbor 10.1.12.2 Down User reset
R1#
00:11:48: BGP: 10.1.12.2 closing
00:11:48: TCP0: state was ESTAB -> FINWAIT1 [11005 -> 10.1.12.2(179)]
00:11:48: TCP0: sending FIN
00:11:48: TCP0: state was FINWAIT1 -> FINWAIT2 [11005 -> 10.1.12.2(179)]
R1#
00:11:49: TCP0: FIN processed
00:11:49: TCP0: state was FINWAIT2 -> TIMEWAIT [11005 -> 10.1.12.2(179)]
R1#
00:12:07: TCP0: state was TIMEWAIT -> CLOSED [179 -> 10.1.12.2(11003)]
00:12:07: TCB 0x613F5B14 destroyed
R1#
00:12:08: BGP: 10.1.12.2 went from Idle to Active
00:12:08: BGP: 10.1.12.2 open active, delay 6540ms
R1#
00:12:14: BGP: 10.1.12.2 open active, local address 10.1.12.1
00:12:14: TCB613F5858 created
00:12:14: TCB613F5858 setting property TCP_WINDOW_SIZE (0) 61545FB8
00:12:14: TCB613F5858 setting property TCP_TOS (11) 61545FA0
00:12:14: TCB613F5858 bound to 10.1.12.1.11006
00:12:14: TCP: sending SYN, seq 2707613242, ack 0
00:12:14: TCP0: Connection to 10.1.12.2:179, advertising MSS 1460
00:12:14: TCP0: state was CLOSED -> SYNSENT [11006 -> 10.1.12.2(179)]
00:12:15: TCP0: state was SYNSENT -> ESTAB [11006 -> 10.1.12.2(179)]
00:12:15: TCP0: Connection to 10.1.12.2:179, received MSS 1460, MSS is 1460
00:12:15: TCB613F5858 connected to 10.1.12.2.179
00:12:15: BGP: 10.1.12.2 went from Active to OpenSent
00:12:15: BGP: 10.1.12.2 sending OPEN, version 4, my as: 1
00:12:15: BGP: 10.1.12.2 send message type 1, length (incl. header) 45
00:12:15: BGP: 10.1.12.2 rcv message type 1, length (excl. header) 26
00:12:15: BGP: 10.1.12.2 rcv OPEN, version 4
00:12:15: BGP: 10.1.12.2 rcv OPEN
R1#w/ OPTION parameter len: 16
00:12:15: BGP: 10.1.12.2 rcvd OPEN w/ optional parameter type 2 (Capability) len 6
00:12:15: BGP: 10.1.12.2 OPEN has CAPABILITY code: 1, length 4
00:12:15: BGP: 10.1.12.2 OPEN has MP_EXT CAP for afi/safi: 1/1
00:12:15: BGP: 10.1.12.2 rcvd OPEN w/ optional parameter type 2 (Capability) len 2
00:12:15: BGP: 10.1.12.2 OPEN has CAPABILITY code: 128, length 0
00:12:15: BGP: 10.1.12.2 OPEN has ROUTE-REFRESH capability(old) for all address-families
00:12:15: BGP: 10.1.12.2 rcvd OPEN w/ optional parameter type 2 (Capability) len 2
00:12:15: BGP: 10.1.12.2 OPEN has CAPABILITY code: 2, length 0
00:12:15: BGP: 10.1.12.2 OPEN has ROUTE-REFRESH capability(new) for all address-families
00:12:15: BGP: 10.1.12.2 went from OpenSent to OpenConfirm
00:12:15: BGP: 10.1.12.2 went from OpenConfirm to Established
00:12:15: %BGP-5-ADJCHANGE: neighbor 10.1.12.2 Up

实验结果:
R1#sh ip bgp s
BGP router identifier 1.1.1.1, local AS number 1
BGP table version is 1, main routing table version 1
Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
10.1.12.2       4     1      21      21        1    0    0 00:01:55        0
R1#sh tcp brie
TCB       Local Address           Foreign Address        (state)
613F5858  10.1.12.1.11006         10.1.12.2.179          ESTAB

实验延伸再通过clear ip bgp * ,得到以下结果:
R1#sh tcp brie  
TCB       Local Address           Foreign Address        (state)
613F53BC  10.1.12.1.179           10.1.12.2.11006        ESTAB
R1#sh tcp brie all
TCB       Local Address           Foreign Address        (state)
613F53BC  10.1.12.1.179           10.1.12.2.11006        ESTAB
613F4884  *.179                   10.1.12.2.*           LISTEN
613ECDA4  *.*                     *.*                LISTEN

实验分析:
证明BGP邻居关系建立是单向发起并建立的,前一个是R1主动发起连接到R2 179端口,后一个反之,通过反复clear ip bgp * 得到的结果验证,说明双方都有可能发起连接,并不一定是由BGP大的router-id 去向小的router-id 发起连接,即跟router-id无关。


2.  R1R2通过物理口建立BGP邻居,R1更新源改为lo0, R2保持默认.
R1  BGP配置:
R1#sh run | b r b
router bgp 1
 bgp router-id 1.1.1.1
 bgp log-neighbor-changes
 neighbor 10.1.12.2 remote-as 1
 neighbor 10.1.12.2 update-source Loopback0
R2   BGP配置:
R2#sh run | b r b
router bgp 1
 bgp router-id 2.2.2.2
 bgp log-neighbor-changes
 neighbor 10.1.12.1 remote-as 1
!

实验现象:
R1#clear ip bgp *
R1#
00:42:06: BGP: 10.1.12.2 went from Established to Idle
00:42:06: %BGP-5-ADJCHANGE: neighbor 10.1.12.2 Down User reset
R1#
00:42:06: BGP: 10.1.12.2 closing
00:42:06: TCP0: state was ESTAB -> FINWAIT1 [179 -> 10.1.12.2(11007)]
00:42:06: TCP0: sending FIN
00:42:07: TCP0: state was FINWAIT1 -> FINWAIT2 [179 -> 10.1.12.2(11007)]
R1#
00:42:08: TCP0: FIN processed
00:42:08: TCP0: state was FINWAIT2 -> TIMEWAIT [179 -> 10.1.12.2(11007)]
R1#
00:42:27: BGP: 10.1.12.2 went from Idle to Active
00:42:27: BGP: 10.1.12.2 open active, delay 8888ms
R1#
00:42:35: BGP: 10.1.12.2 open active, local address 1.1.1.1
00:42:35: TCB613F5858 created
00:42:35: TCB613F5858 setting property TCP_WINDOW_SIZE (0) 61545FB8
00:42:35: TCB613F5858 setting property TCP_TOS (11) 61545FA0
00:42:35: TCB613F5858 bound to 1.1.1.1.11012
00:42:35: TCP: sending SYN, seq 304519487, ack 0
00:42:35: TCP0: Connection to 10.1.12.2:179, advertising MSS 1460
00:42:35: TCP0: state was CLOSED -> SYNSENT [11012 -> 10.1.12.2(179)]
00:42:35: TCP0: state was SYNSENT -> CLOSED [11012 -> 10.1.12.2(179)]
00:42:35: TCP0: bad seg from 10.1.12.2 -- closing connection: port 11012 seq 0 ack 304519488 rcvnxt 0 rcvwnd 0 len 0
R1#
00:42:35: TCP0: connection closed - remote sent RST
00:42:35: TCB 0x613F5858 destroyed
00:42:35: BGP: 10.1.12.2 open failed: Connection refused by remote host
00:42:36: TCB613F5858 created
00:42:36: TCP0: state was LISTEN -> SYNRCVD [179 -> 10.1.12.2(11008)]
00:42:36: TCP0: Connection to 10.1.12.2:11008, received MSS 1460, MSS is 516
00:42:36: TCP: sending SYN, seq 4137325445, ack 895184167
00:42:36: TCP0: Connection to 10.1.12.2:11008, advertising MSS 1460
00:42:36: TCP0: state was SYNRCVD -> ESTAB [179 -> 10.1.12.2(11008)]
00:42:36: TCB613F4884 callback, connection queue = 1
00:42:36: TCB613F4884 accepting 613F5858 from 10.1.12.2.11008
00:42:36: BGP: 10.1.12.2 passive open
00:42:36: BGP: 10.1.12.2 went from Active to Idle
00:42:36: BGP: 10.1.12.2 went from Idle to Connect
00:42:36: BGP: 10.1.12.2 rcv message type 1, length (excl. header) 26
00:42:36: BGP: 10.1.12.2 rcv OPEN, version 4
00:42:36: BGP: 10.1.12.2 went from Connect to OpenSent
00:42:36: BGP: 10.1.12.2
R1#sending OPEN, version 4, my as: 1
00:42:36: BGP: 10.1.12.2 rcv OPEN w/ OPTION parameter len: 16
00:42:36: BGP: 10.1.12.2 rcvd OPEN w/ optional parameter type 2 (Capability) len 6
00:42:36: BGP: 10.1.12.2 OPEN has CAPABILITY code: 1, length 4
00:42:36: BGP: 10.1.12.2 OPEN has MP_EXT CAP for afi/safi: 1/1
00:42:36: BGP: 10.1.12.2 rcvd OPEN w/ optional parameter type 2 (Capability) len 2
00:42:36: BGP: 10.1.12.2 OPEN has CAPABILITY code: 128, length 0
00:42:36: BGP: 10.1.12.2 OPEN has ROUTE-REFRESH capability(old) for all address-families
00:42:36: BGP: 10.1.12.2 rcvd OPEN w/ optional parameter type 2 (Capability) len 2
00:42:36: BGP: 10.1.12.2 OPEN has CAPABILITY code: 2, length 0
00:42:36: BGP: 10.1.12.2 OPEN has ROUTE-REFRESH capability(new) for all address-families
00:42:36: BGP: 10.1.12.2 went from OpenSent to OpenConfirm
00:42:36: BGP: 10.1.12.2 send message type 1, length (incl. header) 45
00:42:36: BGP: 10.1.12.2 went from OpenConfirm to Established
00:42:36: %BGP-5
R1#-ADJCHANGE: neighbor 10.1.12.2 Up

实验结果:
R1#sh ip bgp s
BGP router identifier 1.1.1.1, local AS number 1
BGP table version is 1, main routing table version 1
Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
10.1.12.2       4     1    1037    1041        1    0    0 00:00:36        0
R1#sh tcp brie
TCB       Local Address           Foreign Address        (state)
613F5858  10.1.12.1.179           10.1.12.2.11008        ESTAB
R1#sh tcp brie al
TCB       Local Address           Foreign Address        (state)
613F5858  10.1.12.1.179           10.1.12.2.11008        ESTAB
613F4884  *.179                   10.1.12.2.*           LISTEN
613ECDA4  *.*                     *.*                LISTEN
R1#
通过实验结果及反复clear ip bgp * 得知BGP邻居可以建立,但只能R2主动发起向R1的连接,R1主动发起到R2的连接不能建立。

实验分析:
R2 主动发起连接  BGP建立邻居
R2配置 nei 10.1.12.1 remote 1
意指以 10.1.12.2 为更新源,去访问 10.1.12.1 179 端口
R1回复信息应该是 10.1.12.1 为源,10.1.12.2 为目的的连接
R1配置里 nei 10.1.12.2 remote 1
                      nei 10.1.12.2 up lo0
是以 1.1.1.1 为源,10.1.12.2 为目的建立连接
源不满足,目的满足,但可以建立连接

反之
R1 主动发起连接 BGP 无法建立邻居
R1  nei 10.1.12.2 remote 1
       nei 10.1.12.2 up lo0
意指以 1.1.1.1 为更新源,去访问 10.1.12.2 179 端口
R2 回复信息应该是 10.1.12.2 为源, 1.1.1.1 为目的的连接
1.1.1.1做为目的,无法在R2的配置 nei x.x.x.x remote 1 中找到,因此无法建立邻居

说明更新源在BGP中的作用是路由器R1本身主动发起连接时做为源地址,在回复连接信息时,路由器R2的更新源不需确定也可以建立连接,只需要路由器R2中有neighbor xx.xx.xx.xx remote 1 (R1的更新源地址) 配置既可。