Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introspect support for routing policy
Enhanced UT cases to invoke routing-policy introspect Change-Id: I6809c0cfe7ab3a093afd40e97ab1c364bbd025fe Related-bug: #1500698
- Loading branch information
Showing
11 changed files
with
591 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) 2016 Juniper Networks, Inc. All rights reserved. | ||
*/ | ||
|
||
include "bgp/bgp_peer.sandesh" | ||
include "bgp/routing-policy/routing_policy_internal.sandesh" | ||
|
||
struct PolicyTermInfo { | ||
1: bool terminal; | ||
2: list<string> matches; | ||
3: list<string> actions; | ||
} | ||
|
||
struct ShowRoutingPolicyInfo { | ||
1: string name; | ||
2: u32 generation; | ||
3: u32 ref_count; | ||
4: list<PolicyTermInfo> terms; | ||
5: bool deleted; | ||
} | ||
|
||
response sandesh ShowRoutingPolicyResp { | ||
1: list<ShowRoutingPolicyInfo> routing_policies; | ||
2: optional string next_batch (link="ShowRoutingPolicyReqIterate", | ||
link_title="next_batch"); | ||
} | ||
|
||
request sandesh ShowRoutingPolicyReq { | ||
1: string search_string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
* Copyright (c) 2016 Juniper Networks, Inc. All rights reserved. | ||
*/ | ||
request sandesh ShowRoutingPolicyReqIterate { | ||
1: string iterate_info; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/* | ||
* Copyright (c) 2016 Juniper Networks, Inc. All rights reserved. | ||
*/ | ||
|
||
#include "bgp/bgp_show_handler.h" | ||
|
||
#include <boost/foreach.hpp> | ||
|
||
#include "bgp/bgp_server.h" | ||
#include "bgp/bgp_show_handler.h" | ||
#include "bgp/routing-policy/routing_policy.h" | ||
#include "bgp/routing-policy/routing_policy_action.h" | ||
#include "bgp/routing-policy/routing_policy_match.h" | ||
#include "bgp/routing-policy/routing_policy_types.h" | ||
|
||
using std::string; | ||
using std::vector; | ||
|
||
// | ||
// Fill in information for a policy. | ||
// | ||
static void FillRoutingPolicyInfo(ShowRoutingPolicyInfo *srpi, | ||
const BgpSandeshContext *bsc, const RoutingPolicy *policy, | ||
bool summary) { | ||
srpi->set_name(policy->name()); | ||
srpi->set_generation(policy->generation()); | ||
srpi->set_ref_count(policy->refcount()); | ||
srpi->set_deleted(policy->deleted()); | ||
vector<PolicyTermInfo> term_list; | ||
BOOST_FOREACH(RoutingPolicy::PolicyTermPtr term, policy->terms()) { | ||
PolicyTermInfo show_term; | ||
show_term.set_terminal(term->terminal()); | ||
vector<string> match_list; | ||
BOOST_FOREACH(RoutingPolicyMatch *match, term->matches()) { | ||
match_list.push_back(match->ToString()); | ||
} | ||
show_term.set_matches(match_list); | ||
vector<string> action_list; | ||
BOOST_FOREACH(RoutingPolicyAction *action, term->actions()) { | ||
action_list.push_back(action->ToString()); | ||
} | ||
show_term.set_actions(action_list); | ||
term_list.push_back(show_term); | ||
} | ||
srpi->set_terms(term_list); | ||
} | ||
|
||
// | ||
// Fill in information for list of policies. | ||
// | ||
static bool FillRoutingPolicyInfoList(const BgpSandeshContext *bsc, | ||
bool summary, uint32_t page_limit, uint32_t iter_limit, | ||
const string &start_policy, const string &search_string, | ||
vector<ShowRoutingPolicyInfo> *srpi_list, string *next_policy) { | ||
RoutingPolicyMgr *rpm = bsc->bgp_server->routing_policy_mgr(); | ||
RoutingPolicyMgr::const_name_iterator it = | ||
rpm->name_clower_bound(start_policy); | ||
for (uint32_t iter_count = 0; it != rpm->name_cend(); ++it, ++iter_count) { | ||
const RoutingPolicy *policy = it->second; | ||
if (!search_string.empty() && | ||
(policy->name().find(search_string) == string::npos) && | ||
(search_string != "deleted" || !policy->deleted())) { | ||
continue; | ||
} | ||
ShowRoutingPolicyInfo srpi; | ||
FillRoutingPolicyInfo(&srpi, bsc, policy, summary); | ||
srpi_list->push_back(srpi); | ||
if (srpi_list->size() >= page_limit) | ||
break; | ||
if (iter_count >= iter_limit) | ||
break; | ||
} | ||
|
||
// All done if we've looked at all policies. | ||
if (it == rpm->name_cend() || ++it == rpm->name_end()) | ||
return true; | ||
|
||
// Return true if we've reached the page limit, false if we've reached the | ||
// iteration limit. | ||
bool done = srpi_list->size() >= page_limit; | ||
*next_policy = it->second->name(); | ||
return done; | ||
} | ||
|
||
// Specialization of BgpShowHandler<>::CallbackCommon. | ||
template <> | ||
bool BgpShowHandler<ShowRoutingPolicyReq, ShowRoutingPolicyReqIterate, | ||
ShowRoutingPolicyResp, ShowRoutingPolicyInfo>::CallbackCommon( | ||
const BgpSandeshContext *bsc, Data *data) { | ||
uint32_t page_limit = bsc->page_limit() ? bsc->page_limit() : kPageLimit; | ||
uint32_t iter_limit = bsc->iter_limit() ? bsc->iter_limit() : kIterLimit; | ||
string next_policy; | ||
bool done = FillRoutingPolicyInfoList(bsc, false, page_limit, iter_limit, | ||
data->next_entry, data->search_string, &data->show_list, | ||
&next_policy); | ||
if (!next_policy.empty()) | ||
SaveContextToData(next_policy, done, data); | ||
return done; | ||
} | ||
|
||
// Specialization of BgpShowHandler<>::FillShowList. | ||
template <> | ||
void BgpShowHandler<ShowRoutingPolicyReq, ShowRoutingPolicyReqIterate, | ||
ShowRoutingPolicyResp, ShowRoutingPolicyInfo>::FillShowList( | ||
ShowRoutingPolicyResp *resp, | ||
const vector<ShowRoutingPolicyInfo> &show_list) { | ||
resp->set_routing_policies(show_list); | ||
} | ||
|
||
// Handler for ShowRoutingPolicyReq. | ||
void ShowRoutingPolicyReq::HandleRequest() const { | ||
RequestPipeline::PipeSpec ps(this); | ||
RequestPipeline::StageSpec s1; | ||
TaskScheduler *scheduler = TaskScheduler::GetInstance(); | ||
|
||
s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand"); | ||
s1.cbFn_ = boost::bind(&BgpShowHandler< | ||
ShowRoutingPolicyReq, | ||
ShowRoutingPolicyReqIterate, | ||
ShowRoutingPolicyResp, | ||
ShowRoutingPolicyInfo>::Callback, _1, _2, _3, _4, _5); | ||
s1.allocFn_ = BgpShowHandler< | ||
ShowRoutingPolicyReq, | ||
ShowRoutingPolicyReqIterate, | ||
ShowRoutingPolicyResp, | ||
ShowRoutingPolicyInfo>::CreateData; | ||
s1.instances_.push_back(0); | ||
ps.stages_.push_back(s1); | ||
RequestPipeline rp(ps); | ||
} | ||
|
||
// | ||
// Handler for ShowRoutingPolicyReqIterate. | ||
// | ||
void ShowRoutingPolicyReqIterate::HandleRequest() const { | ||
RequestPipeline::PipeSpec ps(this); | ||
RequestPipeline::StageSpec s1; | ||
TaskScheduler *scheduler = TaskScheduler::GetInstance(); | ||
|
||
s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand"); | ||
s1.cbFn_ = boost::bind(&BgpShowHandler< | ||
ShowRoutingPolicyReq, | ||
ShowRoutingPolicyReqIterate, | ||
ShowRoutingPolicyResp, | ||
ShowRoutingPolicyInfo>::CallbackIterate, _1, _2, _3, _4, _5); | ||
s1.allocFn_ = BgpShowHandler< | ||
ShowRoutingPolicyReq, | ||
ShowRoutingPolicyReqIterate, | ||
ShowRoutingPolicyResp, | ||
ShowRoutingPolicyInfo>::CreateData; | ||
s1.instances_.push_back(0); | ||
ps.stages_.push_back(s1); | ||
RequestPipeline rp(ps); | ||
} |
Oops, something went wrong.