Use this example to create a bidirectional flow for IPv4 TCP packets.
The flow matcher configuration is set up with NTPL. While the supported types of flows are only limited by an upper limit to number of fields read from a package, this code snippet, and the following sections, will focus on setting up the flow manager for bi-directional IPv4 TCP traffic.
This snippet will set up the FPGA to count packets received on known/learned flows then drop them; it will direct packets received on unknown, or not learned, flows to stream ID 1; and finally it will direct packets to stream ID 0 in the rare case that the FPGA was too busy to perform the lookup.
To set up this flow manager the following NTPL commands are used:
- KeyType defines the number and size of fields used by the flow manager
- KeyDef defines the location and masks of the fields defined by KeyType
- Assign sets up filter and key tests based on KeyDef for the flow manager
KeyType[Name=kt] = {sw_32_32, sw_16_16} KeyDef[Name=kd; KeyType=kt; IpProtocolField=Outer] = (Layer3Header[12]/32/32, Layer4Header[0]/16/16) DefineMacro(\"LearnFilterCheck\", \"Port==$1 and Layer3Protocol==IPv4 and Layer4Protocol==TCP\") Assign[StreamId=1; Descriptor=DYN4, ColorBits=FlowID, Offset0=Layer3Header[12]; ColorMask=1] = LearnFilterCheck(0) and Key(kd, KeyID=1)==MISS Assign[StreamId=Drop; Descriptor=DYN4, ColorBits=FlowID, Offset0=Layer3Header[12]; ColorMask=1] = LearnFilterCheck(1) and Key(kd, KeyID=1, FieldAction=Swap)==MISS Assign[StreamId=0] = LearnFilterCheck(0) and Key(kd, KeyID=1)==UNHANDLED Assign[StreamId=0] = LearnFilterCheck(1) and Key(kd, KeyID=1, FieldAction=Swap)==UNHANDLED Assign[StreamId=Drop] = LearnFilterCheck(0) and Key(kd, KeyID=1, CounterSet=CSA)==4 Assign[StreamId=Drop] = LearnFilterCheck(1) and Key(kd, KeyID=1, CounterSet=CSB, FieldAction=Swap)==4