OpenCores
URL https://opencores.org/ocsvn/1g_ethernet_dpi/1g_ethernet_dpi/trunk

Subversion Repositories 1g_ethernet_dpi

[/] [1g_ethernet_dpi/] [trunk/] [hw/] [src/] [tb/] [bfm_eth_log/] [bfm_eth_log_cl.sv] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 kuzmi4
//////////////////////////////////////////////////////////////////////////////////
2
// Company:
3
// Engineer:        IK
4
//
5
// Create Date:     11:35:01 03/21/2013
6
// Design Name:
7
// Module Name:     bfm_eth_log_cl
8
// Project Name:
9
// Target Devices:
10
// Tool versions:
11
// Description:
12
//
13
//
14
// Revision:
15
// Revision 0.01 - File Created,
16
//
17
//////////////////////////////////////////////////////////////////////////////////
18
`timescale 1ns / 1ps
19
 
20
typedef virtual interface rgmii_rx_if virt_rx_if_t;
21
 
22
class bfm_eth_log_cl;
23
//////////////////////////////////////////////////////////////////////////////////
24
    //
25
    virt_rx_if_t    vif_rx;
26
    virt_rx_if_t    vif_tx;
27
    //
28
    string          name;
29
    bit             verbose;
30
    //
31
    int             fd, fd_idx;
32
    pcap_pkg::u_pcap_hdr_t      sv_pcap_hdr_u;
33
    pcap_pkg::u_pcaprec_hdr_t   sv_pcaprec_hdr_u;
34
    //
35
    static int idx=0;
36
 
37
//////////////////////////////////////////////////////////////////////////////////
38
 
39
static function int next_id;
40
    next_id = idx++;
41
endfunction : next_id
42
 
43
function new (string name = "logger", virt_rx_if_t rx, virt_rx_if_t tx, bit i_verbose=0);
44
    string str;
45
    // name
46
    str.itoa(next_id());
47
    this.name = {name, "#" ,str};
48
    this.verbose = i_verbose;
49
    //
50
    this.fd = 0; this.fd_idx = 0;
51
    // fill-in pcap_hdr
52
    sv_pcap_hdr_u.pcap_hdr.magic_number = 32'ha1b2c3d4;
53
    sv_pcap_hdr_u.pcap_hdr.version_major = 2;
54
    sv_pcap_hdr_u.pcap_hdr.version_minor = 4;
55
    sv_pcap_hdr_u.pcap_hdr.thiszone = 0;
56
    sv_pcap_hdr_u.pcap_hdr.sigfigs = 0;
57
    sv_pcap_hdr_u.pcap_hdr.snaplen = 256*1024; // 256KB
58
    sv_pcap_hdr_u.pcap_hdr.network = 1;
59
    // if
60
    this.vif_rx = rx;
61
    this.vif_tx = tx;
62
    // Final
63
endfunction : new
64
 
65
//////////////////////////////////////////////////////////////////////////////////
66
 
67
task init;
68
    vif_rx.init();
69
    vif_tx.init();
70
    $display("%s ready", this.name);
71
    // Final
72
endtask : init
73
 
74
task log_run;
75
    // dec var
76
    int rx_pkt_len, tx_pkt_len;
77
    // if we are in RUN
78
    if (fd_idx)
79
        begin   :   _RE
80
            $fclose(fd);
81
            $display("[%t]: %m: re-open PCAP, last frm can be dropped!", $time);
82
        end
83
    // pcap-open
84
    fd = $fopen($sformatf("%s_%02d.pcap", name, fd_idx++), "wb");
85
    // write pcap-hdr
86
    for (int i = 0; i < pcap_pkg::pcap_hdr_sz; i++)
87
        $fwrite(fd, "%c", 8'(sv_pcap_hdr_u.data[i]));
88
    // sta RX-LOG
89
    fork
90
        forever
91
            begin   :   LOG_RX
92
                // get ETH-pkt
93
                vif_rx.rx_pkt();
94
                // get pkt-id
95
                rx_pkt_len = vif_rx.rx_pkt_len();
96
                // prep-hdr
97
                sv_pcaprec_hdr_u.pcaprec_hdr.ts_sec     =   ($time/1_000_000);
98
                sv_pcaprec_hdr_u.pcaprec_hdr.ts_usec    =   ($time%1_000_000);
99
                sv_pcaprec_hdr_u.pcaprec_hdr.incl_len   =   rx_pkt_len;
100
                sv_pcaprec_hdr_u.pcaprec_hdr.orig_len   =   rx_pkt_len;
101
                // wr-hdr
102
                for (int i = 0; i < pcap_pkg::pcaprec_hdr_sz; i++)
103
                     $fwrite(fd, "%c", 8'(sv_pcaprec_hdr_u.data[i]));
104
                // wr-data
105
                for (int i = 0; i < rx_pkt_len; i++)
106
                    $fwrite(fd, "%c", 8'(vif_rx.rx_pkt_data(i)));
107
                //
108
                if (verbose)
109
                    $display("[%t]: %m: rx-pkt_len=%h", $time, rx_pkt_len);
110
            end
111
    join_none
112
    // sta TX-LOG
113
    fork
114
        forever
115
            begin   :   LOG_TX
116
                // get ETH-pkt
117
                vif_tx.rx_pkt();
118
                // get pkt-id
119
                tx_pkt_len = vif_tx.rx_pkt_len();
120
                // prep-hdr
121
                sv_pcaprec_hdr_u.pcaprec_hdr.ts_sec     =   ($time/1_000_000);
122
                sv_pcaprec_hdr_u.pcaprec_hdr.ts_usec    =   ($time%1_000_000);
123
                sv_pcaprec_hdr_u.pcaprec_hdr.incl_len   =   tx_pkt_len;
124
                sv_pcaprec_hdr_u.pcaprec_hdr.orig_len   =   tx_pkt_len;
125
                // wr-hdr
126
                for (int i = 0; i < pcap_pkg::pcaprec_hdr_sz; i++)
127
                     $fwrite(fd, "%c", 8'(sv_pcaprec_hdr_u.data[i]));
128
                // wr-data
129
                for (int i = 0; i < tx_pkt_len; i++)
130
                    $fwrite(fd, "%c", 8'(vif_tx.rx_pkt_data(i)));
131
                //
132
                if (verbose)
133
                    $display("[%t]: %m: tx-pkt_len=%h", $time, tx_pkt_len);
134
            end
135
    join_none
136
    //
137
endtask : log_run
138
 
139
task log_stop;
140
    if (fd)
141
        begin   :   STOP_LOG
142
            // close pcap-file
143
            $fclose(fd); fd = 0;
144
            // fd=INVALID, so we must stop logging NOW
145
            disable log_run;
146
        end
147
endtask : log_stop
148
//////////////////////////////////////////////////////////////////////////////////
149
endclass : bfm_eth_log_cl

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.