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
ffe2c856
Commit
ffe2c856
authored
Apr 30, 2021
by
Jialin Li
Browse files
net_switch: add pcap support
parent
ceb7e071
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
1 deletion
+27
-1
sims/net/switch/net_switch.cc
sims/net/switch/net_switch.cc
+27
-1
No files found.
sims/net/switch/net_switch.cc
View file @
ffe2c856
...
@@ -23,6 +23,7 @@
...
@@ -23,6 +23,7 @@
*/
*/
#include <unistd.h>
#include <unistd.h>
#include <pcap/pcap.h>
#include <cassert>
#include <cassert>
#include <climits>
#include <climits>
...
@@ -40,6 +41,7 @@ extern "C" {
...
@@ -40,6 +41,7 @@ extern "C" {
static
uint64_t
sync_period
=
(
500
*
1000ULL
);
// 500ns
static
uint64_t
sync_period
=
(
500
*
1000ULL
);
// 500ns
static
uint64_t
eth_latency
=
(
500
*
1000ULL
);
// 500ns
static
uint64_t
eth_latency
=
(
500
*
1000ULL
);
// 500ns
static
pcap_dumper_t
*
dumpfile
=
nullptr
;
/* MAC address type */
/* MAC address type */
struct
MAC
{
struct
MAC
{
...
@@ -85,6 +87,18 @@ static void sigint_handler(int dummy) {
...
@@ -85,6 +87,18 @@ static void sigint_handler(int dummy) {
static
void
forward_pkt
(
volatile
struct
SimbricksProtoNetD2NSend
*
tx
,
static
void
forward_pkt
(
volatile
struct
SimbricksProtoNetD2NSend
*
tx
,
size_t
port
)
{
size_t
port
)
{
volatile
union
SimbricksProtoNetN2D
*
msg_to
;
volatile
union
SimbricksProtoNetN2D
*
msg_to
;
struct
pcap_pkthdr
ph
;
// log to pcap file if initialized
if
(
dumpfile
)
{
memset
(
&
ph
,
0
,
sizeof
(
ph
));
ph
.
ts
.
tv_sec
=
cur_ts
/
1000000000000ULL
;
ph
.
ts
.
tv_usec
=
(
cur_ts
%
1000000000000ULL
)
/
1000ULL
;
ph
.
caplen
=
tx
->
len
;
ph
.
len
=
tx
->
len
;
pcap_dump
((
unsigned
char
*
)
dumpfile
,
&
ph
,
(
unsigned
char
*
)
tx
->
data
);
}
msg_to
=
SimbricksNetIfN2DAlloc
(
&
nsifs
[
port
],
cur_ts
,
eth_latency
);
msg_to
=
SimbricksNetIfN2DAlloc
(
&
nsifs
[
port
],
cur_ts
,
eth_latency
);
if
(
msg_to
!=
NULL
)
{
if
(
msg_to
!=
NULL
)
{
volatile
struct
SimbricksProtoNetN2DRecv
*
rx
;
volatile
struct
SimbricksProtoNetN2DRecv
*
rx
;
...
@@ -143,9 +157,10 @@ int main(int argc, char *argv[]) {
...
@@ -143,9 +157,10 @@ int main(int argc, char *argv[]) {
int
c
;
int
c
;
int
bad_option
=
0
;
int
bad_option
=
0
;
int
sync_mode
=
SIMBRICKS_PROTO_SYNC_SIMBRICKS
;
int
sync_mode
=
SIMBRICKS_PROTO_SYNC_SIMBRICKS
;
pcap_t
*
pc
=
nullptr
;
// Parse command line argument
// Parse command line argument
while
((
c
=
getopt
(
argc
,
argv
,
"s:S:E:m:"
))
!=
-
1
&&
!
bad_option
)
{
while
((
c
=
getopt
(
argc
,
argv
,
"s:S:E:m:
p:
"
))
!=
-
1
&&
!
bad_option
)
{
switch
(
c
)
{
switch
(
c
)
{
case
's'
:
{
case
's'
:
{
struct
SimbricksNetIf
nsif
;
struct
SimbricksNetIf
nsif
;
...
@@ -172,6 +187,17 @@ int main(int argc, char *argv[]) {
...
@@ -172,6 +187,17 @@ int main(int argc, char *argv[]) {
sync_mode
==
SIMBRICKS_PROTO_SYNC_BARRIER
);
sync_mode
==
SIMBRICKS_PROTO_SYNC_BARRIER
);
break
;
break
;
case
'p'
:
pc
=
pcap_open_dead_with_tstamp_precision
(
DLT_EN10MB
,
65535
,
PCAP_TSTAMP_PRECISION_NANO
);
if
(
pc
==
nullptr
)
{
perror
(
"pcap_open_dead failed"
);
return
EXIT_FAILURE
;
}
dumpfile
=
pcap_dump_open
(
pc
,
optarg
);
break
;
default:
default:
fprintf
(
stderr
,
"unknown option %c
\n
"
,
c
);
fprintf
(
stderr
,
"unknown option %c
\n
"
,
c
);
bad_option
=
1
;
bad_option
=
1
;
...
...
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