IP Reassembly in the Plugin

As noted in the introduction, the plugin version of the reassembler example requires no code to perform the fragment reassembly because the plugin framework handles this for you.

The plugin version also illustrates working with data-plane redundancy.

All the code to implement the plugin version is in the file sandbox/src/lib/passthru-plugin/passthru_main.c.

For a general introduction to plugins, see Plugin Architecture, Plugin Functionality and Service Chaining, and Writing a Plugin. For a somewhat more complex example than this one, see The Sync Equilibrium Application Using Plugins.

Comparison With the Daemon Version

The code you write to implement a plugin consists of an entry function, plus data and control event handlers. The entry function (in this example, passthru_entry()) is called by the management daemon when it loads the plugin as a dynamic object. The control event handler (in this example, passthru_ctrl_hdlr())is called by the plugin when the service receives an initialization or configuration data-received event. The data event handler (in this example, passthru_data_hdlr()) is called by the plugin when the service receives an event related to packets.

The plugin entry function is specified in the XML configuration file, which the example provides at sandbox/src/etc/passthru-plugin.xml. After installation, the system places this file in /opt/sdk/pkg/package-name.xml on the MultiServices PIC.

This plugin example illustrates your ability to choose whether to use the session functionality and whether to store configuration information in the policy database. Using the policy database with the session framework allows you to apply stored decisions to forward and reverse packet flows without repeated lookups; your code just handles the data events.

To illustrate this flexibility, processing and configuration #defines are established at the beginning of the file. This version enables the processing mode SESSION_BASED_MODE, which allows full session affinity and session context. In this mode, the plugin will receive separate data events for the first packet and other packets, as well as session open, close, and destroy notifications.

Entry Function

The entry function registers the plugin and its handlers with the framework. It sets basic information parameters in msvcs_plugin_params_t, and calls msvcs_plugin_register(&params).

Control Event Handler

The control handler processes the MSVCS_CONTROL_EV_INIT event. This is where your code stores the configuration in the policy database.

This handler also includes code to process data plane redundancy states, accessible through the MSVCS_CONTROL_EV_HA_INFO_BLOB event. For an introduction to this functionality, see Data-Plane Redundancy.

Data Event Handler

The data event handler performs the packet processing. In contrast to the repeated and complex shared memory allocation in the daemon version, the plugin initializes object cache shared memory only once, when handling the MSVCS_DATA_EV_SM_INIT event. Additional object cache memory is allocated on MSVCS_DATA_EV_FIRST_PKT_PROC, to store the session context.

The code handles the MSVCS_DATA_FIRST_PKT_PROC event to get session information from the first packet. Once this information has been saved, it is then available to all other packets in the flow.

The code uses the MSVCS_DATA_EV_PKT_PROC event to retrieve the stored session information and apply it to the forward and reverse packet flows using framework APIs:

// find the string stored in the session context describing what we want:
        if(md_ctx->sc_flags & MSVCS_CTX_FLAGS_DIR_FORWARD) {
            msvcs_session_get_ext_handle((msvcs_session_t *)md_ctx->sc_session,
                    (uint8_t)plugin_id, (void **)&desc, NULL);
        } else if(md_ctx->sc_flags & MSVCS_CTX_FLAGS_DIR_REVERSE) {
            msvcs_session_get_ext_handle((msvcs_session_t *)md_ctx->sc_session,
                    (uint8_t)plugin_id, NULL, (void **)&desc);
        } else {
            // should never happen
            DLOG(LOG_ALERT, "%s: Direction of packet is not defined.");
        return MSVCS_ST_PKT_FORWARD;

The code also handles the other basic data events.

Notice that the plugin uses jbuf APIs only to find the IP header and discover the protocol. You still use the pullup_bytes() function to get contiguous data, but you no longer need to perform complex manipulations of the data in the jbuf.

2007-2009 Juniper Networks, Inc. All rights reserved. The information contained herein is confidential information of Juniper Networks, Inc., and may not be used, disclosed, distributed, modified, or copied without the prior written consent of Juniper Networks, Inc. in an express license. This information is subject to change by Juniper Networks, Inc. Juniper Networks, the Juniper Networks logo, and JUNOS are registered trademarks of Juniper Networks, Inc. in the United States and other countries. All other trademarks, service marks, registered trademarks, or registered service marks are the property of their respective owners.
Generated on Sun May 30 20:26:47 2010 for Juniper Networks Partner Solution Development Platform JUNOS SDK 10.2R1 by Doxygen 1.4.5