12 #include <bgp_schema_types.h>
13 #include <vnc_cfg_types.h>
34 #define MAX_VRF_DELETE_TIMEOUT_RETRY_COUNT 10
45 agent()->lifetime_manager()), table_(vrf, this) {
51 return table_->AllRouteTableDeleted();
56 table_->SendObjectLog(AgentLogEvent::DEL);
65 name_(name), id_(kInvalidIndex), flags_(flags),
67 rt_table_db_(), delete_timeout_timer_(NULL),
70 rt_table_delete_bmap_(0),
71 route_resync_walker_(NULL), allow_route_add_on_deleted_vrf_(false),
72 layer2_control_word_(false),
73 rd_(0), routing_vrf_(false), retries_(0),
75 hbf_lintf_(
Interface::kInvalidIndex), deleted_(false) {
119 bool flood_unknown_unicast,
120 bool layer2_control_word) {
129 nh_req.
key.reset(vrf_nh_key);
205 if (vhost && vhost->
parent_list().empty() ==
false) {
206 for (
size_t i = 0; i < vhost->
parent_list().size(); i++) {
241 }
else if (addr.is_v6()) {
290 switch (table_type) {
292 return "inet4_unicast";
300 return "inet6_unicast";
304 return "inet4_multicast";
343 VrfListResp *resp =
static_cast<VrfListResp *
>(sresp);
345 if (name.empty() ||
GetName().find(name) != string::npos) {
348 data.set_ucindex(
vrf_id());
349 data.set_mcindex(
vrf_id());
350 data.set_evpnindex(
vrf_id());
351 data.set_l2index(
vrf_id());
352 data.set_brindex(
vrf_id());
353 data.set_uc6index(
vrf_id());
354 std::string vrf_flags;
356 vrf_flags +=
"Config; ";
358 vrf_flags +=
"Gateway; ";
360 vrf_flags +=
"PBB C-Vrf";
361 data.set_source(vrf_flags);
363 data.set_vn(
vn_->GetName());
372 data.set_RD(
rd.str());
374 std::vector<VrfSandeshData> &list =
375 const_cast<std::vector<VrfSandeshData>&
>(resp->get_vrf_list());
384 list.push_back(data);
392 VrfObjectLogInfo vrf;
395 case AgentLogEvent::ADD:
396 str.assign(
"Addition ");
398 case AgentLogEvent::DEL:
399 str.assign(
"Deletion ");
401 case AgentLogEvent::CHANGE:
402 str.assign(
"Modification ");
404 case AgentLogEvent::DELETE_TRIGGER:
405 str.assign(
"Deletion Triggered ");
414 VRF_OBJECT_LOG_LOG(
"AgentVrf", SandeshLevel::SYS_INFO, vrf);
418 uint32_t num_routes = 0;
425 std::ostringstream str;
434 "VRF delete failed, " + str.str(),
name_);
443 "VRF delete failed with max retries",
name_);
509 "Reset Vrf Deletion",
GetName());
518 UpdateRoutesInVrf(
this);
531 if (tor_agent_enabled ==
false) {
538 if (
vn()->vnid() == 0)
587 oper_db()->dependency_manager();
639 return std::unique_ptr<DBEntry>(
static_cast<DBEntry *
>(vrf));
660 Allocate(rkey).get())->index();
678 if (vrf->
vn_.get()) {
701 bool resync_routes =
false;
703 if (vn != vrf->
vn_.get()) {
704 resync_routes =
true;
718 bool layer2_control_word =
false;
740 resync_routes =
true;
804 if (vhost && vhost->
parent_list().empty() ==
false) {
805 for (
size_t i = 0; i < vhost->
parent_list().size(); i++) {
822 vrf->
vn_.reset(NULL);
844 req_key.
id_type =
"routing-instance";
874 VrfNameTree::const_iterator it;
881 return static_cast<VrfEntry *
>(it->second);
898 (
const string &vrf_name) {
904 (
const string &vrf_name) {
922 (
const string &vrf_name) {
928 uint8_t table_type) {
929 VrfDbTree::const_iterator it;
931 it =
dbtree_[table_type].find(vrf_name);
932 if (it ==
dbtree_[table_type].end()) {
958 uint32_t flags, uint32_t isid,
959 const std::string &bmac_vrf_name,
960 uint32_t aging_timeout,
961 bool learning_enabled) {
965 bmac_vrf_name, aging_timeout,
1005 boost::uuids::nil_uuid(), 0,
"", 0,
false);
1007 req.
data.reset(data);
1017 dbtree_[table_type].erase(vrf_name);
1028 OPER_TRACE(Vrf,
"VRF pending delete, Ignoring DB operation for ",
1044 uint32_t &hbf_rintf, uint32_t &hbf_lintf) {
1050 if (iter->IsDeleted()) {
1056 "host-based-service-virtual-network")) {
1057 autogen::HostBasedServiceVirtualNetwork *hbsvn =
1058 static_cast<HostBasedServiceVirtualNetwork *
>
1060 ServiceVirtualNetworkType
type = hbsvn->data();
1063 adj_node->
begin(graph);
1064 iter != node->
end(graph); ++iter) {
1066 static_cast<IFMapNode *
>(iter.operator->());
1068 "virtual-network")) {
1070 hbsvn_adj_node->
begin(graph);
1071 iter != node->
end(graph); ++iter) {
1072 if (iter->IsDeleted()) {
1076 static_cast<IFMapNode *
>(iter.operator->());
1078 "virtual-machine-interface")) {
1079 VirtualMachineInterface *cfg =
1080 static_cast <VirtualMachineInterface *
>
1082 autogen::IdPermsType id_perms = cfg->id_perms();
1085 id_perms.uuid.uuid_lslong, u);
1091 if (!strcmp(
type.virtual_network_type.c_str(),
1093 hbf_rintf = intf->id();
1095 type.virtual_network_type.c_str(),
"left")) {
1096 hbf_lintf = intf->id();
1107 uint32_t &hbf_rintf, uint32_t &hbf_lintf) {
1112 iter != node->
end(graph); ++iter) {
1113 if (iter->IsDeleted()) {
1117 static_cast<IFMapNode *
>(iter.operator->());
1119 if (strcmp(adj_node->
table()->
Typename(),
"host-based-service") == 0) {
1127 uint32_t &hbf_rintf, uint32_t &hbf_lintf) {
1132 iter != node->
end(graph); ++iter) {
1133 if (iter->IsDeleted()) {
1137 static_cast<IFMapNode *
>(iter.operator->());
1139 if (strcmp(adj_node->
table()->
Typename(),
"project") == 0) {
1147 uint32_t &hbf_rintf, uint32_t &hbf_lintf) {
1152 iter != vn_node->
end(graph); ++iter) {
1153 if (iter->IsDeleted()) {
1157 static_cast<IFMapNode *
>(iter.operator->());
1160 "virtual-machine-interface") == 0) {
1168 std::string &forwarding_vrf_name) {
1172 iter != vn_node->
end(graph); ++iter) {
1174 static_cast<IFMapNode *
>(iter.operator->());
1175 if (iter->IsDeleted() ||
1180 VirtualNetwork *cfg =
1181 static_cast <VirtualNetwork *
> (adj_node->
GetObject());
1197 bool learning_enabled =
false;
1198 std::string forwarding_vrf =
"";
1202 uint32_t aging_timeout = 0;
1204 iter != node->
end(graph); ++iter) {
1206 static_cast<IFMapNode *
>(iter.operator->());
1208 if (iter->IsDeleted() ||
1213 VirtualNetwork *cfg =
1214 static_cast <VirtualNetwork *
> (adj_node->
GetObject());
1224 autogen::IdPermsType id_perms = cfg->id_perms();
1225 CfgUuidSet(id_perms.uuid.uuid_mslong, id_perms.uuid.uuid_lslong,
1227 aging_timeout = cfg->mac_aging_time();
1230 autogen::IdPermsType id_perms = cfg->id_perms();
1231 CfgUuidSet(id_perms.uuid.uuid_mslong, id_perms.uuid.uuid_lslong,
1239 aging_timeout, learning_enabled,
1240 hbf_rintf, hbf_lintf);
1266 boost::uuids::nil_uuid(), 0,
"", 0,
false);
1267 if (node->
name() ==
agent()->fabric_policy_vrf_name()) {
1270 req.
data.reset(data);
1294 boost::uuids::nil_uuid(), 0,
"", 0,
false,
1297 if (node->
name() ==
agent()->fabric_policy_vrf_name()) {
1300 req.
data.reset(data);
1312 void VrfListReq::HandleRequest()
const {
1314 sand->DoSandesh(sand);
1318 const std::string &context) {
1334 for(Route::PathList::const_iterator it = rt->
GetPathList().begin();
1337 static_cast<const AgentPath *
>(it.operator->());
1338 Route::PathList::const_iterator next = ++it;
boost::asio::ip::address IpAddress
boost::intrusive_ptr< const Interface > InterfaceConstRef
static void CfgUuidSet(uint64_t ms_long, uint64_t ls_long, boost::uuids::uuid &u)
class boost::shared_ptr< AgentSandesh > AgentSandeshPtr
#define OPER_TRACE(obj,...)
#define OPER_TRACE_ENTRY(obj, table,...)
IFMapAgentTable * cfg_vn_table() const
virtual void Input(DBTablePartition *root, DBClient *client, DBRequest *req)
AgentDBEntry * FindActiveEntry(const DBEntry *key)
virtual void Process(DBRequest &req)
IFMapNode * ifmap_node() const
const std::string & vmware_physical_port() const
const Peer * peer() const
virtual const PrefixType & prefix_address() const
Returns the value of a stored prefix address (IPv4, IPv6 or MAC address)
Agent supports multiple route tables - Inet-unicast (IPv4/IPv6), Inet-multicast, bridge,...
void SetVrf(VrfEntry *vrf)
static const std::string & GetSuffix(Agent::RouteTableType type)
void ReleaseWalker(AgentRouteWalker *walker)
AgentRouteWalkerManager * mgr()
boost::function< void()> WalkDone
Base class for all Route entries in agent.
std::string GetString(const std::string &key) const
InterfaceTable * interface_table() const
ConfigManager * config_manager() const
ResourceManager * resource_manager() const
AgentParam * params() const
const std::string & fabric_policy_vrf_name() const
VrfTable * vrf_table() const
const Peer * local_peer() const
EventManager * event_manager() const
static const MacAddress & right_si_mac()
AgentConfig * cfg() const
const Peer * local_vm_peer() const
const std::string & fabric_vn_name() const
static const MacAddress & left_si_mac()
Ip4Address compute_node_ip() const
static const std::string & NullString()
VnTable * vn_table() const
NextHopTable * nexthop_table() const
static const MacAddress & vrrp_mac()
bool tor_agent_enabled() const
const Interface * vhost_interface() const
const std::string & fabric_vrf_name() const
bool isVmwareMode() const
static void AddBridgeReceiveRoute(const Peer *peer, const std::string &vrf_name, const MacAddress &mac, const std::string &vn_name, const std::string &interface, bool policy)
static void Delete(const Peer *peer, const std::string &vrf_name, const MacAddress &mac, uint32_t ethernet_tag)
void AddVrfNode(IFMapNode *node)
void NodeResync(IFMapNode *node)
std::unique_ptr< DBRequestKey > KeyPtr
DBTableBase * get_table() const
virtual KeyPtr GetDBRequestKey() const =0
edge_iterator edge_list_begin(DBGraph *graph)
adjacency_iterator end(DBGraph *graph)
adjacency_iterator begin(DBGraph *graph)
edge_iterator edge_list_end(DBGraph *graph)
bool Enqueue(DBRequest *req)
const std::string & name() const
DBEntry * Find(const DBEntry *entry)
virtual size_t Size() const
void ReleaseWalker(DBTableWalkRef &walk)
void RemoveTable(DBTableBase *tbl_base)
DBTableBase * CreateTable(const std::string &name)
const DBGraph * GetGraph() const
static IFMapNode * TableEntryLookup(DB *db, RequestKey *key)
void SetNotify(IFMapNode *node, bool notfiy_flag)
IFMapNodePtr SetState(IFMapNode *node)
const std::string & name() const
IFMapObject * GetObject()
virtual const char * Typename() const =0
size_t InsertAtIndex(uint32_t index, EntryType entry)
EntryType At(size_t index) const
void Remove(size_t index)
InetUnicastRouteEntry * FindLPM(const IpAddress &ip)
InterfaceConstRef FindVmi(const boost::uuids::uuid &u)
const MacAddress & mac() const
static const uint32_t kInvalidIndex
static const uint32_t kInvalidLabel
void Process(DBRequest &req)
const MplsLabel * mpls_label() const
AgentRouteWalkerManager * agent_route_walk_manager() const
IFMapDependencyManager * dependency_manager()
boost::shared_ptr< ResourceKey > KeyPtr
static uint32_t walk_done_
static uint32_t walk_start_
static void WalkDone(RouteDeleteWalker *walker)
bool RouteWalkNotify(DBTablePartBase *partition, DBEntryBase *e)
RouteDeleteWalker(const std::string &name, Agent *agent)
const PathList & GetPathList() const
static bool DeleteTimer(Timer *Timer)
static Timer * CreateTimer(boost::asio::io_context &service, const std::string &name, int task_id=Timer::GetTimerTaskId(), int task_instance=Timer::GetTimerInstanceId(), bool delete_on_completion=false)
bool Start(int time, Handler handler, ErrorHandler error_handler=NULL)
InterfaceList parent_list() const
bool layer2_control_word() const
VnEntry * Find(const boost::uuids::uuid &vn_uuid)
static void WalkDone(VrfDeleteWalker *walker)
VrfDeleteWalker(const std::string &name, Agent *agent)
bool RouteWalkNotify(DBTablePartBase *partition, DBEntryBase *e)
bool VrfWalkNotify(DBTablePartBase *partition, DBEntryBase *e)
DeleteActor(VrfEntry *vrf)
virtual bool MayDelete() const
const string & GetName() const
IFMapDependencyManager::IFMapNodePtr vrf_node_ptr_
uint32_t table_label() const
void set_hbf_lintf(uint32_t idx)
AgentRouteTable * GetBridgeRouteTable() const
void set_table_label(uint32_t label)
bool layer2_control_word_
bool learning_enabled() const
void CreateTableLabel(bool learning_enabled, bool l2, bool flod_unknown_unicast, bool layer2_control_word)
bool DBEntrySandesh(Sandesh *sresp, std::string &name) const
virtual void SetKey(const DBRequestKey *key)
VrfEntryRef forwarding_vrf_
bool RouteTableDeleted(uint8_t table_type) const
const std::string GetTableTypeString(uint8_t table_type) const
tbb::mutex delete_reuse_mutex_
InetUnicastAgentRouteTable * GetInet4MplsUnicastRouteTable() const
const uint32_t hbf_lintf() const
tbb::atomic< uint32_t > mac_aging_time_
const uint32_t hbf_rintf() const
virtual string ToString() const
bool UpdateVxlanId(Agent *agent, uint32_t new_vxlan_id)
void set_flags(uint32_t flags)
AgentRouteTable * rt_table_db_[Agent::ROUTE_TABLE_MAX]
InetUnicastRouteEntry * GetUcRoute(const IpAddress &addr) const
void set_routing_vrf(bool val)
InetUnicastAgentRouteTable * GetInet4UnicastRouteTable() const
static const uint32_t kDeleteTimeout
VrfEntry(const string &name, uint32_t flags, Agent *agent)
boost::scoped_ptr< DeleteActor > deleter_
void set_hbf_rintf(uint32_t idx)
static const uint32_t kInvalidIndex
InetUnicastAgentRouteTable * GetInet6UnicastRouteTable() const
virtual bool IsLess(const DBEntry &rhs) const
const uint32_t vrf_id() const
uint32_t rt_table_delete_bmap_
LifetimeActor * deleter()
InetUnicastAgentRouteTable * GetInetUnicastRouteTable(const IpAddress &addr) const
AgentRouteTable * GetEvpnRouteTable() const
AgentRouteTable * GetInet4MulticastRouteTable() const
bool are_flags_set(const VrfData::VrfEntryFlags &flags) const
virtual void RetryDelete()
bool AllRouteTableDeleted() const
uint32_t vxlan_id() const
void SetRouteTableDeleted(uint8_t table_type)
void SendObjectLog(AgentLogEvent::type event) const
virtual KeyPtr GetDBRequestKey() const
uint32_t GetRefCount() const
bool AllRouteTablesEmpty() const
bool layer2_control_word() const
AgentRouteWalkerPtr route_resync_walker_
AgentRouteTable * GetRouteTable(uint8_t table_type) const
int RDInstanceId(bool tor_agent_enabled) const
Timer * delete_timeout_timer_
IndexVector< VrfEntry * > index_table_
void DeleteFromDbTree(int table_type, const std::string &vrf_name)
virtual DBEntry * OperDBAdd(const DBRequest *req)
virtual bool IFNodeToReq(IFMapNode *node, DBRequest &req, const boost::uuids::uuid &u)
static DBTableBase * CreateTable(DB *db, const std::string &name)
bool ProcessConfig(IFMapNode *node, DBRequest &req, const boost::uuids::uuid &u)
void DeleteVrf(const string &name, uint32_t flags=VrfData::ConfigVrf)
void CreateFabricPolicyVrf(const string &name)
void reset_route_delete_walker()
AgentRouteWalkerPtr vrf_delete_walker_
pair< string, RouteTable * > VrfDbPair
VrfEntry * FindVrfFromName(const string &name)
VrfEntry * FindVrfFromIdIncludingDeletedVrf(size_t index)
InetUnicastAgentRouteTable * GetInet6UnicastRouteTable(const std::string &vrf_name)
void reset_vrf_delete_walker()
AgentRouteTable * GetEvpnRouteTable(const std::string &vrf_name)
void DeleteStaticVrf(const string &name)
static VrfTable * vrf_table_
void VrfReuse(std::string name)
VrfTable(DB *db, const std::string &name)
virtual void Input(DBTablePartition *root, DBClient *client, DBRequest *req)
void DeleteVrfReq(const string &name, uint32_t flags=VrfData::ConfigVrf)
virtual std::unique_ptr< DBEntry > AllocEntry(const DBRequestKey *k) const
pair< string, VrfEntry * > VrfNamePair
AgentRouteWalkerPtr route_delete_walker_
AgentRouteTable * GetRouteTable(const string &vrf_name, uint8_t table_type)
AgentRouteTable * GetBridgeRouteTable(const std::string &vrf_name)
VrfEntry * FindVrfFromId(size_t index)
void CreateStaticVrf(const string &name)
void CreateVrf(const string &name, const boost::uuids::uuid &vn_uuid, uint32_t flags)
VrfDbTree dbtree_[Agent::ROUTE_TABLE_MAX]
InetUnicastAgentRouteTable * GetInet4UnicastRouteTable(const std::string &vrf_name)
virtual AgentSandeshPtr GetAgentSandesh(const AgentSandeshArguments *args, const std::string &context)
bool IsStaticVrf(const std::string &vrf_name) const
void FreeVrfId(size_t index)
virtual void OnZeroRefcount(AgentDBEntry *e)
void CreateVrfReq(const string &name, uint32_t flags=VrfData::ConfigVrf)
AgentRouteTable * GetInet4MulticastRouteTable(const std::string &vrf_name)
InetUnicastAgentRouteTable * GetInet4MplsUnicastRouteTable(const std::string &vrf_name)
virtual bool OperDBOnChange(DBEntry *entry, const DBRequest *req)
std::set< std::string > static_vrf_set_
virtual bool OperDBDelete(DBEntry *entry, const DBRequest *req)
static const uint32_t kInvalidvxlan_id
IFMapNode * ifmap_node() const
std::unique_ptr< DBRequestKey > key
std::unique_ptr< DBRequestData > data
boost::uuids::uuid vn_uuid_
boost::uuids::uuid si_vn_ref_uuid_
std::string forwarding_vrf_name_
std::string bmac_vrf_name_
bool IsVRFServiceChainingInstance(const string &vn_name, const string &vrf_name)
static void BuildForwardingVrf(Agent *agent, IFMapNode *vn_node, std::string &forwarding_vrf_name)
static VrfData * BuildData(Agent *agent, IFMapNode *node)
#define MAX_VRF_DELETE_TIMEOUT_RETRY_COUNT
static void FindHbfInterfacesFromVmi(Agent *agent, IFMapNode *node, uint32_t &hbf_rintf, uint32_t &hbf_lintf)
static void FindHbfInterfacesFromHBS(Agent *agent, IFMapNode *node, uint32_t &hbf_rintf, uint32_t &hbf_lintf)
static void FindHbfInterfaces(Agent *agent, IFMapNode *vn_node, uint32_t &hbf_rintf, uint32_t &hbf_lintf)
static void FindHbfInterfacesFromProject(Agent *agent, IFMapNode *node, uint32_t &hbf_rintf, uint32_t &hbf_lintf)