Tuesday, July 28, 2015

GNS3 MPLS Xconnect



Setup Components

The setup mainly consists of GNS3 integrated with VmWare workstation that runs CSR1000v

Basic Configuration

CSR1
interface loopback0
ip address 1.1.1.1 255.255.255.255

interface GigabitEthernet1
no shutdown
ip address 192.168.12.1 255.255.255.0
mpls ip

interface GigabitEthernet2
no ip address

mpls label protocol ldp
mpls ldp router-id loopback 0 force

router ospf 1
router-id 1.1.1.1
network 1.1.1.1 0.0.0.0 area 0
network 192.168.12.1 0.0.0.0 area 0

CSR2
interface loopback0
ip address 3.3.3.3 255.255.255.255

interface GigabitEthernet1
no shutdown
ip address 192.168.23.3 255.255.255.0
mpls ip

interface GigabitEthernet2
no ip address

mpls label protocol ldp
mpls ldp router-id loopback 0 force

router ospf 1
router-id 3.3.3.3
network 3.3.3.3 0.0.0.0 area 0
network 192.168.23.3 0.0.0.0 area 0

CE1
interface FastEthernet1/1
switchport trunk encapsulation dot1q
switchport mode ttrunk

CE2
interface FastEthernet1/1
switchport trunk encapsulation dot1q
switchport mode ttrunk


Xconnect Configuration

Under the sub-interface

CSR1
interface GigabitEthernet2
 no ip address
 negotiation auto

interface GigabitEthernet2.15
 encapsulation dot1Q 15
 xconnect 3.3.3.3 15 encapsulation mpls

CSR2
interface GigabitEthernet2
 no ip address
 negotiation auto

interface GigabitEthernet2.15
 encapsulation dot1Q 15
 xconnect 1.1.1.1 15 encapsulation mpls

CE1
vlan 15

interface vlan 15
ip address 192.168.15.3 255.255.255.0

CE2
vlan 15
interface vlan 15
ip address 192.168.15.4 255.255.255.0

Verification

CSR1#show xconnect interface gigabitEthernet 2.15 detail
Legend:    XC ST=Xconnect State  S1=Segment1 State  S2=Segment2 State
  UP=Up       DN=Down            AD=Admin Down      IA=Inactive
  SB=Standby  HS=Hot Standby     RV=Recovering      NH=No Hardware

XC ST  Segment 1                         S1 Segment 2                         S2
------+---------------------------------+--+---------------------------------+--
UP pri   ac Gi2.15:15(Eth VLAN)          UP mpls 3.3.3.3:15                   UP
            Interworking: ethernet               Local VC label 19
                                                 Remote VC label 19

CSR1#show xconnect interface gigabitEthernet 2.15 event-trace
Legend:    XC ST=Xconnect State  S1=Segment1 State  S2=Segment2 State
  UP=Up       DN=Down            AD=Admin Down      IA=Inactive
  SB=Standby  HS=Hot Standby     RV=Recovering      NH=No Hardware

XC ST  Segment 1                         S1 Segment 2                         S2
------+---------------------------------+--+---------------------------------+--
UP pri   ac Gi2.15:15(Eth VLAN)          UP mpls 3.3.3.3:15                   UP

CE1#ping 192.168.15.4 source vlan 15

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.15.4, timeout is 2 seconds:
Packet sent with a source address of 192.168.15.3
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 28/49/104 ms

CSR1#sh l2vpn atom vc vcid 15 detail
pseudowire100001 is up, VC status is up PW type: Ethernet
  Create time: 01:53:07, last status change time: 01:52:53
    Last label FSM state change time: 01:52:49
  Destination address: 3.3.3.3 VC ID: 15
    Output interface: Gi1, imposed label stack {17 19}
    Preferred path: not configured
    Default path: active
    Next hop: 192.168.12.2
  Member of xconnect service Gi2.15-15, group right
    Associated member Gi2.15 is up, status is up
    Interworking type is Ethernet
    Service id: 0x6b000001
  Signaling protocol: LDP, peer 3.3.3.3:0 up
    Targeted Hello: 1.1.1.1(LDP Id) -> 3.3.3.3, LDP is UP
    Graceful restart: not configured and not enabled
    Non stop routing: not configured and not enabled
    PWid FEC (128), VC ID: 15
    Status TLV support (local/remote)         : enabled/supported
      LDP route watch                         : enabled
      Label/status state machine              : established, LruRru
      Local dataplane status received         : No fault
      BFD dataplane status received           : Not sent
      BFD peer monitor status received        : No fault
      Status received from access circuit     : No fault
      Status sent to access circuit           : No fault
      Status received from pseudowire i/f     : No fault
      Status sent to network peer             : No fault
      Status received from network peer       : No fault
      Adjacency status of remote peer         : No fault
  Sequencing: receive disabled, send disabled
  Bindings
    Parameter    Local                          Remote
    ------------ ------------------------------ ------------------------------
    Label        19                             19
    Group ID     0                              0
    Interface
    MTU          1500                           1500
    Control word on (configured: autosense)     on
    PW type      Ethernet                       Ethernet
    VCCV CV type 0x02                           0x02
                   LSPV [2]                       LSPV [2]
    VCCV CC type 0x07                           0x07
                   CW [1], RA [2], TTL [3]       CW [1], RA [2], TTL [3]
    Status TLV   enabled                        supported
  SSO Descriptor: 3.3.3.3/15, local label: 19
  Dataplane:
    SSM segment/switch IDs: 4102/4101 (used), PWID: 1
  Rx Counters
    58 input transit packets, 4925 bytes
    1 drops, 0 seq err
  Tx Counters
    3444 output transit packets, 310987 bytes
    0 drops

