Feature Arcs

A significant number of vpp features are configurable on a per-interface or per-system basis. Rather than ask feature coders to manually construct the required graph arcs, we built a general mechanism to manage these mechanics.

Specifically, feature arcs comprise ordered sets of graph nodes. Each feature node in an arc is independently controlled. Feature arc nodes are generally unaware of each other. Handing a packet to “the next feature node” is quite inexpensive.

The feature arc implementation solves the problem of creating graph arcs used for steering.

At the beginning of a feature arc, a bit of setup work is needed, but only if at least one feature is enabled on the arc.

On a per-arc basis, individual feature definitions create a set of ordering dependencies. Feature infrastructure performs a topological sort of the ordering dependencies, to determine the actual feature order. Missing dependencies will lead to runtime disorder. See https://gerrit.fd.io/r/#/c/12753 for an example.

If no partial order exists, vpp will refuse to run. Circular dependency loops of the form “a then b, b then c, c then a” are impossible to satisfy.

Adding a feature to an existing feature arc

To nobody’s great surprise, we set up feature arcs using the typical “macro -> constructor function -> list of declarations” pattern:

    VNET_FEATURE_INIT (mactime, static) =
    {
      .arc_name = "device-input",
      .node_name = "mactime",
      .runs_before = VNET_FEATURES ("ethernet-input"),
    };  

This creates a “mactime” feature on the “device-input” arc.

Once per frame, dig up the vnet_feature_config_main_t corresponding to the “device-input” feature arc:

    vnet_main_t *vnm = vnet_get_main ();
    vnet_interface_main_t *im = &vnm->interface_main;
    u8 arc = im->output_feature_arc_index;
    vnet_feature_config_main_t *fcm;

    fcm = vnet_feature_get_config_main (arc);

Note that in this case, we’ve stored the required arc index - assigned by the feature infrastructure - in the vnet_interface_main_t. Where to put the arc index is a programmer’s decision when creating a feature arc.

Per packet, set next0 to steer packets to the next node they should visit:

    vnet_get_config_data (&fcm->config_main,
                          &b0->current_config_index /* value-result */, 
                          &next0, 0 /* # bytes of config data */);

Configuration data is per-feature arc, and is often unused. Note that it’s normal to reset next0 to divert packets elsewhere; often, to drop them for cause:

    next0 = MACTIME_NEXT_DROP;
    b0->error = node->errors[DROP_CAUSE];

Creating a feature arc

Once again, we create feature arcs using constructor macros:

    VNET_FEATURE_ARC_INIT (ip4_unicast, static) =
    {
      .arc_name = "ip4-unicast",
      .start_nodes = VNET_FEATURES ("ip4-input", "ip4-input-no-checksum"),
      .arc_index_ptr = &ip4_main.lookup_main.ucast_feature_arc_index,
    };  

In this case, we configure two arc start nodes to handle the “hardware-verified ip checksum or not” cases. During initialization, the feature infrastructure stores the arc index as shown.

In the head-of-arc node, do the following to send packets along the feature arc:

    ip_lookup_main_t *lm = &im->lookup_main;
    arc = lm->ucast_feature_arc_index;

Once per packet, initialize packet metadata to walk the feature arc:

vnet_feature_arc_start (arc, sw_if_index0, &next, b0);

Enabling / Disabling features

Simply call vnet_feature_enable_disable to enable or disable a specific feature:

    vnet_feature_enable_disable ("device-input", /* arc name */
                                 "mactime",      /* feature name */
           		             sw_if_index,    /* Interface sw_if_index */
                                 enable_disable, /* 1 => enable */
                                 0 /* (void *) feature_configuration */, 
                                 0 /* feature_configuration_nbytes */);

The feature_configuration opaque is seldom used.

If you wish to make a feature a de facto system-level concept, pass sw_if_index=0 at all times. Sw_if_index 0 is always valid, and corresponds to the “local” interface.

Table of Feature Arcs

Simply search for name-strings to track down the arc definition, location of the arc index, etc.

            |    Arc Name      |
            |------------------|
            | device-input     |
            | ethernet-output  |
            | interface-output |
            | ip4-drop         |
            | ip4-local        |
            | ip4-multicast    |
            | ip4-output       |
            | ip4-punt         |
            | ip4-unicast      |
            | ip6-drop         |
            | ip6-local        |
            | ip6-multicast    |
            | ip6-output       |
            | ip6-punt         |
            | ip6-unicast      |
            | mpls-input       |
            | mpls-output      |
            | nsh-output       |