blob: 75a32521dcf3cdddd589186d55a90460a481af0d [file] [log] [blame]
Tom Josephbe703f72017-03-09 12:34:35 +05301#pragma once
William A. Kennington IIIe47fdfb2018-03-15 17:09:28 -07002#include <experimental/optional>
3#include <sdbusplus/server.hpp>
Tom Josephbe703f72017-03-09 12:34:35 +05304
Ratan Guptacc8feb42017-07-25 21:52:10 +05305#include "types.hpp"
Tom Josephbe703f72017-03-09 12:34:35 +05306
7namespace ipmi
8{
9
Ratan Guptacc8feb42017-07-25 21:52:10 +053010constexpr auto MAPPER_BUS_NAME = "xyz.openbmc_project.ObjectMapper";
11constexpr auto MAPPER_OBJ = "/xyz/openbmc_project/object_mapper";
12constexpr auto MAPPER_INTF = "xyz.openbmc_project.ObjectMapper";
13
14constexpr auto ROOT = "/";
15constexpr auto HOST_MATCH = "host0";
Ratan Guptacc8feb42017-07-25 21:52:10 +053016
Ratan Guptab8e99552017-07-27 07:07:48 +053017constexpr auto PROP_INTF = "org.freedesktop.DBus.Properties";
18constexpr auto DELETE_INTERFACE = "xyz.openbmc_project.Object.Delete";
Ratan Guptacc8feb42017-07-25 21:52:10 +053019
20constexpr auto METHOD_GET = "Get";
21constexpr auto METHOD_GET_ALL = "GetAll";
22constexpr auto METHOD_SET = "Set";
23
William A. Kennington IIIe47fdfb2018-03-15 17:09:28 -070024/** @class ServiceCache
25 * @brief Caches lookups of service names from the object mapper.
26 * @details Most ipmi commands need to talk to other dbus daemons to perform
27 * their intended actions on the BMC. This usually means they will
28 * first look up the service name providing the interface they
29 * require. This class reduces the number of such calls by caching
30 * the lookup for a specific service.
31 */
32class ServiceCache {
33 public:
34 /** @brief Creates a new service cache for the given interface
35 * and path.
36 *
37 * @param[in] intf - The interface used for each lookup
38 * @param[in] path - The path used for each lookup
39 */
40 ServiceCache(const std::string& intf, const std::string& path);
41 ServiceCache(std::string&& intf, std::string&& path);
42
43 /** @brief Gets the service name from the cache or does in a
44 * lookup when invalid.
45 *
46 * @param[in] bus - The bus associated with and used for looking
47 * up the service.
48 */
49 const std::string& getService(sdbusplus::bus::bus& bus);
50
51 /** @brief Invalidates the current service name */
52 void invalidate();
53
54 /** @brief A wrapper around sdbusplus bus.new_method_call
55 *
56 * @param[in] bus - The bus used for calling the method
57 * @param[in] intf - The interface containing the method
58 * @param[in] method - The method name
59 * @return The message containing the method call.
60 */
61 sdbusplus::message::message newMethodCall(sdbusplus::bus::bus& bus,
62 const char *intf,
63 const char *method);
William A. Kennington III82c173a2018-05-11 16:10:12 -070064
65 /** @brief Check to see if the current cache is valid
66 *
67 * @param[in] bus - The bus used for the service lookup
68 * @return True if the cache is valid false otherwise.
69 */
70 bool isValid(sdbusplus::bus::bus& bus) const;
William A. Kennington IIIe47fdfb2018-03-15 17:09:28 -070071 private:
72 /** @brief DBUS interface provided by the service */
73 const std::string intf;
74 /** @brief DBUS path provided by the service */
75 const std::string path;
76 /** @brief The name of the service if valid */
77 std::experimental::optional<std::string> cachedService;
78 /** @brief The name of the bus used in the service lookup */
79 std::experimental::optional<std::string> cachedBusName;
William A. Kennington IIIe47fdfb2018-03-15 17:09:28 -070080};
81
Tom Josephbe703f72017-03-09 12:34:35 +053082/**
83 * @brief Get the DBUS Service name for the input dbus path
84 *
85 * @param[in] bus - DBUS Bus Object
86 * @param[in] intf - DBUS Interface
87 * @param[in] path - DBUS Object Path
88 *
89 */
90std::string getService(sdbusplus::bus::bus& bus,
91 const std::string& intf,
92 const std::string& path);
Ratan Guptacc8feb42017-07-25 21:52:10 +053093
94/** @brief Gets the dbus object info implementing the given interface
95 * from the given subtree.
Ratan Gupta01d4bd12017-08-07 15:53:25 +053096 * @param[in] bus - DBUS Bus Object.
Ratan Guptacc8feb42017-07-25 21:52:10 +053097 * @param[in] interface - Dbus interface.
98 * @param[in] subtreePath - subtree from where the search should start.
99 * @param[in] match - identifier for object.
100 * @return On success returns the object having objectpath and servicename.
101 */
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530102DbusObjectInfo getDbusObject(sdbusplus::bus::bus& bus,
103 const std::string& interface,
Ratan Guptacc8feb42017-07-25 21:52:10 +0530104 const std::string& subtreePath = ROOT,
105 const std::string& match = {});
106
Ratan Guptadd646202017-11-21 17:46:59 +0530107/** @brief Get the ipObject of first dbus IP object of Non-LinkLocalIPAddress
Gunnar Mills8991dd62017-10-25 17:11:29 -0500108 * type from the given subtree, if not available gets IP object of
Nagaraju Goruganti1fe5c832017-09-21 07:44:17 -0500109 * LinkLocalIPAddress type.
110 * @param[in] bus - DBUS Bus Object.
111 * @param[in] interface - Dbus interface.
112 * @param[in] subtreePath - subtree from where the search should start.
113 * @param[in] match - identifier for object.
Ratan Guptadd646202017-11-21 17:46:59 +0530114 * @return On success returns the object having objectpath and servicename.
Nagaraju Goruganti1fe5c832017-09-21 07:44:17 -0500115 */
Ratan Guptadd646202017-11-21 17:46:59 +0530116DbusObjectInfo getIPObject(sdbusplus::bus::bus& bus,
117 const std::string& interface,
118 const std::string& subtreePath,
119 const std::string& match);
Nagaraju Goruganti1fe5c832017-09-21 07:44:17 -0500120
Ratan Guptacc8feb42017-07-25 21:52:10 +0530121/** @brief Gets the value associated with the given object
122 * and the interface.
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530123 * @param[in] bus - DBUS Bus Object.
Ratan Guptacc8feb42017-07-25 21:52:10 +0530124 * @param[in] service - Dbus service name.
125 * @param[in] objPath - Dbus object path.
126 * @param[in] interface - Dbus interface.
127 * @param[in] property - name of the property.
128 * @return On success returns the value of the property.
129 */
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530130Value getDbusProperty(sdbusplus::bus::bus& bus,
131 const std::string& service,
Ratan Guptacc8feb42017-07-25 21:52:10 +0530132 const std::string& objPath,
133 const std::string& interface,
134 const std::string& property);
135
136/** @brief Gets all the properties associated with the given object
137 * and the interface.
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530138 * @param[in] bus - DBUS Bus Object.
Ratan Guptacc8feb42017-07-25 21:52:10 +0530139 * @param[in] service - Dbus service name.
140 * @param[in] objPath - Dbus object path.
141 * @param[in] interface - Dbus interface.
142 * @return On success returns the map of name value pair.
143 */
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530144PropertyMap getAllDbusProperties(sdbusplus::bus::bus& bus,
145 const std::string& service,
Ratan Guptacc8feb42017-07-25 21:52:10 +0530146 const std::string& objPath,
147 const std::string& interface);
148
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600149/** @brief Gets all managed objects associated with the given object
150 * path and service.
151 * @param[in] bus - D-Bus Bus Object.
152 * @param[in] service - D-Bus service name.
153 * @param[in] objPath - D-Bus object path.
154 * @return On success returns the map of name value pair.
155 */
156ObjectValueTree getManagedObjects(sdbusplus::bus::bus& bus,
157 const std::string& service,
158 const std::string& objPath);
159
Ratan Guptacc8feb42017-07-25 21:52:10 +0530160/** @brief Sets the property value of the given object.
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530161 * @param[in] bus - DBUS Bus Object.
Ratan Guptacc8feb42017-07-25 21:52:10 +0530162 * @param[in] service - Dbus service name.
163 * @param[in] objPath - Dbus object path.
164 * @param[in] interface - Dbus interface.
165 * @param[in] property - name of the property.
166 * @param[in] value - value which needs to be set.
167 */
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530168void setDbusProperty(sdbusplus::bus::bus& bus,
169 const std::string& service,
Ratan Guptacc8feb42017-07-25 21:52:10 +0530170 const std::string& objPath,
171 const std::string& interface,
172 const std::string& property,
173 const Value& value);
174
Ratan Guptab8e99552017-07-27 07:07:48 +0530175/** @brief Gets all the dbus objects from the given service root
176 * which matches the object identifier.
177 * @param[in] bus - DBUS Bus Object.
178 * @param[in] serviceRoot - Service root path.
179 * @param[in] interface - Dbus interface.
180 * @param[in] match - Identifier for a path.
181 * @returns map of object path and service info.
182 */
183ObjectTree getAllDbusObjects(sdbusplus::bus::bus& bus,
184 const std::string& serviceRoot,
185 const std::string& interface,
Vernon Mauery6f2c8cd2018-07-28 06:40:39 -0700186 const std::string& match = {});
Ratan Guptab8e99552017-07-27 07:07:48 +0530187
188/** @brief Deletes all the dbus objects from the given service root
189 which matches the object identifier.
190 * @param[in] bus - DBUS Bus Object.
191 * @param[in] serviceRoot - Service root path.
192 * @param[in] interface - Dbus interface.
193 * @param[in] match - Identifier for object.
194 */
195void deleteAllDbusObjects(sdbusplus::bus::bus& bus,
196 const std::string& serviceRoot,
197 const std::string& interface,
198 const std::string& match = {});
199
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530200/** @brief Gets the ancestor objects of the given object
201 which implements the given interface.
202 * @param[in] bus - Dbus bus object.
203 * @param[in] path - Child Dbus object path.
204 * @param[in] interfaces - Dbus interface list.
205 * @return map of object path and service info.
206 */
207ObjectTree getAllAncestors(sdbusplus::bus::bus& bus,
208 const std::string& path,
209 InterfaceList&& interfaces);
210
Ratan Guptab8e99552017-07-27 07:07:48 +0530211namespace method_no_args
212{
213
214/** @brief Calls the Dbus method which waits for response.
215 * @param[in] bus - DBUS Bus Object.
216 * @param[in] service - Dbus service name.
217 * @param[in] objPath - Dbus object path.
218 * @param[in] interface - Dbus interface.
219 * @param[in] method - Dbus method.
220 */
221void callDbusMethod(sdbusplus::bus::bus& bus,
222 const std::string& service,
223 const std::string& objPath,
224 const std::string& interface,
225 const std::string& method);
226
227} //namespace method_no_args
228
229namespace network
230{
231
232constexpr auto ROOT = "/xyz/openbmc_project/network";
Ratan Gupta533d03b2017-07-30 10:39:22 +0530233constexpr auto SERVICE = "xyz.openbmc_project.Network";
Ratan Guptab8e99552017-07-27 07:07:48 +0530234constexpr auto IP_TYPE = "ipv4";
Nagaraju Goruganti1fe5c832017-09-21 07:44:17 -0500235constexpr auto IPV4_PREFIX = "169.254";
236constexpr auto IPV6_PREFIX = "fe80";
Ratan Guptab8e99552017-07-27 07:07:48 +0530237constexpr auto IP_INTERFACE = "xyz.openbmc_project.Network.IP";
238constexpr auto MAC_INTERFACE = "xyz.openbmc_project.Network.MACAddress";
239constexpr auto SYSTEMCONFIG_INTERFACE = "xyz.openbmc_project.Network.SystemConfiguration";
240constexpr auto ETHERNET_INTERFACE = "xyz.openbmc_project.Network.EthernetInterface";
241constexpr auto IP_CREATE_INTERFACE = "xyz.openbmc_project.Network.IP.Create";
Ratan Gupta533d03b2017-07-30 10:39:22 +0530242constexpr auto VLAN_CREATE_INTERFACE = "xyz.openbmc_project.Network.VLAN.Create";
243constexpr auto VLAN_INTERFACE = "xyz.openbmc_project.Network.VLAN";
Ratan Guptab8e99552017-07-27 07:07:48 +0530244
245/* @brief converts the given subnet into prefix notation.
246 * @param[in] addressFamily - IP address family(AF_INET/AF_INET6).
247 * @param[in] mask - Subnet Mask.
248 * @returns prefix.
249 */
250uint8_t toPrefix(int addressFamily, const std::string& subnetMask);
251
252
253/** @brief Sets the ip on the system.
254 * @param[in] bus - DBUS Bus Object.
255 * @param[in] service - Dbus service name.
256 * @param[in] objPath - Dbus object path.
257 * @param[in] protocolType - Protocol type
258 * @param[in] ipaddress - IPaddress.
259 * @param[in] prefix - Prefix length.
260 */
261void createIP(sdbusplus::bus::bus& bus,
262 const std::string& service,
263 const std::string& objPath,
264 const std::string& protocolType,
265 const std::string& ipaddress,
266 uint8_t prefix);
267
Ratan Gupta533d03b2017-07-30 10:39:22 +0530268/** @brief Creates the VLAN on the given interface.
269 * @param[in] bus - DBUS Bus Object.
270 * @param[in] service - Dbus service name.
271 * @param[in] objPath - Dbus object path.
272 * @param[in] interface - EthernetInterface.
273 * @param[in] vlanID - Vlan ID.
274 */
275void createVLAN(sdbusplus::bus::bus& bus,
276 const std::string& service,
277 const std::string& objPath,
278 const std::string& interface,
279 uint32_t vlanID);
Ratan Guptab8e99552017-07-27 07:07:48 +0530280
Ratan Gupta533d03b2017-07-30 10:39:22 +0530281/** @brief Gets the vlan id from the given object path.
282 * @param[in] path - Dbus object path.
283 */
284uint32_t getVLAN(const std::string& path);
285
286} //namespace network
Tom Josephbe703f72017-03-09 12:34:35 +0530287} // namespace ipmi
288
289