summaryrefslogtreecommitdiffstats
path: root/src/pre_test.h
blob: 7bbeb40d0cc55bb7f5d0586139fad19e6d925674 (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
/*
  Ido Barnea
  Cisco Systems, Inc.
*/

/*
  Copyright (c) 2016-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 __PRE_TEST_H__
#define __PRE_TEST_H__

#include <iostream>
#include <common/Network/Packet/Arp.h>
#include "bp_sim.h"
#include "trex_defs.h"

class CPretestPortInfo {
    friend class CPretest;
    
 private:
    enum CPretestPortInfoStates {
        INIT_NEEDED,
        RESOLVE_NEEDED,
        RESOLVE_DONE,
        RESOLVE_NOT_NEEDED,
    };

    CPretestPortInfo() {
        m_state = INIT_NEEDED;
        m_is_loopback = false;
    }
    void dump(FILE *fd);
    uint8_t *create_arp_req(uint16_t &pkt_size, uint8_t port, bool is_grat);
    void set_params(CPerPortIPCfg port_cfg, const uint8_t *src_mac, bool resolve_needed);
    void set_dst_mac(const uint8_t *dst_mac);
    
 private:
    uint32_t m_ip;
    uint32_t m_def_gw;
    uint16_t m_vlan;
    uint8_t m_src_mac[6];
    uint8_t m_dst_mac[6];
    enum CPretestPortInfoStates m_state;
    bool m_is_loopback;
};


class CPretest {
 public:
    CPretest(uint16_t max_ports) {
        m_max_ports = max_ports;
    }
    bool get_mac(uint16_t port, uint32_t ip, uint8_t *mac);
    bool is_loopback(uint16_t port);
    void set_port_params(uint16_t port_id, const CPerPortIPCfg &port_cfg, const uint8_t *src_mac, bool resolve_needed);
    bool resolve_all();
    void send_arp_req(uint16_t port, bool is_grat);
    void send_grat_arp_all();
    bool is_arp(const uint8_t *p, uint16_t pkt_size, ArpHdr *&arp);
    void dump(FILE *fd);
    void test();
    
 private:
    int handle_rx(int port, int queue_id);

 private:
    CPretestPortInfo m_port_info[TREX_MAX_PORTS];
    uint16_t m_max_ports;
};

#endif