Layer 4 DataScripts


Starting with Avi Vantage release 18.2.3, DataScript support for inspecting L4 headers and performing load balancing, persistence, logging, and more based on the header data has been provided.

The DataScript scripting language is built upon an embedded Lua interpreter, with additional Avi-specific libraries added to extend the power.  The basic DataScript syntax is based on Lua, with additional commands, called functions, available for Avi-specific tasks.  For in-depth help on Lua scripting syntax and usage, see

DataScripts are executed within the data plane on the Avi Service Engines hosting the virtual service to which the DataScript has been attached. DataScript is different than ControlScript, which is a Python-based scripting tool for automation of the control plane and executed from the Avi Controller.

A DataScript will typically be in some form of if/then logic, similar to a policy’s match/action logic.


In Avi Vantage release 18.2.3, the DataScripts service for two events:


First packet from the client will be subjected to the DataScript with event VS_DATASCRIPT_EVT_L4_REQUEST . Subsequent packets from the client in the same flow will be forwarded to the same server using load balancing mechanism to the same server and not subject to DataScript.

In Avi Vantage release 18.2.3, only the APIs avi.vs.table* and avi.vs.log are supported for VS_DATASCRIPT_EVT_L4_RESPONSE event. avi.vs.table* is applicable only in Avi Vantage release 18.2.3.


  • Early access support to layer 4 DataScripts is provided in Avi Vantage release 18.2.3. This version should be used in non-production environments only.
  • Layer 4 DataScripts are production-ready and available for deployment starting with Avi Vantage release 18.2.5.

Layer 4 DataScript Functions

The following layer 4 DataScript functions are available:

String Description Read the payload from the socket buffer
avi.l4.collect() Gather the num_bytes before subjecting the payload to the DataScript.
avi.vs.log() Log the passed message to the connection log
avi.vs.close_conn() Close the current TCP/UDP connection
avi.vs.client_port() Return the client's source port
avi.vs.client_ip() Return the string containing the client’s source ip
avi.vs.persist() Creates peristence entry using the key used after load balancing traffic
avi.vs.table_insert() Store the value in a key-value store for the key
avi.vs.table_remove() Remove a specified key-value pair from the data store for the specified key
avi.vs.table_lookup() Look up a key and return the corresponding value
avi.vs.table_refresh() Refresh the lifetime of the entry for the key in the key/value store
avi.pool.get_server_status() Determine the status of the server listening at a specified port Selects a pool or a specific server within a pool for the current request.

Note: The aforementioned APIs are not supported for IP groups, and string groups. Starting with Avi Vantage release 18.2.5, the DataScripts are supported for pool groups.