diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-10-19 14:39:04 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-10-20 10:33:10 +0900 |
commit | f634b5035729485105d54c25198d36542337aea5 (patch) | |
tree | 1c39317df070390f397240868e414b78356c5cd0 /server/peer.go | |
parent | 204eacc5c0503cecc796a74fd0c1948ad6a28051 (diff) |
api: support policy assignment modification via grpc
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'server/peer.go')
-rw-r--r-- | server/peer.go | 57 |
1 files changed, 30 insertions, 27 deletions
diff --git a/server/peer.go b/server/peer.go index 71d07c25..cbc3005a 100644 --- a/server/peer.go +++ b/server/peer.go @@ -41,7 +41,7 @@ type Peer struct { peerInfo *table.PeerInfo outgoing chan *bgp.BGPMessage inPolicies []*table.Policy - defaultInPolicy config.DefaultPolicyType + defaultInPolicy table.RouteType accepted uint32 staleAccepted bool isConfederationMember bool @@ -381,49 +381,52 @@ func (peer *Peer) ToApiStruct() *api.Peer { } } -func (peer *Peer) setPolicy(policy map[string]*table.Policy) { - policyConf := peer.conf.ApplyPolicy - inPolicies := make([]*table.Policy, 0) - for _, policyName := range policyConf.ApplyPolicyConfig.InPolicy { - log.WithFields(log.Fields{ - "Topic": "Peer", - "Key": peer.conf.NeighborConfig.NeighborAddress, - "PolicyName": policyName, - }).Info("in-policy installed") - if pol, ok := policy[policyName]; ok { - log.Debug("in policy : ", pol) - inPolicies = append(inPolicies, pol) +func (peer *Peer) GetPolicy(d table.PolicyDirection) []*table.Policy { + switch d { + case table.POLICY_DIRECTION_IN: + return peer.inPolicies + default: + if peer.localRib != nil { + return peer.localRib.GetPolicy(d) } } - peer.inPolicies = inPolicies - peer.defaultInPolicy = policyConf.ApplyPolicyConfig.DefaultInPolicy - if peer.localRib != nil { - peer.localRib.SetPolicy(policyConf, policy) - } + return nil } -func (peer *Peer) GetPolicy(d table.PolicyDirection) []*table.Policy { +func (peer *Peer) SetPolicy(d table.PolicyDirection, policies []*table.Policy) error { switch d { case table.POLICY_DIRECTION_IN: - return peer.inPolicies + peer.inPolicies = policies default: - return peer.localRib.GetPolicy(d) + if peer.localRib != nil { + return peer.localRib.SetPolicy(d, policies) + } } + return nil } func (peer *Peer) GetDefaultPolicy(d table.PolicyDirection) table.RouteType { - var def config.DefaultPolicyType switch d { case table.POLICY_DIRECTION_IN: - def = peer.defaultInPolicy + return peer.defaultInPolicy default: - return peer.localRib.GetDefaultPolicy(d) + if peer.localRib != nil { + return peer.localRib.GetDefaultPolicy(d) + } } + return table.ROUTE_TYPE_NONE +} - if def == config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE { - return table.ROUTE_TYPE_ACCEPT +func (peer *Peer) SetDefaultPolicy(d table.PolicyDirection, typ table.RouteType) error { + switch d { + case table.POLICY_DIRECTION_IN: + peer.defaultInPolicy = typ + default: + if peer.localRib != nil { + return peer.localRib.SetDefaultPolicy(d, typ) + } } - return table.ROUTE_TYPE_REJECT + return nil } func (peer *Peer) ApplyPolicy(d table.PolicyDirection, paths []*table.Path) ([]*table.Path, []*table.Path) { |