diff options
-rw-r--r-- | .travis.yml | 8 | ||||
-rw-r--r-- | docs/sources/lib.md | 82 |
2 files changed, 47 insertions, 43 deletions
diff --git a/.travis.yml b/.travis.yml index 22027f86..5ea321af 100644 --- a/.travis.yml +++ b/.travis.yml @@ -114,10 +114,10 @@ matrix: - test -z "$(go fmt $(go list ./... | grep -v '/vendor/'))" - test -z "$(go vet $(go list ./... | grep -v '/vendor/'))" - megacheck $(go list ./... | grep -v '/vendor/') -# - <<: *_dep_ensure -# env: -# - DESCRIPTION="build_embeded_go.py" -# script: python test/scenario_test/ci-scripts/build_embeded_go.py docs/sources/lib.md + - <<: *_dep_ensure + env: + - DESCRIPTION="build_embeded_go.py" + script: python test/scenario_test/ci-scripts/build_embeded_go.py docs/sources/lib.md # # Docker # diff --git a/docs/sources/lib.md b/docs/sources/lib.md index b7b16698..2b79c092 100644 --- a/docs/sources/lib.md +++ b/docs/sources/lib.md @@ -12,13 +12,14 @@ This page explains how to use GoBGP as a Go Native BGP library. package main import ( - "fmt" - log "github.com/sirupsen/logrus" - "github.com/osrg/gobgp/config" - "github.com/osrg/gobgp/packet/bgp" - gobgp "github.com/osrg/gobgp/server" - "github.com/osrg/gobgp/table" + "context" "time" + + "github.com/golang/protobuf/ptypes" + "github.com/golang/protobuf/ptypes/any" + api "github.com/osrg/gobgp/api" + gobgp "github.com/osrg/gobgp/pkg/server" + log "github.com/sirupsen/logrus" ) func main() { @@ -32,53 +33,56 @@ func main() { go g.Serve() // global configuration - global := &config.Global{ - Config: config.GlobalConfig{ - As: 65000, - RouterId: "10.0.255.254", - Port: -1, // gobgp won't listen on tcp:179 + if err := s.StartBgp(context.Background(), &api.StartBgpRequest{ + Global: &api.Global{ + As: 65003, + RouterId: "10.0.255.254", + ListenPort: -1, // gobgp won't listen on tcp:179 }, - } - - if err := s.Start(global); err != nil { + }); err != nil { log.Fatal(err) } // neighbor configuration - n := &config.Neighbor{ - Config: config.NeighborConfig{ - NeighborAddress: "10.0.255.1", - PeerAs: 65001, + n := &api.Peer{ + Conf: &api.PeerConf{ + NeighborAddress: "172.17.0.2", + PeerAs: 65002, }, } - if err := s.AddNeighbor(n); err != nil { + if err := s.AddPeer(context.Background(), &api.AddPeerRequest{ + Peer: n, + }); err != nil { log.Fatal(err) } // add routes - attrs := []bgp.PathAttributeInterface{ - bgp.NewPathAttributeOrigin(0), - bgp.NewPathAttributeNextHop("10.0.255.254"), - bgp.NewPathAttributeAsPath([]bgp.AsPathParamInterface{bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, []uint32{4000, 400000, 300000, 40001})}), - } - if _, err := s.AddPath("", []*table.Path{table.NewPath(nil, bgp.NewIPAddrPrefix(24, "10.0.0.0"), false, attrs, time.Now(), false)}); err != nil { + nlri, _ := ptypes.MarshalAny(&api.IPAddressPrefix{ + Prefix: "10.0.0.0", + PrefixLen: 24, + }) + + a1, _ := ptypes.MarshalAny(&api.OriginAttribute{ + Origin: 0, + }) + a2, _ := ptypes.MarshalAny(&api.NextHopAttribute{ + NextHop: "10.0.0.1", + }) + attrs := []*any.Any{a1, a2} + + _, err := s.AddPath(context.Background(), &api.AddPathRequest{ + Path: &api.Path{ + Family: uint32(api.Family_IPv4), + AnyNlri: nlri, + AnyPattrs: attrs, + }, + }) + if err != nil { log.Fatal(err) } - // monitor new routes - w := s.Watch(gobgp.WatchBestPath(false)) - for { - select { - case ev := <-w.Event(): - switch msg := ev.(type) { - case *gobgp.WatchEventBestPath: - for _, path := range msg.PathList { - // do something useful - fmt.Println(path) - } - } - } - } + // do something useful here instead of exiting + time.Sleep(time.Minute * 3) } ``` |