Advertisement
Guest User

Untitled

a guest
Jan 17th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 5.64 KB | None | 0 0
  1. func bgppublish(s *gobgp.BgpServer,typ string, ip string, nexthop string){
  2.         nlri, _ := ptypes.MarshalAny(&api.IPAddressPrefix{
  3.                 Prefix:    ip,
  4.                 PrefixLen: 32,
  5.         })
  6.         a1, _ := ptypes.MarshalAny(&api.OriginAttribute{
  7.                 Origin: 0,
  8.         })
  9.         a2, _ := ptypes.MarshalAny(&api.NextHopAttribute{
  10.                 NextHop: nexthop,
  11.         })
  12.         c, _ := ptypes.MarshalAny(&api.CommunitiesAttribute{
  13.                 Communities: []uint32{stringToCommunityValue("11111:11111")}, // real value is different
  14.         })
  15.         attrs := []*any.Any{a1,a2,c}
  16.         path := &api.Path{
  17.                 Family: &api.Family{Afi: api.Family_AFI_IP, Safi: api.Family_SAFI_UNICAST},
  18.                 Nlri:   nlri,
  19.                 Pattrs: attrs,
  20.                 NoImplicitWithdraw: true,
  21.         }
  22.         if typ == "ANNOUNCE" {
  23.                 _, err := s.AddPath(context.Background(), &api.AddPathRequest{
  24.                         Path: path,
  25.                 })
  26.                 if err != nil {
  27.                         log.Fatal(err)
  28.                 }
  29.         } else if typ == "DEANNOUNCE" {
  30.                 err := s.DeletePath(context.Background(), &api.DeletePathRequest{
  31.                         Path: path,
  32.                 })
  33.                 if err != nil {
  34.                         log.Fatal(err)
  35.                 }
  36.         }
  37. }
  38.  
  39.  
  40. func main() {
  41.         bgppublish(bgpserver,"ANNOUNCE","1.1.1.1","2.2.2.2")
  42.         bgppublish(bgpserver,"ANNOUNCE","1.1.1.1","3.3.3.3")
  43.         bgppublish(bgpserver,"DEANNOUNCE","1.1.1.1","2.2.2.2")
  44.         time.Sleep(time.Minute * 3)
  45. }
  46.  
  47.  
  48. INFO[0000] Add a peer configuration for:x.x.x.x    Topic=Peer
  49. DEBU[0000] IdleHoldTimer expired                         Duration=0 Key=x.x.x.x Topic=Peer
  50. DEBU[0000] state changed                                 Key=x.x.x.x Topic=Peer new=BGP_FSM_ACTIVE old=BGP_FSM_IDLE reason=idle-hold-timer-expired
  51. DEBU[0005] try to connect                                Key=x.x.x.x Topic=Peer
  52. DEBU[0005] state changed                                 Key=x.x.x.x Topic=Peer new=BGP_FSM_OPENSENT old=BGP_FSM_ACTIVE reason=new-connection
  53. DEBU[0005] state changed                                 Key=x.x.x.x Topic=Peer new=BGP_FSM_OPENCONFIRM old=BGP_FSM_OPENSENT reason=open-msg-received
  54. INFO[0005] Peer Up                                       Key=x.x.x.x State=BGP_FSM_OPENCONFIRM Topic=Peer
  55. DEBU[0005] state changed                                 Key=x.x.x.x Topic=Peer new=BGP_FSM_ESTABLISHED old=BGP_FSM_OPENCONFIRM reason=open-msg-negotiated
  56. INFO[0005] conf:<local_as:11111111 neighbor_address:"x.x.x.x" peer_as:111111111 > state:<local_as:11111111 neighbor_address:"x.x.x.x" peer_as:111111111 session_state:ESTABLISHED router_id:"85.10.249.230" > transport:<local_address:"x.x.x.x" local_port:32809 remote_port:179 >
  57. DEBU[0010] create Destination                            Nlri=1.1.1.1/32 Topic=Table
  58. DEBU[0010] computeKnownBestPath knownPathList: 1         Topic=Table
  59. DEBU[0010] computeKnownBestPath knownPathList: 2         Topic=Table
  60. DEBU[0010] enter compareByReachableNexthop -- path1: { 1.1.1.1/32 | src: local, nh: 2.2.2.2 }, path2: { 1.1.1.1/32 | src: local, nh: 3.3.3.3 }  Topic=Table
  61. DEBU[0010] enter compareByHighestWeight -- path1: { 1.1.1.1/32 | src: local, nh: 2.2.2.2 }, path2: { 1.1.1.1/32 | src: local, nh: 3.3.3.3 }  Topic=Table
  62. DEBU[0010] enter compareByLocalPref                      Topic=Table
  63. DEBU[0010] enter compareByLocalOrigin                    Topic=Table
  64. DEBU[0010] enter compareByASPath                         Topic=Table
  65. DEBU[0010] compareByASPath -- l1: 0, l2: 0               Topic=Table
  66. DEBU[0010] enter compareByOrigin                         Topic=Table
  67. DEBU[0010] compareByOrigin -- origin1: 0, origin2: 0     Topic=Table
  68. DEBU[0010] enter compareByMED                            Topic=Table
  69. DEBU[0010] compareByMED -- med1: 0, med2: 0              Topic=Table
  70. DEBU[0010] enter compareByASNumber                       Topic=Table
  71. DEBU[0010] compareByASNumber -- p1Asn: 0, p2Asn: 0       Topic=Table
  72. DEBU[0010] sent update                                   Key=x.x.x.x State=BGP_FSM_ESTABLISHED Topic=Peer attributes="[{Origin: i} 11111111 {Nexthop: 3.3.3.3} {Communities: 11111:11111}]" nlri="[1.1.1.1/32]" withdrawals="[]"
  73. DEBU[0010] enter compareByIGPCost -- path1: { 1.1.1.1/32 | src: local, nh: 2.2.2.2 }, path2: { 1.1.1.1/32 | src: local, nh: 3.3.3.3 }  Topic=Table
  74. DEBU[0010] enter compareByRouterID                       Topic=Table
  75. DEBU[0010] Removing withdrawals                          Key=1.1.1.1/32 Topic=Table
  76. DEBU[0010] computeKnownBestPath knownPathList: 1         Topic=Table
  77. DEBU[0010] sent update                                   Key=x.x.x.x State=BGP_FSM_ESTABLISHED Topic=Peer attributes="[{Origin: i} 11111111 {Nexthop: 2.2.2.2} {Communities: 11111:11111}]" nlri="[1.1.1.1/32]" withdrawals="[]"
  78. DEBU[0035] sent                                          Key=x.x.x.x State=BGP_FSM_ESTABLISHED Topic=Peer data="&{{[] 19 4} 0x13dc758}"
  79. DEBU[0065] sent                                          Key=x.x.x.x State=BGP_FSM_ESTABLISHED Topic=Peer data="&{{[] 19 4} 0x13dc758}"
  80. DEBU[0095] sent                                          Key=x.x.x.x State=BGP_FSM_ESTABLISHED Topic=Peer data="&{{[] 19 4} 0x13dc758}"
  81. DEBU[0125] sent                                          Key=x.x.x.x State=BGP_FSM_ESTABLISHED Topic=Peer data="&{{[] 19 4} 0x13dc758}"
  82. DEBU[0155] sent                                          Key=x.x.x.x State=BGP_FSM_ESTABLISHED Topic=Peer data="&{{[] 19 4} 0x13dc758}"
  83. DEBU[0185] sent                                          Key=x.x.x.x State=BGP_FSM_ESTABLISHED Topic=Peer data="&{{[] 19 4} 0x13dc758}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement