]> git.proxmox.com Git - mirror_ovs.git/blobdiff - vtep/vtep-ctl.c
ofproto-dpif-upcall: Remove tabs from output.
[mirror_ovs.git] / vtep / vtep-ctl.c
index 1d8cbcb0908cfdadf17f7b732059eb978a4cf200..c89ec503453ce9a7f7a42393087d5c3cec089794 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2010, 2011, 2012, 2014, 2015, 2016 Nicira, Inc.
+ * Copyright (c) 2009, 2010, 2011, 2012, 2014, 2015, 2016, 2017 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -37,7 +37,7 @@
 #include "openvswitch/json.h"
 #include "ovsdb-data.h"
 #include "ovsdb-idl.h"
-#include "poll-loop.h"
+#include "openvswitch/poll-loop.h"
 #include "process.h"
 #include "stream.h"
 #include "stream-ssl.h"
@@ -82,7 +82,7 @@ OVS_NO_RETURN static void usage(void);
 static void parse_options(int argc, char *argv[], struct shash *local_options);
 static void run_prerequisites(struct ctl_command[], size_t n_commands,
                               struct ovsdb_idl *);
-static void do_vtep_ctl(const char *args, struct ctl_command *, size_t n,
+static bool do_vtep_ctl(const char *args, struct ctl_command *, size_t n,
                         struct ovsdb_idl *);
 static struct vtep_ctl_lswitch *find_lswitch(struct vtep_ctl_context *,
                                              const char *name,
@@ -99,7 +99,6 @@ main(int argc, char *argv[])
     struct shash local_options;
     unsigned int seqno;
     size_t n_commands;
-    char *args;
 
     set_program_name(argv[0]);
     fatal_ignore_sigpipe();
@@ -108,15 +107,14 @@ main(int argc, char *argv[])
 
     vtep_ctl_cmd_init();
 
-    /* Log our arguments.  This is often valuable for debugging systems. */
-    args = process_escape_args(argv);
-    VLOG(ctl_might_write_to_db(argv) ? VLL_INFO : VLL_DBG, "Called as %s", args);
-
     /* Parse command line. */
+    char *args = process_escape_args(argv);
     shash_init(&local_options);
     parse_options(argc, argv, &local_options);
     commands = ctl_parse_commands(argc - optind, argv + optind, &local_options,
                                   &n_commands);
+    VLOG(ctl_might_write_to_db(commands, n_commands) ? VLL_INFO : VLL_DBG,
+         "Called as %s", args);
 
     if (timeout) {
         time_alarm(timeout);
@@ -144,7 +142,10 @@ main(int argc, char *argv[])
 
         if (seqno != ovsdb_idl_get_seqno(idl)) {
             seqno = ovsdb_idl_get_seqno(idl);
-            do_vtep_ctl(args, commands, n_commands, idl);
+            if (do_vtep_ctl(args, commands, n_commands, idl)) {
+                free(args);
+                exit(EXIT_SUCCESS);
+            }
         }
 
         if (seqno == ovsdb_idl_get_seqno(idl)) {
@@ -313,6 +314,7 @@ VTEP commands:\n\
 Manager commands:\n\
   get-manager                 print the managers\n\
   del-manager                 delete the managers\n\
+  [--inactivity-probe=MSECS]\n\
   set-manager TARGET...       set the list of managers to TARGET...\n\
 \n\
 Physical Switch commands:\n\
@@ -358,6 +360,7 @@ MAC binding commands:\n\
   list-remote-macs LS                 list remote mac entries\n\
 \n\
 %s\
+%s\
 \n\
 Options:\n\
   --db=DATABASE               connect to DATABASE\n\
@@ -365,7 +368,9 @@ Options:\n\
   -t, --timeout=SECS          wait at most SECS seconds\n\
   --dry-run                   do not commit changes to database\n\
   --oneline                   print exactly one line of output per command\n",
-           program_name, program_name, ctl_get_db_cmd_usage(), ctl_default_db());
+           program_name, program_name, ctl_get_db_cmd_usage(),
+           ctl_list_db_tables_usage(), ctl_default_db());
+    table_usage();
     vlog_usage();
     printf("\
   --no-syslog                 equivalent to --verbose=vtep_ctl:syslog:warn\n");
@@ -541,6 +546,7 @@ del_cached_port(struct vtep_ctl_context *vtepctl_ctx,
     ovs_list_remove(&port->ports_node);
     shash_find_and_delete(&vtepctl_ctx->ports, cache_name);
     vteprec_physical_port_delete(port->port_cfg);
+    shash_destroy(&port->bindings);
     free(cache_name);
     free(port);
 }
@@ -1084,7 +1090,6 @@ vtep_ctl_context_populate_cache(struct ctl_context *ctx)
             port = add_port_to_cache(vtepctl_ctx, ps, port_cfg);
 
             for (k = 0; k < port_cfg->n_vlan_bindings; k++) {
-                struct vteprec_logical_switch *ls_cfg;
                 struct vtep_ctl_lswitch *ls;
                 char *vlan;
 
@@ -2091,6 +2096,7 @@ pre_manager(struct ctl_context *ctx)
 {
     ovsdb_idl_add_column(ctx->idl, &vteprec_global_col_managers);
     ovsdb_idl_add_column(ctx->idl, &vteprec_manager_col_target);
+    ovsdb_idl_add_column(ctx->idl, &vteprec_manager_col_inactivity_probe);
 }
 
 static void
@@ -2143,10 +2149,13 @@ cmd_del_manager(struct ctl_context *ctx)
 }
 
 static void
-insert_managers(struct vtep_ctl_context *vtepctl_ctx, char *targets[], size_t n)
+insert_managers(struct vtep_ctl_context *vtepctl_ctx, char *targets[],
+                size_t n, struct shash *options)
 {
     struct vteprec_manager **managers;
     size_t i;
+    const char *inactivity_probe = shash_find_data(options,
+                                                   "--inactivity-probe");
 
     /* Insert each manager in a new row in Manager table. */
     managers = xmalloc(n * sizeof *managers);
@@ -2156,6 +2165,10 @@ insert_managers(struct vtep_ctl_context *vtepctl_ctx, char *targets[], size_t n)
         }
         managers[i] = vteprec_manager_insert(vtepctl_ctx->base.txn);
         vteprec_manager_set_target(managers[i], targets[i]);
+        if (inactivity_probe) {
+            int64_t msecs = atoll(inactivity_probe);
+            vteprec_manager_set_inactivity_probe(managers[i], &msecs, 1);
+        }
     }
 
     /* Store uuids of new Manager rows in 'managers' column. */
@@ -2171,76 +2184,25 @@ cmd_set_manager(struct ctl_context *ctx)
 
     verify_managers(vtepctl_ctx->vtep_global);
     delete_managers(vtepctl_ctx);
-    insert_managers(vtepctl_ctx, &ctx->argv[1], n);
+    insert_managers(vtepctl_ctx, &ctx->argv[1], n, &ctx->options);
 }
 
 /* Parameter commands. */