Under the pseudowire

Configuration

CSR1
interface pseudowire60
 encapsulation mpls
 neighbor 3.3.3.3 60

interface GigabitEthernet2
 no ip address
 negotiation auto
 service instance 60 ethernet
  encapsulation dot1q 60

l2vpn xconnect context XCONN1
 member GigabitEthernet2 service-instance 60
 member pseudowire60

CSR2
interface pseudowire60
 encapsulation mpls
 neighbor 1.1.1.1 60

interface GigabitEthernet2
 no ip address
 negotiation auto
 service instance 60 ethernet
  encapsulation dot1q 60

l2vpn xconnect context XCONN1
 member GigabitEthernet2 service-instance 60
 member pseudowire60

CE1
vlan 60

interface vlan 60
ip address 172.16.60.3 255.255.255.0

CE2
vlan 60
interface vlan 60
ip address 172.16.60.4 255.255.255.0

Verification

CSR1#sh xconnect interface gigabitEthernet 2 detail
Legend:    XC ST=Xconnect State  S1=Segment1 State  S2=Segment2 State
  UP=Up       DN=Down            AD=Admin Down      IA=Inactive
  SB=Standby  HS=Hot Standby     RV=Recovering      NH=No Hardware

XC ST  Segment 1                         S1 Segment 2                         S2
------+---------------------------------+--+---------------------------------+--
UP pri   ac Gi2:60(Eth VLAN)             UP mpls 3.3.3.3:60                   UP
            Interworking: ethernet               Local VC label 21
                                                 Remote VC label 21

CSR1#sh xconnect interface gigabitEthernet 2 event-trace
Legend:    XC ST=Xconnect State  S1=Segment1 State  S2=Segment2 State
  UP=Up       DN=Down            AD=Admin Down      IA=Inactive
  SB=Standby  HS=Hot Standby     RV=Recovering      NH=No Hardware

XC ST  Segment 1                         S1 Segment 2                         S2
------+---------------------------------+--+---------------------------------+--
UP pri   ac Gi2:60(Eth VLAN)             UP mpls 3.3.3.3:60                   UP

CE1#ping 172.16.60.4 source vlan 60

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.60.4, timeout is 2 seconds:
Packet sent with a source address of 172.16.60.3
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 48/99/152 ms

CSR1#sh l2vpn atom vc vcid 60 detail
pseudowire60 is up, VC status is up PW type: Ethernet
  Create time: 00:57:37, last status change time: 00:57:17
    Last label FSM state change time: 00:57:17
  Destination address: 3.3.3.3 VC ID: 60
    Output interface: Gi1, imposed label stack {17 21}
    Preferred path: not configured
    Default path: active
    Next hop: 192.168.12.2
  Member of xconnect service XCONN1
    Associated member Gi2 is up, status is up
    Interworking type is Ethernet
    Service id: 0x66000002
  Signaling protocol: LDP, peer 3.3.3.3:0 up
    Targeted Hello: 1.1.1.1(LDP Id) -> 3.3.3.3, LDP is UP
    Graceful restart: not configured and not enabled
    Non stop routing: not configured and not enabled
    PWid FEC (128), VC ID: 60
    Status TLV support (local/remote)         : enabled/supported
      LDP route watch                         : enabled
      Label/status state machine              : established, LruRru
      Local dataplane status received         : No fault
      BFD dataplane status received           : Not sent
      BFD peer monitor status received        : No fault
      Status received from access circuit     : No fault
      Status sent to access circuit           : No fault
      Status received from pseudowire i/f     : No fault
      Status sent to network peer             : No fault
      Status received from network peer       : No fault
      Adjacency status of remote peer         : No fault
  Sequencing: receive disabled, send disabled
  Bindings
    Parameter    Local                          Remote
    ------------ ------------------------------ ------------------------------
    Label        21                             21
    Group ID     0                              0
    Interface
    MTU          1500                           1500
    Control word on (configured: autosense)     on
    PW type      Ethernet                       Ethernet
    VCCV CV type 0x02                           0x02
                   LSPV [2]                       LSPV [2]
    VCCV CC type 0x07                           0x07
                   CW [1], RA [2], TTL [3]       CW [1], RA [2], TTL [3]
    Status TLV   enabled                        supported
  SSO Descriptor: 3.3.3.3/60, local label: 21
  Dataplane:
    SSM segment/switch IDs: 24592/12302 (used), PWID: 3
  Rx Counters
    24 input transit packets, 2381 bytes
    0 drops, 0 seq err
  Tx Counters
    1740 output transit packets, 164359 bytes
    0 drops

Monday, June 8, 2015

BGP Regular Expressions




We are going to use the above topology to demonstrate some regular expressions examples using Cisco IOS software

Configurations 

Each router will be configured with two loopback interfaces that will be advertised into BGP, all BGP relations are eBGP



R1

