Review at  https://gerrit.osmocom.org/5590

abisip-find: add --interval option

Change-Id: I9540054bdda185b2585209289cee565f61f33dcf
---
M src/ipaccess/abisip-find.c
1 file changed, 17 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/90/5590/1

diff --git a/src/ipaccess/abisip-find.c b/src/ipaccess/abisip-find.c
index d94e18a..4d3e390 100644
--- a/src/ipaccess/abisip-find.c
+++ b/src/ipaccess/abisip-find.c
@@ -39,10 +39,12 @@
 
 static struct {
        const char *ifname;
+       int send_interval;
        bool list_view;
        time_t list_view_timeout;
 } cmdline_opts = {
        .ifname = NULL,
+       .send_interval = 5,
        .list_view = false,
        .list_view_timeout = 10,
 };
@@ -53,6 +55,7 @@
        printf("Usage: abisip-find [-l] [<interface-name>]\n");
        printf("  <interface-name>  Specify the outgoing network interface,\n"
               "                    e.g. 'eth0'\n");
+       printf("  -i --interval <s> Send broadcast frames every <s> 
seconds.\n");
        printf("  -l --list-view    Instead of printing received responses,\n"
               "                    output a sorted list of currently present\n"
               "                    base stations and change events.\n");
@@ -67,12 +70,13 @@
                int option_index = 0, c;
                static struct option long_options[] = {
                        {"help", 0, 0, 'h'},
+                       {"send-interval", 1, 0, 'i'},
                        {"list-view", 0, 0, 'l'},
                        {"timeout", 1, 0, 't'},
                        {0, 0, 0, 0}
                };
 
-               c = getopt_long(argc, argv, "hlt:",
+               c = getopt_long(argc, argv, "hi:lt:",
                                long_options, &option_index);
                if (c == -1)
                        break;
@@ -81,6 +85,14 @@
                case 'h':
                        print_help();
                        exit(EXIT_SUCCESS);
+               case 'i':
+                       errno = 0;
+                       cmdline_opts.send_interval = strtoul(optarg, NULL, 10);
+                       if (errno) {
+                               fprintf(stderr, "Invalid interval value: %s\n", 
optarg);
+                               exit(EXIT_FAILURE);
+                       }
+                       break;
                case 't':
                        errno = 0;
                        cmdline_opts.list_view_timeout = strtoul(optarg, NULL, 
10);
@@ -363,7 +375,7 @@
 
        base_stations_bump(false);
 
-       osmo_timer_schedule(&timer, 5, 0);
+       osmo_timer_schedule(&timer, cmdline_opts.send_interval, 0);
 }
 
 int main(int argc, char **argv)
@@ -382,6 +394,8 @@
                        "  network interface, e.g. ``%s eth0''\n", argv[0]);
        if (!cmdline_opts.list_view)
                fprintf(stdout, "- You may find the --list-view option 
convenient.\n");
+       else if (cmdline_opts.send_interval >= cmdline_opts.list_view_timeout)
+               fprintf(stdout, "\nWARNING: the --timeout should be larger than 
--interval.\n\n");
 
        bfd.cb = bfd_cb;
        bfd.when = BSC_FD_READ | BSC_FD_WRITE;
@@ -398,7 +412,7 @@
        }
 
        osmo_timer_setup(&timer, timer_cb, &bfd);
-       osmo_timer_schedule(&timer, 5, 0);
+       osmo_timer_schedule(&timer, cmdline_opts.send_interval, 0);
 
        printf("Trying to find ip.access BTS by broadcast UDP...\n");
 

-- 
To view, visit https://gerrit.osmocom.org/5590
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9540054bdda185b2585209289cee565f61f33dcf
Gerrit-PatchSet: 1
Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <[email protected]>

Reply via email to