trex_port_attr.h revision 234779fd
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    virtual std::string get_rx_filter_mode() {
55        switch (m_rx_filter_mode) {
56        case RX_FILTER_MODE_ALL:
57            return "all";
58        case RX_FILTER_MODE_HW:
59            return "hw";
60        default:
61            assert(0);
62        }
63    }
64
65
66/*    SETTERS    */
67    virtual int set_promiscuous(bool enabled) = 0;
68    virtual int add_mac(char * mac) = 0;
69    virtual int set_link_up(bool up) = 0;
70    virtual int set_flow_ctrl(int mode) = 0;
71    virtual int set_led(bool on) = 0;
72    virtual int set_rx_filter_mode(rx_filter_mode_e mode) = 0;
73
74/*    DUMPS    */
75    virtual void dump_link(FILE *fd) = 0;
76
77protected:
78    uint8_t m_port_id;
79    rte_eth_link m_link;
80    struct rte_eth_dev_info dev_info;
81
82    rx_filter_mode_e m_rx_filter_mode;
83
84    bool flag_is_virtual;
85    bool flag_is_fc_change_supported;
86    bool flag_is_led_change_supported;
87    bool flag_is_link_change_supported;
88
89
90    struct intf_info_st {
91        std::string     pci_addr;
92        std::string     description;
93        int             numa_node;
94    }intf_info_st;
95
96};
97
98class DpdkTRexPortAttr : public TRexPortAttr {
99public:
100
101    DpdkTRexPortAttr(uint8_t port_id, bool is_virtual, bool fc_change_allowed) {
102
103        m_port_id = port_id;
104        m_rx_filter_mode = RX_FILTER_MODE_HW;
105
106        flag_is_virtual = is_virtual;
107        int tmp;
108        flag_is_fc_change_supported = fc_change_allowed && (get_flow_ctrl(tmp) != -ENOTSUP);
109        flag_is_led_change_supported = (set_led(true) != -ENOTSUP);
110        flag_is_link_change_supported = (set_link_up(true) != -ENOTSUP);
111        update_description();
112        update_device_info();
113    }
114
115/*    UPDATES    */
116    virtual void update_link_status();
117    virtual bool update_link_status_nowait(); // returns true if the status was changed
118    virtual void update_device_info();
119    virtual void reset_xstats();
120    virtual void update_description();
121
122/*    GETTERS    */
123    virtual bool get_promiscuous();
124    virtual void macaddr_get(struct ether_addr *mac_addr);
125    virtual int get_xstats_values(xstats_values_t &xstats_values);
126    virtual int get_xstats_names(xstats_names_t &xstats_names);
127    virtual int get_flow_ctrl(int &mode);
128    virtual void get_supported_speeds(supp_speeds_t &supp_speeds);
129
130/*    SETTERS    */
131    virtual int set_promiscuous(bool enabled);
132    virtual int add_mac(char * mac);
133    virtual int set_link_up(bool up);
134    virtual int set_flow_ctrl(int mode);
135    virtual int set_led(bool on);
136
137    virtual int set_rx_filter_mode(rx_filter_mode_e mode);
138
139/*    DUMPS    */
140    virtual void dump_link(FILE *fd);
141
142private:
143    rte_eth_fc_conf fc_conf_tmp;
144    std::vector <struct rte_eth_xstat> xstats_values_tmp;
145    std::vector <struct rte_eth_xstat_name> xstats_names_tmp;
146
147};
148
149
150class SimTRexPortAttr : public TRexPortAttr {
151public:
152    SimTRexPortAttr() {
153        m_link.link_speed   = 10000;
154        m_link.link_duplex  = 1;
155        m_link.link_autoneg = 0;
156        m_link.link_status  = 1;
157        flag_is_virtual = true;
158        flag_is_fc_change_supported = false;
159        flag_is_led_change_supported = false;
160        flag_is_link_change_supported = false;
161    }
162
163    /* DUMMY */
164    void update_link_status() {}
165    bool update_link_status_nowait() { return false; }
166    void update_device_info() {}
167    void reset_xstats() {}
168    void update_description() {}
169    bool get_promiscuous() { return false; }
170    void macaddr_get(struct ether_addr *mac_addr) {}
171    int get_xstats_values(xstats_values_t &xstats_values) { return -ENOTSUP; }
172    int get_xstats_names(xstats_names_t &xstats_names) { return -ENOTSUP; }
173    int get_flow_ctrl(int &mode) { return -ENOTSUP; }
174    void get_description(std::string &description) {}
175    void get_supported_speeds(supp_speeds_t &supp_speeds) {}
176    int set_promiscuous(bool enabled) { return -ENOTSUP; }
177    int add_mac(char * mac) { return -ENOTSUP; }
178    int set_link_up(bool up) { return -ENOTSUP; }
179    int set_flow_ctrl(int mode) { return -ENOTSUP; }
180    int set_led(bool on) { return -ENOTSUP; }
181    void dump_link(FILE *fd) {}
182    int set_rx_filter_mode(rx_filter_mode_e mode) { return -ENOTSUP; }
183};
184
185
186#endif /* __TREX_PORT_ATTR_H__ */
187