Skip to content

Commit

Permalink
ovn-controller: Persist ovn flow tables
Browse files Browse the repository at this point in the history
Ensure that ovn flow tables are persisted so that changes to
them chan be applied incrementally - this is a prereq for
making lflow_run and physical_run incremental.

As part of this change, add a one-to-many hindex for finding
desired flows by their parent's UUID.  Also extend the mapping
by match from one-to-one to one-to-many.

Signed-off-by: Ryan Moats <[email protected]>
[[email protected] adjusted style and comments and added
 HINDEX_FOR_EACH_WITH_HASH_SAFE]
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
jayhawk87 authored and blp committed Jul 19, 2016
1 parent 0643a78 commit fdbdb59
Show file tree
Hide file tree
Showing 8 changed files with 288 additions and 148 deletions.
11 changes: 10 additions & 1 deletion lib/hindex.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013 Nicira, Inc.
* Copyright (c) 2013, 2016 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 @@ -132,6 +132,15 @@ void hindex_remove(struct hindex *, struct hindex_node *);
NODE != OBJECT_CONTAINING(NULL, NODE, MEMBER); \
ASSIGN_CONTAINER(NODE, (NODE)->MEMBER.s, MEMBER))

/* Safe when NODE may be freed (not needed when NODE may be removed from the
* hash map but its members remain accessible and intact). */
#define HINDEX_FOR_EACH_WITH_HASH_SAFE(NODE, NEXT, MEMBER, HASH, HINDEX) \
for (INIT_CONTAINER(NODE, hindex_node_with_hash(HINDEX, HASH), MEMBER); \
(NODE != OBJECT_CONTAINING(NULL, NODE, MEMBER) \
? INIT_CONTAINER(NEXT, (NODE)->MEMBER.s, MEMBER), 1 \
: 0); \
(NODE) = (NEXT))

/* Returns the head node in 'hindex' with the given 'hash', or a null pointer
* if no nodes have that hash value. */
static inline struct hindex_node *
Expand Down
39 changes: 19 additions & 20 deletions ovn/controller/lflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,7 @@ static void consider_logical_flow(const struct lport_index *lports,
struct group_table *group_table,
const struct simap *ct_zones,
struct hmap *dhcp_opts_p,
uint32_t *conj_id_ofs_p,
struct hmap *flow_table);
uint32_t *conj_id_ofs_p);

static bool
lookup_port_cb(const void *aux_, const char *port_name, unsigned int *portp)
Expand Down Expand Up @@ -358,14 +357,14 @@ is_switch(const struct sbrec_datapath_binding *ldp)

}

/* Adds the logical flows from the Logical_Flow table to 'flow_table'. */
/* Adds the logical flows from the Logical_Flow table to flow tables. */
static void
add_logical_flows(struct controller_ctx *ctx, const struct lport_index *lports,
const struct mcgroup_index *mcgroups,
const struct hmap *local_datapaths,
const struct hmap *patched_datapaths,
struct group_table *group_table,
const struct simap *ct_zones, struct hmap *flow_table)
const struct simap *ct_zones)
{
uint32_t conj_id_ofs = 1;

Expand All @@ -380,7 +379,7 @@ add_logical_flows(struct controller_ctx *ctx, const struct lport_index *lports,
SBREC_LOGICAL_FLOW_FOR_EACH (lflow, ctx->ovnsb_idl) {
consider_logical_flow(lports, mcgroups, lflow, local_datapaths,
patched_datapaths, group_table, ct_zones,
&dhcp_opts, &conj_id_ofs, flow_table);
&dhcp_opts, &conj_id_ofs);
}

dhcp_opts_destroy(&dhcp_opts);
Expand All @@ -395,8 +394,7 @@ consider_logical_flow(const struct lport_index *lports,
struct group_table *group_table,
const struct simap *ct_zones,
struct hmap *dhcp_opts_p,
uint32_t *conj_id_ofs_p,
struct hmap *flow_table)
uint32_t *conj_id_ofs_p)
{
/* Determine translation of logical table IDs to physical table IDs. */
bool ingress = !strcmp(lflow->pipeline, "ingress");
Expand Down Expand Up @@ -526,8 +524,8 @@ consider_logical_flow(const struct lport_index *lports,
m->match.flow.conj_id += *conj_id_ofs_p;
}
if (!m->n) {
ofctrl_add_flow(flow_table, ptable, lflow->priority,
&m->match, &ofpacts);
ofctrl_add_flow(ptable, lflow->priority, &m->match, &ofpacts,
&lflow->header_.uuid);
} else {
uint64_t conj_stubs[64 / 8];
struct ofpbuf conj;
Expand All @@ -542,8 +540,9 @@ consider_logical_flow(const struct lport_index *lports,
dst->clause = src->clause;
dst->n_clauses = src->n_clauses;
}
ofctrl_add_flow(flow_table, ptable, lflow->priority,
&m->match, &conj);
ofctrl_add_flow(ptable, lflow->priority, &m->match, &conj,
&lflow->header_.uuid);
ofpbuf_uninit(&conj);
ofpbuf_uninit(&conj);
}
}
Expand All @@ -568,8 +567,7 @@ put_load(const uint8_t *data, size_t len,
}

