5 #include <sandesh/sandesh_trace.h>
6 #include <port_ipc/port_ipc_types.h>
14 using namespace autogen;
15 using boost::uuids::nil_uuid;
24 "virtual-machine-interface")));
25 vmi_config_listener_id_ = vmi_config_table_->Register
31 vmi_config_table_->Unregister(vmi_config_listener_id_);
39 type_(type), ifname_(ifname), version_(version) {
57 return "Namespace Port";
75 const std::string &ifname,
79 const std::string &vm_name,
84 const std::string &mac_addr,
85 uint16_t tx_vlan_id, uint16_t rx_vlan_id,
86 uint8_t vhostuser_mode, uint8_t link_state) :
88 vm_uuid_(vm_uuid), vm_name_(vm_name), vn_uuid_(vn_uuid),
89 project_uuid_(project_uuid), ip4_addr_(ip4_addr), ip6_addr_(ip6_addr),
90 mac_addr_(mac_addr), tx_vlan_id_(tx_vlan_id), rx_vlan_id_(rx_vlan_id),
91 vhostuser_mode_(vhostuser_mode), link_state_(link_state) {
127 tx_vlan_id_p, rx_vlan_id_p, port,
ip6_addr_,
166 const std::string &vm_identifier,
const std::string &vm_ifname,
167 const std::string &vm_namespace) :
169 vn_uuid_(vn_uuid), vm_name_(vm_name), vm_identifier_(vm_identifier),
170 vm_ifname_(vm_ifname), vm_namespace_(vm_namespace), vmi_uuid_(vmi_uuid) {
206 agent_(agent), interface_table_(agent->interface_table()),
207 controller_(agent->controller()),
208 vmi_config_table_(NULL), vmi_config_listener_id_(
DBTableBase::kInvalidId) {
217 tbb::mutex::scoped_lock lock(
mutex_);
218 std::pair<VmiTree::iterator, bool> ret =
219 vmi_tree_.insert(std::make_pair(u, entry));
220 if (ret.second ==
false) {
230 ret =
vmi_tree_.insert(std::make_pair(u, entry));
232 ret.first->second->Update(entry.get());
236 ret.first->second->OnAdd(
agent_,
this);
240 tbb::mutex::scoped_lock lock(
mutex_);
241 VmiTree::iterator it =
vmi_tree_.find(u);
245 it->second->OnDelete(
agent_,
this);
251 tbb::mutex::scoped_lock lock(
mutex_);
252 VmiTree::const_iterator it =
vmi_tree_.find(u);
270 tbb::mutex::scoped_lock lock(
mutex_);
272 (make_pair(
VmVnUuidEntry(vm_uuid, vn_uuid, vmi_uuid),entry));
273 if (ret.second ==
false) {
274 ret.first->second->Update(entry.get());
279 if (vmi_uuid.is_nil())
294 tbb::mutex::scoped_lock lock(mutex_);
295 VmVnTree::iterator it =
296 vmvn_subscribe_tree_.find(
VmVnUuidEntry(vm_uuid, vn_uuid, vmi_uuid));
297 if (it == vmvn_subscribe_tree_.end())
300 it->second->OnDelete(agent_,
this);
301 vmvn_subscribe_tree_.erase(it);
308 VmVnTree::iterator it =
309 vmvn_subscribe_tree_.find(
VmVnUuidEntry(vm_uuid, vn_uuid, vmi_uuid));
310 if (it == vmvn_subscribe_tree_.end())
320 tbb::mutex::scoped_lock lock(mutex_);
321 return GetVmVnPortNoLock(vm_uuid, vn_uuid, vmi_uuid);
334 if (state->
uuid_ != nil_uuid())
348 VirtualMachineInterface *cfg =
349 static_cast <VirtualMachineInterface *> (node->
GetObject());
351 autogen::IdPermsType id_perms = cfg->id_perms();
352 CfgUuidSet(id_perms.uuid.uuid_mslong, id_perms.uuid.uuid_lslong, u);
356 if (state->
uuid_ != u) {
358 if (state->
uuid_ != nil_uuid()) {
360 state->
uuid_ = nil_uuid();
364 if (u != nil_uuid()) {
372 UuidToIFNodeTree::const_iterator it;
382 VmiToVmVnTree::const_iterator it = vmi_to_vmvn_tree_.find(vmi_uuid);
383 if (it == vmi_to_vmvn_tree_.end())
409 VmiToVmVnTree::iterator it;
410 it = vmi_to_vmvn_tree_.find(vmi_uuid);
412 if (it != vmi_to_vmvn_tree_.end()) {
414 if (it->second.vm_uuid_ != data->
vm_uuid_ ||
415 it->second.vn_uuid_ != data->
vn_uuid_) {
422 vmvn_to_vmi_tree_.insert(std::make_pair(entry, vmi_uuid));
430 vmvn_to_vmi_tree_.insert(std::make_pair(entry, vmi_uuid));
433 vmi_to_vmvn_tree_.insert(std::make_pair(vmi_uuid, vmi_entry));
447 tbb::mutex::scoped_lock lock(
mutex_);
452 if (entry_ref.get() == NULL)
458 if (entry->
vmi_uuid() == vmi_uuid) {
463 if (entry->
vmi_uuid().is_nil() ==
false) {
467 if (entry->
vmi_uuid().is_nil() ==
false) {
479 VmiToVmVnTree::iterator it;
480 it = vmi_to_vmvn_tree_.find(vmi_uuid);
481 if (it == vmi_to_vmvn_tree_.end()) {
490 vmi_to_vmvn_tree_.erase(it);
502 tbb::mutex::scoped_lock lock(mutex_);
503 DeleteVmiIfnodeInfo(vmi_uuid);
512 VmiTree::iterator it =
vmi_tree_.begin();
553 tbb::mutex::scoped_lock lock(mutex_);
554 VmiTree::const_iterator it = vmi_tree_.find(vmi_uuid);
555 if (it != vmi_tree_.end())
558 VmVnTree::const_iterator it1 =
559 vmvn_subscribe_tree_.find(
VmVnUuidEntry(vm_uuid, vn_uuid, vmi_uuid));
560 if (it1 != vmvn_subscribe_tree_.end())
568 std::set<boost::uuids::uuid> &vmi_uuid_set)
const {
569 VmVnToVmiTree::const_iterator it =
570 vmvn_to_vmi_tree_.lower_bound(
573 while (it != vmvn_to_vmi_tree_.end()) {
574 if (it->first.vm_uuid_ == vm_uuid)
575 vmi_uuid_set.insert(it->second);
579 if (vmi_uuid_set.empty())
587 std::set<boost::uuids::uuid> &vmi_uuid_set)
const {
588 tbb::mutex::scoped_lock lock(mutex_);
589 return VmVnToVmiSetNoLock(vm_uuid, vmi_uuid_set);
600 table_(agent->port_ipc_handler()->port_subscribe_table()),
616 const std::string &ifname,
624 std::string
Description()
const {
return "SandeshVmiPortSubscribeTask"; }
632 SandeshVmiPortSubscriptionResp *resp =
new SandeshVmiPortSubscriptionResp();
634 PortSubscribeTable::VmiTree::const_iterator it =
table_->
vmi_tree_.begin();
635 std::vector<SandeshVmiPortSubscriptionInfo> port_list;
641 if ((
ifname_.empty() ==
false) &&
650 SandeshVmiPortSubscriptionInfo info;
651 info.set_ifname(entry->
ifname());
652 info.set_version(entry->
version());
656 info.set_vm_name(entry->
vm_name());
657 info.set_ip4_addr(entry->
ip4_addr().to_string());
658 info.set_ip6_addr(entry->
ip6_addr().to_string());
664 port_list.push_back(info);
666 resp->set_port_list(port_list);
669 resp->set_more(
false);
674 void FetchVmiPortSubscriptionReq::HandleRequest()
const {
686 const std::string &ifname,
694 std::string
Description()
const {
return "SandeshVmVnPortSubscribeTask"; }
702 SandeshVmVnPortSubscriptionResp *resp =
703 new SandeshVmVnPortSubscriptionResp();
705 PortSubscribeTable::VmVnTree::const_iterator it =
707 std::vector<SandeshVmVnPortSubscriptionInfo> port_list;
713 if ((
ifname_.empty() ==
false) &&
722 SandeshVmVnPortSubscriptionInfo info;
723 info.set_ifname(entry->
ifname());
724 info.set_version(entry->
version());
727 info.set_vm_name(entry->
vm_name());
732 port_list.push_back(info);
734 resp->set_port_list(port_list);
737 resp->set_more(
false);
742 void FetchVmVnPortSubscriptionReq::HandleRequest()
const {
761 std::string
Description()
const {
return "SandeshVmiToVmVnTask"; }
768 SandeshVmiToVmVnResp *resp =
new SandeshVmiToVmVnResp();
770 PortSubscribeTable::VmiToVmVnTree::const_iterator it =
772 std::vector<SandeshVmiToVmVnInfo> port_list;
784 SandeshVmiToVmVnInfo info;
789 info.set_sub_interface(
"True");
791 info.set_sub_interface(
"False");
794 info.set_mac(vmi_entry->
mac_);
795 port_list.push_back(info);
797 resp->set_port_list(port_list);
800 resp->set_more(
false);
805 void FetchVmiToVmVnUuidReq::HandleRequest()
const {
824 std::string
Description()
const {
return "SandeshVmVnToVmiTask"; }
832 SandeshVmVnToVmiResp *resp =
new SandeshVmVnToVmiResp();
834 PortSubscribeTable::VmVnToVmiTree::const_iterator it =
836 std::vector<SandeshVmVnToVmiInfo> port_list;
851 SandeshVmVnToVmiInfo info;
855 port_list.push_back(info);
857 resp->set_port_list(port_list);
860 resp->set_more(
false);
865 void FetchVmVnToVmiUuidReq::HandleRequest()
const {
virtual ~SandeshVmiToVmVnTask()
virtual const boost::uuids::uuid & vm_uuid() const
virtual ~PortSubscribeEntry()
VmVnToVmiTree vmvn_to_vmi_tree_
boost::uuids::uuid parent_vmi_
virtual bool Run()
Code to execute. Returns true if task is completed. Return false to reschedule the task...
virtual ~SandeshVmVnToVmiTask()
static Agent * GetInstance()
static boost::uuids::uuid StringToUuid(const std::string &str)
boost::uuids::uuid vm_uuid_
virtual bool Run()
Code to execute. Returns true if task is completed. Return false to reschedule the task...
static void CfgUuidSet(uint64_t ms_long, uint64_t ls_long, boost::uuids::uuid &u)
const std::string & vm_identifier() const
bool VmVnToVmiSet(const boost::uuids::uuid &vm_uuid, std::set< boost::uuids::uuid > &vmi_uuid_set) const
void OnAdd(Agent *agent, PortSubscribeTable *table) const
const boost::uuids::uuid & vm_uuid() const
void OnDelete(Agent *agent, PortSubscribeTable *table) const
DBState * GetState(DBTableBase *tbl_base, ListenerId listener) const
virtual bool MatchVn(const boost::uuids::uuid &u) const
boost::uuids::uuid vmi_uuid_
void DeleteVmVnPort(const boost::uuids::uuid &vm_uuid, const boost::uuids::uuid &vn_uuid, const boost::uuids::uuid &vmi_uuid)
boost::uuids::uuid vm_uuid_
void set_vmi_uuid(const boost::uuids::uuid &u)
void OnDelete(Agent *agent, PortSubscribeTable *table) const
const std::string & vmware_physical_port() const
SandeshPortSubscribeTask(Agent *agent, const std::string &context)
virtual ~SandeshVmVnPortSubscribeTask()
boost::uuids::uuid vn_uuid_
bool vrouter_on_host_dpdk() const
DBTableBase::ListenerId vmi_config_listener_id_
void SetState(DBTableBase *tbl_base, ListenerId listener, DBState *state)
void DeleteVmi(const boost::uuids::uuid &u)
boost::uuids::uuid vmi_uuid_
PortIpcHandler * port_ipc_handler() const
SandeshVmVnPortSubscribeTask(Agent *agent, const std::string &context, const std::string &ifname, const boost::uuids::uuid &vm_uuid)
VmiToVmVnTree vmi_to_vmvn_tree_
uint8_t vhostuser_mode() const
const boost::uuids::uuid & vmi_uuid() const
InterfaceTable * interface_table() const
bool VmVnToVmiSetNoLock(const boost::uuids::uuid &vm_uuid, std::set< boost::uuids::uuid > &vmi_uuid_set) const
PortSubscribeTable(Agent *agent)
std::string Description() const
void AddVmVnPort(const boost::uuids::uuid &vm_uuid, const boost::uuids::uuid &vn_uuid, const boost::uuids::uuid &vmi_uuid, PortSubscribeEntryPtr entry)
void OnAdd(Agent *agent, PortSubscribeTable *table) const
static std::string UuidToString(const boost::uuids::uuid &id)
static void SetIfNameReq(InterfaceTable *table, const boost::uuids::uuid &uuid, const std::string &ifname)
std::string Description() const
boost::uuids::uuid vn_uuid_
boost::uuids::uuid vm_uuid_
void Enqueue(ControllerWorkQueueDataType data)
virtual ~SandeshPortSubscribeTask()
SandeshVmiToVmVnTask(Agent *agent, const std::string &context, const boost::uuids::uuid &vmi_uuid)
bool vrouter_on_nic_mode() const
uint16_t rx_vlan_id() const
virtual ~PortSubscribeTable()
bool DeleteVmVnPort(const boost::uuids::uuid &vmi_uuid, string &err_msg)
SandeshVmiPortSubscribeTask(Agent *agent, const std::string &context, const std::string &ifname, const boost::uuids::uuid &vmi_uuid)
IFMapNode * UuidToIFNode(const boost::uuids::uuid &u) const
void AddVmi(const boost::uuids::uuid &u, PortSubscribeEntryPtr entry)
~VmVnPortSubscribeEntry()
boost::uuids::uuid vn_uuid_
const PortSubscribeTable * table_
static const char * TypeToString(Type type)
static void CopyVmiConfigToInfo(PortSubscribeTable::VmiEntry *entry, const VmInterfaceConfigData *data)
DISALLOW_COPY_AND_ASSIGN(SandeshVmiPortSubscribeTask)
virtual bool MatchVm(const boost::uuids::uuid &u) const
TaskScheduler * task_scheduler() const
PortSubscribeEntryPtr GetVmVnPort(const boost::uuids::uuid &vm_uuid, const boost::uuids::uuid &vn_uuid, const boost::uuids::uuid &vmi_uuid)
const std::string & vm_ifname() const
const std::string & mac_addr() const
void UpdateVmiIfnodeInfo(const boost::uuids::uuid &vmi_uuid, const VmInterfaceConfigData *data)
static const uint32_t kInvalidVlanId
virtual ~SandeshVmiPortSubscribeTask()
UuidToIFNodeTree uuid_ifnode_tree_
void Enqueue(Task *task)
Enqueues a task for running. Starts task if all policy rules are met else puts task in waitq...
boost::uuids::uuid vmi_uuid_
boost::asio::ip::address_v6 Ip6Address
virtual bool Run()
Code to execute. Returns true if task is completed. Return false to reschedule the task...
VNController * controller() const
VmiSubscribeEntry(PortSubscribeEntry::Type type, const std::string &ifname, uint32_t version, const boost::uuids::uuid &vmi_uuid, const boost::uuids::uuid vm_uuid, const std::string &vm_name, const boost::uuids::uuid &vn_uuid, const boost::uuids::uuid &project_uuid, const Ip4Address &ip4_addr, const Ip6Address &ip6_addr, const std::string &mac_addr, uint16_t tx_vlan_id, uint16_t rx_vlan_id, uint8_t vhostuser_mode, uint8_t link_state)
boost::uuids::uuid vm_uuid_
virtual bool MatchVn(const boost::uuids::uuid &u) const
bool isVmwareMode() const
static const std::string & NullString()
DISALLOW_COPY_AND_ASSIGN(SandeshPortSubscribeTask)
const std::string & vm_name() const
const std::string & ifname() const
PortSubscribeEntryPtr Get(const boost::uuids::uuid &vmi_uuid, const boost::uuids::uuid &vm_uuid, const boost::uuids::uuid &vn_uuid) const
DISALLOW_COPY_AND_ASSIGN(SandeshVmVnPortSubscribeTask)
boost::shared_ptr< PortSubscribeEntry > PortSubscribeEntryPtr
boost::uuids::uuid parent_vmi_
AgentParam * params() const
void ClearState(DBTableBase *tbl_base, ListenerId listener)
VmVnTree vmvn_subscribe_tree_
boost::asio::ip::address_v4 Ip4Address
const boost::uuids::uuid & vn_uuid() const
IFMapObject * GetObject()
boost::uuids::uuid vm_uuid_
virtual void Update(const PortSubscribeEntry *rhs)
boost::shared_ptr< ControllerWorkQueueData > ControllerWorkQueueDataType
static void DeleteIfNameReq(InterfaceTable *table, const boost::uuids::uuid &uuid)
DISALLOW_COPY_AND_ASSIGN(SandeshVmiToVmVnTask)
const std::string & vm_namespace() const
const std::string & vm_name() const
autogen::VirtualMachineInterface * vmi_cfg
static IFMapTable * FindTable(DB *db, const std::string &element_type)
void HandleVmiIfnodeDelete(const boost::uuids::uuid &vmi_uuid)
void HandleVmiIfnodeAdd(const boost::uuids::uuid &vmi_uuid, const VmInterfaceConfigData *data)
std::string Description() const
static void DBStateClear(DBTable *table, ListenerId id)
boost::uuids::uuid vmi_uuid_
void DeleteVmiIfnodeInfo(const boost::uuids::uuid &vmi_uuid)
virtual bool Run()
Code to execute. Returns true if task is completed. Return false to reschedule the task...
const boost::uuids::uuid & vmi_uuid() const
void StaleWalk(uint64_t version)
DISALLOW_COPY_AND_ASSIGN(SandeshVmVnToVmiTask)
const VmiEntry * VmiToEntry(const boost::uuids::uuid &vmi_uuid) const
void DeleteVmiUuidEntry(const boost::uuids::uuid &u, std::string &err_str)
PortSubscribeEntry(Type type, const std::string &ifname, int32_t version)
#define kTaskHttpRequstHandler
boost::uuids::uuid vm_uuid_
virtual void Update(const PortSubscribeEntry *rhs)
boost::uuids::uuid project_uuid_
boost::uuids::uuid vn_uuid_
autogen::VirtualMachineInterface * GetVmiCfg() const
PortSubscribeEntryPtr GetVmi(const boost::uuids::uuid &u) const
PortSubscribeEntryPtr GetVmVnPortNoLock(const boost::uuids::uuid &vm_uuid, const boost::uuids::uuid &vn_uuid, const boost::uuids::uuid &vmi_uuid)
virtual void Update(const PortSubscribeEntry *rhs)
const Ip6Address & ip6_addr() const
uint16_t tx_vlan_id() const
static void NovaAdd(InterfaceTable *table, const boost::uuids::uuid &intf_uuid, const std::string &os_name, const Ip4Address &addr, const std::string &mac, const std::string &vn_name, const boost::uuids::uuid &vm_project_uuid, uint16_t tx_vlan_id, uint16_t rx_vlan_id, const std::string &parent, const Ip6Address &ipv6, uint8_t vhostuser_mode, Interface::Transport transport, uint8_t link_state)
Task is a wrapper over tbb::task to support policies.
std::string Description() const
const Ip4Address & ip4_addr() const
VmVnPortSubscribeEntry(PortSubscribeEntry::Type type, const std::string &ifname, uint32_t version, const boost::uuids::uuid &vm_uuid, const boost::uuids::uuid &vn_uuid, const boost::uuids::uuid &vmi_uuid, const std::string &vm_name, const std::string &vm_identifier, const std::string &vm_ifname, const std::string &vm_namespace)
SandeshVmVnToVmiTask(Agent *agent, const std::string &context, const boost::uuids::uuid &vm_uuid, const boost::uuids::uuid &vn_uuid)
boost::uuids::uuid vn_uuid_
virtual bool MatchVm(const boost::uuids::uuid &u) const
void Notify(DBTablePartBase *partition, DBEntryBase *e)