Thursday, January 26, 2012

BGP FILTERING + MISC CONVERGENCE + DEFAULT ROUTING

BGP FILTERING
--------------
BGP update filtering occues on per peer basis
with
neighbor "address" distribute-list
neighbor "address" filter-list
neighbor "addresss" prefix list

if we just done it like this like a neighbor was been filtered on distribute list,filterlist
and prefix list
we would not know whether the distribute list would go first and filter list next or would
the prefix list go first i.e the order of operation
A way to be sure would be use a route map
neighbor "address" route-map
you could say permit 10 a distribute-list
permit 20 would be filter-list
you would be sure of the order of operation

Another option which was used pre prefix list for matching prefix and subnet mask is a
extended access-list
access-list 100 deny ip host 150.28.4,0 host 255.255.255.0
access-list 100 permit ip any any

BGP Convergence
================
Hello and Keepalive timers
 - lowest timer are negotiated during peering establishment (so the lowest configured
neighbor is inheret by the other neighbor)
 -timers bgp
 - neighbor timers
Link down detection
  -bgp fast-external-failover  - if a router interface goes down it will auto converge for
that router it will not waitif for missing the keepalives

BFD (BIDIRECTIONAL FORWARDING DETECTION is availible also on BGP)

UPdate Timers
    - neighbor advertisement interval - how often will you advertise. LIke when you recieve 
      a prefix you will wait this advertise time before advertising
   
    - bgp nexthop {trigger{delay "seconds/enable} | route-map "map-name"}- this how often   
      you look for changes in nest hop to ensure that the route recursion will work
    - bgp scan time how often the bgp router will go through the router checkin attributes
      like if you changed as path update if you did not do route refresh you would need to  
    wait the scan time for it to go through the bgp table checking attributes
    - bgp update interval

BGP Default ROuting
--------------------
3 ways to originate default
   - default-information originate + redistribute for use when you are redistributing a
default route from another protocol say you have default in eigrp when you redistribute
eigrp to bgp by default it will not redistribute the default route unless you specify
   - network 0.0.0.0 mask 0.0.0.0
   - neighbor default-originate


LAB
----
We will start the LAB by generating a few routes and filtering so BB1 will generate the
111.1.1.1  & 112.1.1.1
r4 will generate 44.1.1.1.1
s1 will generate 55.1.1.0

we will have a look on r5
r5#sh ip bgp
BGP table version is 6, local router ID is 5.5.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
*  44.1.1.0/24      3.3.3.3                                0 300 100 i
*                   1.1.1.1                                0 100 i
*>                  4.4.4.4                  0             0 100 i
*> 55.1.1.0/24      3.3.3.3                                0 300 i
*                   1.1.1.1                                0 100 300 i
*                   4.4.4.4                                0 100 300 i
*  111.1.1.0/24     3.3.3.3                                0 300 100 54 i
*                   4.4.4.4                                0 100 54 i
*>                  1.1.1.1                                0 100 54 i
*  112.1.1.0/24     3.3.3.3                                0 300 100 54 i
*                   4.4.4.4                                0 100 54 i
*>                  1.1.1.1                                0 100 54 i
r5#


we will create a as path filter list deny as 100
r5(config)#ip as-path access-list 2 deny _100_
r5(config)#ip as-path access-list 2 permit .*


r5(config)#router bgp 400
r5(config-router)#neighbor 3.3.3.3 filter-list 2 in

r5#sh ip bgp
BGP table version is 10, local router ID is 5.5.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
*  44.1.1.0/24      1.1.1.1                                0 100 i
*>                  4.4.4.4                  0             0 100 i
*> 55.1.1.0/24      3.3.3.3                                0 300 i
*                   1.1.1.1                                0 100 300 i
*                   4.4.4.4                                0 100 300 i
*  111.1.1.0/24     4.4.4.4                                0 100 54 i
*>                  1.1.1.1                                0 100 54 i
*  112.1.1.0/24     4.4.4.4                                0 100 54 i
*>                  1.1.1.1                                0 100 54 i
r5#

anything with AS 100 int the path from r3 has been filtered we are sti
the only route we recieved from r3 55.1.1.0 as the only route from r3 with 100 in as-path

Distribute-list
we will do an extended access-list to match route + mask so we filter the route
112.1.1.0 with mask 255.255.255.0
r5(config)#access-list 112 deny ip host 112.1.1.0 host 255.255.255.0
r5(config)#access-list 112 permit ip any any

r5(config)#router bgp 400
r5(config-router)#neighbor 1.1.1.1 distribute-list 112 in

r5#sh ip bgp
BGP table version is 12, local router ID is 5.5.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
*  44.1.1.0/24      1.1.1.1                                0 100 i
*>                  4.4.4.4                  0             0 100 i
*  55.1.1.0/24      1.1.1.1                                0 100 300 i
*>                  3.3.3.3                                0 300 i
*                   4.4.4.4                                0 100 300 i
*  111.1.1.0/24     1.1.1.1                                0 100 54 i
*>                  4.4.4.4                                0 100 54 i
*> 112.1.1.0/24     4.4.4.4                                0 100 54 i
r5#
notice 112.1.1.0 is filtered now from 1.1.1.1

Prefix-list

r5(config)#ip prefix-list R4 deny 111.1.1.0/24
r5(config)#ip prefix-list R4 permit 0.0.0.0/0 le 32

r5#sh ip bgp
BGP table version is 7, local router ID is 5.5.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
*  44.1.1.0/24      4.4.4.4                  0             0 100 i
*>                  1.1.1.1                                0 100 i
*  55.1.1.0/24      4.4.4.4                                0 100 300 i
*>                  3.3.3.3                                0 300 i
*                   1.1.1.1                                0 100 300 i
*> 111.1.1.0/24     1.1.1.1                                0 100 54 i
*> 112.1.1.0/24     4.4.4.4                                0 100 54 i
r5#


We look at default routing now

r5#sh ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route
Gateway of last resort is 155.0.0.3 to network 0.0.0.0
     1.0.0.0/32 is subnetted, 1 subnets
D       1.1.1.1 [90/2297856] via 155.0.0.1, 00:04:50, Serial0/0/0
     2.0.0.0/8 is variably subnetted, 4 subnets, 2 masks
D       2.2.2.2/32 [90/2809856] via 155.0.45.4, 00:04:50, Serial0/1/0
D       2.3.3.0/24 [90/2303232] via 155.0.45.4, 00:00:25, Serial0/1/0
                   [90/2303232] via 155.0.0.4, 00:00:25, Serial0/0/0
                   [90/2303232] via 155.0.0.1, 00:00:25, Serial0/0/0
D       2.1.1.1/32 [90/2302976] via 155.0.45.4, 00:00:25, Serial0/1/0
                   [90/2302976] via 155.0.0.4, 00:00:25, Serial0/0/0
                   [90/2302976] via 155.0.0.1, 00:00:25, Serial0/0/0
D       2.4.4.4/32 [90/158720] via 155.0.58.2, 00:04:50, FastEthernet0/0
     155.0.0.0/24 is subnetted, 9 subnets
D       155.0.146.0 [90/2172416] via 155.0.45.4, 00:04:50, Serial0/1/0
                    [90/2172416] via 155.0.0.4, 00:04:50, Serial0/0/0
                    [90/2172416] via 155.0.0.1, 00:04:52, Serial0/0/0
D       155.0.23.0 [90/3193856] via 155.0.45.4, 00:04:52, Serial0/1/0
D       155.0.13.0 [90/2681856] via 155.0.0.1, 00:04:52, Serial0/0/0
C       155.0.0.0 is directly connected, Serial0/0/0
C       155.0.58.0 is directly connected, FastEthernet0/0
C       155.0.45.0 is directly connected, Serial0/1/0
D       155.0.79.0 [90/2175232] via 155.0.45.4, 00:00:27, Serial0/1/0
                   [90/2175232] via 155.0.0.4, 00:00:27, Serial0/0/0
                   [90/2175232] via 155.0.0.1, 00:00:27, Serial0/0/0
D       155.0.67.0 [90/2174976] via 155.0.45.4, 00:00:27, Serial0/1/0
                   [90/2174976] via 155.0.0.4, 00:00:27, Serial0/0/0
                   [90/2174976] via 155.0.0.1, 00:00:27, Serial0/0/0
D       155.0.108.0 [90/30720] via 155.0.58.2, 00:04:52, FastEthernet0/0
     3.0.0.0/32 is subnetted, 1 subnets
D       3.3.3.3 [90/2297856] via 155.0.0.3, 00:04:52, Serial0/0/0
     4.0.0.0/32 is subnetted, 1 subnets
D       4.4.4.4 [90/2297856] via 155.0.45.4, 00:00:27, Serial0/1/0
                [90/2297856] via 155.0.0.4, 00:00:27, Serial0/0/0
     5.0.0.0/32 is subnetted, 1 subnets
C       5.5.5.5 is directly connected, Loopback0
     6.0.0.0/32 is subnetted, 1 subnets
D       6.6.6.6 [90/2300416] via 155.0.45.4, 00:00:27, Serial0/1/0
                [90/2300416] via 155.0.0.4, 00:00:27, Serial0/0/0
                [90/2300416] via 155.0.0.1, 00:00:29, Serial0/0/0
     22.0.0.0/24 is subnetted, 1 subnets
D       22.2.2.0 [90/156160] via 155.0.58.2, 00:04:55, FastEthernet0/0
     12.0.0.0/32 is subnetted, 1 subnets
D       12.12.12.12 [90/2809856] via 155.0.45.4, 00:04:55, Serial0/1/0
S*   0.0.0.0/0 [120/0] via 155.0.0.3

r5(config)#router bgp 400
r5(config-router)#redistribute static
r5(config-router)#

we are getting no route
r5#sh ip bgp
r5#

r5(config)#router bgp 400
r5(config-router)#default-information origi
r5(config-router)#

this then allows a default route to be redistributed into the network
r5#sh ip bgp
BGP table version is 63, local router ID is 5.5.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
*> 0.0.0.0          155.0.0.3                0         32768 ?
r5#

r5
===
r5(config)#router bgp 400
r5(config-router)#no redistribute static
r5(config-router)#neighbor 3.3.3.3 default-originate


r3
---
r3# sh ip bgp
BGP table version is 159, local router ID is 3.3.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
*> 0.0.0.0          5.5.5.5                  0             0 400 i
r3#






Wednesday, January 25, 2012

REGULAR EXPRESSIONS

Regular Expressions
-------------------
used for string matching in
 - show command output
 - TCL/EEM scripting
 -BGP AS-PATH Access-list
 - BGP expanded community-list
DOcumented in
 - cisco ios terminal services configuration guide
 - Appendices
 - Reg Expression
Common Expressions
_100$ - originated in 100
^100_ - learned from 100
_100_ any instance of 100 in aspath
.* anything
[0-9] any number
+1  1 or more
say we wanted to search the bgp table for prefixes with an as path of exactly 2 AS
sh ip bgp regexp ^[0-9]+[0-9]+$
LAB
----
I am going log on to one of the public route servers
route-server.belwue.de

route-server>sh ip bgp regexp _100$
BGP table version is 268370706, local router ID is 193.196.190.135
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
r i63.150.46.0/24   80.81.194.26          8734    220      0 6461 22669 100 i
r i                 80.81.194.26          8734    220      0 6461 22669 100 i
r>i                 80.81.194.26          8734    220      0 6461 22669 100 i
r i65.160.57.0/24

we get the routes originating in AS 100


route-server>sh ip bgp regexp ^3549_

r i184.28.110.0/23  159.63.22.245        13398     80      0 3549 i
r>i                 159.63.22.245        13398     80      0 3549 i
r i                 159.63.22.245        13398     80      0 3549 i
r i184.28.112.0/23  159.63.22.245        13672     80      0 3549 i
r>i                 159.63.22.245        13672     80      0 3549 i
r i                 159.63.22.245        13672     80      0 3549 i
r i184.28.114.0/23  159.63.22.245        13569     80      0 3549 i
r>i                 159.63.22.245        13569     80      0 3549 i
r i                 159.63.22.245        13569     80      0 3549 i
r i184.28.116.0/23  159.63.22.245        13569     80      0 3549 i

BGP COMMUNITIES

BGP Communities
----------------
BGP Implementation of a ROute tag
used to group prefixes togther for
 - advertisement
 - filtering policy
 - bestpath selection policy
community is an optional transitive attribute
  - not exchanged between peers by default
neighbor "ip address" send-community
BGP Community Values
---------------------
Standard community is a 4 byte value
can be denoted as
- Decimal (0-4294967296)
- AA:NN (0:0-65535:65535)
ip bgp-community new-format
same binary value regardless of visual format

3 Well Known  values are reserved

WELL KNOwN
----------
No export (0xFFFFFF01)
   - dont advertised to ebgp peers (Specfically EBGP peers)
No Advertise (0xFFFFFF02)
   - dont advertise to any peers
Local-AS (0xFFFFFF03)
   - DO not advertise to confed EBGP peers or Regular EBGP peers
   - RFC defines as NO-export-subconfed

Matching and Setting Communities
--------------------------------
Set occur directly in route-map
 - set communities {community-number [additive] [well known] none}
 - Not 'additive' by default
Match Occurs via community list
  - define list
      - standard list matches community none or number
      - ip community-list 1 standard permit no-export
   -expanded matches regular expressions
      - ip community-list expanded AS100 permit 100:[0-9]+
   - reference from route-map
       - match AS 100
Internet community tends to be every thing
if you set to none it strips the community attribute
additive - add to community list + does not remove previous values
generally providers will do additive on the internet
There is alot of agreed upon communities depending on server provider so you may be in case
you provider if you send me a community 500:70 i will make the following change to bgp
attribute it could be local preference as path prepend etc

LAB
----
OK on s1 i am advertising the route 22.1.1.1/32

r3
---

r3#sh ip bgp
BGP table version is 36, local router ID is 3.3.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
*>i22.1.1.1/32      2.1.1.1                  0    100      0 i
r3#

sw3
---
s3#sh ip bgp
BGP table version is 30, local router ID is 2.3.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
*>i22.1.1.1/32      2.1.1.1                  0    100      0 i
s3#

r5
---
r5#sh ip bgp
BGP table version is 15, local router ID is 5.5.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
*  22.1.1.1/32      1.1.1.1                 10             0 100 100 300 i
*                   4.4.4.4         4294967295             0 100 100 300 i
*>                  3.3.3.3                  5             0 300 i
r5#

S1
---

We will create a prefix list to match the route advertisement
s1(config)#ip prefix-list COMM permit 22.1.1.1/32
s1(config)#

ok we will create a route-map
s1(config)#route-map COMM permit 10
s1(config-route-map)#match ip address prefix COMM
s1(config-route-map)#set community no-export
s1(config-route-map)#
which matches the prefix list and set community to no-export

s1(config-router)#router bgp 300
s1(config-router)#neighbor IBGP route-map COMM out
s1(config-router)#neighbor IBGP send-community

r3
==
r3#sh ip bgp
BGP table version is 40, local router ID is 3.3.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
*>i22.1.1.1/32      2.1.1.1                  0    100      0 i
r3#sh ip bgp 22.1.1.1
BGP routing table entry for 22.1.1.1/32, version 40
Paths: (1 available, best #1, table Default-IP-Routing-Table, not advertised to EBGP peer)
Flag: 0x820
  Not advertised to any peer
  Local
    2.1.1.1 (metric 20645120) from 2.1.1.1 (22.1.1.1)
      Origin IGP, metric 0, localpref 100, valid, internal, best
      Community: no-export
r3#

we get with the attribute set


s3
---
s3#sh ip bgp
BGP table version is 34, local router ID is 2.3.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
*>i22.1.1.1/32      2.1.1.1                  0    100      0 i
s3#sh ip bgp 22.1.1.1
BGP routing table entry for 22.1.1.1/32, version 34
Paths: (1 available, best #1, table Default-IP-Routing-Table, not advertised to EBGP peer)
  Not advertised to any peer
  Local
    2.1.1.1 (metric 130816) from 2.1.1.1 (22.1.1.1)
      Origin IGP, metric 0, localpref 100, valid, internal, best
      Community: no-export
s3#

r5
---
r5#sh ip bgp
r5#

we do not get the route as the no-export comm is set

NO ADVERTISE
-------------

s1(config)#route-map COMM
s1(config-route-map)#match ip address prefix-list COMM
s1(config-route-map)#set community no-advertise
s1(config-route-map)#

r3
---


r3#sh ip bgp
BGP table version is 42, local router ID is 3.3.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
*>i22.1.1.1/32      2.1.1.1                  0    100      0 i
r3#sh ip bgp 22.1.1.1/32
BGP routing table entry for 22.1.1.1/32, version 42
Paths: (1 available, best #1, table Default-IP-Routing-Table, not advertised to any peer)
Flag: 0x820
  Not advertised to any peer
  Local
    2.1.1.1 (metric 20645120) from 2.1.1.1 (22.1.1.1)
      Origin IGP, metric 0, localpref 100, valid, internal, best
      Community: no-advertise



S3 is recieving
----------------
s3#sh ip bgp
BGP table version is 36, local router ID is 2.3.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
*>i22.1.1.1/32      2.1.1.1                  0    100      0 i
s3#sh ip bgp 22.1.1.1
BGP routing table entry for 22.1.1.1/32, version 36
Paths: (1 available, best #1, table Default-IP-Routing-Table, not advertised to any peer)
  Not advertised to any peer
  Local
    2.1.1.1 (metric 130816) from 2.1.1.1 (22.1.1.1)
      Origin IGP, metric 0, localpref 100, valid, internal, best
      Community: no-advertise
s3#

r5
---
r5#sh ip bgp
r5#

MED,MED DETERMINISTIC ALWAY COMPARE

MED
----

By default
The comparison of med only occurs if the first AS is the same in the 2 paths or
in other words we will only use med when we have multiple connections to the same AS
Med is non transitive meaning it will not go from AS to As so if i am r1 in AS1 and
advertise
med 100 to r2 in AS 2 r2 will not advertise this on to r3 in AS3

Lowest Med is the preference
route-map TO-R5
set metric 100
router BGP 100
neighbor 155.28.0.5 route-map TO-R5 out

You have to watch out for potential issue here say we are on r1 in AS1 and sending to r5 AS2
r5 will recieve this route from r1 with med of 100 if r5 is connected router AS1 say r3 it
may recieves
this route with a null metric. Some ios will interpret the null value as 0. So when we come
to compare
if everything is a tie up till the med it will compare of 0 vs 100 med so the 0 route will
win.
We can change this default behaviour by using the command
router bgp 400
bgp bestpath med missing-as-worst

if we do this a missing/null  will be interpreted as the highest med value so least
preference.

As stated above the comparison of med only occurs if the first AS is the same in both paths.
We can override this
so it will compare med from path from different AS. We do this with the command
bgp always compare med

LAB
----
I look at the various med related commands
so the lab will be that bb1 in AS 54 is advertising network 111.1.1.0/24
R1 will advertise the path via r6>>>bb1 while r4 should advertise the path via r4>>bb3>>bb1
to r5

r5
---
r5#sh ip bgp
BGP table version is 22, local router ID is 5.5.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
*  111.1.1.0/24     3.3.3.3                                0 300 100 54 i
*                   1.1.1.1                                0 100 54 i
*>                  4.4.4.4                                0 100 54 i

At the moment this is the status i want the routes to be all even when it comes to the bgp
selection policy up until moment at the moment 3.3.3.3 has as path of 3 compared to 1.1.1.
and 4.4.4.4 which is aspath of 4
I am going do an ASPATH prepend for r1 advertising to r5 and same for r4 advertising to r5
r5#sh ip bgp
BGP table version is 24, local router ID is 5.5.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
*  111.1.1.0/24     1.1.1.1                                0 100 100 54 i
*                   4.4.4.4                                0 100 100 54 i
*>                  3.3.3.3                                0 300 100 54 i

ok now it is all equal it is choosing 3.3.3.3 this is going be by one of the tie breakers
oldest route table i would imagine since we cleared the process to apply the aspath change
for both 1.1.1.1 and 4.4.4.4

I am going set the metric for the route to 20 on 3.3.3.3 and the metric to 1 on 1.1.1.1

R3
----
Ok we will set route-map to change the med and assign to 5.5.5.5 out
r3(config)#route-map MED permit 10
r3(config-route-map)#set metric 20
r3(config-route-map)#exit
r3(config)#router bgp 300
r3(config-router)#neighbor 5.5.5.5 route-map MED to 20 out
r3(config-router)#


r1
===

Same on r1 except we are setting to metric 10
r1(config)#route-map PREPEND permit 10
r1(config-route-map)#set metric 10
r1(config-route-map)#exit
r1(config)#do sh run | sec router
router bgp 100
 no synchronization
 bgp log-neighbor-changes
 aggregate-address 155.0.0.0 255.255.0.0 summary-only
 neighbor IBGP peer-group
 neighbor IBGP remote-as 100
 neighbor IBGP update-source Loopback0
 neighbor 3.3.3.3 remote-as 300
 neighbor 3.3.3.3 disable-connected-check
 neighbor 3.3.3.3 update-source Loopback0
 neighbor 4.4.4.4 peer-group IBGP
 neighbor 5.5.5.5 remote-as 400
 neighbor 5.5.5.5 disable-connected-check
 neighbor 5.5.5.5 update-source Loopback0
 neighbor 5.5.5.5 route-map PREPEND out
 neighbor 6.6.6.6 peer-group IBGP
 no auto-summary

r5#sh i
*Jan 25 20:38:56.863: %SYS-5-CONFIG_I: Configured from console by consolep bgp
BGP table version is 26, local router ID is 5.5.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
*  111.1.1.0/24     3.3.3.3                 20             0 300 100 54 i
*                   1.1.1.1                 10             0 100 100 54 i
*>                  4.4.4.4                                0 100 100 54 i
r5#config t

ok r4 was chooosen as the best route this either because the metric null is picked up as 0
are we are ignoring med as they are from different AS


5(config)#router bgp 400
r5(config-router)#bgp bestpath med missing-as-worst
r5(config-router)#exit
r5(config)#exit

r5#sh ip bgp
BGP table version is 2, local router ID is 5.5.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
*> 111.1.1.0/24     1.1.1.1                 10             0 100 100 54 i
*                   4.4.4.4         4294967295             0 100 100 54 i
*                   3.3.3.3                 20             0 300 100 54 i

it is choosen so it looks good lets try lowering the med on r3 and see does it select that
as the best route

so on r3
-----------
r3(config)#route-map MED permit 10
r3(config-route-map)#no set metric 20
r3(config-route-map)#set metric 5
r3(config-route-map)#

it is as i thought it was order of operation why 1.1.1.1 got selected the routes were
probably of all same age it did not compare the med and as 1.1.1.1 it probably ran route id

r5#sh ip bgp
BGP table version is 2, local router ID is 5.5.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
*  111.1.1.0/24     3.3.3.3                  5             0 300 100 54 i
*>                  1.1.1.1                 10             0 100 100 54 i
*                   4.4.4.4         4294967295             0 100 100 54 i
r5#

r1 is remaining the best route even though 3.3.3.3 has lower metric this is because by
default med will be only compared from paths from the 2 same AS

ALWAYS COMPARE MED on DETEMISTIC MED OFF
=====================================

r5(config)#router bgp 400
r5(config-router)#bgp always-compare-med
r5(config-router)#


r5#sh ip bgp
BGP table version is 2, local router ID is 5.5.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
*  111.1.1.0/24     4.4.4.4         4294967295             0 100 100 54 i
*                   1.1.1.1                 10             0 100 100 54 i
*>                  3.3.3.3                  5             0 300 100 54 i
r5#
since it is always compare it comparing med from multiple AS so r3 routes wins

NO ALWAYS COMPARE MED + DETERMINISTIC MED ON
---------------------------------------------

r5(config)#router bgp 400
r5(config-router)#bgp deterministic-med
r5(config-router)#

r5#sh ip bgp
BGP table version is 2, local router ID is 5.5.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
*  111.1.1.0/24     3.3.3.3                  5             0 300 100 54 i
*>                  1.1.1.1                 10             0 100 100 54 i
*                   4.4.4.4         4294967295             0 100 100 54 i

OK so r1 and r4 are compared r1 is selected as the best then compared to r3 but since bgp
always compare med is off med is not checked and r1 is selected as the best route based on
lowest route id.
ALWAYS COMPARE MED ON + DETERMINISTIC MED ON
---------------------------------------------
config)#router bgp 400
r5(config-router)#bgp always-compare-med
r5(config-router)#bgp deterministic-med
r5(config-router)#

r5#sh ip bgp
BGP table version is 2, local router ID is 5.5.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
*  111.1.1.0/24     1.1.1.1                 10             0 100 100 54 i
*                   4.4.4.4         4294967295             0 100 100 54 i
*>                  3.3.3.3                  5             0 300 100 54 i

Tuesday, January 24, 2012

BGP LOCAL PREF ,LOCAL PREF WITH COMMUNITIES & AS PATH PREPENDING

BGP LOCAL PREFERENCE
--------------------
So local preference is the next in path selection after weight
local Pref affect AS wide and influence path selection for all routers
int the AS for the routes set
SO it is set on inbound control plane traffic (updates)
and will affect outbound dataplance traffic decisions
Highest is best
default value is 100

route-map FROM-BB1
set local-preference 101
router bgp 100
neighbor 54.28.1.254 route-map FROM-BB1 in

There is an option the most service providers or should give as of teh RFC 1998 Using
Communties for Local Preference. It basically details that service provider should on
recieving routes with the community of
any of the following 
"SP AS" : 70
"SP:AS" : 80
"SP:AS" :90     
you should the local pref for that route to 70,80 or 90 depending on which was recieved.
So this would influence return path to my AS

Communties are transitive so this is a good option for influencing as it will be passed AS
to AS

Another option for influencing how network get to you could be set AS Path Prepending
i.e in update set your AS multiple times making the AS path longer + less desirable
route-map TO-R2
set as-path prepend 300 300 300 300
router bgp 300
neighbor 155.28.23.2 route-map TO-R2 out

LAB
---

OK for the lab same scenerio as last lab. BB1 is advertising 11.1.1.1 r1 is recieving
11.1.1.1 from both r6 and r4. The path selection is tied right up till metric to next hop
and it selects r4 as it has shorter metric to the next hop on bb3 then the next hop on bb1
we want to influence all router in the AS to take the router 6 path rather than the r4 path

r1
--
r1#sh ip bgp
BGP table version is 16, local router ID is 1.1.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
*>i11.1.1.1/32      172.25.13.3              0    100      0 54 i
* i                 10.229.254.1             0    100      0 54 i
r1#

we see it is using next hop of bb3 for the best route

r6
---
ok on r6

we create a route map setting local-pref 110
r6(config)#route-map LOCAL permit 10
r6(config-route-map)#set local-pref 110
r6(config-route-map)#exit

then on router bgp for the neighbor relationship to bb1 we say for routes coming in from
this neighbor set the local preference. We set it coming in to affect the dataplane traffic
going out
r6(config)#router bgp 100
r6(config-router)#neighbor 10.229.254.1 route-map LOCAL in
r6(config-router)#

on r6
r6#sh ip bgp
BGP table version is 2, local router ID is 6.6.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
*> 11.1.1.1/32      10.229.254.1             0    110      0 54 i
r6#

we see the local pref has changed to 110

we are recieving both routes one from r6 the other from bb2
r4#sh ip bgp
BGP table version is 3, local router ID is 4.4.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
*>i11.1.1.1/32      10.229.254.1             0    110      0 54 i
*                   172.25.13.3                            0 54 i
r4#

we are selecting the r6 as of the local preference

on r1
r1#sh ip bgp
BGP table version is 17, local router ID is 1.1.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
*>i11.1.1.1/32      10.229.254.1             0    110      0 54 i
r1#

we only get the one route as r4 is not sending the route via bb3 as it has not choosen that
as the best route
OK i will do quick lab on local preference affect incoming taffic through the use of
communities

so r5  AS 400 has ebgp connections to r4 and r1 in AS 100

r5#sh ip bg
*Jan 24 21:41:14.559: %SYS-5-CONFIG_I: Configured from console by consolep
BGP table version is 113, local router ID is 5.5.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
*  11.1.1.1/32      4.4.4.4                                0 100 54 i
*                   3.3.3.3                                0 300 100 54 i
*>                  1.1.1.1                                0 100 54 i
r5#

On r5 currently we are choosing 1.1.1.1 r1 as entry to AS 100 to get to AS 54
we want to use local prefernce to influence it onto r4 with communities

so on r5
---------
we specify the community list
r5(config)#ip community-list 1 permit 500:120
r5(config)#route-map MATCH
r5(config-route-map)#match community 1
r5(config-route-map)#set local-pref 120

so we have a route map matching community 1 which is 500:120 if that is present we will sent
the local preference

r5(config)#router bgp 400
r5(config-router)#neighbor 4.4.4.4 route-map MATCH in
r5(config-router)#
we have applieds for route from r4

r4
---

OK we have create a route-map in r4 setting the community to 500:120
r4(config)#route-map SET
r4(config-route-map)#set community 500:120

r4(config)#router bgp 100
r4(config-router)#neighbor 5.5.5.5 route-map SET out
r4(config-router)#neighbor 5.5.5.5 send-community
so we apply the route-map to neighbor 5..5.5.5 in the outbound direction


r5
---
r5#sh ip bg
*Jan 24 22:02:35.903: %SYS-5-CONFIG_I: Configured from console by consolep
BGP table version is 3, local router ID is 5.5.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
*> 11.1.1.1/32      4.4.4.4                       120      0 100 54 i
*                   1.1.1.1                                0 100 54 i
*                   3.3.3.3                                0 300 100 54 i

we are now choosing the via r4 as the local preference is 120

ANother way we could do this is by using the AS Path Prepending

I have defaulted it back

r5#sh ip bgp
BGP table version is 2, local router ID is 5.5.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
*  11.1.1.1/32      4.4.4.4                                0 100 54 i
*>                  1.1.1.1                                0 100 54 i
*                   3.3.3.3                                0 300 100 54 i
r5#

ok we will do this from r1


r1
---
r1(config)#route-map ASPATH permit 10
r1(config-route-map)#set as-path prepend 100 100 100

ok for r1 i have created a route-map setting AS-Path to an extra 3 AS's

r1(config)#router bgp 100
r1(config-router)#neighbor 5.5.5.5 route-map ASPATH out
r1(config-router)#

so i have set the ASPATH out outbound to affect the incoming taffic path

r5#sh ip bgp
BGP table version is 3, local router ID is 5.5.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
*  11.1.1.1/32      1.1.1.1                                0 100 100 100 100 54 i
*>                  4.4.4.4                                0 100 54 i

we are seeing now r1 is sending AS path of 5 compared to r4 which is 2 so no r4 is the
preference/







BGP BESTPATH & WEIGHT

BGP BESTPATH SELECTION
-----------------------
Chooses which routes can be
 - installed in the rib/fib
 - advertised to other IBGP Peers
    (best path is the only one to be advertised)
 - In general path selection is standard
     - Decision Process RFC 4271

Best Path Selection Prerequisites
----------------------------------
There are few prerequsites that need to be met before we will even start looking at the
path selection
* Next-hop value must be in the routing table - this prevents route recursion failures
*synchronisation rule must be met or disabled- synch was legacy blackhole prevention technique
*AS-Path must not contain local-as - normal EBGP loop prevention
*First ASN in path must be neighbor ASN- bgp enforce-first-as - on by default

How the Best Path Algorithm works
--------------------------------
Checks in prerequisites are met. Then it works in top down fashion once it matches it leaves the algorithm not processing
through the other steps

1. Prefer path with highest weight (locally significant)
2. Prefer path with highest local pref
3. Prefer locally Originated (via network or redistribution or aggregate. Locally sourced redisribution / network are
   prefered over aggregation
4.Prefer the path with the shortest AS path
    - step can be skipped if you configure bgp bestpath-aspath-ignore
    - An as-set counts as 1 no matter how AS are in the set
    - AS-confed squence + confed set are not included in the AS path lenght
5.Prefer IGP Path lowest origin- IGP is lower than EGP (legacy pre bgp) which is lower than incomplete (?) redistributed routes
6.Prefer the path with the lowest med
7.Prefer EBGP over IBGP
8.Prefer the path with the lowest metric to next hop
9.then we move into the tie breakers one thing to note if 2 routes have the same aspath and
the same 1-8 on the best path algorithm they can utilise load balancing with bgp multipath
10. When both paths are external prefer the path that we recieved first- if you have bgp bestpath compare-routerid enabled
this step is skipped
11.Prefer the route that comes from the BGP with the lowest router-id
12.Prefer the shortest cluster-list - min no of route reflectors the route has gone through
13.Prefer Lowest neighbor address

multipath can be done with the command
router bgp 100
maximum-paths ibgp 2

When editing attribute like the weight local preference etc
remeber that
OUtbound routing policy affect inbound traffic
Inbound routing policy affects outbound traffic
weight & local pref
 - Set INBOUND
 - Affects outbound traffic
AS-PATH & MED
- set outbound
-affects inbound traffic

WEIGHT
---------
is locally significant highest weight is best. Although it locally significant it can affect AS decision as if particular router
change it > best route in bgp it will start advertising this route to peers. BGP we only advertise our best routes

LAB
----




bb1
---
we will advertise a route

bb1(config)#router bgp 54
bb1(config-router)#network 11.1.1.1 mask 255.255.255.255

r1#sh ip bgp
BGP table version is 8, local router ID is 1.1.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
* i11.1.1.1/32      10.229.254.1             0    100      0 54 i
*>i                 172.25.13.3              0    100      0 54 i
r1#

BB1 advertises the route to r6 and to bb3. Then bb3 adverises the route to r4

OK r1 is receving this from r6 and r4 then

 has selected the next hop of 172.25.13.3 which is the segement between r4 and bb3

r1#sh ip bgp
BGP table version is 8, local router ID is 1.1.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
* i11.1.1.1/32      10.229.254.1             0    100      0 54 i
*>i                 172.25.13.3              0    100      0 54 i
r1#
r1#sh ip bgp 11.1.1.1 255.255.255.255
BGP routing table entry for 11.1.1.1/32, version 8
Paths: (2 available, best #2, table Default-IP-Routing-Table)
  Advertised to update-groups:
     2
  54
    10.229.254.1 (metric 2172416) from 6.6.6.6 (6.6.6.6)
      Origin IGP, metric 0, localpref 100, valid, internal
  54
    172.25.13.3 (metric 30720) from 4.4.4.4 (4.4.4.4)
      Origin IGP, metric 0, localpref 100, valid, internal, best
r1#

if we look at this in more detail to figure why it choose the next hop route of 172.25.13.3

FOr the prereq both have valid next hop
r1#ping 10.229.254.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.229.254.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 68/68/68 ms
r1#
r1#ping 172.25.13.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.25.13.3, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/4/4 ms
r1#

we meet all prerequisites

1)the weight both are 0 so moves on
2)the local preference both are 100 some moves on
3)the networks are coming from another as so not locally originated so onto next
4)both have as path of 1 so goes onto next
5)both origin type are igp (i) so next
6)both metric are 0 so next
7)Both paths are learnt via igp so onto next
8) THis is where it is decided

