OpenCores
URL https://opencores.org/ocsvn/xge_mac/xge_mac/trunk

Subversion Repositories xge_mac

[/] [xge_mac/] [trunk/] [tbench/] [systemc/] [sc_pkt_generator.cpp] - Blame information for rev 19

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 antanguay
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  File name "sc_pkt_generator.cpp"                            ////
4
////                                                              ////
5
////  This file is part of the "10GE MAC" project                 ////
6
////  http://www.opencores.org/cores/xge_mac/                     ////
7
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - A. Tanguay (antanguay@opencores.org)                  ////
10
////                                                              ////
11
//////////////////////////////////////////////////////////////////////
12
////                                                              ////
13
//// Copyright (C) 2008 AUTHORS. All rights reserved.             ////
14
////                                                              ////
15
//// This source file may be used and distributed without         ////
16
//// restriction provided that this copyright statement is not    ////
17
//// removed from the file and that any derivative work contains  ////
18
//// the original copyright notice and the associated disclaimer. ////
19
////                                                              ////
20
//// This source file is free software; you can redistribute it   ////
21
//// and/or modify it under the terms of the GNU Lesser General   ////
22
//// Public License as published by the Free Software Foundation; ////
23
//// either version 2.1 of the License, or (at your option) any   ////
24
//// later version.                                               ////
25
////                                                              ////
26
//// This source is distributed in the hope that it will be       ////
27
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
28
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
29
//// PURPOSE.  See the GNU Lesser General Public License for more ////
30
//// details.                                                     ////
31
////                                                              ////
32
//// You should have received a copy of the GNU Lesser General    ////
33
//// Public License along with this source; if not, download it   ////
34
//// from http://www.opencores.org/lgpl.shtml                     ////
35
////                                                              ////
36
//////////////////////////////////////////////////////////////////////
37
 
38
#include <stdio.h>
39
#include <iostream>
40
#include <sys/times.h>
41
#include <sys/stat.h>
42
 
43
#include "systemc.h"
44
 
45
#include "sc_pkt_generator.h"
46
 
47
 
48
void pkt_generator::init(void) {
49
    crc_interval = 0;
50
    fragment_interval = 0;
51
    coding_interval = 0;
52
    local_fault_interval = 0;
53
    remote_fault_interval = 0;
54
}
55
 
56
void pkt_generator::connect_fifo(sc_fifo<packet_t*> * fifo) {
57
    tx_fifo = fifo;
58
}
59
 
60
 
