From 6535523a2768a5c867fd22b4fa62c7fb43fd9ad8 Mon Sep 17 00:00:00 2001 From: imarom Date: Mon, 27 Jun 2016 15:31:00 +0300 Subject: draft #2 for trex client config --- src/trex_client_config.h | 95 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 91 insertions(+), 4 deletions(-) (limited to 'src/trex_client_config.h') diff --git a/src/trex_client_config.h b/src/trex_client_config.h index 27b11836..442d228b 100644 --- a/src/trex_client_config.h +++ b/src/trex_client_config.h @@ -25,6 +25,21 @@ limitations under the License. #include #include +/** + * single client config + * + * @author imarom (27-Jun-16) + */ +class ClientCfg { +public: + uint8_t m_init_mac[6]; + uint16_t m_init_vlan; + + uint8_t m_res_mac[6]; + uint16_t m_res_vlan; + +}; + /** * describes a single client group * configuration @@ -32,19 +47,57 @@ limitations under the License. class ClientGroup { public: + ClientGroup() { + reset(); + } + + + void dump() const; + + bool contains(uint32_t ip) const { + return ( (ip >= m_ip_start) && (ip <= m_ip_end) ); + } + + void reset() { + m_iterator = 0; + } + + /** + * assings a client config from the group + * it will advance MAC addresses andf etc. + * + * @author imarom (27-Jun-16) + * + * @param info + */ + void assign(ClientCfg &info) { + + for (int i = 0; i < 6; i++) { + info.m_init_mac[i] = ( (m_init_mac + m_iterator) >> ((5 - i) * 8) ) & 0xFF; + info.m_res_mac[i] = ( (m_res_mac + m_iterator) >> ((5 - i) * 8) ) & 0xFF; + } + + info.m_init_vlan = m_init_vlan; + info.m_res_vlan = m_res_vlan; + + /* advance */ + m_iterator = (m_iterator + 1) % m_count; + } + +public: uint32_t m_ip_start; uint32_t m_ip_end; - uint8_t m_init_mac[6]; + uint64_t m_init_mac; uint16_t m_init_vlan; - uint8_t m_res_mac[6]; + uint64_t m_res_mac; uint16_t m_res_vlan; uint32_t m_count; - - void dump(); +private: + uint32_t m_iterator; }; /** @@ -53,6 +106,21 @@ public: */ class ClientGroupsDB { public: + + ClientGroupsDB() { + m_is_empty = true; + m_cache_group = NULL; + } + + /** + * if no config file was loaded + * this should return true + * + */ + bool is_empty() { + return m_is_empty; + } + /** * loads a YAML file * configuration will be built @@ -61,10 +129,29 @@ public: */ void load_yaml_file(const std::string &filename); + /** + * lookup for a specific IP address for + * a group that contains this IP + * + */ + ClientGroup * lookup(uint32_t ip); + ClientGroup * lookup(const std::string &ip); private: + + void yaml_parse_err(const std::string &err, const YAML::Mark *mark = NULL) const; + + /** + * verify the YAML file loaded in valid + * + */ + void verify() const; + /* maps the IP start value to client groups */ std::map m_groups; + ClientGroup *m_cache_group; + std::string m_filename; + bool m_is_empty; }; #endif /* __TREX_CLIENT_CONFIG_H__ */ -- cgit 1.2.3-korg