r1#sh ip route 172.25.13.3
Routing entry for 172.25.13.0/24
  Known via "eigrp 1", distance 170, metric 30720, type external
  Redistributing via eigrp 1
  Last update from 155.0.146.4 on FastEthernet0/0, 01:10:30 ago
  Routing Descriptor Blocks:
  * 155.0.146.4, from 155.0.146.4, 01:10:30 ago, via FastEthernet0/0
      Route metric is 30720, traffic share count is 1
      Total delay is 200 microseconds, minimum bandwidth is 100000 Kbit
      Reliability 255/255, minimum MTU 1500 bytes
      Loading 1/255, Hops 1
r1#sh ip route 10.229.254.1
Routing entry for 10.229.254.0/24
  Known via "eigrp 1", distance 90, metric 2172416, type internal
  Redistributing via eigrp 1
  Last update from 155.0.146.6 on FastEthernet0/0, 00:58:36 ago
  Routing Descriptor Blocks:
  * 155.0.146.6, from 155.0.146.6, 00:58:36 ago, via FastEthernet0/0
      Route metric is 2172416, traffic share count is 1
      Total delay is 20100 microseconds, minimum bandwidth is 1544 Kbit
      Reliability 255/255, minimum MTU 1500 bytes
      Loading 1/255, Hops 1

