summaryrefslogtreecommitdiffhomepage
path: root/config
diff options
context:
space:
mode:
authorSatoshi Fujimoto <satoshi.fujimoto7@gmail.com>2017-12-12 11:35:43 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2017-12-16 22:10:33 +0900
commit61cdca78d7ee84ac2f0384f2096a42fa54acb6b7 (patch)
treef5383109893e78f0d8504a7b26da8dbe7e63b255 /config
parenteb5e3b8ff21726f819e431751777b489ba7da546 (diff)
config/util: Refactor to make arguments to receivers
For code readability, this commit make some arguments to receivers. Signed-off-by: Satoshi Fujimoto <satoshi.fujimoto7@gmail.com>
Diffstat (limited to 'config')
-rw-r--r--config/util.go68
1 files changed, 34 insertions, 34 deletions
diff --git a/config/util.go b/config/util.go
index bcb5f2a7..dfe60d6c 100644
--- a/config/util.go
+++ b/config/util.go
@@ -86,19 +86,9 @@ func (n *Neighbor) IsEBGPPeer(g *Global) bool {
return n.Config.PeerAs != g.Config.As
}
-type AfiSafis []AfiSafi
-
-func (c AfiSafis) ToRfList() ([]bgp.RouteFamily, error) {
- rfs := make([]bgp.RouteFamily, 0, len(c))
- for _, af := range c {
- rfs = append(rfs, af.State.Family)
- }
- return rfs, nil
-}
-
-func CreateRfMap(p *Neighbor) map[bgp.RouteFamily]bgp.BGPAddPathMode {
+func (n *Neighbor) CreateRfMap() map[bgp.RouteFamily]bgp.BGPAddPathMode {
rfMap := make(map[bgp.RouteFamily]bgp.BGPAddPathMode)
- for _, af := range p.AfiSafis {
+ for _, af := range n.AfiSafis {
mode := bgp.BGP_ADD_PATH_NONE
if af.AddPaths.State.Receive {
mode |= bgp.BGP_ADD_PATH_RECEIVE
@@ -111,8 +101,8 @@ func CreateRfMap(p *Neighbor) map[bgp.RouteFamily]bgp.BGPAddPathMode {
return rfMap
}
-func GetAfiSafi(p *Neighbor, family bgp.RouteFamily) *AfiSafi {
- for _, a := range p.AfiSafis {
+func (n *Neighbor) GetAfiSafi(family bgp.RouteFamily) *AfiSafi {
+ for _, a := range n.AfiSafis {
if string(a.Config.AfiSafiName) == family.String() {
return &a
}
@@ -120,6 +110,36 @@ func GetAfiSafi(p *Neighbor, family bgp.RouteFamily) *AfiSafi {
return nil
}
+func (n *Neighbor) ExtractNeighborAddress() (string, error) {
+ addr := n.State.NeighborAddress
+ if addr == "" {
+ addr = n.Config.NeighborAddress
+ if addr == "" {
+ return "", fmt.Errorf("NeighborAddress is not configured")
+ }
+ }
+ return addr, nil
+}
+
+func (n *Neighbor) IsAddPathReceiveEnabled(family bgp.RouteFamily) bool {
+ for _, af := range n.AfiSafis {
+ if af.State.Family == family {
+ return af.AddPaths.State.Receive
+ }
+ }
+ return false
+}
+
+type AfiSafis []AfiSafi
+
+func (c AfiSafis) ToRfList() ([]bgp.RouteFamily, error) {
+ rfs := make([]bgp.RouteFamily, 0, len(c))
+ for _, af := range c {
+ rfs = append(rfs, af.State.Family)
+ }
+ return rfs, nil
+}
+
func CheckAfiSafisChange(x, y []AfiSafi) bool {
if len(x) != len(y) {
return true
@@ -173,23 +193,3 @@ func ParseMaskLength(prefix, mask string) (int, int, error) {
}
return min, max, nil
}
-
-func ExtractNeighborAddress(c *Neighbor) (string, error) {
- addr := c.State.NeighborAddress
- if addr == "" {
- addr = c.Config.NeighborAddress
- if addr == "" {
- return "", fmt.Errorf("NeighborAddress is not configured")
- }
- }
- return addr, nil
-}
-
-func (n *Neighbor) IsAddPathReceiveEnabled(family bgp.RouteFamily) bool {
- for _, af := range n.AfiSafis {
- if af.State.Family == family {
- return af.AddPaths.State.Receive
- }
- }
- return false
-}