Thursday, January 24, 2013

你将如何衡量投资?

投资的定义因人而异,而用来形容它,即通俗又简单的三个字就是“钱找钱” 吧!投资就真得非得用到金钱吗?总会有人说,“哇老, 投资什么鸟哦,我又没钱”,“如果投资能找钱的话,没有人做工了咯”  你应该不是其中一位吧!?而我对投资的理解是,任何事情若有干涉到“付出”, “回报”和“风险”,就是投资的一种了。而它,也不一定非得干涉到与钱有关的活动。
举个很简单的例子: 中学时,我总觉得读书本身是没有意义的,是为了读书而读书。但为了那张“文凭”, 我只好漫无目的地“读”, 但既是如此, 还会有拿不到文凭的可能“如果国语不及格了”。这里面包含了付出,回报和风险,对我个人而言,也是投资的一种。
曾经阅读过无数句有关投资的名句精华,而有一句是让我印象深刻的, “ Investing in yourself is the best investment you will ever make. It will not only improve your life, it will improve the lives of all those around you”. “投资在自己身上将会是你这辈子最成功的投资。它不但会改善你自己的生活,也会改善你周边的人的生活。” 而投资最不可缺乏的并不是金钱,而是知识。只有知识,是不会随着时间,环境而逐渐减少的。
当然,有投资者因为犯了某些错误,而投资失败了,就认为自己没有投资的能力,并不适合当投资者而放弃了。而有些,却继续努力研究,希望自己能在投资界创出自己的一片天空。回报,有时也很抽象,当投资者犯错而得不到回报甚至还赔上了金钱时,难道时间,金钱与精力就白白浪费了吗?并不是的,他们也从中得到了宝贵的经验,而曾犯下的那错误,将会是今后提醒自己一生,不再犯下同一个错误的工具啊!这也是收获的一种吧!?曾经看过这么一句,“所有坏的事情到最后都会变成好事,如果还没的话,那代表你还没走到最后”
一个好的投资者所需要具备的其中一个条件是有清晰的目标,知道自己要得到什么,而在这过程中,自己得放弃与付出什么来得到自己想要的东西。当你觉得自己所要付出的,远远比收获的来得多来得重要,那就适而止步吧!为了投资而投资,本身绝对是没有意义的。
想要在投资界闯出一片天,首先就要有对投资含有热爱及理性的激情,只有当我们做着喜欢及足够热爱的事物时,我们才不会轻易地放弃,并坚持到最后。曾经,一名美籍哈佛教授,Clayton M. Christesen在课堂上说过,人在自己的一生中,一定要问自己三个问题。第一个问题是: 你需要问自己对怎样的工作,怎样的工作环境是热爱的。因为,如果你对自己的工作并不喜欢及热爱,你将浪费及燃烧你的一生,若你人生大部分时间都花在工作上。
在此,希望大家能找到自己热爱的工作,热爱的兴趣,不管是投资还是在哪个领域,只要坚持不懈,一定也会闯出属于自己的那一片天空!

Tuesday, January 8, 2013

[转贴] 37歲就退休的投資大師

愛消費是個錯誤!
整理者:單小懿 採訪者:單小懿


沒有富爸爸,原物料投資大師吉姆‧羅傑斯(Jim Rogers.)卻能在37歲就賺夠錢、提早退休,他到底有什麼祕訣?


4月才造訪台灣,掀起投資旋風的羅傑斯,5月於新加坡接受《Smart智富》月刊獨家專訪,分享自己如何學習理財、提早退休的心得。


羅傑斯說:「你要退休,得先餵飽自己,你要打點自己穿甚麼,所以得要有錢,不然就成了睡在公園的流浪漢!」可是,每個人退休需要的錢不一樣。「你覺得你退休需要多少錢,跟我不會相同。我沒有車,從沒擁有超過1棟房子,但有些人有5棟房子才退休,5輛車子、5個女朋友,什麼東西都5個,哈哈哈!」羅傑斯幽默地談著,「要有足夠的錢,一定要先存錢;愛消費是一個錯誤。」以下是羅傑斯針對存錢、投資的口述紀要:


