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