system: Implement network files generator from ietf-interfaces
Add a systemd-networkd files network files generator according to the
data in startup/running datastore in the ietf-interfaces model.
The IETFInterfaces class appeared (to me) a little bit too complex when
the systemd-networkd config files generator was added. Therefore I have
added the generator into IETFInterfacesConfig class and the
IETFInterfaces class handles only operational data (current status of
the network). Further, we can instantiate IETFInterfacesConfig twice
with different sessions (running, startup) and keep things little bit
simpler than if we pass two types of sessions, config directories,
reload callbacks, etc.
So far, we generate a static config. The interface is always a slave to
master br0. Only the description can vary.
Change-Id: I864df44549bb4189f2bc6d412efe501c83381369
diff --git a/src/system/IETFInterfacesConfig.h b/src/system/IETFInterfacesConfig.h
new file mode 100644
index 0000000..6ba54c3
--- /dev/null
+++ b/src/system/IETFInterfacesConfig.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2021 CESNET, https://photonics.cesnet.cz/
+ *
+ * Written by Tomáš Pecka <tomas.pecka@cesnet.cz>
+ *
+ */
+#pragma once
+
+#include <filesystem>
+#include <sysrepo-cpp/Session.hpp>
+#include "utils/log-fwd.h"
+
+namespace velia::system {
+
+class Rtnetlink;
+
+class IETFInterfacesConfig {
+public:
+ using reload_cb_t = std::function<void(const std::vector<std::string>&)>;
+ explicit IETFInterfacesConfig(std::shared_ptr<::sysrepo::Session> srSess, std::filesystem::path configDirectory, std::vector<std::string> managedLinks, reload_cb_t reloadCallback);
+
+private:
+ velia::Log m_log;
+ reload_cb_t m_reloadCb;
+ std::filesystem::path m_configDirectory;
+ std::vector<std::string> m_managedLinks;
+ std::shared_ptr<::sysrepo::Session> m_srSession;
+ std::shared_ptr<::sysrepo::Subscribe> m_srSubscribe;
+
+ int moduleChange(std::shared_ptr<::sysrepo::Session> session) const;
+ std::vector<std::string> updateNetworkFiles(const std::map<std::string, std::string>& networkConfig, const std::filesystem::path& configDir) const;
+};
+}