trex_port_attr.h revision 111bd366
1/*
2Copyright (c) 2015-2015 Cisco Systems, Inc.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#ifndef __TREX_PORT_ATTR_H__
18#define __TREX_PORT_ATTR_H__
19
20#include <string>
21#include <vector>
22#include "rte_ethdev_includes.h"
23#include "trex_defs.h"
24
25
26class TRexPortAttr {
27public:
28    virtual ~TRexPortAttr(){}
29
30/*    UPDATES    */
31    virtual void update_link_status() = 0;
32    virtual bool update_link_status_nowait() = 0; // returns true if the status was changed
33    virtual void update_device_info() = 0;
34    virtual void reset_xstats() = 0;
35    virtual void update_description() = 0;
36
37/*    GETTERS    */
38    virtual bool get_promiscuous() = 0;
39    virtual void macaddr_get(struct ether_addr *mac_addr) = 0;
40    virtual uint32_t get_link_speed() { return m_link.link_speed; } // L1 Mbps
41    virtual bool is_link_duplex() { return (m_link.link_duplex ? true : false); }
42    virtual bool is_link_autoneg() { return (m_link.link_autoneg ? true : false); }
43    virtual bool is_link_up() { return (m_link.link_status ? true : false); }
44    virtual int get_xstats_values(xstats_values_t &xstats_values) = 0;
45    virtual int get_xstats_names(xstats_names_t &xstats_names) = 0;
46    virtual int get_flow_ctrl(int &mode) = 0;
47    virtual bool is_virtual() { return flag_is_virtual; }
48    virtual bool is_fc_change_supported() { return flag_is_fc_change_supported; }
49    virtual bool is_led_change_supported() { return flag_is_led_change_supported; }
50    virtual bool is_link_change_supported() { return flag_is_link_change_supported; }
51    virtual void get_description(std::string &description) { description = intf_info_st.description; }
52    virtual void get_supported_speeds(supp_speeds_t &supp_speeds) = 0;
53
54/*    SETTERS    */
55    virtual int set_promiscuous(bool enabled) = 0;
56    virtual int add_mac(char * mac) = 0;
57    virtual int set_link_up(bool up) = 0;
58    virtual int set_flow_ctrl(int mode) = 0;
59    virtual int set_led(bool on) = 0;
60
61/*    DUMPS    */
62    virtual void dump_link(FILE *fd) = 0;
63
64protected:
65    uint8_t m_port_id;
66    rte_eth_link m_link;
67    struct rte_eth_dev_info dev_info;
68    bool flag_is_virtual;
69    bool flag_is_fc_change_supported;
70    bool flag_is_led_change_supported;
71    bool flag_is_link_change_supported;
72
73    struct intf_info_st {
74        std::string     pci_addr;
75        std::string     description;
76        int             numa_node;
77    }intf_info_st;
78
79};
80
81class DpdkTRexPortAttr : public TRexPortAttr {
82public:
83
84    DpdkTRexPortAttr(uint8_t port_id, bool is_virtual, bool fc_change_allowed) {
85        m_port_id = port_id;
86        flag_is_virtual = is_virtual;
87        int tmp;
88        flag_is_fc_change_supported = fc_change_allowed && (get_flow_ctrl(tmp) != -ENOTSUP);
89        flag_is_led_change_supported = (set_led(true) != -ENOTSUP);
90        flag_is_link_change_supported = (set_link_up(true) != -ENOTSUP);
91        update_description();
92        update_device_info();
93    }
94
95/*    UPDATES    */
96    virtual void update_link_status();
97    virtual bool update_link_status_nowait(); // returns true if the status was changed
98    virtual void update_device_info();
99    virtual void reset_xstats();
100    virtual void update_description();
101
102/*    GETTERS    */
103    virtual bool get_promiscuous();
104    virtual void macaddr_get(struct ether_addr *mac_addr);
105    virtual int get_xstats_values(xstats_values_t &xstats_values);
106    virtual int get_xstats_names(xstats_names_t &xstats_names);
107    virtual int get_flow_ctrl(int &mode);
108    virtual void get_supported_speeds(supp_speeds_t &supp_speeds);
109
110/*    SETTERS    */
111    virtual int set_promiscuous(bool enabled);
112    virtual int add_mac(char * mac);
113    virtual int set_link_up(bool up);
114    virtual int set_flow_ctrl(int mode);
115    virtual int set_led(bool on);
116
117
118/*    DUMPS    */
119    virtual void dump_link(FILE *fd);
120
121private:
122    rte_eth_fc_conf fc_conf_tmp;
123    std::vector <struct rte_eth_xstat> xstats_values_tmp;
124    std::vector <struct rte_eth_xstat_name> xstats_names_tmp;
125
126};
127
128
129class SimTRexPortAttr : public TRexPortAttr {
130public:
131    SimTRexPortAttr() {
132        m_link.link_speed   = 10000;
133        m_link.link_duplex  = 1;
134        m_link.link_autoneg = 0;
135        m_link.link_status  = 1;
136        flag_is_virtual = true;
137        flag_is_fc_change_supported = false;
138        flag_is_led_change_supported = false;
139        flag_is_link_change_supported = false;
140    }
141
142    /* DUMMY */
143    void update_link_status() {}
144    bool update_link_status_nowait() { return false; }
145    void update_device_info() {}
146    void reset_xstats() {}
147    void update_description() {}
148    bool get_promiscuous() { return false; }
149    void macaddr_get(struct ether_addr *mac_addr) {}
150    int get_xstats_values(xstats_values_t &xstats_values) { return -ENOTSUP; }
151    int get_xstats_names(xstats_names_t &xstats_names) { return -ENOTSUP; }
152    int get_flow_ctrl(int &mode) { return -ENOTSUP; }
153    void get_description(std::string &description) {}
154    void get_supported_speeds(supp_speeds_t &supp_speeds) {}
155    int set_promiscuous(bool enabled) { return -ENOTSUP; }
156    int add_mac(char * mac) { return -ENOTSUP; }
157    int set_link_up(bool up) { return -ENOTSUP; }
158    int set_flow_ctrl(int mode) { return -ENOTSUP; }
159    int set_led(bool on) { return -ENOTSUP; }
160    void dump_link(FILE *fd) {}
161};
162
163
164#endif /* __TREX_PORT_ATTR_H__ */
165