"docs/git@developer.sourcefind.cn:OpenDAS/opencompass.git" did not exist on "9e5746d3d8903165cc884637504de634bf4d04b6"
Commit 71f62f2d authored by Hejing Li's avatar Hejing Li
Browse files

net_switch: dummy pcap debug flag for timestamp precision

parent ec288c09
...@@ -24,6 +24,9 @@ ...@@ -24,6 +24,9 @@
#include <unistd.h> #include <unistd.h>
#include <pcap/pcap.h> #include <pcap/pcap.h>
#include <linux/ip.h>
#include <linux/if_ether.h>
#include <arpa/inet.h>
#include <cassert> #include <cassert>
#include <climits> #include <climits>
...@@ -39,6 +42,8 @@ extern "C" { ...@@ -39,6 +42,8 @@ extern "C" {
#include <simbricks/proto/base.h> #include <simbricks/proto/base.h>
}; };
//#define NETSWITCH_DEBUG
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; static pcap_dumper_t *dumpfile = nullptr;
...@@ -89,6 +94,7 @@ static void forward_pkt(volatile struct SimbricksProtoNetD2NSend *tx, ...@@ -89,6 +94,7 @@ static void forward_pkt(volatile struct SimbricksProtoNetD2NSend *tx,
volatile union SimbricksProtoNetN2D *msg_to; volatile union SimbricksProtoNetN2D *msg_to;
struct pcap_pkthdr ph; struct pcap_pkthdr ph;
// log to pcap file if initialized // log to pcap file if initialized
if (dumpfile) { if (dumpfile) {
memset(&ph, 0, sizeof(ph)); memset(&ph, 0, sizeof(ph));
...@@ -98,6 +104,30 @@ static void forward_pkt(volatile struct SimbricksProtoNetD2NSend *tx, ...@@ -98,6 +104,30 @@ static void forward_pkt(volatile struct SimbricksProtoNetD2NSend *tx,
ph.len = tx->len; ph.len = tx->len;
pcap_dump((unsigned char *)dumpfile, &ph, (unsigned char *)tx->data); 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); msg_to = SimbricksNetIfN2DAlloc(&nsifs[port], cur_ts, eth_latency);
if (msg_to != NULL) { if (msg_to != NULL) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment