Line data Source code
1 : /*
2 : * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
3 : */
4 :
5 : #ifndef _ROOT_PORT_IPC_HANDLER_H_
6 : #define _ROOT_PORT_IPC_HANDLER_H_
7 :
8 : #include <string>
9 : #include <rapidjson/document.h>
10 : #include <base/timer.h>
11 : #include <base/address.h>
12 : #include <port_ipc/config_stale_cleaner.h>
13 : #include <vgw/cfg_vgw.h>
14 :
15 : class Agent;
16 : class PortSubscribeTable;
17 : class PortSubscribeEntry;
18 : class VmiSubscribeEntry;
19 : class VmVnPortSubscribeEntry;
20 : typedef boost::shared_ptr<PortSubscribeEntry> PortSubscribeEntryPtr;
21 : typedef std::vector<PortSubscribeEntryPtr> VmiSubscribeEntryPtrList;
22 :
23 : class PortIpcHandler {
24 : public:
25 : static const std::string kPortsDir;
26 :
27 : PortIpcHandler(Agent *agent, const std::string &dir);
28 : virtual ~PortIpcHandler();
29 :
30 : void InitDone();
31 : void Shutdown();
32 : void ReloadAllPorts(const std::string &dir, bool check_port,
33 : bool vm_vn_port);
34 : void ReloadAllPorts(bool check_port);
35 : void SyncHandler();
36 :
37 1 : InterfaceConfigStaleCleaner *interface_stale_cleaner() const {
38 1 : return interface_stale_cleaner_.get();
39 : }
40 :
41 : bool AddPortArrayFromJson(const contrail_rapidjson::Value &d,
42 : const std::string &json,
43 : VmiSubscribeEntryPtrList &req_list,
44 : bool check_port, std::string &err_msg);
45 : bool AddPortFromJson(const string &json, bool check_port, string &err_msg,
46 : bool write_file);
47 : bool DeletePort(const string &url, string &err_msg);
48 : void DeleteVmiUuidEntry(const boost::uuids::uuid &u, std::string &err_str);
49 : bool GetPortInfo(const std::string &uuid_str, std::string &info) const;
50 : bool AddVgwFromJson(const std::string &json, std::string &err_msg) const;
51 : bool DelVgwFromJson(const std::string &json, std::string &err_msg) const;
52 : std::string MakeVmiUuidJson(const VmiSubscribeEntry *entry,
53 : bool meta_info) const;
54 : bool EnablePort(const string &url, string &err_msg);
55 : bool DisablePort(const string &url, string &err_msg);
56 :
57 : // VM+Vn message handlers
58 : bool AddVmVnPort(const std::string &json, bool check_port,
59 : std::string &err_msg, bool write_file);
60 : bool DeleteVmVnPort(const boost::uuids::uuid &vmi_uuid, string &err_msg);
61 : bool DeleteVmVnPort(const std::string &json, const std::string &vm,
62 : string &err_msg);
63 : bool GetVmVnPort(const std::string &vm_uuid, const std::string &vmi_uuid,
64 : std::string &info) const;
65 : bool GetVmVnCfgPort(const string &vm, string &info) const;
66 :
67 :
68 : boost::uuids::uuid VmVnToVmi(const boost::uuids::uuid &vm_uuid) const;
69 : bool MakeJsonFromVmi(const boost::uuids::uuid &vmi_uuid,
70 : std::string &resp) const;
71 : bool MakeJsonFromVmiConfig(const boost::uuids::uuid &vmi_uuid,
72 : string &resp) const;
73 167 : PortSubscribeTable *port_subscribe_table() const {
74 167 : return port_subscribe_table_.get();
75 : }
76 : private:
77 : friend class PortIpcTest;
78 : bool InterfaceExists(const std::string &name) const;
79 :
80 : VmiSubscribeEntry *MakeAddVmiUuidRequest(const contrail_rapidjson::Value &d,
81 : bool check_port,
82 : std::string &err_msg) const;
83 :
84 : VmVnPortSubscribeEntry *MakeAddVmVnPortRequest(const contrail_rapidjson::Value &d,
85 : bool check_port,
86 : std::string &err_msg) const;
87 :
88 : bool BuildGateway(const contrail_rapidjson::Value &d, const std::string &json,
89 : std::string &err_msg, VirtualGatewayInfo *req) const;
90 : bool HasAllGatewayFields(const contrail_rapidjson::Value &d,
91 : std::string &member_err,
92 : VirtualGatewayInfo *req) const;
93 : bool ValidGatewayJsonString(const contrail_rapidjson::Value &d,
94 : VirtualGatewayConfig::SubnetList *list) const;
95 : bool BuildGatewayArrayElement(const contrail_rapidjson::Value &d,
96 : VirtualGatewayConfig::Subnet *entry) const;
97 :
98 : bool AddVmiUuidEntry(PortSubscribeEntryPtr entry, const contrail_rapidjson::Value &d,
99 : bool write_file, std::string &err_msg) const;
100 : bool AddVmVnPortEntry(PortSubscribeEntryPtr entry,
101 : const contrail_rapidjson::Value &d, bool write_file,
102 : std::string &err_msg) const;
103 :
104 : bool ValidateMac(const std::string &mac) const;
105 : bool IsUUID(const std::string &uuid_str) const;
106 : void ProcessFile(const std::string &file, bool check_port, bool vm_vn_port);
107 : void AddMember(const char *key, const char *value,
108 : contrail_rapidjson::Document *doc) const;
109 : bool WriteJsonToFile(VmiSubscribeEntry *entry, bool overwrite) const;
110 : bool WriteJsonToFile(VmVnPortSubscribeEntry *entry) const;
111 :
112 : void MakeVmVnPortJson(const VmVnPortSubscribeEntry *entry, string &info,
113 : bool meta_info) const;
114 :
115 : Agent *agent_;
116 : std::string ports_dir_;
117 : std::string vmvn_dir_;
118 : int version_;
119 : boost::scoped_ptr<InterfaceConfigStaleCleaner> interface_stale_cleaner_;
120 : std::unique_ptr<PortSubscribeTable> port_subscribe_table_;
121 :
122 : DISALLOW_COPY_AND_ASSIGN(PortIpcHandler);
123 : };
124 : #endif // _ROOT_PORT_IPC_HANDLER_H_
|