61
void pkt_generator::gen_packet() {
62
 
63
    int len = 0;
64
    int crc_int = 0;
65
    int fragment_int = 0;
66
    int coding_int = 0;
67
    int local_fault_int = 0;
68
    int remote_fault_int = 0;
69
    int fault_spacing = 120;
70
    int pause_int = 0;
71
    char running_cnt = 0;
72
 
73
    while (true) {
74
 
75
        wait(5, SC_NS);
76
 
77
        if (tx_bucket != 0 && tx_fifo->num_available() == 0) {
78
 
79
            //--
80
            // Check fifo
81
 
82
            if (tx_fifo == NULL || tx_fifo->num_free() == 0) {
83
                cout << "ERROR: FIFO not defined or full" << endl;
84
                sc_stop();
85
            }
86
 
87
            //---
88
            // Update constraints
89
 
90
            if (len < min_pkt_size) {
91
                len = min_pkt_size;
92
            }
93
 
94
            if (len > max_pkt_size) {
95
                len = min_pkt_size;
96
            }
97
 
98
            //--
99
            // Generate packet
100
 
101
            packet_t* pkt = new(packet_t);
102
 
103
            for (int i = 0; i < len+8; i++) {
104
                pkt->payload[i] = len+i;
105
            }
106
            pkt->payload[0] = running_cnt;
107
            running_cnt++;
108
 
109
            pkt->length = len;
110
 
111
            //---
112
            // Inject errors
113
 
114
            if (crc_interval != 0) {
115
                if (crc_int >= crc_interval) {
116
                    pkt->err_flags |= PKT_FLAG_ERR_CRC;
117
                    crc_int = 0;
118
                }
119
                else {
120
                    crc_int++;
121
                }
122
            }
123
            else {
124
                crc_int = 0;
125
            }
126
 
127
            if (fragment_interval != 0) {
128
                if (fragment_int >= fragment_interval) {
129
                    pkt->err_flags |= PKT_FLAG_ERR_FRG;
130
                    fragment_int = 0;
131
                }
132
                else {
133
                    fragment_int++;
134
                }
135
            }
136
            else {
137
                fragment_int = 0;
138
            }
139
 
140
            if (coding_interval != 0) {
141
                if (coding_int >= coding_interval) {
142
                    pkt->err_flags |= PKT_FLAG_ERR_CODING;
143
                    coding_int = 0;
144
                }
145
                else {
146
                    coding_int++;
147
                }
148
            }
149
            else {
150
                coding_int = 0;
151
            }
152
 
153
            //--
154
            // Inject local / remote faults
155
 
156
            if (local_fault_interval != 0) {
157
                if (local_fault_int >= local_fault_interval) {
158
 
159
                    pkt->err_flags |= PKT_FLAG_LOCAL_FAULT;
160
                    local_fault_int = 0;
161
 
162
                    fault_spacing++;
163
                    if (fault_spacing > (132 - 4)) {
164
                        fault_spacing = 120;
165
                    }
166
                    pkt->err_info = fault_spacing;
167
                }
168
                else {
169
                    local_fault_int++;
170
                }
171
            }
172
            else {
173
                local_fault_int = 0;
174
            }
175
 
176
            if (remote_fault_interval != 0) {
177
                if (remote_fault_int >= remote_fault_interval) {
178
 
179
                    pkt->err_flags |= PKT_FLAG_REMOTE_FAULT;
180
                    remote_fault_int = 0;
181
 
182
                    fault_spacing++;
183
                    if (fault_spacing > (132 - 4)) {
184
                        fault_spacing = 120;
185
                    }
186
                    pkt->err_info = fault_spacing;
187
                }
188
                else {
189
                    remote_fault_int++;
190
                }
191
            }
192
            else {
193
                remote_fault_int = 0;
194
            }
195
 
196
            //--
197
            // Inject PAUSE frames
198
 
199
            if (inject_pause_interval != 0) {
200
                if (pause_int >= inject_pause_interval) {
201
 
202
                    pkt->dest_addr = 0x0180c2;
203
                    pkt->dest_addr = (pkt->dest_addr << 24) | 0x000001;
204
                    pause_int = 0;
205
 
206
                }
207
                else {
208
                    pause_int++;
209
                }
210
            }
211
 
212
            //--
213
            // Send packet
214
 
215
            tx_fifo->write(pkt);
216
 
217
            tx_bucket--;
218
            len++;
219
 
220
        }
221
        else {
222
            wait(50, SC_NS);
223
        }
224
 
225
    }
226
}
227
 
228
void pkt_generator::set_tx_bucket(int cnt) {
229
    tx_bucket = cnt;
230
}
231
 
232
int pkt_generator::get_tx_bucket(void) {
233
    return tx_bucket;
234
}
235
 
236
void pkt_generator::set_pkt_size(int min, int max) {
237
 
238
    min_pkt_size = min;
239
    max_pkt_size = max;
240
 
241
}
242
 
243
void pkt_generator::set_crc_errors(int interval) {
244
    crc_interval = interval;
245
}
246
 
247
void pkt_generator::set_fragment_errors(int interval) {
248
    fragment_interval = interval;
249
}
250
 
251
void pkt_generator::set_coding_errors(int interval) {
252
    coding_interval = interval;
253
}
254
 
255
void pkt_generator::set_local_fault(int interval) {
256
    local_fault_interval = interval;
257
}
258
 
259
void pkt_generator::set_remote_fault(int interval) {
260
    remote_fault_interval = interval;
261
}
262
 
263
void pkt_generator::set_inject_pause(int interval) {
264
    inject_pause_interval = interval;
265
}

powered by: WebSVN 2.1.0

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