summaryrefslogtreecommitdiffstats
path: root/src/stateless/rx/trex_stateless_capture_rc.h
blob: 12b37c1da4d7264e896a8a8f60aad1ebb1d14d89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
 Itay Marom
 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.
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 __TREX_STATELESS_CAPTURE_RC_H__
#define __TREX_STATELESS_CAPTURE_RC_H__

typedef int32_t capture_id_t;

/**
 * a base class for a capture command RC 
 * not to be used directly 
 */
class TrexCaptureRC {
    
protected:
    /* cannot instantiate this object from outside */
    TrexCaptureRC() {
        m_rc = RC_INVALID;
    }

public:

    /**
     * error types for commands
     */
    enum rc_e {
        RC_INVALID = 0,
        RC_OK = 1,
        RC_CAPTURE_NOT_FOUND,
        RC_CAPTURE_LIMIT_REACHED,
        RC_CAPTURE_FETCH_UNDER_ACTIVE
    };

    bool operator !() const {
        return (m_rc != RC_OK);
    }
    
    std::string get_err() const {
        assert(m_rc != RC_INVALID);
        
        switch (m_rc) {
        case RC_OK:
            return "";
        case RC_CAPTURE_LIMIT_REACHED:
            return "capture limit has reached";
        case RC_CAPTURE_NOT_FOUND:
            return "capture ID not found";
        case RC_CAPTURE_FETCH_UNDER_ACTIVE:
            return "fetch command cannot be executed on an active capture";
        case RC_INVALID:
            /* should never be called under invalid */
            assert(0);
            
        default:
            assert(0);
        }
    }
    
    void set_err(rc_e rc) {
        m_rc = rc;
    }
    
    
protected:
    rc_e m_rc;
};

/**
 * return code for executing capture start
 */
class TrexCaptureRCStart : public TrexCaptureRC {
public:

    void set_rc(capture_id_t new_id, dsec_t start_ts) {
        m_capture_id  = new_id;
        m_start_ts    = start_ts;
        m_rc          = RC_OK;
    }
    
    capture_id_t get_new_id() const {
        assert(m_rc == RC_OK);
        return m_capture_id;
    }
    
    dsec_t get_start_ts() const {
        assert(m_rc == RC_OK);
        return m_start_ts;
    }
    
private:
    capture_id_t  m_capture_id;
    dsec_t        m_start_ts;
};

/**
 * return code for exectuing capture stop
 */
class TrexCaptureRCStop : public TrexCaptureRC {
public:
    
    void set_rc(uint32_t pkt_count) {
        m_pkt_count = pkt_count;
        m_rc        = RC_OK;
    }
    
    uint32_t get_pkt_count() const {
        assert(m_rc == RC_OK);
        return m_pkt_count;
    }
    
private:
    uint32_t m_pkt_count;
};

/**
 * return code for executing capture fetch
 */
class TrexCaptureRCFetch : public TrexCaptureRC {
public:

    void set_rc(const TrexPktBuffer *pkt_buffer, uint32_t pending, dsec_t start_ts) {
        m_pkt_buffer  = pkt_buffer;
        m_pending     = pending;
        m_start_ts    = start_ts;
        m_rc          = RC_OK;
    }
    
    const TrexPktBuffer *get_pkt_buffer() const {
        assert(m_rc == RC_OK);
        return m_pkt_buffer;
    }
    
    uint32_t get_pending() const {
        assert(m_rc == RC_OK);
        return m_pending;
    }
    
    dsec_t get_start_ts() const {
        assert(m_rc == RC_OK);
        return m_start_ts;
    }
    
private:
    const TrexPktBuffer *m_pkt_buffer;
    uint32_t             m_pending;
    dsec_t               m_start_ts;
};



class TrexCaptureRCRemove : public TrexCaptureRC {
public:
    void set_rc() {
        m_rc = RC_OK;
    }
};


class TrexCaptureRCStatus : public TrexCaptureRC {
public:
    
    void set_rc(const Json::Value &json) {
        m_json = json;
        m_rc   = RC_OK;
    }
    
    const Json::Value & get_status() const {
        assert(m_rc == RC_OK);
        return m_json;
    }
    
private:
    Json::Value m_json;
};


#endif /* __TREX_STATELESS_CAPTURE_RC_H__ */