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
71f62f2d
Commit
71f62f2d
authored
Aug 05, 2021
by
Hejing Li
Browse files
net_switch: dummy pcap debug flag for timestamp precision
parent
ec288c09
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
0 deletions
+30
-0
sims/net/switch/net_switch.cc
sims/net/switch/net_switch.cc
+30
-0
No files found.
sims/net/switch/net_switch.cc
View file @
71f62f2d
...
...
@@ -24,6 +24,9 @@
#include <unistd.h>
#include <pcap/pcap.h>
#include <linux/ip.h>
#include <linux/if_ether.h>
#include <arpa/inet.h>
#include <cassert>
#include <climits>
...
...
@@ -39,6 +42,8 @@ extern "C" {
#include <simbricks/proto/base.h>
};
//#define NETSWITCH_DEBUG
static
uint64_t
sync_period
=
(
500
*
1000ULL
);
// 500ns
static
uint64_t
eth_latency
=
(
500
*
1000ULL
);
// 500ns
static
pcap_dumper_t
*
dumpfile
=
nullptr
;
...
...
@@ -89,6 +94,7 @@ static void forward_pkt(volatile struct SimbricksProtoNetD2NSend *tx,
volatile
union
SimbricksProtoNetN2D
*
msg_to
;
struct
pcap_pkthdr
ph
;
// log to pcap file if initialized
if
(
dumpfile
)
{
memset
(
&
ph
,
0
,
sizeof
(
ph
));
...
...
@@ -98,6 +104,30 @@ static void forward_pkt(volatile struct SimbricksProtoNetD2NSend *tx,
ph
.
len
=
tx
->
len
;
pcap_dump
((
unsigned
char
*
)
dumpfile
,
&
ph
,
(
unsigned
char
*
)
tx
->
data
);
}
// print sending tick: [packet type] source_IP -> dest_IP len:
#ifdef NETSWITCH_DEBUG
uint16_t
eth_proto
;
struct
ethhdr
*
hdr
;
struct
iphdr
*
iph
;
hdr
=
(
struct
ethhdr
*
)
tx
->
data
;
eth_proto
=
ntohs
(
hdr
->
h_proto
);
iph
=
(
struct
iphdr
*
)(
hdr
+
1
);
fprintf
(
stderr
,
"%20lu: "
,
cur_ts
);
if
(
eth_proto
==
ETH_P_IP
){
fprintf
(
stderr
,
"[ IP] "
);
}
else
if
(
eth_proto
==
ETH_P_ARP
){
fprintf
(
stderr
,
"[ARP] "
);
}
else
{
fprintf
(
stderr
,
"unkwon eth type
\n
"
);
}
fprintf
(
stderr
,
"%8X -> %8X len: %lu
\n
"
,
iph
->
saddr
,
iph
->
daddr
,
iph
->
tot_len
+
sizeof
(
struct
ethhdr
));
#endif
msg_to
=
SimbricksNetIfN2DAlloc
(
&
nsifs
[
port
],
cur_ts
,
eth_latency
);
if
(
msg_to
!=
NULL
)
{
...
...
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