diff options
author | Hiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp> | 2015-03-24 22:11:27 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-03-24 22:11:27 +0900 |
commit | 38bb94707f35e103db3b313978bcac4046f99a20 (patch) | |
tree | 6f740cfc751931fc47c223c39ce7dfeaa87fe1e7 /config | |
parent | 8fb175eb2c3079613a7970e85d1648207c9d829b (diff) |
policy: apply import/export policy
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'config')
-rw-r--r-- | config/serve.go | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/config/serve.go b/config/serve.go index 6832f6b4..390229c1 100644 --- a/config/serve.go +++ b/config/serve.go @@ -3,9 +3,15 @@ package config import ( "github.com/BurntSushi/toml" log "github.com/Sirupsen/logrus" + "reflect" ) -func ReadConfigfileServe(path string, configCh chan Bgp, reloadCh chan bool) { +type BgpConfigSet struct { + Bgp Bgp + Policy RoutingPolicy +} + +func ReadConfigfileServe(path string, configCh chan BgpConfigSet, reloadCh chan bool) { for { <-reloadCh @@ -18,7 +24,14 @@ func ReadConfigfileServe(path string, configCh chan Bgp, reloadCh chan bool) { log.Fatal("can't read config file ", path, ", ", err) } - configCh <- b + p := RoutingPolicy{} + md, err = toml.DecodeFile(path, &p) + if err != nil { + log.Fatal("can't read config file ", path, ", ", err) + } + + bgpConfig := BgpConfigSet{Bgp: b, Policy: p} + configCh <- bgpConfig } } @@ -58,3 +71,23 @@ func UpdateConfig(curC *Bgp, newC *Bgp) (*Bgp, []Neighbor, []Neighbor) { bgpConfig.NeighborList = newC.NeighborList return &bgpConfig, added, deleted } + +func CheckPolicyDifference(currentPolicy *RoutingPolicy, newPolicy *RoutingPolicy) bool { + + log.Debug("current policy : ", currentPolicy) + log.Debug("newPolicy policy : ", newPolicy) + + var result bool = false + if currentPolicy == nil && newPolicy == nil { + + result = false + } else { + if currentPolicy != nil && newPolicy != nil { + // TODO: reconsider the way of policy object comparison + result = !reflect.DeepEqual(*currentPolicy, *newPolicy) + } else { + result = true + } + } + return result +} |