summaryrefslogtreecommitdiffhomepage
path: root/server/server.go
diff options
context:
space:
mode:
authorHiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp>2015-06-19 20:58:14 +0900
committerHiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp>2015-07-01 14:20:42 +0900
commita45849df3993acf57d410df81176cb795510db26 (patch)
treecb20bc65c62238ab538ae80f941ce16d824d4917 /server/server.go
parentd1850ee8f591d80a44f4d48f2e475135a2df8a00 (diff)
policy: distribute policy
Diffstat (limited to 'server/server.go')
-rw-r--r--server/server.go41
1 files changed, 33 insertions, 8 deletions
diff --git a/server/server.go b/server/server.go
index 96fb651d..fa831c19 100644
--- a/server/server.go
+++ b/server/server.go
@@ -34,6 +34,14 @@ const (
GLOBAL_RIB_NAME = "global"
)
+type Direction string
+
+const (
+ POLICY_DIRECTION_IMPORT Direction = "import"
+ POLICY_DIRECTION_EXPORT = "export"
+ POLICY_DIRECTION_DISTRIBUTE = "distribute"
+)
+
type SenderMsg struct {
messages []*bgp.BGPMessage
sendCh chan *bgp.BGPMessage
@@ -200,6 +208,8 @@ func (server *BgpServer) Serve() {
loc := NewLocalRib(name, peer.configuredRFlist(), make(map[string]*policy.Policy))
server.addLocalRib(loc)
loc.setPolicy(peer, server.policyMap)
+ // set distribute policy
+ peer.setPolicy(server.policyMap)
pathList := make([]*table.Path, 0)
for _, p := range server.neighborMap {
@@ -210,7 +220,7 @@ func (server *BgpServer) Serve() {
pathList = append(pathList, p.adjRib.GetInPathList(rf)...)
}
}
- pathList = applyPolicies(peer, loc, false, pathList)
+ pathList = applyPolicies(peer, loc, POLICY_DIRECTION_IMPORT, pathList)
if len(pathList) > 0 {
loc.rib.ProcessPaths(pathList)
}
@@ -370,19 +380,32 @@ func (server *BgpServer) dropPeerAllRoutes(peer *Peer) []*SenderMsg {
return msgs
}
-func applyPolicies(peer *Peer, loc *LocalRib, isExport bool, pathList []*table.Path) []*table.Path {
+func applyPolicies(peer *Peer, loc *LocalRib, d Direction, pathList []*table.Path) []*table.Path {
var defaultPolicy config.DefaultPolicyType
- if isExport == true {
+ switch d {
+ case POLICY_DIRECTION_EXPORT:
defaultPolicy = loc.defaultExportPolicy
- } else {
+ case POLICY_DIRECTION_IMPORT:
defaultPolicy = loc.defaultImportPolicy
+ case POLICY_DIRECTION_DISTRIBUTE:
+ defaultPolicy = peer.defaultDistributePolicy
+ default:
+ log.WithFields(log.Fields{
+ "Topic": "Server",
+ "Key": peer.config.NeighborAddress,
+ }).Error("direction is not specified.")
}
ret := make([]*table.Path, 0, len(pathList))
for _, path := range pathList {
if !path.IsWithdraw {
var applied bool = false
- applied, path = loc.applyPolicies(isExport, path)
+ if d == POLICY_DIRECTION_DISTRIBUTE {
+ applied, path = peer.applyPolicies(path)
+ } else {
+ applied, path = loc.applyPolicies(d, path)
+ }
+
if applied {
if path == nil {
log.WithFields(log.Fields{
@@ -462,11 +485,11 @@ func (server *BgpServer) propagateUpdate(neighborAddress string, RouteServerClie
if loc.isGlobal() || loc.OwnerName() == neighborAddress {
continue
}
- sendPathList, _ := loc.rib.ProcessPaths(applyPolicies(targetPeer, loc, false, dropSameAsPath(targetPeer.config.PeerAs, filterpath(targetPeer, pathList))))
+ sendPathList, _ := loc.rib.ProcessPaths(applyPolicies(targetPeer, loc, POLICY_DIRECTION_IMPORT, dropSameAsPath(targetPeer.config.PeerAs, filterpath(targetPeer, pathList))))
if targetPeer.fsm.state != bgp.BGP_FSM_ESTABLISHED || len(sendPathList) == 0 {
continue
}
- sendPathList = applyPolicies(targetPeer, loc, true, sendPathList)
+ sendPathList = applyPolicies(targetPeer, loc, POLICY_DIRECTION_EXPORT, sendPathList)
if len(sendPathList) == 0 {
continue
}
@@ -534,7 +557,7 @@ func (server *BgpServer) handleFSMMessage(peer *Peer, e *fsmMsg, incoming chan *
pathList := make([]*table.Path, 0)
if peer.isRouteServerClient() {
loc := server.localRibMap[peer.config.NeighborAddress.String()]
- pathList = applyPolicies(peer, loc, true, peer.getBests(loc))
+ pathList = applyPolicies(peer, loc, POLICY_DIRECTION_EXPORT, peer.getBests(loc))
} else {
peer.config.LocalAddress = peer.fsm.LocalAddr()
for _, path := range peer.getBests(globalRib) {
@@ -621,6 +644,8 @@ func (server *BgpServer) handlePolicy(pl config.RoutingPolicy) {
}
targetPeer := server.neighborMap[loc.OwnerName()]
loc.setPolicy(targetPeer, server.policyMap)
+ // set distribute policy
+ targetPeer.setPolicy(server.policyMap)
}
}