summaryrefslogtreecommitdiffstats
path: root/src/trex_client_config.h
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2016-06-27 15:31:00 +0300
committerimarom <imarom@cisco.com>2016-07-03 13:40:19 +0300
commit6535523a2768a5c867fd22b4fa62c7fb43fd9ad8 (patch)
treee6834cbe44dfb738f7a9c45503bde1b73aabadfa /src/trex_client_config.h
parente7eb06bbeb882d8743ce0018938fb5af61aade2e (diff)
draft #2 for trex client config
Diffstat (limited to 'src/trex_client_config.h')
-rw-r--r--src/trex_client_config.h95
1 files changed, 91 insertions, 4 deletions
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
@@ -26,25 +26,78 @@ limitations under the License.
#include <map>
/**
+ * 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
*/
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<uint32_t, ClientGroup> m_groups;
+ ClientGroup *m_cache_group;
+ std::string m_filename;
+ bool m_is_empty;
};
#endif /* __TREX_CLIENT_CONFIG_H__ */