interface Loopback1

 ip address 192.168.1.1 255.255.255.0



interface Loopback2

 ip address 172.16.1.1 255.255.255.0



interface FastEthernet0/0

 ip address 192.168.12.1 255.255.255.0

 speed 100

 full-duplex

 no shut



interface FastEthernet0/1

 ip address 192.168.13.1 255.255.255.0

 speed 100

 full-duplex

 no shut



interface FastEthernet1/0

 ip address 192.168.14.1 255.255.255.0

 speed 100

 full-duplex

 no shut



router bgp 9038

 no bgp default ipv4-unicast

 bgp log-neighbor-changes

 neighbor 192.168.12.2 remote-as 3356

 neighbor 192.168.13.3 remote-as 47887

 neighbor 192.168.14.4 remote-as 44666



 address-family ipv4

  neighbor 192.168.12.2 activate

  neighbor 192.168.13.3 activate

  neighbor 192.168.14.4 activate

  no auto-summary

  no synchronization

  network 172.16.1.0 mask 255.255.255.0

  network 192.168.1.0

 exit-address-family



R2

interface Loopback1

 ip address 192.168.2.2 255.255.255.0



interface Loopback2

 ip address 172.16.2.2 255.255.255.0



interface FastEthernet0/0

 ip address 192.168.12.2 255.255.255.0

 speed 100

 full-duplex

 no shut



interface FastEthernet0/1

 ip address 192.168.25.2 255.255.255.0

 speed 100

 full-duplex

 no shut



router bgp 3356

 no bgp default ipv4-unicast

 bgp log-neighbor-changes

 neighbor 192.168.12.1 remote-as 9038

 neighbor 192.168.25.5 remote-as 8966



 address-family ipv4

  neighbor 192.168.12.1 activate

  neighbor 192.168.25.5 activate

  no auto-summary

  no synchronization

  network 172.16.2.0 mask 255.255.255.0

  network 192.168.2.0

 exit-address-family



R3

interface Loopback1

 ip address 192.168.3.3 255.255.255.0



interface Loopback2

 ip address 172.16.3.3 255.255.255.0



interface FastEthernet0/0

 ip address 192.168.13.3 255.255.255.0

 speed 100

 full-duplex

 no shut



interface FastEthernet0/1

 ip address 192.168.35.3 255.255.255.0

 speed 100

 full-duplex

 no shut



router bgp 47887

 no bgp default ipv4-unicast

 bgp log-neighbor-changes

 neighbor 192.168.13.1 remote-as 9038

 neighbor 192.168.35.5 remote-as 8966



 address-family ipv4

  neighbor 192.168.13.1 activate

  neighbor 192.168.35.5 activate

  no auto-summary

  no synchronization

  network 172.16.3.0 mask 255.255.255.0

  network 192.168.3.0

 exit-address-family



R4

interface Loopback1

 ip address 192.168.4.4 255.255.255.0



interface Loopback2

 ip address 172.16.4.4 255.255.255.0



interface FastEthernet0/0

 ip address 192.168.14.4 255.255.255.0

 speed 100

 full-duplex

 no shut



interface FastEthernet0/1

 ip address 192.168.46.4 255.255.255.0

 speed 100

 full-duplex

 no shut



router bgp 44666

 no bgp default ipv4-unicast

 bgp log-neighbor-changes

 neighbor 192.168.14.1 remote-as 9038

 neighbor 192.168.46.6 remote-as 7922



 address-family ipv4

  neighbor 192.168.14.1 activate

  neighbor 192.168.46.6 activate

  no auto-summary

  no synchronization

  network 172.16.4.0 mask 255.255.255.0

  network 192.168.4.0

 exit-address-family



R5

interface Loopback1

 ip address 192.168.5.5 255.255.255.0



interface Loopback2

 ip address 172.16.5.5 255.255.255.0



interface FastEthernet0/0

 ip address 192.168.25.5 255.255.255.0

 speed 100

 full-duplex

 no shut



interface FastEthernet0/1

 ip address 192.168.56.5 255.255.255.0

 speed 100

 full-duplex

 no shut



interface FastEthernet1/0

 ip address 192.168.35.5 255.255.255.0

 speed 100

 full-duplex

 no shut



router bgp 8966

 no bgp default ipv4-unicast

 bgp log-neighbor-changes

 neighbor 192.168.25.2 remote-as 3356

 neighbor 192.168.35.3 remote-as 47887

 neighbor 192.168.56.6 remote-as 7922



 address-family ipv4

  neighbor 192.168.25.2 activate

  neighbor 192.168.35.3 activate

  neighbor 192.168.56.6 activate

  no auto-summary

  no synchronization

  network 172.16.5.0 mask 255.255.255.0

  network 192.168.5.0

 exit-address-family



R6

interface Loopback1

 ip address 192.168.6.6 255.255.255.0



interface Loopback2

 ip address 172.16.6.6 255.255.255.0



interface FastEthernet0/0

 ip address 192.168.56.6 255.255.255.0

 speed 100

 full-duplex

 no shut



interface FastEthernet0/1

 ip address 192.168.46.6 255.255.255.0

 speed 100

 full-duplex

 no shut