we have a lower metric to 172.25.13.3 30720 vs 2172416
if we had got passed we could used multipath but since we havent it will not work

 r1(config)#router bgp 100
r1(config-router)#maximum-path 2
r1(config-router)#exit

it will not work as the metric are different to next hop
r1#sh ip bgp
BGP table version is 12, local router ID is 1.1.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
*>i11.1.1.1/32      172.25.13.3              0    100      0 54 i
* i                 10.229.254.1             0    100      0 54 i
r1#sh ip route 11.1.1.1
Routing entry for 11.1.1.1/32
  Known via "bgp 100", distance 200, metric 0
  Tag 54, type internal
  Last update from 172.25.13.3 00:09:13 ago
  Routing Descriptor Blocks:
  * 172.25.13.3, from 4.4.4.4, 00:09:13 ago
      Route metric is 0, traffic share count is 1
      AS Hops 1
      Route tag 54

Ok Lets have a look at weight

say we want r4 not to go it directly connected network BB3 instead we want it to go r6 >> BB1

r4(config)#router bgp 100
r4(config-router)#neighbor 6.6.6.6 weight 100
r4(config-router)#exit
r4(config)#exit

r4#sh ip bgp
BGP table version is 2, local router ID is 4.4.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
*  11.1.1.1/32      172.25.13.3                            0 54 i
*>i                 10.229.254.1             0    100    100 54 i

