From bf83f301e4fdbf333240af7f316735e35634c5fd Mon Sep 17 00:00:00 2001 From: Ido Barnea Date: Tue, 15 Nov 2016 16:27:08 +0200 Subject: client config ARP resolve working. Still missing IPv6 support. Signed-off-by: Ido Barnea --- src/tuple_gen.cpp | 92 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 79 insertions(+), 13 deletions(-) (limited to 'src/tuple_gen.cpp') diff --git a/src/tuple_gen.cpp b/src/tuple_gen.cpp index 6861b73f..f91a71a2 100755 --- a/src/tuple_gen.cpp +++ b/src/tuple_gen.cpp @@ -6,7 +6,7 @@ */ /* -Copyright (c) 2015-2015 Cisco Systems, Inc. +Copyright (c) 2015-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. @@ -21,11 +21,10 @@ See the License for the specific language governing permissions and limitations under the License. */ - -#include "tuple_gen.h" #include #include "utl_yaml.h" #include "bp_sim.h" +#include "tuple_gen.h" void CServerPool::Create(IP_DIST_t dist_value, uint32_t min_ip, @@ -216,13 +215,84 @@ void CTupleGeneratorSmart::Delete(){ m_server_pool.clear(); } +void CTupleGenYamlInfo::dump(FILE *fd) { + fprintf(fd, "Client pools:\n"); + for (int i=0; i < m_client_pool.size(); i++) { + m_client_pool[i].Dump(fd); + } + fprintf(fd, "Server pools:\n"); + for (int i=0; i < m_server_pool.size(); i++) { + m_server_pool[i].Dump(fd); + } +} + +// Find out matching port for given ip range. +// If found, port is returned in port, otherwise port is set to UINT8_MAX +// Return false in case of error. True otherwise. Port not found is not considered error. +bool CTupleGenYamlInfo::find_port(uint32_t ip_start, uint32_t ip_end, uint8_t &port) { + uint8_t num_ports = CGlobalInfo::m_options.get_expected_ports(); + + for (int i=0; i < m_client_pool.size(); i++) { + CTupleGenPoolYaml &pool = m_client_pool[i]; + uint32_t pool_start = pool.get_ip_start(); + uint32_t pool_end = pool.get_ip_end(); + uint32_t pool_offset = pool.getDualMask(); + for (uint8_t port_id = 0; port_id < num_ports; port_id += 2) { + uint32_t pool_port_start = pool_start + pool_offset * port_id / 2; + uint32_t pool_port_end = pool_end + pool_offset * port_id / 2; + if ((ip_start >= pool_port_start) && (ip_start <= pool_port_end)) { + if ((ip_end >= pool_port_start) && (ip_end <= pool_port_end)) { + port = port_id; + return true; + } else { + // ip_start in range, ip_end not + fprintf(stderr, "Error for range %s - %s. Start is inside range %s - %s, but end is outside\n" + , ip_to_str(ip_start).c_str(), ip_to_str(ip_end).c_str() + , ip_to_str(pool_port_start).c_str(), ip_to_str(pool_port_end).c_str()); + port = UINT8_MAX; + return false; + } + } + } + } + + for (int i=0; i < m_server_pool.size(); i++) { + CTupleGenPoolYaml &pool = m_server_pool[i]; + uint32_t pool_start = pool.get_ip_start(); + uint32_t pool_end = pool.get_ip_end(); + uint32_t pool_offset = pool.getDualMask(); + for (uint8_t port_id = 1; port_id < num_ports; port_id += 2) { + uint32_t pool_port_start = pool_start + pool_offset * (port_id - 1) / 2; + uint32_t pool_port_end = pool_end + pool_offset * (port_id - 1)/ 2; + if ((ip_start >= pool_port_start) && (ip_start <= pool_port_end)) { + if ((ip_end >= pool_port_start) && (ip_end <= pool_port_end)) { + port = port_id; + return true; + } else { + fprintf(stderr, "Error for range %s - %s. Start is inside range %s - %s, but end is outside\n" + , ip_to_str(ip_start).c_str(), ip_to_str(ip_end).c_str() + , ip_to_str(pool_port_start).c_str(), ip_to_str(pool_port_end).c_str()); + // ip_start in range, ip_end not + port = UINT8_MAX; + return false; + } + } + } + } + + port = UINT8_MAX; + return true; +} + void CTupleGenPoolYaml::Dump(FILE *fd){ - fprintf(fd," dist : %d \n",m_dist); - fprintf(fd," IPs : %08x -%08x \n",m_ip_start,m_ip_end); - fprintf(fd," clients per gb : %d \n",m_number_of_clients_per_gb); - fprintf(fd," min clients : %d \n",m_min_clients); - fprintf(fd," tcp aging : %d sec \n",m_tcp_aging_sec); - fprintf(fd," udp aging : %d sec \n",m_udp_aging_sec); + fprintf(fd," Pool %s:\n", (m_name.size() == 0) ? "default":m_name.c_str()); + fprintf(fd," dist : %d \n",m_dist); + fprintf(fd," IPs : %s - %s \n",ip_to_str(m_ip_start).c_str(), ip_to_str(m_ip_end).c_str()); + fprintf(fd," dual_port_mask : %s \n",ip_to_str(m_dual_interface_mask).c_str()); + fprintf(fd," clients per gb : %d \n",m_number_of_clients_per_gb); + fprintf(fd," min clients : %d \n",m_min_clients); + fprintf(fd," tcp aging : %d sec \n",m_tcp_aging_sec); + fprintf(fd," udp aging : %d sec \n",m_udp_aging_sec); } bool CTupleGenPoolYaml::is_valid(uint32_t num_threads,bool is_plugins){ @@ -244,10 +314,6 @@ bool CTupleGenPoolYaml::is_valid(uint32_t num_threads,bool is_plugins){ return (true); } - - - - #define UTL_YAML_READ(type, field, target) if (node.FindValue(#field)) { \ utl_yaml_read_ ## type (node, #field , target); \ } else { printf("generator definition mising " #field "\n"); } -- cgit 1.2.3-korg