From dd6140c6a28eb6e2dc41b47611240647e2b938fd Mon Sep 17 00:00:00 2001 From: ISHIDA Wataru Date: Fri, 9 Oct 2015 19:39:03 +0900 Subject: table: merge policy package into table --- server/peer.go | 55 ++++++++++++++++++++++++++----------------------------- 1 file changed, 26 insertions(+), 29 deletions(-) (limited to 'server/peer.go') diff --git a/server/peer.go b/server/peer.go index 90c73469..4a602675 100644 --- a/server/peer.go +++ b/server/peer.go @@ -21,7 +21,6 @@ import ( api "github.com/osrg/gobgp/api" "github.com/osrg/gobgp/config" "github.com/osrg/gobgp/packet" - "github.com/osrg/gobgp/policy" "github.com/osrg/gobgp/table" "net" "time" @@ -41,13 +40,13 @@ type Peer struct { adjRib *table.AdjRib peerInfo *table.PeerInfo outgoing chan *bgp.BGPMessage - inPolicies []*policy.Policy + inPolicies []*table.Policy defaultInPolicy config.DefaultPolicyType accepted uint32 staleAccepted bool - importPolicies []*policy.Policy + importPolicies []*table.Policy defaultImportPolicy config.DefaultPolicyType - exportPolicies []*policy.Policy + exportPolicies []*table.Policy defaultExportPolicy config.DefaultPolicyType isConfederationMember bool recvOpen *bgp.BGPMessage @@ -358,10 +357,9 @@ func (peer *Peer) ToApiStruct() *api.Peer { } } -func (peer *Peer) setPolicy(policyMap map[string]*policy.Policy) { - // configure in-policy +func (peer *Peer) setPolicy(policyMap map[string]*table.Policy) { policyConf := peer.conf.ApplyPolicy - inPolicies := make([]*policy.Policy, 0) + inPolicies := make([]*table.Policy, 0) for _, policyName := range policyConf.ApplyPolicyConfig.InPolicy { log.WithFields(log.Fields{ "Topic": "Peer", @@ -376,13 +374,13 @@ func (peer *Peer) setPolicy(policyMap map[string]*policy.Policy) { peer.inPolicies = inPolicies peer.defaultInPolicy = policyConf.ApplyPolicyConfig.DefaultInPolicy - importPolicies := make([]*policy.Policy, 0) + importPolicies := make([]*table.Policy, 0) for _, policyName := range policyConf.ApplyPolicyConfig.ImportPolicy { log.WithFields(log.Fields{ "Topic": "Peer", "Key": peer.conf.NeighborConfig.NeighborAddress, "PolicyName": policyName, - }).Info("import policy installed") + }).Info("import-policy installed") if pol, ok := policyMap[policyName]; ok { log.Debug("import policy : ", pol) importPolicies = append(importPolicies, pol) @@ -391,14 +389,13 @@ func (peer *Peer) setPolicy(policyMap map[string]*policy.Policy) { peer.importPolicies = importPolicies peer.defaultImportPolicy = policyConf.ApplyPolicyConfig.DefaultImportPolicy - // configure export policy - exportPolicies := make([]*policy.Policy, 0) + exportPolicies := make([]*table.Policy, 0) for _, policyName := range policyConf.ApplyPolicyConfig.ExportPolicy { log.WithFields(log.Fields{ "Topic": "Peer", "Key": peer.conf.NeighborConfig.NeighborAddress, "PolicyName": policyName, - }).Info("export policy installed") + }).Info("export-policy installed") if pol, ok := policyMap[policyName]; ok { log.Debug("export policy : ", pol) exportPolicies = append(exportPolicies, pol) @@ -408,60 +405,60 @@ func (peer *Peer) setPolicy(policyMap map[string]*policy.Policy) { peer.defaultExportPolicy = policyConf.ApplyPolicyConfig.DefaultExportPolicy } -func (peer *Peer) GetPolicy(d PolicyDirection) []*policy.Policy { +func (peer *Peer) GetPolicy(d table.PolicyDirection) []*table.Policy { switch d { - case POLICY_DIRECTION_IN: + case table.POLICY_DIRECTION_IN: return peer.inPolicies - case POLICY_DIRECTION_IMPORT: + case table.POLICY_DIRECTION_IMPORT: return peer.importPolicies - case POLICY_DIRECTION_EXPORT: + case table.POLICY_DIRECTION_EXPORT: return peer.exportPolicies } return nil } -func (peer *Peer) GetDefaultPolicy(d PolicyDirection) policy.RouteType { +func (peer *Peer) GetDefaultPolicy(d table.PolicyDirection) table.RouteType { var def config.DefaultPolicyType switch d { - case POLICY_DIRECTION_IN: + case table.POLICY_DIRECTION_IN: def = peer.defaultInPolicy - case POLICY_DIRECTION_IMPORT: + case table.POLICY_DIRECTION_IMPORT: def = peer.defaultImportPolicy - case POLICY_DIRECTION_EXPORT: + case table.POLICY_DIRECTION_EXPORT: def = peer.defaultExportPolicy } if def == config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE { - return policy.ROUTE_TYPE_ACCEPT + return table.ROUTE_TYPE_ACCEPT } - return policy.ROUTE_TYPE_REJECT + return table.ROUTE_TYPE_REJECT } -func (peer *Peer) ApplyPolicy(d PolicyDirection, paths []*table.Path) ([]*table.Path, []*table.Path) { - if d == POLICY_DIRECTION_IN { +func (peer *Peer) ApplyPolicy(d table.PolicyDirection, paths []*table.Path) ([]*table.Path, []*table.Path) { + if d == table.POLICY_DIRECTION_IN { peer.staleAccepted = true } newpaths := make([]*table.Path, 0, len(paths)) filteredPaths := make([]*table.Path, 0) for _, path := range paths { - result := policy.ROUTE_TYPE_NONE + result := table.ROUTE_TYPE_NONE newpath := path for _, p := range peer.GetPolicy(d) { result, newpath = p.Apply(path) - if result != policy.ROUTE_TYPE_NONE { + if result != table.ROUTE_TYPE_NONE { break } } - if result == policy.ROUTE_TYPE_NONE { + if result == table.ROUTE_TYPE_NONE { result = peer.GetDefaultPolicy(d) } switch result { - case policy.ROUTE_TYPE_ACCEPT: + case table.ROUTE_TYPE_ACCEPT: path.Filtered = false newpaths = append(newpaths, newpath) - case policy.ROUTE_TYPE_REJECT: + case table.ROUTE_TYPE_REJECT: path.Filtered = true filteredPaths = append(filteredPaths, path) log.WithFields(log.Fields{ -- cgit v1.2.3