now r4 is choosing 10.229.254.1 as it next hop
r4#traceroute 11.1.1.1
Type escape sequence to abort.
Tracing the route to 11.1.1.1
  1 155.0.146.6 4 msec 0 msec 0 msec
  2 10.229.254.1 36 msec *  32 msec
r4#

it is going out r6 then bb1

r4#sh ip route bgp
     11.0.0.0/32 is subnetted, 1 subnets
B       11.1.1.1 [200/0] via 10.229.254.1, 00:03:01
r4#

now lets look at the affect on r1

r1#sh ip bgp
BGP table version is 15, local router ID is 1.1.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
*>i11.1.1.1/32      10.229.254.1             0    100      0 54 i
r1#

r1 is now select the route via r6 as it never recieves the route via r4 as
r4 has now choosen the route via R6 it no longer advertise the other route as in BGP we only advertise our best routes

BGP INJECT AND EXIST MAP

BGP CONDITIONAL ROUTE INJECTION
--------------------------------
Originates subnets from aggregate for purpose of longest match traffic engineering
It is like the opposite of aggregation. Agreggation you taking specfic subnets and generating a less specfic match. BGP Conditional Route Injection is generating a specfic subnet from an aggregate in the bgp table.

Inject-map
- subnet to be advertised
-set ip address prefix-list "list"

