//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
//// ////
|
//// ////
|
//// File name "sc_pkt_generator.cpp" ////
|
//// File name "sc_pkt_generator.cpp" ////
|
//// ////
|
//// ////
|
//// This file is part of the "10GE MAC" project ////
|
//// This file is part of the "10GE MAC" project ////
|
//// http://www.opencores.org/cores/xge_mac/ ////
|
//// http://www.opencores.org/cores/xge_mac/ ////
|
//// ////
|
//// ////
|
//// Author(s): ////
|
//// Author(s): ////
|
//// - A. Tanguay (antanguay@opencores.org) ////
|
//// - A. Tanguay (antanguay@opencores.org) ////
|
//// ////
|
//// ////
|
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
//// ////
|
//// ////
|
//// Copyright (C) 2008 AUTHORS. All rights reserved. ////
|
//// Copyright (C) 2008 AUTHORS. All rights reserved. ////
|
//// ////
|
//// ////
|
//// This source file may be used and distributed without ////
|
//// This source file may be used and distributed without ////
|
//// restriction provided that this copyright statement is not ////
|
//// restriction provided that this copyright statement is not ////
|
//// removed from the file and that any derivative work contains ////
|
//// removed from the file and that any derivative work contains ////
|
//// the original copyright notice and the associated disclaimer. ////
|
//// the original copyright notice and the associated disclaimer. ////
|
//// ////
|
//// ////
|
//// This source file is free software; you can redistribute it ////
|
//// This source file is free software; you can redistribute it ////
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
//// Public License as published by the Free Software Foundation; ////
|
//// Public License as published by the Free Software Foundation; ////
|
//// either version 2.1 of the License, or (at your option) any ////
|
//// either version 2.1 of the License, or (at your option) any ////
|
//// later version. ////
|
//// later version. ////
|
//// ////
|
//// ////
|
//// This source is distributed in the hope that it will be ////
|
//// This source is distributed in the hope that it will be ////
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
//// details. ////
|
//// details. ////
|
//// ////
|
//// ////
|
//// You should have received a copy of the GNU Lesser General ////
|
//// You should have received a copy of the GNU Lesser General ////
|
//// Public License along with this source; if not, download it ////
|
//// Public License along with this source; if not, download it ////
|
//// from http://www.opencores.org/lgpl.shtml ////
|
//// from http://www.opencores.org/lgpl.shtml ////
|
//// ////
|
//// ////
|
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
|
|
#include <stdio.h>
|
#include <stdio.h>
|
#include <iostream>
|
#include <iostream>
|
#include <sys/times.h>
|
#include <sys/times.h>
|
#include <sys/stat.h>
|
#include <sys/stat.h>
|
|
|
#include "systemc.h"
|
#include "systemc.h"
|
|
|
#include "sc_pkt_generator.h"
|
#include "sc_pkt_generator.h"
|
|
|
|
|
void pkt_generator::init(void) {
|
void pkt_generator::init(void) {
|
crc_interval = 0;
|
crc_interval = 0;
|
fragment_interval = 0;
|
fragment_interval = 0;
|
|
lenght_err_interval = 0;
|
|
lenght_err_size = 10000;
|
coding_interval = 0;
|
coding_interval = 0;
|
local_fault_interval = 0;
|
local_fault_interval = 0;
|
remote_fault_interval = 0;
|
remote_fault_interval = 0;
|
}
|
}
|
|
|
void pkt_generator::connect_fifo(sc_fifo<packet_t*> * fifo) {
|
void pkt_generator::connect_fifo(sc_fifo<packet_t*> * fifo) {
|
tx_fifo = fifo;
|
tx_fifo = fifo;
|
}
|
}
|
|
|
|
|
void pkt_generator::gen_packet() {
|
void pkt_generator::gen_packet() {
|
|
|
int len = 0;
|
int len = 0;
|
int crc_int = 0;
|
int crc_int = 0;
|
int fragment_int = 0;
|
int fragment_int = 0;
|
|
int lenght_err_int = 0;
|
int coding_int = 0;
|
int coding_int = 0;
|
int local_fault_int = 0;
|
int local_fault_int = 0;
|
int remote_fault_int = 0;
|
int remote_fault_int = 0;
|
int fault_spacing = 120;
|
int fault_spacing = 120;
|
int pause_int = 0;
|
int pause_int = 0;
|
char running_cnt = 0;
|
char running_cnt = 0;
|
|
|
while (true) {
|
while (true) {
|
|
|
wait(5, SC_NS);
|
wait(5, SC_NS);
|
|
|
if (tx_bucket != 0 && tx_fifo->num_available() == 0) {
|
if (tx_bucket != 0 && tx_fifo->num_available() == 0) {
|
|
|
//--
|
//--
|
// Check fifo
|
// Check fifo
|
|
|
if (tx_fifo == NULL || tx_fifo->num_free() == 0) {
|
if (tx_fifo == NULL || tx_fifo->num_free() == 0) {
|
cout << "ERROR: FIFO not defined or full" << endl;
|
cout << "ERROR: FIFO not defined or full" << endl;
|
sc_stop();
|
sc_stop();
|
}
|
}
|
|
|
//---
|
//---
|
// Update constraints
|
// Update constraints
|
|
|
if (len < min_pkt_size) {
|
if (len < min_pkt_size) {
|
len = min_pkt_size;
|
len = min_pkt_size;
|
}
|
}
|
|
|
if (len > max_pkt_size) {
|
if (len > max_pkt_size) {
|
len = min_pkt_size;
|
len = min_pkt_size;
|
}
|
}
|
|
|
//--
|
//--
|
// Generate packet
|
// Generate packet
|
|
|
packet_t* pkt = new(packet_t);
|
packet_t* pkt = new(packet_t);
|
|
|
for (int i = 0; i < len+8; i++) {
|
for (int i = 0; i < len+8; i++) {
|
pkt->payload[i] = len+i;
|
pkt->payload[i] = len+i;
|
}
|
}
|
pkt->payload[0] = running_cnt;
|
pkt->payload[0] = running_cnt;
|
running_cnt++;
|
running_cnt++;
|
|
|
pkt->length = len;
|
pkt->length = len;
|
|
|
//---
|
//---
|
// Inject errors
|
// Inject errors
|
|
|
if (crc_interval != 0) {
|
if (crc_interval != 0) {
|
if (crc_int >= crc_interval) {
|
if (crc_int >= crc_interval) {
|
pkt->err_flags |= PKT_FLAG_ERR_CRC;
|
pkt->err_flags |= PKT_FLAG_ERR_CRC;
|
crc_int = 0;
|
crc_int = 0;
|
}
|
}
|
else {
|
else {
|
crc_int++;
|
crc_int++;
|
}
|
}
|
}
|
}
|
else {
|
else {
|
crc_int = 0;
|
crc_int = 0;
|
}
|
}
|
|
|
if (fragment_interval != 0) {
|
if (fragment_interval != 0) {
|
if (fragment_int >= fragment_interval) {
|
if (fragment_int >= fragment_interval) {
|
pkt->err_flags |= PKT_FLAG_ERR_FRG;
|
pkt->err_flags |= PKT_FLAG_ERR_FRG;
|
fragment_int = 0;
|
fragment_int = 0;
|
}
|
}
|
else {
|
else {
|
fragment_int++;
|
fragment_int++;
|
}
|
}
|
}
|
}
|
else {
|
else {
|
fragment_int = 0;
|
fragment_int = 0;
|
}
|
}
|
|
|
|
if (lenght_err_interval != 0) {
|
|
if (lenght_err_int >= lenght_err_interval) {
|
|
pkt->err_flags |= PKT_FLAG_ERR_LENGHT;
|
|
lenght_err_int = 0;
|
|
pkt->length = lenght_err_size;
|
|
}
|
|
else {
|
|
lenght_err_int++;
|
|
}
|
|
}
|
|
else {
|
|
lenght_err_int = 0;
|
|
}
|
|
|
if (coding_interval != 0) {
|
if (coding_interval != 0) {
|
if (coding_int >= coding_interval) {
|
if (coding_int >= coding_interval) {
|
pkt->err_flags |= PKT_FLAG_ERR_CODING;
|
pkt->err_flags |= PKT_FLAG_ERR_CODING;
|
coding_int = 0;
|
coding_int = 0;
|
}
|
}
|
else {
|
else {
|
coding_int++;
|
coding_int++;
|
}
|
}
|
}
|
}
|
else {
|
else {
|
coding_int = 0;
|
coding_int = 0;
|
}
|
}
|
|
|
//--
|
//--
|
// Inject local / remote faults
|
// Inject local / remote faults
|
|
|
if (local_fault_interval != 0) {
|
if (local_fault_interval != 0) {
|
if (local_fault_int >= local_fault_interval) {
|
if (local_fault_int >= local_fault_interval) {
|
|
|
pkt->err_flags |= PKT_FLAG_LOCAL_FAULT;
|
pkt->err_flags |= PKT_FLAG_LOCAL_FAULT;
|
local_fault_int = 0;
|
local_fault_int = 0;
|
|
|
fault_spacing++;
|
fault_spacing++;
|
if (fault_spacing > (132 - 4)) {
|
if (fault_spacing > (132 - 4)) {
|
fault_spacing = 120;
|
fault_spacing = 120;
|
}
|
}
|
pkt->err_info = fault_spacing;
|
pkt->err_info = fault_spacing;
|
}
|
}
|
else {
|
else {
|
local_fault_int++;
|
local_fault_int++;
|
}
|
}
|
}
|
}
|
else {
|
else {
|
local_fault_int = 0;
|
local_fault_int = 0;
|
}
|
}
|
|
|
if (remote_fault_interval != 0) {
|
if (remote_fault_interval != 0) {
|
if (remote_fault_int >= remote_fault_interval) {
|
if (remote_fault_int >= remote_fault_interval) {
|
|
|
pkt->err_flags |= PKT_FLAG_REMOTE_FAULT;
|
pkt->err_flags |= PKT_FLAG_REMOTE_FAULT;
|
remote_fault_int = 0;
|
remote_fault_int = 0;
|
|
|
fault_spacing++;
|
fault_spacing++;
|
if (fault_spacing > (132 - 4)) {
|
if (fault_spacing > (132 - 4)) {
|
fault_spacing = 120;
|
fault_spacing = 120;
|
}
|
}
|
pkt->err_info = fault_spacing;
|
pkt->err_info = fault_spacing;
|
}
|
}
|
else {
|
else {
|
remote_fault_int++;
|
remote_fault_int++;
|
}
|
}
|
}
|
}
|
else {
|
else {
|
remote_fault_int = 0;
|
remote_fault_int = 0;
|
}
|
}
|
|
|
//--
|
//--
|
// Inject PAUSE frames
|
// Inject PAUSE frames
|
|
|
if (inject_pause_interval != 0) {
|
if (inject_pause_interval != 0) {
|
if (pause_int >= inject_pause_interval) {
|
if (pause_int >= inject_pause_interval) {
|
|
|
pkt->dest_addr = 0x0180c2;
|
pkt->dest_addr = 0x0180c2;
|
pkt->dest_addr = (pkt->dest_addr << 24) | 0x000001;
|
pkt->dest_addr = (pkt->dest_addr << 24) | 0x000001;
|
pause_int = 0;
|
pause_int = 0;
|
|
|
}
|
}
|
else {
|
else {
|
pause_int++;
|
pause_int++;
|
}
|
}
|
}
|
}
|
|
|
//--
|
//--
|
// Send packet
|
// Send packet
|
|
|
tx_fifo->write(pkt);
|
tx_fifo->write(pkt);
|
|
|
tx_bucket--;
|
tx_bucket--;
|
len++;
|
len++;
|
|
|
}
|
}
|
else {
|
else {
|
wait(50, SC_NS);
|
wait(50, SC_NS);
|
}
|
}
|
|
|
}
|
}
|
}
|
}
|
|
|
void pkt_generator::set_tx_bucket(int cnt) {
|
void pkt_generator::set_tx_bucket(int cnt) {
|
tx_bucket = cnt;
|
tx_bucket = cnt;
|
}
|
}
|
|
|
int pkt_generator::get_tx_bucket(void) {
|
int pkt_generator::get_tx_bucket(void) {
|
return tx_bucket;
|
return tx_bucket;
|
}
|
}
|
|
|
void pkt_generator::set_pkt_size(int min, int max) {
|
void pkt_generator::set_pkt_size(int min, int max) {
|
|
|
min_pkt_size = min;
|
min_pkt_size = min;
|
max_pkt_size = max;
|
max_pkt_size = max;
|
|
|
}
|
}
|
|
|
void pkt_generator::set_crc_errors(int interval) {
|
void pkt_generator::set_crc_errors(int interval) {
|
crc_interval = interval;
|
crc_interval = interval;
|
}
|
}
|
|
|
void pkt_generator::set_fragment_errors(int interval) {
|
void pkt_generator::set_fragment_errors(int interval) {
|
fragment_interval = interval;
|
fragment_interval = interval;
|
}
|
}
|
|
|
|
void pkt_generator::set_lenght_errors(int interval, int size) {
|
|
lenght_err_interval = interval;
|
|
lenght_err_size = size;
|
|
}
|
|
|
void pkt_generator::set_coding_errors(int interval) {
|
void pkt_generator::set_coding_errors(int interval) {
|
coding_interval = interval;
|
coding_interval = interval;
|
}
|
}
|
|
|
void pkt_generator::set_local_fault(int interval) {
|
void pkt_generator::set_local_fault(int interval) {
|
local_fault_interval = interval;
|
local_fault_interval = interval;
|
}
|
}
|
|
|
void pkt_generator::set_remote_fault(int interval) {
|
void pkt_generator::set_remote_fault(int interval) {
|
remote_fault_interval = interval;
|
remote_fault_interval = interval;
|
}
|
}
|
|
|
void pkt_generator::set_inject_pause(int interval) {
|
void pkt_generator::set_inject_pause(int interval) {
|
inject_pause_interval = interval;
|
inject_pause_interval = interval;
|
}
|
}
|
|
|