Commit 08cebb0c authored by Antoine Kaufmann's avatar Antoine Kaufmann
Browse files

net_switch: add parameters for latencies

parent f73b15de
...@@ -11,8 +11,8 @@ extern "C" { ...@@ -11,8 +11,8 @@ extern "C" {
#include <netsim.h> #include <netsim.h>
}; };
#define SYNC_PERIOD (500 * 1000ULL) // 500ns static uint64_t sync_period = (500 * 1000ULL); // 500ns
#define ETH_LATENCY (500 * 1000ULL) // 500ns static uint64_t eth_latency = (500 * 1000ULL); // 500ns
/* MAC address type */ /* MAC address type */
struct MAC { struct MAC {
...@@ -60,7 +60,7 @@ static void sigint_handler(int dummy) ...@@ -60,7 +60,7 @@ static void sigint_handler(int dummy)
static void forward_pkt(volatile struct cosim_eth_proto_d2n_send *tx, int port) static void forward_pkt(volatile struct cosim_eth_proto_d2n_send *tx, int port)
{ {
volatile union cosim_eth_proto_n2d *msg_to; volatile union cosim_eth_proto_n2d *msg_to;
msg_to = netsim_n2d_alloc(&nsifs[port], cur_ts, ETH_LATENCY); msg_to = netsim_n2d_alloc(&nsifs[port], cur_ts, eth_latency);
if (msg_to != NULL) { if (msg_to != NULL) {
volatile struct cosim_eth_proto_n2d_recv *rx; volatile struct cosim_eth_proto_n2d_recv *rx;
rx = &msg_to->recv; rx = &msg_to->recv;
...@@ -117,9 +117,10 @@ static void switch_pkt(struct netsim_interface *nsif, int iport) ...@@ -117,9 +117,10 @@ static void switch_pkt(struct netsim_interface *nsif, int iport)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int c; int c;
int bad_option = 0;
// Parse command line argument // Parse command line argument
while ((c = getopt(argc, argv, "s:")) != -1) { while ((c = getopt(argc, argv, "s:S:E:")) != -1 && !bad_option) {
switch (c) { switch (c) {
case 's': { case 's': {
struct netsim_interface nsif; struct netsim_interface nsif;
...@@ -131,13 +132,25 @@ int main(int argc, char *argv[]) ...@@ -131,13 +132,25 @@ int main(int argc, char *argv[])
nsifs.push_back(nsif); nsifs.push_back(nsif);
break; break;
} }
case 'S':
sync_period = strtoull(optarg, NULL, 0) * 1000ULL;
break;
case 'E':
eth_latency = strtoull(optarg, NULL, 0) * 1000ULL;
break;
default: default:
fprintf(stderr, "unknown option %c\n", c); fprintf(stderr, "unknown option %c\n", c);
bad_option = 1;
break;
} }
} }
if (nsifs.empty()) { if (nsifs.empty() || bad_option) {
fprintf(stderr, "Usage: net_switch -s SOCKET-A [-s SOCKET-B ...]\n"); fprintf(stderr, "Usage: net_switch [-S SYNC-PERIOD] [-E ETH-LATENCY] "
"-s SOCKET-A [-s SOCKET-B ...]\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
...@@ -148,7 +161,7 @@ int main(int argc, char *argv[]) ...@@ -148,7 +161,7 @@ int main(int argc, char *argv[])
while (!exiting) { while (!exiting) {
// Sync all interfaces // Sync all interfaces
for (auto &nsif : nsifs) { for (auto &nsif : nsifs) {
if (netsim_n2d_sync(&nsif, cur_ts, ETH_LATENCY, SYNC_PERIOD) != 0) { if (netsim_n2d_sync(&nsif, cur_ts, eth_latency, sync_period) != 0) {
fprintf(stderr, "netsim_n2d_sync failed\n"); fprintf(stderr, "netsim_n2d_sync failed\n");
abort(); abort();
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment