diff options
Diffstat (limited to 'src/trex_client_config.h')
-rw-r--r-- | src/trex_client_config.h | 226 |
1 files changed, 150 insertions, 76 deletions
diff --git a/src/trex_client_config.h b/src/trex_client_config.h index a5bb83b3..1122c6f9 100644 --- a/src/trex_client_config.h +++ b/src/trex_client_config.h @@ -24,35 +24,52 @@ limitations under the License. #include <stdint.h> #include <string> #include <map> +#include "utl_ip.h" +#include "common/Network/Packet/MacAddress.h" class YAMLParserWrapper; - +struct CTupleGenYamlInfo; /** * client configuration per direction - * + * * @author imarom (29-Jun-16) */ class ClientCfgDir { + friend class ClientCfgCompactEntry; private: enum { - HAS_SRC_MAC = 0x1, - HAS_DST_MAC = 0x2, - HAS_VLAN = 0x4, + HAS_SRC_MAC = 0x1, + HAS_DST_MAC = 0x2, + HAS_VLAN = 0x4, + HAS_NEXT_HOP = 0x8, + HAS_IPV6_NEXT_HOP = 0x10, + HAS_SRC_IP = 0x20, + HAS_SRC_IPV6 = 0x40, }; - uint8_t m_src_mac[6]; - uint8_t m_dst_mac[6]; + //???? do we need to save memory? Maybe do another class that inherit from ClientCfgDir to be used here? + uint32_t m_next_hop; + uint32_t m_src_ip; + uint16_t m_src_ipv6[8]; + uint16_t m_ipv6_next_hop[8]; + MacAddress m_src_mac; + MacAddress m_dst_mac; uint16_t m_vlan; uint8_t m_bitfield; - + std::vector <MacAddress> m_resolved_macs; public: ClientCfgDir() { m_bitfield = 0; } + void dump(FILE *fd) const; + void set_resolved_macs(CManyIPInfo &pretest_result, uint16_t count); + bool need_resolve() const; + void set_no_resolve_needed(); + bool has_src_mac_addr() const { return (m_bitfield & HAS_SRC_MAC); } @@ -64,17 +81,29 @@ public: return (m_bitfield & HAS_VLAN); } + bool has_next_hop() const { + return (m_bitfield & HAS_NEXT_HOP); + } + + bool has_ipv6_next_hop() const { + return (m_bitfield & HAS_IPV6_NEXT_HOP); + } + + bool has_src_ip() const { + return (m_bitfield & HAS_SRC_IP); + } + + bool has_src_ipv6() const { + return (m_bitfield & HAS_SRC_IPV6); + } + void set_src_mac_addr(uint64_t mac_addr) { - for (int i = 0; i < 6; i++) { - m_src_mac[i] = ( mac_addr >> ((5 - i) * 8) ) & 0xFF; - } + m_src_mac.set(mac_addr); m_bitfield |= HAS_SRC_MAC; } void set_dst_mac_addr(uint64_t mac_addr) { - for (int i = 0; i < 6; i++) { - m_dst_mac[i] = ( mac_addr >> ((5 - i) * 8) ) & 0xFF; - } + m_dst_mac.set(mac_addr); m_bitfield |= HAS_DST_MAC; } @@ -83,79 +112,119 @@ public: m_bitfield |= HAS_VLAN; } + void set_src_ip(uint32_t src_ip) { + m_src_ip = src_ip; + m_bitfield |= HAS_SRC_IP; + } + + void set_src_ipv6(const uint16_t src_ipv6[8]) { + for (int i = 0; i < 8; i++) { + m_src_ipv6[i] = src_ipv6[i]; + } + m_bitfield |= HAS_SRC_IPV6; + } + + void set_next_hop(uint32_t next_hop) { + m_next_hop = next_hop; + m_bitfield |= HAS_NEXT_HOP; + } + + void set_ipv6_next_hop(const uint16_t next_hop[8]) { + for (int i = 0; i < 8; i++) { + m_ipv6_next_hop[i] = next_hop[i]; + } + m_bitfield |= HAS_IPV6_NEXT_HOP; + } + /* updates a configuration with a group index member */ - void update(uint32_t index) { + void update(uint32_t index, const ClientCfgDir &cfg) { if (has_src_mac_addr()) { - mac_add(m_src_mac, index); + m_src_mac += index; } - if (has_dst_mac_addr()) { - mac_add(m_dst_mac, index); + if (has_dst_mac_addr() || has_next_hop() || has_ipv6_next_hop()) { + m_dst_mac = cfg.m_resolved_macs[index]; + m_bitfield |= HAS_DST_MAC; } } const uint8_t *get_src_mac_addr() const { assert(has_src_mac_addr()); - return m_src_mac; + return m_src_mac.GetConstBuffer(); } const uint8_t *get_dst_mac_addr() const { assert(has_dst_mac_addr()); - return m_dst_mac; + return m_dst_mac.GetConstBuffer(); } uint16_t get_vlan() const { assert(has_vlan()); return m_vlan; } - -private: - /** - * transform MAC address to uint64_t - * performs add and return to MAC format - * - */ - void mac_add(uint8_t *mac, uint32_t i) { - uint64_t tmp = 0; - - for (int i = 0; i < 6; i++) { - tmp <<= 8; - tmp |= mac[i]; - } - - tmp += i; - - for (int i = 0; i < 6; i++) { - mac[i] = ( tmp >> ((5 - i) * 8) ) & 0xFF; - } - - } }; /** * single client config - * + * */ class ClientCfg { public: - void update(uint32_t index) { - m_initiator.update(index); - m_responder.update(index); + void dump (FILE *fd) const { + fprintf(fd, "initiator:\n"); + m_initiator.dump(fd); + fprintf(fd, "responder:\n"); + m_responder.dump(fd); + } + void update(uint32_t index, const ClientCfg &cfg) { + m_initiator.update(index, cfg.m_initiator); + m_responder.update(index, cfg.m_responder); } ClientCfgDir m_initiator; ClientCfgDir m_responder; }; +class ClientCfgCompactEntry { + friend class ClientCfgDB; + public: + uint16_t get_count() {return m_count;} + uint16_t get_vlan() {return m_vlan;} + uint16_t get_port() {return m_port;} + bool is_ipv4() {return m_is_ipv4;} + uint32_t get_dst_ip() {return m_next_hop_base.ip;} + uint16_t *get_dst_ipv6() {return m_next_hop_base.ipv6;} + uint32_t get_src_ip() {return m_src_ip.ip;} + uint16_t *get_src_ipv6() {return m_src_ip.ipv6;} + + public: + void fill_from_dir(ClientCfgDir cfg, uint8_t port_id); + + private: + uint16_t m_count; + uint16_t m_vlan; + uint8_t m_port; + bool m_is_ipv4; + union { + uint32_t ip; + uint16_t ipv6[8]; + } m_next_hop_base; + union { + uint32_t ip; + uint16_t ipv6[8]; + } m_src_ip; + +}; + /******************************** internal section ********************************/ /** - * describes a single client config + * describes a single client config * entry loaded from the config file - * + * */ class ClientCfgEntry { @@ -165,9 +234,8 @@ public: reset(); } - - void dump() const; - + void dump(FILE *fd) const; + void set_resolved_macs(CManyIPInfo &pretest_result); bool contains(uint32_t ip) const { return ( (ip >= m_ip_start) && (ip <= m_ip_end) ); } @@ -176,19 +244,19 @@ public: m_iterator = 0; } - + /** - * assings a client config from the group - * it will advance MAC addresses andf etc. - * + * assings a client config from the group + * it will advance MAC addresses andf etc. + * * @author imarom (27-Jun-16) - * - * @param info + * + * @param info */ void assign(ClientCfg &info) { info = m_cfg; - info.update(m_iterator); - + info.update(m_iterator, m_cfg); + /* advance for the next assign */ m_iterator = (m_iterator + 1) % m_count; } @@ -207,7 +275,7 @@ private: /** * holds all the configured clients groups - * + * */ class ClientCfgDB { public: @@ -216,32 +284,39 @@ public: m_is_empty = true; m_cache_group = NULL; m_under_vlan = false; + m_tg = NULL; } + void dump(FILE *fd) ; + /** - * if no config file was loaded - * this should return true - * + * if no config file was loaded + * this should return true + * */ bool is_empty() { return m_is_empty; } + void set_resolved_macs(CManyIPInfo &pretest_result); + std::vector<ClientCfgCompactEntry *> get_entry_list(); + /** - * loads a YAML file - * configuration will be built - * according to the YAML config - * + * loads a YAML file + * configuration will be built + * according to the YAML config + * */ void load_yaml_file(const std::string &filename); /** - * lookup for a specific IP address for - * a group that contains this IP - * + * lookup for a specific IP address for + * a group that contains this IP + * */ ClientCfgEntry * lookup(uint32_t ip); ClientCfgEntry * lookup(const std::string &ip); + void set_tuple_gen_info(CTupleGenYamlInfo *tg) {m_tg = tg;} private: void parse_single_group(YAMLParserWrapper &parser, const YAML::Node &node); @@ -249,17 +324,16 @@ private: /** * verify the YAML file loaded in valid - * + * */ void verify(const YAMLParserWrapper &parser) const; /* maps the IP start value to client groups */ std::map<uint32_t, ClientCfgEntry> m_groups; - bool m_under_vlan; - - ClientCfgEntry *m_cache_group; - bool m_is_empty; + bool m_under_vlan; + CTupleGenYamlInfo * m_tg; + ClientCfgEntry * m_cache_group; + bool m_is_empty; }; #endif /* __TREX_CLIENT_CONFIG_H__ */ - |