summaryrefslogtreecommitdiffstats
path: root/src/trex_port_attr.h
diff options
context:
space:
mode:
authorYaroslav Brustinov <ybrustin@cisco.com>2016-10-28 14:32:05 +0200
committerYaroslav Brustinov <ybrustin@cisco.com>2016-10-28 14:39:56 +0200
commit111bd3664b91279883d9f8e2483e436cbdcf3d38 (patch)
treeaabbd949a315e5551903e6febd4c0460216d9636 /src/trex_port_attr.h
parent1016c3d481dc9e2eb9ab03332aff441c03239614 (diff)
move port_attr from driver class to physical port class + small fixes according to code review
Signed-off-by: Yaroslav Brustinov <ybrustin@cisco.com>
Diffstat (limited to 'src/trex_port_attr.h')
-rwxr-xr-xsrc/trex_port_attr.h164
1 files changed, 110 insertions, 54 deletions
diff --git a/src/trex_port_attr.h b/src/trex_port_attr.h
index cc267104..9231e263 100755
--- a/src/trex_port_attr.h
+++ b/src/trex_port_attr.h
@@ -25,83 +25,139 @@ limitations under the License.
class TRexPortAttr {
public:
- TRexPortAttr(uint8_t total_ports, bool is_virtual, bool fc_change_allowed) : total_ports(total_ports) {
- flag_is_virtual = is_virtual;
- m_link.resize(total_ports);
- intf_info_st.resize(total_ports);
- dev_info.resize(total_ports);
- int tmp;
- flag_is_fc_change_supported = fc_change_allowed && (get_flow_ctrl(0, tmp) != -ENOTSUP);
- flag_is_led_change_supported = (set_led(0, true) != -ENOTSUP);
- flag_is_link_change_supported = (set_link_up(0, true) != -ENOTSUP);
- update_descriptions();
- for (int i=0; i<total_ports; i++) {
- update_device_info(i);
- }
- }
+ virtual ~TRexPortAttr(){}
/* UPDATES */
- virtual void update_link_status(uint8_t port_id);
- virtual bool update_link_status_nowait(uint8_t port_id); // returns true if the status was changed
- virtual void update_device_info(uint8_t port_id);
- virtual void reset_xstats(uint8_t port_id);
- virtual void update_descriptions();
+ virtual void update_link_status() = 0;
+ virtual bool update_link_status_nowait() = 0; // returns true if the status was changed
+ virtual void update_device_info() = 0;
+ virtual void reset_xstats() = 0;
+ virtual void update_description() = 0;
/* GETTERS */
- virtual bool get_promiscuous(uint8_t port_id);
- virtual void macaddr_get(uint8_t port_id, struct ether_addr *mac_addr);
- virtual uint32_t get_link_speed(uint8_t port_id) { return m_link[port_id].link_speed; } // L1 Mbps
- virtual bool is_link_duplex(uint8_t port_id) { return (m_link[port_id].link_duplex ? true : false); }
- virtual bool is_link_autoneg(uint8_t port_id) { return (m_link[port_id].link_autoneg ? true : false); }
- virtual bool is_link_up(uint8_t port_id) { return (m_link[port_id].link_status ? true : false); }
- virtual int get_xstats_values(uint8_t port_id, xstats_values_t &xstats_values);
- virtual int get_xstats_names(uint8_t port_id, xstats_names_t &xstats_names);
- virtual int get_flow_ctrl(uint8_t port_id, int &mode);
+ virtual bool get_promiscuous() = 0;
+ virtual void macaddr_get(struct ether_addr *mac_addr) = 0;
+ virtual uint32_t get_link_speed() { return m_link.link_speed; } // L1 Mbps
+ virtual bool is_link_duplex() { return (m_link.link_duplex ? true : false); }
+ virtual bool is_link_autoneg() { return (m_link.link_autoneg ? true : false); }
+ virtual bool is_link_up() { return (m_link.link_status ? true : false); }
+ virtual int get_xstats_values(xstats_values_t &xstats_values) = 0;
+ virtual int get_xstats_names(xstats_names_t &xstats_names) = 0;
+ virtual int get_flow_ctrl(int &mode) = 0;
virtual bool is_virtual() { return flag_is_virtual; }
virtual bool is_fc_change_supported() { return flag_is_fc_change_supported; }
virtual bool is_led_change_supported() { return flag_is_led_change_supported; }
virtual bool is_link_change_supported() { return flag_is_link_change_supported; }
- virtual void get_description(uint8_t port_id, std::string &description) { description = intf_info_st[port_id].description; }
- virtual void get_supported_speeds(uint8_t port_id, supp_speeds_t &supp_speeds);
+ virtual void get_description(std::string &description) { description = intf_info_st.description; }
+ virtual void get_supported_speeds(supp_speeds_t &supp_speeds) = 0;
/* SETTERS */
- virtual int set_promiscuous(uint8_t port_id, bool enabled);
- virtual int add_mac(uint8_t port_id, char * mac);
- virtual int set_link_up(uint8_t port_id, bool up);
- virtual int set_flow_ctrl(uint8_t port_id, int mode);
- virtual int set_led(uint8_t port_id, bool on);
-
+ virtual int set_promiscuous(bool enabled) = 0;
+ virtual int add_mac(char * mac) = 0;
+ virtual int set_link_up(bool up) = 0;
+ virtual int set_flow_ctrl(int mode) = 0;
+ virtual int set_led(bool on) = 0;
/* DUMPS */
- virtual void dump_link(uint8_t port_id, FILE *fd);
+ virtual void dump_link(FILE *fd) = 0;
-private:
- const uint8_t total_ports;
- rte_eth_fc_conf fc_conf_tmp;
- std::vector<rte_eth_link> m_link;
- std::vector<struct rte_eth_dev_info> dev_info;
- std::vector<struct rte_eth_xstat> xstats_values_tmp;
- std::vector<struct rte_eth_xstat_name> xstats_names_tmp;
+protected:
+ uint8_t m_port_id;
+ rte_eth_link m_link;
+ struct rte_eth_dev_info dev_info;
bool flag_is_virtual;
bool flag_is_fc_change_supported;
bool flag_is_led_change_supported;
bool flag_is_link_change_supported;
- struct mac_cfg_st {
- uint8_t hw_macaddr[6];
- uint8_t src_macaddr[6];
- uint8_t dst_macaddr[6];
- };
-
- struct intf_info_st_type {
- mac_cfg_st mac_info;
+ struct intf_info_st {
std::string pci_addr;
std::string description;
int numa_node;
- };
+ }intf_info_st;
+
+};
+
+class DpdkTRexPortAttr : public TRexPortAttr {
+public:
+
+ DpdkTRexPortAttr(uint8_t port_id, bool is_virtual, bool fc_change_allowed) {
+ m_port_id = port_id;
+ flag_is_virtual = is_virtual;
+ int tmp;
+ flag_is_fc_change_supported = fc_change_allowed && (get_flow_ctrl(tmp) != -ENOTSUP);
+ flag_is_led_change_supported = (set_led(true) != -ENOTSUP);
+ flag_is_link_change_supported = (set_link_up(true) != -ENOTSUP);
+ update_description();
+ update_device_info();
+ }
+
+/* UPDATES */
+ virtual void update_link_status();
+ virtual bool update_link_status_nowait(); // returns true if the status was changed
+ virtual void update_device_info();
+ virtual void reset_xstats();
+ virtual void update_description();
+
+/* GETTERS */
+ virtual bool get_promiscuous();
+ virtual void macaddr_get(struct ether_addr *mac_addr);
+ virtual int get_xstats_values(xstats_values_t &xstats_values);
+ virtual int get_xstats_names(xstats_names_t &xstats_names);
+ virtual int get_flow_ctrl(int &mode);
+ virtual void get_supported_speeds(supp_speeds_t &supp_speeds);
+
+/* SETTERS */
+ virtual int set_promiscuous(bool enabled);
+ virtual int add_mac(char * mac);
+ virtual int set_link_up(bool up);
+ virtual int set_flow_ctrl(int mode);
+ virtual int set_led(bool on);
+
+
+/* DUMPS */
+ virtual void dump_link(FILE *fd);
- std::vector <intf_info_st_type> intf_info_st;
+private:
+ rte_eth_fc_conf fc_conf_tmp;
+ std::vector <struct rte_eth_xstat> xstats_values_tmp;
+ std::vector <struct rte_eth_xstat_name> xstats_names_tmp;
+
+};
+
+
+class SimTRexPortAttr : public TRexPortAttr {
+public:
+ SimTRexPortAttr() {
+ m_link.link_speed = 10000;
+ m_link.link_duplex = 1;
+ m_link.link_autoneg = 0;
+ m_link.link_status = 1;
+ flag_is_virtual = true;
+ flag_is_fc_change_supported = false;
+ flag_is_led_change_supported = false;
+ flag_is_link_change_supported = false;
+ }
+ /* DUMMY */
+ void update_link_status() {}
+ bool update_link_status_nowait() { return false; }
+ void update_device_info() {}
+ void reset_xstats() {}
+ void update_description() {}
+ bool get_promiscuous() { return false; }
+ void macaddr_get(struct ether_addr *mac_addr) {}
+ int get_xstats_values(xstats_values_t &xstats_values) { return -ENOTSUP; }
+ int get_xstats_names(xstats_names_t &xstats_names) { return -ENOTSUP; }
+ int get_flow_ctrl(int &mode) { return -ENOTSUP; }
+ void get_description(std::string &description) {}
+ void get_supported_speeds(supp_speeds_t &supp_speeds) {}
+ int set_promiscuous(bool enabled) { return -ENOTSUP; }
+ int add_mac(char * mac) { return -ENOTSUP; }
+ int set_link_up(bool up) { return -ENOTSUP; }
+ int set_flow_ctrl(int mode) { return -ENOTSUP; }
+ int set_led(bool on) { return -ENOTSUP; }
+ void dump_link(FILE *fd) {}
};