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
2f308d01
Commit
2f308d01
authored
Apr 22, 2022
by
Antoine Kaufmann
Browse files
sims/net/wire: new API refactor
parent
7f1b94ae
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
44 deletions
+32
-44
sims/net/wire/net_wire.c
sims/net/wire/net_wire.c
+31
-43
sims/net/wire/rules.mk
sims/net/wire/rules.mk
+1
-1
No files found.
sims/net/wire/net_wire.c
View file @
2f308d01
...
...
@@ -36,11 +36,8 @@
#include <sys/mman.h>
#include <unistd.h>
#include <simbricks/netif/netif.h>
#include <simbricks/proto/base.h>
#include <simbricks/network/if.h>
static
uint64_t
sync_period
=
(
500
*
1000ULL
);
// 500ns
static
uint64_t
eth_latency
=
(
500
*
1000ULL
);
// 500ns
static
uint64_t
cur_ts
;
static
int
exiting
=
0
;
static
pcap_dumper_t
*
dumpfile
=
NULL
;
...
...
@@ -54,20 +51,20 @@ static void sigusr1_handler(int dummy) {
}
static
void
move_pkt
(
struct
SimbricksNetIf
*
from
,
struct
SimbricksNetIf
*
to
)
{
volatile
union
SimbricksProtoNet
D2N
*
msg_from
=
SimbricksNetIf
D2N
Poll
(
from
,
cur_ts
);
volatile
union
SimbricksProtoNet
N2D
*
msg_to
;
volatile
struct
SimbricksProtoNet
D2NSend
*
tx
;
volatile
struct
SimbricksProtoNet
N2DRecv
*
rx
;
volatile
union
SimbricksProtoNet
Msg
*
msg_from
=
SimbricksNetIf
In
Poll
(
from
,
cur_ts
);
volatile
union
SimbricksProtoNet
Msg
*
msg_to
;
volatile
struct
SimbricksProtoNet
MsgPacket
*
tx
;
volatile
struct
SimbricksProtoNet
MsgPacket
*
rx
;
struct
pcap_pkthdr
ph
;
uint8_t
type
;
if
(
msg_from
==
NULL
)
return
;
type
=
msg_from
->
dummy
.
own_type
&
SIMBRICKS_PROTO_NET_D2N_MSG_MASK
;
if
(
type
==
SIMBRICKS_PROTO_NET_
D2N_MSG_SEND
)
{
tx
=
&
msg_from
->
send
;
type
=
SimbricksNetIfInType
(
from
,
msg_from
)
;
if
(
type
==
SIMBRICKS_PROTO_NET_
MSG_PACKET
)
{
tx
=
&
msg_from
->
packet
;
// log to pcap file if initialized
if
(
dumpfile
)
{
...
...
@@ -79,38 +76,38 @@ static void move_pkt(struct SimbricksNetIf *from, struct SimbricksNetIf *to) {
pcap_dump
((
unsigned
char
*
)
dumpfile
,
&
ph
,
(
unsigned
char
*
)
tx
->
data
);
}
msg_to
=
SimbricksNetIf
N2D
Alloc
(
to
,
cur_ts
,
eth_latency
);
msg_to
=
SimbricksNetIf
Out
Alloc
(
to
,
cur_ts
);
if
(
msg_to
!=
NULL
)
{
rx
=
&
msg_to
->
recv
;
rx
=
&
msg_to
->
packet
;
rx
->
len
=
tx
->
len
;
rx
->
port
=
0
;
memcpy
((
void
*
)
rx
->
data
,
(
void
*
)
tx
->
data
,
tx
->
len
);
// WMB();
rx
->
own_type
=
SIMBRICKS_PROTO_NET_N2D_MSG_RECV
|
SIMBRICKS_PROTO_NET_N2D_OWN_DEV
;
SimbricksNetIfOutSend
(
to
,
msg_to
,
SIMBRICKS_PROTO_NET_MSG_PACKET
);
}
else
{
fprintf
(
stderr
,
"move_pkt: dropping packet
\n
"
);
}
}
else
if
(
type
==
SIMBRICKS_PROTO_
NET_D2N_MSG
_SYNC
)
{
}
else
if
(
type
==
SIMBRICKS_PROTO_
MSG_TYPE
_SYNC
)
{
}
else
{
fprintf
(
stderr
,
"move_pkt: unsupported type=%u
\n
"
,
type
);
abort
();
}
SimbricksNetIf
D2N
Done
(
from
,
msg_from
);
SimbricksNetIf
In
Done
(
from
,
msg_from
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
struct
SimbricksBaseIfParams
params
;
struct
SimbricksNetIf
nsif_a
,
nsif_b
;
uint64_t
ts_a
,
ts_b
;
int
sync_a
,
sync_b
;
pcap_t
*
pc
=
NULL
;
int
sync_mode
=
SIMBRICKS_PROTO_SYNC_SIMBRICKS
;
SimbricksNetIfDefaultParams
(
&
params
);
if
(
argc
<
3
||
argc
>
7
)
{
fprintf
(
stderr
,
"Usage: net_wire SOCKET-A SOCKET-B [SYNC-MODE] "
"Usage: net_wire SOCKET-A SOCKET-B [SYNC-MODE
(ignored)
] "
"[SYNC-PERIOD] [ETH-LATENCY] [PCAP-FILE]
\n
"
);
return
EXIT_FAILURE
;
}
...
...
@@ -119,14 +116,12 @@ int main(int argc, char *argv[]) {
signal
(
SIGTERM
,
sigint_handler
);
signal
(
SIGUSR1
,
sigusr1_handler
);
if
(
argc
>=
4
)
sync_mode
=
strtol
(
argv
[
3
],
NULL
,
0
);
if
(
argc
>=
5
)
sync_period
=
strtoull
(
argv
[
4
],
NULL
,
0
)
*
1000ULL
;
params
.
sync_interval
=
strtoull
(
argv
[
4
],
NULL
,
0
)
*
1000ULL
;
if
(
argc
>=
6
)
eth
_latency
=
strtoull
(
argv
[
5
],
NULL
,
0
)
*
1000ULL
;
params
.
link
_latency
=
strtoull
(
argv
[
5
],
NULL
,
0
)
*
1000ULL
;
if
(
argc
>=
7
)
{
pc
=
pcap_open_dead_with_tstamp_precision
(
DLT_EN10MB
,
65535
,
...
...
@@ -139,46 +134,39 @@ int main(int argc, char *argv[]) {
dumpfile
=
pcap_dump_open
(
pc
,
argv
[
6
]);
}
assert
(
sync_mode
==
SIMBRICKS_PROTO_SYNC_SIMBRICKS
||
sync_mode
==
SIMBRICKS_PROTO_SYNC_BARRIER
);
sync_a
=
sync_b
=
1
;
if
(
SimbricksNetIfInit
(
&
nsif_a
,
argv
[
1
],
&
sync_a
)
!=
0
)
{
if
(
SimbricksNetIfInit
(
&
nsif_a
,
&
params
,
argv
[
1
],
&
sync_a
)
!=
0
)
{
return
-
1
;
}
if
(
SimbricksNetIfInit
(
&
nsif_b
,
argv
[
2
],
&
sync_b
)
!=
0
)
{
if
(
SimbricksNetIfInit
(
&
nsif_b
,
&
params
,
argv
[
2
],
&
sync_b
)
!=
0
)
{
return
-
1
;
}
printf
(
"start polling
\n
"
);
while
(
!
exiting
)
{
if
(
SimbricksNetIfN2DSync
(
&
nsif_a
,
cur_ts
,
eth_latency
,
sync_period
,
sync_mode
)
!=
0
)
{
fprintf
(
stderr
,
"SimbricksNetIfN2DSync(nsif_a) failed
\n
"
);
if
(
SimbricksNetIfOutSync
(
&
nsif_a
,
cur_ts
)
!=
0
)
{
fprintf
(
stderr
,
"SimbricksNetIfOutSync(nsif_a) failed
\n
"
);
abort
();
}
if
(
SimbricksNetIfN2DSync
(
&
nsif_b
,
cur_ts
,
eth_latency
,
sync_period
,
sync_mode
)
!=
0
)
{
fprintf
(
stderr
,
"SimbricksNetIfN2DSync(nsif_a) failed
\n
"
);
if
(
SimbricksNetIfOutSync
(
&
nsif_b
,
cur_ts
)
!=
0
)
{
fprintf
(
stderr
,
"SimbricksNetIfN2DSync(nsif_b) failed
\n
"
);
abort
();
}
SimbricksNetIfAdvanceEpoch
(
cur_ts
,
sync_period
,
sync_mode
);
do
{
move_pkt
(
&
nsif_a
,
&
nsif_b
);
move_pkt
(
&
nsif_b
,
&
nsif_a
);
ts_a
=
SimbricksNetIf
D2N
Timestamp
(
&
nsif_a
);
ts_b
=
SimbricksNetIf
D2N
Timestamp
(
&
nsif_b
);
ts_a
=
SimbricksNetIf
In
Timestamp
(
&
nsif_a
);
ts_b
=
SimbricksNetIf
In
Timestamp
(
&
nsif_b
);
}
while
(
!
exiting
&&
((
sync_a
&&
ts_a
<=
cur_ts
)
||
(
sync_b
&&
ts_b
<=
cur_ts
)));
if
(
sync_a
&&
sync_b
)
cur_ts
=
SimbricksNetIfAdvanceTime
(
ts_a
<=
ts_b
?
ts_a
:
ts_b
,
sync_period
,
sync_mode
);
cur_ts
=
ts_a
<=
ts_b
?
ts_a
:
ts_b
;
else
if
(
sync_a
)
cur_ts
=
SimbricksNetIfAdvanceTime
(
ts_a
,
sync_period
,
sync_mode
)
;
cur_ts
=
ts_a
;
else
if
(
sync_b
)
cur_ts
=
SimbricksNetIfAdvanceTime
(
ts_b
,
sync_period
,
sync_mode
)
;
cur_ts
=
ts_b
;
}
if
(
dumpfile
)
...
...
sims/net/wire/rules.mk
View file @
2f308d01
...
...
@@ -28,7 +28,7 @@ OBJS := $(d)net_wire.o
$(OBJS)
:
CPPFLAGS := $(CPPFLAGS) -I$(d)include/
$(bin_net_wire)
:
$(OBJS) $(lib_netif) -lpcap
$(bin_net_wire)
:
$(OBJS) $(lib_netif)
$(lib_base)
-lpcap
CLEAN
:=
$(bin_net_wire)
$(OBJS)
ALL
:=
$(bin_net_wire)
...
...
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