mirror of
https://github.com/openvswitch/ovs
synced 2025-09-02 15:25:22 +00:00
ofp-actions: Add truncate action.
The patch adds a new action to support packet truncation. The new action is formatted as 'output(port=n,max_len=m)', as output to port n, with packet size being MIN(original_size, m). One use case is to enable port mirroring to send smaller packets to the destination port so that only useful packet information is mirrored/copied, saving some performance overhead of copying entire packet payload. Example use case is below as well as shown in the testcases: - Output to port 1 with max_len 100 bytes. - The output packet size on port 1 will be MIN(original_packet_size, 100). # ovs-ofctl add-flow br0 'actions=output(port=1,max_len=100)' - The scope of max_len is limited to output action itself. The following packet size of output:1 and output:2 will be intact. # ovs-ofctl add-flow br0 \ 'actions=output(port=1,max_len=100),output:1,output:2' - The Datapath actions shows: # Datapath actions: trunc(100),1,1,2 Tested-at: https://travis-ci.org/williamtu/ovs-travis/builds/140037134 Signed-off-by: William Tu <u9012063@gmail.com> Acked-by: Pravin B Shelar <pshelar@ovn.org>
This commit is contained in:
committed by
Pravin B Shelar
parent
4c7804f14b
commit
aaca4fe0ce
@@ -4057,13 +4057,17 @@ dp_execute_cb(void *aux_, struct dp_packet_batch *packets_,
|
||||
case OVS_ACTION_ATTR_TUNNEL_PUSH:
|
||||
if (*depth < MAX_RECIRC_DEPTH) {
|
||||
struct dp_packet_batch tnl_pkt;
|
||||
struct dp_packet_batch *orig_packets_ = packets_;
|
||||
int err;
|
||||
|
||||
if (!may_steal) {
|
||||
dp_packet_batch_clone(&tnl_pkt, packets_);
|
||||
packets_ = &tnl_pkt;
|
||||
dp_packet_batch_reset_cutlen(orig_packets_);
|
||||
}
|
||||
|
||||
dp_packet_batch_apply_cutlen(packets_);
|
||||
|
||||
err = push_tnl_action(pmd, a, packets_);
|
||||
if (!err) {
|
||||
(*depth)++;
|
||||
@@ -4076,6 +4080,7 @@ dp_execute_cb(void *aux_, struct dp_packet_batch *packets_,
|
||||
|
||||
case OVS_ACTION_ATTR_TUNNEL_POP:
|
||||
if (*depth < MAX_RECIRC_DEPTH) {
|
||||
struct dp_packet_batch *orig_packets_ = packets_;
|
||||
odp_port_t portno = u32_to_odp(nl_attr_get_u32(a));
|
||||
|
||||
p = pmd_tx_port_cache_lookup(pmd, portno);
|
||||
@@ -4084,10 +4089,13 @@ dp_execute_cb(void *aux_, struct dp_packet_batch *packets_,
|
||||
int i;
|
||||
|
||||
if (!may_steal) {
|
||||
dp_packet_batch_clone(&tnl_pkt, packets_);
|
||||
packets_ = &tnl_pkt;
|
||||
dp_packet_batch_clone(&tnl_pkt, packets_);
|
||||
packets_ = &tnl_pkt;
|
||||
dp_packet_batch_reset_cutlen(orig_packets_);
|
||||
}
|
||||
|
||||
dp_packet_batch_apply_cutlen(packets_);
|
||||
|
||||
netdev_pop_header(p->netdev, packets_);
|
||||
if (!packets_->count) {
|
||||
return;
|
||||
@@ -4107,22 +4115,42 @@ dp_execute_cb(void *aux_, struct dp_packet_batch *packets_,
|
||||
|
||||
case OVS_ACTION_ATTR_USERSPACE:
|
||||
if (!fat_rwlock_tryrdlock(&dp->upcall_rwlock)) {
|
||||
struct dp_packet_batch *orig_packets_ = packets_;
|
||||
struct dp_packet **packets = packets_->packets;
|
||||
const struct nlattr *userdata;
|
||||
struct dp_packet_batch usr_pkt;
|
||||
struct ofpbuf actions;
|
||||
struct flow flow;
|
||||
ovs_u128 ufid;
|
||||
bool clone = false;
|
||||
int i;
|
||||
|
||||
userdata = nl_attr_find_nested(a, OVS_USERSPACE_ATTR_USERDATA);
|
||||
ofpbuf_init(&actions, 0);
|
||||
|
||||
if (packets_->trunc) {
|
||||
if (!may_steal) {
|
||||
dp_packet_batch_clone(&usr_pkt, packets_);
|
||||
packets_ = &usr_pkt;
|
||||
packets = packets_->packets;
|
||||
clone = true;
|
||||
dp_packet_batch_reset_cutlen(orig_packets_);
|
||||
}
|
||||
|
||||
dp_packet_batch_apply_cutlen(packets_);
|
||||
}
|
||||
|
||||
for (i = 0; i < packets_->count; i++) {
|
||||
flow_extract(packets[i], &flow);
|
||||
dpif_flow_hash(dp->dpif, &flow, sizeof flow, &ufid);
|
||||
dp_execute_userspace_action(pmd, packets[i], may_steal, &flow,
|
||||
&ufid, &actions, userdata);
|
||||
}
|
||||
|
||||
if (clone) {
|
||||
dp_packet_delete_batch(packets_, true);
|
||||
}
|
||||
|
||||
ofpbuf_uninit(&actions);
|
||||
fat_rwlock_unlock(&dp->upcall_rwlock);
|
||||
|
||||
@@ -4170,6 +4198,7 @@ dp_execute_cb(void *aux_, struct dp_packet_batch *packets_,
|
||||
case OVS_ACTION_ATTR_SAMPLE:
|
||||
case OVS_ACTION_ATTR_HASH:
|
||||
case OVS_ACTION_ATTR_UNSPEC:
|
||||
case OVS_ACTION_ATTR_TRUNC:
|
||||
case __OVS_ACTION_ATTR_MAX:
|
||||
OVS_NOT_REACHED();
|
||||
}
|
||||
|
Reference in New Issue
Block a user