第1步:學會存錢,且不輕易消費


現代年輕人愛花錢,不愛存錢,我覺得這是一個錯誤(雙手一攤,很無奈的表情)。我年輕時一定存錢,盡可能的多存,現在連我女兒都有5個小豬撲滿,我讓她從5歲開始練習存錢。通常投資之前必須先存錢,然後慢慢投資才可能成功,一般都是這個方法。


我真的覺得年輕時喜歡消費是個錯誤,但如果他們真想這麼做,那就做吧!又不是我的錢,也不用跟任何人報備。但就我所知,要成功一定要先能夠存錢。以我來說,我很少買衣服(比比身上破了一個小洞的Polo衫),4、5年才買一次衣服,我也很少買其他東西,物質欲望很低。


第2步:研究徹底,會有更多訊息


存夠了錢,你可以開始準備投資;但投資的態度要很謹慎,如果一輩子只能投資20次,你一定會很謹慎的研究吧!


讀雜誌可以當做是開始,然後做自己的功課。就像很多人對車子、時尚感興趣,當你真的感興趣,就會多方蒐集資料,而當你真的對車子很了解的時候,你自然會知道哪些是好車,什麼時候市場會有轉變,就會知道得比華爾街(意指分析師)還多。
假如我要投資一家公司,我會詳讀每一份財務報告,包括最細微的註解。我也會想盡辦法查證財務報告的準確性,或是最高經營階層宣稱的未來預測。這一切都做完後,除非我有把握比98%的華爾街分析師更了解這家公司,否則不會把錢投進去。


如果要投資一個國家,我會親自到這個國家去看看有沒有貨幣黑市市場。政府匯兌率與黑市匯兌率之間的差異大小,代表這個國家的問題有多嚴重,公定的與黑市的匯兌率差異愈大,國家問題愈大。


注意到最細小的枝微末節,是成功和失敗的關鍵。世界上只有一種方式能使你得到的訊息比別人多、更占優勢,那就是「鉅細靡遺的徹底研究」。


第3步:不追多頭,專找空頭市場


我能賺大錢、提早退休的一個原因是我從不追多頭,而是反其道尋找空頭市場。大部分的投資者尋找的是多頭而忽略空頭,一旦人們為某個炒作過頭的股市瘋狂,而忽略其他好投資,這時通常是我找到好交易的時候。


一般來說,有兩種方法可以檢視特定市場是否為空頭,第一是歸納法,就是從觀察中得到結論。例如,股票和原物料市場多頭交替出現,股票價格不佳時,原物料商品表現比較好,反之亦然,這個循環大約有15年到23年。所以按照歷史先例,原物料市場的多頭可以看好到2014年至2022年之間。