router bgp 7922

 no bgp default ipv4-unicast

 bgp log-neighbor-changes

 neighbor 192.168.46.4 remote-as 44666

 neighbor 192.168.56.5 remote-as 8966

 !

 address-family ipv4

  neighbor 192.168.46.4 activate

  neighbor 192.168.56.5 activate

  no auto-summary

  no synchronization

  network 172.16.6.0 mask 255.255.255.0

  network 192.168.6.0

 exit-address-family

Characters

Below is the characters used in the BGP regular expressions configuration



?
repeats the previous character one or zero times.
*
repeats the previous character zero or many times.
+
repeats the previous character one or more times.
^
matches the beginning of a string.
$
matches the end of a string.
[]
is a range.
_
matches the space between AS numbers or the end of the AS PATH list.
\\
is an escape character. You’ll need this for BGP confederations.

Outputs

Before we start manipulating with regular expressions, let us check the BGP table on R1



R1#sh ip bgp

BGP table version is 15, local router ID is 192.168.14.1

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete



   Network          Next Hop            Metric LocPrf Weight Path

*> 172.16.1.0/24    0.0.0.0                  0         32768 i

*> 172.16.2.0/24    192.168.12.2             0             0 3356 i

*> 172.16.3.0/24    192.168.13.3             0             0 47887 i

*> 172.16.4.0/24    192.168.14.4             0             0 44666 i

*   172.16.5.0/24    192.168.14.4                           0 44666 7922 8966 i

*                            192.168.13.3                           0 47887 8966 i

*>                          192.168.12.2                           0 3356 8966 i

*> 172.16.6.0/24    192.168.14.4                           0 44666 7922 i

*                            192.168.13.3                           0 47887 8966 7922 i

*                            192.168.12.2                           0 3356 8966 7922 i

*> 192.168.1.0      0.0.0.0                  0         32768 i

*> 192.168.2.0      192.168.12.2             0             0 3356 i

*> 192.168.3.0      192.168.13.3             0             0 47887 i

*> 192.168.4.0      192.168.14.4             0             0 44666 i

*   192.168.5.0      192.168.14.4                           0 44666 7922 8966 i

*                          192.168.13.3                           0 47887 8966 i

*>                        192.168.12.2                           0 3356 8966 i

   Network              Next Hop            Metric LocPrf Weight Path

*> 192.168.6.0      192.168.14.4                           0 44666 7922 i

*                           192.168.13.3                           0 47887 8966 7922 i

*                           192.168.12.2                           0 3356 8966 7922 i





As well, let us dive deeply in the output above as a review for the BGP attributes and best path selection criteria



The prefixes 192.168.1.0 and 172.16.1.0/24 have a next-hop value of 0.0.0.0, which means that these prefixes were locally originated (either using network or redistribution), the 172.16.1.0 appears attached with its subnet mask because it’s a class B prefix and we configured the mask to be /24 in the network statement, 192.168.1.0 is already class C prefix and we did not change the classful boundary, as well, the as-path is empty because again these prefixes are locally originated



Let us check now the prefix 172.16.5.0/24 , it has been learned through three different paths , as we did not manipulate any attributes , the as-path will play a role according to the selection criteria , so the path 44666 7922 8966  will be discarded compared to the other two paths which are shorter , the tie will be between the 47887 8966 and  3356 8966 which are equal in the as-path and both are eBGP , so going down the list , the oldest one learned will be installed in the RIB (routing table)

Regular Expressions Examples

Locally Originated Routes

As mentioned above, the locally originated routes have a next-hop value of 0.0.0.0 and can be shown using the regular expression of ^$



R1#sh ip bgp regexp ^$

BGP table version is 15, local router ID is 192.168.14.1

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete



   Network          Next Hop            Metric LocPrf Weight Path

*> 172.16.1.0/24    0.0.0.0                  0         32768 i

*> 192.168.1.0      0.0.0.0                  0         32768 i



R2#sh ip bgp regexp ^$

BGP table version is 13, local router ID is 192.168.2.2

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete



   Network          Next Hop            Metric LocPrf Weight Path

*> 172.16.2.0/24    0.0.0.0                  0         32768 i

*> 192.168.2.0      0.0.0.0                  0         32768 i



R3#sh ip bgp regexp ^$

BGP table version is 13, local router ID is 192.168.3.3

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete



   Network          Next Hop            Metric LocPrf Weight Path

*> 172.16.3.0/24    0.0.0.0                  0         32768 i

*> 192.168.3.0      0.0.0.0                  0         32768 i



R4#sh ip bgp regexp ^$

BGP table version is 15, local router ID is 192.168.4.4

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete



   Network          Next Hop            Metric LocPrf Weight Path

*> 172.16.4.0/24    0.0.0.0                  0         32768 i

*> 192.168.4.0      0.0.0.0                  0         32768 i



R5#sh ip bgp regexp ^$

BGP table version is 15, local router ID is 192.168.5.5

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete



   Network          Next Hop            Metric LocPrf Weight Path

*> 172.16.5.0/24    0.0.0.0                  0         32768 i

*> 192.168.5.0      0.0.0.0                  0         32768 i



R6#sh ip bgp regexp ^$

BGP table version is 13, local router ID is 192.168.6.6

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete



   Network          Next Hop            Metric LocPrf Weight Path

*> 172.16.6.0/24    0.0.0.0                  0         32768 i

*> 192.168.6.0      0.0.0.0                  0         32768 i

