Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "os"
- "time"
- cli "github.com/osrg/gobgp/client"
- "github.com/osrg/gobgp/packet/bgp"
- "github.com/osrg/gobgp/table"
- )
- func showRib(c *cli.Client) {
- fmt.Println("showRib")
- family := bgp.RF_IPv4_UC
- if t, err := c.GetRIB(family, nil); err == nil {
- for _, d := range t.GetDestinations() {
- for _, p := range d.GetAllKnownPathList() {
- fmt.Println(p)
- }
- }
- }
- }
- func main() {
- c, err := cli.New("localhost:50051")
- if err != nil {
- fmt.Println(err)
- os.Exit(1)
- }
- //peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
- origin := bgp.NewPathAttributeOrigin(0)
- aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})}
- aspath := bgp.NewPathAttributeAsPath(aspathParam)
- nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
- med := bgp.NewPathAttributeMultiExitDisc(0)
- pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
- nlri := bgp.NewIPAddrPrefix(24, "10.10.0.0")
- p := table.NewPath(nil, nlri, false, pathAttributes, time.Now(), false)
- if _, err := c.AddPath([]*table.Path{p}); err != nil {
- fmt.Println(err)
- os.Exit(1)
- }
- nlri = bgp.NewIPAddrPrefix(24, "10.20.0.0")
- p = table.NewPath(nil, nlri, false, pathAttributes, time.Now(), false)
- if _, err := c.AddPath([]*table.Path{p}); err != nil {
- fmt.Println(err)
- os.Exit(1)
- }
- showRib(c)
- time.Sleep(time.Second * 10)
- fmt.Println("try to delete all")
- if err := c.DeletePath([]*table.Path{}); err != nil {
- fmt.Println(err)
- }
- showRib(c)
- }
Add Comment
Please, Sign In to add comment