另一個是演繹法(deduction),就是從邏輯中得到結論。以家樂氏(Kellogg's)為例,當原物料市場低迷時,原料成本穩定,公司淨利自然上升,股價也會上升。反過來當原物料價格上升,公司成本上升,但不可能把增加的成本反映到售價上,連帶拖累股票價格。找出原物料和股票為何負相關,這是很好的心智練習。


第4步:獨立判斷,不受別人影響


我年輕時,經常被別人的勸告沖昏頭,沒有聽從自己內心的決定,奇怪得很,每次這種投資都失敗。後來我不再讓別人影響我,並根據自己所下的決定採取行動。直到年過30,我終於認定這是最佳投資之道,我會成功是因為自己遵照了這些原則。
你要做很多功課、研究,千萬不要投資自己不熟悉的標的,千萬不要聽信媒體、報紙、雜誌的消息,追隨別人的腳步(笑,呵呵呵)。假如你追隨別人的腳步,你永遠不會成功;當你聽到某人說他要去買某支股票或炒短線,只做當日沖銷,通常是他們太亢奮,以致高估市場。在這種情況下,你不可能賺到錢,在任何領域都不可能成功。


第5步:感覺無所不能時,就危險了


做完足夠的研究後,就動手買股票。買下足以說服你的股票,然後等待時機轉變,就會獲得戲劇性的報酬;換言之,你知道你在等什麼(you stay in what you know)。所以大多數時間,你什麼也不用做,你就是坐在那邊等,等你看到錢已經出現在轉角,你就彎腰把它撿起來。多數時候你什麼也沒做,望著窗外發呆,把錢放在銀行,等待機會。


另外,不論什麼時候你開始感覺自己無所不能,趕快停下來,什麼都不要做,因為再投資,就危險了,因為你開始跟別人的想法一樣了。記得坐下來休息一下,克服感染你的烏合之眾心理學。


Sunday, January 6, 2013

Mnemonic For BGP Attributes

“We Love Oranges AS Oranges Mean Pure Refreshment”
W   Weight (Highest)
L   Local_Pref (Highest)
O   Originate (local originate)
AS  As_Path (shortest)
O   Origin Code (IGP < EGP < Incomplete)
M   MED (lowest)
P   Paths (External Paths preferred Over Internal)
R   Router ID (lowest)

BGP Path Manipulation + Goofy Mnemonic

When altering BGP path selection, it is a good idea to have the following table committed to memory:
MethodDirection AppliedDirection AffectedBest Metric
WeightInboundOutboundHighest
Local PreferenceInboundOutboundHighest
AS PathOutboundInboundShortest
MED (metric)OutboundInboundLowest

This table shows the four most common BGP path manipulation attributes in order of preference (here’s a mnemonic to memorize all of the BGP attributes).  Whenever I am tasked with BGP path manipulation in the lab I quickly recreate the above table with the following mnemonic:
“When applying in London in April, make love.”
W = Weight
A = applied (April reminds me of showers which reminds me of London, so this helps recreate the mnemonic as well)
I = inbound
L = Local Preference
I = inbound
A = AS Path
M = MED (London makes me think of sex for reasons I’ll keep to myself :-) )
L = lowest
You’re probably thinking “Nice. But that doesn’t look like the entire table to me is represented in that stupid phrase.” And you’re right.  :-)
I write out the table first with the headers only:
MethodDirection AppliedDirection AffectedBest Metric
    
    
    
    

Then I write ‘Weight’.  The “applying” bit just reminds me that the second header should be “Direction Applied” and not “Direction Affected“.  If you mix up those two headers, then you are in for a very bad experience.  :-)
MethodDirection AppliedDirection AffectedBest Metric
Weight   
    
    
    

“In” means inbound (under Direction Applied).  With just this bit of information I can fill in the rest of the “Direction” fields because I know that the first two attributes are applied inbound.  That means the that the last two attributes are applied outbound.  Since the “Direction Affected” is the opposite of the “Direction Applied”, it’s a snap to fill in that information as well.
MethodDirection AppliedDirection AffectedBest Metric
WeightInboundOutbound 
 InboundOutbound 
 OutboundInbound 
 OutboundInbound 

So we’re left with ‘London in April, make love’.  ‘London’ = local preference.  ‘in’ is another reminder that Local_Pref is applied inbound (and it makes the goofy sentence flow better).  ‘April’ = AS Path and ‘make’ = MED.
MethodDirection AppliedDirection AffectedBest Metric
WeightInboundOutbound 
Local PreferenceInboundOutbound 
AS PathOutboundInbound 
MEDOutboundInbound 

Now all we need is to fill in the ‘Best Metric’ column.  I assume that the highest metric is always the best metric except in the case of the last two attributes.  In this case, ‘love’ = lowest (for MED).  I know that the shortest AS Path is the best (no need to memorize that as it’s pretty logical). 
So now I have the whole table:
MethodDirection AppliedDirection AffectedBest Metric
WeightInboundOutboundHighest
Local PreferenceInboundOutboundHighest
AS PathOutboundInboundShortest
MEDOutboundInboundLowest