Anything to Match

This will match any route, i.e. it will show the BGP table



R1#sh ip bgp regexp .*

BGP table version is 15, local router ID is 192.168.14.1

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete



   Network          Next Hop            Metric LocPrf Weight Path

*> 172.16.1.0/24    0.0.0.0                  0         32768 i

*> 172.16.2.0/24    192.168.12.2             0             0 3356 i

*> 172.16.3.0/24    192.168.13.3             0             0 47887 i

*> 172.16.4.0/24    192.168.14.4             0             0 44666 i

*  172.16.5.0/24     192.168.14.4                           0 44666 7922 8966 i

*                            192.168.13.3                           0 47887 8966 i

*>                         192.168.12.2                           0 3356 8966 i

*> 172.16.6.0/24    192.168.14.4                           0 44666 7922 i

*                            192.168.13.3                           0 47887 8966 7922 i

*                            192.168.12.2                           0 3356 8966 7922 i

*> 192.168.1.0      0.0.0.0                  0         32768 i

*> 192.168.2.0      192.168.12.2             0             0 3356 i

*> 192.168.3.0      192.168.13.3             0             0 47887 i

*> 192.168.4.0      192.168.14.4             0             0 44666 i

*  192.168.5.0       192.168.14.4                           0 44666 7922 8966 i

*                           192.168.13.3                           0 47887 8966 i

*>                        192.168.12.2                           0 3356 8966 i

   Network              Next Hop            Metric LocPrf Weight Path

*> 192.168.6.0      192.168.14.4                           0 44666 7922 i

*                          192.168.13.3                           0 47887 8966 7922 i

*                           192.168.12.2                           0 3356 8966 7922 i

Routes originated in a specific AS

To check routes originated in a specific AS #, we will be using the pattern _AS#$



R1#sh ip bgp regexp _3356$

BGP table version is 15, local router ID is 192.168.14.1

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete



   Network          Next Hop            Metric LocPrf Weight Path

*> 172.16.2.0/24    192.168.12.2             0             0 3356 i

*> 192.168.2.0      192.168.12.2             0             0 3356 i



R1#sh ip bgp regexp _47887$

BGP table version is 15, local router ID is 192.168.14.1

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete



   Network          Next Hop            Metric LocPrf Weight Path

*> 172.16.3.0/24    192.168.13.3             0             0 47887 i

*> 192.168.3.0      192.168.13.3             0             0 47887 i



R1#sh ip bgp regexp _44666$

BGP table version is 15, local router ID is 192.168.14.1

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete



   Network          Next Hop            Metric LocPrf Weight Path

*> 172.16.4.0/24    192.168.14.4             0             0 44666 i

*> 192.168.4.0      192.168.14.4             0             0 44666 i


R1#sh ip bgp regexp _8966$

BGP table version is 15, local router ID is 192.168.14.1

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete



   Network          Next Hop            Metric LocPrf Weight Path

*  172.16.5.0/24    192.168.14.4                           0 44666 7922 8966 i

*                   192.168.13.3                           0 47887 8966 i

*>                  192.168.12.2                           0 3356 8966 i

*  192.168.5.0      192.168.14.4                           0 44666 7922 8966 i

*                   192.168.13.3                           0 47887 8966 i

*>                  192.168.12.2                           0 3356 8966 i



R1#sh ip bgp regexp _7922$

BGP table version is 15, local router ID is 192.168.14.1

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete



   Network          Next Hop            Metric LocPrf Weight Path

*> 172.16.6.0/24    192.168.14.4                           0 44666 7922 i

*                   192.168.13.3                           0 47887 8966 7922 i

*                   192.168.12.2                           0 3356 8966 7922 i

*> 192.168.6.0      192.168.14.4                           0 44666 7922 i

*                   192.168.13.3                           0 47887 8966 7922 i

*                   192.168.12.2                           0 3356 8966 7922 i

Routes learned from specific AS (the AS-PATH starts with that AS)

To match these kind of routes we will using the regular expression ^AS_



R1#sh ip bgp regexp .*

BGP table version is 15, local router ID is 192.168.14.1

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete



   Network          Next Hop            Metric LocPrf Weight Path

*> 172.16.1.0/24    0.0.0.0                  0         32768 i

*> 172.16.2.0/24    192.168.12.2             0             0 3356 i

*> 172.16.3.0/24    192.168.13.3             0             0 47887 i

*> 172.16.4.0/24    192.168.14.4             0             0 44666 i

*  172.16.5.0/24    192.168.14.4                           0 44666 7922 8966 i

*                          192.168.13.3                           0 47887 8966 i

*>                        192.168.12.2                           0 3356 8966 i

*> 172.16.6.0/24    192.168.14.4                           0 44666 7922 i

*                           192.168.13.3                           0 47887 8966 7922 i

*                           192.168.12.2                           0 3356 8966 7922 i

*> 192.168.1.0      0.0.0.0                  0         32768 i

*> 192.168.2.0      192.168.12.2             0             0 3356 i

*> 192.168.3.0      192.168.13.3             0             0 47887 i

*> 192.168.4.0      192.168.14.4             0             0 44666 i

*  192.168.5.0      192.168.14.4                           0 44666 7922 8966 i

