OpenSDN source code
service_instance.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #ifndef VNSW_AGENT_OPER_SERVICE_INSTANCE_H__
7 #define VNSW_AGENT_OPER_SERVICE_INSTANCE_H__
8 
9 #include <string>
10 #include <map>
11 #include <boost/uuid/uuid.hpp>
12 #include "cmn/agent_db.h"
14 #include "schema/vnc_cfg_types.h"
15 
16 class DBGraph;
18 class InstanceManager;
19 
20 class ServiceInstanceKey : public AgentKey {
21  public:
23  uuid_ = uuid;
24  }
26  return uuid_;
27  }
28 
29  private:
31 };
32 
33 class ServiceInstance : public AgentRefCount<ServiceInstance>,
34  public AgentDBEntry {
35 public:
36  enum ServiceType {
37  Other = 1,
40  };
45  };
47  KVM = 1,
48  Docker
49  };
50 
51  /*
52  * Properties computed from walking the ifmap graph.
53  * POD type.
54  */
55  struct Properties {
56  void Clear();
57  int CompareTo(const Properties &rhs) const;
58  const std::string &ServiceTypeString() const;
59 
60  bool Usable() const;
61  std::string DiffString(const Properties &rhs) const;
62  std::string IdToCmdLineStr() const;
64 
65  /* template parameters */
69 
70  /* virtual machine */
72 
73  /* interfaces */
77 
78  std::string mac_addr_inside;
79  std::string mac_addr_outside;
80  std::string mac_addr_management;
81 
82  std::string ip_addr_inside;
83  std::string ip_addr_outside;
84  std::string ip_addr_management;
85 
86  std::string gw_ip;
87  std::string image_name;
88 
92 
94 
95  std::string instance_data;
96  std::vector<autogen::KeyValuePair> instance_kvps;
97 
98  // loadbalancer id
99  std::string loadbalancer_id;
100  };
101 
102  ServiceInstance();
103  virtual bool IsLess(const DBEntry &rhs) const;
104  virtual std::string ToString() const;
105  virtual void SetKey(const DBRequestKey *key);
106  virtual KeyPtr GetDBRequestKey() const;
107  bool DBEntrySandesh(Sandesh *sresp, std::string &name) const;
108 
109  virtual uint32_t GetRefCount() const {
111  }
112 
115  }
116 
117  const Properties &properties() const { return properties_; }
118 
119  const boost::uuids::uuid &uuid() const { return uuid_; }
120 
121  bool IsUsable() const;
122 
124  ifmap_node_state_ref_ = ref;
125  }
126 
129  return NULL;
130  IFMapNodeState *state = ifmap_node_state_ref_.get();
131  return state->node();
132  }
133 private:
137 
139 };
140 
142  public:
143  ServiceInstanceTable(DB *db, const std::string &name);
144 
145  virtual std::unique_ptr<DBEntry> AllocEntry(const DBRequestKey *key) const;
146 
147  /*
148  * Register with the dependency manager.
149  */
150  void Initialize(DBGraph *graph, IFMapDependencyManager *dependency_manager);
151 
152  /*
153  * Add/Delete methods establish the mapping between the IFMapNode
154  * and the ServiceInstance DBEntry with the dependency manager.
155  */
156  virtual DBEntry *Add(const DBRequest *request);
157  virtual bool Delete(DBEntry *entry, const DBRequest *request);
158  virtual bool OnChange(DBEntry *entry, const DBRequest *request);
159 
160  /*
161  * Walk the IFMap graph and calculate the properties for this node.
162  */
163  void CalculateProperties(DBGraph *graph, IFMapNode *node,
164  ServiceInstance::Properties *properties);
165 
166  /*
167  * IFNodeToReq
168  *
169  * Convert the ifmap node to a (key,data) pair stored in the database.
170  */
171  virtual bool IFNodeToReq(IFMapNode *node, DBRequest &req,
172  const boost::uuids::uuid &u);
173  virtual bool IFNodeToUuid(IFMapNode *node, boost::uuids::uuid &id);
174 
176  const std::string &context);
177  static DBTableBase *CreateTable(DB *db, const std::string &name);
178 
179  private:
180  /*
181  * Invoked by dependency manager whenever a node in the graph
182  * changes in a way that it affects the service instance
183  * configuration. The dependency tracking policy is configured in
184  * the dependency manager directly.
185  */
186  void ChangeEventHandler(IFMapNode *node, DBEntry *entry);
187  bool HandleAddChange(ServiceInstance **svc_instance, const DBRequest *key);
188 
191 
193 };
194 
195 #endif // VNSW_AGENT_OPER_SERVICE_INSTANCE_H__
class boost::shared_ptr< AgentSandesh > AgentSandeshPtr
Definition: agent_db.h:21
uint32_t GetRefCount() const
Definition: agent_db.h:57
std::unique_ptr< DBRequestKey > KeyPtr
Definition: db_entry.h:25
const std::string & name() const
Definition: db_table.h:111
Definition: db.h:25
boost::intrusive_ptr< IFMapNodeState > IFMapNodePtr
boost::uuids::uuid uuid_
ServiceInstanceKey(boost::uuids::uuid uuid)
const boost::uuids::uuid & instance_id() const
IFMapDependencyManager * dependency_manager_
virtual bool IFNodeToReq(IFMapNode *node, DBRequest &req, const boost::uuids::uuid &u)
void ChangeEventHandler(IFMapNode *node, DBEntry *entry)
virtual bool IFNodeToUuid(IFMapNode *node, boost::uuids::uuid &id)
virtual bool OnChange(DBEntry *entry, const DBRequest *request)
static DBTableBase * CreateTable(DB *db, const std::string &name)
virtual DBEntry * Add(const DBRequest *request)
void CalculateProperties(DBGraph *graph, IFMapNode *node, ServiceInstance::Properties *properties)
virtual AgentSandeshPtr GetAgentSandesh(const AgentSandeshArguments *args, const std::string &context)
ServiceInstanceTable(DB *db, const std::string &name)
bool HandleAddChange(ServiceInstance **svc_instance, const DBRequest *key)
DISALLOW_COPY_AND_ASSIGN(ServiceInstanceTable)
virtual bool Delete(DBEntry *entry, const DBRequest *request)
void Initialize(DBGraph *graph, IFMapDependencyManager *dependency_manager)
virtual std::unique_ptr< DBEntry > AllocEntry(const DBRequestKey *key) const
const Properties & properties() const
virtual uint32_t GetRefCount() const
bool DBEntrySandesh(Sandesh *sresp, std::string &name) const
DISALLOW_COPY_AND_ASSIGN(ServiceInstance)
const boost::uuids::uuid & uuid() const
bool IsUsable() const
boost::uuids::uuid uuid_
void set_properties(const Properties &properties)
virtual void SetKey(const DBRequestKey *key)
virtual KeyPtr GetDBRequestKey() const
Properties properties_
virtual bool IsLess(const DBEntry &rhs) const
IFMapNode * ifmap_node()
IFMapDependencyManager::IFMapNodePtr ifmap_node_state_ref_
virtual std::string ToString() const
void SetIFMapNodeState(IFMapDependencyManager::IFMapNodePtr ref)
boost::uuids::uuid ToId() const
boost::uuids::uuid vmi_inside
boost::uuids::uuid instance_id
boost::uuids::uuid vmi_management
std::string DiffString(const Properties &rhs) const
int CompareTo(const Properties &rhs) const
std::vector< autogen::KeyValuePair > instance_kvps
boost::uuids::uuid vmi_outside
const std::string & ServiceTypeString() const
std::string IdToCmdLineStr() const
boost::uuids::uuid uuid