Guest User

Untitled

a guest
Jun 21st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "os"
  6. "time"
  7.  
  8. cli "github.com/osrg/gobgp/client"
  9. "github.com/osrg/gobgp/packet/bgp"
  10. "github.com/osrg/gobgp/table"
  11. )
  12.  
  13. func showRib(c *cli.Client) {
  14. fmt.Println("showRib")
  15. family := bgp.RF_IPv4_UC
  16. if t, err := c.GetRIB(family, nil); err == nil {
  17. for _, d := range t.GetDestinations() {
  18. for _, p := range d.GetAllKnownPathList() {
  19. fmt.Println(p)
  20. }
  21. }
  22. }
  23. }
  24.  
  25. func main() {
  26. c, err := cli.New("localhost:50051")
  27. if err != nil {
  28. fmt.Println(err)
  29. os.Exit(1)
  30. }
  31.  
  32. //peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
  33. origin := bgp.NewPathAttributeOrigin(0)
  34. aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})}
  35. aspath := bgp.NewPathAttributeAsPath(aspathParam)
  36. nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
  37. med := bgp.NewPathAttributeMultiExitDisc(0)
  38. pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
  39.  
  40. nlri := bgp.NewIPAddrPrefix(24, "10.10.0.0")
  41. p := table.NewPath(nil, nlri, false, pathAttributes, time.Now(), false)
  42. if _, err := c.AddPath([]*table.Path{p}); err != nil {
  43. fmt.Println(err)
  44. os.Exit(1)
  45. }
  46.  
  47. nlri = bgp.NewIPAddrPrefix(24, "10.20.0.0")
  48. p = table.NewPath(nil, nlri, false, pathAttributes, time.Now(), false)
  49. if _, err := c.AddPath([]*table.Path{p}); err != nil {
  50. fmt.Println(err)
  51. os.Exit(1)
  52. }
  53.  
  54. showRib(c)
  55. time.Sleep(time.Second * 10)
  56. fmt.Println("try to delete all")
  57. if err := c.DeletePath([]*table.Path{}); err != nil {
  58. fmt.Println(err)
  59. }
  60. showRib(c)
  61. }
Add Comment
Please, Sign In to add comment