Skip to content

Instantly share code, notes, and snippets.

@abhi
Created September 1, 2016 01:30
Show Gist options
  • Save abhi/303ff2b602cb3468e67573f3e24d6614 to your computer and use it in GitHub Desktop.
Save abhi/303ff2b602cb3468e67573f3e24d6614 to your computer and use it in GitHub Desktop.
ofnet new gobgp
diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json
index 35491ab..d854e5e 100644
--- a/Godeps/Godeps.json
+++ b/Godeps/Godeps.json
@@ -1,6 +1,6 @@
{
"ImportPath": "github.com/contiv/ofnet",
- "GoVersion": "go1.5",
+ "GoVersion": "go1.6",
"GodepVersion": "v74",
"Packages": [
"./..."
@@ -39,8 +39,23 @@
"Rev": "b5d4dd420f593267b1a699020a7387b35b891efc"
},
{
+ "ImportPath": "github.com/eapache/channels",
+ "Comment": "v1.1.0",
+ "Rev": "47238d5aae8c0fefd518ef2bee46290909cf8263"
+ },
+ {
+ "ImportPath": "github.com/eapache/queue",
+ "Comment": "v1.0.2-7-g44cc805",
+ "Rev": "44cc805cf13205b55f69e14bcb69867d1ae92f98"
+ },
+ {
+ "ImportPath": "github.com/fsnotify/fsnotify",
+ "Comment": "v1.3.1",
+ "Rev": "a8a77c9133d2d6fd8334f3260d06f60e8d80a5fb"
+ },
+ {
"ImportPath": "github.com/golang/protobuf/proto",
- "Rev": "221834dcb89c96e4b057ed8bb878bfe569dfacf4"
+ "Rev": "2c1988e8c18d14b142c0b472624f71647cf39adb"
},
{
"ImportPath": "github.com/google/gopacket",
@@ -58,39 +73,131 @@
"Rev": "7abd91e1d374797e8c5b9a85a44bea266a62d7c5"
},
{
+ "ImportPath": "github.com/hashicorp/hcl",
+ "Rev": "578dd9746824a54637686b51a41bad457a56bcef"
+ },
+ {
+ "ImportPath": "github.com/hashicorp/hcl/hcl/ast",
+ "Rev": "578dd9746824a54637686b51a41bad457a56bcef"
+ },
+ {
+ "ImportPath": "github.com/hashicorp/hcl/hcl/parser",
+ "Rev": "578dd9746824a54637686b51a41bad457a56bcef"
+ },
+ {
+ "ImportPath": "github.com/hashicorp/hcl/hcl/scanner",
+ "Rev": "578dd9746824a54637686b51a41bad457a56bcef"
+ },
+ {
+ "ImportPath": "github.com/hashicorp/hcl/hcl/strconv",
+ "Rev": "578dd9746824a54637686b51a41bad457a56bcef"
+ },
+ {
+ "ImportPath": "github.com/hashicorp/hcl/hcl/token",
+ "Rev": "578dd9746824a54637686b51a41bad457a56bcef"
+ },
+ {
+ "ImportPath": "github.com/hashicorp/hcl/json/parser",
+ "Rev": "578dd9746824a54637686b51a41bad457a56bcef"
+ },
+ {
+ "ImportPath": "github.com/hashicorp/hcl/json/scanner",
+ "Rev": "578dd9746824a54637686b51a41bad457a56bcef"
+ },
+ {
+ "ImportPath": "github.com/hashicorp/hcl/json/token",
+ "Rev": "578dd9746824a54637686b51a41bad457a56bcef"
+ },
+ {
+ "ImportPath": "github.com/influxdata/influxdb/client/v2",
+ "Comment": "v1.0.0-beta3-128-g3c12403",
+ "Rev": "3c124036f0aea8e7f7b4dde76bdda5052bc58333"
+ },
+ {
+ "ImportPath": "github.com/influxdata/influxdb/models",
+ "Comment": "v1.0.0-beta3-128-g3c12403",
+ "Rev": "3c124036f0aea8e7f7b4dde76bdda5052bc58333"
+ },
+ {
+ "ImportPath": "github.com/influxdata/influxdb/pkg/escape",
+ "Comment": "v1.0.0-beta3-128-g3c12403",
+ "Rev": "3c124036f0aea8e7f7b4dde76bdda5052bc58333"
+ },
+ {
"ImportPath": "github.com/jainvipin/bitset",
"Comment": "v1.0.0-12-g1f0c6de",
"Rev": "1f0c6de81a62732e75f6c97f1e28e5a009b5df68"
},
{
+ "ImportPath": "github.com/kr/fs",
+ "Rev": "2788f0dbd16903de03cb8186e5c7d97b69ad387b"
+ },
+ {
+ "ImportPath": "github.com/magiconair/properties",
+ "Comment": "v1.6.0-1-gc81f9d7",
+ "Rev": "c81f9d71af8f8cba1466501d30326b99a4e56c19"
+ },
+ {
+ "ImportPath": "github.com/mitchellh/mapstructure",
+ "Rev": "281073eb9eb092240d33ef253c404f1cca550309"
+ },
+ {
"ImportPath": "github.com/osrg/gobgp/api",
- "Comment": "v1.2",
- "Rev": "e84989706157ffd7b895f42e4057e3f8ca382b3d"
+ "Comment": "v1.10-8-g7bf91ea",
+ "Rev": "7bf91ea437181b85ecc3a1473adc3fbc0da80cbe"
},
{
"ImportPath": "github.com/osrg/gobgp/config",
- "Comment": "v1.2",
- "Rev": "e84989706157ffd7b895f42e4057e3f8ca382b3d"
+ "Comment": "v1.10-8-g7bf91ea",
+ "Rev": "7bf91ea437181b85ecc3a1473adc3fbc0da80cbe"
+ },
+ {
+ "ImportPath": "github.com/osrg/gobgp/packet/bgp",
+ "Comment": "v1.10-8-g7bf91ea",
+ "Rev": "7bf91ea437181b85ecc3a1473adc3fbc0da80cbe"
},
{
- "ImportPath": "github.com/osrg/gobgp/packet",
- "Comment": "v1.2",
- "Rev": "e84989706157ffd7b895f42e4057e3f8ca382b3d"
+ "ImportPath": "github.com/osrg/gobgp/packet/bmp",
+ "Comment": "v1.10-8-g7bf91ea",
+ "Rev": "7bf91ea437181b85ecc3a1473adc3fbc0da80cbe"
+ },
+ {
+ "ImportPath": "github.com/osrg/gobgp/packet/mrt",
+ "Comment": "v1.10-8-g7bf91ea",
+ "Rev": "7bf91ea437181b85ecc3a1473adc3fbc0da80cbe"
+ },
+ {
+ "ImportPath": "github.com/osrg/gobgp/packet/rtr",
+ "Comment": "v1.10-8-g7bf91ea",
+ "Rev": "7bf91ea437181b85ecc3a1473adc3fbc0da80cbe"
},
{
"ImportPath": "github.com/osrg/gobgp/server",
- "Comment": "v1.2",
- "Rev": "e84989706157ffd7b895f42e4057e3f8ca382b3d"
+ "Comment": "v1.10-8-g7bf91ea",
+ "Rev": "7bf91ea437181b85ecc3a1473adc3fbc0da80cbe"
},
{
"ImportPath": "github.com/osrg/gobgp/table",
- "Comment": "v1.2",
- "Rev": "e84989706157ffd7b895f42e4057e3f8ca382b3d"
+ "Comment": "v1.10-8-g7bf91ea",
+ "Rev": "7bf91ea437181b85ecc3a1473adc3fbc0da80cbe"
},
{
"ImportPath": "github.com/osrg/gobgp/zebra",
- "Comment": "v1.2",
- "Rev": "e84989706157ffd7b895f42e4057e3f8ca382b3d"
+ "Comment": "v1.10-8-g7bf91ea",
+ "Rev": "7bf91ea437181b85ecc3a1473adc3fbc0da80cbe"
+ },
+ {
+ "ImportPath": "github.com/pkg/errors",
+ "Comment": "v0.7.0-13-ga221380",
+ "Rev": "a22138067af1c4942683050411a841ade67fe1eb"
+ },
+ {
+ "ImportPath": "github.com/pkg/sftp",
+ "Rev": "a71e8f580e3b622ebff585309160b1cc549ef4d2"
+ },
+ {
+ "ImportPath": "github.com/satori/go.uuid",
+ "Rev": "d41af8bb6a7704f00bc3b7cba9355ae6a5a80048"
},
{
"ImportPath": "github.com/shaleman/libOpenflow/common",
@@ -109,6 +216,34 @@
"Rev": "11954d9e46275d5cd47788dd8bc31420a238e34e"
},
{
+ "ImportPath": "github.com/spf13/afero",
+ "Rev": "cc9c21814bb945440253108c4d3c65c85aac3c68"
+ },
+ {
+ "ImportPath": "github.com/spf13/afero/mem",
+ "Rev": "cc9c21814bb945440253108c4d3c65c85aac3c68"
+ },
+ {
+ "ImportPath": "github.com/spf13/afero/sftp",
+ "Rev": "cc9c21814bb945440253108c4d3c65c85aac3c68"
+ },
+ {
+ "ImportPath": "github.com/spf13/cast",
+ "Rev": "e31f36ffc91a2ba9ddb72a4b6a607ff9b3d3cb63"
+ },
+ {
+ "ImportPath": "github.com/spf13/jwalterweatherman",
+ "Rev": "33c24e77fb80341fe7130ee7c594256ff08ccc46"
+ },
+ {
+ "ImportPath": "github.com/spf13/pflag",
+ "Rev": "f676131e2660dc8cd88de99f7486d34aa8172635"
+ },
+ {
+ "ImportPath": "github.com/spf13/viper",
+ "Rev": "346299ea79e446ebdddb834371ceba2e5926b732"
+ },
+ {
"ImportPath": "github.com/streamrail/concurrent-map",
"Rev": "238fe79560e1b42091fb0eba460fdefb8a485931"
},
@@ -125,12 +260,20 @@
"Rev": "493029407eeb434d0c2d44e02ea072ff2488d322"
},
{
+ "ImportPath": "golang.org/x/crypto/ssh",
+ "Rev": "cc04154d65fb9296747569b107cfd05380b1ea3e"
+ },
+ {
"ImportPath": "golang.org/x/net/context",
- "Rev": "195180cfebf7362bd243a52477697895128c8777"
+ "Rev": "075e191f18186a8ff2becaf64478e30f4545cdad"
},
{
"ImportPath": "golang.org/x/net/http2",
- "Rev": "195180cfebf7362bd243a52477697895128c8777"
+ "Rev": "075e191f18186a8ff2becaf64478e30f4545cdad"
+ },
+ {
+ "ImportPath": "golang.org/x/net/http2/hpack",
+ "Rev": "075e191f18186a8ff2becaf64478e30f4545cdad"
},
{
"ImportPath": "golang.org/x/net/http2/hpack",
@@ -138,19 +281,32 @@
},
{
"ImportPath": "golang.org/x/net/internal/timeseries",
- "Rev": "195180cfebf7362bd243a52477697895128c8777"
+ "Rev": "075e191f18186a8ff2becaf64478e30f4545cdad"
+ },
+ {
+ "ImportPath": "golang.org/x/net/lex/httplex",
+ "Rev": "075e191f18186a8ff2becaf64478e30f4545cdad"
},
{
"ImportPath": "golang.org/x/net/trace",
- "Rev": "195180cfebf7362bd243a52477697895128c8777"
+ "Rev": "075e191f18186a8ff2becaf64478e30f4545cdad"
},
{
"ImportPath": "golang.org/x/sys/unix",
"Rev": "342d6a85aa15bcd2ec54803cdffe90d52b6f35a7"
},
{
+ "ImportPath": "golang.org/x/text/transform",
+ "Rev": "2910a502d2bf9e43193af9d68ca516529614eed3"
+ },
+ {
+ "ImportPath": "golang.org/x/text/unicode/norm",
+ "Rev": "2910a502d2bf9e43193af9d68ca516529614eed3"
+ },
+ {
"ImportPath": "google.golang.org/grpc",
- "Rev": "a202995ce9a99c7d65875ba9f0cf04ff43169dd5"
+ "Comment": "v1.0.0-164-gedc5ccf",
+ "Rev": "edc5ccf8cbfd321723e26d2cf177b05c16132ad9"
},
{
"ImportPath": "google.golang.org/grpc/codes",
@@ -170,11 +326,51 @@
},
{
"ImportPath": "google.golang.org/grpc/transport",
- "Rev": "a202995ce9a99c7d65875ba9f0cf04ff43169dd5"
+ "Comment": "v1.0.0-164-gedc5ccf",
+ "Rev": "edc5ccf8cbfd321723e26d2cf177b05c16132ad9"
+ },
+ {
+ "ImportPath": "google.golang.org/grpc/credentials",
+ "Comment": "v1.0.0-164-gedc5ccf",
+ "Rev": "edc5ccf8cbfd321723e26d2cf177b05c16132ad9"
+ },
+ {
+ "ImportPath": "google.golang.org/grpc/grpclog",
+ "Comment": "v1.0.0-164-gedc5ccf",
+ "Rev": "edc5ccf8cbfd321723e26d2cf177b05c16132ad9"
+ },
+ {
+ "ImportPath": "google.golang.org/grpc/internal",
+ "Comment": "v1.0.0-164-gedc5ccf",
+ "Rev": "edc5ccf8cbfd321723e26d2cf177b05c16132ad9"
+ },
+ {
+ "ImportPath": "google.golang.org/grpc/metadata",
+ "Comment": "v1.0.0-164-gedc5ccf",
+ "Rev": "edc5ccf8cbfd321723e26d2cf177b05c16132ad9"
+ },
+ {
+ "ImportPath": "google.golang.org/grpc/naming",
+ "Comment": "v1.0.0-164-gedc5ccf",
+ "Rev": "edc5ccf8cbfd321723e26d2cf177b05c16132ad9"
+ },
+ {
+ "ImportPath": "google.golang.org/grpc/peer",
+ "Comment": "v1.0.0-164-gedc5ccf",
+ "Rev": "edc5ccf8cbfd321723e26d2cf177b05c16132ad9"
+ },
+ {
+ "ImportPath": "google.golang.org/grpc/transport",
+ "Comment": "v1.0.0-164-gedc5ccf",
+ "Rev": "edc5ccf8cbfd321723e26d2cf177b05c16132ad9"
},
{
"ImportPath": "gopkg.in/tomb.v2",
"Rev": "14b3d72120e8d10ea6e6b7f87f7175734b1faab8"
+ },
+ {
+ "ImportPath": "gopkg.in/yaml.v2",
+ "Rev": "f7716cbe52baa25d2e9b0d0da546fcf909fc16b4"
}
]
}
diff --git a/Vagrantfile b/Vagrantfile
index d3c7f84..e967294 100644
--- a/Vagrantfile
+++ b/Vagrantfile
@@ -31,6 +31,12 @@ source /etc/profile.d/envvar.sh
# Change permissions for gopath folder
chown -R vagrant #{gopath_folder}
+start docker daemon
+systemctl start docker
+
+# Start OVS if required
+systemctl start openvswitch
+
# Setup OVSDB listener
(ovs-vsctl set-manager tcp:127.0.0.1:6640 && \
ovs-vsctl set-manager ptcp:6640) || exit 1
@@ -39,8 +45,9 @@ SCRIPT
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
- config.vm.box = "contiv/ubuntu1504-netplugin"
- config.vm.box_version = "0.3.1"
+ config.vm.box = "contiv/centos72"
+ config.vm.box_version = "0.7.0"
+ config.ssh.insert_key = false
num_nodes = 1
base_ip = "192.168.11."
node_ips = num_nodes.times.collect { |n| base_ip + "#{n+10}" }
diff --git a/ofctrl/fgraphTable.go b/ofctrl/fgraphTable.go
index dffbe7d..0213482 100755
--- a/ofctrl/fgraphTable.go
+++ b/ofctrl/fgraphTable.go
@@ -18,9 +18,8 @@ package ofctrl
import (
"errors"
- "sync"
-
"github.com/shaleman/libOpenflow/openflow13"
+ "sync"
log "github.com/Sirupsen/logrus"
)
diff --git a/ofnet.go b/ofnet.go
index 215ca53..a4a3b86 100755
--- a/ofnet.go
+++ b/ofnet.go
@@ -109,10 +109,10 @@ type OfnetProto interface {
GetRouterInfo() *OfnetProtoRouterInfo
//Add Local Route
- AddLocalProtoRoute(path *OfnetProtoRouteInfo) error
+ AddLocalProtoRoute(path []*OfnetProtoRouteInfo) error
//Delete Local Route
- DeleteLocalProtoRoute(path *OfnetProtoRouteInfo) error
+ DeleteLocalProtoRoute(path []*OfnetProtoRouteInfo) error
//Modify protocol Rib (Could be used for testing)
ModifyProtoRib(path interface{})
diff --git a/ofnetAgent.go b/ofnetAgent.go
index 5f83a37..a352223 100755
--- a/ofnetAgent.go
+++ b/ofnetAgent.go
@@ -927,9 +927,11 @@ func (self *OfnetAgent) AddBgp(routerIP string, As string, neighborAs string, pe
self.DeleteBgp()
}
- go self.protopath.StartProtoServer(routerInfo)
-
- err := self.protopath.AddProtoNeighbor(neighborInfo)
+ err := self.protopath.StartProtoServer(routerInfo)
+ if err != nil {
+ return err
+ }
+ err = self.protopath.AddProtoNeighbor(neighborInfo)
if err != nil {
log.Errorf("Error adding protocol neighbor")
return err
@@ -965,13 +967,13 @@ func (self *OfnetAgent) GetRouterInfo() *OfnetProtoRouterInfo {
return nil
}
-func (self *OfnetAgent) AddLocalProtoRoute(path *OfnetProtoRouteInfo) {
+func (self *OfnetAgent) AddLocalProtoRoute(path []*OfnetProtoRouteInfo) {
if self.protopath != nil {
self.protopath.AddLocalProtoRoute(path)
}
}
-func (self *OfnetAgent) DeleteLocalProtoRoute(path *OfnetProtoRouteInfo) {
+func (self *OfnetAgent) DeleteLocalProtoRoute(path []*OfnetProtoRouteInfo) {
if self.protopath != nil {
self.protopath.DeleteLocalProtoRoute(path)
}
diff --git a/ofnetBgp.go b/ofnetBgp.go
index d5277c3..0442e0b 100755
--- a/ofnetBgp.go
+++ b/ofnetBgp.go
@@ -17,23 +17,21 @@ package ofnet
import (
"errors"
"fmt"
- "io"
"net"
"strconv"
"sync"
"time"
- bgp "github.com/osrg/gobgp/packet"
-
log "github.com/Sirupsen/logrus"
+ bgp "github.com/osrg/gobgp/packet/bgp"
+ table "github.com/osrg/gobgp/table"
api "github.com/osrg/gobgp/api"
bgpconf "github.com/osrg/gobgp/config"
- bgpserver "github.com/osrg/gobgp/server"
+ gobgp "github.com/osrg/gobgp/server"
"github.com/shaleman/libOpenflow/openflow13"
"github.com/shaleman/libOpenflow/protocol"
"github.com/vishvananda/netlink"
- "golang.org/x/net/context"
"google.golang.org/grpc"
)
@@ -44,24 +42,24 @@ type OfnetBgp struct {
agent *OfnetAgent // Pointer back to ofnet agent that owns this
//bgp resources
- modRibCh chan *api.Path //channel for route change notif
- advPathCh chan *api.Path
- bgpServer *bgpserver.BgpServer // bgp server instance
- grpcServer *bgpserver.Server // grpc server to talk to gobgp
-
- myRouterMac net.HardwareAddr //Router mac used for external proxy
- myBgpPeer string // bgp neighbor
- myBgpAs uint32
- cc *grpc.ClientConn //grpc client connection
- stop chan bool
- start chan bool
- stopArp chan bool
- intfName string //loopback intf to run bgp
+ bgpServer *gobgp.BgpServer // bgp server instance
+ grpcServer *api.Server // grpc server to talk to gobgp
+
+ myRouterMac net.HardwareAddr //Router mac used for external proxy
+ myBgpPeer string // bgp neighbor
+ myBgpAs uint32
+ cc *grpc.ClientConn //grpc client connection
+ stopWatch chan bool
+ start chan bool
+ stopArp chan bool
+ intfName string //loopback intf to run bgp
+ oldState string
+ oldAdminState string
}
type OfnetBgpInspect struct {
- Peer *api.Peer
- Rib *api.Table
+ Peers []*bgpconf.Neighbor
+ Rib map[string][]*table.Path
}
// Create a new vlrouter instance
@@ -88,7 +86,7 @@ func NewOfnetBgp(agent *OfnetAgent, routerInfo []string) *OfnetBgp {
log.Errorf("Error instantiating Bgp server")
return nil
}
- ofnetBgp.stop = make(chan bool, 1)
+ ofnetBgp.stopWatch = make(chan bool, 1)
ofnetBgp.intfName = "inb01"
ofnetBgp.start = make(chan bool, 1)
ofnetBgp.stopArp = make(chan bool, 1)
@@ -102,6 +100,7 @@ Bgp serve routine does the following:
3) Kicks off routines to monitor route updates and peer state
*/
func (self *OfnetBgp) StartProtoServer(routerInfo *OfnetProtoRouterInfo) error {
+
log.Infof("Starting the Bgp Server with %v", routerInfo)
//go routine to start gobgp server
var len uint
@@ -110,32 +109,12 @@ func (self *OfnetBgp) StartProtoServer(routerInfo *OfnetProtoRouterInfo) error {
as, _ := strconv.Atoi(routerInfo.As)
self.myBgpAs = uint32(as)
- self.modRibCh = make(chan *api.Path, 16)
- self.advPathCh = make(chan *api.Path, 16)
-
timeout := grpc.WithTimeout(time.Second)
- conn, err := grpc.Dial("127.0.0.1:8080", timeout, grpc.WithBlock(), grpc.WithInsecure())
+ conn, err := grpc.Dial("127.0.0.1:50051", timeout, grpc.WithBlock(), grpc.WithInsecure())
if err != nil {
log.Fatal(err)
}
self.cc = conn
- defer self.cc.Close()
-
- client := api.NewGobgpApiClient(self.cc)
- if client == nil {
- log.Errorf("Invalid Gobgpapi client")
- return errors.New("Error creating Gobgpapiclient")
- }
- path := &api.Path{
- Pattrs: make([][]byte, 0),
- }
-
- path.Nlri, _ = bgp.NewIPAddrPrefix(uint8(32), self.routerIP).Serialize()
- n, _ := bgp.NewPathAttributeNextHop("0.0.0.0").Serialize()
- path.Pattrs = append(path.Pattrs, n)
- origin, _ := bgp.NewPathAttributeOrigin(bgp.BGP_ORIGIN_ATTR_TYPE_INCOMPLETE).Serialize()
- path.Pattrs = append(path.Pattrs, origin)
-
log.Debugf("Creating the loopback port ")
err = self.agent.ovsDriver.CreatePort(self.intfName, "internal", 1)
if err != nil {
@@ -196,30 +175,26 @@ func (self *OfnetBgp) StartProtoServer(routerInfo *OfnetProtoRouterInfo) error {
self.agent.endpointDb.Set(epid, ep)
self.agent.localEndpointDb.Set(string(ep.PortNo), ep)
- //Add bgp router id as well
- bgpGlobalCfg := &bgpconf.Global{}
- setDefaultGlobalConfigValues(bgpGlobalCfg)
- bgpGlobalCfg.GlobalConfig.RouterId = net.ParseIP(self.routerIP)
- bgpGlobalCfg.GlobalConfig.As = self.myBgpAs
- self.bgpServer.SetGlobalType(*bgpGlobalCfg)
-
- //monitor route updates from peer
- go self.monitorBest()
- //monitor peer state
- go self.monitorPeer()
- self.start <- true
- for {
- select {
- case p := <-self.modRibCh:
- err = self.modRib(p)
- if err != nil {
- log.Error("failed to mod rib: ", err)
- }
- case <-self.stop:
- return nil
- }
+ // global configuration
+ global := &bgpconf.Global{
+ Config: bgpconf.GlobalConfig{
+ As: self.myBgpAs,
+ RouterId: self.routerIP,
+ Port: 179,
+ },
}
+
+ if err := self.bgpServer.Start(global); err != nil {
+ return err
+ }
+
+ //monitor route updates from peer, peer state
+ go self.watch()
+ // register for link ups on uplink and inb01 intf
+ self.start <- true
+ return nil
}
+
func (self *OfnetBgp) StopProtoServer() error {
log.Info("Stopping bgp server")
@@ -243,9 +218,11 @@ func (self *OfnetBgp) StopProtoServer() error {
}
self.routerIP = ""
self.myBgpAs = 0
+ self.cc.Close()
self.agent.deleteVrf("default")
- self.stop <- true
+ self.stopWatch <- true
+ self.bgpServer.Stop()
return nil
}
@@ -259,32 +236,12 @@ func (self *OfnetBgp) DeleteProtoNeighbor() error {
4) Mark the routes learn via json rpc as unresolved
*/
log.Infof("Received DeleteProtoNeighbor to delete bgp neighbor %v", self.myBgpPeer)
- client := api.NewGobgpApiClient(self.cc)
- if client == nil {
- log.Errorf("Invalid Gobgpapi client")
- return errors.New("Error creating Gobgpapiclient")
- }
- arg := &api.Arguments{Name: self.myBgpPeer}
-
- peer, err := client.GetNeighbor(context.Background(), arg)
- if err != nil {
- log.Errorf("GetNeighbor failed: %v", err)
- return err
+ n := &bgpconf.Neighbor{
+ Config: bgpconf.NeighborConfig{
+ NeighborAddress: self.myBgpPeer,
+ },
}
- p := bgpconf.Neighbor{}
- setNeighborConfigValues(&p)
-
- p.NeighborAddress = net.ParseIP(peer.Conf.NeighborAddress)
- p.NeighborConfig.NeighborAddress = net.ParseIP(peer.Conf.NeighborAddress)
- p.NeighborConfig.PeerAs = uint32(peer.Conf.PeerAs)
- //FIX ME set ipv6 depending on peerip (for v6 BGP)
- p.AfiSafis.AfiSafiList = []bgpconf.AfiSafi{
- bgpconf.AfiSafi{AfiSafiName: "ipv4-unicast"}}
- self.bgpServer.SetBmpConfig(bgpconf.BmpServers{
- BmpServerList: []bgpconf.BmpServer{},
- })
-
- self.bgpServer.PeerDelete(p)
+ self.bgpServer.DeleteNeighbor(n)
self.stopArp <- true
bgpEndpoint := self.agent.getEndpointByIpVrf(net.ParseIP(self.myBgpPeer), "default")
@@ -316,26 +273,26 @@ func (self *OfnetBgp) DeleteProtoNeighbor() error {
func (self *OfnetBgp) AddProtoNeighbor(neighborInfo *OfnetProtoNeighborInfo) error {
<-self.start
-
log.Infof("Received AddProtoNeighbor to add bgp neighbor %v", neighborInfo.NeighborIP)
- var policyConfig bgpconf.RoutingPolicy
-
peerAs, _ := strconv.Atoi(neighborInfo.As)
- p := &bgpconf.Neighbor{}
- setNeighborConfigValues(p)
- p.NeighborAddress = net.ParseIP(neighborInfo.NeighborIP)
- p.NeighborConfig.NeighborAddress = net.ParseIP(neighborInfo.NeighborIP)
- p.NeighborConfig.PeerAs = uint32(peerAs)
- //FIX ME set ipv6 depending on peerip (for v6 BGP)
- p.AfiSafis.AfiSafiList = []bgpconf.AfiSafi{
- bgpconf.AfiSafi{AfiSafiName: "ipv4-unicast"}}
- self.bgpServer.SetBmpConfig(bgpconf.BmpServers{
- BmpServerList: []bgpconf.BmpServer{},
- })
-
- self.bgpServer.PeerAdd(*p)
- self.bgpServer.SetPolicy(policyConfig)
+
+ n := &bgpconf.Neighbor{
+ Config: bgpconf.NeighborConfig{
+ NeighborAddress: neighborInfo.NeighborIP,
+ PeerAs: uint32(peerAs),
+ },
+ Timers: bgpconf.Timers{
+ Config: bgpconf.TimersConfig{
+ ConnectRetry: 60,
+ },
+ },
+ }
+
+ err := self.bgpServer.AddNeighbor(n)
+ if err != nil {
+ return err
+ }
epid := self.agent.getEndpointIdByIpVrf(net.ParseIP(neighborInfo.NeighborIP), "default")
epreg := &OfnetEndpoint{
@@ -350,17 +307,18 @@ func (self *OfnetBgp) AddProtoNeighbor(neighborInfo *OfnetProtoNeighborInfo) err
// Install the endpoint in datapath
// First, add the endpoint to local routing table
- self.agent.endpointDb.Set(epreg.EndpointID, epreg)
- err := self.agent.datapath.AddEndpoint(epreg)
+ err = self.agent.datapath.AddEndpoint(epreg)
if err != nil {
log.Errorf("Error adding endpoint: {%+v}. Err: %v", epreg, err)
return err
}
+ self.agent.endpointDb.Set(epreg.EndpointID, epreg)
self.myBgpPeer = neighborInfo.NeighborIP
go self.sendArp(self.stopArp)
+ paths := []*OfnetProtoRouteInfo{}
//Walk through all the localEndpointDb and them to protocol rib
for endpoint := range self.agent.localEndpointDb.IterBuffered() {
ep := endpoint.Val.(*OfnetEndpoint)
@@ -369,8 +327,9 @@ func (self *OfnetBgp) AddProtoNeighbor(neighborInfo *OfnetProtoNeighborInfo) err
localEpIP: ep.IpAddr.String(),
nextHopIP: self.routerIP,
}
- self.AddLocalProtoRoute(path)
+ paths = append(paths, path)
}
+ self.AddLocalProtoRoute(paths)
return nil
}
@@ -388,256 +347,131 @@ func (self *OfnetBgp) GetRouterInfo() *OfnetProtoRouterInfo {
}
//AddLocalProtoRoute is used to add local endpoint to the protocol RIB
-func (self *OfnetBgp) AddLocalProtoRoute(pathInfo *OfnetProtoRouteInfo) error {
+func (self *OfnetBgp) AddLocalProtoRoute(pathInfo []*OfnetProtoRouteInfo) error {
if self.routerIP == "" {
//ignoring populating to the bgp rib because
//Bgp is not configured.
return nil
}
+ log.Infof("Received AddLocalProtoRoute to add local endpoint to protocol RIB: %+v", pathInfo)
- log.Infof("Received AddLocalProtoRoute to add local endpoint to protocol RIB: %v", pathInfo)
-
- path := &api.Path{
- Pattrs: make([][]byte, 0),
+ // add routes
+ attrs := []bgp.PathAttributeInterface{
+ bgp.NewPathAttributeOrigin(1),
+ bgp.NewPathAttributeNextHop(pathInfo[0].nextHopIP),
+ bgp.NewPathAttributeAsPath([]bgp.AsPathParamInterface{bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, []uint32{self.myBgpAs})}),
}
-
- // form the path structure with appropriate path attributes
- nlri := bgp.NewIPAddrPrefix(32, pathInfo.localEpIP)
- path.Nlri, _ = nlri.Serialize()
- origin, _ := bgp.NewPathAttributeOrigin(bgp.BGP_ORIGIN_ATTR_TYPE_EGP).Serialize()
- path.Pattrs = append(path.Pattrs, origin)
- aspathParam := []bgp.AsPathParamInterface{bgp.NewAs4PathParam(2, []uint32{self.myBgpAs})}
- aspath, _ := bgp.NewPathAttributeAsPath(aspathParam).Serialize()
- path.Pattrs = append(path.Pattrs, aspath)
- n, _ := bgp.NewPathAttributeNextHop(pathInfo.nextHopIP).Serialize()
- path.Pattrs = append(path.Pattrs, n)
-
- name := ""
-
- arg := &api.ModPathArguments{
- Resource: api.Resource_GLOBAL,
- Name: name,
- Paths: []*api.Path{path},
- }
-
- //send arguement stream
- client := api.NewGobgpApiClient(self.cc)
- if client == nil {
- log.Errorf("Gobgpapi stream invalid")
- return nil
+ paths := []*table.Path{}
+ for _, path := range pathInfo {
+ paths = append(paths, table.NewPath(nil, bgp.NewIPAddrPrefix(32, path.localEpIP), false, attrs, time.Now(), false))
}
- stream, err := client.ModPath(context.Background())
- if err != nil {
- log.Errorf("Fail to enforce Modpath: %v", err)
- return err
- }
- err = stream.Send(arg)
+ _, err := self.bgpServer.AddPath("", paths)
if err != nil {
- log.Errorf("Failed to send strean: %v", err)
return err
}
- stream.CloseSend()
- res, e := stream.CloseAndRecv()
- if e != nil {
- log.Errorf("Falied toclose stream ")
- return e
- }
- if res.Code != api.Error_SUCCESS {
- return fmt.Errorf("error: code: %d, msg: %s", res.Code, res.Msg)
- }
+
return nil
}
//DeleteLocalProtoRoute withdraws local endpoints from protocol RIB
-func (self *OfnetBgp) DeleteLocalProtoRoute(pathInfo *OfnetProtoRouteInfo) error {
+func (self *OfnetBgp) DeleteLocalProtoRoute(pathInfo []*OfnetProtoRouteInfo) error {
log.Infof("Received DeleteLocalProtoRoute to withdraw local endpoint to protocol RIB: %v", pathInfo)
- path := &api.Path{
- Pattrs: make([][]byte, 0),
- }
-
- //form appropraite path attributes for path to be withdrawn
- nlri := bgp.NewIPAddrPrefix(32, pathInfo.localEpIP)
- path.Nlri, _ = nlri.Serialize()
- origin, _ := bgp.NewPathAttributeOrigin(bgp.BGP_ORIGIN_ATTR_TYPE_EGP).Serialize()
- path.Pattrs = append(path.Pattrs, origin)
- aspathParam := []bgp.AsPathParamInterface{bgp.NewAs4PathParam(2, []uint32{self.myBgpAs})}
- aspath, _ := bgp.NewPathAttributeAsPath(aspathParam).Serialize()
- path.Pattrs = append(path.Pattrs, aspath)
- n, _ := bgp.NewPathAttributeNextHop(pathInfo.nextHopIP).Serialize()
- path.Pattrs = append(path.Pattrs, n)
- path.IsWithdraw = true
- name := ""
-
- arg := &api.ModPathArguments{
- Resource: api.Resource_GLOBAL,
- Name: name,
- Paths: []*api.Path{path},
- }
-
- //send arguement stream
- client := api.NewGobgpApiClient(self.cc)
- if client == nil {
- log.Errorf("Gobgpapi stream invalid")
- return nil
+ attrs := []bgp.PathAttributeInterface{
+ bgp.NewPathAttributeOrigin(1),
+ bgp.NewPathAttributeNextHop(pathInfo[0].nextHopIP),
+ bgp.NewPathAttributeAsPath([]bgp.AsPathParamInterface{bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, []uint32{self.myBgpAs})}),
}
-
- stream, err := client.ModPath(context.Background())
- if err != nil {
- log.Errorf("Fail to enforce Modpathi: %v", err)
- return err
+ paths := []*table.Path{}
+ for _, path := range pathInfo {
+ paths = append(paths, table.NewPath(nil, bgp.NewIPAddrPrefix(32, path.localEpIP), true, attrs, time.Now(), false))
}
-
- err = stream.Send(arg)
- if err != nil {
- log.Errorf("Failed to send strean: %v", err)
+ if err := self.bgpServer.DeletePath(nil, bgp.RF_IPv4_UC, "", paths); err != nil {
return err
}
- stream.CloseSend()
-
- res, e := stream.CloseAndRecv()
- if e != nil {
- log.Errorf("Falied toclose stream ")
- return e
- }
- if res.Code != api.Error_SUCCESS {
- return fmt.Errorf("error: code: %d, msg: %s", res.Code, res.Msg)
- }
return nil
}
//monitorBest monitors for route updates/changes form peer
-func (self *OfnetBgp) monitorBest() {
-
- client := api.NewGobgpApiClient(self.cc)
- if client == nil {
- log.Errorf("Invalid Gobgpapi client")
- return
- }
- arg := &api.Arguments{
- Resource: api.Resource_GLOBAL,
- Rf: uint32(bgp.RF_IPv4_UC),
- }
-
- stream, err := client.MonitorBestChanged(context.Background(), arg)
- if err != nil {
- return
- }
-
+func (self *OfnetBgp) watch() {
+ w := self.bgpServer.Watch(gobgp.WatchBestPath(), gobgp.WatchPeerState(true))
for {
- dst, err := stream.Recv()
- if err == io.EOF {
- break
- } else if err != nil {
- log.Infof("monitorBest stream ended")
+ select {
+ case ev := <-w.Event():
+ switch msg := ev.(type) {
+ case *gobgp.WatchEventBestPath:
+ for _, path := range msg.PathList {
+ self.modRib(path)
+ }
+ case *gobgp.WatchEventPeerState:
+ self.peerUpdate(msg)
+
+ }
+ case <-self.stopWatch:
return
}
- self.modRibCh <- dst.Paths[0]
}
- return
}
// monitorPeer is used to monitor the bgp peer state
-func (self *OfnetBgp) monitorPeer() {
-
- var oldAdminState, oldState string
-
- client := api.NewGobgpApiClient(self.cc)
- if client == nil {
- log.Errorf("Invalid Gobgpapi client")
- return
- }
- arg := &api.Arguments{}
-
- stream, err := client.MonitorPeerState(context.Background(), arg)
- if err != nil {
- log.Errorf("MonitorPeerState failed: %v", err)
- return
- }
- for {
- s, err := stream.Recv()
- if err == io.EOF {
- break
- } else if err != nil {
- log.Warnf("MonitorPeerState stream ended :")
- break
+func (self *OfnetBgp) peerUpdate(s *gobgp.WatchEventPeerState) {
+
+ fmt.Printf("[NEIGH] %s fsm: %s admin: %v\n", s.PeerAddress,
+ s.State, s.AdminState.String())
+ if self.oldState == "BGP_FSM_ESTABLISHED" && self.oldAdminState == "ADMIN_STATE_UP" {
+ uplink, _ := self.agent.ovsDriver.GetOfpPortNo(self.vlanIntf)
+ /*If the state changed from being established to idle or active:
+ 1) delete all endpoints learnt via bgp Peer
+ 2) mark routes pointing to the bgp nexthop as unresolved
+ 3) mark the bgp peer reachbility as unresolved
+ */
+ endpoint := self.agent.getEndpointByIpVrf(net.ParseIP(self.myBgpPeer), "default")
+ self.agent.datapath.RemoveEndpoint(endpoint)
+ endpoint.PortNo = 0
+
+ err := self.agent.datapath.AddEndpoint(endpoint)
+ if err != nil {
+ log.Errorf("Error unresolving bgp peer %s ", self.myBgpPeer)
}
- fmt.Printf("[NEIGH] %s fsm: %s admin: %s\n", s.Conf.NeighborAddress,
- s.Info.BgpState, s.Info.AdminState)
- if oldState == "BGP_FSM_ESTABLISHED" && oldAdminState == "ADMIN_STATE_UP" {
- uplink, _ := self.agent.ovsDriver.GetOfpPortNo(self.vlanIntf)
- /*If the state changed from being established to idle or active:
- 1) delete all endpoints learnt via bgp Peer
- 2) mark routes pointing to the bgp nexthop as unresolved
- 3) mark the bgp peer reachbility as unresolved
- */
- endpoint := self.agent.getEndpointByIpVrf(net.ParseIP(self.myBgpPeer), "default")
- self.agent.datapath.RemoveEndpoint(endpoint)
- endpoint.PortNo = 0
-
- self.agent.endpointDb.Set(endpoint.EndpointID, endpoint)
- err = self.agent.datapath.AddEndpoint(endpoint)
- if err != nil {
- log.Errorf("Error unresolving bgp peer %s ", self.myBgpPeer)
- }
-
- var ep *OfnetEndpoint
- for endpoint := range self.agent.endpointDb.IterBuffered() {
- ep = endpoint.Val.(*OfnetEndpoint)
- if ep.PortNo == uplink {
- self.agent.datapath.RemoveEndpoint(ep)
- if ep.EndpointType == "internal" {
- ep.PortNo = 0
- self.agent.endpointDb.Set(ep.EndpointID, ep)
- //We readd unresolved endpoints that were learnt via
- //json rpc
- self.agent.datapath.AddEndpoint(ep)
- } else if ep.EndpointType == "external" {
- self.agent.endpointDb.Remove(ep.EndpointID)
- }
+ self.agent.endpointDb.Set(endpoint.EndpointID, endpoint)
+
+ var ep *OfnetEndpoint
+ for endpoint := range self.agent.endpointDb.IterBuffered() {
+ ep = endpoint.Val.(*OfnetEndpoint)
+ if ep.PortNo == uplink {
+ self.agent.datapath.RemoveEndpoint(ep)
+ if ep.EndpointType == "internal" {
+ ep.PortNo = 0
+ self.agent.endpointDb.Set(ep.EndpointID, ep)
+ //We readd unresolved endpoints that were learnt via
+ //json rpc
+ self.agent.datapath.AddEndpoint(ep)
+ } else if ep.EndpointType == "external" {
+ self.agent.endpointDb.Remove(ep.EndpointID)
}
}
}
- oldState = s.Info.BgpState
- oldAdminState = s.Info.AdminState
}
+ self.oldState = s.State.String()
+ self.oldAdminState = s.AdminState.String()
+
return
}
//modrib receives route updates from BGP server and adds the endpoint
-func (self *OfnetBgp) modRib(path *api.Path) error {
+func (self *OfnetBgp) modRib(path *table.Path) error {
var nlri bgp.AddrPrefixInterface
var nextHop string
var macAddrStr string
var portNo uint32
- if len(path.Nlri) > 0 {
- nlri = &bgp.IPAddrPrefix{}
- err := nlri.DecodeFromBytes(path.Nlri)
- if err != nil {
- return err
- }
- }
-
- for _, attr := range path.Pattrs {
- p, err := bgp.GetPathAttribute(attr)
- if err != nil {
- return err
- }
- err = p.DecodeFromBytes(attr)
- if err != nil {
- return err
- }
+ nlri = path.GetNlri()
+ nextHop = path.GetNexthop().String()
- if p.GetType() == bgp.BGP_ATTR_TYPE_NEXT_HOP {
- nextHop = p.(*bgp.PathAttributeNextHop).Value.String()
- break
- }
- }
if nextHop == "0.0.0.0" {
return nil
}
@@ -647,8 +481,7 @@ func (self *OfnetBgp) modRib(path *api.Path) error {
}
endpointIPNet, _ := netlink.ParseIPNet(nlri.String())
- log.Infof("Bgp Rib Received endpoint update for %v , with nexthop %v",
- endpointIPNet, nextHop)
+ log.Infof("Bgp Rib Received endpoint update for path %s", path.String())
//check if bgp published a route local to the host
epid := self.agent.getEndpointIdByIpVrf(endpointIPNet.IP.Mask(endpointIPNet.Mask), "default")
@@ -712,8 +545,8 @@ func (self *OfnetBgp) modRib(path *api.Path) error {
}
//createBgpServer creates and starts a bgp server and correspoinding grpc server
-func createBgpServer() (bgpServer *bgpserver.BgpServer, grpcServer *bgpserver.Server) {
- bgpServer = bgpserver.NewBgpServer(bgp.BGP_PORT)
+func createBgpServer() (bgpServer *gobgp.BgpServer, grpcServer *api.Server) {
+ bgpServer = gobgp.NewBgpServer()
if bgpServer == nil {
log.Errorf("Error creating bgp server")
return
@@ -721,7 +554,7 @@ func createBgpServer() (bgpServer *bgpserver.BgpServer, grpcServer *bgpserver.Se
go bgpServer.Serve()
}
// start grpc Server
- grpcServer = bgpserver.NewGrpcServer(bgpserver.GRPC_PORT, bgpServer.GrpcReqCh)
+ grpcServer = api.NewGrpcServer(bgpServer, ":50051")
if grpcServer == nil {
log.Errorf("Error creating bgp server")
return
@@ -731,48 +564,14 @@ func createBgpServer() (bgpServer *bgpserver.BgpServer, grpcServer *bgpserver.Se
return
}
-//setDefaultGlobalConfigValues sets the default global configs for bgp
-func setDefaultGlobalConfigValues(bt *bgpconf.Global) error {
-
- bt.AfiSafis.AfiSafiList = []bgpconf.AfiSafi{
- bgpconf.AfiSafi{AfiSafiName: "ipv4-unicast"},
- bgpconf.AfiSafi{AfiSafiName: "ipv6-unicast"},
- bgpconf.AfiSafi{AfiSafiName: "l3vpn-ipv4-unicast"},
- bgpconf.AfiSafi{AfiSafiName: "l3vpn-ipv6-unicast"},
- bgpconf.AfiSafi{AfiSafiName: "l2vpn-evpn"},
- bgpconf.AfiSafi{AfiSafiName: "encap"},
- bgpconf.AfiSafi{AfiSafiName: "rtc"},
- bgpconf.AfiSafi{AfiSafiName: "ipv4-flowspec"},
- bgpconf.AfiSafi{AfiSafiName: "l3vpn-ipv4-flowspec"},
- bgpconf.AfiSafi{AfiSafiName: "ipv6-flowspec"},
- bgpconf.AfiSafi{AfiSafiName: "l3vpn-ipv6-flowspec"},
- }
- bt.MplsLabelRange.MinLabel = bgpconf.DEFAULT_MPLS_LABEL_MIN
- bt.MplsLabelRange.MaxLabel = bgpconf.DEFAULT_MPLS_LABEL_MAX
-
- return nil
-}
-
-//setNeighborConfigValues sets the default neighbor configs for bgp
-func setNeighborConfigValues(neighbor *bgpconf.Neighbor) error {
-
- neighbor.Timers.TimersConfig.ConnectRetry = float64(bgpconf.DEFAULT_CONNECT_RETRY)
- neighbor.Timers.TimersConfig.HoldTime = float64(bgpconf.DEFAULT_HOLDTIME)
- neighbor.Timers.TimersConfig.KeepaliveInterval = float64(bgpconf.DEFAULT_HOLDTIME / 3)
- neighbor.Timers.TimersConfig.IdleHoldTimeAfterReset =
- float64(bgpconf.DEFAULT_IDLE_HOLDTIME_AFTER_RESET)
- //FIX ME need to check with global peer to set internal or external
- neighbor.NeighborConfig.PeerType = bgpconf.PEER_TYPE_EXTERNAL
- neighbor.Transport.TransportConfig.PassiveMode = false
- return nil
-}
-
func (self *OfnetBgp) sendArp(stopArp chan bool) {
//Get the Mac of the vlan intf
//Get the portno of the uplink
//Build an arp packet and send on portno of uplink
- time.Sleep(5 * time.Second)
+ time.Sleep(2 * time.Second)
+ self.sendArpPacketOut()
+
for {
select {
case <-stopArp:
@@ -784,14 +583,13 @@ func (self *OfnetBgp) sendArp(stopArp chan bool) {
}
func (self *OfnetBgp) ModifyProtoRib(path interface{}) {
- self.modRibCh <- path.(*api.Path)
+ self.modRib(path.(*table.Path))
}
func (self *OfnetBgp) sendArpPacketOut() {
if self.myBgpPeer == "" {
return
}
-
intf, _ := net.InterfaceByName(self.vlanIntf)
ofPortno, _ := self.agent.ovsDriver.GetOfpPortNo(self.vlanIntf)
bMac, _ := net.ParseMAC("FF:FF:FF:FF:FF:FF")
@@ -831,25 +629,20 @@ func (self *OfnetBgp) InspectProto() (interface{}, error) {
OfnetBgpInspect := new(OfnetBgpInspect)
var err error
- client := api.NewGobgpApiClient(self.cc)
- if client == nil {
- log.Errorf("Invalid Gobgpapi client")
- return nil, errors.New("Error creating Gobgpapiclient")
+ if self.bgpServer == nil {
+ return nil, nil
}
-
// Get Bgp info
- arg := &api.Arguments{Name: self.myBgpPeer}
- OfnetBgpInspect.Peer, err = client.GetNeighbor(context.Background(), arg)
- if err != nil {
- log.Errorf("GetNeighbor failed: %v", err)
- return nil, err
+ OfnetBgpInspect.Peers = self.bgpServer.GetNeighbor()
+
+ if OfnetBgpInspect.Peers == nil {
+ return nil, nil
}
// Get rib info
- table := &api.Table{Type: api.Resource_GLOBAL, Family: uint32(bgp.RF_IPv4_UC)}
- OfnetBgpInspect.Rib, err = client.GetRib(context.Background(), table)
+ _, OfnetBgpInspect.Rib, err = self.bgpServer.GetRib(self.myBgpPeer, bgp.RF_IPv4_UC, nil)
if err != nil {
- log.Errorf("GetRib failed: %v", err)
+ log.Errorf("Bgp Inspect failed: %v", err)
return nil, err
}
diff --git a/ofnet_route_test.go b/ofnet_route_test.go
old mode 100644
new mode 100755
index 9badf78..782cf85
--- a/ofnet_route_test.go
+++ b/ofnet_route_test.go
@@ -10,7 +10,8 @@ import (
log "github.com/Sirupsen/logrus"
api "github.com/osrg/gobgp/api"
- "github.com/osrg/gobgp/packet"
+ bgp "github.com/osrg/gobgp/packet/bgp"
+ table "github.com/osrg/gobgp/table"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
@@ -309,7 +310,7 @@ func TestOfnetBgpPeerAddDelete(t *testing.T) {
}
timeout := grpc.WithTimeout(time.Second)
- conn, err := grpc.Dial("127.0.0.1:8080", timeout, grpc.WithBlock(), grpc.WithInsecure())
+ conn, err := grpc.Dial("127.0.0.1:50051", timeout, grpc.WithBlock(), grpc.WithInsecure())
if err != nil {
t.Fatal(err)
}
@@ -318,10 +319,9 @@ func TestOfnetBgpPeerAddDelete(t *testing.T) {
if client == nil {
t.Errorf("GoBgpApiclient is invalid")
}
- arg := &api.Arguments{Name: peer}
//Check if neighbor is added to bgp server
- bgpPeer, err := client.GetNeighbor(context.Background(), arg)
+ bgpPeer, err := client.GetNeighbor(context.Background(), &api.GetNeighborRequest{})
if err != nil {
t.Errorf("GetNeighbor failed: %v", err)
return
@@ -335,8 +335,8 @@ func TestOfnetBgpPeerAddDelete(t *testing.T) {
}
//Check if neighbor is added to bgp server
- bgpPeer, err = client.GetNeighbor(context.Background(), arg)
- if bgpPeer != nil {
+ bgpPeer, err = client.GetNeighbor(context.Background(), &api.GetNeighborRequest{})
+ if len(bgpPeer.Peers) != 0 {
t.Errorf("Neighbor is not deleted: %v", err)
return
}
@@ -354,19 +354,19 @@ func TestOfnetVlrouteAddDelete(t *testing.T) {
for i := 0; i < NUM_VLRTR_AGENT; i++ {
err := vlrtrAgents[i].AddBgp(routerIP, as, neighborAs, peer)
if err != nil {
+ log.Infof("THE ERROR IS %s", err)
t.Errorf("Error adding Bgp Neighbor: %v", err)
return
}
-
macAddr, _ := net.ParseMAC("02:02:01:06:06:06")
ipAddr := net.ParseIP("20.20.20.20")
- ipv6Addr := net.ParseIP("2020::20:20")
+ // ipv6Addr := net.ParseIP("2020::20:20")
endpoint := EndpointInfo{
- PortNo: uint32(NUM_AGENT + 3),
- MacAddr: macAddr,
- Vlan: 1,
- IpAddr: ipAddr,
- Ipv6Addr: ipv6Addr,
+ PortNo: uint32(NUM_AGENT + 3),
+ MacAddr: macAddr,
+ Vlan: 1,
+ IpAddr: ipAddr,
+ // Ipv6Addr: ipv6Addr,
}
log.Infof("Installing local vlrouter endpoint: %+v", endpoint)
@@ -403,24 +403,22 @@ func TestOfnetVlrouteAddDelete(t *testing.T) {
log.Infof("Found ipflow %s on ovs %s", ipFlowMatch, brName)
// verify IPv6 flow entry exists
- ipv6FlowMatch := fmt.Sprintf("priority=100,ipv6,ipv6_dst=2020::20:20")
- if !ofctlFlowMatch(flowList, ipTableId, ipv6FlowMatch) {
- t.Errorf("Could not find the route %s on ovs %s", ipv6FlowMatch, brName)
- return
- }
- log.Infof("Found ipv6 flow %s on ovs %s", ipv6FlowMatch, brName)
+ // ipv6FlowMatch := fmt.Sprintf("priority=100,ipv6,ipv6_dst=2020::20:20")
+ // if !ofctlFlowMatch(flowList, ipTableId, ipv6FlowMatch) {
+ // t.Errorf("Could not find the route %s on ovs %s", ipv6FlowMatch, brName)
+ // return
+ // }
+ // log.Infof("Found ipv6 flow %s on ovs %s", ipv6FlowMatch, brName)
log.Infof("Adding Vlrouter endpoint successful.\n Testing Delete")
macAddr, _ = net.ParseMAC("02:02:01:06:06:06")
ipAddr = net.ParseIP("20.20.20.20")
- ipv6Addr = net.ParseIP("2020::20:20")
endpoint = EndpointInfo{
- PortNo: uint32(NUM_AGENT + 3),
- MacAddr: macAddr,
- Vlan: 1,
- IpAddr: ipAddr,
- Ipv6Addr: ipv6Addr,
+ PortNo: uint32(NUM_AGENT + 3),
+ MacAddr: macAddr,
+ Vlan: 1,
+ IpAddr: ipAddr,
}
log.Infof("Deleting local vlrouter endpoint: %+v", endpoint)
@@ -448,12 +446,6 @@ func TestOfnetVlrouteAddDelete(t *testing.T) {
t.Errorf("Still found the flow %s on ovs %s", ipFlowMatch, brName)
}
// verify IPv6 flow entry exists
- ipv6FlowMatch = fmt.Sprintf("priority=100,ipv6,ipv6_dst=2020::20:20")
- ipTableId = IP_TBL_ID
- if ofctlFlowMatch(flowList, ipTableId, ipv6FlowMatch) {
- t.Errorf("Still found the flow %s on ovs %s", ipv6FlowMatch, brName)
- return
- }
err = vlrtrAgents[i].DeleteBgp()
log.Infof("Verified all flows are deleted")
}
@@ -475,18 +467,14 @@ func TestOfnetBgpVlrouteAddDelete(t *testing.T) {
t.Errorf("Error adding Bgp Neighbor: %v", err)
return
}
- path := &api.Path{
- Pattrs: make([][]byte, 0),
- }
- nlri := bgp.NewIPAddrPrefix(32, "20.20.20.20")
- path.Nlri, _ = nlri.Serialize()
- origin, _ := bgp.NewPathAttributeOrigin(bgp.BGP_ORIGIN_ATTR_TYPE_EGP).Serialize()
- path.Pattrs = append(path.Pattrs, origin)
- aspathParam := []bgp.AsPathParamInterface{bgp.NewAs4PathParam(2, []uint32{65002})}
- aspath, _ := bgp.NewPathAttributeAsPath(aspathParam).Serialize()
- path.Pattrs = append(path.Pattrs, aspath)
- n, _ := bgp.NewPathAttributeNextHop("50.1.1.3").Serialize()
- path.Pattrs = append(path.Pattrs, n)
+ attrs := []bgp.PathAttributeInterface{
+ bgp.NewPathAttributeOrigin(1),
+ bgp.NewPathAttributeNextHop("50.1.1.3"),
+ bgp.NewPathAttributeAsPath([]bgp.AsPathParamInterface{bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, []uint32{65002})}),
+ }
+
+ path := table.NewPath(nil, bgp.NewIPAddrPrefix(32, "20.20.20.20"), false, attrs, time.Now(), false)
+
vlrtrAgents[i].protopath.ModifyProtoRib(path)
log.Infof("Adding path to the Bgp Rib")
time.Sleep(2 * time.Second)
diff --git a/vlrouter.go b/vlrouter.go
index 79c8af6..8d8a215 100755
--- a/vlrouter.go
+++ b/vlrouter.go
@@ -185,7 +185,6 @@ func (self *Vlrouter) AddLocalEndpoint(endpoint OfnetEndpoint) error {
// save the flow entry
self.portVlanFlowDb[endpoint.PortNo] = portVlanFlow
-
outPort, err := self.ofSwitch.OutputPort(endpoint.PortNo)
if err != nil {
log.Errorf("Error creating output port %d. Err: %v", endpoint.PortNo, err)
@@ -202,7 +201,6 @@ func (self *Vlrouter) AddLocalEndpoint(endpoint OfnetEndpoint) error {
log.Errorf("Error creating flow for endpoint: %+v. Err: %v", endpoint, err)
return err
}
-
destMacAddr, _ := net.ParseMAC(endpoint.MacAddrStr)
// Set Mac addresses
@@ -235,9 +233,8 @@ func (self *Vlrouter) AddLocalEndpoint(endpoint OfnetEndpoint) error {
if self.agent.GetRouterInfo() != nil {
path.nextHopIP = self.agent.GetRouterInfo().RouterIP
}
- self.agent.AddLocalProtoRoute(path)
+ self.agent.AddLocalProtoRoute([]*OfnetProtoRouteInfo{path})
}
-
if endpoint.Ipv6Addr != nil && endpoint.Ipv6Addr.String() != "" {
err = self.AddLocalIpv6Flow(endpoint)
if err != nil {
@@ -294,7 +291,7 @@ func (self *Vlrouter) RemoveLocalEndpoint(endpoint OfnetEndpoint) error {
if self.agent.GetRouterInfo() != nil {
path.nextHopIP = self.agent.GetRouterInfo().RouterIP
}
- self.agent.DeleteLocalProtoRoute(path)
+ self.agent.DeleteLocalProtoRoute([]*OfnetProtoRouteInfo{path})
if endpoint.Ipv6Addr != nil && endpoint.Ipv6Addr.String() != "" {
err = self.RemoveLocalIpv6Flow(endpoint)
@@ -360,7 +357,7 @@ func (self *Vlrouter) AddLocalIpv6Flow(endpoint OfnetEndpoint) error {
if self.agent.GetRouterInfo() != nil {
path.nextHopIP = self.agent.GetRouterInfo().RouterIP
}
- self.agent.AddLocalProtoRoute(path)
+ self.agent.AddLocalProtoRoute([]*OfnetProtoRouteInfo{path})
}
return nil
@@ -399,7 +396,7 @@ func (self *Vlrouter) RemoveLocalIpv6Flow(endpoint OfnetEndpoint) error {
if self.agent.GetRouterInfo() != nil {
path.nextHopIP = self.agent.GetRouterInfo().RouterIP
}
- self.agent.DeleteLocalProtoRoute(path)
+ self.agent.DeleteLocalProtoRoute([]*OfnetProtoRouteInfo{path})
return nil
}
@@ -454,10 +451,14 @@ func (self *Vlrouter) AddEndpoint(endpoint *OfnetEndpoint) error {
//maintainer in cache.
log.Debugf("Storing endpoint info in cache")
self.unresolvedEPs.Set(endpoint.EndpointID, endpoint.EndpointID)
+ return nil
}
}
if endpoint.EndpointType == "external-bgp" {
self.myBgpPeer = endpoint.IpAddr.String()
+ if endpoint.PortNo == 0 {
+ return nil
+ }
}
vrfid := self.agent.getvrfId(endpoint.Vrf)
@@ -529,7 +530,10 @@ func (self *Vlrouter) RemoveEndpoint(endpoint *OfnetEndpoint) error {
}
//Delete the endpoint if it is in the cache
- self.unresolvedEPs.Remove(endpoint.EndpointID)
+ if _, ok := self.unresolvedEPs.Get(endpoint.EndpointID); ok {
+ self.unresolvedEPs.Remove(endpoint.EndpointID)
+ return nil
+ }
// Find the flow entry
//flowId := self.agent.getEndpointIdByIpVlan(endpoint.IpAddr, endpoint.Vlan)
@@ -792,7 +796,6 @@ func (self *Vlrouter) processArp(pkt protocol.Ethernet, inPort uint32) {
self.agent.incrStats("ArpReqUnknownEndpoint")
return
}
-
}
}
@@ -803,7 +806,6 @@ func (self *Vlrouter) processArp(pkt protocol.Ethernet, inPort uint32) {
if endpoint.PortNo == 0 {
log.Infof("Received ARP from BGP Peer on %s: Mac: %s", endpoint.PortNo, endpoint.MacAddrStr)
//learn the mac address and portno for the endpoint
- self.RemoveEndpoint(endpoint)
endpoint.PortNo = inPort
endpoint.MacAddrStr = arpHdr.HWSrc.String()
self.agent.endpointDb.Set(endpoint.EndpointID, endpoint)
@@ -851,7 +853,6 @@ func (self *Vlrouter) processArp(pkt protocol.Ethernet, inPort uint32) {
if endpoint.PortNo == 0 {
log.Infof("Received ARP from BGP Peer on %s: Mac: %s", endpoint.PortNo, endpoint.MacAddrStr)
//learn the mac address and portno for the endpoint
- self.RemoveEndpoint(endpoint)
endpoint.PortNo = inPort
endpoint.MacAddrStr = arpHdr.HWSrc.String()
self.agent.endpointDb.Set(endpoint.EndpointID, endpoint)
@@ -884,14 +885,12 @@ func (self *Vlrouter) resolveUnresolvedEPs(MacAddrStr string, portNo uint32) {
for id := range self.unresolvedEPs.IterBuffered() {
endpointID := id.Val.(string)
endpoint := self.agent.getEndpointByID(endpointID)
- self.RemoveEndpoint(endpoint)
endpoint.PortNo = portNo
endpoint.MacAddrStr = MacAddrStr
self.agent.endpointDb.Set(endpoint.EndpointID, endpoint)
self.AddEndpoint(endpoint)
self.unresolvedEPs.Remove(endpointID)
}
-
}
// AddUplink adds an uplink to the switch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment