command-line: add ovs_cmdl_ prefix
[cascardo/ovs.git] / vtep / vtep-ctl.c
index 7b904f6..ead22ea 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc.
+ * Copyright (c) 2009, 2010, 2011, 2012, 2014 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@
 #include "compiler.h"
 #include "dirs.h"
 #include "dynamic-string.h"
+#include "fatal-signal.h"
 #include "hash.h"
 #include "json.h"
 #include "ovsdb-data.h"
 #include "smap.h"
 #include "sset.h"
 #include "svec.h"
-#include "lib/vtep-idl.h"
+#include "vtep/vtep-idl.h"
 #include "table.h"
 #include "timeval.h"
 #include "util.h"
-#include "vconn.h"
-#include "vlog.h"
+#include "openvswitch/vconn.h"
+#include "openvswitch/vlog.h"
 
 VLOG_DEFINE_THIS_MODULE(vtep_ctl);
 
@@ -114,19 +115,16 @@ static int timeout;
 /* Format for table output. */
 static struct table_style table_style = TABLE_STYLE_DEFAULT;
 
-/* All supported commands. */
-static const struct vtep_ctl_command_syntax all_commands[];
-
 /* The IDL we're using and the current transaction, if any.
  * This is for use by vtep_ctl_exit() only, to allow it to clean up.
  * Other code should use its context arguments. */
 static struct ovsdb_idl *the_idl;
 static struct ovsdb_idl_txn *the_idl_txn;
 
-static void vtep_ctl_exit(int status) NO_RETURN;
-static void vtep_ctl_fatal(const char *, ...) PRINTF_FORMAT(1, 2) NO_RETURN;
+OVS_NO_RETURN static void vtep_ctl_exit(int status);
+OVS_NO_RETURN static void vtep_ctl_fatal(const char *, ...) OVS_PRINTF_FORMAT(1, 2);
 static char *default_db(void);
-static void usage(void) NO_RETURN;
+OVS_NO_RETURN static void usage(void);
 static void parse_options(int argc, char *argv[], struct shash *local_options);
 static bool might_write_to_db(char **argv);
 
@@ -154,6 +152,7 @@ static bool is_condition_satisfied(const struct vtep_ctl_table_class *,
 static struct vtep_ctl_lswitch *find_lswitch(struct vtep_ctl_context *,
                                              const char *name,
                                              bool must_exist);
+static const struct vtep_ctl_command_syntax *get_all_commands(void);
 
 int
 main(int argc, char *argv[])
@@ -167,9 +166,9 @@ main(int argc, char *argv[])
     char *args;
 
     set_program_name(argv[0]);
-    signal(SIGPIPE, SIG_IGN);
+    fatal_ignore_sigpipe();
     vlog_set_levels(NULL, VLF_CONSOLE, VLL_WARN);
-    vlog_set_levels(&VLM_reconnect, VLF_ANY_FACILITY, VLL_WARN);
+    vlog_set_levels(&VLM_reconnect, VLF_ANY_DESTINATION, VLL_WARN);
     vteprec_init();
 
     /* Log our arguments.  This is often valuable for debugging systems. */
@@ -273,7 +272,7 @@ parse_options(int argc, char *argv[], struct shash *local_options)
     size_t n_options;
     size_t i;
 
-    tmp = long_options_to_short_options(global_long_options);
+    tmp = ovs_cmdl_long_options_to_short_options(global_long_options);
     short_options = xasprintf("+%s", tmp);
     free(tmp);
 
@@ -284,7 +283,7 @@ parse_options(int argc, char *argv[], struct shash *local_options)
     options = xmemdup(global_long_options, sizeof global_long_options);
     allocated_options = ARRAY_SIZE(global_long_options);
     n_options = n_global_long_options;
-    for (p = all_commands; p->name; p++) {
+    for (p = get_all_commands(); p->name; p++) {
         if (p->options[0]) {
             char *save_ptr = NULL;
             char *name;
@@ -369,6 +368,7 @@ parse_options(int argc, char *argv[], struct shash *local_options)
 
         case 'V':
             ovs_print_version(0, 0);
+            printf("DB Schema %s\n", vteprec_get_db_version());
             exit(EXIT_SUCCESS);
 
         case 't':
@@ -542,7 +542,7 @@ find_command(const char *name)
     if (shash_is_empty(&commands)) {
         const struct vtep_ctl_command_syntax *p;
 
-        for (p = all_commands; p->name; p++) {
+        for (p = get_all_commands(); p->name; p++) {
             shash_add_assert(&commands, p->name, p);
         }
     }
@@ -725,11 +725,11 @@ struct vtep_ctl_context {
 struct vtep_ctl_pswitch {
     const struct vteprec_physical_switch *ps_cfg;
     char *name;
-    struct list ports;          /* Contains "struct vteprec_physical_port"s. */
+    struct ovs_list ports;      /* Contains "struct vteprec_physical_port"s. */
 };
 
 struct vtep_ctl_port {
-    struct list ports_node;     /* In struct vtep_ctl_pswitch's 'ports' list. */
+    struct ovs_list ports_node; /* In struct vtep_ctl_pswitch's 'ports' list. */
     const struct vteprec_physical_port *port_cfg;
     struct vtep_ctl_pswitch *ps;
     struct shash bindings;      /* Maps from vlan to vtep_ctl_lswitch. */
@@ -749,12 +749,12 @@ struct vtep_ctl_mcast_mac {
     const struct vteprec_mcast_macs_remote *remote_cfg;
 
     const struct vteprec_physical_locator_set *ploc_set_cfg;
-    struct list locators;       /* Contains 'vtep_ctl_ploc's. */
+    struct ovs_list locators;   /* Contains 'vtep_ctl_ploc's. */
 };
 
 struct vtep_ctl_ploc {
-    struct list locators_node;  /* In struct vtep_ctl_ploc_set's 'locators'
-                                   list. */
+    struct ovs_list locators_node;  /* In struct vtep_ctl_ploc_set's 'locators'
+                                       list. */
     const struct vteprec_physical_locator *ploc_cfg;
 };
 
@@ -1076,6 +1076,7 @@ pre_get_info(struct vtep_ctl_context *ctx)
 
     ovsdb_idl_add_column(ctx->idl, &vteprec_physical_switch_col_name);
     ovsdb_idl_add_column(ctx->idl, &vteprec_physical_switch_col_ports);
+    ovsdb_idl_add_column(ctx->idl, &vteprec_physical_switch_col_tunnels);
 
     ovsdb_idl_add_column(ctx->idl, &vteprec_physical_port_col_name);
     ovsdb_idl_add_column(ctx->idl, &vteprec_physical_port_col_vlan_bindings);
@@ -1111,6 +1112,9 @@ pre_get_info(struct vtep_ctl_context *ctx)
                          &vteprec_physical_locator_col_dst_ip);
     ovsdb_idl_add_column(ctx->idl,
                          &vteprec_physical_locator_col_encapsulation_type);
+
+    ovsdb_idl_add_column(ctx->idl, &vteprec_tunnel_col_local);
+    ovsdb_idl_add_column(ctx->idl, &vteprec_tunnel_col_remote);
 }
 
 static void
@@ -1122,6 +1126,7 @@ vtep_ctl_context_populate_cache(struct vtep_ctl_context *ctx)
     const struct vteprec_ucast_macs_remote *ucast_remote_cfg;
     const struct vteprec_mcast_macs_local *mcast_local_cfg;
     const struct vteprec_mcast_macs_remote *mcast_remote_cfg;
+    const struct vteprec_tunnel *tunnel_cfg;
     struct sset pswitches, ports, lswitches;
     size_t i;
 
@@ -1247,6 +1252,15 @@ vtep_ctl_context_populate_cache(struct vtep_ctl_context *ctx)
         mcast_mac->remote_cfg = mcast_remote_cfg;
     }
 
+    VTEPREC_TUNNEL_FOR_EACH (tunnel_cfg, ctx->idl) {
+        if (tunnel_cfg->local) {
+            add_ploc_to_cache(ctx, tunnel_cfg->local);
+        }
+        if (tunnel_cfg->remote) {
+            add_ploc_to_cache(ctx, tunnel_cfg->remote);
+        }
+    }
+
     sset_init(&pswitches);
     for (i = 0; i < vtep_global->n_switches; i++) {
         struct vteprec_physical_switch *ps_cfg = vtep_global->switches[i];
@@ -2283,6 +2297,10 @@ static const struct vtep_ctl_table_class tables[] = {
      {{&vteprec_table_physical_switch, &vteprec_physical_switch_col_name, NULL},
       {NULL, NULL, NULL}}},
 
+    {&vteprec_table_tunnel,
+     {{NULL, NULL, NULL},
+      {NULL, NULL, NULL}}},
+
     {NULL, {{NULL, NULL, NULL}, {NULL, NULL, NULL}}}
 };
 
@@ -2568,7 +2586,7 @@ missing_operator_error(const char *arg, const char **allowed_operators,
  *
  * On success, returns NULL.  On failure, returned a malloc()'d string error
  * message and stores NULL into all of the nonnull output arguments. */
-static char * WARN_UNUSED_RESULT
+static char * OVS_WARN_UNUSED_RESULT
 parse_column_key_value(const char *arg,
                        const struct vtep_ctl_table_class *table,
                        const struct ovsdb_idl_column **columnp, char **keyp,
@@ -3199,11 +3217,11 @@ cmd_remove(struct vtep_ctl_context *ctx)
         error = ovsdb_datum_from_string(&rm, &rm_type,
                                         ctx->argv[i], ctx->symtab);
         if (error && ovsdb_type_is_map(&rm_type)) {
-            free(error);
             rm_type.value.type = OVSDB_TYPE_VOID;
             die_if_error(ovsdb_datum_from_string(&rm, &rm_type,
                                                  ctx->argv[i], ctx->symtab));
         }
+        free(error);
         ovsdb_datum_subtract(&old, type, &rm, &rm_type);
         ovsdb_datum_destroy(&rm, &rm_type);
     }
@@ -3324,7 +3342,7 @@ post_create(struct vtep_ctl_context *ctx)
     struct uuid dummy;
 
     if (!uuid_from_string(&dummy, ds_cstr(&ctx->output))) {
-        NOT_REACHED();
+        OVS_NOT_REACHED();
     }
     real = ovsdb_idl_txn_get_insert_uuid(ctx->txn, &dummy);
     if (real) {
@@ -3441,7 +3459,7 @@ evaluate_relop(const struct ovsdb_datum *a, const struct ovsdb_datum *b,
         return ovsdb_datum_includes_all(b, a, type);
 
     default:
-        NOT_REACHED();
+        OVS_NOT_REACHED();
     }
 }
 
@@ -3739,7 +3757,7 @@ do_vtep_ctl(const char *args, struct vtep_ctl_command *commands,
     switch (status) {
     case TXN_UNCOMMITTED:
     case TXN_INCOMPLETE:
-        NOT_REACHED();
+        OVS_NOT_REACHED();
 
     case TXN_ABORTED:
         /* Should not happen--we never call ovsdb_idl_txn_abort(). */
@@ -3760,7 +3778,7 @@ do_vtep_ctl(const char *args, struct vtep_ctl_command *commands,
         vtep_ctl_fatal("database not locked");
 
     default:
-        NOT_REACHED();
+        OVS_NOT_REACHED();
     }
     free(error);
 
@@ -3888,3 +3906,8 @@ static const struct vtep_ctl_command_syntax all_commands[] = {
     {NULL, 0, 0, NULL, NULL, NULL, NULL, RO},
 };
 
+static const struct vtep_ctl_command_syntax *
+get_all_commands(void)
+{
+    return all_commands;
+}