summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xlinux/ws_main.py24
-rw-r--r--scripts/automation/regression/unit_tests/functional_tests/stl_basic_tests.py12
-rwxr-xr-xscripts/automation/trex_control_plane/stl/console/trex_console.py6
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py82
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py30
-rwxr-xr-xscripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py21
-rw-r--r--scripts/stl/udp_1pkt_simple.py6
-rw-r--r--src/internal_api/trex_platform_api.h76
-rw-r--r--src/main_dpdk.cpp9
-rw-r--r--src/mock/rte_ethdev.h44
-rw-r--r--src/mock/trex_platform_api_mock.cpp54
-rw-r--r--src/mock/trex_rpc_server_mock.cpp191
-rw-r--r--src/rpc-server/commands/trex_rpc_cmd_general.cpp36
-rw-r--r--src/rpc-server/commands/trex_rpc_cmds.h2
-rw-r--r--src/rpc-server/trex_rpc_cmds_table.cpp1
-rw-r--r--src/sim/trex_sim.h45
-rw-r--r--src/stateless/cp/trex_stateless_port.cpp19
-rw-r--r--src/stateless/cp/trex_stateless_port.h9
18 files changed, 274 insertions, 393 deletions
diff --git a/linux/ws_main.py b/linux/ws_main.py
index 9e4ac4d4..a8e7deef 100755
--- a/linux/ws_main.py
+++ b/linux/ws_main.py
@@ -178,16 +178,8 @@ rpc_server_src = SrcGroup(dir='src/rpc-server/',
'commands/trex_rpc_cmd_general.cpp',
'commands/trex_rpc_cmd_stream.cpp',
- # for simulation we use mock API
- '../mock/trex_platform_api_mock.cpp',
])
-# RPC mock server (test)
-rpc_server_mock_src = SrcGroup(dir='src/mock/',
- src_list=[
- 'trex_rpc_server_mock.cpp',
- '../gtest/rpc_test.cpp',
- ])
# JSON package
json_src = SrcGroup(dir='external_libs/json',
@@ -231,17 +223,6 @@ yaml_src = SrcGroup(dir='external_libs/yaml-cpp/src/',
stubs = SrcGroup(dir='/src/stub/',
src_list=['zmq_stub.c'])
-rpc_server_mock = SrcGroups([
- main_src,
- stubs,
- cmn_src,
- rpc_server_src,
- rpc_server_mock_src,
- stateless_src,
- json_src,
- yaml_src,
- net_src,
- ])
bp =SrcGroups([
bp_sim_main,
@@ -272,7 +253,6 @@ cxxflags_base =['-DWIN_UCODE_SIM',
includes_path =''' ../src/pal/linux/
../src/
- ../src/mock/
../src/rpc-server/
../src/stateless/cp/
../src/stateless/dp/
@@ -415,10 +395,6 @@ build_types = [
flags = ['-Wall', '-Werror', '-Wno-sign-compare', '-Wno-strict-aliasing'],
rpath = ['.']),
- # not supported any more
- #build_option(name = "mock-rpc-server", use = [''], src = rpc_server_mock, debug_mode= DEBUG_,platform = PLATFORM_64, is_pie = False,
- # flags = ['-DTREX_RPC_MOCK_SERVER', '-Wall', '-Werror', '-Wno-sign-compare'],
- # rpath = ['.']),
]
diff --git a/scripts/automation/regression/unit_tests/functional_tests/stl_basic_tests.py b/scripts/automation/regression/unit_tests/functional_tests/stl_basic_tests.py
index 5ae890ba..f7638746 100644
--- a/scripts/automation/regression/unit_tests/functional_tests/stl_basic_tests.py
+++ b/scripts/automation/regression/unit_tests/functional_tests/stl_basic_tests.py
@@ -61,13 +61,13 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test):
def compare_caps (self, cap1, cap2, max_diff_sec = 0.01):
- f1 = open(cap1, 'r')
- reader1 = pcap.Reader(f1)
- pkts1 = reader1.readpkts()
+ with open(cap1, 'r') as f1:
+ reader1 = pcap.Reader(f1)
+ pkts1 = reader1.readpkts()
- f2 = open(cap2, 'r')
- reader2 = pcap.Reader(f2)
- pkts2 = reader2.readpkts()
+ with open(cap2, 'r') as f2:
+ reader2 = pcap.Reader(f2)
+ pkts2 = reader2.readpkts()
assert_equal(len(pkts1), len(pkts2))
diff --git a/scripts/automation/trex_control_plane/stl/console/trex_console.py b/scripts/automation/trex_control_plane/stl/console/trex_console.py
index 0beb10df..53817464 100755
--- a/scripts/automation/trex_control_plane/stl/console/trex_console.py
+++ b/scripts/automation/trex_control_plane/stl/console/trex_console.py
@@ -332,6 +332,12 @@ class TRexConsole(TRexGeneralCmd):
def help_push (self):
return self.do_push("-h")
+ def do_portattr (self, line):
+ '''Change/show port(s) attributes\n'''
+ return self.stateless_client.set_port_attr_line(line)
+
+ def help_portattr (self):
+ return self.do_portattr("-h")
def do_history (self, line):
'''Manage the command history\n'''
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py
index fe162096..90a17ce2 100644
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py
@@ -609,6 +609,15 @@ class STLClient(object):
return rc
+ def __set_port_attr (self, port_id_list = None, attr_dict = None):
+
+ port_id_list = self.__ports(port_id_list)
+ rc = RC()
+
+ for port_id in port_id_list:
+ rc.add(self.ports[port_id].set_attr(attr_dict))
+
+ return rc
# connect to server
def __connect(self):
@@ -1639,6 +1648,47 @@ class STLClient(object):
raise STLTimeoutError(timeout)
+ #
+ """
+ set port(s) attributes
+
+ :parameters:
+ promiscuous - set this to True or False
+
+ :raises:
+ None
+
+ """
+ @__api_check(True)
+ def set_port_attr (self, ports = None, promiscuous = None):
+ # by default use all acquired ports
+ if ports == None:
+ ports = self.get_acquired_ports()
+
+ # verify valid port id list
+ rc = self._validate_port_list(ports)
+ if not rc:
+ raise STLArgumentError('ports', ports, valid_values = self.get_all_ports())
+
+ # check arguments
+ validate_type('promiscuous', promiscuous, bool)
+
+ # build attributes
+ attr_dict = {}
+ if promiscuous is not None:
+ attr_dict['promiscuous'] = {'enabled': bool(promiscuous)}
+
+ # no attributes to set
+ if not attr_dict:
+ return
+
+ self.logger.pre_cmd("Applying attributes on port(s) {0}:".format(ports))
+ rc = self.__set_port_attr(ports, attr_dict)
+ self.logger.post_cmd(rc)
+
+ if not rc:
+ raise STLError(rc)
+
"""
clear all events
@@ -2022,3 +2072,35 @@ class STLClient(object):
return True
+
+
+ @__console
+ def set_port_attr_line (self, line):
+ '''Sets port attributes '''
+
+ parser = parsing_opts.gen_parser(self,
+ "port",
+ self.set_port_attr_line.__doc__,
+ parsing_opts.PORT_LIST_WITH_ALL,
+ parsing_opts.PROMISCUOUS_SWITCH)
+
+ opts = parser.parse_args(line.split())
+ if opts is None:
+ return
+
+ try:
+ self.set_port_attr(opts.ports, opts.prom)
+ except STLError as e:
+ print e.brief()
+ return
+
+ # show
+ print ""
+ for port_id in opts.ports:
+ print format_text('Port {0}:\n'.format(port_id), 'bold', 'underline')
+ for k, v in self.get_port(port_id).get_attr().iteritems():
+ print "{0}:".format(k)
+ for pk, pv in v.iteritems():
+ print " {0}: {1}".format(pk, format_text(str(pv), 'bold'))
+ print ""
+
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py
index 4dd07a13..8d542b35 100644
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py
@@ -54,6 +54,7 @@ class Port(object):
self.streams = {}
self.profile = None
self.session_id = session_id
+ self.attr = {}
self.port_stats = trex_stl_stats.CPortStats(self)
@@ -138,6 +139,9 @@ class Port(object):
self.next_available_id = long(rc.data()['max_stream_id']) + 1
+ # attributes
+ self.attr = rc.data()['attr']
+
# sync the streams
params = {"port_id": self.port_id}
@@ -448,10 +452,34 @@ class Port(object):
return self.ok()
+ def set_attr (self, attr_dict):
+ if not self.is_acquired():
+ return self.err("port is not owned")
+
+ if (self.state == self.STATE_DOWN):
+ return self.err("port is down")
+
+ params = {"handler": self.handler,
+ "port_id": self.port_id,
+ "attr": attr_dict}
+
+ rc = self.transmit("set_port_attr", params)
+ if rc.bad():
+ return self.err(rc.err())
+
+
+ self.attr.update(attr_dict)
+
+ return self.ok()
+
+
+ def get_attr (self):
+ return self.attr
+
def get_profile (self):
return self.profile
-
+
def print_profile (self, mult, duration):
if not self.get_profile():
return
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py
index 92e9a1d6..0c70801f 100755
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py
@@ -27,6 +27,9 @@ FULL_OUTPUT = 15
IPG = 16
SPEEDUP = 17
COUNT = 18
+PROMISCUOUS = 19
+NO_PROMISCUOUS = 20
+PROMISCUOUS_SWITCH = 21
GLOBAL_STATS = 50
PORT_STATS = 51
@@ -223,6 +226,19 @@ OPTIONS_DB = {MULTIPLIER: ArgumentPack(['-m', '--multiplier'],
'default': 1,
'type': int}),
+ PROMISCUOUS: ArgumentPack(['--prom'],
+ {'help': "sets port promiscuous on",
+ 'dest': "prom",
+ 'default': None,
+ 'action': "store_true"}),
+
+ NO_PROMISCUOUS: ArgumentPack(['--no_prom'],
+ {'help': "sets port promiscuous off",
+ 'dest': "prom",
+ 'default': None,
+ 'action': "store_false"}),
+
+
PORT_LIST: ArgumentPack(['--port'],
{"nargs": '+',
'dest':'ports',
@@ -305,6 +321,11 @@ OPTIONS_DB = {MULTIPLIER: ArgumentPack(['-m', '--multiplier'],
'default': []}),
+ # promiscuous
+ PROMISCUOUS_SWITCH: ArgumentGroup(MUTEX, [PROMISCUOUS,
+ NO_PROMISCUOUS],
+ {'required': False}),
+
# advanced options
PORT_LIST_WITH_ALL: ArgumentGroup(MUTEX, [PORT_LIST,
ALL_PORTS],
diff --git a/scripts/stl/udp_1pkt_simple.py b/scripts/stl/udp_1pkt_simple.py
index 31492291..2cfb9f1d 100644
--- a/scripts/stl/udp_1pkt_simple.py
+++ b/scripts/stl/udp_1pkt_simple.py
@@ -3,8 +3,10 @@ from trex_stl_lib.api import *
class STLS1(object):
def create_stream (self):
- return STLStream( packet = STLPktBuilder(pkt = Ether()/IP(src="16.0.0.1",dst="48.0.0.1")/UDP(dport=12,sport=1025)/(10*'x')),
- mode = STLTXCont() )
+ return STLStream( packet = STLPktBuilder(pkt = Ether(dst = "5")/IP(src="16.0.0.1",dst="48.0.0.1")/UDP(dport=12,sport=1025)/(10*'x')),
+ #mode = STLTXCont()
+ mode = STLTXSingleBurst(total_pkts = 1)
+ )
def get_streams (self, direction = 0):
# create 1 stream
diff --git a/src/internal_api/trex_platform_api.h b/src/internal_api/trex_platform_api.h
index 831fd778..249adb2f 100644
--- a/src/internal_api/trex_platform_api.h
+++ b/src/internal_api/trex_platform_api.h
@@ -127,7 +127,9 @@ public:
virtual void get_port_num(uint8_t &port_num) const = 0;
virtual int add_rx_flow_stat_rule(uint8_t port_id, uint8_t type, uint16_t proto, uint16_t id) const = 0;
virtual int del_rx_flow_stat_rule(uint8_t port_id, uint8_t type, uint16_t proto, uint16_t id) const = 0;
-
+ virtual void set_promiscuous(uint8_t port_id, bool enabled) const = 0;
+ virtual bool get_promiscuous(uint8_t port_id) const = 0;
+
virtual ~TrexPlatformApi() {}
};
@@ -155,36 +157,66 @@ public:
void get_port_num(uint8_t &port_num) const;
int add_rx_flow_stat_rule(uint8_t port_id, uint8_t type, uint16_t proto, uint16_t id) const;
int del_rx_flow_stat_rule(uint8_t port_id, uint8_t type, uint16_t proto, uint16_t id) const;
+ void set_promiscuous(uint8_t port_id, bool enabled) const;
+ bool get_promiscuous(uint8_t port_id) const;
};
+
/**
- * MOCK implementation of the platform API
+ * for simulation
*
- * @author imarom (26-Oct-15)
+ * @author imarom (25-Feb-16)
*/
-class TrexMockPlatformApi : public TrexPlatformApi {
+class SimPlatformApi : public TrexPlatformApi {
public:
- void port_id_to_cores(uint8_t port_id, std::vector<std::pair<uint8_t, uint8_t>> &cores_id_list) const;
- void get_global_stats(TrexPlatformGlobalStats &stats) const;
- void get_interface_stats(uint8_t interface_id, TrexPlatformInterfaceStats &stats) const;
- void get_interface_info(uint8_t interface_id,
- std::string &driver_name,
- driver_speed_e &speed,
- bool &has_crc) const {
- driver_name = "MOCK";
- speed = SPEED_INVALID;
- has_crc = false;
+ SimPlatformApi(int dp_core_count) {
+ m_dp_core_count = dp_core_count;
}
- void publish_async_data_now(uint32_t key) const {}
- uint8_t get_dp_core_count() const;
- void get_interface_stat_info(uint8_t interface_id, uint16_t &num_counters, uint16_t &capabilities) const
- {num_counters = 0; capabilities = 0;}
- int get_rx_stats(uint8_t port_id, uint64_t *stats, int index, bool reset) const {return 0;}
- void get_port_num(uint8_t &port_num) const {port_num = 2;};
- int add_rx_flow_stat_rule(uint8_t port_id, uint8_t type, uint16_t proto, uint16_t id) const {return 0;}
- int del_rx_flow_stat_rule(uint8_t port_id, uint8_t type, uint16_t proto, uint16_t id) const {return 0;}
+ virtual uint8_t get_dp_core_count() const {
+ return m_dp_core_count;
+ }
+
+ virtual void get_global_stats(TrexPlatformGlobalStats &stats) const {
+ }
+
+ virtual void get_interface_info(uint8_t interface_id,
+ std::string &driver_name,
+ driver_speed_e &speed,
+ bool &has_crc) const {
+ driver_name = "TEST";
+ speed = TrexPlatformApi::SPEED_10G;
+ has_crc = true;
+ }
+
+ virtual void get_interface_stats(uint8_t interface_id, TrexPlatformInterfaceStats &stats) const {
+ }
+ virtual void get_interface_stat_info(uint8_t interface_id, uint16_t &num_counters, uint16_t &capabilities) const {num_counters=128; capabilities=0; }
+
+ virtual void port_id_to_cores(uint8_t port_id, std::vector<std::pair<uint8_t, uint8_t>> &cores_id_list) const {
+ for (int i = 0; i < m_dp_core_count; i++) {
+ cores_id_list.push_back(std::make_pair(i, 0));
+ }
+ }
+
+ virtual void publish_async_data_now(uint32_t key) const {
+
+ }
+ virtual int get_rx_stats(uint8_t port_id, uint64_t *stats, int index, bool reset) const {return 0;}
+ virtual void get_port_num(uint8_t &port_num) const {port_num = 2;};
+ virtual int add_rx_flow_stat_rule(uint8_t port_id, uint8_t type, uint16_t proto, uint16_t id) const {return 0;}
+ virtual int del_rx_flow_stat_rule(uint8_t port_id, uint8_t type, uint16_t proto, uint16_t id) const {return 0;}
+
+ void set_promiscuous(uint8_t port_id, bool enabled) const {
+ }
+
+ bool get_promiscuous(uint8_t port_id) const {
+ return false;
+ }
+
+private:
+ int m_dp_core_count;
};
#endif /* __TREX_PLATFORM_API_H__ */
diff --git a/src/main_dpdk.cpp b/src/main_dpdk.cpp
index 8cc94e7d..25c10e5d 100644
--- a/src/main_dpdk.cpp
+++ b/src/main_dpdk.cpp
@@ -5171,3 +5171,12 @@ int TrexDpdkPlatformApi::del_rx_flow_stat_rule(uint8_t port_id, uint8_t type, ui
return CTRexExtendedDriverDb::Ins()->get_drv()
->add_del_rx_flow_stat_rule(port_id, RTE_ETH_FILTER_DELETE, type, proto, id);
}
+
+void TrexDpdkPlatformApi::set_promiscuous(uint8_t port_id, bool enabled) const {
+ g_trex.m_ports[port_id].set_promiscuous(enabled);
+}
+
+bool TrexDpdkPlatformApi::get_promiscuous(uint8_t port_id) const {
+ return g_trex.m_ports[port_id].get_promiscuous();
+}
+
diff --git a/src/mock/rte_ethdev.h b/src/mock/rte_ethdev.h
deleted file mode 100644
index 046d8366..00000000
--- a/src/mock/rte_ethdev.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- Itay Marom
- Cisco Systems, Inc.
-*/
-
-/*
-Copyright (c) 2015-2015 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 __MOCK_FILE_RTE_ETHDEV_H__
-#define __MOCK_FILE_RTE_ETHDEV_H__
-
-#include <string.h>
-
-struct rte_eth_stats {
- uint64_t obytes;
- uint64_t ibytes;
- uint64_t opackets;
- uint64_t ipackets;
-};
-
-static inline void
-rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats) {
- memset(stats, 0, sizeof(rte_eth_stats));
-}
-
-static inline uint16_t
-rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
- struct rte_mbuf **tx_pkts, uint16_t nb_pkts) {
- return (0);
-}
-
-#endif /* __MOCK_FILE_RTE_ETHDEV_H__ */
diff --git a/src/mock/trex_platform_api_mock.cpp b/src/mock/trex_platform_api_mock.cpp
deleted file mode 100644
index 7cacd96c..00000000
--- a/src/mock/trex_platform_api_mock.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- Itay Marom
- Cisco Systems, Inc.
-*/
-
-/*
-Copyright (c) 2015-2015 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 <internal_api/trex_platform_api.h>
-
-void
-TrexMockPlatformApi::get_global_stats(TrexPlatformGlobalStats &stats) const {
-
- stats.m_stats.m_cpu_util = 0;
-
- stats.m_stats.m_tx_bps = 0;
- stats.m_stats.m_tx_pps = 0;
- stats.m_stats.m_total_tx_pkts = 0;
- stats.m_stats.m_total_tx_bytes = 0;
-
- stats.m_stats.m_rx_bps = 0;
- stats.m_stats.m_rx_pps = 0;
- stats.m_stats.m_total_rx_pkts = 0;
- stats.m_stats.m_total_rx_bytes = 0;
-}
-
-void
-TrexMockPlatformApi::get_interface_stats(uint8_t interface_id, TrexPlatformInterfaceStats &stats) const {
-
-}
-
-uint8_t
-TrexMockPlatformApi::get_dp_core_count() const {
- return (1);
-}
-
-void
-TrexMockPlatformApi::port_id_to_cores(uint8_t port_id, std::vector<std::pair<uint8_t, uint8_t>> &cores_id_list) const {
- cores_id_list.push_back(std::make_pair(0, 0));
-}
-
diff --git a/src/mock/trex_rpc_server_mock.cpp b/src/mock/trex_rpc_server_mock.cpp
deleted file mode 100644
index ecfa308d..00000000
--- a/src/mock/trex_rpc_server_mock.cpp
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- Itay Marom
- Cisco Systems, Inc.
-*/
-
-/*
-Copyright (c) 2015-2015 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 <trex_rpc_server_api.h>
-#include <trex_stateless.h>
-#include <trex_stateless_dp_core.h>
-
-#include <msg_manager.h>
-
-#include <iostream>
-#include <sstream>
-#include <unistd.h>
-#include <string.h>
-#include <zmq.h>
-#include <bp_sim.h>
-
-using namespace std;
-
-static TrexStateless *g_trex_stateless;
-static uint16_t g_rpc_port;
-
-static bool
-verify_tcp_port_is_free(uint16_t port) {
- void *m_context = zmq_ctx_new();
- void *m_socket = zmq_socket (m_context, ZMQ_REP);
- std::stringstream ss;
- ss << "tcp://*:";
- ss << port;
-
- int rc = zmq_bind (m_socket, ss.str().c_str());
-
- zmq_close(m_socket);
- zmq_term(m_context);
-
- return (rc == 0);
-}
-
-static uint16_t
-find_free_tcp_port(uint16_t start_port = 5050) {
- void *m_context = zmq_ctx_new();
- void *m_socket = zmq_socket (m_context, ZMQ_REP);
-
- uint16_t port = start_port;
- while (true) {
- std::stringstream ss;
- ss << "tcp://*:";
- ss << port;
-
- int rc = zmq_bind (m_socket, ss.str().c_str());
- if (rc == 0) {
- break;
- }
-
- port++;
- }
-
- zmq_close(m_socket);
- zmq_term(m_context);
-
- return port;
-}
-
-uint16_t gtest_get_mock_server_port() {
- return g_rpc_port;
-}
-
-/**
- * on simulation this is not rebuild every version
- * (improved stub)
- *
- */
-extern "C" const char * get_build_date(void){
- return (__DATE__);
-}
-
-extern "C" const char * get_build_time(void){
- return (__TIME__ );
-}
-
-int gtest_main(int argc, char **argv);
-
-static bool parse_uint16(const string arg, uint16_t &port) {
- stringstream ss(arg);
-
- bool x = (ss >> port);
-
- return (x);
-}
-
-static void
-run_dummy_core() {
- //TODO: connect this to the scheduler
-
- //CFlowGenList fl;
- //fl.Create();
- //CFlowGenListPerThread *lp = new CFlowGenListPerThread();
- //lp->Create(0, 0, NULL, 0);
- //TrexStatelessDpCore dummy_core(0, lp);
- //lp->start_stateless_daemon();
-}
-
-int main(int argc, char *argv[]) {
- bool is_gtest = false;
-
- time_init();
- CGlobalInfo::m_socket.Create(0);
-
- CGlobalInfo::init_pools(1000);
- assert( CMsgIns::Ins()->Create(1));
-
- std::thread *m_thread = new std::thread(run_dummy_core);
- (void)m_thread;
-
- // gtest ?
- if (argc > 1) {
- string arg = string(argv[1]);
-
- if (arg == "--ut") {
- g_rpc_port = find_free_tcp_port();
- is_gtest = true;
- } else if (parse_uint16(arg, g_rpc_port)) {
- bool rc = verify_tcp_port_is_free(g_rpc_port);
- if (!rc) {
- cout << "port " << g_rpc_port << " is not available to use\n";
- exit(-1);
- }
- } else {
-
- cout << "\n[Usage] " << argv[0] << ": " << " [--ut] or [port number < 65535]\n\n";
- exit(-1);
- }
-
- } else {
- g_rpc_port = find_free_tcp_port();
- }
-
- /* configure the stateless object with 4 ports */
- TrexStatelessCfg cfg;
-
- TrexRpcServerConfig rpc_req_resp_cfg(TrexRpcServerConfig::RPC_PROT_TCP, g_rpc_port);
- //TrexRpcServerConfig rpc_async_cfg(TrexRpcServerConfig::RPC_PROT_TCP, 5051);
-
- cfg.m_port_count = 4;
- cfg.m_rpc_req_resp_cfg = &rpc_req_resp_cfg;
- cfg.m_rpc_async_cfg = NULL;
- cfg.m_rpc_server_verbose = (is_gtest ? false : true);
- cfg.m_platform_api = new TrexMockPlatformApi();
-
- g_trex_stateless = new TrexStateless(cfg);
-
- g_trex_stateless->launch_control_plane();
-
- /* gtest handling */
- if (is_gtest) {
- int rc = gtest_main(argc, argv);
- delete g_trex_stateless;
- g_trex_stateless = NULL;
- return rc;
- }
-
- cout << "\n-= Starting RPC Server Mock =-\n\n";
- cout << "Listening on tcp://localhost:" << g_rpc_port << " [ZMQ]\n\n";
-
- cout << "Server Started\n\n";
-
- while (true) {
- sleep(1);
- }
-
- delete g_trex_stateless;
- g_trex_stateless = NULL;
-}
-
diff --git a/src/rpc-server/commands/trex_rpc_cmd_general.cpp b/src/rpc-server/commands/trex_rpc_cmd_general.cpp
index 9b3b59a7..05565179 100644
--- a/src/rpc-server/commands/trex_rpc_cmd_general.cpp
+++ b/src/rpc-server/commands/trex_rpc_cmd_general.cpp
@@ -208,6 +208,39 @@ TrexRpcCmdGetSysInfo::_run(const Json::Value &params, Json::Value &result) {
}
/**
+ * set port commands
+ *
+ * @author imarom (24-Feb-16)
+ *
+ * @param params
+ * @param result
+ *
+ * @return trex_rpc_cmd_rc_e
+ */
+trex_rpc_cmd_rc_e
+TrexRpcCmdSetPortAttr::_run(const Json::Value &params, Json::Value &result) {
+
+ uint8_t port_id = parse_port(params, result);
+ TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id);
+
+ const Json::Value &attr = parse_object(params, "attr", result);
+
+ /* iterate over all attributes in the dict */
+ for (const std::string &name : attr.getMemberNames()) {
+
+ /* handle promiscuous */
+ if (name == "promiscuous") {
+ bool enabled = parse_bool(attr[name], "enabled", result);
+ port->set_promiscuous(enabled);
+ }
+ }
+
+ result["result"] = Json::objectValue;
+ return (TREX_RPC_CMD_OK);
+}
+
+
+/**
* returns the current owner of the device
*
* @author imarom (08-Sep-15)
@@ -318,6 +351,9 @@ TrexRpcCmdGetPortStatus::_run(const Json::Value &params, Json::Value &result) {
result["result"]["state"] = port->get_state_as_string();
result["result"]["max_stream_id"] = port->get_max_stream_id();
+ /* attributes */
+ result["result"]["attr"]["promiscuous"]["enabled"] = port->get_promiscuous();
+
return (TREX_RPC_CMD_OK);
}
diff --git a/src/rpc-server/commands/trex_rpc_cmds.h b/src/rpc-server/commands/trex_rpc_cmds.h
index 9545e585..ac63e39d 100644
--- a/src/rpc-server/commands/trex_rpc_cmds.h
+++ b/src/rpc-server/commands/trex_rpc_cmds.h
@@ -81,7 +81,7 @@ TREX_RPC_CMD_DEFINE(TrexRpcCmdRelease, "release", 1, true);
*/
TREX_RPC_CMD_DEFINE(TrexRpcCmdGetPortStats, "get_port_stats", 1, false);
TREX_RPC_CMD_DEFINE(TrexRpcCmdGetPortStatus, "get_port_status", 1, false);
-
+TREX_RPC_CMD_DEFINE(TrexRpcCmdSetPortAttr, "set_port_attr", 3, false);
/**
* stream cmds
diff --git a/src/rpc-server/trex_rpc_cmds_table.cpp b/src/rpc-server/trex_rpc_cmds_table.cpp
index 5218cd0a..7b8dfdfc 100644
--- a/src/rpc-server/trex_rpc_cmds_table.cpp
+++ b/src/rpc-server/trex_rpc_cmds_table.cpp
@@ -43,6 +43,7 @@ TrexRpcCommandsTable::TrexRpcCommandsTable() {
register_command(new TrexRpcCmdRelease());
register_command(new TrexRpcCmdGetPortStats());
register_command(new TrexRpcCmdGetPortStatus());
+ register_command(new TrexRpcCmdSetPortAttr());
/* stream commands */
diff --git a/src/sim/trex_sim.h b/src/sim/trex_sim.h
index 6e842eb7..3a3a62ea 100644
--- a/src/sim/trex_sim.h
+++ b/src/sim/trex_sim.h
@@ -40,51 +40,6 @@ in_range(int x, int low, int high) {
return ( (x >= low) && (x <= high) );
}
-/*************** hook for platform API **************/
-class SimPlatformApi : public TrexPlatformApi {
-public:
- SimPlatformApi(int dp_core_count) {
- m_dp_core_count = dp_core_count;
- }
-
- virtual uint8_t get_dp_core_count() const {
- return m_dp_core_count;
- }
-
- virtual void get_global_stats(TrexPlatformGlobalStats &stats) const {
- }
-
- virtual void get_interface_info(uint8_t interface_id,
- std::string &driver_name,
- driver_speed_e &speed,
- bool &has_crc) const {
- driver_name = "TEST";
- speed = TrexPlatformApi::SPEED_10G;
- has_crc = true;
- }
-
- virtual void get_interface_stats(uint8_t interface_id, TrexPlatformInterfaceStats &stats) const {
- }
- virtual void get_interface_stat_info(uint8_t interface_id, uint16_t &num_counters, uint16_t &capabilities) const {num_counters=128; capabilities=0; }
-
- virtual void port_id_to_cores(uint8_t port_id, std::vector<std::pair<uint8_t, uint8_t>> &cores_id_list) const {
- for (int i = 0; i < m_dp_core_count; i++) {
- cores_id_list.push_back(std::make_pair(i, 0));
- }
- }
-
- virtual void publish_async_data_now(uint32_t key) const {
-
- }
- virtual int get_rx_stats(uint8_t port_id, uint64_t *stats, int index, bool reset) const {return 0;}
- virtual void get_port_num(uint8_t &port_num) const {port_num = 2;};
- virtual int add_rx_flow_stat_rule(uint8_t port_id, uint8_t type, uint16_t proto, uint16_t id) const {return 0;}
- virtual int del_rx_flow_stat_rule(uint8_t port_id, uint8_t type, uint16_t proto, uint16_t id) const {return 0;}
-
-private:
- int m_dp_core_count;
-};
-
/**
* interface for a sim target
*
diff --git a/src/stateless/cp/trex_stateless_port.cpp b/src/stateless/cp/trex_stateless_port.cpp
index d2463925..43f32d22 100644
--- a/src/stateless/cp/trex_stateless_port.cpp
+++ b/src/stateless/cp/trex_stateless_port.cpp
@@ -40,7 +40,6 @@ limitations under the License.
// DPDK c++ issue
#endif
-#include <rte_ethdev.h>
#include <os_time.h>
void
@@ -251,9 +250,9 @@ TrexStatelessPort::common_port_stop_actions(bool event_triggered) {
data["port_id"] = m_port_id;
if (event_triggered) {
- get_stateless_obj()->get_publisher()->publish_event(TrexPublisher::EVENT_PORT_STOPPED, data);
- } else {
get_stateless_obj()->get_publisher()->publish_event(TrexPublisher::EVENT_PORT_FINISHED_TX, data);
+ } else {
+ get_stateless_obj()->get_publisher()->publish_event(TrexPublisher::EVENT_PORT_STOPPED, data);
}
for (auto entry : m_stream_table) {
@@ -668,6 +667,20 @@ TrexStatelessPort::get_port_effective_rate(double &pps,
}
+
+void
+TrexStatelessPort::set_promiscuous(bool enabled) {
+ get_stateless_obj()->get_platform_api()->set_promiscuous(m_port_id, enabled);
+}
+
+bool
+TrexStatelessPort::get_promiscuous() {
+ return get_stateless_obj()->get_platform_api()->get_promiscuous(m_port_id);
+}
+
+
+
+
void
TrexStatelessPort::add_stream(TrexStream *stream) {
diff --git a/src/stateless/cp/trex_stateless_port.h b/src/stateless/cp/trex_stateless_port.h
index a956c421..1d3eebc3 100644
--- a/src/stateless/cp/trex_stateless_port.h
+++ b/src/stateless/cp/trex_stateless_port.h
@@ -323,6 +323,15 @@ public:
double &bps_L2,
double &percentage);
+
+ /**
+ * set port promiscuous on/off
+ *
+ * @param enabled
+ */
+ void set_promiscuous(bool enabled);
+ bool get_promiscuous();
+
private: