Add originator id & type for user trigerred dumps

The LogEntry schema has the below properties to store the
originator (or the source) of the dump log entry and type of
originator data:
  * Originator
  * OriginatorType

The above properties are used for all the user trigerred dumps,
where ip of the dump originator will be stored in the originatorId
field. The same is stored in the backend (phosphor-debug-collector).

phosphor-debug-collector orchestrates the collection and offload of
dumps. It now implements the OriginatedBy interface for dumps. The below
change is upstreamed:
[1] https://gerrit.openbmc.org/c/openbmc/phosphor-debug-collector/+/48337

Reference:
[1] https://redfish.dmtf.org/schemas/v1/LogEntry_v1.xml

Redfish Validator passed.

Tested By:
* Created bmc dump
* Get on the created bmc dump lists the newly added properties in
  the redfish response

Signed-off-by: Asmitha Karunanithi <asmitk01@in.ibm.com>
Change-Id: I473eabb81db7511f064904120992ed5449d323e5
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index 34625d3..f2a5722 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -18,6 +18,7 @@
 #include "app.hpp"
 #include "dbus_utility.hpp"
 #include "error_messages.hpp"
+#include "generated/enums/log_entry.hpp"
 #include "gzfile.hpp"
 #include "http_utility.hpp"
 #include "human_sort.hpp"
@@ -308,9 +309,31 @@
     return !redfishLogFiles.empty();
 }
 
+inline log_entry::OriginatorTypes
+    mapDbusOriginatorTypeToRedfish(const std::string& originatorType)
+{
+    if (originatorType ==
+        "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client")
+    {
+        return log_entry::OriginatorTypes::Client;
+    }
+    if (originatorType ==
+        "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Internal")
+    {
+        return log_entry::OriginatorTypes::Internal;
+    }
+    if (originatorType ==
+        "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.SupportingService")
+    {
+        return log_entry::OriginatorTypes::SupportingService;
+    }
+    return log_entry::OriginatorTypes::Invalid;
+}
+
 inline void parseDumpEntryFromDbusObject(
     const dbus::utility::ManagedObjectType::value_type& object,
     std::string& dumpStatus, uint64_t& size, uint64_t& timestampUs,
+    std::string& originatorId, log_entry::OriginatorTypes& originatorType,
     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
 {
     for (const auto& interfaceMap : object.second)
@@ -368,6 +391,42 @@
                 }
             }
         }
+        else if (interfaceMap.first ==
+                 "xyz.openbmc_project.Common.OriginatedBy")
+        {
+            for (const auto& propertyMap : interfaceMap.second)
+            {
+                if (propertyMap.first == "OriginatorId")
+                {
+                    const std::string* id =
+                        std::get_if<std::string>(&propertyMap.second);
+                    if (id == nullptr)
+                    {
+                        messages::internalError(asyncResp->res);
+                        break;
+                    }
+                    originatorId = *id;
+                }
+
+                if (propertyMap.first == "OriginatorType")
+                {
+                    const std::string* type =
+                        std::get_if<std::string>(&propertyMap.second);
+                    if (type == nullptr)
+                    {
+                        messages::internalError(asyncResp->res);
+                        break;
+                    }
+
+                    originatorType = mapDbusOriginatorTypeToRedfish(*type);
+                    if (originatorType == log_entry::OriginatorTypes::Invalid)
+                    {
+                        messages::internalError(asyncResp->res);
+                        break;
+                    }
+                }
+            }
+        }
     }
 }
 
@@ -453,6 +512,9 @@
             uint64_t timestampUs = 0;
             uint64_t size = 0;
             std::string dumpStatus;
+            std::string originatorId;
+            log_entry::OriginatorTypes originatorType =
+                log_entry::OriginatorTypes::Internal;
             nlohmann::json::object_t thisEntry;
 
             std::string entryID = object.first.filename();
@@ -462,6 +524,7 @@
             }
 
             parseDumpEntryFromDbusObject(object, dumpStatus, size, timestampUs,
+                                         originatorId, originatorType,
                                          asyncResp);
 
             if (dumpStatus !=
@@ -472,7 +535,7 @@
                 continue;
             }
 
-            thisEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
+            thisEntry["@odata.type"] = "#LogEntry.v1_11_0.LogEntry";
             thisEntry["@odata.id"] = entriesPath + entryID;
             thisEntry["Id"] = entryID;
             thisEntry["EntryType"] = "Event";
@@ -480,6 +543,12 @@
             thisEntry["Created"] =
                 redfish::time_utils::getDateTimeUintUs(timestampUs);
 
+            if (!originatorId.empty())
+            {
+                thisEntry["Originator"] = originatorId;
+                thisEntry["OriginatorType"] = originatorType;
+            }
+
             if (dumpType == "BMC")
             {
                 thisEntry["DiagnosticDataType"] = "Manager";
@@ -541,9 +610,13 @@
             uint64_t timestampUs = 0;
             uint64_t size = 0;
             std::string dumpStatus;
+            std::string originatorId;
+            log_entry::OriginatorTypes originatorType =
+                log_entry::OriginatorTypes::Internal;
 
             parseDumpEntryFromDbusObject(objectPath, dumpStatus, size,
-                                         timestampUs, asyncResp);
+                                         timestampUs, originatorId,
+                                         originatorType, asyncResp);
 
             if (dumpStatus !=
                     "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" &&
@@ -557,7 +630,7 @@
             }
 
             asyncResp->res.jsonValue["@odata.type"] =
-                "#LogEntry.v1_9_0.LogEntry";
+                "#LogEntry.v1_11_0.LogEntry";
             asyncResp->res.jsonValue["@odata.id"] = entriesPath + entryID;
             asyncResp->res.jsonValue["Id"] = entryID;
             asyncResp->res.jsonValue["EntryType"] = "Event";
@@ -565,6 +638,12 @@
             asyncResp->res.jsonValue["Created"] =
                 redfish::time_utils::getDateTimeUintUs(timestampUs);
 
+            if (!originatorId.empty())
+            {
+                asyncResp->res.jsonValue["Originator"] = originatorId;
+                asyncResp->res.jsonValue["OriginatorType"] = originatorType;
+            }
+
             if (dumpType == "BMC")
             {
                 asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager";
@@ -867,6 +946,13 @@
     std::vector<std::pair<std::string, std::variant<std::string, uint64_t>>>
         createDumpParamVec;
 
+    createDumpParamVec.emplace_back(
+        "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorId",
+        req.session->clientIp);
+    createDumpParamVec.emplace_back(
+        "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorType",
+        "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client");
+
     crow::connections::systemBus->async_method_call(
         [asyncResp, payload(task::Payload(req)),
          dumpPath](const boost::system::error_code& ec,