Filters are written in NTPL (Napatech programming language).
Filter resource
Filter resources are FPGA hardware resources that are allocated when an NTPL filter is created. And that there are only limited hardware resources available.
Applying NTPL
To apply NTPL commands, save any provided examples in a file and run the
ntpl tool as follows. For example, copy the following example and paste
in a file.
Delete=All Assign[StreamId=0] = Allwhere:
- Delete=All is for deleting all the previously applied filters.
- Assign[StreamId=0] = All configures the SmartNIC to capture all frames and to deliver to stream 0 in the host.
After saving the file, run the ntpl tool as
follows.
/opt/napatech/bin/ntpl -f test.ntplAn output example:
NTPL CMD: Delete=All NTPL ID: 0 NTPL CMD: Assign[StreamId=0] = All NTPL ID: 52For more information on the ntpl tool, see ntpl tool in DN-0449.
Note: NTPL commands can also be applied using NTAPI (the
NT_NTPL function) in the application. Refer to the code examples which are placed in
the /opt/napatech3/examples/ directory.
Filter resources
Filter resources are hardware resources in the SmartNIC that are allocated when an NTPL filter is created. However, there are limited hardware resources available.
The usage of filter resources can be queried from the SmartNIC using the
FilterInfo command as
follows.
/opt/napatech3/bin/ntpl -e "FilterInfo[Type=Info] = all"An output example:
... Filter Info Debug... ============================ adapter 0 ---------------------------- Categorizer Functions 4/64 Length Comparators 0/8 Data Extractors 2/4 Data Comparators 2/32 KmFunctions 4/32 KmTCAMBanks 8/12 KmCAMUsage(%) 1 KmTCAMUsage(%) 2The following items are shown in the output.
- Categorizer functions: Central filter resources in the SmartNIC. 64 filter resources are available.
- Length Comparators: Length filter resources. 8 comparators are available.
- Data Extractors: Data filter resources. 4 extractors are available, and each extractor is 32 bits.
- Data Comparators: Data filter resources. 32 comparators are available, and each comparator is 32 bits.
- KmCAMUsage: Content-addressable memory (CAM) usage for the exact value search of key match.
- KmTCAMUsage: Ternary content-addressable memory (TCAM) usage for the wild card search of key match. For more information on the CAM and the TCAM, see CAM and TCAM.
More detailed information can be queried using the following
command.
/opt/napatech3/bin/ntpl -e "FilterInfo[Type=Details] = all"For more information on the FilterInfo command, see FilterInfo Command in DN-0449.
Define command
Commonly
used fields, filters and macros can be defined using the Define command.
It is useful for simplifying filter expressions. In addition, definitions are reusable and
improve readability. See the following examples which define various protocol fields using
the Field
keyword.
// Define MAC address fields. Define DstMac = Field(StartOfFrame[0]/48) Define SrcMac = Field(StartOfFrame[6]/48) // Define fields for IPv4. Define SrcIPv4 = Field(Layer3Header[12]/32) Define DstIPv4 = Field(Layer3Header[16]/32) Define InnerSrcIPv4 = Field(InnerLayer3Header[12]/32) Define InnerDstIPv4 = Field(InnerLayer3Header[16]/32) // Define fields for UDP/TCP ports. Define SrcPort = Field(Layer4Header[0]/16) Define DstPort = Field(Layer4Header[2]/16)The following examples show defining various filter expressions using the Filter keyword.
// Define port filters. Define upstream = Filter(Port==0) Define downstream = Filter(Port==1) // Define UDP and TCP protocol filters. Define isUDP = Filter(Layer4Protocol==UDP) Define isTCP = Filter(Layer4Protocol==TCP) // Define IPv4 and IPv6 protocol filters. Define isIPv4 = Filter(Layer3Protocol==IPv4) Define isIPv6 = Filter(Layer3Protocol==IPv6)The Macro keyword instructs the compiler to replace all occurrences of macro names with the defined strings. Macros for data filters can be defined as follows.
// Define Macros for the label fields of the MPLS header. Define MPLS0_Value = Macro("Data[ProtOffset=FirstMPLS[0];DataType=ByteStr4;DataMask=[31:12]]") Define MPLS1_Value = Macro("Data[ProtOffset=FirstMPLS[4];DataType=ByteStr4;DataMask=[31:12]]") Define MPLS2_Value = Macro("Data[ProtOffset=FirstMPLS[8];DataType=ByteStr4;DataMask=[31:12]]")See More macro examples in DN-0449. For more information on the Define command, see Define Command in DN-0449.
Priority parameter
If multiple filters match a
frame, the highest priority filter is applied to the frame. Priority can be configured in
the Assign command as
follows.
// Capture IPv4 frames. Assign[StreamId=0; Priority=0] = Layer3Protocol==IPv4 // Capture the rest frames. Assign[StreamId=1; Priority=1] = AllThis example configures the SmartNIC to deliver IPv4 frames to stream 0 and the rest frames to stream 1. Supported values for the Priority parameter are 0 to 62 where 0 indicates the highest priority, and 62 indicates the lowest priority. Target frames are delivered to the corresponding streams as the first Assign command has the higher priority than the second Assign command in this example.
Priority is set to 0 by default if not specified. If multiple
Assign commands have the same priority, the last entered
Assign command gets the highest priority. See the following NTPL
example.
// Capture frames which are received on port 0. Assign[StreamId=0] = Layer3Protocol==IPv4 // Capture the rest frames. Assign[StreamId=1] = AllIn this example, priority is not specified. This means that Priority=0 is set for both Assign commands, and the second Assign command gets the highest priority. As a result, no frames are delivered to stream 0 because the second Assign command is applied to all the received frames including IPv4 frames.