Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 1 | /* |
| 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át | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 11 | #include <set> |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 12 | #include <unordered_map> |
| 13 | #include "ast_path.hpp" |
| 14 | #include "schema.hpp" |
| 15 | |
Václav Kubernát | ff45f31 | 2019-10-09 12:45:27 +0200 | [diff] [blame] | 16 | namespace yang { |
| 17 | enum class ContainerTraits { |
| 18 | Presence, |
| 19 | None, |
| 20 | }; |
| 21 | |
| 22 | struct container { |
| 23 | yang::ContainerTraits m_presence; |
| 24 | }; |
| 25 | struct list { |
| 26 | std::set<std::string> m_keys; |
| 27 | }; |
| 28 | |
| 29 | struct leaf { |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 30 | yang::TypeInfo m_type; |
Václav Kubernát | ff45f31 | 2019-10-09 12:45:27 +0200 | [diff] [blame] | 31 | }; |
| 32 | |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 33 | struct leaflist { |
| 34 | yang::TypeInfo m_type; |
| 35 | }; |
| 36 | |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 37 | struct rpc { |
| 38 | }; |
| 39 | |
Václav Kubernát | ff45f31 | 2019-10-09 12:45:27 +0200 | [diff] [blame] | 40 | struct module { |
| 41 | }; |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 42 | |
| 43 | enum class AccessType { |
| 44 | Writable, |
| 45 | ReadOnly |
| 46 | }; |
Václav Kubernát | ff45f31 | 2019-10-09 12:45:27 +0200 | [diff] [blame] | 47 | } |
| 48 | |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 49 | using NodeType = std::variant<yang::container, yang::list, yang::leaf, yang::leaflist, yang::rpc>; |
Václav Kubernát | ff45f31 | 2019-10-09 12:45:27 +0200 | [diff] [blame] | 50 | |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 51 | struct NodeInfo { |
| 52 | NodeType m_nodeType; |
| 53 | yang::AccessType m_configType; |
| 54 | }; |
| 55 | |
Václav Kubernát | ff45f31 | 2019-10-09 12:45:27 +0200 | [diff] [blame] | 56 | |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 57 | /*! \class StaticSchema |
| 58 | * \brief Static schema, used mainly for testing |
| 59 | * */ |
| 60 | |
| 61 | class StaticSchema : public Schema { |
| 62 | public: |
| 63 | StaticSchema(); |
| 64 | |
Václav Kubernát | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 65 | yang::NodeTypes nodeType(const std::string& path) const override; |
| 66 | yang::NodeTypes nodeType(const schemaPath_& location, const ModuleNodePair& node) const override; |
Václav Kubernát | 75877de | 2019-11-20 17:43:02 +0100 | [diff] [blame] | 67 | bool isModule(const std::string& name) const override; |
Václav Kubernát | 2db124c | 2020-05-28 21:58:36 +0200 | [diff] [blame] | 68 | bool listHasKey(const schemaPath_& listPath, const std::string& key) const override; |
Václav Kubernát | c386679 | 2020-02-20 14:12:56 +0100 | [diff] [blame] | 69 | bool leafIsKey(const std::string& leafPath) const override; |
Václav Kubernát | 0599e9f | 2020-04-21 09:51:33 +0200 | [diff] [blame] | 70 | bool isConfig(const std::string& leafPath) const override; |
Václav Kubernát | b1a75c6 | 2020-04-21 15:20:16 +0200 | [diff] [blame] | 71 | std::optional<std::string> defaultValue(const std::string& leafPath) const override; |
Václav Kubernát | 2db124c | 2020-05-28 21:58:36 +0200 | [diff] [blame] | 72 | const std::set<std::string> listKeys(const schemaPath_& listPath) const override; |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 73 | yang::TypeInfo leafType(const schemaPath_& location, const ModuleNodePair& node) const override; |
| 74 | yang::TypeInfo leafType(const std::string& path) const override; |
Václav Kubernát | 6fcd028 | 2020-02-21 16:33:08 +0100 | [diff] [blame] | 75 | std::optional<std::string> leafTypeName(const std::string& path) const override; |
Václav Kubernát | bd5e3c2 | 2020-02-19 15:22:00 +0100 | [diff] [blame] | 76 | std::string leafrefPath(const std::string& leafrefPath) const override; |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 77 | std::set<ModuleNodePair> availableNodes(const boost::variant<dataPath_, schemaPath_, module_>& path, const Recursion recursion) const override; |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 78 | std::optional<std::string> description(const std::string& path) const override; |
Václav Kubernát | a1c4c9e | 2020-04-22 00:37:52 +0200 | [diff] [blame] | 79 | yang::Status status(const std::string& location) const override; |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 80 | |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 81 | /** A helper for making tests a little bit easier. It returns all |
| 82 | * identities which are based on the argument passed and which can then be |
| 83 | * used in addLeaf for the `type` argument */ |
| 84 | std::set<identityRef_> validIdentities(std::string_view module, std::string_view value); |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 85 | void addContainer(const std::string& location, const std::string& name, yang::ContainerTraits isPresence = yang::ContainerTraits::None); |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 86 | void addLeaf(const std::string& location, const std::string& name, const yang::LeafDataType& type, const yang::AccessType accessType = yang::AccessType::Writable); |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 87 | void addLeafList(const std::string& location, const std::string& name, const yang::LeafDataType& type); |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 88 | void addList(const std::string& location, const std::string& name, const std::set<std::string>& keys); |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 89 | void addRpc(const std::string& location, const std::string& name); |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 90 | void addModule(const std::string& name); |
Václav Kubernát | 222ecff | 2020-05-14 23:14:35 +0200 | [diff] [blame] | 91 | void addIdentity(const std::optional<identityRef_>& base, const identityRef_& name); |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 92 | |
| 93 | private: |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 94 | const std::unordered_map<std::string, NodeInfo>& children(const std::string& name) const; |
Václav Kubernát | 222ecff | 2020-05-14 23:14:35 +0200 | [diff] [blame] | 95 | void getIdentSet(const identityRef_& ident, std::set<identityRef_>& res) const; |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 96 | |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 97 | std::unordered_map<std::string, std::unordered_map<std::string, NodeInfo>> m_nodes; |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 98 | std::set<std::string> m_modules; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 99 | |
Václav Kubernát | 222ecff | 2020-05-14 23:14:35 +0200 | [diff] [blame] | 100 | std::map<identityRef_, std::set<identityRef_>> m_identities; |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 101 | }; |