Skip to content

Commit

Permalink
vswitch.ovsschema: Add datapath_types and port_types.
Browse files Browse the repository at this point in the history
At startup enumerate datapath and port types and add this information to
the datapath_types and port_types columns in the ovsdb.

This allows an ovsdb client to query the datapath in order to determine
if certain datapath and port types exist. For example, by querying the
port_types column, an ovsdb client will be able to determine if this
instance of ovs-vswitchd was compiled with DPDK support.

Signed-off-by: Mark D. Gray <mark.d.gray@intel.com>
Signed-off-by: Billy O'Mahony <billy.o.mahony@intel.com>
[blp@nicira.com made several changes]
Signed-off-by: Ben Pfaff <blp@nicira.com>
  • Loading branch information
Mark D. Gray authored and blp committed Mar 24, 2015
1 parent 59a3333 commit 842733c
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 22 deletions.
38 changes: 24 additions & 14 deletions lib/sset.c
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2012, 2013 Nicira, Inc.
* Copyright (c) 2011, 2012, 2013, 2015 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -269,21 +269,12 @@ sset_at_position(const struct sset *set, uint32_t *bucketp, uint32_t *offsetp)
return SSET_NODE_FROM_HMAP_NODE(hmap_node);
}

static int
compare_string_pointers(const void *a_, const void *b_)
{
const char *const *a = a_;
const char *const *b = b_;

return strcmp(*a, *b);
}

/* Returns a null-terminated array of pointers to the strings in 'set', sorted
* alphabetically. The caller must free the returned array when it is no
/* Returns a null-terminated array of pointers to the strings in 'set', in no
* particular order. The caller must free the returned array when it is no
* longer needed, but the strings in the array belong to 'set' and thus must
* not be modified or freed. */
const char **
sset_sort(const struct sset *set)
sset_array(const struct sset *set)
{
size_t n = sset_count(set);
const char **array;
Expand All @@ -298,7 +289,26 @@ sset_sort(const struct sset *set)
ovs_assert(i == n);
array[n] = NULL;

qsort(array, n, sizeof *array, compare_string_pointers);
return array;
}

static int
compare_string_pointers(const void *a_, const void *b_)
{
const char *const *a = a_;
const char *const *b = b_;

return strcmp(*a, *b);
}

/* Returns a null-terminated array of pointers to the strings in 'set', sorted
* alphabetically. The caller must free the returned array when it is no
* longer needed, but the strings in the array belong to 'set' and thus must
* not be modified or freed. */
const char **
sset_sort(const struct sset *set)
{
const char **array = sset_array(set);
qsort(array, sset_count(set), sizeof *array, compare_string_pointers);
return array;
}
3 changes: 2 additions & 1 deletion lib/sset.h
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2012, 2013 Nicira, Inc.
* Copyright (c) 2011, 2012, 2013, 2015 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -80,6 +80,7 @@ struct sset_node *sset_at_position(const struct sset *,
: false); \
(NAME) = (NEXT))

const char **sset_array(const struct sset *);
const char **sset_sort(const struct sset *);

/* Implementation helper macros. */
Expand Down
40 changes: 40 additions & 0 deletions vswitchd/bridge.c
Expand Up @@ -18,6 +18,7 @@
#include <errno.h>
#include <inttypes.h>
#include <stdlib.h>

#include "async-append.h"
#include "bfd.h"
#include "bitmap.h"
Expand All @@ -26,6 +27,7 @@
#include "coverage.h"
#include "daemon.h"
#include "dirs.h"
#include "dpif.h"
#include "dynamic-string.h"
#include "hash.h"
#include "hmap.h"
Expand Down Expand Up @@ -317,6 +319,7 @@ static ofp_port_t iface_get_requested_ofp_port(
const struct ovsrec_interface *);
static ofp_port_t iface_pick_ofport(const struct ovsrec_interface *);