Exist Map
- Aggregate to be originate from
- match ip address prefix-list "list"
-match ip route-source prefix-list "list"

THe summary route has to be in the BGP table before we can generate the specfic subnet we can generate any subnet that is part of summary route

LAB
----
OK for this LAB r1 is going originate a route summary for the loopbacks in AS100

r1
---
r1(config)#router bgp 100
r1(config-router)#network 155.0.0.0 mask 255.255.255.0
r1(config-router)#exit
r1(config)#do sh ip bgp
BGP table version is 6, local router ID is 1.1.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
*> 155.0.0.0/24     0.0.0.0                  0         32768 i
r1(config)#

The first thing is to get a subnet of the summary into the bgp table

r1(config)#router bgp 100
r1(config-router)#aggregate-address 155.0.0.0 255.255.0.0 summary-only
we are setting as summary only

BB1
----

bb1#sh ip bgp
BGP table version is 4, local router ID is 10.229.254.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal
Origin codes: i - IGP, e - EGP, ? - incomplete
   Network          Next Hop            Metric LocPrf Weight Path
* i155.0.0.0        172.25.13.4                   100      0 100 i
*>                  10.229.254.6                           0 100 i
bb1#

we recieved the summary from 2 source one via our ibgp relationship with bb3 and the other with our ebgp relationship with r6 as ebgp is preferred ibgp we will always select the ebgp route

