Skip to content

Commit

Permalink
Merge into master from pull request floodlight#229:
Browse files Browse the repository at this point in the history
add sample and raw VLAN actions (floodlight#229)
  • Loading branch information
abat committed Dec 9, 2014
2 parents 8d5f796 + d975e0e commit bed861d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
3 changes: 3 additions & 0 deletions modules/action/module/inc/action/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ void action_controller(struct action_context *ctx, uint64_t userdata);
void action_output(struct action_context *ctx, uint32_t port_no);
void action_output_local(struct action_context *ctx);
void action_output_in_port(struct action_context *ctx);
void action_sample_to_controller(struct action_context *ctx, uint64_t userdata, uint32_t probability);

/* Ethernet */

Expand All @@ -71,6 +72,8 @@ void action_set_vlan_vid(struct action_context *ctx, uint16_t vlan_vid);
void action_set_vlan_pcp(struct action_context *ctx, uint8_t vlan_pcp);
void action_pop_vlan(struct action_context *ctx);
void action_push_vlan(struct action_context *ctx);
void action_pop_vlan_raw(struct action_context *ctx);
void action_push_vlan_raw(struct action_context *ctx, uint16_t vlan_tci);

/* IPv4 */

Expand Down
43 changes: 43 additions & 0 deletions modules/action/module/src/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,33 @@ action_output_in_port(struct action_context *ctx)
nla_put_u32(ctx->msg, OVS_ACTION_ATTR_OUTPUT, ctx->current_key.in_port);
}

/*
* Randomly send the packet back to an upcall thread with the given userdata
*
* The probability is a fraction of UINT32_MAX.
*/
void
action_sample_to_controller(struct action_context *ctx, uint64_t userdata, uint32_t probability)
{
uint32_t netlink_port = ind_ovs_port_lookup_netlink(ctx->current_key.in_port);

commit_set_field_actions(ctx);

struct nlattr *sample_attr = nla_nest_start(ctx->msg, OVS_ACTION_ATTR_SAMPLE);
nla_put_u32(ctx->msg, OVS_SAMPLE_ATTR_PROBABILITY, probability);
{
struct nlattr *sample_action_attr = nla_nest_start(ctx->msg, OVS_SAMPLE_ATTR_ACTIONS);
{
struct nlattr *action_attr = nla_nest_start(ctx->msg, OVS_ACTION_ATTR_USERSPACE);
nla_put_u32(ctx->msg, OVS_USERSPACE_ATTR_PID, netlink_port);
nla_put_u64(ctx->msg, OVS_USERSPACE_ATTR_USERDATA, userdata);
nla_nest_end(ctx->msg, action_attr);
}
nla_nest_end(ctx->msg, sample_action_attr);
}
nla_nest_end(ctx->msg, sample_attr);
}

/*
* Ethernet actions
*/
Expand Down Expand Up @@ -172,6 +199,22 @@ action_push_vlan(struct action_context *ctx)
}
}

void
action_pop_vlan_raw(struct action_context *ctx)
{
nla_put_flag(ctx->msg, OVS_ACTION_ATTR_POP_VLAN);
}

void
action_push_vlan_raw(struct action_context *ctx, uint16_t vlan_tci)
{
struct ovs_action_push_vlan vlan = {
.vlan_tpid = htons(ETH_P_8021Q),
.vlan_tci = vlan_tci,
};
nla_put(ctx->msg, OVS_ACTION_ATTR_PUSH_VLAN, sizeof(vlan), &vlan);
}

/*
* IPv4 actions
*/
Expand Down

0 comments on commit bed861d

Please sign in to comment.