static void
consider_neighbor_flow(struct hmap *flow_table,
const struct lport_index *lports,
consider_neighbor_flow(const struct lport_index *lports,
const struct sbrec_mac_binding *b,
struct ofpbuf *ofpacts_p,
struct match *match_p)
Expand Down Expand Up @@ -601,15 +599,16 @@ consider_neighbor_flow(struct hmap *flow_table,
ofpbuf_clear(ofpacts_p);
put_load(mac.ea, sizeof mac.ea, MFF_ETH_DST, 0, 48, ofpacts_p);

ofctrl_add_flow(flow_table, OFTABLE_MAC_BINDING, 100, match_p, ofpacts_p);
ofctrl_add_flow(OFTABLE_MAC_BINDING, 100, match_p, ofpacts_p,
&b->header_.uuid);
}

/* Adds an OpenFlow flow to 'flow_table' for each MAC binding in the OVN
/* Adds an OpenFlow flow to flow tables for each MAC binding in the OVN
* southbound database, using 'lports' to resolve logical port names to
* numbers. */
static void
add_neighbor_flows(struct controller_ctx *ctx,
const struct lport_index *lports, struct hmap *flow_table)
const struct lport_index *lports)
{
struct ofpbuf ofpacts;
struct match match;
Expand All @@ -618,7 +617,7 @@ add_neighbor_flows(struct controller_ctx *ctx,

const struct sbrec_mac_binding *b;
SBREC_MAC_BINDING_FOR_EACH (b, ctx->ovnsb_idl) {
consider_neighbor_flow(flow_table, lports, b, &ofpacts, &match);
consider_neighbor_flow(lports, b, &ofpacts, &match);
}
ofpbuf_uninit(&ofpacts);
}
Expand All @@ -631,12 +630,12 @@ lflow_run(struct controller_ctx *ctx, const struct lport_index *lports,
const struct hmap *local_datapaths,
const struct hmap *patched_datapaths,
struct group_table *group_table,
const struct simap *ct_zones, struct hmap *flow_table)
const struct simap *ct_zones)
{
update_address_sets(ctx);
add_logical_flows(ctx, lports, mcgroups, local_datapaths,
patched_datapaths, group_table, ct_zones, flow_table);
add_neighbor_flows(ctx, lports, flow_table);
patched_datapaths, group_table, ct_zones);
add_neighbor_flows(ctx, lports);
}

void
Expand Down
3 changes: 1 addition & 2 deletions ovn/controller/lflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ void lflow_run(struct controller_ctx *, const struct lport_index *,
const struct hmap *local_datapaths,
const struct hmap *patched_datapaths,
struct group_table *group_table,
const struct simap *ct_zones,
struct hmap *flow_table);
const struct simap *ct_zones);
void lflow_destroy(void);

#endif /* ovn/lflow.h */
Loading

0 comments on commit fdbdb59

Please sign in to comment.