- [Narrator] We've previously discussed the fact
that BGP Route Advertisements consist
of Network Layer Reachability Information, or NLRI,
and also various path attributes, or PAs.
So here, in order to understand
how BGP path selection works,
we want to expand upon those path attributes,
and actually, there are so many attributes
that they're broken down into four distinct categories.
Let's start with the first category,
which is what we call, well-known mandatory attributes.
These attributes must be presented in all BGP updates,
or the update will be ignored and considered invalid.
So we have listed here: ORIGIN, AS_PATH, and NEXT_HOP.
ORIGIN indicates how BGP learned about a particular network.
AS_PATH is essentially a list of all the autonomous systems
through which the update message has passed,
and NEXT_HOP identifies the next-hop IP address
that will be used to reach a certain destination.
The next category is well-known discretionary attributes.
As the name suggests,
these do not necessarily have to be identified.
They're optional,
and we can see the well known examples listed here
as local preference.
This is one of the ways that we can influence
our traffic path, specifically here if we're using iBGP.
This can identify the path
for traffic leaving a particular autonomous system.
The next category is optional transitive attributes.
Transitive meaning that these attributes are passed
on to other BGP routers, and of course, they're optional.
The big one that we use often here is
the COMMUNITY attribute.
This is a method for filtering,
where we assign a numerical value to a specific prefix.
This COMMUNITY value would be advertised to BGP neighbors,
and the neighbor will examine the COMMUNITY value
and then determine a proper action to take,
such as filtering or modifying other attributes,
and finally, we have optional non-transitive attributes.
A popular example of this is the MED value,
the multi-exit discriminator.
If you have multiple paths between your autonomous system
and a neighboring autonomous system,
this informs the neighboring autonomous system
about which path should be used for traffic bound
into your autonomous system.
Let's jump into our live interface now
and see our well-known attributes
with a verification command output.
Now here we have a simple topology.
You can see we have three routers
in three different autonomous systems.
So from router one, let's say show ip bgp,
and if we do that, we can see our known networks.
We see the 20.20.20.0 / 24 network,
which connects out to our three,
and we see the 10.10.10.0 network connecting to our one.
We also see networks 30.30.30.0 and 40.40.40.0.
Both of which were injected into BGP
with the network command on these routers.
If we look at the end of these statements,
notice you see this lowercase i that I've highlighted.
This is the origin code that we mentioned.
If we look at our status codes above that,
you can see the lowercase i indicates that this is IGP,
which is exactly what we would expect to see
when injecting routes with the network command.
If we had redistributed these routes,
we would see this incomplete status code
with a question mark, but in our case, we see that as IGP,
which is exactly what we would expect to see.
Next we see the path, which is the autonomous system path,
and actually to get a better to look at that,
let's jump over to router two,
and let's also say show ip bgp.
We still see the lowercase i, but under our path,
we have a couple of autonomous systems listed.
Notice there are two AS numbers listed here,
and we actually want to read these from right to left.
So for example,
will this 30.30.30.0 network-
That is on our three.
The AS path tells us that this prefix originated
in autonomous system, 65 300,
which you can see in our topology is router three,
and then it moved to autonomous system, 65 100,
which is of course where we see router one in the topology,
before that arrives here in the local autonomous system
on router two,
and we see our third well-known mandatory attribute,
which is the NEXT_HOP.
We can see those listed here, and of course the NEXT_HOP
for router two, that's pointing over to our one.
So these basic attributes are
how BGP chooses a route to a particular network,
and we can have some influence over those
if we want to shape our traffic.
BGP does not load balance by default, but instead it tries
to narrow down the path selection to one best path using
what's called a best path selection algorithm.
We need to understand this path selection criteria for BGP,
because it's different from other routing protocols
that you might be familiar with.
First, BGP will choose the route with the highest weight.
Weight is a Cisco specific parameter that is local
to the router where it's configured.
If the weight is not set, then BGP will prefer the path
with the highest local preference.
If that isn't specified,
that's going to default to a value of 100.
Next, BGP will prefer a path using routes
that originate from the local router by the network command,
the aggregate command,
or through redistribution from an IGP.
The network and redistribute commands are going to be preferred
over those that are identified by the aggregate command.
Then BGP will prefer the route
with the shortest, autonomous system path,
followed by the lowest origin type.
Remember we looked at some of the origin types
in the output of our show ip bgp command.
We had three origin code types.
A lowercase i, designating a prefix was learned
from an interior gateway protocol.
We had a lowercase e, meaning that it originated
from the EGP protocol, or a question mark,
meaning that it originated from some unknown source,
such as redistribution,
and that's the same order of preference here.
IGP is the lowest followed by EGP and then unknown.
Next would be the lowest multi exit discriminator value,
or MED value, which we use to denote a preferred path
that has multiple entry points, and again,
remember that is an optional attribute.
Next, BGP prefers an eBGP over an iBGP route,
then we prefer to choose a route
through the nearest IGP neighbor based
on the lowest IGP metric,
followed by choosing the oldest route,
or the route which was received first.
After this, we get into some tiebreaker attributes
for path selection.
First, BGP chooses a path through the neighbor
with the lowest router ID.
If we don't manually configure a router ID,
that's going to be set to the highest IP address on the router,
and the preference is going to be given to loopback addresses.
So don't confuse the highest and the lowest here.
If we don't manually configure the router ID,
it's going to be set
to the highest loopback in the up state.
If we don't have loopbacks in the up state,
then it's going to be set to the highest interface IP address,
but at this step,
the lowest router ID is going to be the preferred path,
then the path with the minimum cluster length,
and finally, the neighbor with the lowest IP address.