Skip to content

Instantly share code, notes, and snippets.

@fujita
Created December 27, 2015 03:57
Show Gist options
  • Save fujita/c5d5983690039673b807 to your computer and use it in GitHub Desktop.
Save fujita/c5d5983690039673b807 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
api "github.com/osrg/gobgp/api"
"github.com/osrg/gobgp/gobgp/cmd"
"github.com/osrg/gobgp/packet"
"github.com/satori/go.uuid"
"golang.org/x/net/context"
"google.golang.org/grpc"
"os"
"time"
)
func main() {
conn, err := grpc.Dial("localhost:50051", grpc.WithBlock(), grpc.WithInsecure())
if err != nil {
fmt.Println(err)
os.Exit(1)
}
args := []string{"10.33.0.0/16"}
path, err := cmd.ParsePath(bgp.RF_IPv4_UC, args)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
client := api.NewGobgpApiClient(conn)
arg := &api.ModPathArguments{
Operation: api.Operation_ADD,
Resource: api.Resource_GLOBAL,
Path: path,
}
rsp, err := client.ModPath(context.Background(), arg)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
var u uuid.UUID
u.UnmarshalBinary(rsp.Uuid)
fmt.Println("Added a route, ", u.String())
time.Sleep(time.Second * 30)
arg = &api.ModPathArguments{
Operation: api.Operation_DEL,
Resource: api.Resource_GLOBAL,
Uuid: rsp.Uuid,
}
rsp, err = client.ModPath(context.Background(), arg)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println("Deleted the route, ", u.String())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment