[ovs-dev] [PATCH 02/11] ofproto-dpif: Use flow pointer in action execution.
Jarno Rajahalme
jarno.rajahalme at nsn.com
Fri May 31 11:35:12 UTC 2013
With the recent change in xlate_ctx some of the code became repetitive
in accessing the ctx->xin->flow. This replaces the *ctx argument with
*flow argument for action execution functions that only need to access
ctx->xin->flow, making the code more readable.
Summary:Summary:
Signed-off-by: Jarno Rajahalme <jarno.rajahalme at nsn.com>
---
ofproto/ofproto-dpif.c | 89 +++++++++++++++++++++++++-----------------------
1 file changed, 46 insertions(+), 43 deletions(-)
diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index 7c26c2f..37a7e3a 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -6233,96 +6233,87 @@ execute_controller_action(struct xlate_ctx *ctx, int len,
}
static void
-execute_mpls_push_action(struct xlate_ctx *ctx, ovs_be16 eth_type)
+execute_mpls_push_action(struct flow *flow, ovs_be16 eth_type)
{
ovs_assert(eth_type_mpls(eth_type));
- if (ctx->xin->flow.mpls_depth) {
- ctx->xin->flow.mpls_lse &= ~htonl(MPLS_BOS_MASK);
- ctx->xin->flow.mpls_depth++;
+ if (flow->mpls_depth) {
+ flow->mpls_lse &= ~htonl(MPLS_BOS_MASK);
+ flow->mpls_depth++;
} else {
ovs_be32 label;
uint8_t tc, ttl;
- if (ctx->xin->flow.dl_type == htons(ETH_TYPE_IPV6)) {
+ if (flow->dl_type == htons(ETH_TYPE_IPV6)) {
label = htonl(0x2); /* IPV6 Explicit Null. */
} else {
label = htonl(0x0); /* IPV4 Explicit Null. */
}
- tc = (ctx->xin->flow.nw_tos & IP_DSCP_MASK) >> 2;
- ttl = ctx->xin->flow.nw_ttl ? ctx->xin->flow.nw_ttl : 0x40;
- ctx->xin->flow.mpls_lse = set_mpls_lse_values(ttl, tc, 1, label);
- ctx->xin->flow.mpls_depth = 1;
+ tc = (flow->nw_tos & IP_DSCP_MASK) >> 2;
+ ttl = flow->nw_ttl ? flow->nw_ttl : 0x40;
+ flow->mpls_lse = set_mpls_lse_values(ttl, tc, 1, label);
+ flow->mpls_depth = 1;
}
- ctx->xin->flow.dl_type = eth_type;
+ flow->dl_type = eth_type;
}
static void
-execute_mpls_pop_action(struct xlate_ctx *ctx, ovs_be16 eth_type)
+execute_mpls_pop_action(struct flow *flow, ovs_be16 eth_type)
{
- ovs_assert(eth_type_mpls(ctx->xin->flow.dl_type));
+ ovs_assert(eth_type_mpls(flow->dl_type));
ovs_assert(!eth_type_mpls(eth_type));
- if (ctx->xin->flow.mpls_depth) {
- ctx->xin->flow.mpls_depth--;
- ctx->xin->flow.mpls_lse = htonl(0);
- if (!ctx->xin->flow.mpls_depth) {
- ctx->xin->flow.dl_type = eth_type;
+ if (flow->mpls_depth) {
+ flow->mpls_depth--;
+ flow->mpls_lse = htonl(0);
+ if (!flow->mpls_depth) {
+ flow->dl_type = eth_type;
}
}
}
static bool
-compose_dec_ttl(struct xlate_ctx *ctx, struct ofpact_cnt_ids *ids)
+compose_dec_ttl(struct flow *flow)
{
- if (ctx->xin->flow.dl_type != htons(ETH_TYPE_IP) &&
- ctx->xin->flow.dl_type != htons(ETH_TYPE_IPV6)) {
+ if (flow->dl_type != htons(ETH_TYPE_IP) &&
+ flow->dl_type != htons(ETH_TYPE_IPV6)) {
return false;
}
- if (ctx->xin->flow.nw_ttl > 1) {
- ctx->xin->flow.nw_ttl--;
+ if (flow->nw_ttl > 1) {
+ flow->nw_ttl--;
return false;
} else {
- size_t i;
-
- for (i = 0; i < ids->n_controllers; i++) {
- execute_controller_action(ctx, UINT16_MAX, OFPR_INVALID_TTL,
- ids->cnt_ids[i]);
- }
-
/* Stop processing for current table. */
return true;
}
}
static bool
-execute_set_mpls_ttl_action(struct xlate_ctx *ctx, uint8_t ttl)
+execute_set_mpls_ttl_action(struct flow *flow, uint8_t ttl)
{
- if (!eth_type_mpls(ctx->xin->flow.dl_type)) {
+ if (!eth_type_mpls(flow->dl_type)) {
return true;
}
- set_mpls_lse_ttl(&ctx->xin->flow.mpls_lse, ttl);
+ set_mpls_lse_ttl(&flow->mpls_lse, ttl);
return false;
}
static bool
-execute_dec_mpls_ttl_action(struct xlate_ctx *ctx)
+execute_dec_mpls_ttl_action(struct flow *flow)
{
- uint8_t ttl = mpls_lse_to_ttl(ctx->xin->flow.mpls_lse);
+ uint8_t ttl = mpls_lse_to_ttl(flow->mpls_lse);
- if (!eth_type_mpls(ctx->xin->flow.dl_type)) {
+ if (!eth_type_mpls(flow->dl_type)) {
return false;
}
if (ttl > 1) {
ttl--;
- set_mpls_lse_ttl(&ctx->xin->flow.mpls_lse, ttl);
+ set_mpls_lse_ttl(&flow->mpls_lse, ttl);
return false;
} else {
- execute_controller_action(ctx, UINT16_MAX, OFPR_INVALID_TTL, 0);
-
/* Stop processing for current table. */
return true;
}
@@ -6721,28 +6712,40 @@ do_xlate_actions(const struct ofpact *ofpacts, size_t ofpacts_len,
break;
case OFPACT_PUSH_MPLS:
- execute_mpls_push_action(ctx, ofpact_get_PUSH_MPLS(a)->ethertype);
+ execute_mpls_push_action(&ctx->xin->flow,
+ ofpact_get_PUSH_MPLS(a)->ethertype);
break;
case OFPACT_POP_MPLS:
- execute_mpls_pop_action(ctx, ofpact_get_POP_MPLS(a)->ethertype);
+ execute_mpls_pop_action(&ctx->xin->flow,
+ ofpact_get_POP_MPLS(a)->ethertype);
break;
case OFPACT_SET_MPLS_TTL:
- if (execute_set_mpls_ttl_action(ctx,
+ if (execute_set_mpls_ttl_action(&ctx->xin->flow,
ofpact_get_SET_MPLS_TTL(a)->ttl)) {
goto out;
}
break;
case OFPACT_DEC_MPLS_TTL:
- if (execute_dec_mpls_ttl_action(ctx)) {
+ if (execute_dec_mpls_ttl_action(&ctx->xin->flow)) {
+ execute_controller_action(ctx, UINT16_MAX, OFPR_INVALID_TTL,
+ 0);
goto out;
}
break;
case OFPACT_DEC_TTL:
- if (compose_dec_ttl(ctx, ofpact_get_DEC_TTL(a))) {
+ if (compose_dec_ttl(&ctx->xin->flow)) {
+ struct ofpact_cnt_ids *ids = ofpact_get_DEC_TTL(a);
+ size_t i;
+
+ for (i = 0; i < ids->n_controllers; i++) {
+ execute_controller_action(ctx, UINT16_MAX,
+ OFPR_INVALID_TTL,
+ ids->cnt_ids[i]);
+ }
goto out;
}
break;
--
1.7.10.4
More information about the dev
mailing list