Skip to content

Commit

Permalink
ovn-controller: Datapath based conntrack zone for load-balancing.
Browse files Browse the repository at this point in the history
Currently ct_lb() logical action is only added for a logical switch and
we use the conntrack zone allocated for the logical port.  A future commit
will use ct_lb() for a logical router too.  In that case, use the allocated
DNAT zone.

Rationale for not passing zone as an argument for ct_lb():
One way to look at it would be that a "zone" is an internal implementation
detail and should not be seen in a action of logical flow.  But we can then
say that we could rename "zone" as "datapath" in the logical action.  But,
then we would be limiting it to 2 anyway (datapath=lswitch or
datapath=lrouter) - in which case we are inferring it with the current patch.

Signed-off-by: Gurucharan Shetty <guru@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
  • Loading branch information
shettyg committed Sep 9, 2016
1 parent f09c5b7 commit d9f9e0c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
3 changes: 3 additions & 0 deletions include/ovn/actions.h
Expand Up @@ -397,6 +397,9 @@ struct ovnact_encode_params {
unsigned int *portp);
const void *aux;

/* 'true' if the flow is for a switch. */
bool is_switch;

/* A map from a port name to its connection tracking zone. */
const struct simap *ct_zones;

Expand Down
1 change: 1 addition & 0 deletions ovn/controller/lflow.c
Expand Up @@ -251,6 +251,7 @@ consider_logical_flow(const struct lport_index *lports,
struct ovnact_encode_params ep = {
.lookup_port = lookup_port_cb,
.aux = &aux,
.is_switch = is_switch(ldp),
.ct_zones = ct_zones,
.group_table = group_table,

Expand Down
9 changes: 7 additions & 2 deletions ovn/lib/actions.c
Expand Up @@ -912,7 +912,8 @@ encode_CT_LB(const struct ovnact_ct_lb *cl,
struct ofpact_conntrack *ct = ofpact_put_CT(ofpacts);
struct ofpact_nat *nat;
size_t nat_offset;
ct->zone_src.field = mf_from_id(MFF_LOG_CT_ZONE);
ct->zone_src.field = ep->is_switch ? mf_from_id(MFF_LOG_CT_ZONE)
: mf_from_id(MFF_LOG_DNAT_ZONE);
ct->zone_src.ofs = 0;
ct->zone_src.n_bits = 16;
ct->flags = 0;
Expand All @@ -936,12 +937,16 @@ encode_CT_LB(const struct ovnact_ct_lb *cl,
uint32_t group_id = 0, hash;
struct group_info *group_info;
struct ofpact_group *og;
uint32_t zone_reg = ep->is_switch ? MFF_LOG_CT_ZONE - MFF_REG0
: MFF_LOG_DNAT_ZONE - MFF_REG0;

struct ds ds = DS_EMPTY_INITIALIZER;
ds_put_format(&ds, "type=select");

BUILD_ASSERT(MFF_LOG_CT_ZONE >= MFF_REG0);
BUILD_ASSERT(MFF_LOG_CT_ZONE < MFF_REG0 + FLOW_N_REGS);
BUILD_ASSERT(MFF_LOG_DNAT_ZONE >= MFF_REG0);
BUILD_ASSERT(MFF_LOG_DNAT_ZONE < MFF_REG0 + FLOW_N_REGS);
for (size_t bucket_id = 0; bucket_id < cl->n_dsts; bucket_id++) {
const struct ovnact_ct_lb_dst *dst = &cl->dsts[bucket_id];
ds_put_format(&ds, ",bucket=bucket_id=%"PRIuSIZE",weight:100,actions="
Expand All @@ -950,7 +955,7 @@ encode_CT_LB(const struct ovnact_ct_lb *cl,
ds_put_format(&ds, ":%"PRIu16, dst->port);
}
ds_put_format(&ds, "),commit,table=%d,zone=NXM_NX_REG%d[0..15])",
recirc_table, MFF_LOG_CT_ZONE - MFF_REG0);
recirc_table, zone_reg);
}

hash = hash_string(ds_cstr(&ds), 0);
Expand Down
6 changes: 4 additions & 2 deletions ovn/ovn-sb.xml
Expand Up @@ -1345,8 +1345,10 @@
DNAT address. Processing automatically moves on to the next table,
as if <code>next;</code> were specified, and later tables act on
the packet as modified by the connection tracker. Connection
tracking state is scoped by the logical port, so overlapping
addresses may be used.
tracking state is scoped by the logical port when the action is
used in a flow for a logical switch, so overlapping
addresses may be used. Connection tracking state is scoped by the
logical topology when the action is used in a flow for a router.
</p>
<p>
Without arguments, <code>ct_lb</code> sends the packet to the
Expand Down
1 change: 1 addition & 0 deletions tests/test-ovn.c
Expand Up @@ -1182,6 +1182,7 @@ test_parse_actions(struct ovs_cmdl_context *ctx OVS_UNUSED)
const struct ovnact_encode_params ep = {
.lookup_port = lookup_port_cb,
.aux = &ports,
.is_switch = true,
.ct_zones = &ct_zones,
.group_table = &group_table,

Expand Down

0 comments on commit d9f9e0c

Please sign in to comment.