Skip to content

Commit

Permalink
ovn: Use Logical_Switch_Port in NB.
Browse files Browse the repository at this point in the history
We have both logical switch and router ports.  Router ports are
referenced in "Logical_Router_Port" table, so this make it more
consistent.

Also change internal use of "lport" to "lsp".

Signed-off-by: Justin Pettit <[email protected]>
Acked-by: Ryan Moats <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
justinpettit committed Jun 11, 2016
1 parent e48ccf3 commit 80f408f
Show file tree
Hide file tree
Showing 16 changed files with 294 additions and 285 deletions.
13 changes: 7 additions & 6 deletions ovn/CONTAINERS.OpenStack.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ Neutron that are currently needed, it sends the vif-id and the VLAN tag as
inputs.

* Neutron in turn will verify that the vif-id belongs to the tenant in question
and then uses the OVN specific plugin to create a new row in the Logical_Port
table of the OVN Northbound Database. Neutron responds back with an
IP address and MAC address for that network interface. So Neutron becomes
the IPAM system and provides unique IP and MAC addresses across VMs and
containers in the same logical network.
and then uses the OVN specific plugin to create a new row in the
Logical_Switch_Port table of the OVN Northbound Database. Neutron
responds back with an IP address and MAC address for that network
interface. So Neutron becomes the IPAM system and provides unique IP
and MAC addresses across VMs and containers in the same logical network.

* The Neutron API call above to create a logical port for the container
could add a relatively significant amount of time to container creation.
Expand All @@ -80,7 +80,8 @@ port needs to be attached to a different logical network.

* When a container is eventually deleted, the network plugin in that VM
may make a call to Neutron to delete that port. Neutron in turn will
delete the entry in the Logical_Port table of the OVN Northbound Database.
delete the entry in the Logical_Switch_Port table of the OVN Northbound
Database.

