Skip to content

Commit

Permalink
ovn: Rename Binding table to Port_Binding.
Browse files Browse the repository at this point in the history
An upcoming patch will add a Datapath_Binding table, so clarifying the
name seems useful.

Signed-off-by: Ben Pfaff <[email protected]>
Acked-by: Justin Pettit <[email protected]>
  • Loading branch information
blp committed Aug 3, 2015
1 parent d70bc24 commit dcda6e0
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 80 deletions.
28 changes: 14 additions & 14 deletions ovn/controller/binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ binding_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int,
const char *chassis_id)
{
const struct sbrec_chassis *chassis_rec;
const struct sbrec_binding *binding_rec;
const struct sbrec_port_binding *binding_rec;
struct sset lports, all_lports;
const char *name;

Expand All @@ -99,11 +99,11 @@ binding_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int,
}
sset_clone(&all_lports, &lports);

ovsdb_idl_txn_add_comment(ctx->ovnsb_idl_txn,
"ovn-controller: updating bindings for '%s'",
chassis_id);
ovsdb_idl_txn_add_comment(
ctx->ovnsb_idl_txn,"ovn-controller: updating port bindings for '%s'",
chassis_id);

SBREC_BINDING_FOR_EACH(binding_rec, ctx->ovnsb_idl) {
SBREC_PORT_BINDING_FOR_EACH(binding_rec, ctx->ovnsb_idl) {
if (sset_find_and_delete(&lports, binding_rec->logical_port) ||
(binding_rec->parent_port && binding_rec->parent_port[0] &&
sset_contains(&all_lports, binding_rec->parent_port))) {
Expand All @@ -116,14 +116,14 @@ binding_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int,
binding_rec->chassis->name,
chassis_rec->name);
}
sbrec_binding_set_chassis(binding_rec, chassis_rec);
sbrec_port_binding_set_chassis(binding_rec, chassis_rec);
} else if (binding_rec->chassis == chassis_rec) {
sbrec_binding_set_chassis(binding_rec, NULL);
sbrec_port_binding_set_chassis(binding_rec, NULL);
}
}

SSET_FOR_EACH (name, &lports) {
VLOG_DBG("No binding record for lport %s", name);
VLOG_DBG("No port binding record for lport %s", name);
}
sset_destroy(&lports);
sset_destroy(&all_lports);
Expand All @@ -147,15 +147,15 @@ binding_cleanup(struct controller_ctx *ctx, const char *chassis_id)
return true;
}

ovsdb_idl_txn_add_comment(ctx->ovnsb_idl_txn,
"ovn-controller: removing all bindings for '%s'",
chassis_id);
ovsdb_idl_txn_add_comment(
ctx->ovnsb_idl_txn,
"ovn-controller: removing all port bindings for '%s'", chassis_id);

