Yes, you missed something. This pattern is used in inline functions called with
compile-time constant values for is_ip6:
always_inline uword
ah_encrypt_inline (vlib_main_t * vm,
vlib_node_runtime_t * node, vlib_frame_t * from_frame,
int is_ip6)
VLIB_NODE_FN (ah4_encrypt_node) (vlib_main_t * vm,
vlib_node_runtime_t * node,
vlib_frame_t * from_frame)
{
return ah_encrypt_inline (vm, node, from_frame, 0 /* is_ip6 */ );
}
VLIB_NODE_FN (ah6_encrypt_node) (vlib_main_t * vm,
vlib_node_runtime_t * node,
vlib_frame_t * from_frame)
{
return ah_encrypt_inline (vm, node, from_frame, 1 /* is_ip6 */ );
}
The compiler discards either the “if” clause or the “else” clause, and
(certainly) never tests is_ip6 at runtime. It might be marginally worth
s/xxx_node.index/node->node_index/.
Another instance of this game may make sense in performance-critical nodes.
Here, we remove packet-tracer code:
always_inline uword
nsim_inline (vlib_main_t * vm,
vlib_node_runtime_t * node, vlib_frame_t * frame, int is_trace)
{
<snip>
if (is_trace)
{
if (b[0]->flags & VLIB_BUFFER_IS_TRACED)
{
nsim_trace_t *t = vlib_add_trace (vm, node, b[0], sizeof (*t));
t->expires = expires;
t->is_drop = is_drop0;
t->tx_sw_if_index = (is_drop0 == 0) ? ep->tx_sw_if_index : 0;
}
}
<snip>
}
VLIB_NODE_FN (nsim_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
vlib_frame_t * frame)
{
if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE))
return nsim_inline (vm, node, frame, 1 /* is_trace */ );
else
return nsim_inline (vm, node, frame, 0 /* is_trace */ );
}
From: [email protected] <[email protected]> On Behalf Of Kingwel Xie
Sent: Thursday, November 1, 2018 8:43 PM
To: [email protected]
Subject: [vpp-dev] Incrementing node counters
Hi vPPers,
I’m looking at the latest changes in IPSEC, and I notice ip4 and ip6 nodes are
separated. So there are a lot of code in the node function like this:
if (is_ip6)
vlib_node_increment_counter (vm, esp6_decrypt_node.index,
ESP_DECRYPT_ERROR_RX_PKTS,
from_frame->n_vectors);
else
vlib_node_increment_counter (vm, esp4_decrypt_node.index,
ESP_DECRYPT_ERROR_RX_PKTS,
from_frame->n_vectors);
I’m wondering why not like this:
vlib_node_increment_counter (vm, node->node_index,
ESP_DECRYPT_ERROR_RX_PKTS,
from_frame->n_vectors);
My understanding is that node functions are always dispatched with the correct
node instances. Or do I miss something? BTW, nt just ipsec, quite some other
nodes are written as the former.
Regards,
Kingwel
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#11076): https://lists.fd.io/g/vpp-dev/message/11076
Mute This Topic: https://lists.fd.io/mt/27823101/21656
Group Owner: [email protected]
Unsubscribe: https://lists.fd.io/g/vpp-dev/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-