10 #include <boost/foreach.hpp>
23 #include "bgp/routing-instance/routing_instance_analytics_types.h"
29 using std::ostringstream;
36 sg_(sg), global_ermvpn_tree_rt_(NULL), spmsi_rt_(NULL),
37 source_active_rt_(NULL), states_(states), project_manager_(pm) {
59 lifetime_manager()),
manager_(manager) {
85 listener_id_(
DBTable::kInvalidId),
86 table_delete_ref_(this, table->
deleter()) {
97 if (!partition->
states().empty()) {
99 "MvpnProjectManager::MayDelete() paused due to pending " +
125 "MvpnProjectManager");
126 MVPN_LOG(MvpnProjectManagerCreate,
"Initialized MvpnProjectManager");
134 MVPN_LOG(MvpnProjectManagerDelete,
"Terminated MvpnProjectManager");
143 for (
size_t part_id = 0; part_id <
partitions_.size(); part_id++) {
182 : manager_(manager), part_id_(part_id) {
191 assert(
states_.insert(make_pair(sg, state.get())).second);
206 MvpnState::StatesMap::const_iterator iter =
states_.find(sg);
207 return iter !=
states_.end() ? iter->second : NULL;
211 MvpnState::StatesMap::iterator iter =
states_.find(sg);
212 return iter !=
states_.end() ? iter->second : NULL;
220 rd_(rd), originator_(originator), source_as_(0) {
243 NeighborMap::const_iterator iter =
neighbors_.find(rd);
267 source(route->GetPrefix().source()),
268 group(route->GetPrefix().group()) {
272 source(route->GetPrefix().source()), group(route->GetPrefix().group()) {
276 source(source), group(group) {
280 if (source < other.
source)
282 if (source > other.
source)
284 if (group < other.
group)
286 if (group > other.
group)
374 lifetime_manager()),
manager_(manager) {
400 ermvpn_table_(ermvpn_table),
401 listener_id_(
DBTable::kInvalidId),
402 identifier_listener_id_(-1),
403 table_delete_ref_(this, table->
deleter()),
404 ermvpn_table_delete_ref_(this, ermvpn_table->
deleter()) {
452 MVPN_LOG(MvpnManagerDelete,
"Terminated MvpnManager");
465 for (
size_t part_id = 0; part_id <
partitions_.size(); part_id++) {
476 "MvpnManager::MayDelete() paused due to pending " +
508 : manager_(manager), part_id_(part_id) {
541 assert(project_manager_partition);
550 if (!project_manager_partition)
554 return project_manager_partition->
GetState(sg);
579 if (
table()->tree_manager())
591 uint32_t *label,
Ip4Address *address, vector<string> *enc)
const {
592 if (!
table()->tree_manager())
598 Ip4Address *address, vector<string> *encap)
const {
623 MVPN_LOG(MvpnManagerCreate,
"Initialized MvpnManager");
649 attr_spec.push_back(&nexthop);
732 if (found && old_neighbor == neighbor)
746 if (!ermvpn_route || !ermvpn_route->
IsUsable())
748 if (!
table()->tree_manager())
752 return (global_rt && global_rt == ermvpn_route);
769 assert(ermvpn_route);
784 mvpn_state->set_global_ermvpn_tree_rt(NULL);
789 BOOST_FOREACH(
MvpnRoute *route, mvpn_state->spmsi_routes_received()) {
794 "Processed MVPN GlobalErmVpnRoute deletion");
807 mvpn_state = mvpn_dbstate->
state();
811 mvpn_dbstate->
state()->set_global_ermvpn_tree_rt(ermvpn_route);
814 BOOST_FOREACH(
MvpnRoute *route, mvpn_state->spmsi_routes_received()) {
819 "Processed MVPN GlobalErmVpnRoute creation");
835 mvpn_dbstate->
state() ? mvpn_dbstate->
state()->spmsi_rt() : NULL;
836 if (spmsi_rt && spmsi_rt->
IsUsable()) {
843 mvpn_dbstate->
state()->set_source_active_rt(NULL);
844 mvpn_dbstate->
state()->set_spmsi_rt(NULL);
848 MVPN_RT_LOG(rt,
"Processed MVPN Source Active route deletion");
859 state->set_source_active_rt(rt);
872 if (!join_rt || !join_rt->
IsUsable() ||
877 assert(!state->spmsi_rt() || spmsi_rt == state->spmsi_rt());
878 state->set_spmsi_rt(NULL);
882 MVPN_RT_LOG(spmsi_rt,
"Deleted already originated SPMSI path");
893 state->set_spmsi_rt(spmsi_rt);
894 if (!mvpn_dbstate->
route()) {
897 assert(spmsi_rt == mvpn_dbstate->
route());
918 MVPN_RT_LOG(rt,
"Processed MVPN Source Active route creation");
934 if (mvpn_dbstate->
state()->source_active_rt())
935 mvpn_dbstate->
state()->source_active_rt()->Notify();
937 MVPN_RT_LOG(join_rt,
"Processed Type 7 Join route deletion");
954 if (state->source_active_rt()) {
955 state->source_active_rt()->Notify();
956 MVPN_RT_LOG(join_rt,
"Processed Type 7 Join route creation and "
957 "notified Source Active route");
959 MVPN_RT_LOG(join_rt,
"Processed Type 7 Join route creation");
971 assert(mvpn_dbstate->
state()->leafad_routes_attr_received().
973 MvpnRoute *sa_active_rt = mvpn_dbstate->
state()->source_active_rt();
977 if (sa_active_rt && sa_active_rt->
IsUsable()) {
979 MVPN_RT_LOG(leaf_ad,
"Processed Type 4 LeafAD route deletion"
980 " and notified type5 source active route");
982 MVPN_RT_LOG(leaf_ad,
"Processed Type 4 LeafAD route deletion");
1000 pair<MvpnState::RoutesMap::iterator, bool> result =
1001 state->leafad_routes_attr_received().insert(make_pair(leaf_ad,
1005 if (!result.second) {
1013 MvpnRoute *sa_active_rt = mvpn_dbstate->
state()->source_active_rt();
1014 if (sa_active_rt && sa_active_rt->
IsUsable()) {
1016 MVPN_RT_LOG(sa_active_rt,
"Processed Type 4 Leaf AD route creation"
1017 " and Type-5 source active route was notified");
1019 MVPN_RT_LOG(sa_active_rt,
"Processed Type 4 Leaf AD route creation");
1037 assert(mvpn_dbstate->
state() == mvpn_state);
1041 leaf_ad_route = mvpn_dbstate->
route();
1042 if (leaf_ad_route) {
1049 assert(mvpn_state->spmsi_routes_received().erase(spmsi_rt));
1051 delete mvpn_dbstate;
1052 if (leaf_ad_route) {
1059 MVPN_RT_LOG(spmsi_rt,
"Processed Type 3 S-PMSI route deletion"
1060 " and notified local ForestNode");
1062 MVPN_RT_LOG(spmsi_rt,
"Processed Type 3 S-PMSI route deletion");
1073 if (!join_rt || !join_rt->
IsUsable())
1082 if (!mvpn_dbstate) {
1085 assert(mvpn_state->spmsi_routes_received().insert(spmsi_rt).second);
1087 leaf_ad_route = mvpn_dbstate->
route();
1094 MVPN_RT_LOG(spmsi_rt,
"No need to process Type 3 S-PMSI route as"
1095 " LeafInfoRequired bit is not set");
1099 ErmVpnRoute *global_rt = mvpn_state->global_ermvpn_tree_rt();
1102 vector<string> tunnel_encaps;
1110 if (leaf_ad_route) {
1118 MVPN_RT_LOG(spmsi_rt,
"Processed Type 3 S-PMSI route as deletion"
1119 " and notified local ForestNode due to missing PMSI");
1124 if (!leaf_ad_route) {
1136 ReplaceRTargetAndLocate(attrp->ext_community(), rtarget);
1139 BOOST_FOREACH(
string encap, tunnel_encaps) {
1140 tunnel_encaps_list.push_back(
TunnelEncap(encap).GetExtCommunity());
1144 ReplaceTunnelEncapsulationAndLocate(ext_community.get(),
1145 tunnel_encaps_list);
1148 attrp.get(), ext_community);
1154 pmsi_spec.
SetLabel(label, ext_community.get());
1166 if (old_path && old_path->
GetAttr() == new_attrp.get())
1176 MVPN_RT_LOG(spmsi_rt,
"Processed Type 3 S-PMSI route creation");
1191 if (!state || !state->spmsi_rt() || !state->spmsi_rt()->IsUsable())
1196 state->spmsi_rt()->get_table_partition()->parent());
1203 secondary_tables->insert(
table);
1204 MVPN_RT_LOG(mvpn_rt,
"Updated tables for replication with table " +
1222 if (!state->global_ermvpn_tree_rt() ||
1223 !state->global_ermvpn_tree_rt()->IsUsable()) {
1228 if (state->spmsi_routes_received().empty())
1232 *addrp = (*(state->spmsi_routes_received().begin()))->
1233 GetPrefix().originator();
1235 addrp->to_string());
1255 if (!state || state->leafad_routes_attr_received().empty())
1260 BOOST_FOREACH(MvpnState::RoutesMap::value_type &iter,
1261 state->leafad_routes_attr_received()) {
1269 uint32_t label = attr->pmsi_tunnel()->GetLabel(extcomm);
1274 olist_spec.
elements.push_back(elem);
boost::asio::ip::address IpAddress
boost::asio::ip::address_v4 Ip4Address
std::vector< BgpAttribute * > BgpAttrSpec
boost::intrusive_ptr< const BgpAttr > BgpAttrPtr
#define MVPN_TRACE(type,...)
#define MVPN_ERMVPN_RT_LOG(rt,...)
#define MVPN_LOG(type,...)
#define MVPN_RT_LOG(rt,...)
boost::intrusive_ptr< MvpnState > MvpnStatePtr
BgpAttrPtr ReplaceOListAndLocate(const BgpAttr *attr, const BgpOListSpec *olist_spec)
BgpAttrPtr ReplacePmsiTunnelAndLocate(const BgpAttr *attr, const PmsiTunnelSpec *pmsi_spec)
BgpAttrPtr ReplaceExtCommunityAndLocate(const BgpAttr *attr, ExtCommunityPtr extcomm)
const PmsiTunnel * pmsi_tunnel() const
TypePtr Locate(Type *attr)
virtual bool IsReplicated() const
const BgpAttr * GetAttr() const
const BgpPath * FindPath(BgpPath::PathSource src) const
const BgpPath * BestPath() const
void DeletePath(BgpPath *path)
void InsertPath(BgpPath *path)
ExtCommunityDB * extcomm_db()
int RegisterIdentifierUpdateCallback(IdentifierUpdateCb callback)
uint32_t bgp_identifier() const
bool mvpn_ipv4_enable() const
void UnregisterIdentifierUpdateCallback(int listener)
std::set< BgpTable * > TableSet
DBState * GetState(DBTableBase *tbl_base, ListenerId listener) const
void ClearState(DBTableBase *tbl_base, ListenerId listener)
DBTablePartBase * get_table_partition() const
void SetState(DBTableBase *tbl_base, ListenerId listener, DBState *state)
ListenerId Register(ChangeCallback callback, const std::string &name="unspecified")
static const int kInvalidId
void Unregister(ListenerId listener)
const std::string & name() const
Ip4Address source() const
const ErmVpnPrefix & GetPrefix() const
const McastTreeManager * tree_manager() const
void DestroyMvpnProjectManager()
virtual int PartitionCount() const
void NotifyForestNode(int part_id, const Ip4Address &source, const Ip4Address &group)
virtual bool GetForestNodePMSI(ErmVpnRoute *rt, uint32_t *label, Ip4Address *address, std::vector< std::string > *encap) const
virtual ErmVpnRoute * GetGlobalTreeRootRoute(const Ip4Address &source, const Ip4Address &group) const
bool GetForestNodePMSI(ErmVpnRoute *rt, uint32_t *label, Ip4Address *address, std::vector< std::string > *encap) const
void ProcessType7SourceTreeJoinRoute(MvpnRoute *join_rt)
void ProcessType4LeafADRoute(MvpnRoute *leaf_ad)
MvpnManagerPartition(MvpnManager *manager, int part_id)
MvpnStatePtr GetState(MvpnRoute *route)
void ProcessType3SPMSIRoute(MvpnRoute *spmsi_rt)
MvpnStatePtr LocateState(MvpnRoute *route)
virtual ~MvpnManagerPartition()
void NotifyForestNode(const Ip4Address &source, const Ip4Address &group)
void ProcessType5SourceActiveRoute(MvpnRoute *join_rt)
MvpnProjectManagerPartition * GetProjectManagerPartition()
virtual bool MayDelete() const
DeleteActor(MvpnManager *manager)
boost::scoped_ptr< DeleteActor > deleter_
void SetDBState(MvpnRoute *route, MvpnDBState *mvpn_dbstate)
virtual void Initialize()
void RouteListener(DBTablePartBase *tpart, DBEntryBase *db_entry)
MvpnProjectManager * GetProjectManager()
void ReOriginateType1Route(const Ip4Address &old_identifier)
void ProcessType1ADRoute(MvpnRoute *route)
MvpnManager(MvpnTable *table, ErmVpnTable *ermvpn_table)
PartitionList partitions_
std::map< RouteDistinguisher, MvpnNeighbor > NeighborMap
void ClearDBState(MvpnRoute *route)
std::atomic< int > db_states_count_
std::shared_mutex neighbors_mutex_
const NeighborMap & neighbors() const
void OriginateType1Route()
bool FindNeighbor(const RouteDistinguisher &rd, MvpnNeighbor *nbr) const
const LifetimeActor * deleter() const
int identifier_listener_id_
size_t neighbors_count() const
virtual void UpdateSecondaryTablesForReplication(MvpnRoute *rt, BgpTable::TableSet *secondary_tables) const
Ip4Address source() const
IpAddress sourceIpAddress() const
Ip4Address originator() const
const RouteDistinguisher & route_distinguisher() const
IpAddress groupIpAddress() const
MvpnProjectManagerPartition(MvpnProjectManager *manager, int part_id)
void RouteListener(DBEntryBase *db_entry)
MvpnState::StatesMap states_
MvpnStatePtr GetState(const SG &sg)
bool GetForestNodePMSI(ErmVpnRoute *rt, uint32_t *label, Ip4Address *address, std::vector< std::string > *encap) const
const MvpnState::StatesMap & states() const
virtual ~MvpnProjectManagerPartition()
MvpnStatePtr CreateState(const SG &sg)
bool IsUsableGlobalTreeRootRoute(ErmVpnRoute *ermvpn_route) const
void NotifyForestNode(const Ip4Address &source, const Ip4Address &group)
MvpnStatePtr LocateState(const SG &sg)
MvpnProjectManager * manager_
DeleteActor(MvpnProjectManager *manager)
virtual bool MayDelete() const
MvpnProjectManager * manager_
const LifetimeActor * deleter() const
MvpnProjectManagerPartition * GetPartition(int part_id)
boost::scoped_ptr< DeleteActor > deleter_
UpdateInfo * GetUpdateInfo(MvpnRoute *route)
MvpnStatePtr GetState(MvpnRoute *route) const
PartitionList partitions_
void GetMvpnSourceAddress(ErmVpnRoute *ermvpn_route, Ip4Address *address) const
MvpnProjectManager(ErmVpnTable *table)
UpdateInfo * GetType7UpdateInfo(MvpnRoute *route)
void RouteListener(DBTablePartBase *tpart, DBEntryBase *db_entry)
virtual void Initialize()
virtual ~MvpnProjectManager()
const MvpnPrefix & GetPrefix() const
RoutesSet spmsi_routes_received_
RoutesMap & leafad_routes_attr_received()
std::set< MvpnRoute * > RoutesSet
const ErmVpnTable * table() const
MvpnState(const SG &sg, StatesMap *states, MvpnProjectManager *pm)
ErmVpnRoute * global_ermvpn_tree_rt()
void set_source_active_rt(MvpnRoute *source_active_rt)
std::atomic< int > refcount_
std::map< MvpnRoute *, BgpAttrPtr > RoutesMap
ErmVpnRoute * global_ermvpn_tree_rt_
std::map< SG, MvpnState * > StatesMap
MvpnRoute * source_active_rt_
RoutesSet & spmsi_routes_received()
RoutesMap leafad_routes_attr_received_
MvpnRoute * source_active_rt()
void set_spmsi_rt(MvpnRoute *spmsi_rt)
MvpnProjectManager * project_manager_
void set_global_ermvpn_tree_rt(ErmVpnRoute *global_ermvpn_tree_rt)
bool IsProjectManagerUsable() const
const MvpnProjectManager * GetProjectManager() const
MvpnRoute * LocateType4LeafADRoute(const MvpnRoute *type3_spmsi_rt)
MvpnRoute * LocateType3SPMSIRoute(const MvpnRoute *type7_join_rt)
MvpnRoute * LocateType1ADRoute()
virtual int PartitionCount() const
const MvpnRoute * FindType7SourceTreeJoinRoute(MvpnRoute *rt) const
const MvpnProjectManagerPartition * GetProjectManagerPartition(BgpRoute *route) const
MvpnRoute * FindType1ADRoute(const Ip4Address &originator_ip)
const uint8_t tunnel_flags() const
const PmsiTunnelSpec & pmsi_tunnel() const
const uint8_t tunnel_type() const
const Ip4Address identifier() const
std::string ToString() const
static const std::string integerToString(const NumberType &num)
MvpnDBState(MvpnStatePtr state)
void set_state(MvpnStatePtr state)
void set_route(MvpnRoute *route)
const IpAddress & originator() const
uint32_t source_as() const
bool operator==(const MvpnNeighbor &rhs) const
const RouteDistinguisher & rd() const
bool operator<(const SG &other) const
SG(const Ip4Address &source, const Ip4Address &group)
virtual std::string ToString() const
void SetIdentifier(Ip4Address identifier)
void SetLabel(uint32_t label, const ExtCommunity *ext)
#define CHECK_CONCURRENCY(...)