As an example, consider Docker containers. Since Docker currently does not
have a network plugin feature, this example uses a hypothetical wrapper
Expand Down
2 changes: 1 addition & 1 deletion ovn/controller/pinctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ send_garp_update(const struct sbrec_port_binding *binding_rec,
int i;
for (i = 0; i < binding_rec->n_mac; i++) {
struct lport_addresses laddrs;
if (!extract_lport_addresses(binding_rec->mac[i], &laddrs, false)
if (!extract_lsp_addresses(binding_rec->mac[i], &laddrs, false)
|| !laddrs.n_ipv4_addrs) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions ovn/lib/ovn-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ VLOG_DEFINE_THIS_MODULE(ovn_util);
* returns true with laddrs->n_ipv4_addrs = 1 and laddrs->n_ipv6_addrs = 0.
*/
bool
extract_lport_addresses(char *address, struct lport_addresses *laddrs,
bool store_ipv6)
extract_lsp_addresses(char *address, struct lport_addresses *laddrs,
bool store_ipv6)
{
char *buf = address;
int buf_index = 0;
Expand Down
4 changes: 2 additions & 2 deletions ovn/lib/ovn-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ struct lport_addresses {
};

bool
extract_lport_addresses(char *address, struct lport_addresses *laddrs,
bool store_ipv6);
extract_lsp_addresses(char *address, struct lport_addresses *laddrs,
bool store_ipv6);

char *
alloc_nat_zone_key(const struct sbrec_port_binding *port_binding,
Expand Down
8 changes: 4 additions & 4 deletions ovn/northd/ovn-northd.8.xml
Original file line number Diff line number Diff line change
Expand Up @@ -760,10 +760,10 @@ icmp4 {
data in the <code>OVN_Northbound</code> database. For router ports
connected to logical switches, MAC bindings can be known statically
from the <code>addresses</code> column in the
<code>Logical_Port</code> table. For router ports connected to other
logical routers, MAC bindings can be known statically from the
<code>mac</code> and <code>network</code> column in the
<code>Logical_Router_Port</code> table.
<code>Logical_Switch_Port</code> table. For router ports
connected to other logical routers, MAC bindings can be known
statically from the <code>mac</code> and <code>network</code>
column in the <code>Logical_Router_Port</code> table.
</p>

<p>
Expand Down
55 changes: 28 additions & 27 deletions ovn/northd/ovn-northd.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ struct ovn_port {
char *key; /* nbs->name, nbr->name, sb->logical_port. */
char *json_key; /* 'key', quoted for use in JSON. */

const struct nbrec_logical_port *nbs; /* May be NULL. */
const struct nbrec_logical_switch_port *nbs; /* May be NULL. */
const struct nbrec_logical_router_port *nbr; /* May be NULL. */
const struct sbrec_port_binding *sb; /* May be NULL. */

Expand All @@ -501,7 +501,7 @@ struct ovn_port {

static struct ovn_port *
ovn_port_create(struct hmap *ports, const char *key,
const struct nbrec_logical_port *nbs,
const struct nbrec_logical_switch_port *nbs,
const struct nbrec_logical_router_port *nbr,
const struct sbrec_port_binding *sb)
{
Expand Down Expand Up @@ -575,7 +575,7 @@ join_logical_ports(struct northd_context *ctx,
HMAP_FOR_EACH (od, key_node, datapaths) {
if (od->nbs) {
for (size_t i = 0; i < od->nbs->n_ports; i++) {
const struct nbrec_logical_port *nbs = od->nbs->ports[i];
const struct nbrec_logical_switch_port *nbs = od->nbs->ports[i];
struct ovn_port *op = ovn_port_find(ports, nbs->name);
if (op) {
if (op->nbs || op->nbr) {
Expand Down Expand Up @@ -752,7 +752,7 @@ ovn_port_update_sbrec(const struct ovn_port *op)
}

/* Updates the southbound Port_Binding table so that it contains the logical
* ports specified by the northbound database.
* switch ports specified by the northbound database.
*
* Initializes 'ports' to contain a "struct ovn_port" for every logical port,
* using the "struct ovn_datapath"s in 'datapaths' to look up logical
Expand Down Expand Up @@ -989,7 +989,7 @@ ovn_lflow_destroy(struct hmap *lflows, struct ovn_lflow *lflow)
/* Appends port security constraints on L2 address field 'eth_addr_field'
* (e.g. "eth.src" or "eth.dst") to 'match'. 'port_security', with
* 'n_port_security' elements, is the collection of port_security constraints
* from an OVN_NB Logical_Port row. */
* from an OVN_NB Logical_Switch_Port row. */
static void
build_port_security_l2(const char *eth_addr_field,
char **port_security, size_t n_port_security,
Expand Down Expand Up @@ -1103,7 +1103,7 @@ build_port_security_nd(struct ovn_port *op, struct hmap *lflows)
{
for (size_t i = 0; i < op->nbs->n_port_security; i++) {
struct lport_addresses ps;
if (!extract_lport_addresses(op->nbs->port_security[i], &ps, true)) {
if (!extract_lsp_addresses(op->nbs->port_security[i], &ps, true)) {
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
VLOG_INFO_RL(&rl, "invalid syntax '%s' in port security. No MAC"
" address found", op->nbs->port_security[i]);
Expand Down Expand Up @@ -1198,7 +1198,7 @@ build_port_security_ip(enum ovn_pipeline pipeline, struct ovn_port *op,

for (size_t i = 0; i < op->nbs->n_port_security; i++) {
struct lport_addresses ps;
if (!extract_lport_addresses(op->nbs->port_security[i], &ps, true)) {
if (!extract_lsp_addresses(op->nbs->port_security[i], &ps, true)) {
continue;
}

Expand Down Expand Up @@ -1301,15 +1301,15 @@ build_port_security_ip(enum ovn_pipeline pipeline, struct ovn_port *op,
}

static bool
lport_is_enabled(const struct nbrec_logical_port *lport)
lsp_is_enabled(const struct nbrec_logical_switch_port *lsp)
{
return !lport->enabled || *lport->enabled;
return !lsp->enabled || *lsp->enabled;
}

static bool
lport_is_up(const struct nbrec_logical_port *lport)
lsp_is_up(const struct nbrec_logical_switch_port *lsp)
{
return !lport->up || *lport->up;
return !lsp->up || *lsp->up;
}

static bool
Expand Down Expand Up @@ -1525,7 +1525,7 @@ build_lswitch_flows(struct hmap *datapaths, struct hmap *ports,
continue;
}

if (!lport_is_enabled(op->nbs)) {
if (!lsp_is_enabled(op->nbs)) {
/* Drop packets from disabled logical ports (since logical flow
* tables are default-drop). */
continue;
Expand Down Expand Up @@ -1584,14 +1584,14 @@ build_lswitch_flows(struct hmap *datapaths, struct hmap *ports,
* - port is up or
* - port type is router
*/
if (!lport_is_up(op->nbs) && strcmp(op->nbs->type, "router")) {
if (!lsp_is_up(op->nbs) && strcmp(op->nbs->type, "router")) {
continue;
}

for (size_t i = 0; i < op->nbs->n_addresses; i++) {
struct lport_addresses laddrs;
if (!extract_lport_addresses(op->nbs->addresses[i], &laddrs,
false)) {
if (!extract_lsp_addresses(op->nbs->addresses[i], &laddrs,
false)) {
continue;
}
for (size_t j = 0; j < laddrs.n_ipv4_addrs; j++) {
Expand Down Expand Up @@ -1639,7 +1639,7 @@ build_lswitch_flows(struct hmap *datapaths, struct hmap *ports,
continue;
}

if (lport_is_enabled(op->nbs)) {
if (lsp_is_enabled(op->nbs)) {
ovn_multicast_add(mcgroups, &mc_flood, op);
}
}
Expand Down Expand Up @@ -1675,7 +1675,7 @@ build_lswitch_flows(struct hmap *datapaths, struct hmap *ports,
ds_destroy(&actions);
ds_destroy(&match);
} else if (!strcmp(op->nbs->addresses[i], "unknown")) {
if (lport_is_enabled(op->nbs)) {
if (lsp_is_enabled(op->nbs)) {
ovn_multicast_add(mcgroups, &mc_unknown, op);
op->od->has_unknown = true;
}
Expand Down Expand Up @@ -1730,7 +1730,7 @@ build_lswitch_flows(struct hmap *datapaths, struct hmap *ports,

struct ds match = DS_EMPTY_INITIALIZER;
ds_put_format(&match, "outport == %s", op->json_key);
if (lport_is_enabled(op->nbs)) {
if (lsp_is_enabled(op->nbs)) {
build_port_security_l2("eth.dst", op->nbs->port_security,
op->nbs->n_port_security, &match);
ovn_lflow_add(lflows, op->od, S_SWITCH_OUT_PORT_SEC_L2, 50,
Expand Down Expand Up @@ -2080,16 +2080,17 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,

for (size_t i = 0; i < op->nbs->n_addresses; i++) {
struct lport_addresses laddrs;
if (!extract_lport_addresses(op->nbs->addresses[i], &laddrs,
false)) {
if (!extract_lsp_addresses(op->nbs->addresses[i], &laddrs,
false)) {
continue;
}

for (size_t k = 0; k < laddrs.n_ipv4_addrs; k++) {
ovs_be32 ip = laddrs.ipv4_addrs[k].addr;
for (size_t j = 0; j < op->od->n_router_ports; j++) {
/* Get the Logical_Router_Port that the Logical_Port is
* connected to, as 'peer'. */
/* Get the Logical_Router_Port that the
* Logical_Switch_Port is connected to, as
* 'peer'. */
const char *peer_name = smap_get(
&op->od->router_ports[j]->nbs->options,
"router-port");
Expand Down Expand Up @@ -2351,16 +2352,16 @@ ovnsb_db_run(struct northd_context *ctx)
}
struct hmap lports_hmap;
const struct sbrec_port_binding *sb;
const struct nbrec_logical_port *nb;
const struct nbrec_logical_switch_port *nb;

struct lport_hash_node {
struct hmap_node node;
const struct nbrec_logical_port *nb;
const struct nbrec_logical_switch_port *nb;
} *hash_node;

hmap_init(&lports_hmap);

NBREC_LOGICAL_PORT_FOR_EACH(nb, ctx->ovnnb_idl) {
NBREC_LOGICAL_SWITCH_PORT_FOR_EACH(nb, ctx->ovnnb_idl) {
hash_node = xzalloc(sizeof *hash_node);
hash_node->nb = nb;
hmap_insert(&lports_hmap, &hash_node->node, hash_string(nb->name, 0));
Expand All @@ -2386,10 +2387,10 @@ ovnsb_db_run(struct northd_context *ctx)

if (sb->chassis && (!nb->up || !*nb->up)) {
bool up = true;
nbrec_logical_port_set_up(nb, &up, 1);
nbrec_logical_switch_port_set_up(nb, &up, 1);
} else if (!sb->chassis && (!nb->up || *nb->up)) {
bool up = false;
nbrec_logical_port_set_up(nb, &up, 1);
nbrec_logical_switch_port_set_up(nb, &up, 1);
}
}

Expand Down
38 changes: 20 additions & 18 deletions ovn/ovn-architecture.7.xml
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,11 @@

<li>
The CMS plugin updates the OVN Northbound database to include the new
VIF, by adding a row to the <code>Logical_Port</code> table. In the new
row, <code>name</code> is <var>vif-id</var>, <code>mac</code> is
<var>mac</var>, <code>switch</code> points to the OVN logical switch's
Logical_Switch record, and other columns are initialized appropriately.
VIF, by adding a row to the <code>Logical_Switch_Port</code>
table. In the new row, <code>name</code> is <var>vif-id</var>,
<code>mac</code> is <var>mac</var>, <code>switch</code> points to
the OVN logical switch's Logical_Switch record, and other columns
are initialized appropriately.
</li>

<li>
Expand Down Expand Up @@ -394,11 +395,11 @@
networking is ready. To support this, <code>ovn-northd</code> notices
the <code>chassis</code> column updated for the row in
<code>Binding</code> table and pushes this upward by updating the
<ref column="up" table="Logical_Port" db="OVN_NB"/> column in the OVN
Northbound database's <ref table="Logical_Port" db="OVN_NB"/> table to
indicate that the VIF is now up. The CMS, if it uses this feature, can
then
react by allowing the VM's execution to proceed.
<ref column="up" table="Logical_Switch_Port" db="OVN_NB"/> column
in the OVN Northbound database's <ref table="Logical_Switch_Port"
db="OVN_NB"/> table to indicate that the VIF is now up. The CMS,
if it uses this feature, can then react by allowing the VM's
execution to proceed.
</li>

<li>
Expand Down Expand Up @@ -440,7 +441,7 @@

<li>
The CMS plugin removes the VIF from the OVN Northbound database,
by deleting its row in the <code>Logical_Port</code> table.
by deleting its row in the <code>Logical_Switch_Port</code> table.
</li>

<li>
Expand Down Expand Up @@ -533,10 +534,11 @@
The container spawning entity (either directly or through the CMS that
manages the underlying infrastructure) updates the OVN Northbound
database to include the new CIF, by adding a row to the
<code>Logical_Port</code> table. In the new row, <code>name</code> is
any unique identifier, <code>parent_name</code> is the <var>vif-id</var>
of the VM through which the CIF's network traffic is expected to go
through and the <code>tag</code> is the VLAN tag that identifies the
<code>Logical_Switch_Port</code> table. In the new row,
<code>name</code> is any unique identifier,
<code>parent_name</code> is the <var>vif-id</var> of the VM
through which the CIF's network traffic is expected to go through
and the <code>tag</code> is the VLAN tag that identifies the
network traffic of that CIF.
</li>

Expand Down Expand Up @@ -567,17 +569,17 @@
One can only start the application inside the container after the
underlying network is ready. To support this, <code>ovn-northd</code>
notices the updated <code>chassis</code> column in <code>Binding</code>
table and updates the <ref column="up" table="Logical_Port"
table and updates the <ref column="up" table="Logical_Switch_Port"
db="OVN_NB"/> column in the OVN Northbound database's
<ref table="Logical_Port" db="OVN_NB"/> table to indicate that the
<ref table="Logical_Switch_Port" db="OVN_NB"/> table to indicate that the
CIF is now up. The entity responsible to start the container application
queries this value and starts the application.
</li>

<li>
Eventually the entity that created and started the container, stops it.
The entity, through the CMS (or directly) deletes its row in the
<code>Logical_Port</code> table.
<code>Logical_Switch_Port</code> table.
</li>

<li>
Expand Down Expand Up @@ -943,7 +945,7 @@
<li>
Now, the administrator can use the CMS to add a VTEP logical switch
to the OVN logical network. To do that, the CMS must first create a
new <code>Logical_Port</code> table entry in the <code>
new <code>Logical_Switch_Port</code> table entry in the <code>
OVN_Northbound</code> database. Then, the <var>type</var> column
of this entry must be set to "vtep". Next, the <var>
vtep-logical-switch</var> and <var>vtep-physical-switch</var> keys
Expand Down
8 changes: 4 additions & 4 deletions ovn/ovn-nb.ovsschema
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "OVN_Northbound",
"version": "2.1.2",
"cksum": "429668869 5325",
"version": "3.0.0",
"cksum": "1808140260 5339",
"tables": {
"Logical_Switch": {
"columns": {
"name": {"type": "string"},
"ports": {"type": {"key": {"type": "uuid",
"refTable": "Logical_Port",
"refTable": "Logical_Switch_Port",
"refType": "strong"},
"min": 0,
"max": "unlimited"}},
Expand All @@ -20,7 +20,7 @@
"type": {"key": "string", "value": "string",
"min": 0, "max": "unlimited"}}},
"isRoot": true},
"Logical_Port": {
"Logical_Switch_Port": {
"columns": {
"name": {"type": "string"},
"type": {"type": "string"},
Expand Down
Loading

0 comments on commit 80f408f

Please sign in to comment.