-static const struct ctl_table_class tables[] = {
-    {&vteprec_table_global,
-     {{&vteprec_table_global, NULL, NULL},
-      {NULL, NULL, NULL}}},
-
-    {&vteprec_table_logical_binding_stats,
-     {{NULL, NULL, NULL},
-      {NULL, NULL, NULL}}},
-
-    {&vteprec_table_logical_switch,
-     {{&vteprec_table_logical_switch, &vteprec_logical_switch_col_name, NULL},
-      {NULL, NULL, NULL}}},
-
-    {&vteprec_table_ucast_macs_local,
-     {{NULL, NULL, NULL},
-      {NULL, NULL, NULL}}},
-
-    {&vteprec_table_ucast_macs_remote,
-     {{NULL, NULL, NULL},
-      {NULL, NULL, NULL}}},
-
-    {&vteprec_table_mcast_macs_local,
-     {{NULL, NULL, NULL},
-      {NULL, NULL, NULL}}},
-
-    {&vteprec_table_mcast_macs_remote,
-     {{NULL, NULL, NULL},
-      {NULL, NULL, NULL}}},
+static const struct ctl_table_class tables[VTEPREC_N_TABLES] = {
+    [VTEPREC_TABLE_LOGICAL_SWITCH].row_ids[0]
+    = {&vteprec_logical_switch_col_name, NULL, NULL},
 
-    {&vteprec_table_manager,
-     {{&vteprec_table_manager, &vteprec_manager_col_target, NULL},
-      {NULL, NULL, NULL}}},
-
-    {&vteprec_table_physical_locator,
-     {{NULL, NULL, NULL},
-      {NULL, NULL, NULL}}},
-
-    {&vteprec_table_physical_locator_set,
-     {{NULL, NULL, NULL},
-      {NULL, NULL, NULL}}},
-
-    {&vteprec_table_physical_port,
-     {{&vteprec_table_physical_port, &vteprec_physical_port_col_name, NULL},
-      {NULL, NULL, NULL}}},
-
-    {&vteprec_table_physical_switch,
-     {{&vteprec_table_physical_switch, &vteprec_physical_switch_col_name, NULL},
-      {NULL, NULL, NULL}}},
-
-    {&vteprec_table_tunnel,
-     {{NULL, NULL, NULL},
-      {NULL, NULL, NULL}}},
-
-    {&vteprec_table_logical_router,
-     {{&vteprec_table_logical_router, &vteprec_logical_router_col_name, NULL},
-      {NULL, NULL, NULL}}},
+    [VTEPREC_TABLE_MANAGER].row_ids[0]
+    = {&vteprec_manager_col_target, NULL, NULL},
 
-    {&vteprec_table_arp_sources_local,
-     {{NULL, NULL, NULL},
-      {NULL, NULL, NULL}}},
+    [VTEPREC_TABLE_PHYSICAL_PORT].row_ids[0]
+    = {&vteprec_physical_port_col_name, NULL, NULL},
 
-    {&vteprec_table_arp_sources_remote,
-     {{NULL, NULL, NULL},
-      {NULL, NULL, NULL}}},
+    [VTEPREC_TABLE_PHYSICAL_SWITCH].row_ids[0]
+    = {&vteprec_physical_switch_col_name, NULL, NULL},
 
-    {NULL, {{NULL, NULL, NULL}, {NULL, NULL, NULL}}}
+    [VTEPREC_TABLE_LOGICAL_ROUTER].row_ids[0]
+    = {&vteprec_logical_router_col_name, NULL, NULL},
 };
 
 \f
@@ -2307,7 +2269,7 @@ run_prerequisites(struct ctl_command *commands, size_t n_commands,
     }
 }
 
