blob: 3009d7ebc72b496ec711f14d7c691245efaf290d [file] [log] [blame]
Václav Kubernátbddbb172018-06-13 16:27:39 +02001/*
2 * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/
3 * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/
4 *
5 * Written by Václav Kubernát <kubervac@fit.cvut.cz>
6 *
7*/
8
9#pragma once
10
Václav Kubernátbddbb172018-06-13 16:27:39 +020011#include <set>
Václav Kubernátbddbb172018-06-13 16:27:39 +020012#include <unordered_map>
13#include "ast_path.hpp"
14#include "schema.hpp"
15
Václav Kubernátff45f312019-10-09 12:45:27 +020016namespace yang {
17enum class ContainerTraits {
18 Presence,
19 None,
20};
21
22struct container {
23 yang::ContainerTraits m_presence;
24};
25struct list {
26 std::set<std::string> m_keys;
27};
28
29struct leaf {
Václav Kubernát13b23d72020-04-16 21:49:51 +020030 yang::TypeInfo m_type;
Václav Kubernátff45f312019-10-09 12:45:27 +020031};
32
Václav Kubernát5b8a8f32020-05-20 00:57:22 +020033struct leaflist {
34 yang::TypeInfo m_type;
35};
36
Václav Kubernáte7248b22020-06-26 15:38:59 +020037struct rpc {
38};
39
Václav Kubernát3d787b12020-10-29 09:11:26 +010040struct action {
41};
42
Václav Kubernátff45f312019-10-09 12:45:27 +020043struct module {
44};
Václav Kubernátabf52802020-05-19 01:31:17 +020045
46enum class AccessType {
47 Writable,
48 ReadOnly
49};
Václav Kubernátff45f312019-10-09 12:45:27 +020050}
51
Václav Kubernát3d787b12020-10-29 09:11:26 +010052using NodeType = std::variant<yang::container, yang::list, yang::leaf, yang::leaflist, yang::rpc, yang::action>;
Václav Kubernátff45f312019-10-09 12:45:27 +020053
Václav Kubernátabf52802020-05-19 01:31:17 +020054struct NodeInfo {
55 NodeType m_nodeType;
56 yang::AccessType m_configType;
57};
58
Václav Kubernátff45f312019-10-09 12:45:27 +020059
Václav Kubernátbddbb172018-06-13 16:27:39 +020060/*! \class StaticSchema
61 * \brief Static schema, used mainly for testing
62 * */
63
64class StaticSchema : public Schema {
65public:
66 StaticSchema();
67
Václav Kubernát34ee85a2020-02-18 17:12:12 +010068 yang::NodeTypes nodeType(const std::string& path) const override;
69 yang::NodeTypes nodeType(const schemaPath_& location, const ModuleNodePair& node) const override;
Václav Kubernát75877de2019-11-20 17:43:02 +010070 bool isModule(const std::string& name) const override;
Václav Kubernát2db124c2020-05-28 21:58:36 +020071 bool listHasKey(const schemaPath_& listPath, const std::string& key) const override;
Václav Kubernátc3866792020-02-20 14:12:56 +010072 bool leafIsKey(const std::string& leafPath) const override;
Václav Kubernát0599e9f2020-04-21 09:51:33 +020073 bool isConfig(const std::string& leafPath) const override;
Václav Kubernátb1a75c62020-04-21 15:20:16 +020074 std::optional<std::string> defaultValue(const std::string& leafPath) const override;
Václav Kubernát2db124c2020-05-28 21:58:36 +020075 const std::set<std::string> listKeys(const schemaPath_& listPath) const override;
Václav Kubernát13b23d72020-04-16 21:49:51 +020076 yang::TypeInfo leafType(const schemaPath_& location, const ModuleNodePair& node) const override;
77 yang::TypeInfo leafType(const std::string& path) const override;
Václav Kubernát6fcd0282020-02-21 16:33:08 +010078 std::optional<std::string> leafTypeName(const std::string& path) const override;
Václav Kubernátbd5e3c22020-02-19 15:22:00 +010079 std::string leafrefPath(const std::string& leafrefPath) const override;
Václav Kubernát95b08872020-04-28 01:04:17 +020080 std::set<ModuleNodePair> availableNodes(const boost::variant<dataPath_, schemaPath_, module_>& path, const Recursion recursion) const override;
Václav Kubernát1e09bd62020-02-17 15:13:38 +010081 std::optional<std::string> description(const std::string& path) const override;
Václav Kubernáta1c4c9e2020-04-22 00:37:52 +020082 yang::Status status(const std::string& location) const override;
Václav Kubernátbddbb172018-06-13 16:27:39 +020083
Václav Kubernát3a99f002020-03-31 02:27:41 +020084 /** A helper for making tests a little bit easier. It returns all
85 * identities which are based on the argument passed and which can then be
86 * used in addLeaf for the `type` argument */
87 std::set<identityRef_> validIdentities(std::string_view module, std::string_view value);
Václav Kubernátbddbb172018-06-13 16:27:39 +020088 void addContainer(const std::string& location, const std::string& name, yang::ContainerTraits isPresence = yang::ContainerTraits::None);
Václav Kubernátabf52802020-05-19 01:31:17 +020089 void addLeaf(const std::string& location, const std::string& name, const yang::LeafDataType& type, const yang::AccessType accessType = yang::AccessType::Writable);
Václav Kubernát5b8a8f32020-05-20 00:57:22 +020090 void addLeafList(const std::string& location, const std::string& name, const yang::LeafDataType& type);
Václav Kubernátbddbb172018-06-13 16:27:39 +020091 void addList(const std::string& location, const std::string& name, const std::set<std::string>& keys);
Václav Kubernáte7248b22020-06-26 15:38:59 +020092 void addRpc(const std::string& location, const std::string& name);
Václav Kubernát3d787b12020-10-29 09:11:26 +010093 void addAction(const std::string& location, const std::string& name);
Václav Kubernát744f57f2018-06-29 22:46:26 +020094 void addModule(const std::string& name);
Václav Kubernát222ecff2020-05-14 23:14:35 +020095 void addIdentity(const std::optional<identityRef_>& base, const identityRef_& name);
Václav Kubernátbddbb172018-06-13 16:27:39 +020096
97private:
Václav Kubernátabf52802020-05-19 01:31:17 +020098 const std::unordered_map<std::string, NodeInfo>& children(const std::string& name) const;
Václav Kubernát222ecff2020-05-14 23:14:35 +020099 void getIdentSet(const identityRef_& ident, std::set<identityRef_>& res) const;
Václav Kubernátbddbb172018-06-13 16:27:39 +0200100
Václav Kubernátabf52802020-05-19 01:31:17 +0200101 std::unordered_map<std::string, std::unordered_map<std::string, NodeInfo>> m_nodes;
Václav Kubernát744f57f2018-06-29 22:46:26 +0200102 std::set<std::string> m_modules;
Václav Kubernát3a99f002020-03-31 02:27:41 +0200103
Václav Kubernát222ecff2020-05-14 23:14:35 +0200104 std::map<identityRef_, std::set<identityRef_>> m_identities;
Václav Kubernátbddbb172018-06-13 16:27:39 +0200105};