diff options
author | Naoto Hanaue <hanaue.naoto@po.ntts.co.jp> | 2015-05-12 19:50:57 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-05-19 16:33:16 +0900 |
commit | 0349e0d69926a6cb16467fcd88edf69cbd0f524e (patch) | |
tree | e9e1ce9e4ee9313e7494d9cfb02b7806f83dd77b /server/peer.go | |
parent | 77eaf6a051f7272a3217ab199f53aa3fc9d546a6 (diff) |
cli: add the show command for routing policy of neighbor
% gobgp -u 10.0.255.1 neighbor 10.0.0.3 policy
DefaultImportPolicy: ACCEPT
DefaultImportPolicy: ACCEPT
ImportPolicies:
PolicyName policy0:
StatementName st0:
Conditions:
PrefixSet: ps0 192.168.0.0/16 16..24
NeighborSet: ns0 10.0.0.2
MatchOption: ALL
Actions:
REJECT
PolicyName policy5:
ExportPolicies:
PolicyName policy1:
StatementName st1:
Conditions:
PrefixSet: ps1 192.168.20.0/24
192.168.200.0/24
NeighborSet: ns0 10.0.0.2
MatchOption: ALL
Actions:
REJECT
Diffstat (limited to 'server/peer.go')
-rw-r--r-- | server/peer.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/server/peer.go b/server/peer.go index 2a4e71a0..a89fb303 100644 --- a/server/peer.go +++ b/server/peer.go @@ -587,6 +587,47 @@ func (peer *Peer) handleGrpc(grpcReq *GrpcRequest) { } } result.Data = err + case REQ_NEIGHBOR_POLICY: + result := &GrpcResponse{} + resInPolicies := []*api.PolicyDefinition{} + resOutPolicies := []*api.PolicyDefinition{} + + // Add importpolies that has been set in the configuration file to the list. + // However, peer haven't target importpolicy when add PolicyDefinition of name only to the list. + conInPolicyNames := peer.peerConfig.ApplyPolicy.ImportPolicies + for _, conInPolicyName := range conInPolicyNames { + for _, inPolicy := range peer.importPolicies { + if conInPolicyName == inPolicy.Name { + resInPolicies = append(resInPolicies, inPolicy.ToApiStruct()) + } else { + resInPolicies = append(resInPolicies, &api.PolicyDefinition{PolicyDefinitionName: conInPolicyName}) + } + + } + } + // Add importpolies that has been set in the configuration file to the list. + // However, peer haven't target importpolicy when add PolicyDefinition of name only to the list. + conOutPolicyNames := peer.peerConfig.ApplyPolicy.ExportPolicies + for _, conOutPolicyName := range conOutPolicyNames { + for _, outPolicy := range peer.exportPolicies { + if conOutPolicyName == outPolicy.Name { + resOutPolicies = append(resOutPolicies, outPolicy.ToApiStruct()) + } else { + resOutPolicies = append(resOutPolicies, &api.PolicyDefinition{PolicyDefinitionName: conOutPolicyName}) + } + + } + } + result.Data = &api.ApplyPolicy{ + DefaultImportPolicy: int64(peer.defaultImportPolicy), + ImportPolicies: resInPolicies, + DefaultExportPolicy: int64(peer.defaultExportPolicy), + ExportPolicies: resOutPolicies, + } + grpcReq.ResponseCh <- result + + close(grpcReq.ResponseCh) + return } grpcReq.ResponseCh <- result close(grpcReq.ResponseCh) |