BB3
----
bb3#sh ip bgp
BGP table version is 4, local router ID is 133.133.133.133
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal
Origin codes: i - IGP, e - EGP, ? - incomplete
   Network          Next Hop            Metric LocPrf Weight Path
* i155.0.0.0        10.229.254.6                  100      0 100 i
*>                  172.25.13.4                            0 100 i

same story on BB3

Now lets look at use an inject map to influence the decision I want bb3 traffic to route via r6 rather than r4 to r1 address 155.0.0.1

r6
--
first thing i need to make sure the summary route in the bgp table
r6(config)#do sh ip bgp
BGP table version is 10, local router ID is 6.6.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
r>i155.0.0.0        1.1.1.1                  0    100      0 i
r6(config)#

we can do sh ip bgp
r6#sh ip bgp 155.0.0.0
BGP routing table entry for 155.0.0.0/16, version 10
Paths: (1 available, best #1, table Default-IP-Routing-Table, RIB-failure(17))
  Advertised to update-groups:
     2
  Local, (aggregated by 100 1.1.1.1)
    1.1.1.1 (metric 156160) from 1.1.1.1 (1.1.1.1)
      Origin IGP, metric 0, localpref 100, valid, internal, atomic-aggregate, best
r6#

to check the from field

The first thing is we need to define prefix list to match the source
r6(config)#ip prefix-list ROUTE-SOURCE permit 1.1.1.1/32

next we need to match the summary route
r6(config)#ip prefix-list AGGREGATE permit 155.0.0.0/16
Next define a the prefix we wish to generate
r6(config)#ip prefix-list SUBNET permit 155.0.0.3/32

we will define a route-map to bring togther the route-srouce and the aggregate
r6(config)#route-map MATCH permit 10
r6(config-route-map)#match ip route-source prefix ROUTE-SOURCE
r6(config-route-map)#match ip address prefix AGGREGATE
r6(config-route-map)#

we will create a route-map to generate the subnet 155.0.0.1/24 in prefix list subnet

r6(config)#route-map SUBNET
r6(config-route-map)#set ip address prefix-list SUBNET
r6(config-route-map)#
r6#

next we will create the inject and exist map

r6
---
r6(config)#router bgp 100
r6(config-router)#bgp inject-map SUBNET exist-map MATCH
r6(config-router)#

so this is saying that inject the subnet in prefix-list subnet if  both the source and the route aggregate is in the bgp table

we can see it is generating on r6

r6#sh ip bgp
BGP table version is 3, local router ID is 6.6.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
*>i155.0.0.0        1.1.1.1                  0    100      0 i
*>i155.0.0.3/32     1.1.1.1                                0

BB3
------
bb3#sh ip bgp
BGP table version is 3, local router ID is 133.133.133.133
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal
Origin codes: i - IGP, e - EGP, ? - incomplete
   Network          Next Hop            Metric LocPrf Weight Path
* i155.0.0.0        10.229.254.6                  100      0 100 i
*>                  172.25.13.4                            0 100 i
*>i155.0.0.3/32     10.229.254.6                  100      0 100 ?
bb3#

ok so now on BB3 we see that the route 155.0.0.0/16 summary is going from BB3 >>>>>>>> r4
But from BB3 to 155.0.0.3 the specfic route is going from BB3 to BB1 then to r6 then to r1 so we have traffic engineered via the more specfic route that we injected

BB1
---
bb1#sh ip bgp
BGP table version is 11, local router ID is 10.229.254.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal
Origin codes: i - IGP, e - EGP, ? - incomplete
   Network          Next Hop            Metric LocPrf Weight Path
*> 155.0.0.0        10.229.254.6                           0 100 i
* i                 172.25.13.4                   100      0 100 i
*> 155.0.0.3/32     10.229.254.6                           0 100 ?
bb1#