*                         192.168.13.3                           0 47887 8966 i

*>                       192.168.12.2                           0 3356 8966 i

   Network               Next Hop            Metric LocPrf Weight Path

*> 192.168.6.0      192.168.14.4                           0 44666 7922 i

*                           192.168.13.3                           0 47887 8966 7922 i

*                           192.168.12.2                           0 3356 8966 7922 i



R1#sh ip bgp regexp ^3356_

BGP table version is 15, local router ID is 192.168.14.1

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete



   Network          Next Hop            Metric LocPrf Weight Path

*> 172.16.2.0/24    192.168.12.2             0             0 3356 i

*> 172.16.5.0/24    192.168.12.2                           0 3356 8966 i

*  172.16.6.0/24    192.168.12.2                           0 3356 8966 7922 i

*> 192.168.2.0      192.168.12.2             0             0 3356 i

*> 192.168.5.0      192.168.12.2                           0 3356 8966 i

*  192.168.6.0       192.168.12.2                           0 3356 8966 7922 i



R1#sh ip bgp regexp ^47887_

BGP table version is 15, local router ID is 192.168.14.1

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete



   Network          Next Hop            Metric LocPrf Weight Path

*> 172.16.3.0/24    192.168.13.3             0             0 47887 i

*  172.16.5.0/24    192.168.13.3                           0 47887 8966 i

*  172.16.6.0/24    192.168.13.3                           0 47887 8966 7922 i

*> 192.168.3.0      192.168.13.3             0             0 47887 i

*  192.168.5.0      192.168.13.3                           0 47887 8966 i

*  192.168.6.0      192.168.13.3                           0 47887 8966 7922 i

Match any instance of a specific AS (from or through)

To match these kinds of routes we will be using the pattern _AS_



R1#sh ip bgp regexp _3356_

BGP table version is 15, local router ID is 192.168.14.1

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete



   Network          Next Hop            Metric LocPrf Weight Path

*> 172.16.2.0/24    192.168.12.2             0             0 3356 i

*> 172.16.5.0/24    192.168.12.2                           0 3356 8966 i

*  172.16.6.0/24    192.168.12.2                           0 3356 8966 7922 i

*> 192.168.2.0      192.168.12.2             0             0 3356 i

*> 192.168.5.0      192.168.12.2                           0 3356 8966 i

*  192.168.6.0      192.168.12.2                           0 3356 8966 7922 i



R1#sh ip bgp regexp _47887_

BGP table version is 15, local router ID is 192.168.14.1

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete



   Network          Next Hop            Metric LocPrf Weight Path

*> 172.16.3.0/24    192.168.13.3             0             0 47887 i

*  172.16.5.0/24     192.168.13.3                           0 47887 8966 i

*  172.16.6.0/24     192.168.13.3                           0 47887 8966 7922 i

*> 192.168.3.0       192.168.13.3             0             0 47887 i

*  192.168.5.0        192.168.13.3                           0 47887 8966 i

*  192.168.6.0        192.168.13.3                           0 47887 8966 7922 i



R1#sh ip bgp regexp _44666_

BGP table version is 15, local router ID is 192.168.14.1

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete



   Network          Next Hop            Metric LocPrf Weight Path

*> 172.16.4.0/24    192.168.14.4             0             0 44666 i

*  172.16.5.0/24      192.168.14.4                           0 44666 7922 8966 i

*> 172.16.6.0/24    192.168.14.4                           0 44666 7922 i

*> 192.168.4.0      192.168.14.4             0             0 44666 i

*  192.168.5.0        192.168.14.4                           0 44666 7922 8966 i

*> 192.168.6.0      192.168.14.4                           0 44666 7922 i



R1#sh ip bgp regexp _8966_

BGP table version is 15, local router ID is 192.168.14.1

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete



   Network          Next Hop            Metric LocPrf Weight Path

*  172.16.5.0/24    192.168.14.4                           0 44666 7922 8966 i

*                           192.168.13.3                           0 47887 8966 i

*>                        192.168.12.2                           0 3356 8966 i

*  172.16.6.0/24    192.168.13.3                           0 47887 8966 7922 i

*                          192.168.12.2                           0 3356 8966 7922 i

*  192.168.5.0      192.168.14.4                           0 44666 7922 8966 i

*                         192.168.13.3                           0 47887 8966 i

*>                      192.168.12.2                           0 3356 8966 i

*  192.168.6.0      192.168.13.3                           0 47887 8966 7922 i

*                         192.168.12.2                           0 3356 8966 7922 i



R1#sh ip bgp regexp _7922_

BGP table version is 15, local router ID is 192.168.14.1

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete



   Network          Next Hop            Metric LocPrf Weight Path

*  172.16.5.0/24    192.168.14.4                           0 44666 7922 8966 i

*> 172.16.6.0/24    192.168.14.4                           0 44666 7922 i

*                            192.168.13.3                           0 47887 8966 7922 i

*                            192.168.12.2                           0 3356 8966 7922 i

*  192.168.5.0        192.168.14.4                           0 44666 7922 8966 i

*> 192.168.6.0      192.168.14.4                           0 44666 7922 i

*                           192.168.13.3                           0 47887 8966 7922 i

*                           192.168.12.2                           0 3356 8966 7922 i

Routes learned from my directly connected ASes

