Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ycai
simbricks
Commits
08cebb0c
Commit
08cebb0c
authored
Nov 25, 2020
by
Antoine Kaufmann
Browse files
net_switch: add parameters for latencies
parent
f73b15de
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
7 deletions
+20
-7
net_switch/net_switch.cc
net_switch/net_switch.cc
+20
-7
No files found.
net_switch/net_switch.cc
View file @
08cebb0c
...
@@ -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
();
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment