LCOV - code coverage report
Current view: top level - vnsw/agent/oper - service_instance.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 0 20 0.0 %
Date: 2026-06-18 01:51:13 Functions: 0 8 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14