From patchwork Mon Apr 16 12:12:45 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xabier R B X-Patchwork-Id: 1700 X-Patchwork-Delegate: mareklindner@neomailbox.ch Return-Path: Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.171]) by open-mesh.org (Postfix) with ESMTP id 420DE6007D1 for ; Mon, 16 Apr 2012 14:11:32 +0200 (CEST) Received: from [172.24.0.6] (39.4.27.77.dynamic.mundo-r.com [77.27.4.39]) by mrelayeu.kundenserver.de (node=mreu1) with ESMTP (Nemesis) id 0LuHH1-1SAv1Y2vjj-011B9v; Mon, 16 Apr 2012 14:11:31 +0200 Message-ID: <4F8C0CBD.1000907@kalrong.net> Date: Mon, 16 Apr 2012 14:12:45 +0200 From: Xabier R B User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 MIME-Version: 1.0 To: The list for a Better Approach To Mobile Ad-hoc Networking X-Enigmail-Version: 1.4 X-Provags-ID: V02:K0:lSXFsFqJ+YYL61YxOoXwCJgejf5ePUUXO3ru0Nv/Kx0 ZJpOpQy5GCTN72nv7EuAHIR3qaO9uf7ms4Lt6Sl1NDv8//9iUg 3tlSccHOD5GpGfimKijCIXNbJcL0I3khkoUl5wWE4bDYHwu/h1 l4iyiaSbq3LYuA/xA2l6566RYcAbqa6OfSqwUgch1ida69Z+af 0MUwYE8DOV+werqhG5h1VNhWHbc+46fZuiNjbfJN7ymph7jhXM i0ojR1o0wQBbPETiYB+/nlSTHRkJtj5lja0EjaEFozb09vmVWL SP6F12hKnZRQ6aqfXRgyEvaDYRt35Yk+4Z+BalAChcfM+hldA= = Subject: [B.A.T.M.A.N.] [PATCH] Add options for network coding managment. X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.13 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Apr 2012 12:11:32 -0000 Signed-off-by: Xabier Rodriguez --- main.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ sys.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ sys.h | 10 ++++++++++ 3 files changed, 108 insertions(+), 0 deletions(-) extern const char *sysfs_param_enable[]; extern const char *sysfs_param_server[]; +extern const char *sysfs_param_range[]; +extern const char *sysfs_param_one_range[]; void aggregation_usage(void); void bonding_usage(void); @@ -54,6 +60,10 @@ void ap_isolation_usage(void); void gw_mode_usage(void); void vis_mode_usage(void); void orig_interval_usage(void); +void network_coding_usage(void); +void nc_min_tq_usage(void); +void nc_hold_usage(void); +void nc_purge_usage(void); int interface(char *mesh_iface, int argc, char **argv); int handle_loglevel(char *mesh_iface, int argc, char **argv); int handle_sys_setting(char *mesh_iface, int argc, char **argv, diff --git a/main.c b/main.c index 86e2078..2a62c03 100644 --- a/main.c +++ b/main.c @@ -63,6 +63,8 @@ void print_usage(void) { printf(" \tfragmentation|f [0|1] \tdisplay or modify the fragmentation mode setting\n"); printf(" \tap_isolation|ap [0|1] \tdisplay or modify the ap isolation mode setting\n"); printf("\n"); + printf(" \tnetwork_coding|nc [command] \tdisplay the network coding commands\n"); + printf("\n"); printf(" \tping|p \tping another batman adv host via layer 2\n"); printf(" \ttraceroute|tr \ttraceroute another batman adv host via layer 2\n"); printf(" \ttcpdump|td \ttcpdump layer 2 traffic on the given interface\n"); @@ -73,6 +75,16 @@ void print_usage(void) { printf(" \t-v print version\n"); } +void print_usage_nc(void) { + + printf("Usage: batctl nc [options] commands \n"); + printf("commands:\n"); + printf("\tstatus|st [0|1] \tdisplay or modify network coding status\n"); + printf("\tmin_tq|mtq [1-254] \tdisplay or modify minimum tq value\n"); + printf("\thold|hd [>10] \tdisplay or modify hold value\n"); + printf("\tpurge|pg [>10] \tdisplay or modify purge value\n"); +} + int main(int argc, char **argv) { int ret = EXIT_FAILURE; @@ -217,7 +229,41 @@ int main(int argc, char **argv) ret = bisect(argc - 1, argv + 1); + } else if ((strcmp(argv[1], "network_coding") == 0) || (strcmp(argv[1], "nc") == 0)) { + + if (argc>2) { + + if ((strcmp(argv[2], "status") == 0) || (strcmp(argv[2], "st") == 0)){ + + ret = handle_sys_setting(mesh_iface, argc - 2, argv + 2, + SYS_NETWORK_CODING, network_coding_usage, sysfs_param_enable); + + } else if ((strcmp(argv[2], "min_tq") == 0) || (strcmp(argv[2], "mtq") == 0)) { + + ret = handle_sys_setting(mesh_iface, argc - 2, argv + 2, + SYS_NC_MIN_TQ, nc_min_tq_usage, sysfs_param_range); + + } else if ((strcmp(argv[2], "hold") == 0) || (strcmp(argv[2], "hd") == 0)) { + + ret = handle_sys_setting(mesh_iface, argc - 2, argv + 2, + SYS_NC_HOLD, nc_hold_usage, sysfs_param_one_range); + + } else if ((strcmp(argv[2], "purge") == 0) || (strcmp(argv[2], "pg") == 0)) { + + ret = handle_sys_setting(mesh_iface, argc - 2, argv + 2, + SYS_NC_PURGE, nc_purge_usage, sysfs_param_one_range); + + } + + } else { + + printf("Error - no command specified\n"); + print_usage_nc(); + + } + } else { + printf("Error - no command specified\n"); print_usage(); } diff --git a/sys.c b/sys.c index d3bf7fa..e8077d9 100644 --- a/sys.c +++ b/sys.c @@ -49,6 +49,17 @@ const char *sysfs_param_server[] = { NULL, }; +const char *sysfs_param_range[] = { + "1", + "254", + NULL, +}; + +const char *sysfs_param_one_range[] = { + "10", + NULL, +}; + static void interface_usage(void) { printf("Usage: batctl interface [options] [add|del iface(s)] \n"); @@ -320,6 +331,34 @@ void ap_isolation_usage(void) printf(" \t -h print this help\n"); } +void network_coding_usage(void) +{ + printf("Usage: batctl [options] nc status [0|1]\n"); + printf("options:\n"); + printf(" \t -h print this help\n"); +} + +void nc_min_tq_usage(void) +{ + printf("Usage: batctl [options] nc min_tq [1-254]\n"); + printf("options:\n"); + printf(" \t -h print this help\n"); +} + +void nc_hold_usage(void) +{ + printf("Usage: batctl [options] nc hold [>10]\n"); + printf("options:\n"); + printf("\t -h print this help\n"); +} + +void nc_purge_usage(void) +{ + printf("Usage: batctl [options] nc purge [>10]\n"); + printf("options\n"); + printf("\t -h print this help\n"); +} + int handle_sys_setting(char *mesh_iface, int argc, char **argv, char *file_path, void setting_usage(void), const char *sysfs_param[]) @@ -351,6 +390,19 @@ int handle_sys_setting(char *mesh_iface, int argc, char **argv, goto write_file; ptr = sysfs_param; + + if (ptr[1]==NULL){ + + if (atoi(ptr[0]) <= atoi(argv[1])) + goto write_file; + + }else{ + + if (atoi(ptr[0]) <= atoi(argv[1]) && atoi(ptr[1]) >= atoi(argv[1])) + goto write_file; + + } + while (*ptr) { if (strcmp(*ptr, argv[1]) == 0) goto write_file; diff --git a/sys.h b/sys.h index 46a1159..317309f 100644 --- a/sys.h +++ b/sys.h @@ -36,6 +36,10 @@ #define SYS_IFACE_STATUS_FMT SYS_IFACE_PATH"/%s/batman_adv/iface_status" #define SYS_FRAG "fragmentation" #define SYS_AP_ISOLA "ap_isolation" +#define SYS_NETWORK_CODING "network_coding" +#define SYS_NC_MIN_TQ "nc_min_tq" +#define SYS_NC_HOLD "nc_hold" +#define SYS_NC_PURGE "nc_purge" enum gw_modes { GW_MODE_OFF, @@ -45,6 +49,8 @@ enum gw_modes {