Skip to content

Commit

Permalink
Dumping incoming packets to file
Browse files Browse the repository at this point in the history
This is disabled by default option.
It can be enabled and disabled with vrouter util.

Closes-Bug: #1804454

Change-Id: I4f506c34da773a57c2a199ab892c71ec4be83b03
  • Loading branch information
jacekchalupka committed Nov 28, 2018
1 parent 001edb7 commit ddbc67b
Show file tree
Hide file tree
Showing 14 changed files with 390 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -34,3 +34,4 @@ modules.order
/sandesh/gen-c/*
/test/cmocka
/test/atomic-test/x64
.vscode/*
7 changes: 6 additions & 1 deletion dp-core/vrouter.c
Expand Up @@ -370,6 +370,10 @@ vrouter_ops_get_process(void *s_req)
resp->vo_udp_coff = vr_udp_coff;
resp->vo_flow_hold_limit = vr_flow_hold_limit;
resp->vo_mudp = vr_mudp;
resp->vo_packet_dump = 0;
if(vr_get_dump_packets != NULL) {
resp->vo_packet_dump = vr_get_dump_packets();
}

/* Build info */
strncpy(resp->vo_build_info, ContrailBuildInfo,
Expand Down Expand Up @@ -438,6 +442,8 @@ vrouter_ops_add_process(void *s_req)
vr_set_log_type(req->vo_log_type_disable[i], 0);

/* Runtime parameters */
if (req->vo_packet_dump != -1 && vr_set_dump_packets != NULL)
vr_set_dump_packets(req->vo_packet_dump);
if (req->vo_perfr != -1)
vr_perfr = req->vo_perfr;
if (req->vo_perfs != -1)
Expand Down Expand Up @@ -679,4 +685,3 @@ vr_hugepage_config_process(void *s_req)

return;
}

5 changes: 4 additions & 1 deletion include/vrouter.h
Expand Up @@ -233,7 +233,8 @@ struct host_os {
int (*hos_offload_flow_create)(struct vr_offload_flow *oflow);
int (*hos_offload_flow_destroy)(struct vr_offload_flow *oflow);
void (*hos_offload_prepare)(struct vr_packet *pkt, struct vr_forwarding_md *fmd);

void (*hos_set_dump_packets)(int);
int (*hos_get_dump_packets)(void);
};