/* Linux VLAN device support (e.g. "eth0.10" for VLAN 10.)
*
* This is deprecated. It is only for compatibility with broken device drivers
Expand All @@ -335,6 +338,8 @@ static void add_vlan_splinter_ports(struct bridge *,
const unsigned long int *splinter_vlans,
struct shash *ports);

static void discover_types(const struct ovsrec_open_vswitch *cfg);

static void
bridge_init_ofproto(const struct ovsrec_open_vswitch *cfg)
{
Expand Down Expand Up @@ -394,6 +399,8 @@ bridge_init(const char *remote)

ovsdb_idl_omit_alert(idl, &ovsrec_open_vswitch_col_cur_cfg);
ovsdb_idl_omit_alert(idl, &ovsrec_open_vswitch_col_statistics);
ovsdb_idl_omit_alert(idl, &ovsrec_open_vswitch_col_datapath_types);
ovsdb_idl_omit_alert(idl, &ovsrec_open_vswitch_col_iface_types);
ovsdb_idl_omit(idl, &ovsrec_open_vswitch_col_external_ids);
ovsdb_idl_omit(idl, &ovsrec_open_vswitch_col_ovs_version);
ovsdb_idl_omit(idl, &ovsrec_open_vswitch_col_db_version);
Expand Down Expand Up @@ -571,6 +578,10 @@ bridge_reconfigure(const struct ovsrec_open_vswitch *ovs_cfg)
smap_get_int(&ovs_cfg->other_config, "n-handler-threads", 0),
smap_get_int(&ovs_cfg->other_config, "n-revalidator-threads", 0));

if (ovs_cfg) {
discover_types(ovs_cfg);
}

/* Destroy "struct bridge"s, "struct port"s, and "struct iface"s according
* to 'ovs_cfg', with only very minimal configuration otherwise.
*
Expand Down Expand Up @@ -2940,6 +2951,7 @@ bridge_run(void)

if (cfg) {
ovsrec_open_vswitch_set_cur_cfg(cfg, cfg->next_cfg);
discover_types(cfg);
}

/* If we are completing our initial configuration for this run
Expand Down Expand Up @@ -5023,3 +5035,31 @@ mirror_refresh_stats(struct mirror *m)

ovsrec_mirror_set_statistics(m->cfg, keys, values, stat_cnt);
}

/*
* Add registered netdev and dpif types to ovsdb to allow external
* applications to query the capabilities of the Open vSwitch instance
* running on the node.
*/
static void
discover_types(const struct ovsrec_open_vswitch *cfg)
{
struct sset types;

/* Datapath types. */
sset_init(&types);
dp_enumerate_types(&types);
const char **datapath_types = sset_array(&types);
ovsrec_open_vswitch_set_datapath_types(cfg, datapath_types,
sset_count(&types));
free(datapath_types);
sset_destroy(&types);

/* Port types. */
sset_init(&types);
netdev_enumerate_types(&types);
const char **iface_types = sset_array(&types);
ovsrec_open_vswitch_set_iface_types(cfg, iface_types, sset_count(&types));
free(iface_types);
sset_destroy(&types);
}
12 changes: 9 additions & 3 deletions vswitchd/vswitch.ovsschema
@@ -1,6 +1,6 @@
{"name": "Open_vSwitch",
"version": "7.11.2",
"cksum": "320332148 22294",
"version": "7.12.1",
"cksum": "2211824403 22535",
"tables": {
"Open_vSwitch": {
"columns": {
Expand Down Expand Up @@ -39,7 +39,13 @@
"min": 0, "max": 1}},
"system_version": {
"type": {"key": {"type": "string"},
"min": 0, "max": 1}}},
"min": 0, "max": 1}},
"datapath_types": {
"type": {"key": {"type": "string"},
"min": 0, "max": "unlimited"}},
"iface_types": {
"type": {"key": {"type": "string"},
"min": 0, "max": "unlimited"}}},
"isRoot": true,
"maxRows": 1},
"Bridge": {
Expand Down
36 changes: 32 additions & 4 deletions vswitchd/vswitch.xml
Expand Up @@ -423,6 +423,28 @@

</group>

<group title="Capabilities">
<p>
These columns report capabilities of the Open vSwitch instance.
</p>
<column name="datapath_types">
<p>
This column reports the different dpifs registered with the system.
These are the values that this instance supports in the <ref
column="datapath_type" table="Bridge"/> column of the <ref
table="Bridge"/> table.
</p>
</column>
<column name="iface_types">
<p>
This column reports the different netdevs registered with the system.
These are the values that this instance supports in the <ref
column="type" table="Interface"/> column of the <ref
table="Interface"/> table.
</p>
</column>
</group>

<group title="Database Configuration">
<p>
These columns primarily configure the Open vSwitch database
Expand Down Expand Up @@ -928,9 +950,12 @@

<group title="Other Features">
<column name="datapath_type">
Name of datapath provider. The kernel datapath has
type <code>system</code>. The userspace datapath has
type <code>netdev</code>.
Name of datapath provider. The kernel datapath has type
<code>system</code>. The userspace datapath has type
<code>netdev</code>. A manager may refer to the <ref
table="Open_vSwitch" column="datapath_types"/> column of the <ref
table="Open_vSwitch"/> table for a list of the types accepted by this
Open vSwitch instance.
</column>

<column name="external_ids" key="bridge-id">
Expand Down Expand Up @@ -1747,7 +1772,10 @@
<group title="System-Specific Details">
<column name="type">
<p>
The interface type, one of:
The interface type. The types supported by a particular instance of
Open vSwitch are listed in the <ref table="Open_vSwitch"
column="iface_types"/> column in the <ref table="Open_vSwitch"/>
table. The following types are defined:
</p>

<dl>
Expand Down

0 comments on commit 842733c

Please sign in to comment.