-static void
+static bool
 do_vtep_ctl(const char *args, struct ctl_command *commands,
             size_t n_commands, struct ovsdb_idl *idl)
 {
@@ -2455,7 +2417,7 @@ do_vtep_ctl(const char *args, struct ctl_command *commands,
 
     ovsdb_idl_destroy(idl);
 
-    exit(EXIT_SUCCESS);
+    return true;
 
 try_again:
     /* Our transaction needs to be rerun, or a prerequisite was not met.  Free
@@ -2471,6 +2433,7 @@ try_again:
         free(c->table);
     }
     free(error);
+    return false;
 }
 
 static const struct ctl_command_syntax vtep_commands[] = {
@@ -2535,8 +2498,8 @@ static const struct ctl_command_syntax vtep_commands[] = {
     /* Manager commands. */
     {"get-manager", 0, 0, NULL, pre_manager, cmd_get_manager, NULL, "", RO},
     {"del-manager", 0, 0, NULL, pre_manager, cmd_del_manager, NULL, "", RW},
-    {"set-manager", 1, INT_MAX, NULL, pre_manager, cmd_set_manager, NULL, "",
-     RW},
+    {"set-manager", 1, INT_MAX, NULL, pre_manager, cmd_set_manager, NULL,
+     "--inactivity-probe=", RW},
 
     {NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, RO},
 };
@@ -2545,6 +2508,7 @@ static const struct ctl_command_syntax vtep_commands[] = {
 static void
 vtep_ctl_cmd_init(void)
 {
-    ctl_init(tables, cmd_show_tables, vtep_ctl_exit);
+    ctl_init(&vteprec_idl_class, vteprec_table_classes, tables,
+             cmd_show_tables, vtep_ctl_exit);
     ctl_register_commands(vtep_commands);
 }