Skip to content

Commit

Permalink
feat(frr): get frr address from external config
Browse files Browse the repository at this point in the history
Signed-off-by: Boris Glimcher <[email protected]>
  • Loading branch information
glimchb committed Oct 27, 2023
1 parent 695ff86 commit c5d770b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
18 changes: 12 additions & 6 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ func main() {
var redisAddress string
flag.StringVar(&redisAddress, "redis_addr", "127.0.0.1:6379", "Redis address in ip_address:port format")

var frrAddress string
flag.StringVar(&frrAddress, "frr_addr", "127.0.0.1", "Frr address in ip_address format, no port")

flag.Parse()

// Create KV store for persistence
Expand All @@ -67,10 +70,10 @@ func main() {
}(store)

go runGatewayServer(grpcPort, httpPort)
runGrpcServer(grpcPort, tlsFiles, store)
runGrpcServer(grpcPort, tlsFiles, frrAddress, store)
}

func runGrpcServer(grpcPort int, tlsFiles string, store gokv.Store) {
func runGrpcServer(grpcPort int, tlsFiles, frrAddress string, store gokv.Store) {
tp := utils.InitTracerProvider("opi-evpn-bridge")
defer func() {
if err := tp.Shutdown(context.Background()); err != nil {
Expand Down Expand Up @@ -112,10 +115,13 @@ func runGrpcServer(grpcPort int, tlsFiles string, store gokv.Store) {
)
s := grpc.NewServer(serverOptions...)

bridgeServer := bridge.NewServer(store)
portServer := port.NewServer(store)
vrfServer := vrf.NewServer(store)
sviServer := svi.NewServer(store)
nLink := utils.NewNetlinkWrapper()
frr := utils.NewFrrWrapperWithArgs(frrAddress)

bridgeServer := bridge.NewServerWithArgs(nLink, frr, store)
portServer := port.NewServerWithArgs(nLink, frr, store)
vrfServer := vrf.NewServerWithArgs(nLink, frr, store)
sviServer := svi.NewServerWithArgs(nLink, frr, store)

pe.RegisterLogicalBridgeServiceServer(s, bridgeServer)
pe.RegisterBridgePortServiceServer(s, portServer)
Expand Down
24 changes: 15 additions & 9 deletions pkg/utils/frr.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (
)

const (
network = "tcp"
password = "opi"
address = "localhost"
timeout = 10 * time.Second
network = "tcp"
password = "opi"
defaultAddress = "localhost"
timeout = 10 * time.Second
)

// Ports defined here https://docs.frrouting.org/en/latest/setup.html#servicess
Expand Down Expand Up @@ -58,13 +58,19 @@ type Frr interface {

// FrrWrapper wrapper for Frr package
type FrrWrapper struct {
tracer trace.Tracer
address string
tracer trace.Tracer
}

// NewFrrWrapper creates initialized instance of FrrWrapper
// NewFrrWrapper creates initialized instance of FrrWrapper with default address
func NewFrrWrapper() *FrrWrapper {
return NewFrrWrapperWithArgs(defaultAddress)
}

// NewFrrWrapperWithArgs creates initialized instance of FrrWrapper
func NewFrrWrapperWithArgs(address string) *FrrWrapper {
// default tracer name is good for now
return &FrrWrapper{tracer: otel.Tracer("")}
return &FrrWrapper{address: address, tracer: otel.Tracer("")}
}

// build time check that struct implements interface
Expand Down Expand Up @@ -141,13 +147,13 @@ func (n *FrrWrapper) TelnetDialAndCommunicate(ctx context.Context, command strin
childSpan.SetAttributes(
attribute.Int("frr.port", port),
attribute.String("frr.name", command),
attribute.String("frr.address", address),
attribute.String("frr.address", n.address),
attribute.String("frr.network", network),
)
}

// new connection every time
conn, err := telnet.DialTimeout(network, fmt.Sprintf("%s:%d", address, port), timeout)
conn, err := telnet.DialTimeout(network, fmt.Sprintf("%s:%d", n.address, port), timeout)
if err != nil {
return "", err
}
Expand Down

0 comments on commit c5d770b

Please sign in to comment.