#define vr_printf vrouter_host->hos_printf
Expand Down Expand Up @@ -289,6 +290,8 @@ struct host_os {
#define vr_offload_flow_destroy vrouter_host->hos_offload_flow_destroy
#define vr_offload_flow_create vrouter_host->hos_offload_flow_create
#define vr_offload_prepare vrouter_host->hos_offload_prepare
#define vr_set_dump_packets vrouter_host->hos_set_dump_packets
#define vr_get_dump_packets vrouter_host->hos_get_dump_packets

extern struct host_os *vrouter_host;

Expand Down
1 change: 1 addition & 0 deletions sandesh/vr.sandesh
Expand Up @@ -311,6 +311,7 @@ buffer sandesh vrouter_ops {
38: u32 vo_priority_tagging;
39: i32 vo_vif_bridge_entries;
40: i32 vo_vif_oflow_bridge_entries;
41: i32 vo_packet_dump;
}

buffer sandesh vr_mem_stats_req {
Expand Down
2 changes: 1 addition & 1 deletion test/windows/SConscript
Expand Up @@ -22,7 +22,7 @@ env.Append(LIBS = 'cmocka')

env.AppendENVPath('Path', Dir('#build/bin'))

common_tests_src = ['fake_win_packet_raw.c', 'fake_win_memory.c', 'fake_vrouter.c']
common_tests_src = ['fake_win_packet_raw.c', 'fake_win_memory.c', 'fake_vrouter.c', 'fake_win_packetdump.c']
common_tests_obj = env.Object(common_tests_src)

test_suite_base_names = [
Expand Down
7 changes: 7 additions & 0 deletions test/windows/fake_win_packetdump.c
@@ -0,0 +1,7 @@
#include <vr_packet.h>

void
DontWriteVrPacketToFile(struct vr_packet *packet, char tag[]) {}

typedef void (*PWRITEVRPACKETTOFILEFUNCTION)(struct vr_packet *packet, char tag[]);
extern PWRITEVRPACKETTOFILEFUNCTION PacketToFileWriter = DontWriteVrPacketToFile;
14 changes: 8 additions & 6 deletions utils/vr_util.c
Expand Up @@ -869,7 +869,7 @@ vr_interface_req_destroy(vr_interface_req *req)
req->vifr_fat_flow_dst_aggregate_plen_size = 0;
}

if (req->vifr_fat_flow_exclude_ip_list_size &&
if (req->vifr_fat_flow_exclude_ip_list_size &&
req->vifr_fat_flow_exclude_ip_list) {
free(req->vifr_fat_flow_exclude_ip_list);
req->vifr_fat_flow_exclude_ip_list = NULL;
Expand All @@ -881,7 +881,7 @@ vr_interface_req_destroy(vr_interface_req *req)
req->vifr_fat_flow_exclude_ip6_u_list = NULL;
req->vifr_fat_flow_exclude_ip6_u_list_size = 0;
}
if (req->vifr_fat_flow_exclude_ip6_l_list_size &&
if (req->vifr_fat_flow_exclude_ip6_l_list_size &&
req->vifr_fat_flow_exclude_ip6_l_list) {
free(req->vifr_fat_flow_exclude_ip6_l_list);
req->vifr_fat_flow_exclude_ip6_l_list = NULL;
Expand Down Expand Up @@ -1077,7 +1077,7 @@ vr_interface_req_get_copy(vr_interface_req *src)
if (!dst->vifr_fat_flow_exclude_ip_list) {
goto free_vif;
}
memcpy(dst->vifr_fat_flow_exclude_ip_list, src->vifr_fat_flow_exclude_ip_list,
memcpy(dst->vifr_fat_flow_exclude_ip_list, src->vifr_fat_flow_exclude_ip_list,
src->vifr_fat_flow_exclude_ip_list_size * sizeof(uint64_t));
dst->vifr_fat_flow_exclude_ip_list_size = src->vifr_fat_flow_exclude_ip_list_size;
}
Expand All @@ -1088,7 +1088,7 @@ vr_interface_req_get_copy(vr_interface_req *src)
if (!dst->vifr_fat_flow_exclude_ip6_u_list) {
goto free_vif;
}
memcpy(dst->vifr_fat_flow_exclude_ip6_u_list, src->vifr_fat_flow_exclude_ip6_u_list,
memcpy(dst->vifr_fat_flow_exclude_ip6_u_list, src->vifr_fat_flow_exclude_ip6_u_list,
src->vifr_fat_flow_exclude_ip6_u_list_size * sizeof(uint64_t));
dst->vifr_fat_flow_exclude_ip6_u_list_size = src->vifr_fat_flow_exclude_ip6_u_list_size;
}
Expand All @@ -1098,7 +1098,7 @@ vr_interface_req_get_copy(vr_interface_req *src)
if (!dst->vifr_fat_flow_exclude_ip6_l_list) {
goto free_vif;
}
memcpy(dst->vifr_fat_flow_exclude_ip6_l_list, src->vifr_fat_flow_exclude_ip6_l_list,
memcpy(dst->vifr_fat_flow_exclude_ip6_l_list, src->vifr_fat_flow_exclude_ip6_l_list,
src->vifr_fat_flow_exclude_ip6_l_list_size * sizeof(uint64_t));
dst->vifr_fat_flow_exclude_ip6_l_list_size = src->vifr_fat_flow_exclude_ip6_l_list_size;
}
Expand Down Expand Up @@ -2082,6 +2082,7 @@ vr_send_vrouter_set_logging(struct nl_client *cl, unsigned int router_id,
req.vo_udp_coff = -1;
req.vo_flow_hold_limit = -1;
req.vo_mudp = -1;
req.vo_packet_dump = -1;

return vr_sendmsg(cl, &req, "vrouter_ops");
}
Expand All @@ -2092,7 +2093,7 @@ vr_send_vrouter_set_runtime_opts(struct nl_client *cl, unsigned int router_id,
int perfr1, int perfr2, int perfr3, int perfp, int perfq1,
int perfq2, int perfq3, int udp_coff, int flow_hold_limit,
int mudp, int btokens, int binterval, int bstep,
unsigned int priority_tagging)
unsigned int priority_tagging, int packet_dump)
{
vrouter_ops req;

Expand Down Expand Up @@ -2124,6 +2125,7 @@ vr_send_vrouter_set_runtime_opts(struct nl_client *cl, unsigned int router_id,
req.vo_burst_interval = binterval;
req.vo_burst_step = bstep;
req.vo_priority_tagging = priority_tagging;
req.vo_packet_dump = packet_dump;

/*
* We create request to change runtime (sysctl) options only. Log level
Expand Down
21 changes: 19 additions & 2 deletions utils/vrouter.c
Expand Up @@ -56,6 +56,7 @@ enum opt_vrouter_index {
SET_BURST_INTERVAL_INDEX,
SET_BURST_STEP_INDEX,
SET_PRIORITY_TAGGING_INDEX,
SET_PACKET_DUMP_INDEX,
MAX_OPT_INDEX
};

Expand Down Expand Up @@ -124,6 +125,7 @@ static int perfr1 = -1, perfr2 = -1, perfr3 = -1, perfp = -1, perfq1 = -1;
static int perfq2 = -1, perfq3 = -1, udp_coff = -1, flow_hold_limit = -1;
static int mudp = -1, burst_tokens = -1, burst_interval = -1, burst_step = -1;
static unsigned int priority_tagging = 0;
static int packet_dump = -1;

static int platform, vrouter_op = -1;

Expand Down Expand Up @@ -331,6 +333,7 @@ print_vrouter_parameters(vrouter_ops *req)
" Burst Interval %u\n"
" Burst Step %u\n"
" NIC Priority Tagging %u\n"
" Packet dump %u\n"
"\n",

req->vo_perfr, req->vo_perfs,
Expand All @@ -341,7 +344,7 @@ print_vrouter_parameters(vrouter_ops *req)
req->vo_flow_used_entries, req->vo_flow_used_oentries,
req->vo_bridge_used_entries, req->vo_bridge_used_oentries,
req->vo_burst_tokens, req->vo_burst_interval, req->vo_burst_step,
req->vo_priority_tagging
req->vo_priority_tagging, req->vo_packet_dump
);

return;
Expand Down Expand Up @@ -443,7 +446,7 @@ vr_vrouter_op(struct nl_client *cl)
perfr1, perfr2, perfr3, perfp, perfq1,
perfq2, perfq3, udp_coff, flow_hold_limit,
mudp, burst_tokens, burst_interval, burst_step,
priority_tagging);
priority_tagging, packet_dump);
}
break;

Expand Down Expand Up @@ -534,6 +537,9 @@ static struct option long_options[] = {
[SET_PRIORITY_TAGGING_INDEX] = {
"set-priority-tagging", required_argument, &opt[SET_PRIORITY_TAGGING_INDEX], 1
},
[SET_PACKET_DUMP_INDEX] = {
"packet-dump", required_argument, &opt[SET_PACKET_DUMP_INDEX], 1
},
[MAX_OPT_INDEX] = {NULL, 0, 0, 0}
};

Expand Down Expand Up @@ -608,6 +614,7 @@ Usage(void)
"--burst_interval <int> timer interval of burst tokens in ms\n"
"--burst_step <int> burst tokens to add at every interval\n"
"--set-priority-tagging <1 | 0> priority tagging on the NIC\n"
"--packet-dump <1 | 0> dumps packets\n"
"--help Prints this message\n"
"\n");
break;
Expand Down Expand Up @@ -900,6 +907,16 @@ parse_long_opts(int opt_index, char *opt_arg)

break;

case SET_PACKET_DUMP_INDEX:
vrouter_op = SANDESH_OP_ADD;
packet_dump = (int)strtol(opt_arg, NULL, 0);
if (errno != 0) {
printf("vrouter: Error parsing packet_dump: %s: %s (%d)\n", opt_arg,
strerror(errno), errno);
Usage();
}
break;

case HELP_OPT_INDEX:
default:
Usage();
Expand Down
2 changes: 2 additions & 0 deletions windows/vRouter.vcxproj
Expand Up @@ -134,6 +134,7 @@
<ClInclude Include="win_csum.h" />
<ClInclude Include="win_packet_splitting.h" />
<ClInclude Include="win_interface.h" />
<ClInclude Include="win_packetdump.h" />
<ClInclude Include="win_tx_postprocess.h" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -194,6 +195,7 @@
<ClCompile Include="win_csum.c" />
<ClCompile Include="win_packet_splitting.c" />
<ClCompile Include="win_interface.c" />
<ClCompile Include="win_packetdump.c" />
<ClCompile Include="win_tx_postprocess.c" />
</ItemGroup>
<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions windows/vr_driver.c
Expand Up @@ -6,6 +6,7 @@
#include "windows_shmem.h"
#include "windows_nbl.h"
#include "win_interface.h"
#include "win_packetdump.h"

#include <vrouter.h>
#include <vr_packet.h>
Expand Down Expand Up @@ -270,6 +271,8 @@ InitializeVRouter(pvr_switch_context ctx)
static NDIS_STATUS
InitializeWindowsComponents(PSWITCH_OBJECT Switch)
{
InitPacketDumping();

pvr_switch_context ctx = NULL;

ctx = ExAllocatePoolWithTag(NonPagedPoolNx, sizeof(vr_switch_context), VrAllocationTag);
Expand Down
21 changes: 21 additions & 0 deletions windows/vr_host.c
Expand Up @@ -9,6 +9,7 @@
#include "vr_windows.h"
#include "vrouter.h"

#include "win_packetdump.h"
#include "win_callbacks.h"
#include "win_packet.h"
#include "win_packet_raw.h"
Expand Down Expand Up @@ -934,6 +935,24 @@ win_register_nic(struct vr_interface* vif, vr_interface_req* vifr)
vif_attach(vif);
}

static void
win_set_dump_packets(int packets_dump_flag)
{
if(packets_dump_flag == 1)
EnablePacketDumping();
else
DisablePacketDumping();
}

static int
win_get_dump_packets(void)
{
if(IsPacketDumpingEnabled())
return 1;

return 0;
}

struct host_os windows_host = {
.hos_printf = win_printf,
.hos_malloc = win_malloc,
Expand Down Expand Up @@ -984,6 +1003,8 @@ struct host_os windows_host = {
.hos_get_enabled_log_types = win_get_enabled_log_types,
.hos_soft_reset = win_soft_reset,
.hos_register_nic = win_register_nic,
.hos_set_dump_packets = win_set_dump_packets,
.hos_get_dump_packets = win_get_dump_packets,
};

struct host_os *
Expand Down

0 comments on commit ddbc67b

Please sign in to comment.