As can be seen from the topology, AS# 9038 has three directly connected ASes, we will be using the expression ^[0-9]+$ to match these routes



R1#sh ip bgp summary

BGP router identifier 192.168.14.1, local AS number 9038

BGP table version is 15, main routing table version 15

12 network entries using 1440 bytes of memory

20 path entries using 1040 bytes of memory

11/6 BGP path/bestpath attribute entries using 1364 bytes of memory

9 BGP AS-PATH entries using 216 bytes of memory

0 BGP route-map cache entries using 0 bytes of memory

0 BGP filter-list cache entries using 0 bytes of memory

Bitfield cache entries: current 1 (at peak 1) using 32 bytes of memory

BGP using 4092 total bytes of memory

BGP activity 12/0 prefixes, 20/0 paths, scan interval 60 secs



Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd

192.168.12.2    4  3356      40      41       15    0    0 00:31:25        6

192.168.13.3    4 47887      39      40       15    0    0 00:29:33        6

192.168.14.4    4 44666      38      38       15    0    0 00:27:34        6



R1#sh ip bgp regexp ^[0-9]+$

BGP table version is 15, local router ID is 192.168.14.1

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete



   Network          Next Hop            Metric LocPrf Weight Path

*> 172.16.2.0/24    192.168.12.2             0             0 3356 i

*> 172.16.3.0/24    192.168.13.3             0             0 47887 i

*> 172.16.4.0/24    192.168.14.4             0             0 44666 i

*> 192.168.2.0      192.168.12.2             0             0 3356 i

*> 192.168.3.0      192.168.13.3             0             0 47887 i

*> 192.168.4.0      192.168.14.4             0             0 44666 i

Quote-regexp

If we wanted to filter the output more , we can use quote-regexp instead , for example if we wanted to show all routes originated in AS #9038 that starts with 192 , we can use the below command



R3#sh ip bgp quote-regexp "_9038$" | include ^.  192\.

*  192.168.1.0      192.168.35.5                           0 8966 3356 9038 i



R3#sh ip bgp quote-regexp "_9038$" | include ^.  172\.

*  172.16.1.0/24    192.168.35.5                           0 8966 3356 9038 i



R5#sh ip bgp quote-regexp "_9038$" | include ^.  192\.

*  192.168.1.0      192.168.56.6                           0 7922 44666 9038 i



R5#sh ip bgp quote-regexp "_9038$" | include ^.  172\.

*  172.16.1.0/24    192.168.56.6                           0 7922 44666 9038 i

Brackets


The below output will match routes from AS that start with 4, 5, 6, 7 or 8 and have 6 more 6s in the as-path



R2#sh ip bgp regexp [4-8]6+$

BGP table version is 13, local router ID is 192.168.2.2

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete



   Network          Next Hop            Metric LocPrf Weight Path

*  172.16.4.0/24    192.168.25.5                           0 8966 7922 44666 i

*>                  192.168.12.1                           0 9038 44666 i

*  172.16.5.0/24    192.168.12.1                           0 9038 47887 8966 i

*>                  192.168.25.5             0             0 8966 i

*  192.168.4.0      192.168.25.5                           0 8966 7922 44666 i

*>                       192.168.12.1                           0 9038 44666 i

*  192.168.5.0      192.168.12.1                           0 9038 47887 8966 i

*>                       192.168.25.5             0             0 8966 i



R3#sh ip bgp regexp _3*[5-6]+[1-9]$

BGP table version is 13, local router ID is 192.168.3.3

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete



   Network          Next Hop            Metric LocPrf Weight Path

*  172.16.2.0/24    192.168.35.5                           0 8966 3356 i

*>                        192.168.13.1                           0 9038 3356 i

*  192.168.2.0      192.168.35.5                           0 8966 3356 i

*>                       192.168.13.1                           0 9038 3356 i



. matches any character, so we if we applied the output below, we can see that 9 will be matched as the rest of the command contains 038



R3#sh ip bgp regexp ^.038

BGP table version is 13, local router ID is 192.168.3.3

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete



   Network          Next Hop            Metric LocPrf Weight Path

*> 172.16.1.0/24    192.168.13.1             0             0 9038 i

*> 172.16.2.0/24    192.168.13.1                           0 9038 3356 i

*> 172.16.4.0/24    192.168.13.1                           0 9038 44666 i

*  172.16.6.0/24    192.168.13.1                           0 9038 44666 7922 i

*> 192.168.1.0      192.168.13.1             0             0 9038 i

*> 192.168.2.0      192.168.13.1                           0 9038 3356 i

*> 192.168.4.0      192.168.13.1                           0 9038 44666 i

*  192.168.6.0      192.168.13.1                           0 9038 44666 7922 i



The below matches the routes from my directly connected neighbors, but not all neighbors only 3356



R1#sh ip bgp regexp ^[3356]+$

BGP table version is 15, local router ID is 192.168.1.1

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete



   Network          Next Hop            Metric LocPrf Weight Path

*> 172.16.2.0/24    192.168.12.2             0             0 3356 i

*> 192.168.2.0      192.168.12.2             0             0 3356 i



The below matches the routes that starts from 3356 and passes through the direct AS 8966 (following each other in the as-path)



R1#show ip bgp regexp ^3356_8966$

