Adding support for gobgp configuration
This commit is contained in:
parent
bc09e62091
commit
9dd5f34f8e
@ -8,12 +8,14 @@ import (
|
||||
|
||||
"github.com/alice-lg/alice-lg/backend/sources"
|
||||
"github.com/alice-lg/alice-lg/backend/sources/birdwatcher"
|
||||
"github.com/alice-lg/alice-lg/backend/sources/gobgp"
|
||||
|
||||
"github.com/go-ini/ini"
|
||||
)
|
||||
|
||||
const SOURCE_UNKNOWN = 0
|
||||
const SOURCE_BIRDWATCHER = 1
|
||||
const SOURCE_GOBGP = 2
|
||||
|
||||
type ServerConfig struct {
|
||||
Listen string `ini:"listen_http"`
|
||||
@ -90,6 +92,7 @@ type SourceConfig struct {
|
||||
// Source configurations
|
||||
Type int
|
||||
Birdwatcher birdwatcher.Config
|
||||
GoBGP gobgp.Config
|
||||
|
||||
// Source instance
|
||||
instance sources.Source
|
||||
@ -133,6 +136,8 @@ func getBackendType(section *ini.Section) int {
|
||||
name := section.Name()
|
||||
if strings.HasSuffix(name, "birdwatcher") {
|
||||
return SOURCE_BIRDWATCHER
|
||||
} else if strings.HasSuffix(name, "gobgp") {
|
||||
return SOURCE_GOBGP
|
||||
}
|
||||
|
||||
return SOURCE_UNKNOWN
|
||||
@ -671,6 +676,8 @@ func (self *SourceConfig) getInstance() sources.Source {
|
||||
switch self.Type {
|
||||
case SOURCE_BIRDWATCHER:
|
||||
instance = birdwatcher.NewBirdwatcher(self.Birdwatcher)
|
||||
case SOURCE_GOBGP:
|
||||
instance = gobgp.NewGoBGP(self.GoBGP)
|
||||
}
|
||||
|
||||
self.instance = instance
|
||||
|
8
backend/sources/gobgp/config.go
Normal file
8
backend/sources/gobgp/config.go
Normal file
@ -0,0 +1,8 @@
|
||||
package gobgp;
|
||||
|
||||
type Config struct {
|
||||
Id string
|
||||
Name string
|
||||
|
||||
Host string `ini:"api"`
|
||||
}
|
137
backend/sources/gobgp/source.go
Normal file
137
backend/sources/gobgp/source.go
Normal file
@ -0,0 +1,137 @@
|
||||
package gobgp
|
||||
|
||||
import (
|
||||
aliceapi "github.com/alice-lg/alice-lg/backend/api"
|
||||
"github.com/alice-lg/alice-lg/backend/caches"
|
||||
api "github.com/osrg/gobgp/api"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"log"
|
||||
_ "sort"
|
||||
)
|
||||
|
||||
type GoBGP struct {
|
||||
config Config
|
||||
client api.GobgpApiClient
|
||||
|
||||
// Caches: Neighbors
|
||||
neighborsCache *caches.NeighborsCache
|
||||
|
||||
// Caches: Routes
|
||||
routesRequiredCache *caches.RoutesCache
|
||||
routesReceivedCache *caches.RoutesCache
|
||||
routesFilteredCache *caches.RoutesCache
|
||||
routesNotExportedCache *caches.RoutesCache
|
||||
}
|
||||
|
||||
func NewGoBGP(config Config) *GoBGP {
|
||||
|
||||
conn, err := grpc.Dial(":50051", grpc.WithInsecure())
|
||||
if err != nil {
|
||||
log.Fatalf("did not connect: %v", err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
client := api.NewGobgpApiClient(conn)
|
||||
|
||||
|
||||
|
||||
|
||||
// Cache settings:
|
||||
// TODO: Maybe read from config file
|
||||
neighborsCacheDisable := false
|
||||
|
||||
routesCacheDisabled := false
|
||||
routesCacheMaxSize := 128
|
||||
|
||||
// Initialize caches
|
||||
neighborsCache := caches.NewNeighborsCache(neighborsCacheDisable)
|
||||
routesRequiredCache := caches.NewRoutesCache(
|
||||
routesCacheDisabled, routesCacheMaxSize)
|
||||
routesReceivedCache := caches.NewRoutesCache(
|
||||
routesCacheDisabled, routesCacheMaxSize)
|
||||
routesFilteredCache := caches.NewRoutesCache(
|
||||
routesCacheDisabled, routesCacheMaxSize)
|
||||
routesNotExportedCache := caches.NewRoutesCache(
|
||||
routesCacheDisabled, routesCacheMaxSize)
|
||||
|
||||
return &GoBGP{
|
||||
config: config,
|
||||
client: client,
|
||||
|
||||
neighborsCache: neighborsCache,
|
||||
|
||||
routesRequiredCache: routesRequiredCache,
|
||||
routesReceivedCache: routesReceivedCache,
|
||||
routesFilteredCache: routesFilteredCache,
|
||||
routesNotExportedCache: routesNotExportedCache,
|
||||
}
|
||||
}
|
||||
|
||||
func (gobgp *GoBGP) Status() (*aliceapi.StatusResponse, error) {
|
||||
return nil,nil
|
||||
}
|
||||
|
||||
// Get bird BGP protocols
|
||||
func (gobgp *GoBGP) Neighbours() (*aliceapi.NeighboursResponse, error) {
|
||||
return nil,nil
|
||||
}
|
||||
|
||||
// Get neighbors from neighbors summary
|
||||
func (gobgp *GoBGP) summaryNeighbors() (*aliceapi.NeighboursResponse, error) {
|
||||
return nil,nil
|
||||
}
|
||||
|
||||
// Get neighbors from protocols
|
||||
func (gobgp *GoBGP) bgpProtocolsNeighbors() (*aliceapi.NeighboursResponse, error) {
|
||||
return nil,nil
|
||||
}
|
||||
|
||||
// Get filtered and exported routes
|
||||
func (gobgp *GoBGP) Routes(neighbourId string) (*aliceapi.RoutesResponse, error) {
|
||||
return nil,nil
|
||||
}
|
||||
|
||||
/*
|
||||
RoutesRequired is a specialized request to fetch:
|
||||
|
||||
- RoutesExported and
|
||||
- RoutesFiltered
|
||||
|
||||
from Birdwatcher. As the not exported routes can be very many
|
||||
these are optional and can be loaded on demand using the
|
||||
RoutesNotExported() API.
|
||||
|
||||
A route deduplication is applied.
|
||||
*/
|
||||
|
||||
func (gobgp *GoBGP) RoutesRequired(neighborId string,) (*aliceapi.RoutesResponse, error) {
|
||||
return nil,nil
|
||||
}
|
||||
|
||||
|
||||
// Get all received routes
|
||||
func (gobgp *GoBGP) RoutesReceived(neighborId string,) (*aliceapi.RoutesResponse, error) {
|
||||
return nil,nil
|
||||
}
|
||||
|
||||
|
||||
// Get all filtered routes
|
||||
func (gobgp *GoBGP) RoutesFiltered(neighborId string,) (*aliceapi.RoutesResponse, error) {
|
||||
return nil,nil
|
||||
}
|
||||
|
||||
// Get all not exported routes
|
||||
func (gobgp *GoBGP) RoutesNotExported(neighborId string,) (*aliceapi.RoutesResponse, error) {
|
||||
return nil,nil
|
||||
}
|
||||
|
||||
// Make routes lookup
|
||||
func (gobgp *GoBGP) LookupPrefix(prefix string) (*aliceapi.RoutesLookupResponse, error) {
|
||||
return nil,nil
|
||||
}
|
||||
|
||||
func (gobgp *GoBGP) AllRoutes() (*aliceapi.RoutesResponse, error) {
|
||||
return nil,nil
|
||||
}
|
||||
|
2
go.mod
2
go.mod
@ -5,4 +5,6 @@ require (
|
||||
github.com/daaku/go.zipexe v0.0.0-20150329023125-a5fe2436ffcb // indirect
|
||||
github.com/go-ini/ini v1.41.0
|
||||
github.com/julienschmidt/httprouter v1.2.0
|
||||
github.com/osrg/gobgp v2.0.0+incompatible
|
||||
google.golang.org/grpc v1.17.0
|
||||
)
|
||||
|
24
go.sum
24
go.sum
@ -1,8 +1,32 @@
|
||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
github.com/GeertJohan/go.rice v0.0.0-20181229193832-0af3f3b09a0a h1:QgnJzkfb29JXtLXJN8alxzPWZhiNcAYZOa06dU5O46w=
|
||||
github.com/GeertJohan/go.rice v0.0.0-20181229193832-0af3f3b09a0a/go.mod h1:DgrzXonpdQbfN3uYaGz1EG4Sbhyum/MMIn6Cphlh2bw=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/daaku/go.zipexe v0.0.0-20150329023125-a5fe2436ffcb h1:tUf55Po0vzOendQ7NWytcdK0VuzQmfAgvGBUOQvN0WA=
|
||||
github.com/daaku/go.zipexe v0.0.0-20150329023125-a5fe2436ffcb/go.mod h1:U0vRfAucUOohvdCxt5MWLF+TePIL0xbCkbKIiV8TQCE=
|
||||
github.com/go-ini/ini v1.41.0 h1:526aoxDtxRHFQKMZfcX2OG9oOI8TJ5yPLM0Mkno/uTY=
|
||||
github.com/go-ini/ini v1.41.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/julienschmidt/httprouter v1.2.0 h1:TDTW5Yz1mjftljbcKqRcrYhd4XeOoI98t+9HbQbYf7g=
|
||||
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/osrg/gobgp v2.0.0+incompatible h1:91ARQbE1AtO0U4TIxHPJ7wYVZIqduyBwS1+FjlHlmrY=
|
||||
github.com/osrg/gobgp v2.0.0+incompatible/go.mod h1:vGVJPLW6JFDD7WA1vJsjB8OKmbbC2TKwHtr90CZS/u4=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d h1:g9qWBGx4puODJTMVyoPrpoxPFgVGd+z1DZwjfRu4d0I=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/grpc v1.17.0 h1:TRJYBgMclJvGYn2rIMjj+h9KtMt5r1Ij7ODVRIZkwhk=
|
||||
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
|
||||
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
|
Loading…
x
Reference in New Issue
Block a user