So thanks for crawling into my mind.  Pretty empty huh? The exit is through my ears.  :-)
You can create your own mnemonic (I’m sure that mine is not the best) and add more or less detail as needed.  After you are able to recreate this table a couple of times, you’ll find that you won’t need to use the mnemonic, but it’s nice to have it in case you need it.

BGP Best Path Selection Algorithm with examples

BGP is the protocol used to announce prefixes throughout the internet. It’s a very robust protocol, and very useful to carry lot of prefixes, such as the Internet prefixes or internal client prefixes of an ISP.
When a prefix is received in BGP, the path passes through two steps before being chosen as candidate to populate the RIB.
The first step consists on checking if the path is valid. If it is, the prefix will get into the BGP table, and later the second step of selection will start.
In order to pass this first check, the path must meet the following requirements:
  • The prefix must not been marked as “not-synchronized”
  • There must be a route in the RIB to reach the next-hop
  • For prefixes learned through eBGP sessions, the local ASN must not be in the AS_PATH of the prefix
In the second step, the best path to reach the prefix is selected. If there is only one path, no comparison needed. If there are many paths to reach the prefix, there is a special algorithm that BGP uses to select the best path, and this is what I want to talk about.
This algorithm dictates the following:
  1. Prefer the path with the highest WEIGHT
  2. Prefer the path with the highest LOCAL PREFERENCE
  3. Prefer the path that was locally originated via a network o redistribute command over aggregate-address command
  4. Prefer the path with the lowest AS_PATH
  5. Prefer the path with the lowest ORIGIN type
  6. Prefer the path with the lowest MULTI-EXIT DISCRIMINATOR (MED)
  7. Prefer eBGP over iBGP
  8. Prefer the path with the lowest IGP metric to the BGP next-hop
  9. When both path are external, prefer the one that was received first
  10. Prefer the route that comes from the BGP router with the lowest router ID
  11. If the originator or router ID is the same for multiple paths, prefer the path with the minimum cluster list length
  12. Prefer the path that comes from the lowest neighbor address
As you can see, the selection process is quite long, although in most  cases the selection doesn’t go further than point 8.
Let’s study points  1 through  8 and how we can influence them within the following lab. The prefix we are going to be working with is 100.100.100.0/24, announced by R4 and R6:
BGP Topology
1.- PATH WITH HIGHEST WEIGHT
Weight is a Cisco-specific attribute, that means it’s not standard. This attribute is local to the router on witch it’s configured, so it’s not advertised with the prefix to other peers. This attribute is used to tell the router which path to use to reach the prefix. The highest value wins.

It’s the first attribute checked by BGP, so if there are two different paths for the same prefix but with different Weight values, the path with the highest value wins.
In the lab scenario, R4 and R6 both announce the prefix 100.100.100.0/24, one through an eBGP session and other through an iBGP session. Let’s check how R2 and R1 see this prefix without changing anything:
R2#show ip bgp
BGP table version is 3, local router ID is 2.2.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
*  100.100.100.0/24 4.4.4.4                  0             0 65002 i
*>i                 6.6.6.6                  0    100      0 i