BGP table version is 15, local router ID is 192.168.1.1

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete



   Network          Next Hop            Metric LocPrf Weight Path

*  172.16.5.0/24    192.168.12.2                           0 3356 8966 i

*  192.168.5.0      192.168.12.2                           0 3356 8966 i

Filtering

We can use regular expressions to filter routes and modify attributes instead of matching the same prefixes



Let us change the local preference value for a specific routes matched based on a specific regular expression


R2#sh ip bgp
BGP table version is 13, local router ID is 192.168.2.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 172.16.1.0/24    192.168.12.1             0             0 9038 i
*> 172.16.2.0/24    0.0.0.0                  0         32768 i
*  172.16.3.0/24    192.168.25.5                           0 8966 47887 i
*>                  192.168.12.1                           0 9038 47887 i
*  172.16.4.0/24    192.168.25.5                           0 8966 7922 44666 i
*>                  192.168.12.1                           0 9038 44666 i
*  172.16.5.0/24    192.168.12.1                           0 9038 47887 8966 i
*>                  192.168.25.5             0             0 8966 i
*  172.16.6.0/24    192.168.12.1                           0 9038 44666 7922 i
*>                  192.168.25.5                           0 8966 7922 i
*> 192.168.1.0      192.168.12.1             0             0 9038 i
*> 192.168.2.0      0.0.0.0                  0         32768 i
*  192.168.3.0      192.168.25.5                           0 8966 47887 i
*>                  192.168.12.1                           0 9038 47887 i
*  192.168.4.0      192.168.25.5                           0 8966 7922 44666 i
*>                  192.168.12.1                           0 9038 44666 i
*  192.168.5.0      192.168.12.1                           0 9038 47887 8966 i
   Network          Next Hop            Metric LocPrf Weight Path
*>                  192.168.25.5             0             0 8966 i
*  192.168.6.0      192.168.12.1                           0 9038 44666 7922 i
*>                  192.168.25.5                           0 8966 7922 i

R2
ip as-path access-list 10 permit ^9038_44666$

route-map LP permit 10
match as-path 10
set local-preference 300
route-map LP permit 20

router bgp 3356
address-family ipv4 unicast
neighbor 192.168.12.1 route-map LP in

R2#sho ip bgp regexp ^9038_44666$
BGP table version is 15, local router ID is 192.168.2.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 172.16.4.0/24    192.168.12.1                  300      0 9038 44666 i
*> 192.168.4.0      192.168.12.1                  300      0 9038 44666 i

Now, let us try to change the origin code for specific routes matched based on a specific regular expression

R1#sh ip bgp regexp _47887$
BGP table version is 15, local router ID is 192.168.1.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
   Network          Next Hop            Metric LocPrf Weight Path
*> 172.16.3.0/24    192.168.13.3             0             0 47887 i
*> 192.168.3.0      192.168.13.3             0             0 47887 i

R1
ip as-path access-list 14 permit _47887$

route-map ORIGIN permit 10
match as-path 14
set origin incomplete
route-map ORIGIN permit 20

router bgp 9038
address-family ipv4 unicast
neighbor 192.168.13.3 route-map ORIGIN in

R1#sh ip bgp regexp _47887$
BGP table version is 17, local router ID is 192.168.1.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network                 Next Hop            Metric LocPrf Weight Path
*> 172.16.3.0/24    192.168.13.3             0             0 47887 ?
*> 192.168.3.0       192.168.13.3             0             0 47887 ?
 

IOS vs IOS XR

As we know, the syntax is somehow different between the IOS and IOS XR, we will go the same examples we listed above and convert them to IOS XR syntax

IOS Command
IOS XR Command
show ip bgp regexp {Regular-Expression)
show bgp regexp {Regular-Expression}
ip as-path access-list 10 permit ^9038_44666$

as-path-set SET1
  ios-regex '^9038_44666$'
end-set
ip as-path access-list 11 permit _9038$
as-path-set SET2
  ios-regex '_9038$'
end-set
or
as-path-set SET2
  originates-from '9038'
end-set
ip as-path access-list 12 permit _3356_
as-path-set SET3
  ios-regex '_3356_'
end-set
or
as-path-set SET2
  passes-through '3356'
end-set
ip as-path access-list 14 permit _47887$

route-map ORIGIN permit 10
match as-path 14
set origin incomplete
route-map ORIGIN permit 20

router bgp 9038
address-family ipv4 unicast
neighbor 192.168.13.3 route-map ORIGIN in

as-path-set SET4
  ios-regex '_47887$'
end-set

route-policy ORIGIN
  if as-path in SET4 then
    set origin incomplete
  else
    pass
  endif
end-policy

router bgp 9038
neighbor 192.168.13.3
address-family ipv4 unicast
route-policy ORIGIN in
ip as-path access-list 10 permit ^9038_44666$

route-map LP permit 10
match as-path 10
set local-preference 300
route-map LP permit 20

router bgp 3356
address-family ipv4 unicast
neighbor 192.168.12.1 route-map LP in

as-path-set SET5
  ios-regex '^9038_44666$'
end-set

route-policy LP
  if as-path in SET5 then
    set local-preference 300
  else
    pass
  endif
end-policy

router bgp 9038
neighbor 192.168.12.1
address-family ipv4 unicast
route-policy LP in