Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #include "bgp/bgp_show_handler.h" 6 : 7 : #include "base/regex.h" 8 : #include "bgp/bgp_peer_internal_types.h" 9 : #include "bgp/bgp_multicast.h" 10 : #include "bgp/bgp_server.h" 11 : #include "bgp/ermvpn/ermvpn_table.h" 12 : #include "bgp/routing-instance/routing_instance.h" 13 : 14 : using contrail::regex; 15 : using contrail::regex_match; 16 : using contrail::regex_search; 17 : using std::string; 18 : using std::vector; 19 : 20 : // 21 : // Fill in information for an ermvpn table. 22 : // 23 0 : static void FillMulticastManagerInfo(ShowMulticastManager *smm, 24 : const BgpSandeshContext *bsc, const ErmVpnTable *table) { 25 0 : smm->set_name(table->name()); 26 0 : const McastTreeManager *manager = table->GetTreeManager(); 27 0 : if (!manager) 28 0 : return; 29 : 30 0 : smm->set_deleted(manager->deleted()); 31 0 : smm->set_deleted_at( 32 0 : UTCUsecToString(manager->deleter()->delete_time_stamp_usecs())); 33 : 34 0 : uint32_t total_trees = 0; 35 0 : for (McastTreeManager::const_iterator it = manager->begin(); 36 0 : it != manager->end(); ++it) { 37 0 : const McastManagerPartition *partition = *it; 38 0 : total_trees += partition->size(); 39 : } 40 0 : smm->set_total_trees(total_trees); 41 : } 42 : 43 : // 44 : // Specialization of BgpShowHandler<>::CallbackCommon. 45 : // 46 : template <> 47 0 : bool BgpShowHandler<ShowMulticastManagerReq, ShowMulticastManagerReqIterate, 48 : ShowMulticastManagerResp, ShowMulticastManager>::CallbackCommon( 49 : const BgpSandeshContext *bsc, Data *data) { 50 0 : uint32_t page_limit = bsc->page_limit() ? bsc->page_limit() : kPageLimit; 51 0 : uint32_t iter_limit = bsc->iter_limit() ? bsc->iter_limit() : kIterLimit; 52 0 : RoutingInstanceMgr *rim = bsc->bgp_server->routing_instance_mgr(); 53 : 54 0 : regex search_expr(data->search_string); 55 : RoutingInstanceMgr::const_name_iterator it = 56 0 : rim->name_clower_bound(data->next_entry); 57 0 : for (uint32_t iter_count = 0; it != rim->name_cend(); ++it, ++iter_count) { 58 0 : const RoutingInstance *rtinstance = it->second; 59 : const ErmVpnTable *table = static_cast<const ErmVpnTable *>( 60 0 : rtinstance->GetTable(Address::ERMVPN)); 61 0 : if (!table) 62 0 : continue; 63 0 : if ((!regex_search(table->name(), search_expr)) && 64 0 : (data->search_string != "deleted" || !table->IsDeleted())) { 65 0 : continue; 66 : } 67 0 : ShowMulticastManager smm; 68 0 : FillMulticastManagerInfo(&smm, bsc, table); 69 0 : data->show_list.push_back(smm); 70 0 : if (data->show_list.size() >= page_limit) 71 0 : break; 72 0 : if (iter_count >= iter_limit) 73 0 : break; 74 0 : } 75 : 76 : // All done if we've looked at all instances. 77 0 : if (it == rim->name_cend() || ++it == rim->name_cend()) 78 0 : return true; 79 : 80 : // Return true if we've reached the page limit, false if we've reached the 81 : // iteration limit. 82 0 : bool done = data->show_list.size() >= page_limit; 83 0 : SaveContextToData(it->second->name(), done, data); 84 0 : return done; 85 0 : } 86 : 87 : // 88 : // Specialization of BgpShowHandler<>::FillShowList. 89 : // 90 : template <> 91 0 : void BgpShowHandler<ShowMulticastManagerReq, ShowMulticastManagerReqIterate, 92 : ShowMulticastManagerResp, ShowMulticastManager>::FillShowList( 93 : ShowMulticastManagerResp *resp, 94 : const vector<ShowMulticastManager> &show_list) { 95 0 : resp->set_managers(show_list); 96 0 : } 97 : 98 : // 99 : // Handler for ShowMulticastManagerReq. 100 : // 101 0 : void ShowMulticastManagerReq::HandleRequest() const { 102 0 : RequestPipeline::PipeSpec ps(this); 103 0 : RequestPipeline::StageSpec s1; 104 0 : TaskScheduler *scheduler = TaskScheduler::GetInstance(); 105 : 106 0 : s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand"); 107 : s1.cbFn_ = boost::bind(&BgpShowHandler< 108 : ShowMulticastManagerReq, 109 : ShowMulticastManagerReqIterate, 110 : ShowMulticastManagerResp, 111 0 : ShowMulticastManager>::Callback, _1, _2, _3, _4, _5); 112 : s1.allocFn_ = BgpShowHandler< 113 : ShowMulticastManagerReq, 114 : ShowMulticastManagerReqIterate, 115 : ShowMulticastManagerResp, 116 0 : ShowMulticastManager>::CreateData; 117 0 : s1.instances_.push_back(0); 118 0 : ps.stages_.push_back(s1); 119 0 : RequestPipeline rp(ps); 120 0 : } 121 : 122 : // 123 : // Handler for ShowMulticastManagerReqIterate. 124 : // 125 0 : void ShowMulticastManagerReqIterate::HandleRequest() const { 126 0 : RequestPipeline::PipeSpec ps(this); 127 0 : RequestPipeline::StageSpec s1; 128 0 : TaskScheduler *scheduler = TaskScheduler::GetInstance(); 129 : 130 0 : s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand"); 131 : s1.cbFn_ = boost::bind(&BgpShowHandler< 132 : ShowMulticastManagerReq, 133 : ShowMulticastManagerReqIterate, 134 : ShowMulticastManagerResp, 135 0 : ShowMulticastManager>::CallbackIterate, _1, _2, _3, _4, _5); 136 : s1.allocFn_ = BgpShowHandler< 137 : ShowMulticastManagerReq, 138 : ShowMulticastManagerReqIterate, 139 : ShowMulticastManagerResp, 140 0 : ShowMulticastManager>::CreateData; 141 0 : s1.instances_.push_back(0); 142 0 : ps.stages_.push_back(s1); 143 0 : RequestPipeline rp(ps); 144 0 : }