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
a194b94f
Commit
a194b94f
authored
Jun 09, 2020
by
Antoine Kaufmann
Browse files
net tap: support for receive
parent
4b89b515
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
7 deletions
+42
-7
net_tap/Makefile
net_tap/Makefile
+1
-0
net_tap/net_tap.c
net_tap/net_tap.c
+41
-7
No files found.
net_tap/Makefile
View file @
a194b94f
CPPFLAGS
+=
-I
../proto
CFLAGS
+=
-Wall
-Wextra
-Wno-unused-parameter
-O3
LDLIBS
+=
-lpthread
net_tap
:
net_tap.o
...
...
net_tap/net_tap.c
View file @
a194b94f
...
...
@@ -22,6 +22,7 @@
*/
#include <fcntl.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
...
...
@@ -56,7 +57,7 @@ int uxsocket_connect(const char *path)
/* prepare and connect socket */
memset
(
&
saun
,
0
,
sizeof
(
saun
));
saun
.
sun_family
=
AF_UNIX
;
strcpy
(
saun
.
sun_path
,
"/tmp/cosim-e
th
"
);
strcpy
(
saun
.
sun_path
,
pa
th
);
if
((
fd
=
socket
(
AF_UNIX
,
SOCK_STREAM
,
0
))
==
-
1
)
{
perror
(
"socket failed"
);
...
...
@@ -155,16 +156,11 @@ static int tap_open(const char *name)
static
void
d2n_send
(
volatile
struct
cosim_eth_proto_d2n_send
*
s
)
{
printf
(
"sent packet: len=%u
\n
"
,
s
->
len
);
if
(
write
(
tap_fd
,
(
void
*
)
s
->
data
,
s
->
len
)
!=
(
ssize_t
)
s
->
len
)
{
perror
(
"d2n_send: send failed"
);
}
/*uint16_t i;
printf("packet [len=%u]:", s->len);
for (i = 0; i < s->len; i++) {
printf(" %02x", s->data[i]);
}
printf("\n");*/
}
static
void
poll_d2n
(
void
)
...
...
@@ -194,6 +190,39 @@ static void poll_d2n(void)
d2n_pos
=
(
d2n_pos
+
1
)
%
d2n_enum
;
}
static
void
*
rx_handler
(
void
*
arg
)
{
volatile
union
cosim_eth_proto_n2d
*
msg
;
volatile
struct
cosim_eth_proto_n2d_recv
*
rx
;
ssize_t
len
;
while
(
1
)
{
msg
=
(
volatile
union
cosim_eth_proto_n2d
*
)
(
n2d_queue
+
n2d_pos
*
n2d_elen
);
if
((
msg
->
dummy
.
own_type
&
COSIM_ETH_PROTO_N2D_OWN_MASK
)
!=
COSIM_ETH_PROTO_N2D_OWN_NET
)
{
fprintf
(
stderr
,
"coudl not allocate message for rx
\n
"
);
abort
();
}
rx
=
&
msg
->
recv
;
len
=
read
(
tap_fd
,
(
void
*
)
rx
->
data
,
n2d_elen
-
sizeof
(
*
msg
));
if
(
len
<=
0
)
{
perror
(
"rx handler: read failed"
);
}
rx
->
len
=
len
;
rx
->
port
=
0
;
printf
(
"received packet: len=%u
\n
"
,
rx
->
len
);
// WMB();
rx
->
own_type
=
COSIM_ETH_PROTO_N2D_MSG_RECV
|
COSIM_ETH_PROTO_N2D_OWN_DEV
;
n2d_pos
=
(
n2d_pos
+
1
)
%
n2d_enum
;
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
struct
cosim_eth_proto_dev_intro
di
;
...
...
@@ -237,6 +266,11 @@ int main(int argc, char *argv[])
n2d_enum
=
di
.
n2d_nentries
;
d2n_pos
=
n2d_pos
=
0
;
pthread_t
worker
;
if
(
pthread_create
(
&
worker
,
NULL
,
rx_handler
,
NULL
)
!=
0
)
{
return
EXIT_FAILURE
;
}
printf
(
"start polling
\n
"
);
while
(
1
)
{
poll_d2n
();
...
...
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