R2#show ip bgp 100.100.100.0/24
BGP routing table entry for 100.100.100.0/24, version 3
Paths: (2 available, best #2, table default)
  Advertised to update-groups:
     13         16
  65002
    4.4.4.4 (metric 11) from 4.4.4.4 (4.4.4.4)
      Origin IGP, metric 0, localpref 100, valid, external
  Local    6.6.6.6 (metric 11) from 6.6.6.6 (6.6.6.6)      Origin IGP, metric 0, localpref 100, valid, internal, best
R2 gets two paths for the prefix 100.100.100.0/24: one of them from an eBGP peer and the other one from an iBGP peer. So R2 doesn’t choose the path through the eBGP peer, as we could think initially as the Administrative Distance for eBGP is less than for iBGP, but that’s not what really happens.
R2  picks the one from the iBGP peer as the best one, because as we will see later,  it’s the one with the shortest AS_PATH length. Both paths (through R4 and through R6) have the same weight, local-preference and route origin. So the tie-breaker is the  shorter AS_PATH, that is the path through R6.
Let’s see what happens when the weight parameter is configured on R2:
R2#conf term
R2(config)#router bgp 65001
R2(config-router)#neig 4.4.4.4 weight 200
R2(config-router)#end
R2#clear ip bgp 4.4.4.4

R2#sh ip bgp
BGP table version is 4, local router ID is 2.2.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
*> 100.100.100.0/24 4.4.4.4                  0            200  65002 i
* i                 6.6.6.6                  0    100       0  i
Now R2 takes the path through R4. And it announces this path to R1 as its own choice, but we said the weight attribute is not attached to the prefix, so if R1 had a BGP session with R6, it would prefer the path through R6 as R2 did at the beginning.
Let’s build this BGP session between R1 and R6, and let’s see which path R1 chooses:
R1#sh ip bgp sum
BGP router identifier 1.1.1.1, local AS number 65001
....
Neighbor        V           AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
2.2.2.2         4        65001      30      30       14    0    0 00:24:37        1
6.6.6.6         4        65001       4       3       14    0    0 00:00:31        1

R1#sh ip bgp 100.100.100.0/24
BGP routing table entry for 100.100.100.0/24, version 14
Paths: (2 available, best #1, table default)
  Not advertised to any peer
  Local
    6.6.6.6 (metric 21) from 6.6.6.6 (6.6.6.6)
      Origin IGP, metric 0, localpref 100, valid, internal, best
  65002
    4.4.4.4 (metric 21) from 2.2.2.2 (2.2.2.2)
      Origin IGP, metric 0, localpref 100, valid, internal
R1#
Although R2 prefers the path through R4, R1 prefers the path through R6 because it has a shorter AS_PATH.
So as I said before, the weight attribute only has local significance, and it’s not attached to the prefix when announced via BGP.
2.- PATH WITH HIGHEST LOCAL-PREFERENCE
When all the paths to the destination have the same weight value, the next attribute to be checked is Local-Preference.
Local-preference is a standard attribute, and it’s transmitted only between iBGP peers.
This parameter is set to outgoing or incoming prefixes by using a route-map with the peer. If there isn’t any statement matching a specific prefix inside the route-map, the local-preference is set for all the prefixes outgoing or incoming for that peer. The highest value wins.
Let’s get back to the original scenario. R4, R3, and R6 are announcing the same 100.100.100.0/24 prefix. But, R3 is announcing this prefix with a local-preference of 150:
R2#sh ip bgp
BGP table version is 7, local router ID is 2.2.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
*>i100.100.100.0/24 3.3.3.3                  0    150      0 i
*                   4.4.4.4                  0             0 65002 i
* i                 6.6.6.6                  0    100      0 i

R2#sh ip bgp 100.100.100.0/24
BGP routing table entry for 100.100.100.0/24, version 7
Paths: (3 available, best #1, table default)
Flag: 0x800
  Advertised to update-groups:
     13         18
  Local, (Received from a RR-client)    3.3.3.3 (metric 11) from 3.3.3.3 (3.3.3.3)      Origin IGP, metric 0, localpref 150, valid, internal, best
  65002
    4.4.4.4 (metric 11) from 4.4.4.4 (4.4.4.4)
      Origin IGP, metric 0, localpref 100, valid, external
  Local, (Received from a RR-client)
    6.6.6.6 (metric 11) from 6.6.6.6 (6.6.6.6)
      Origin IGP, metric 0, localpref 100, valid, internal
It makes R2 select the path through R3 as the best choice, and announce this choice to other iBGP neighbors, as we can see in R1:
R1#sh ip bgp 100.100.100.0/24
BGP routing table entry for 100.100.100.0/24, version 17
Paths: (1 available, best #1, table default)
  Not advertised to any peer
  Local
    3.3.3.3 (metric 11) from 2.2.2.2 (2.2.2.2)
      Origin IGP, metric 0, localpref 150, valid, internal, best
      Originator: 3.3.3.3, Cluster list: 2.2.2.2
As we can see, the value of Local-Preference is attached to the prefix.

In order to change this decision, we can configure a route-map in R2 with a higher local-preference value and apply it to the session with R6. After resetting the session with R6 on R2, the prefix announced by R6 will have the highest local-preference value, so R2 will choose this new path. At the same time it would be announced this way to their clients:
R2#configure t
R2(config)#route-map LP-200
R2(config-route-map)#set local-preference 200
R2(config-route-map)#exit
R2(config)#router bgp 65001
R2(config-router)#neig 6.6.6.6 route-map LP-200 in
R2(config-router)#end
R2#clear ip bgp 6.6.6.6
R2#sh ip bgp
BGP table version is 8, local router ID is 2.2.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
*>i100.100.100.0/24 6.6.6.6                  0    200      0 i
* i                 3.3.3.3                  0    150      0 i
*                   4.4.4.4                  0             0 65002 i
R1#show ip bgp 100.100.100.0/24
BGP routing table entry for 100.100.100.0/24, version 18
Paths: (1 available, best #1, table default)
  Not advertised to any peer
  Local
    6.6.6.6 (metric 21) from 2.2.2.2 (2.2.2.2)
      Origin IGP, metric 0, localpref 200, valid, internal, best
      Originator: 6.6.6.6, Cluster list: 2.2.2.2
A path without LOCAL_PREF is considered to have the value that is set with the bgp default local-preference command, or if this is not configured, a 100 by default.
3.- PATH LOCALLY ORIGINATED
This point is reached if all of the above attributes have the same value for all the feasible paths.

Local paths that are sourced by the network or redistribute commands are preferred over local aggregates that are sourced by theaggregate-address command.

Let’s get back to the original scenario.

Now R5 is announcing the prefix 100.100.100.0/30 to R3 using an iBGP session and R3 generates the bgp aggregated prefix 100.100.100.0/24 using the aggregate-address command, and also through the redistribution of its Loopback100 interface:
R3#show ip bgp
BGP table version is 4, 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
s>i100.100.100.0/30 5.5.5.5                  0    100      0 i
*  100.100.100.0/24 0.0.0.0                            32768 i
*>                  0.0.0.0                  0         32768 ?

R3#sh ip bgp 100.100.100.0/24
BGP routing table entry for 100.100.100.0/24, version 3
Paths: (2 available, best #2, table default)
  Advertised to update-groups:
     16         17
  Local, (aggregated by 65001 3.3.3.3)
    0.0.0.0 from 0.0.0.0 (3.3.3.3)
      Origin IGP, localpref 100, weight 32768, valid, aggregated, local, atomic-aggregate
  Local    0.0.0.0 from 0.0.0.0 (3.3.3.3)      Origin incomplete, metric 0, localpref 100, weight 32768, valid, sourced, best
R3 prefers the path originated via the redistribute command, instead of the one from the aggregate command. And that path is the one announced to R2.
4.- PATH WITH SHORTEST AS_PATH
If none of the above attributes break the tie and the router doesn’t have the prefix locally generated, the next parameter to check is the AS_PATH attribute.

The AS_PATH is a well-known mandatory attribute. It means every prefix has this attribute attached, and every router must understand this attribute. The shorter this attribute is, the more preferable is the path.
Let’s get back again to the original scenario, with all already seen attributes set by default.
In this scenario, the prefix received from R4 has the longest AS_PATH because it’s an eBGP session.
R2#sh ip bgp
BGP table version is 61, local router ID is 2.2.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
*>i100.100.100.0/24 6.6.6.6                  0    100      0 i
*                   4.4.4.4                  0             0 65002 i>/pre>
That’s why R2 prefers the iBGP prefix than the eBGP prefix.
The manipulation of the AS_PATH attribute must be done in a eBGP session. Among iBGP peers is not possible to manipulate the AS_PATH (you could hide it with the aggregate-address command, or to manipulate it with confederations)
5.- PATH WITH LOWEST ORIGIN
Origin is also a well-known mandatory attribute, like next-hop and as_path. So every BGP prefix has this attribute.

There are 3 origin types: IGP, EGP and INCOMPLETE.
IGP is more preferable than Exterior Gateway Protocol (EGP), and EGP is more preferable than INCOMPLETE.
Typically, when a prefix is generated by the command network, it gets the type IGP, and when it’s redistributed from another protocol, it gets the type INCOMPLETE.
In our scenario, R6 is generating the prefix 100.100.100.0/24 by redistributing it Loopback100 interface:
R6#show route-map
route-map CONN, permit, sequence 10
  Match clauses:
    interface Loopback100
  Set clauses:
  Policy routing matches: 0 packets, 0 bytes
R6#conf term
R6(config)#router bgp 65001
R6(config-router)#redistribute connected route-map CONN
R6(config-router)#end
R6#clear ip bgp
R2#sh ip bgp 100.100.100.0/24
BGP routing table entry for 100.100.100.0/24, version 76
Paths: (3 available, best #1, table default)
  Advertised to update-groups:
     13         18
  Local, (Received from a RR-client)
    3.3.3.3 (metric 11) from 3.3.3.3 (3.3.3.3)
      Origin IGP, metric 0, localpref 100, valid, internal, best
  Local, (Received from a RR-client)
    6.6.6.6 (metric 11) from 6.6.6.6 (6.6.6.6)
      Origin incomplete, metric 0, localpref 100, valid, internal
  65002
    4.4.4.4 (metric 11) from 4.4.4.4 (4.4.4.4)
      Origin IGP, metric 0, localpref 100, valid, external
R2 prefers the path through R3 because of the origin type.
In order to change the origin type, a route-map must be used:
R6#conf term
Enter configuration commands, one per line.  End with CNTL/Z.
R6(config)#route-map CONN
R6(config-route-map)#set origin igp
R6(config-route-map)#end
R6# clear ip bgp 2.2.2.2
R2#sh ip bgp 100.100.100.0/24
BGP routing table entry for 100.100.100.0/24, version 76
Paths: (3 available, best #1, table default)
  Advertised to update-groups:
     13         18
  Local, (Received from a RR-client)
    6.6.6.6 (metric 11) from 6.6.6.6 (6.6.6.6)
      Origin IGP, metric 0, localpref 100, valid, internal, best
  Local, (Received from a RR-client)
    3.3.3.3 (metric 11) from 3.3.3.3 (3.3.3.3)
      Origin IGP, metric 0, localpref 100, valid, internal
  65002
    4.4.4.4 (metric 11) from 4.4.4.4 (4.4.4.4)
      Origin IGP, metric 0, localpref 100, valid, external
6.- PATH WITH THE LOWEST MED
MED comparison only occurs if the first (the neighboring) AS is the same in the two paths to compare. There are other implications (check this Cisco reference to know more about this parameter)
It’s an Optional Non-transitive Attribute, so it may not been passed to other AS’s and its usage as a tie-breaker between several paths depends on each AS policy. The lowest MED is the most preferable.

MED can be manipulated using a route-map:
R3#conf term
R3(config)#route-map MED
R3(config-route-map)#set metric 20000
R3(config-route-map)#router bgp 65001
R3(config-router)#neig 2.2.2.2 route-map MED out
R3(config-router)#end
R3#clear ip bgp 2.2.2.2
R6#conf term
R6(config)#route-map MED
R6(config-route-map)#set metric 1000
R6(config-route-map)#exit
R6(config)#router bgp 65001
R6(config-router)#neig 2.2.2.2 route-map MED out
R6(config-router)#end
R6#clear ip bgp 2.2.2.2
R2#sh ip bgp
BGP table version is 81, local router ID is 2.2.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
* i100.100.100.0/24 3.3.3.3               2000    100      0 i
*>i                 6.6.6.6               1000    100      0 i
*                   4.4.4.4                  0             0 65002 i
7.- PREFER EBGP OVER IBGP
We reached the most interesting point.. From the first part of the post, we saw that the path through R6, who it’s an iBGP peer, was preferred over the path through R4, who is an eBGP peer.

This is because the fact that the route is learned via iBGP or eBGP is not considered until all the above attributes are equal.  In that case, the prefix learned through an eBGP session is preferred over an iBGP session.
In order to try this, I have changed a little bit the scenario. Now R5 keeps an eBGP session with R3, and it announces the prefix 100.100.100.0/24.
R4 has an eBGP session with R2, and it announces also the prefix 100.100.100.0/24. Between R2 and R3 there is an iBGP session, but R2 filters everything towards R3.
BGP Topology
In this situation, we see that R2 gets two path for the prefix 100.100.100.0/24. Both paths have the same attributes, but one of them is through an iBGP peer, and the other one through an eBGP peer:
R2#sh ip bgp
BGP table version is 84, local router ID is 2.2.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
* i100.100.100.0/24 5.5.5.5                  0    100      0 65003 i
*>                  4.4.4.4                  0             0 65002 i

R2#sh ip bgp 100.100.100.0/24
BGP routing table entry for 100.100.100.0/24, version 84
Paths: (2 available, best #2, table default)
  Advertised to update-groups:
     13
  65003, (Received from a RR-client)
    5.5.5.5 (metric 21) from 3.3.3.3 (3.3.3.3)
      Origin IGP, metric 0, localpref 100, valid, internal
  65002    4.4.4.4 (metric 11) from 4.4.4.4 (4.4.4.4)      Origin IGP, metric 0, localpref 100, valid, external, best
R2 prefers the path through the eBGP peer, although it has another path through an iBGP peer.
8.- PATH WITH LOWEST IGP METRIC
If all the above attributes are  equal and no path has been chosen yet, the next parameter to check is the IGP cost to reach the different next-hops of the prefix.
Getting back to the original scenario, I changed the OSPF cost of R3′s loopback. Now only R6 and R3 are announcing the prefix 100.100.100.0/24:
R2#sh ip bgp
BGP table version is 88, local router ID is 2.2.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
* i100.100.100.0/24 3.3.3.3                  0    100      0 i
*>i                 6.6.6.6                  0    100      0 i

R2#sh ip bgp 100.100.100.0/24
BGP routing table entry for 100.100.100.0/24, version 88
Paths: (2 available, best #2, table default)
  Advertised to update-groups:
     13
  Local, (Received from a RR-client)
    3.3.3.3 (metric 1010) from 3.3.3.3 (3.3.3.3)
      Origin IGP, metric 0, localpref 100, valid, internal
  Local, (Received from a RR-client)
    6.6.6.6 (metric 11) from 6.6.6.6 (6.6.6.6)
      Origin IGP, metric 0, localpref 100, valid, internal, best

R2#sh ip route 3.3.3.3
Routing entry for 3.3.3.3/32
  Known via "ospf 1", distance 110, metric 1010, type intra area
  Last update from 10.10.23.3 on Ethernet0/2, 00:00:47 ago
  Routing Descriptor Blocks:
  * 10.10.23.3, from 3.3.3.3, 00:00:47 ago, via Ethernet0/2
      Route metric is 1010, traffic share count is 1

R2#sh ip route 6.6.6.6
Routing entry for 6.6.6.6/32
  Known via "ospf 1", distance 110, metric 11, type intra area
  Last update from 10.10.26.6 on Ethernet0/3, 05:23:31 ago
  Routing Descriptor Blocks:
  * 10.10.26.6, from 6.6.6.6, 05:23:31 ago, via Ethernet0/3
      Route metric is 11, traffic share count is 1
R2 prefers the path through R6 because the OSPF metric to reach that next-hop is smaller, all the other parameters are exactly the same for both paths.
And that’s all for now.

I hope this post helps clear the BGP best-path selection algorithm!

Related Posts Plugin for WordPress, Blogger...