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

Subversion Repositories turbo8051

[/] [turbo8051/] [trunk/] [verif/] [agents/] [ethernet/] [tb_eth_tasks.v] - Blame information for rev 15

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 15 dinesha
 
2
 
3
/*-----------------------------------------------------------------
4
|           Ethernet MAC Testbench                                  |
5
|                                                                   |
6
------------------------------------------------------------------*/
7
 
8
/*-----------------------------------------------------------------\
9
|  DESCRIPTION:                                                    |
10
|  tb_tasks.v:  Testbench tasks included in th_top.v               |
11
|                                                                  |
12
|  Instantiated modules: none                                      |
13
|  Included files: none                                            |
14
\-----------------------------------------------------------------*/
15
 
16
 /*-------------------------------------------------------------\
17
 |                                                              |
18
 |      Tasks to set port and MAC parameters such as            |
19
 |      preamble, collision parameters, etc.                    |
20
 |                                                              |
21
 \-------------------------------------------------------------*/
22
 
23
task init_port;
24
      input [2:0] speed;
25
   input [2:0]     MII_type;
26
   input duplex_status;
27
   input IFG_length;
28
   integer IFG_length;
29
 
30
   begin
31
      if ((port_mii_type != 3'b111) &&
32
          (port_mii_type != MII_type))
33
       begin
34
          $write("testbench_init_port:  MII type_new cannot be changed once set\n");
35
          if (`TERMINATE_ON_TASK_ERRORS)
36
           $finish;
37
       end // if ((port_mii_type != 3'b111) &&...
38
      else
39
       begin
40
          port_mii_type = MII_type;
41
          port_duplex_status = duplex_status;
42
          port_speed = speed;
43
          port_min_ifg = IFG_length;
44
 
45
          // initialize port parameters to their default values
46
          port_idle_count = 0; // number of idle bits transmitted before preamble
47
          preamble_length = 64; // 64-bit preamble, including SFD
48
          preamble_reg = {64'd0,
49
                          64'hd555_5555_5555_5555}; // preamble pattern
50
 
51
          dribble_bit_count = 0; //bits buffered in PHY when carrier goes down
52
          carrier_override = 0; // Do not force carrier
53
          frame_extend_bit_count = 0; // Do not send additional bits after packet data
54
          frame_extend_reg = 32'd0; // Pattern of additional bits
55
          ignore_rcv_pause = 0; // handle received PAUSE frames normally
56
          pause_increment = 0; // Do not change received PAUSE parameter
57
          collision_detection_delay = 0;  // collision detection delay in PHY
58
          force_collision = 0; // Do not force collisions
59
          jam_length = 32; // length of jamming pattern in bits
60
 
61
          force_collision_delay = 32'd0;
62
 
63
          packet_seq_no = 32'd0; // Running sequence number for port
64
 
65
          // activate the proper MII interface
66
          case (port_mii_type)
67
            0: // Reduced MII
68
             begin
69
                RMII_port_tx_enable = 1;
70
                RMII_port_rx_enable = 1;
71
             end // case: 0
72
            1: // Full MII
73
             begin
74
                MII_port_tx_enable = 1;
75
                MII_port_rx_enable = 1;
76
             end // case: 1
77
            2: // Gigabit MII
78
             begin
79
                GMII_port_tx_enable = 1;
80
                GMII_port_rx_enable = 1;
81
             end // case: 2
82
            3: // Serial MII
83
             begin
84
                SMII_port_tx_enable = 1;
85
                SMII_port_rx_enable = 1;
86
             end // case: 3
87
            4: // custom interface
88
             begin
89
                custom_tx_enable = 1;
90
                custom_rx_enable = 1;
91
             end // case: 4
92
            5: // Gigabit 10-bit SERDES interface
93
             begin
94
                SERDES_tx_enable = 1;
95
                SERDES_rx_enable = 1;
96
             end // case: 0
97
            default:
98
             begin
99
                $write("testbench_init_port: MII type_new %0d not supported",
100
                       port_mii_type);
101
                if (`TERMINATE_ON_PARAM_ERRORS)
102
                 $finish;
103
             end // case: default
104
          endcase // case(port_mii_type)
105
       end // else: !if((port_mii_type != 3'b111) &&...
106
   end
107
endtask // testbench_init_port
108
 
109
task set_idle_count;
110
 
111
   // Sets number if idle bits sent before preamble
112
   input bit_count;
113
   integer bit_count;
114
   begin
115
      port_idle_count = bit_count;
116
   end
117
endtask // set_idle_count
118
 
119
task set_preamble;
120
 
121
   // Sets preamble length and pattern
122
   input length;
123
   input [127:0] pattern;
124
   integer length;
125
   begin
126
      preamble_length = length;
127
      preamble_reg = pattern;
128
   end
129
endtask // set_preamble
130
 
131
task set_dribble_bit_count;
132
   // Sets number of bits buffered in the PHY when carrier sense is deasserted
133
   input count;
134
   integer count;
135
   begin
136
      dribble_bit_count = count;
137
   end
138
endtask // set_dribble_bit_count
139
 
140
task set_frame_extension_bits;
141
   // Sets count of bits added to the frame to generate alignment error
142
   input count;
143
   input [31:0] pattern;
144
   integer count;
145
   begin
146
      frame_extend_bit_count = count;
147
      frame_extend_reg = pattern;
148
   end
149
endtask // set_frame_extension_bits
150
 
151
task set_carrier_sense;
152
   input value;
153
   begin
154
      carrier_override = value;
155
   end
156
endtask // set_carrier_sense
157
 
158
task set_pause_options;
159
   // Set option for handling of received PAUSE frames
160
   input option, increment;
161
   integer option, increment;
162
   begin
163
      case(option)
164
        1: // add user-supplied increment to pause parameter received
165
         begin
166
            ignore_rcv_pause = 0;
167
            pause_increment = increment;
168
         end // case: 1
169
        2: // ignore received pause frames
170
         begin
171
            ignore_rcv_pause = 1;
172
         end // case: 2
173
        default: // handle pause frames normally
174
         begin
175
            ignore_rcv_pause = 0;
176
            pause_increment = 0;
177
         end // case: 0
178
      endcase // case(option)
179
   end
180
endtask // set_pause_options
181
 
182
task set_collision_detect_delay;
183
   // Set delay between occurrence of collision and
184
   // processing by the testbench
185
   // value in nanoseconds
186
   input delay;
187
   integer delay;
188
   begin
189
      collision_detection_delay = delay;
190
   end
191
endtask // set_collision_detect_delay
192
 
193
task set_jam_length;
194
   // Set length of jamming pattern sent in response to collision event
195
   input length;
196
   integer length;
197
   begin
198
      jam_length = length;
199
   end
200
endtask // set_jam_length
201
 
202
 
203
task set_collision_backoff;
204
   // Set collision backoff in number of slots
205
   // collision_count
206
   // index = index of collision whose parameters are to be set
207
   // slots = number of slots to backoff
208
   // flag = 0: back off deterministically by constant number of slots
209
   //      = 1: back off by random number of slots between 0 and slots-1
210
   //      = 2: end backoff and reset collision counter
211
   input index, slots, flag;
212
   integer index, slots, flag;
213
   begin
214
      if ((index > 0) && (index <= `MAX_COLLISIONS)) // check validity of index
215
       begin
216
          case(flag)
217
            0: begin // deterministic backoff
218
               backoff_slots[index] = slots;
219
               backoff_type[index] = 0;
220
            end // case: 0
221
            1: begin // random backoff
222
               backoff_slots[index] = slots;
223
               backoff_type[index] = 1;
224
            end // case: 1
225
            default: begin // set collision limit
226
               collision_limit = index;
227
            end // case: default
228
          endcase // case(flag)
229
       end // if ((index > 0) && (index <= `MAX_COLLISIONS))
230
      else
231
       if ((index == `MAX_COLLISIONS) && (flag >= 2)) // set collision limit
232
        collision_limit = index;
233
   end
234
endtask // set_collision_backoff
235
 
236
 /*-------------------------------------------------------------\
237
 |                                                              |
238
 |      Tasks to set flow parameters such as                    |
239
 |      packet size and header fields                           |
240
 |                                                              |
241
 \-------------------------------------------------------------*/
242
 
243
task set_flow_type;
244
// Sets flow type_new for the packet sequence to be generated
245
   input [7:0]  type_new;
246
   begin
247
      flow_type = type_new;
248
   end
249
endtask // set_flow_type
250
 
251
task set_L2_protocol;
252
   // sets L2 protocol at ingress
253
   input type_new;
254
   integer type_new;
255
   begin
256
      L2_protocol_type = type_new[7:0];
257
      L2_custom_header_enable = 0; // disable custom header
258
   end
259
endtask // testbench_set_L2_protocol
260
 
261
task set_L2_source_address;
262
   // sets source MAC address for transmitted frames
263
   input type_new;
264
   input [47:0] mac_min, mac_max, mac_incr;
265
   integer type_new;
266
 
267
   reg [31:0] x, y;
268
   reg [47:0] mac_random;
269
 
270
   begin
271
      L2_src_mac_min = mac_min;
272
      L2_src_mac_max = mac_max;
273
      L2_src_mac_incr = mac_incr;
274
      L2_src_mac_option = type_new[1:0];
275
      L2_custom_header_enable = 0; // disable custom header
276
 
277
      // set current MAC address for packet sequence
278
      case (L2_src_mac_option)
279
        0: // constant
280
         current_src_mac = L2_src_mac_min;
281
        1: // incremental
282
         if (L2_src_mac_incr[47] == 0)
283
          current_src_mac = L2_src_mac_min;
284
         else
285
          current_src_mac = L2_src_mac_max;
286
        2: // random
287
         begin
288
            x = $random();
289
            y = $random();
290
            mac_random = {x[15:0], y[31:0]};
291
            if (L2_src_mac_min != L2_src_mac_max)
292
             current_src_mac = L2_src_mac_min +
293
                                  (mac_random % (L2_src_mac_max -
294
                                                 L2_src_mac_min));
295
            else
296
             current_src_mac = L2_src_mac_min;
297
         end // case: 2
298
      endcase // case(L2_src_mac_option)
299
   end
300
endtask // set_L2_source_address
301
 
302
task set_L2_destination_address;
303
   // sets destination MAC address for transmitted frames
304
   input type_new;
305
   input [47:0] mac_min, mac_max, mac_incr;
306
   integer type_new;
307
 
308
   reg [31:0] x, y;
309
   reg [47:0] mac_random;
310
   begin
311
      L2_dstn_mac_min = mac_min;
312
      L2_dstn_mac_max = mac_max;
313
      L2_dstn_mac_incr = mac_incr;
314
      L2_dstn_mac_option = type_new[1:0];
315
      L2_custom_header_enable = 0; // disable custom header
316
 
317
      // Set current destination MAC for packet sequence
318
      case (L2_dstn_mac_option)
319
        0: // constant
320
         current_dstn_mac = L2_dstn_mac_min;
321
        1: // incremental
322
         if (L2_dstn_mac_incr[47] == 0)
323
          current_dstn_mac = L2_dstn_mac_min;
324
         else
325
          current_dstn_mac = L2_dstn_mac_max;
326
        2: // random
327
         begin
328
            x = $random();
329
            y = $random();
330
            mac_random = {x[15:0], y[31:0]};
331
            if (L2_dstn_mac_min != L2_dstn_mac_max)
332
             current_dstn_mac = L2_dstn_mac_min +
333
                                   (mac_random % (L2_dstn_mac_max -
334
                                                  L2_dstn_mac_min));
335
            else
336
             current_dstn_mac = L2_dstn_mac_min;
337
         end // case: 2
338
      endcase // case(L2_dstn_mac_option)
339
   end
340
endtask // set_L2_destination_address
341
 
342
task set_L2_VLAN_TCI;
343
   // sets VLAN TCI of transmitted frames
344
   input type_new;
345
   input [15:0] min_TCI, max_TCI, increment;
346
   integer type_new;
347
 
348
   reg [31:0] x;
349
   begin
350
      L2_VLAN_TCI_min = min_TCI;
351
      L2_VLAN_TCI_max = max_TCI;
352
      L2_VLAN_TCI_incr = increment;
353
      L2_VLAN_TCI_option = type_new[1:0];
354
      L2_custom_header_enable = 0; // disable custom header
355
 
356
      // set current VLAN TCI for packet sequence
357
      case (L2_VLAN_TCI_option)
358
        0: // constant
359
         current_VLAN_TCI = L2_VLAN_TCI_min;
360
        1: // incremental
361
         if (L2_VLAN_TCI_incr[15] == 0)
362
          current_VLAN_TCI = L2_VLAN_TCI_min;
363
         else
364
          current_VLAN_TCI = L2_VLAN_TCI_max;
365
        2: // random
366
         begin
367
            x = $random();
368
            if (L2_VLAN_TCI_max != L2_VLAN_TCI_min)
369
             current_VLAN_TCI = L2_VLAN_TCI_min +
370
                                   (x % (L2_VLAN_TCI_max -
371
                                         L2_VLAN_TCI_min));
372
            else
373
             current_VLAN_TCI = L2_VLAN_TCI_min;
374
         end // case: 2
375
      endcase // case(L2_VLAN_TCI_option)
376
   end
377
endtask // set_L2_VLAN_TCI
378
 
379
task set_L2_VLAN_TPID;
380
   // sets VLAN TPID field
381
   input [15:0] TPID;
382
   begin
383
      L2_VLAN_TPID = TPID;
384
      L2_custom_header_enable = 0; // disable custom header
385
   end
386
endtask
387
 
388
task set_L2_frame_size;
389
   // sets size of transmitted frames
390
   input type_new, min_size, max_size, increment;
391
   integer type_new, min_size, max_size, increment;
392
 
393
   reg [31:0] x;
394
   begin
395
      L2_frame_size_option = type_new[1:0];
396
      L2_frame_size_min = min_size;
397
      L2_frame_size_max = max_size;
398
      L2_frame_size_incr = increment;
399
 
400
      // set current packet size parameter
401
      case (L2_frame_size_option)
402
        0: // constant
403
         current_pkt_size = L2_frame_size_min;
404
        1: // incremental
405
         if (increment >= 0)
406
          current_pkt_size = L2_frame_size_min;
407
         else
408
          current_pkt_size = L2_frame_size_max;
409
        2: // $random
410
         begin
411
            x = $random();
412
            if (L2_frame_size_max != L2_frame_size_min)
413
             current_pkt_size = L2_frame_size_min +
414
                                     (x % (L2_frame_size_max - L2_frame_size_min));
415
            else
416
             current_pkt_size = L2_frame_size_min;
417
         end // case: 2
418
      endcase // case(L2_frame_size_option)
419
   end
420
endtask
421
 
422
task set_L2_type_field;
423
   // sets 16-bit type_new field for L2 Ethernet flows
424
   input [15:0] type_new;
425
   begin
426
      L2_type_field = type_new;
427
   end
428
endtask // testbench_set_L2_type_field
429
 
430
task set_LLC_header;
431
   // sets LLC and SNAP headers for transmitted frames
432
   // default is aa_aa_03_00_00_00_08_00 hex
433
   input header_length;
434
   input [`MAX_HEADER_SIZE*8-1: 0] header;
435
      integer header_length;
436
   begin
437
      L2_LLC_header = header;
438
      L2_LLC_header_length = header_length;
439
      L2_LLC_header_enable = 1;
440
   end
441
endtask // testbench_set_LLC_header
442
 
443
task set_L2_custom_header;
444
   // sets a user-defined L2 header
445
   input header_length;
446
   input [`MAX_HEADER_SIZE*8-1: 0] header;
447
   integer header_length;
448
 
449
   begin
450
      if (header_length == 0) //disable user-defined L2 header
451
       L2_custom_header_enable = 0;
452
      else
453
       begin
454
          L2_custom_header_enable = 1;
455
          L2_custom_header = header;
456
          L2_custom_header_length = header_length;
457
       end // else: !if(header_length == 0)
458
   end
459
endtask // testbench_set_L2_custom_header
460
 
461
task set_L3_protocol;
462
   // sets L3 protocol
463
   input protocol;
464
   integer protocol;
465
   begin
466
      L3_protocol_type = protocol[7:0];
467
   end
468
endtask
469
 
470
task set_IP_header;
471
   // sets IP header fields
472
   input [31:0] src_addr, dstn_addr;
473
   input [7:0] service_type;
474
   input [15:0] sequence_number;
475
   input [2:0] flags;
476
   input [12:0] fragment_offset;
477
   input [7:0] ttl;
478
   input [7:0] protocol;
479
   begin
480
      L3_src_address = src_addr;
481
      L3_dstn_address = dstn_addr;
482
      L3_sequence_number = sequence_number;
483
      IP_flags = flags;
484
      IP_fragment_offset = fragment_offset;
485
      L3_TTL = ttl;
486
      IP_protocol_field = protocol;
487
      IP_service_type = service_type;
488
   end // else: !if((flow_id < 0) || (flow_id > NFLOWS))
489
endtask // testbench_set_L3_IP_header
490
 
491
task set_IP_extension_header;
492
   // sets IP extension header
493
   input header_length;
494
   input [`IP_EXTENSION_HEADER_SIZE*8-1: 0] header;
495
   integer header_length;
496
   begin
497
      IP_ext_header = header;
498
      IP_ext_header_length = header_length;
499
   end // else: !if((flow_id < 0) || (flow_id > NFLOWS))
500
endtask // set_IP_extension_header
501
 
502
task set_L3_custom_header;
503
   // sets a user-defined L2 header
504
   input header_length;
505
   input [`MAX_HEADER_SIZE*8-1: 0] header;
506
   integer header_length;
507
   begin
508
      if (header_length == 0) //disable user-defined LLC header
509
       L3_custom_header_enable = 0;
510
      else
511
       begin
512
          L3_custom_header_enable = 1;
513
          L3_custom_header = header;
514
          L3_custom_header_length = header_length;
515
       end // else: !if(header_length == 0)
516
   end
517
endtask // set_L3_custom_header
518
 
519
task set_L4_protocol;
520
   // sets L4 protocol
521
   input protocol;
522
   integer protocol;
523
   begin
524
      L4_protocol_type = protocol[7:0];
525
   end
526
endtask
527
 
528
task set_TCP_port_numbers;
529
   // sets TCP header fields
530
   input src_port, dstn_port;
531
   integer src_port, dstn_port;
532
   begin
533
      L4_src_port = src_port;
534
      L4_dstn_port = dstn_port;
535
   end
536
endtask // set_TCP_header
537
 
538
task set_TCP_sequence_number;
539
   input sequence_number;
540
   integer sequence_number;
541
   begin
542
      L4_sequence_number = sequence_number;
543
   end
544
endtask // set_TCP_sequence_number
545
 
546
task set_TCP_header_fields;
547
   // sets other fields in TCP header
548
   input [31:0] ack_number;
549
   input [5:0] flags;
550
   input [15:0] urgent_pointer;
551
   input [15:0] window_size;
552
   begin
553
      L4_ack_number = ack_number;
554
      TCP_flags = flags;
555
      TCP_urgent_pointer = urgent_pointer;
556
      TCP_window_size = window_size;
557
   end
558
endtask
559
 
560
task set_UDP_port_numbers;
561
   // sets UDP header fields
562
   input src_port, dstn_port;
563
   integer src_port, dstn_port;
564
   begin
565
      L4_src_port = src_port;
566
      L4_dstn_port = dstn_port;
567
   end
568
endtask // 
569
 
570
task set_L4_custom_header;
571
   // sets a user-defined L4 header
572
   input header_length;
573
   input [`MAX_HEADER_SIZE*8-1: 0] header;
574
   integer header_length;
575
   begin
576
      if (header_length == 0) //disable user-defined LLC header
577
       L4_custom_header_enable = 0;
578
      else
579
       begin
580
          L4_custom_header_enable = 1;
581
          L4_custom_header = header;
582
          L4_custom_header_length = header_length;
583
       end // else: !if(header_length == 0)
584
   end
585
endtask // testbench_set_L4_custom_header
586
 
587
task set_payload_data;
588
   // sets payload of transmitted packets from user-supplied buffer
589
   input length;
590
   input [`MAX_PKT_SIZE*8-1: 0] payload;
591
   integer length;
592
   begin
593
      user_payload = payload;
594
      payload_length = length;
595
      payload_option = 2'd3; // enable user_defined payload
596
   end
597
endtask // set_payload
598
 
599
task set_payload_type;
600
   input option, length, start;
601
   integer option, length, start;
602
   begin
603
      payload_option = option[1:0]; // defines random, increasing, or decreasing sequence
604
      payload_length = length;
605
      payload_start = start;
606
   end
607
endtask // set_payload_option
608
 
609
task set_crc_option;
610
   // Sets option for L2 CRC generation
611
   input option, value;
612
   integer option, value;
613
   begin
614
      flowrec_crc_option = option[1:0];
615
      flowrec_user_crc = value;
616
   end
617
endtask // set_crc_option
618
 
619
task set_user_crc_option;
620
   // Sets option for CRC generation for user-supplied frames,
621
   // including PAUSE frames
622
   input option, value;
623
   integer option, value;
624
   begin
625
      user_crc_option = option[1:0];
626
      user_crc_value = value;
627
   end
628
endtask // set_user_crc_option
629
 
630
task set_L3_checksum_option;
631
   // Sets option for L3 checksum generation
632
   input option;
633
   input [15:0]  value;
634
   integer option;
635
   begin
636
      L3_checksum_option = option;
637
      L3_user_checksum = value;
638
   end
639
endtask // set_L3_checksum_option
640
 
641
task set_L4_checksum_option;
642
   // Sets option for L4 checksum generation
643
   input option;
644
   input [15:0] value;
645
   integer option;
646
   begin
647
      L4_checksum_option = option;
648
      L4_user_checksum = value;
649
   end
650
endtask // set_L4_checksum_option
651
 
652
task enable_sequence_number;
653
   input flag, offset;
654
   integer offset;
655
   begin
656
      seqno_enable = flag;
657
      if (seqno_enable)
658
       seq_number_offset = offset;
659
   end
660
endtask // enable_sequence_number
661
 
662
task enable_timestamp;
663
   input flag, offset;
664
   integer offset;
665
   begin
666
      timestamp_enable = flag;
667
      if (timestamp_enable)
668
       timestamp_offset = offset;
669
   end
670
endtask // enable_timestamp
671
 
672
task set_default_header_parameters;
673
   begin
674
      // initialize default header parameters
675
 
676
      L2_custom_header_enable = 0; // do not use custom headers
677
      L3_custom_header_enable = 0;
678
      IP_ext_header_length = 0; // No IP extension header
679
      L4_custom_header_enable = 0;
680
      payload_option = 0; // generate payload as increasing sequence of byte_news
681
 
682
      L2_protocol_type = 2; // default = 802.3 with no VLAN tagging
683
      L2_src_mac_option = 2'b00;    // Fixed source MAC
684
      L2_src_mac_min = 48'h01_02_03_04_05_06; // source MAC address
685
      L2_dstn_mac_option = 2'b00;    // Fixed destination MAC
686
      if (flow_type == 1) // Layer-2 broadcast
687
       L2_dstn_mac_min = 48'hff_ff_ff_ff_ff_ff; // destination MAC address
688
      else
689
       L2_dstn_mac_min = 48'h06_05_04_03_02_01;
690
      L2_type_field = `DEFAULT_L2_TYPE;   // Default type_new field for Ethernet frames
691
      L2_VLAN_TCI_option = 2'b00; // Fixed VLAN tag
692
      L2_VLAN_TCI_min = 0;        // Null VLAN tag
693
 
694
      L2_VLAN_TPID = `DEFAULT_VLAN_TPID; // default 802.1Q TPID = 8100 hex
695
 
696
      L2_frame_size_option = 2'b00; // constant size frames
697
      L2_frame_size_min = 64;       // 64-byte_new frames
698
      flowrec_crc_option = 0;  // append good CRC
699
 
700
      // set current packet parameters
701
      current_pkt_size = L2_frame_size_min;
702
      current_src_mac = L2_src_mac_min;
703
      current_dstn_mac = L2_dstn_mac_min;
704
      current_VLAN_TCI = L2_VLAN_TCI_min;
705
 
706
      // Set default LLC header (for IP)
707
      L2_LLC_header_length = 8;  // 3-byte_new LLC + 5-byte_new SNAP
708
      L2_LLC_header = {192'd0, 64'haa_aa_03_00_00_00_08_00};
709
 
710
      // Set default L3 header parameters
711
      L3_protocol_type = 4;  // default = IP v4
712
      L3_checksum_option = 0; // transmit good checksum
713
 
714
      L3_src_address =  32'h80_00_00_01; // IP source address
715
      L3_dstn_address = 32'h81_00_00_01; // IP destination address
716
      L3_TTL = 1;                        // IP time-to-live field
717
      L3_sequence_number = 16'd0;
718
      IP_flags = 3'd0;
719
      IP_fragment_offset = 0;
720
      L3_TTL = 1;
721
      IP_protocol_field = 8'd0;
722
      IP_service_type = 8'd0;
723
 
724
      // Set default L4 header parameters
725
      L4_protocol_type = 0;  // default = TCP
726
      L4_src_port = 0;       // TCP source port
727
      L4_dstn_port = 0;      // TCP destination port
728
      L4_checksum_option = 0; // enable good L4 checksum
729
      L4_sequence_number = 0;
730
      L4_ack_number = 0;    // TCP sequence and ack numbers
731
      TCP_flags = 6'b000000; // Flags in TCP header;
732
      TCP_urgent_pointer = 0; // Urgent pointer in TCP header
733
      TCP_window_size = 0;   // TCP advertised window
734
 
735
      payload_length = `MAX_PKT_SIZE; // set default max payload size 
736
      payload_option = 2'b00; // payload = increasing sequence of byte_news
737
      payload_start = 0; // starting at 0
738
   end
739
 
740
endtask // set_default_header_parameters
741
 
742
task print_packet_parameters;
743
   // print current parameter settings to console and file 
744
 
745
   integer int1, int2, int3, int4, int5;
746
   integer i, j;
747
   reg [`MAX_HEADER_SIZE*8-1:0] header;
748
   reg [47:0] mac_addr1;
749
   reg [7:0] byte_new;
750
 
751
   begin
752
      int1 = flow_type;
753
      $write("flow type_new = %0d ", int1);
754
      $fwrite(outfile, "flow type_new = %0d ", int1);
755
      case (int1)
756
        0:
757
         begin
758
            $write("(L2 unicast)\n");
759
            $fwrite(outfile, "(L2 unicast)\n");
760
         end // case: 0
761
        1:
762
         begin
763
            $write("(L2 broadcast)\n");
764
            $fwrite(outfile, "(L2 broadcast)\n");
765
         end // case: 1
766
        2:
767
         begin
768
            $write("(L2 multicast)\n");
769
            $fwrite(outfile, "(L2 multicast)\n");
770
         end // case: 2
771
        3:
772
         begin
773
            $write("(L3 unicast)\n");
774
            $fwrite(outfile, "(L3 unicast)\n");
775
         end // case: 3
776
        4:
777
         begin
778
            $write("(L3 multicast)\n");
779
            $fwrite(outfile, "(L3 multicast)\n");
780
         end // case: 4
781
        5:
782
         begin
783
            $write("(L4 unicast)\n");
784
            $fwrite(outfile, "(L4 unicast)\n");
785
         end // case: 5
786
        6:
787
         begin
788
            $write("(L4 multicast)\n");
789
            $fwrite(outfile, "(L4 multicast)\n");
790
         end // case: 6
791
        default:
792
         begin
793
            $write("(unknown)\n");
794
            $fwrite(outfile, "(unknown)\n");
795
         end // case: default
796
      endcase // case(int1)
797
 
798
      if (!L2_custom_header_enable)
799
       begin
800
          int1 = L2_protocol_type;
801
          $write("L2 protocol = %0d ", int1);
802
          $fwrite(outfile, "L2 protocol = %0d ", int1);
803
          case (int1)
804
            0:
805
             begin
806
                $write("(untagged Ethernet)\n");
807
                $fwrite(outfile, "(untagged Ethernet)\n");
808
             end // case: 0
809
            1:
810
             begin
811
                $write("(tagged Ethernet)\n");
812
                $fwrite(outfile, "(tagged Ethernet)\n");
813
             end
814
            2:
815
             begin
816
                $write("(untagged 802.3)\n");
817
                $fwrite(outfile, "(untagged 802.3)\n");
818
             end // case: 2
819
            3:
820
             begin
821
                $write("(tagged 802.3)\n");
822
                $fwrite(outfile, "(tagged 802.3)\n");
823
             end // case: 3
824
            4:
825
             begin
826
                $write("(802.1d BPDU)\n");
827
                $fwrite(outfile, "(802.1d BPDU)\n");
828
             end // case: 4
829
            default:
830
             begin
831
                $write("(unknown)\n");
832
                $fwrite(outfile, "(unknown)\n");
833
             end // case: default
834
          endcase // case(int1)
835
 
836
          int1 = L2_frame_size_option;
837
          $write("L2 frame size option = %0d ", int1);
838
          $fwrite(outfile, "L2 frame size option = %0d ", int1);
839
          case (int1)
840
            0:
841
             begin
842
                int2 = L2_frame_size_min;
843
                $write("(constant), frame size = %0d\n", int2);
844
                $fwrite(outfile, "(constant), frame size = %0d\n", int2);
845
             end // case: 0
846
            1:
847
             begin
848
                int2 = L2_frame_size_min;
849
                int3 = L2_frame_size_max;
850
                int4 = current_pkt_size;
851
                int5 = L2_frame_size_incr;
852
                $write("(incremental), current size = %0d, min = %0d, max = %0d, increment = %0d\n",
853
                       int4, int2, int3, int5);
854
                $fwrite(outfile,
855
                        "(incremental), current size = %0d, min = %0d, max = %0d, increment = %0d\n",
856
                        int4, int2, int3, int5);
857
             end // case: 1
858
            2:
859
             begin
860
                int2 = L2_frame_size_min;
861
                int3 = L2_frame_size_max;
862
                $write("(random), min = %0d, max = %0d\n",
863
                       int2, int3);
864
                $fwrite(outfile, "(random), min = %0d, max = %0d\n",
865
                        int2, int3);
866
             end // case: 2
867
            default:
868
             begin
869
                $write("\n");
870
                $fwrite(outfile, "\n");
871
             end // case: default
872
          endcase // case(int1)
873
 
874
          // print source MAC
875
          int1 = L2_src_mac_option;
876
          $write("Source MAC option = %0d ", int1);
877
          $fwrite(outfile, "Source MAC option = %0d ", int1);
878
          case (int1)
879
            0:
880
             begin
881
                mac_addr1 = L2_src_mac_min;
882
                $write("(constant), MAC addr = ");
883
                $fwrite(outfile, "(constant), MAC addr = ");
884
                $write("%h:%h:%h:%h:%h:%h\n",
885
                       mac_addr1[47:40], mac_addr1[39:32], mac_addr1[31:24],
886
                       mac_addr1[23:16], mac_addr1[15: 8], mac_addr1[ 7: 0]);
887
                $fwrite(outfile, "%h:%h:%h:%h:%h:%h\n",
888
                        mac_addr1[47:40], mac_addr1[39:32], mac_addr1[31:24],
889
                        mac_addr1[23:16], mac_addr1[15: 8], mac_addr1[ 7: 0]);
890
             end // case: 0
891
            1:
892
             begin
893
                $write("(incremental), current = ");
894
                $fwrite(outfile, "(incremental), current = ");
895
                mac_addr1 = current_src_mac;
896
                $write("%h:%h:%h:%h:%h:%h\n",
897
                       mac_addr1[47:40], mac_addr1[39:32], mac_addr1[31:24],
898
                       mac_addr1[23:16], mac_addr1[15: 8], mac_addr1[ 7: 0]);
899
                $fwrite(outfile, "%h:%h:%h:%h:%h:%h\n",
900
                        mac_addr1[47:40], mac_addr1[39:32], mac_addr1[31:24],
901
                        mac_addr1[23:16], mac_addr1[15: 8], mac_addr1[ 7: 0]);
902
                $write("min = ");
903
                $fwrite(outfile, "min = ");
904
                mac_addr1 = L2_src_mac_min;
905
                $write("%h:%h:%h:%h:%h:%h",
906
                       mac_addr1[47:40], mac_addr1[39:32], mac_addr1[31:24],
907
                       mac_addr1[23:16], mac_addr1[15: 8], mac_addr1[ 7: 0]);
908
                $fwrite(outfile, "%h:%h:%h:%h:%h:%h",
909
                        mac_addr1[47:40], mac_addr1[39:32], mac_addr1[31:24],
910
                        mac_addr1[23:16], mac_addr1[15: 8], mac_addr1[ 7: 0]);
911
                $write(", max = ");
912
                $fwrite(outfile, ", max = ");
913
                mac_addr1 = L2_src_mac_max;
914
                $write("%h:%h:%h:%h:%h:%h",
915
                       mac_addr1[47:40], mac_addr1[39:32], mac_addr1[31:24],
916
                       mac_addr1[23:16], mac_addr1[15: 8], mac_addr1[ 7: 0]);
917
                $fwrite(outfile, "%h:%h:%h:%h:%h:%h",
918
                        mac_addr1[47:40], mac_addr1[39:32], mac_addr1[31:24],
919
                        mac_addr1[23:16], mac_addr1[15: 8], mac_addr1[ 7: 0]);
920
                $write(", incr = ");
921
                $fwrite(outfile, ", incr = ");
922
                mac_addr1 = L2_src_mac_incr;
923
                $write("%h:%h:%h:%h:%h:%h\n",
924
                       mac_addr1[47:40], mac_addr1[39:32], mac_addr1[31:24],
925
                       mac_addr1[23:16], mac_addr1[15: 8], mac_addr1[ 7: 0]);
926
                $fwrite(outfile, "%h:%h:%h:%h:%h:%h\n",
927
                        mac_addr1[47:40], mac_addr1[39:32], mac_addr1[31:24],
928
                        mac_addr1[23:16], mac_addr1[15: 8], mac_addr1[ 7: 0]);
929
             end // case: 1
930
            2:
931
             begin
932
                $write("(random), min = ");
933
                $fwrite(outfile, "(random), min = ");
934
                mac_addr1 = L2_src_mac_min;
935
                $write("%h:%h:%h:%h:%h:%h",
936
                       mac_addr1[47:40], mac_addr1[39:32], mac_addr1[31:24],
937
                       mac_addr1[23:16], mac_addr1[15: 8], mac_addr1[ 7: 0]);
938
                $fwrite(outfile, "%h:%h:%h:%h:%h:%h",
939
                        mac_addr1[47:40], mac_addr1[39:32], mac_addr1[31:24],
940
                        mac_addr1[23:16], mac_addr1[15: 8], mac_addr1[ 7: 0]);
941
                $write(", max = ");
942
                $fwrite(outfile, ", max = ");
943
                mac_addr1 = L2_src_mac_max;
944
                $write("%h:%h:%h:%h:%h:%h\n",
945
                       mac_addr1[47:40], mac_addr1[39:32], mac_addr1[31:24],
946
                       mac_addr1[23:16], mac_addr1[15: 8], mac_addr1[ 7: 0]);
947
                $fwrite(outfile, "%h:%h:%h:%h:%h:%h\n",
948
                        mac_addr1[47:40], mac_addr1[39:32], mac_addr1[31:24],
949
                        mac_addr1[23:16], mac_addr1[15: 8], mac_addr1[ 7: 0]);
950
             end // case: 2
951
            default:
952
             begin
953
                $write("\n");
954
                $fwrite(outfile, "\n");
955
             end // case: default
956
          endcase // case(int1)
957
 
958
          // print destination MAC
959
          int1 = L2_dstn_mac_option;
960
          $write("Dest MAC option = %0d ", int1);
961
          $fwrite(outfile, "Dest MAC option = %0d ", int1);
962
          case (int1)
963
            0:
964
             begin
965
                mac_addr1 = L2_dstn_mac_min;
966
                $write("(constant), MAC addr = ");
967
                $fwrite(outfile, "(constant), MAC addr = ");
968
                $write("%h:%h:%h:%h:%h:%h\n",
969
                       mac_addr1[47:40], mac_addr1[39:32], mac_addr1[31:24],
970
                       mac_addr1[23:16], mac_addr1[15: 8], mac_addr1[ 7: 0]);
971
                $fwrite(outfile, "%h:%h:%h:%h:%h:%h\n",
972
                        mac_addr1[47:40], mac_addr1[39:32], mac_addr1[31:24],
973
                        mac_addr1[23:16], mac_addr1[15: 8], mac_addr1[ 7: 0]);
974
             end // case: 0
975
            1:
976
             begin
977
                $write("(incremental), current = ");
978
                $fwrite(outfile, "(incremental), current = ");
979
                mac_addr1 = current_dstn_mac;
980
                $write("%h:%h:%h:%h:%h:%h\n",
981
                       mac_addr1[47:40], mac_addr1[39:32], mac_addr1[31:24],
982
                       mac_addr1[23:16], mac_addr1[15: 8], mac_addr1[ 7: 0]);
983
                $fwrite(outfile, "%h:%h:%h:%h:%h:%h\n",
984
                        mac_addr1[47:40], mac_addr1[39:32], mac_addr1[31:24],
985
                        mac_addr1[23:16], mac_addr1[15: 8], mac_addr1[ 7: 0]);
986
                $write("min = ");
987
                $fwrite(outfile, "min = ");
988
                mac_addr1 = L2_dstn_mac_min;
989
                $write("%h:%h:%h:%h:%h:%h",
990
                       mac_addr1[47:40], mac_addr1[39:32], mac_addr1[31:24],
991
                       mac_addr1[23:16], mac_addr1[15: 8], mac_addr1[ 7: 0]);
992
                $fwrite(outfile, "%h:%h:%h:%h:%h:%h",
993
                        mac_addr1[47:40], mac_addr1[39:32], mac_addr1[31:24],
994
                        mac_addr1[23:16], mac_addr1[15: 8], mac_addr1[ 7: 0]);
995
                $write(", max = ");
996
                $fwrite(outfile, ", max = ");
997
                mac_addr1 = L2_dstn_mac_max;
998
                $write("%h:%h:%h:%h:%h:%h",
999
                       mac_addr1[47:40], mac_addr1[39:32], mac_addr1[31:24],
1000
                       mac_addr1[23:16], mac_addr1[15: 8], mac_addr1[ 7: 0]);
1001
                $fwrite(outfile, "%h:%h:%h:%h:%h:%h",
1002
                        mac_addr1[47:40], mac_addr1[39:32], mac_addr1[31:24],
1003
                        mac_addr1[23:16], mac_addr1[15: 8], mac_addr1[ 7: 0]);
1004
                $write(", incr = ");
1005
                $fwrite(outfile, ", incr = ");
1006
                mac_addr1 = L2_dstn_mac_incr;
1007
                $write("%h:%h:%h:%h:%h:%h\n",
1008
                       mac_addr1[47:40], mac_addr1[39:32], mac_addr1[31:24],
1009
                       mac_addr1[23:16], mac_addr1[15: 8], mac_addr1[ 7: 0]);
1010
                $fwrite(outfile, "%h:%h:%h:%h:%h:%h\n",
1011
                        mac_addr1[47:40], mac_addr1[39:32], mac_addr1[31:24],
1012
                        mac_addr1[23:16], mac_addr1[15: 8], mac_addr1[ 7: 0]);
1013
             end // case: 1
1014
            2:
1015
             begin
1016
                $write("(random), min = ");
1017
                $fwrite(outfile, "(random), min = ");
1018
                mac_addr1 = L2_dstn_mac_min;
1019
                $write("%h:%h:%h:%h:%h:%h",
1020
                       mac_addr1[47:40], mac_addr1[39:32], mac_addr1[31:24],
1021
                       mac_addr1[23:16], mac_addr1[15: 8], mac_addr1[ 7: 0]);
1022
                $fwrite(outfile, "%h:%h:%h:%h:%h:%h",
1023
                        mac_addr1[47:40], mac_addr1[39:32], mac_addr1[31:24],
1024
                        mac_addr1[23:16], mac_addr1[15: 8], mac_addr1[ 7: 0]);
1025
                $write(", max = ");
1026
                $fwrite(outfile, ", max = ");
1027
                mac_addr1 = L2_dstn_mac_max;
1028
                $write("%h:%h:%h:%h:%h:%h\n",
1029
                       mac_addr1[47:40], mac_addr1[39:32], mac_addr1[31:24],
1030
                       mac_addr1[23:16], mac_addr1[15: 8], mac_addr1[ 7: 0]);
1031
                $fwrite(outfile, "%h:%h:%h:%h:%h:%h\n",
1032
                        mac_addr1[47:40], mac_addr1[39:32], mac_addr1[31:24],
1033
                        mac_addr1[23:16], mac_addr1[15: 8], mac_addr1[ 7: 0]);
1034
             end // case: 2
1035
            default:
1036
             begin
1037
                $write("\n");
1038
                $fwrite(outfile, "\n");
1039
             end // case: default
1040
          endcase // case(int1)
1041
 
1042
          // print VLAN TCI
1043
          int1 = L2_protocol_type;
1044
          if ((int1 == 1) || (int1 == 3)) // tagged frames
1045
           begin
1046
              int1 = L2_VLAN_TCI_option;
1047
              $write("L2 VLAN TCI option = %0d ", int1);
1048
              $fwrite(outfile, "L2 VLAN TCI option = %0d ", int1);
1049
              case (int1)
1050
                0:
1051
                 begin
1052
                    int2 = L2_VLAN_TCI_min;
1053
                    $write("(constant), TCI = %h\n", int2[15:0]);
1054
                    $fwrite(outfile, "(constant), TCI = %h\n", int2[15:0]);
1055
                 end // case: 0
1056
                1:
1057
                 begin
1058
                    int2 = L2_VLAN_TCI_min;
1059
                    int3 = L2_VLAN_TCI_max;
1060
                    int4 = current_VLAN_TCI;
1061
                    int5 = L2_VLAN_TCI_incr;
1062
                    $write("(incremental), current = %h, min = %h, max = %h, increment = %h\n",
1063
                           int4[15:0], int2[15:0], int3[15:0], int5[15:0]);
1064
                    $fwrite(outfile,
1065
                            "(incremental), current = %h, min = %h, max = %h, increment = %h\n",
1066
                            int4[15:0], int2[15:0], int3[15:0], int5[15:0]);
1067
                 end // case: 1
1068
                2:
1069
                 begin
1070
                    int2 = L2_VLAN_TCI_min;
1071
                    int3 = L2_VLAN_TCI_max;
1072
                    $write("(random), min = %h, max = %h\n",
1073
                           int2[15:0], int3[15:0]);
1074
                    $fwrite(outfile, "(random), min = %h, max = %h\n",
1075
                            int2[15:0], int3[15:0]);
1076
                 end // case: 2
1077
                default:
1078
                 begin
1079
                    $write("\n");
1080
                    $fwrite(outfile, "\n");
1081
                 end // case: default
1082
              endcase // case(int1)
1083
           end // if ((int1 == 1) || (int1 == 3))
1084
 
1085
          // print type_new field
1086
          int1 = L2_protocol_type;
1087
          if ((int1 == 0) || (int1 == 1)) // Only for Ethernet frames
1088
           begin
1089
              int1 = L2_type_field;
1090
              $write("L2 type_new = %h\n", int1[15:0]);
1091
              $fwrite(outfile, "L2 type_new = %h\n", int1[15:0]);
1092
           end // if ((int1 == 0) || (int1 == 1))
1093
 
1094
          // print L2 LLC header
1095
          if ((L2_LLC_header_enable) &&
1096
              (L2_LLC_header_length != 0))
1097
           begin
1098
              $write("LLC header = ");
1099
              $fwrite(outfile, "LLC header = ");
1100
              header = L2_LLC_header;
1101
              for (i= L2_LLC_header_length-1; i >= 0;
1102
                   i = i-1)
1103
               begin
1104
                  for (j=0; j < 8; j= j+1)
1105
                   byte_new[j] = header[i*8 +j];
1106
                  $write("%h ", byte_new[7:0]);
1107
                  $fwrite(outfile,"%h ", byte_new[7:0]);
1108
               end // for (i = L2_LLC_header_length;...
1109
              $write("\n");
1110
              $fwrite(outfile, "\n");
1111
           end // if ((L2_LLC_header_enable) &&...
1112
       end // if (!L2_custom_header_enable)
1113
      else
1114
       // print L2 custom header
1115
       if (L2_custom_header_length != 0)
1116
        begin
1117
           $write("L2 custom header = ");
1118
           $fwrite(outfile, "L2 custom header = ");
1119
           header = L2_custom_header;
1120
           for (i = L2_custom_header_length -1;
1121
                i >= 0; i = i-1)
1122
            begin
1123
               for (j=0; j < 8; j= j+1)
1124
                byte_new[j] = header[i*8 +j];
1125
               $write("%h ", byte_new[7:0]);
1126
               $fwrite(outfile,"%h ", byte_new[7:0]);
1127
            end // for (i = L2_custom_header_length;...
1128
           $write("\n");
1129
           $fwrite(outfile, "\n");
1130
        end // if (L2_custom_header_length != 0)
1131
 
1132
      // print IFG
1133
      $write("Current IFG = %0d\n", current_ifg);
1134
      $fwrite(outfile,
1135
              "Current IFG = %0d\n", current_ifg);
1136
 
1137
      // print CRC option
1138
      $write("L2 CRC option = %0d ", flowrec_crc_option);
1139
      $fwrite(outfile,
1140
              "L2 CRC option = %0d ", flowrec_crc_option);
1141
      case (flowrec_crc_option)
1142
        0:
1143
         begin
1144
            $write("(normal CRC)\n");
1145
            $fwrite(outfile, "(normal CRC)\n");
1146
         end // case: 0
1147
        1:
1148
         begin
1149
            $write("(bad CRC)\n");
1150
            $fwrite(outfile, "(bad CRC)\n");
1151
         end // case: 1
1152
        2:
1153
         begin
1154
            $write("(no CRC appended)\n");
1155
            $fwrite(outfile, "(no CRC appended)\n");
1156
         end // case: 2
1157
        3:
1158
         begin
1159
            $write("(user-defined CRC), CRC = %h\n",
1160
                   flowrec_user_crc);
1161
            $fwrite(outfile, "(user-defined CRC), CRC = %h\n",
1162
                    flowrec_user_crc);
1163
         end // case: 3
1164
      endcase // case(flowrec_crc_option)
1165
 
1166
      if (flow_type >= 3) // Layer-3/4 flow
1167
       begin
1168
          // print L3 parameters
1169
          case(L3_protocol_type)
1170
            4: // IP v4
1171
             begin
1172
                $write("L3 protocol = 4 (IPv4)\n");
1173
                $fwrite(outfile, "L3 protocol = 4 (IPv4)\n");
1174
                int1 = L3_src_address;
1175
                int2 = L3_dstn_address;
1176
                byte_new = L3_TTL;
1177
                $write("IP src addr = %h.%h.%h.%h, ",
1178
                       int1[31:24], int1[23:16], int1[15:8], int1[7:0]);
1179
                $fwrite(outfile, "IP src addr = %h.%h.%h.%h, ",
1180
                        int1[31:24], int1[23:16], int1[15:8], int1[7:0]);
1181
                $write("dstn addr = %h.%h.%h.%h, ",
1182
                       int2[31:24], int2[23:16], int2[15:8], int2[7:0]);
1183
                $fwrite(outfile, "dstn addr = %h.%h.%h.%h, ",
1184
                        int2[31:24], int2[23:16], int2[15:8], int2[7:0]);
1185
                $write("TTL = %0d\n", byte_new);
1186
                $fwrite(outfile, "TTL = %0d\n", byte_new);
1187
                byte_new = IP_service_type;
1188
                $write("IP service type_new = %h, ", byte_new);
1189
                $fwrite(outfile, "IP service type_new = %h, ", byte_new);
1190
                byte_new = IP_flags;
1191
                int1 = IP_fragment_offset;
1192
                int2 = IP_protocol_field;
1193
                $write("flags = %b, frag offset = %0d, protocol = %h\n",
1194
                       byte_new[2:0], int1[12:0], int2[7:0]);
1195
                $fwrite(outfile,
1196
                        "flags = %b, frag offset = %0d, protocol = %h\n",
1197
                        byte_new[2:0], int1[12:0], int2[7:0]);
1198
                if (IP_ext_header_length != 0)
1199
                 begin
1200
                    // print IP extension header
1201
                    $write("IP extension header = ");
1202
                    $fwrite(outfile, "IP extension header = ");
1203
                    header = IP_ext_header;
1204
                    for (i = IP_ext_header_length -1;
1205
                         i >= 0; i = i-1)
1206
                     begin
1207
                        for (j=0; j < 8; j= j+1)
1208
                         byte_new[j] = header[i*8 +j];
1209
                        $write("%h ", byte_new[7:0]);
1210
                        $fwrite(outfile,"%h ", byte_new[7:0]);
1211
                     end // for (i = IP_ext_header_length -1;...
1212
                    $write("\n");
1213
                    $fwrite(outfile, "\n");
1214
                 end // if (IP_ext_header_length != 0)
1215
             end // case: 4
1216
          endcase // case(L3-Protocol_type)
1217
          if (L3_custom_header_enable)
1218
           begin
1219
              // print L3 custom header
1220
              $write("L3 custom header = ");
1221
              $fwrite(outfile, "L3 custom header = ");
1222
              header = L3_custom_header;
1223
              for (i = L3_custom_header_length -1;
1224
                   i >= 0; i = i-1)
1225
               begin
1226
                  for (j=0; j < 8; j= j+1)
1227
                   byte_new[j] = header[i*8 +j];
1228
                  $write("%h ", byte_new[7:0]);
1229
                  $fwrite(outfile,"%h ", byte_new[7:0]);
1230
               end // for (i = L3_custom_header_length;...
1231
              $write("\n");
1232
              $fwrite(outfile, "\n");
1233
           end // if (L3_custom_header_enable)
1234
 
1235
          // print checksum option
1236
          $write("L3 checksum option = %0d ", L3_checksum_option);
1237
          $fwrite(outfile,
1238
                  "L3 checksum option = %0d ", L3_checksum_option);
1239
          case (L3_checksum_option)
1240
            0:
1241
             begin
1242
                $write("(normal checksum)\n");
1243
                $fwrite(outfile, "(normal checksum)\n");
1244
             end // case: 0
1245
            1:
1246
             begin
1247
                $write("(bad checksum)\n");
1248
                $fwrite(outfile, "(bad checksum)\n");
1249
             end // case: 1
1250
            2:
1251
             begin
1252
                $write("(zero checksum)\n");
1253
                $fwrite(outfile, "(zero checksum)\n");
1254
             end // case: 2
1255
            3:
1256
             begin
1257
                $write("(user-defined checksum), checksum = %h\n",
1258
                       L3_user_checksum);
1259
                $fwrite(outfile,
1260
                        "(user-defined checksum), checksum = %h\n",
1261
                        L3_user_checksum);
1262
             end // case: 3
1263
          endcase // case(L3_checksum_option)
1264
       end // if (flow_type >= 3)
1265
 
1266
      if (flow_type >= 4) // Layer-4 flow
1267
       begin
1268
          // print L4 parameters
1269
          case(L4_protocol_type)
1270
            0:
1271
             begin // TCP
1272
                int1 = L4_src_port;
1273
                int2 = L4_dstn_port;
1274
                byte_new = TCP_flags;
1275
                $write("TCP src port = %h, dstn port = %h, flags = %b\n",
1276
                       int1[15:0], int2[15:0], byte_new[5:0]);
1277
                $fwrite(outfile,
1278
                        "TCP src port = %h, dstn port = %h, flags = %b\n",
1279
                        int1[15:0], int2[15:0], byte_new[5:0]);
1280
                int1 = L4_sequence_number;
1281
                int2 = L4_ack_number;
1282
                int3 = TCP_urgent_pointer;
1283
                int4 = TCP_window_size;
1284
                $write("TCP seq no = %0d, ack no = %0d, urgent ptr = %0d, window size = %0d\n",
1285
                       int1, int2, int3[15:0], int4[15:0]);
1286
                $fwrite(outfile,
1287
                        "TCP seq no = %0d, ack no = %0d, urgent ptr = %0d, window size = %0d\n",
1288
                        int1, int2, int3[15:0], int4[15:0]);
1289
             end // case: 0
1290
            1:
1291
             begin // UDP
1292
                int1 = L4_src_port;
1293
                int2 = L4_dstn_port;
1294
                $write("UDP src port = %h, dstn port = %h\n",
1295
                       int1[15:0], int2[15:0]);
1296
                $fwrite(outfile, "UDP src port = %h, dstn port = %h\n",
1297
                        int1[15:0], int2[15:0]);
1298
             end // case: 1
1299
          endcase // case(L4_protocol_type)
1300
 
1301
          // print L4 checksum option
1302
          $write("L4 checksum option = %0d ", L4_checksum_option);
1303
          $fwrite(outfile,
1304
                  "L4 checksum option = %0d ", L4_checksum_option);
1305
          case (L4_checksum_option)
1306
            0:
1307
             begin
1308
                $write("(normal checksum)\n");
1309
                $fwrite(outfile, "(normal checksum)\n");
1310
             end // case: 0
1311
            1:
1312
             begin
1313
                $write("(bad checksum)\n");
1314
                $fwrite(outfile, "(bad checksum)\n");
1315
             end // case: 1
1316
            2:
1317
             begin
1318
                $write("(zero checksum)\n");
1319
                $fwrite(outfile, "(zero checksum)\n");
1320
             end // case: 2
1321
            3:
1322
             begin
1323
                $write("(user-defined checksum), checksum = %h\n",
1324
                       L4_user_checksum);
1325
                $fwrite(outfile,
1326
                        "(user-defined checksum), checksum = %h\n",
1327
                        L4_user_checksum);
1328
             end // case: 3
1329
          endcase // case(L4_checksum_option)
1330
       end // if (flow_type >= 4)
1331
 
1332
      $write("----------------------------------\n");
1333
      $fwrite(outfile, "----------------------------------\n");
1334
   end
1335
endtask
1336
 
1337
 
1338
/*-------------------------------------------------------------\
1339
 |                                                              |
1340
 |      Tasks for transmission and reception of packets         |
1341
 |                                                              |
1342
 \-------------------------------------------------------------*/
1343
 
1344
task transmit_packet_sequence;
1345
   // transmits a sequence of packets with header parameters already set
1346
   // npackets = number of packets in sequence
1347
   // IFG = inter-frame-gap
1348
   // blocking = 0 => task returns immediately, otherwise waits
1349
   // until all packets have been transmitted
1350
   // timeout: used in blocking mode to avoid indefinite wait
1351
   // value in microseconds
1352
 
1353
      input npackets, IFG;
1354
   input blocking;
1355
   input timeout_value;
1356
   integer npackets, IFG, timeout_value;
1357
 
1358
 
1359
   integer port;
1360
   integer x, y;
1361
   reg [47:0] mac_random;
1362
 
1363
   begin
1364
      if (port_tx_busy)
1365
       begin
1366
          $write("%t: testbench_transmit_packet_sequence:  Port already transmitting, packets not sent\n",$time);
1367
          if (`TERMINATE_ON_TRANSMIT_ERRORS)
1368
           $finish;
1369
       end // if (port_tx_busy)
1370
      else
1371
       begin
1372
          packets_sent = 0;
1373
          user_frame = 0;
1374
          transmit_packet_count = npackets;
1375
          if (IFG > port_min_ifg)
1376
           current_ifg = IFG;
1377
          else
1378
           current_ifg = port_min_ifg;
1379
          port_tx_busy = 1;
1380
 
1381
          if (blocking)
1382
           begin
1383
              transmit_timer_expired = 0;
1384
              transmit_timer = timeout_value;
1385
              transmit_timer_active = 1;
1386
              wait((port_tx_busy == 0) ||
1387
                   (transmit_timer_expired));
1388
              transmit_timer_active = 0;
1389
           end // if (blocking)
1390
 
1391
       end // else: !if(port_busy)
1392
   end
1393
endtask // port_tx_busy
1394
 
1395
task update_header_parameters;
1396
   integer x, y;
1397
   reg [47:0] mac_random;
1398
 
1399
   begin
1400
      // set packet size
1401
      case (L2_frame_size_option)
1402
        1: // incremental
1403
         begin
1404
            current_pkt_size =  current_pkt_size +
1405
                                            L2_frame_size_incr;
1406
            if (current_pkt_size > L2_frame_size_max)
1407
             current_pkt_size = L2_frame_size_max;
1408
            if (current_pkt_size < L2_frame_size_min)
1409
             current_pkt_size = L2_frame_size_min;
1410
         end // case: 1
1411
        2: // random
1412
         begin
1413
            x = $random();
1414
            if (L2_frame_size_max != L2_frame_size_min)
1415
             current_pkt_size = L2_frame_size_min +
1416
                                     (x % (L2_frame_size_max - L2_frame_size_min));
1417
            else
1418
             current_pkt_size = L2_frame_size_min;
1419
         end // case: 2
1420
      endcase // case(L2_frame_size_option)
1421
      // Set source MAC
1422
      case (L2_src_mac_option)
1423
        1: // incremental
1424
         begin
1425
            current_src_mac = current_src_mac +
1426
                                       L2_src_mac_incr;
1427
 
1428
            if (current_src_mac < L2_src_mac_min)
1429
             current_src_mac = L2_src_mac_min;
1430
            if (current_src_mac > L2_src_mac_max)
1431
             current_src_mac = L2_src_mac_max;
1432
         end
1433
        2: // random
1434
         begin
1435
            x = $random();
1436
            y = $random();
1437
            mac_random = {x[15:0], y[31:0]};
1438
            if (L2_src_mac_min != L2_src_mac_max)
1439
             current_src_mac = L2_src_mac_min +
1440
                                  (mac_random % (L2_src_mac_max -
1441
                                                 L2_src_mac_min));
1442
            else
1443
             current_src_mac = L2_src_mac_min;
1444
         end // case: 2
1445
      endcase // case(L2_src_mac_option)
1446
 
1447
          // Set destination MAC
1448
      case (L2_dstn_mac_option)
1449
        1: // incremental
1450
         begin
1451
            current_dstn_mac = current_dstn_mac +
1452
                                       L2_dstn_mac_incr;
1453
 
1454
            if (current_dstn_mac < L2_dstn_mac_min)
1455
             current_dstn_mac = L2_dstn_mac_min;
1456
            if (current_dstn_mac > L2_dstn_mac_max)
1457
             current_dstn_mac = L2_dstn_mac_max;
1458
         end
1459
        2: // random
1460
         begin
1461
            x = $random();
1462
            y = $random();
1463
            mac_random = {x[15:0], y[31:0]};
1464
            if (L2_dstn_mac_min != L2_dstn_mac_max)
1465
             current_dstn_mac = L2_dstn_mac_min +
1466
                                   (mac_random % (L2_dstn_mac_max -
1467
                                                  L2_dstn_mac_min));
1468
            else
1469
             current_dstn_mac = L2_dstn_mac_min;
1470
         end // case: 2
1471
      endcase // case(L2_dstn_mac_option)
1472
 
1473
 
1474
      // set VLAN TCI
1475
      case (L2_VLAN_TCI_option)
1476
        1: // incremental
1477
         begin
1478
            current_VLAN_TCI = current_VLAN_TCI +
1479
                                        L2_VLAN_TCI_incr;
1480
 
1481
            if (current_VLAN_TCI > L2_VLAN_TCI_max)
1482
             current_VLAN_TCI = L2_VLAN_TCI_max;
1483
            if (current_VLAN_TCI < L2_VLAN_TCI_min)
1484
             current_VLAN_TCI = L2_VLAN_TCI_min;
1485
         end // case: 1
1486
 
1487
        2: // random
1488
         begin
1489
            x = $random();
1490
            if (L2_VLAN_TCI_max != L2_VLAN_TCI_min)
1491
             current_VLAN_TCI = L2_VLAN_TCI_min +
1492
                                   (x % (L2_VLAN_TCI_max -
1493
                                         L2_VLAN_TCI_min));
1494
            else
1495
             current_VLAN_TCI = L2_VLAN_TCI_min;
1496
         end // case: 2
1497
      endcase // case(L2_VLAN_TCI_option)
1498
 
1499
   end
1500
endtask // update_header_parameters
1501
 
1502
task transmit_packet_from_buffer;
1503
 
1504
   // transmits a sequence of packets from the given buffer
1505
   // npackets = number of packets in sequence
1506
   // IFG = inter-frame-gap
1507
   // blocking = 0 => task returns immediately, otherwise waits
1508
   // until all packets have been transmitted
1509
   // timeout: used in blocking mode to avoid indefinite wait
1510
   // value in microseconds
1511
 
1512
    input npackets, IFG;
1513
   input [`MAX_PKT_SIZE*8-1:0] packet_data;
1514
   input size;
1515
      input blocking;
1516
      input timeout_value;
1517
      integer npackets, IFG, timeout_value, size;
1518
 
1519
   begin
1520
      if (port_tx_busy) // port currently transmitting
1521
       begin
1522
          $write("%tns: testbench_transmit_packet_from_buffer:  Port already transmitting, packets not sent\n",
1523
                 $time);
1524
          if (`TERMINATE_ON_TRANSMIT_ERRORS)
1525
           $finish;
1526
       end // if (port_tx_busy)
1527
      else
1528
       begin
1529
          user_frame = 1;
1530
          transmit_packet_count = npackets;
1531
          packets_sent = 0;
1532
          if (IFG > port_min_ifg)
1533
           current_ifg = IFG;
1534
          else
1535
           current_ifg = port_min_ifg;
1536
          transmit_pkt = packet_data;
1537
          transmit_pkt_size = size;
1538
          port_tx_busy = 1;
1539
 
1540
          if (blocking)
1541
           begin
1542
              transmit_timer_expired = 0;
1543
              transmit_timer = timeout_value;
1544
              transmit_timer_active = 1;
1545
              wait((port_tx_busy == 0) ||
1546
                   (transmit_timer_expired));
1547
              transmit_timer_active = 0;
1548
           end // if (blocking)
1549
       end // else: !if(port_busy)
1550
   end
1551
endtask // transmit_packet_from_buffer
1552
 
1553
task transmit_pause_frame;
1554
   // Transmit a pause frame to the Device under Test
1555
   // blocking = 0 => task returns immediately, otherwise waits
1556
   // until frame has been transmitted
1557
   // timeout: used in blocking mode to avoid indefinite wait
1558
   // value in microseconds
1559
 
1560
   input [47:0] src_mac; // source MAC address
1561
   input [15:0] pause_time;
1562
   input blocking, timeout_value;
1563
   integer timeout_value;
1564
 
1565
   reg [`MAX_PKT_SIZE*8-1:0] packet_data;
1566
   integer size;
1567
   begin
1568
      if (port_tx_busy)
1569
       begin
1570
          $write("testbench_transmit_pause_frame:  Port already transmitting, packets not sent\n");
1571
          if (`TERMINATE_ON_TRANSMIT_ERRORS)
1572
           $finish;
1573
       end // if (port_tx_busy)
1574
      else
1575
       begin
1576
          user_frame = 1;
1577
          transmit_packet_count = 1;
1578
          packets_sent = 0;
1579
          user_frame_current_ifg = port_min_ifg;
1580
          construct_pause_frame(src_mac, pause_time, packet_data, size);
1581
          transmit_pkt = packet_data;
1582
          transmit_pkt_size = size;
1583
          port_tx_busy = 1;
1584
 
1585
          if (blocking)
1586
           begin
1587
              transmit_timer_expired = 0;
1588
              transmit_timer = timeout_value;
1589
              transmit_timer_active = 1;
1590
              wait((port_tx_busy == 0) ||
1591
                   (transmit_timer_expired));
1592
              transmit_timer_active = 0;
1593
           end // if (blocking)
1594
       end // else: !if(port_tx_busy[port])
1595
   end
1596
endtask // testbench_transmit_pause_frame
1597
 
1598
 
1599
task read_transmit_buffer;
1600
   // returns last packet transmitted
1601
   // must be called when the transmitter in state
1602
   // `TRANSMIT_FRAME to get correct CRC
1603
   output [`MAX_PKT_SIZE*8-1:0] buffer;
1604
   output size;
1605
   integer size;
1606
   begin
1607
      buffer = transmit_pkt;
1608
      size = transmit_pkt_size;
1609
   end
1610
endtask // read_transmit_buffer
1611
 
1612
task receive_packet;
1613
   output [`MAX_PKT_SIZE*8-1:0] buffer;
1614
   output size;
1615
   integer size;
1616
   begin
1617
      wait (receive_data_available);
1618
      buffer = receive_pkt;
1619
      size = receive_pkt_size;
1620
      receive_data_available = 0;
1621
   end
1622
endtask // receive_packet   
1623
 
1624
 
1625
 /*-------------------------------------------------------------\
1626
 |                                                              |
1627
 |      Tasks for event and status reporting                    |
1628
 |                                                              |
1629
 \-------------------------------------------------------------*/
1630
 
1631
 
1632
task get_transmit_state;
1633
   output state;
1634
   integer state;
1635
   // monitors state of transmit port
1636
   begin
1637
      if (mii_transmit_state == 2)
1638
       state = 1; // curently transmitting a frame
1639
      else
1640
       if (mii_transmit_state == 3)
1641
        state = 2; // curently resolving a collision
1642
       else
1643
        if (port_tx_busy == 1)
1644
         state = 3; // in the middle of a packet sequence
1645
        else
1646
         state = 0; // idle
1647
   end
1648
endtask // get_transmit_state
1649
 
1650
 
1651
task get_receive_state;
1652
   output state;
1653
   integer state;
1654
   // monitors state of receive port
1655
   begin
1656
      if (mii_receive_state == 2)
1657
       state = 1; // curently receiving a frame
1658
      else
1659
       if (mii_receive_state == 3)
1660
        state = 2; // curently resolving a collision
1661
       else
1662
        state = 0; // idle
1663
   end
1664
endtask // get_receive_state
1665
 
1666
task wait_for_event;
1667
   // waits for designated event
1668
   input event_type, value;
1669
   integer event_type, value;
1670
   begin
1671
      case(event_type)
1672
        1: begin // wait until transmission of current frame starts
1673
           wait(mii_transmit_state == 2);
1674
        end // case: 1
1675
 
1676
        2: begin // wait until transmission of current packet sequence ends
1677
           wait (port_tx_busy == 0);
1678
        end
1679
 
1680
        3: begin // wait until transmission of current frame ends
1681
           @(posedge transmit_done);
1682
        end
1683
 
1684
        4: begin // wait for arrival of first bit of next frame
1685
           @(posedge mii_SFD_received);
1686
        end
1687
        5: begin // wait until last bit of current frame is received
1688
           @(posedge receive_data_valid);
1689
        end
1690
 
1691
        6: begin // wait until a collision is detected at the port
1692
           wait(mii_transmit_state == 3);
1693
        end
1694
 
1695
        7: begin // wait until collision detected and collision counter = value
1696
           wait ((mii_transmit_state == 3) &&
1697
                 (mii_collision_counter == value));
1698
        end
1699
        default: begin
1700
           $display("%t ns: testbench_wait-for_event: Invalid event type_new",$time);
1701
           if (`TERMINATE_ON_PARAM_ERRORS)
1702
            $finish;
1703
        end // case: default
1704
      endcase // case(event_type)
1705
   end
1706
endtask // testbench_wait_for_event
1707
 

powered by: WebSVN 2.1.0

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