summaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2016-01-02 02:13:30 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-01-09 05:17:57 -0800
commitcc8d0fd748f83d774ec59e680586421cd9d9a6d2 (patch)
tree393a564c3d6389084f098732528b3b4206cd60de /server
parent0c1c373e498db1023e4f307f362598a096e36df0 (diff)
config: refactor config structure
- change config variable name to chaincase from camelcase - remove unnecessary wrapper structs which only contain one slice field Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'server')
-rw-r--r--server/bmp.go8
-rw-r--r--server/fsm.go2
-rw-r--r--server/peer.go4
-rw-r--r--server/rpki.go8
-rw-r--r--server/server.go36
5 files changed, 29 insertions, 29 deletions
diff --git a/server/bmp.go b/server/bmp.go
index b439f1e6..86029983 100644
--- a/server/bmp.go
+++ b/server/bmp.go
@@ -45,9 +45,9 @@ type bmpClient struct {
connCh chan *bmpConn
}
-func newBMPClient(conf config.BmpServers, connCh chan *bmpConn) (*bmpClient, error) {
+func newBMPClient(servers []config.BmpServer, connCh chan *bmpConn) (*bmpClient, error) {
b := &bmpClient{}
- if len(conf.BmpServerList) == 0 {
+ if len(servers) == 0 {
return b, nil
}
@@ -87,7 +87,7 @@ func newBMPClient(conf config.BmpServers, connCh chan *bmpConn) (*bmpClient, err
}
}
- for _, c := range conf.BmpServerList {
+ for _, c := range servers {
b := c.Config
go tryConnect(net.JoinHostPort(b.Address, strconv.Itoa(int(b.Port))))
}
@@ -114,7 +114,7 @@ func newBMPClient(conf config.BmpServers, connCh chan *bmpConn) (*bmpClient, err
for _, msg := range m.msgList {
if msg.Header.Type == bgp.BMP_MSG_ROUTE_MONITORING {
c := func() *config.BmpServerConfig {
- for _, c := range conf.BmpServerList {
+ for _, c := range servers {
b := &c.Config
if host == net.JoinHostPort(b.Address, strconv.Itoa(int(b.Port))) {
return b
diff --git a/server/fsm.go b/server/fsm.go
index af635f83..93fa457a 100644
--- a/server/fsm.go
+++ b/server/fsm.go
@@ -421,7 +421,7 @@ func (h *FSMHandler) active() bgp.FSMState {
func capabilitiesFromConfig(gConf *config.Global, pConf *config.Neighbor) []bgp.ParameterCapabilityInterface {
caps := make([]bgp.ParameterCapabilityInterface, 0, 4)
caps = append(caps, bgp.NewCapRouteRefresh())
- for _, rf := range pConf.AfiSafis.AfiSafiList {
+ for _, rf := range pConf.AfiSafis {
k, _ := bgp.GetRouteFamily(rf.AfiSafiName)
caps = append(caps, bgp.NewCapMultiProtocol(k))
}
diff --git a/server/peer.go b/server/peer.go
index 518edefe..5233c892 100644
--- a/server/peer.go
+++ b/server/peer.go
@@ -58,7 +58,7 @@ func NewPeer(g config.Global, conf config.Neighbor, loc *table.TableManager, pol
peer.tableId = tableId
conf.State.SessionState = uint32(bgp.BGP_FSM_IDLE)
conf.Timers.State.Downtime = time.Now().Unix()
- rfs, _ := conf.AfiSafis.ToRfList()
+ rfs, _ := config.AfiSafis(conf.AfiSafis).ToRfList()
peer.adjRibIn = table.NewAdjRib(peer.ID(), rfs)
peer.adjRibOut = table.NewAdjRib(peer.ID(), rfs)
peer.fsm = NewFSM(&g, &conf, policy)
@@ -94,7 +94,7 @@ func (peer *Peer) isRouteReflectorClient() bool {
}
func (peer *Peer) configuredRFlist() []bgp.RouteFamily {
- rfs, _ := peer.conf.AfiSafis.ToRfList()
+ rfs, _ := config.AfiSafis(peer.conf.AfiSafis).ToRfList()
return rfs
}
diff --git a/server/rpki.go b/server/rpki.go
index aa50a475..742dac91 100644
--- a/server/rpki.go
+++ b/server/rpki.go
@@ -106,23 +106,23 @@ type roaClientEvent struct {
type roaManager struct {
AS uint32
roas map[bgp.RouteFamily]*radix.Tree
- config config.RpkiServers
+ config []config.RpkiServer
eventCh chan *roaClientEvent
clientMap map[string]*roaClient
}
-func newROAManager(as uint32, conf config.RpkiServers) (*roaManager, error) {
+func newROAManager(as uint32, servers []config.RpkiServer) (*roaManager, error) {
m := &roaManager{
AS: as,
roas: make(map[bgp.RouteFamily]*radix.Tree),
- config: conf,
+ config: servers,
}
m.roas[bgp.RF_IPv4_UC] = radix.New()
m.roas[bgp.RF_IPv6_UC] = radix.New()
m.eventCh = make(chan *roaClientEvent)
m.clientMap = make(map[string]*roaClient)
- for _, entry := range conf.RpkiServerList {
+ for _, entry := range servers {
c := entry.Config
client := &roaClient{
host: net.JoinHostPort(c.Address, strconv.Itoa(int(c.Port))),
diff --git a/server/server.go b/server/server.go
index 6d9306a6..71eefced 100644
--- a/server/server.go
+++ b/server/server.go
@@ -82,8 +82,8 @@ type BgpServer struct {
updatedPeerCh chan config.Neighbor
fsmincomingCh chan *FsmMsg
fsmStateCh chan *FsmMsg
- rpkiConfigCh chan config.RpkiServers
- bmpConfigCh chan config.BmpServers
+ rpkiConfigCh chan []config.RpkiServer
+ bmpConfigCh chan []config.BmpServer
GrpcReqCh chan *GrpcRequest
policyUpdateCh chan config.RoutingPolicy
@@ -107,14 +107,14 @@ func NewBgpServer() *BgpServer {
b.addedPeerCh = make(chan config.Neighbor)
b.deletedPeerCh = make(chan config.Neighbor)
b.updatedPeerCh = make(chan config.Neighbor)
- b.rpkiConfigCh = make(chan config.RpkiServers)
- b.bmpConfigCh = make(chan config.BmpServers)
+ b.rpkiConfigCh = make(chan []config.RpkiServer)
+ b.bmpConfigCh = make(chan []config.BmpServer)
b.bmpConnCh = make(chan *bmpConn)
b.GrpcReqCh = make(chan *GrpcRequest, 1)
b.policyUpdateCh = make(chan config.RoutingPolicy)
b.neighborMap = make(map[string]*Peer)
b.watchers = make(map[watcherType]watcher)
- b.roaManager, _ = newROAManager(0, config.RpkiServers{})
+ b.roaManager, _ = newROAManager(0, nil)
b.policy = table.NewRoutingPolicy()
return &b
}
@@ -166,8 +166,8 @@ func (server *BgpServer) Serve() {
}
}
- server.bmpClient, _ = newBMPClient(config.BmpServers{BmpServerList: []config.BmpServer{}}, server.bmpConnCh)
- server.roaManager, _ = newROAManager(g.Config.As, config.RpkiServers{})
+ server.bmpClient, _ = newBMPClient(nil, server.bmpConnCh)
+ server.roaManager, _ = newROAManager(g.Config.As, nil)
if g.Mrt.FileName != "" {
w, err := newMrtWatcher(g.Mrt.FileName)
@@ -182,7 +182,7 @@ func (server *BgpServer) Serve() {
if g.Zebra.Url == "" {
g.Zebra.Url = "unix:/var/run/quagga/zserv.api"
}
- err := server.NewZclient(g.Zebra.Url, g.Zebra.RedistributeRouteType)
+ err := server.NewZclient(g.Zebra.Url, g.Zebra.RedistributeRouteTypeList)
if err != nil {
log.Error(err)
}
@@ -221,7 +221,7 @@ func (server *BgpServer) Serve() {
}
}(broadcastCh)
- rfs, _ := g.AfiSafis.ToRfList()
+ rfs, _ := config.AfiSafis(g.AfiSafis).ToRfList()
server.globalRib = table.NewTableManager(rfs, g.MplsLabelRange.MinLabel, g.MplsLabelRange.MaxLabel)
server.listenerMap = make(map[string]*net.TCPListener)
acceptCh := make(chan *net.TCPConn, 4096)
@@ -965,11 +965,11 @@ func (server *BgpServer) SetGlobalType(g config.Global) {
}
}
-func (server *BgpServer) SetRpkiConfig(c config.RpkiServers) {
+func (server *BgpServer) SetRpkiConfig(c []config.RpkiServer) {
server.rpkiConfigCh <- c
}
-func (server *BgpServer) SetBmpConfig(c config.BmpServers) {
+func (server *BgpServer) SetBmpConfig(c []config.BmpServer) {
server.bmpConfigCh <- c
}
@@ -2049,19 +2049,19 @@ func (server *BgpServer) handleGrpcModNeighbor(grpcReq *GrpcRequest) (sMsgs []*S
if a.ApplyPolicy.ImportPolicy != nil {
pconf.ApplyPolicy.Config.DefaultImportPolicy = config.DefaultPolicyType(a.ApplyPolicy.ImportPolicy.Default)
for _, p := range a.ApplyPolicy.ImportPolicy.Policies {
- pconf.ApplyPolicy.Config.ImportPolicy = append(pconf.ApplyPolicy.Config.ImportPolicy, p.Name)
+ pconf.ApplyPolicy.Config.ImportPolicyList = append(pconf.ApplyPolicy.Config.ImportPolicyList, p.Name)
}
}
if a.ApplyPolicy.ExportPolicy != nil {
pconf.ApplyPolicy.Config.DefaultExportPolicy = config.DefaultPolicyType(a.ApplyPolicy.ExportPolicy.Default)
for _, p := range a.ApplyPolicy.ExportPolicy.Policies {
- pconf.ApplyPolicy.Config.ExportPolicy = append(pconf.ApplyPolicy.Config.ExportPolicy, p.Name)
+ pconf.ApplyPolicy.Config.ExportPolicyList = append(pconf.ApplyPolicy.Config.ExportPolicyList, p.Name)
}
}
if a.ApplyPolicy.InPolicy != nil {
pconf.ApplyPolicy.Config.DefaultInPolicy = config.DefaultPolicyType(a.ApplyPolicy.InPolicy.Default)
for _, p := range a.ApplyPolicy.InPolicy.Policies {
- pconf.ApplyPolicy.Config.InPolicy = append(pconf.ApplyPolicy.Config.InPolicy, p.Name)
+ pconf.ApplyPolicy.Config.InPolicyList = append(pconf.ApplyPolicy.Config.InPolicyList, p.Name)
}
}
}
@@ -2072,14 +2072,14 @@ func (server *BgpServer) handleGrpcModNeighbor(grpcReq *GrpcRequest) (sMsgs []*S
return pconf, fmt.Errorf("invalid address family: %d", family)
}
cAfiSafi := config.AfiSafi{AfiSafiName: name}
- pconf.AfiSafis.AfiSafiList = append(pconf.AfiSafis.AfiSafiList, cAfiSafi)
+ pconf.AfiSafis = append(pconf.AfiSafis, cAfiSafi)
}
} else {
if net.ParseIP(a.Conf.NeighborAddress).To4() != nil {
- pconf.AfiSafis.AfiSafiList = []config.AfiSafi{
+ pconf.AfiSafis = []config.AfiSafi{
config.AfiSafi{AfiSafiName: "ipv4-unicast"}}
} else {
- pconf.AfiSafis.AfiSafiList = []config.AfiSafi{
+ pconf.AfiSafis = []config.AfiSafi{
config.AfiSafi{AfiSafiName: "ipv6-unicast"}}
}
}
@@ -2496,7 +2496,7 @@ func (server *BgpServer) handleModRpki(grpcReq *GrpcRequest) {
r := config.RpkiServer{}
r.Config.Address = arg.Address
r.Config.Port = arg.Port
- server.bgpConfig.RpkiServers.RpkiServerList = append(server.bgpConfig.RpkiServers.RpkiServerList, r)
+ server.bgpConfig.RpkiServers = append(server.bgpConfig.RpkiServers, r)
server.roaManager, _ = newROAManager(server.bgpConfig.Global.Config.As, server.bgpConfig.RpkiServers)
grpcDone(grpcReq, nil)
return