const struct sbrec_binding *binding_rec;
const struct sbrec_port_binding *binding_rec;
bool any_changes = false;
SBREC_BINDING_FOR_EACH(binding_rec, ctx->ovnsb_idl) {
SBREC_PORT_BINDING_FOR_EACH(binding_rec, ctx->ovnsb_idl) {
if (binding_rec->chassis == chassis_rec) {
sbrec_binding_set_chassis(binding_rec, NULL);
sbrec_port_binding_set_chassis(binding_rec, NULL);
any_changes = true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions ovn/controller/physical.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ physical_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int,

/* Set up flows in table 0 for physical-to-logical translation and in table
* 64 for logical-to-physical translation. */
const struct sbrec_binding *binding;
SBREC_BINDING_FOR_EACH (binding, ctx->ovnsb_idl) {
const struct sbrec_port_binding *binding;
SBREC_PORT_BINDING_FOR_EACH (binding, ctx->ovnsb_idl) {
/* Find the OpenFlow port for the logical port, as 'ofport'. If it's
* on a remote chassis, this is the OpenFlow port for the tunnel to
* that chassis (and set 'local' to false). Otherwise, if it's on the
Expand Down
8 changes: 4 additions & 4 deletions ovn/controller/pipeline.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ symtab_init(void)
* practical for use in an OpenFlow flow table than a UUID.
*
* 'ports' maps 'logical_port' names to 'tunnel_key' values in the OVN_SB
* Binding table within the logical datapath. */
* Port_Binding table within the logical datapath. */
struct logical_datapath {
struct hmap_node hmap_node; /* Indexed on 'uuid'. */
struct uuid uuid; /* The logical_datapath's UUID. */
Expand Down Expand Up @@ -204,7 +204,7 @@ ldp_free(struct logical_datapath *ldp)
free(ldp);
}

/* Iterates through all of the records in the Binding table, updating the
/* Iterates through all of the records in the Port_Binding table, updating the
* table of logical_datapaths to match the values found in active Bindings. */
static void
ldp_run(struct controller_ctx *ctx)
Expand All @@ -214,8 +214,8 @@ ldp_run(struct controller_ctx *ctx)
simap_clear(&ldp->ports);
}

const struct sbrec_binding *binding;
SBREC_BINDING_FOR_EACH (binding, ctx->ovnsb_idl) {
const struct sbrec_port_binding *binding;
SBREC_PORT_BINDING_FOR_EACH (binding, ctx->ovnsb_idl) {
struct logical_datapath *ldp;

ldp = ldp_lookup(&binding->logical_datapath);
Expand Down
113 changes: 60 additions & 53 deletions ovn/northd/ovn-northd.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,16 +442,16 @@ int64_first_equal(int64_t *i1, size_t n_i1, int64_t *i2, size_t n_i2)
return i1 ? (i1[0] == i2[0]) : true;
}

struct binding_hash_node {
struct port_binding_hash_node {
struct hmap_node lp_node; /* In 'lp_map', by binding->logical_port. */
struct hmap_node tk_node; /* In 'tk_map', by binding->tunnel_key. */
const struct sbrec_binding *binding;
const struct sbrec_port_binding *binding;
};

static bool
tunnel_key_in_use(const struct hmap *tk_hmap, uint16_t tunnel_key)
{
const struct binding_hash_node *hash_node;
const struct port_binding_hash_node *hash_node;

HMAP_FOR_EACH_IN_BUCKET (hash_node, tk_node, hash_int(tunnel_key, 0),
tk_hmap) {
Expand Down Expand Up @@ -483,19 +483,19 @@ choose_tunnel_key(const struct hmap *tk_hmap)

/*
* When a change has occurred in the OVN_Northbound database, we go through and
* make sure that the contents of the Binding table in the OVN_Southbound
* make sure that the contents of the Port_Binding table in the OVN_Southbound
* database are up to date with the logical ports defined in the
* OVN_Northbound database.
*/
static void
set_bindings(struct northd_context *ctx)
set_port_bindings(struct northd_context *ctx)
{
const struct sbrec_binding *binding;
const struct sbrec_port_binding *binding;

/*
* We will need to look up a binding for every logical port. We don't want
* to have to do an O(n) search for every binding, so start out by hashing
* them on the logical port.
* We will need to look up a port binding for every logical port. We don't
* want to have to do an O(n) search for every binding, so start out by
* hashing them on the logical port.
*
* As we go through every logical port, we will update the binding if it
* exists or create one otherwise. When the update is done, we'll remove
Expand All @@ -504,14 +504,14 @@ set_bindings(struct northd_context *ctx)
*
* We index the logical_port column because that's the shared key between
* the OVN_NB and OVN_SB databases. We index the tunnel_key column to
* allow us to choose a unique tunnel key for any Binding rows we have to
* add.
* allow us to choose a unique tunnel key for any Port_Binding rows we have
* to add.
*/
struct hmap lp_hmap = HMAP_INITIALIZER(&lp_hmap);
struct hmap tk_hmap = HMAP_INITIALIZER(&tk_hmap);

SBREC_BINDING_FOR_EACH(binding, ctx->ovnsb_idl) {
struct binding_hash_node *hash_node = xzalloc(sizeof *hash_node);
SBREC_PORT_BINDING_FOR_EACH(binding, ctx->ovnsb_idl) {
struct port_binding_hash_node *hash_node = xzalloc(sizeof *hash_node);
hash_node->binding = binding;
hmap_insert(&lp_hmap, &hash_node->lp_node,
hash_string(binding->logical_port, 0));
Expand All @@ -525,7 +525,7 @@ set_bindings(struct northd_context *ctx)

for (size_t i = 0; i < lswitch->n_ports; i++) {
const struct nbrec_logical_port *lport = lswitch->ports[i];
struct binding_hash_node *hash_node;
struct port_binding_hash_node *hash_node;
binding = NULL;
HMAP_FOR_EACH_WITH_HASH(hash_node, lp_node,
hash_string(lport->name, 0), &lp_hmap) {
Expand All @@ -543,26 +543,29 @@ set_bindings(struct northd_context *ctx)

if (!macs_equal(binding->mac, binding->n_mac,
lport->macs, lport->n_macs)) {
sbrec_binding_set_mac(binding, (const char **) lport->macs,
lport->n_macs);
sbrec_port_binding_set_mac(binding,
(const char **) lport->macs,
lport->n_macs);
}
if (!strings_equal(binding->parent_port, lport->parent_name)) {
sbrec_binding_set_parent_port(binding, lport->parent_name);
sbrec_port_binding_set_parent_port(binding,
lport->parent_name);
}
if (!int64_first_equal(binding->tag, binding->n_tag,
lport->tag, lport->n_tag)) {
sbrec_binding_set_tag(binding, lport->tag, lport->n_tag);
sbrec_port_binding_set_tag(binding,
lport->tag, lport->n_tag);
}
if (!uuid_equals(&binding->logical_datapath,
logical_datapath)) {
sbrec_binding_set_logical_datapath(binding,
*logical_datapath);
sbrec_port_binding_set_logical_datapath(binding,
*logical_datapath);
}
if (!strings_equal(binding->type, lport->type)) {
sbrec_binding_set_type(binding, lport->type);
sbrec_port_binding_set_type(binding, lport->type);
}
if (!smap_equal(&binding->options, &lport->options)) {
sbrec_binding_set_options(binding, &lport->options);
sbrec_port_binding_set_options(binding, &lport->options);
}
} else {
/* There is no binding for this logical port, so create one. */
Expand All @@ -572,26 +575,30 @@ set_bindings(struct northd_context *ctx)
continue;
}

binding = sbrec_binding_insert(ctx->ovnsb_txn);
sbrec_binding_set_logical_port(binding, lport->name);
sbrec_binding_set_mac(binding, (const char **) lport->macs,
lport->n_macs);
binding = sbrec_port_binding_insert(ctx->ovnsb_txn);
sbrec_port_binding_set_logical_port(binding, lport->name);
sbrec_port_binding_set_mac(binding,
(const char **) lport->macs,
lport->n_macs);
if (lport->parent_name && lport->n_tag > 0) {
sbrec_binding_set_parent_port(binding, lport->parent_name);
sbrec_binding_set_tag(binding, lport->tag, lport->n_tag);
sbrec_port_binding_set_parent_port(binding,
lport->parent_name);
sbrec_port_binding_set_tag(binding,
lport->tag, lport->n_tag);
}

sbrec_binding_set_tunnel_key(binding, tunnel_key);
sbrec_binding_set_logical_datapath(binding, *logical_datapath);
sbrec_port_binding_set_tunnel_key(binding, tunnel_key);
sbrec_port_binding_set_logical_datapath(binding,
*logical_datapath);

sbrec_binding_set_type(binding, lport->type);
sbrec_binding_set_options(binding, &lport->options);
sbrec_port_binding_set_type(binding, lport->type);
sbrec_port_binding_set_options(binding, &lport->options);

/* Add the tunnel key to the tk_hmap so that we don't try to
* use it for another port. (We don't want it in the lp_hmap
* because that would just get the Binding record deleted
* later.) */
struct binding_hash_node *hash_node
struct port_binding_hash_node *hash_node
= xzalloc(sizeof *hash_node);
hash_node->binding = binding;
hmap_insert(&tk_hmap, &hash_node->tk_node,
Expand All @@ -600,14 +607,14 @@ set_bindings(struct northd_context *ctx)
}
}

struct binding_hash_node *hash_node;
struct port_binding_hash_node *hash_node;
HMAP_FOR_EACH (hash_node, lp_node, &lp_hmap) {
hmap_remove(&lp_hmap, &hash_node->lp_node);
sbrec_binding_delete(hash_node->binding);
sbrec_port_binding_delete(hash_node->binding);
}
hmap_destroy(&lp_hmap);

struct binding_hash_node *hash_node_next;
struct port_binding_hash_node *hash_node_next;
HMAP_FOR_EACH_SAFE (hash_node, hash_node_next, tk_node, &tk_hmap) {
hmap_remove(&tk_hmap, &hash_node->tk_node);
free(hash_node);
Expand All @@ -620,20 +627,20 @@ ovnnb_db_changed(struct northd_context *ctx)
{
VLOG_DBG("ovn-nb db contents have changed.");

set_bindings(ctx);
set_port_bindings(ctx);
build_pipeline(ctx);
}

/*
* The only change we get notified about is if the 'chassis' column of the
* 'Binding' table changes. When this column is not empty, it means we need to
* set the corresponding logical port as 'up' in the northbound DB.
* 'Port_Binding' table changes. When this column is not empty, it means we
* need to set the corresponding logical port as 'up' in the northbound DB.
*/
static void
ovnsb_db_changed(struct northd_context *ctx)
{
struct hmap lports_hmap;
const struct sbrec_binding *binding;
const struct sbrec_port_binding *binding;
const struct nbrec_logical_port *lport;

struct lport_hash_node {
Expand All @@ -652,7 +659,7 @@ ovnsb_db_changed(struct northd_context *ctx)
hash_string(lport->name, 0));
}

SBREC_BINDING_FOR_EACH(binding, ctx->ovnsb_idl) {
SBREC_PORT_BINDING_FOR_EACH(binding, ctx->ovnsb_idl) {
lport = NULL;
HMAP_FOR_EACH_WITH_HASH(hash_node, node,
hash_string(binding->logical_port, 0), &lports_hmap) {
Expand All @@ -663,9 +670,9 @@ ovnsb_db_changed(struct northd_context *ctx)
}

if (!lport) {
/* The logical port doesn't exist for this binding. This can
/* The logical port doesn't exist for this port binding. This can
* happen under normal circumstances when ovn-northd hasn't gotten
* around to pruning the Binding yet. */
* around to pruning the Port_Binding yet. */
continue;
}

Expand Down Expand Up @@ -807,16 +814,16 @@ main(int argc, char *argv[])
* has to care about, so we'll enable monitoring those directly. */
ctx.ovnsb_idl = ovnsb_idl = ovsdb_idl_create(ovnsb_db,
&sbrec_idl_class, false, true);
ovsdb_idl_add_table(ovnsb_idl, &sbrec_table_binding);
ovsdb_idl_add_column(ovnsb_idl, &sbrec_binding_col_logical_port);
ovsdb_idl_add_column(ovnsb_idl, &sbrec_binding_col_chassis);
ovsdb_idl_add_column(ovnsb_idl, &sbrec_binding_col_mac);
ovsdb_idl_add_column(ovnsb_idl, &sbrec_binding_col_tag);
ovsdb_idl_add_column(ovnsb_idl, &sbrec_binding_col_parent_port);
ovsdb_idl_add_column(ovnsb_idl, &sbrec_binding_col_logical_datapath);
ovsdb_idl_add_column(ovnsb_idl, &sbrec_binding_col_tunnel_key);
ovsdb_idl_add_column(ovnsb_idl, &sbrec_binding_col_type);
ovsdb_idl_add_column(ovnsb_idl, &sbrec_binding_col_options);
ovsdb_idl_add_table(ovnsb_idl, &sbrec_table_port_binding);
ovsdb_idl_add_column(ovnsb_idl, &sbrec_port_binding_col_logical_port);
ovsdb_idl_add_column(ovnsb_idl, &sbrec_port_binding_col_chassis);
ovsdb_idl_add_column(ovnsb_idl, &sbrec_port_binding_col_mac);
ovsdb_idl_add_column(ovnsb_idl, &sbrec_port_binding_col_tag);
ovsdb_idl_add_column(ovnsb_idl, &sbrec_port_binding_col_parent_port);
ovsdb_idl_add_column(ovnsb_idl, &sbrec_port_binding_col_logical_datapath);
ovsdb_idl_add_column(ovnsb_idl, &sbrec_port_binding_col_tunnel_key);
ovsdb_idl_add_column(ovnsb_idl, &sbrec_port_binding_col_type);
ovsdb_idl_add_column(ovnsb_idl, &sbrec_port_binding_col_options);
ovsdb_idl_add_column(ovnsb_idl, &sbrec_pipeline_col_logical_datapath);
ovsdb_idl_omit_alert(ovnsb_idl, &sbrec_pipeline_col_logical_datapath);
ovsdb_idl_add_column(ovnsb_idl, &sbrec_pipeline_col_table_id);
Expand Down
4 changes: 2 additions & 2 deletions ovn/ovn-architecture.7.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@
logical network in terms of ``logical datapath flows,'' and
<dfn>Binding</dfn> tables that link logical network components'
locations to the physical network. The hypervisors populate the PN and
Binding tables, whereas <code>ovn-northd</code>(8) populates the LN
tables.
Port_Binding tables, whereas <code>ovn-northd</code>(8) populates the
LN tables.
</p>

<p>
Expand Down
2 changes: 1 addition & 1 deletion ovn/ovn-sb.ovsschema
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"match": {"type": "string"},
"actions": {"type": "string"}},
"isRoot": true},
"Binding": {
"Port_Binding": {
"columns": {
"logical_datapath": {"type": "uuid"},
"logical_port": {"type": "string"},
Expand Down
Loading

0 comments on commit dcda6e0

Please sign in to comment.