Add network static gateway configuration support

This commit enables static gateway configuration on EthernetInterface
Implements CreateStaticGateway method which creates a new d-bus object
with StaticGateway interface.

Tested By:
Run StaticGateway D-bus method and verified D-bus object and
configuration.
Delete StaticGateway object
Add static gateway
Delete static gateway

Change-Id: I3fbc6f85ede00b6c1949a0ac85f501037a69c831
Signed-off-by: Ravi Teja <raviteja28031990@gmail.com>
diff --git a/src/static_gateway.cpp b/src/static_gateway.cpp
new file mode 100644
index 0000000..f1e9db4
--- /dev/null
+++ b/src/static_gateway.cpp
@@ -0,0 +1,77 @@
+#include "static_gateway.hpp"
+
+#include "ethernet_interface.hpp"
+#include "network_manager.hpp"
+
+#include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/elog.hpp>
+#include <xyz/openbmc_project/Common/error.hpp>
+
+#include <string>
+
+namespace phosphor
+{
+namespace network
+{
+
+static auto makeObjPath(std::string_view root, std::string addr)
+{
+    auto ret = sdbusplus::message::object_path(std::string(root));
+    ret /= addr;
+    return ret;
+}
+
+StaticGateway::StaticGateway(sdbusplus::bus_t& bus, std::string_view objRoot,
+                             stdplus::PinnedRef<EthernetInterface> parent,
+                             std::string gateway, IP::Protocol protocolType) :
+    StaticGateway(bus, makeObjPath(objRoot, gateway), parent, gateway,
+                  protocolType)
+{}
+
+StaticGateway::StaticGateway(sdbusplus::bus_t& bus,
+                             sdbusplus::message::object_path objPath,
+                             stdplus::PinnedRef<EthernetInterface> parent,
+                             std::string gateway, IP::Protocol protocolType) :
+    StaticGatewayObj(bus, objPath.str.c_str(),
+                     StaticGatewayObj::action::defer_emit),
+    parent(parent), objPath(std::move(objPath))
+{
+    StaticGatewayObj::gateway(gateway, true);
+    StaticGatewayObj::protocolType(protocolType, true);
+    emit_object_added();
+}
+
+void StaticGateway::delete_()
+{
+    auto& staticGateways = parent.get().staticGateways;
+    std::unique_ptr<StaticGateway> ptr;
+    for (auto it = staticGateways.begin(); it != staticGateways.end(); ++it)
+    {
+        if (it->second.get() == this)
+        {
+            ptr = std::move(it->second);
+            staticGateways.erase(it);
+            break;
+        }
+    }
+
+    parent.get().writeConfigurationFile();
+    parent.get().manager.get().reloadConfigs();
+}
+
+using sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed;
+using REASON =
+    phosphor::logging::xyz::openbmc_project::Common::NotAllowed::REASON;
+using phosphor::logging::elog;
+
+std::string StaticGateway::gateway(std::string /*gateway*/)
+{
+    elog<NotAllowed>(REASON("Property update is not allowed"));
+}
+
+IP::Protocol StaticGateway::protocolType(IP::Protocol /*protocolType*/)
+{
+    elog<NotAllowed>(REASON("Property update is not allowed"));
+}
+} // namespace network
+} // namespace phosphor