summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/trex_client_config.cpp125
-rw-r--r--src/trex_client_config.h70
2 files changed, 195 insertions, 0 deletions
diff --git a/src/trex_client_config.cpp b/src/trex_client_config.cpp
new file mode 100644
index 00000000..f3084942
--- /dev/null
+++ b/src/trex_client_config.cpp
@@ -0,0 +1,125 @@
+/*
+ Itay Marom
+ Cisco Systems, Inc.
+*/
+
+/*
+Copyright (c) 2016 Cisco Systems, Inc.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include <stdexcept>
+#include <sstream>
+#include <fstream>
+
+#include <yaml-cpp/yaml.h>
+
+#include "utl_yaml.h"
+#include "trex_client_config.h"
+#include "common/basic_utils.h"
+#include "bp_sim.h"
+
+void
+ClientGroup::dump() {
+ char ip_str[100];
+
+ ip_to_str(m_ip_start, ip_str);
+ std::cout << "IP start: " << ip_str << "\n";
+
+ ip_to_str(m_ip_end, ip_str);
+ std::cout << "IP end: " << ip_str << "\n";
+
+ std::cout << "Init. MAC addr: ";
+ for (int i = 0; i < 6; i++) {
+ printf("%x:", m_init_mac[i]);
+ }
+ std::cout << "\n";
+
+ std::cout << "Init. VLAN: " << m_init_vlan << "\n";
+
+ std::cout << "Res. MAC addr: ";
+ for (int i = 0; i < 6; i++) {
+ printf("%x:", m_res_mac[i]);
+ }
+ std::cout << "\n";
+
+ std::cout << "Res. VLAN: " << m_res_vlan << "\n";
+}
+
+/**
+ * loads a YAML file containing
+ * the client groups configuration
+ *
+ */
+void
+ClientGroupsDB::load_yaml_file(const std::string &filename) {
+ std::stringstream ss;
+
+ ss << "'" << filename << "' YAML parsing error: ";
+
+ if (!utl_is_file_exists(filename)){
+ ss << "file does not exists";
+ throw std::runtime_error(ss.str());
+ }
+
+ std::ifstream fin(filename);
+ YAML::Parser parser(fin);
+ YAML::Node root;
+
+ parser.GetNextDocument(root);
+
+ for (int i = 0; i < root.size(); i++) {
+ const YAML::Mark &mark = root[i].GetMark();
+ ClientGroup group;
+ bool rc;
+
+ /* ip_start */
+ rc = utl_yaml_read_ip_addr(root[i], "ip_start", group.m_ip_start);
+ if (!rc) {
+ ss << "line " << mark.line << " - 'ip_start' field does not exists";
+ throw std::runtime_error(ss.str());
+ }
+
+ /* ip_end */
+ rc = utl_yaml_read_ip_addr(root[i], "ip_end", group.m_ip_end);
+ if (!rc) {
+ ss << "line " << mark.line << " - 'ip_end' field does not exists";
+ throw std::runtime_error(ss.str());
+ }
+
+ /* init_mac */
+ rc = utl_yaml_read_mac_addr(root[i], "init_mac", group.m_init_mac);
+ if (!rc) {
+ ss << "line " << mark.line << " - 'init_mac' field does not exists";
+ throw std::runtime_error(ss.str());
+ }
+
+ /* res_mac */
+ rc = utl_yaml_read_mac_addr(root[i], "res_mac", group.m_res_mac);
+ if (!rc) {
+ ss << "line " << mark.line << " - 'init_mac' field does not exists";
+ throw std::runtime_error(ss.str());
+ }
+
+
+ root[i]["init_vlan"] >> group.m_init_vlan;
+ root[i]["res_vlan"] >> group.m_res_vlan;
+ root[i]["count"] >> group.m_count;
+
+ printf("\n");
+ group.dump();
+ printf("\n");
+ //std::cout << root[i]["ip_start"] << "\n";
+ }
+}
diff --git a/src/trex_client_config.h b/src/trex_client_config.h
new file mode 100644
index 00000000..27b11836
--- /dev/null
+++ b/src/trex_client_config.h
@@ -0,0 +1,70 @@
+/*
+ Itay Marom
+ Cisco Systems, Inc.
+*/
+
+/*
+Copyright (c) 2016 Cisco Systems, Inc.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+#ifndef __TREX_CLIENT_CONFIG_H__
+#define __TREX_CLIENT_CONFIG_H__
+
+#include <stdint.h>
+#include <string>
+#include <map>
+
+/**
+ * describes a single client group
+ * configuration
+ */
+class ClientGroup {
+public:
+
+ uint32_t m_ip_start;
+ uint32_t m_ip_end;
+
+ uint8_t m_init_mac[6];
+ uint16_t m_init_vlan;
+
+ uint8_t m_res_mac[6];
+ uint16_t m_res_vlan;
+
+ uint32_t m_count;
+
+
+ void dump();
+};
+
+/**
+ * describes the DB of every client group
+ *
+ */
+class ClientGroupsDB {
+public:
+ /**
+ * loads a YAML file
+ * configuration will be built
+ * according to the YAML config
+ *
+ */
+ void load_yaml_file(const std::string &filename);
+
+
+private:
+ /* maps the IP start value to client groups */
+ std::map<uint32_t, ClientGroup> m_groups;
+};
+
+#endif /* __TREX_CLIENT_CONFIG_H__ */