FastClick is a high-performance packet processing framework extending Click Modular Router with DPDK support, batching, flow management, and performance optimizations.
Basic DPDK build (recommended):
./configure CFLAGS="-O3" CXXFLAGS="-std=c++11 -O3" \
--enable-dpdk --enable-intel-cpu --disable-dynamic-linking \
--enable-bound-port-transfer --enable-flow \
--disable-task-stats --disable-cpu-load
makeFastClick "Light" (maximum performance):
./configure CFLAGS="-O3" CXXFLAGS="-std=c++11 -O3" \
--enable-dpdk --enable-intel-cpu --disable-dynamic-linking \
--enable-bound-port-transfer --enable-flow \
--disable-task-stats --disable-cpu-load \
--enable-dpdk-packet --disable-clone --disable-dpdk-softqueue
makeUser-level only (no DPDK):
./configure --enable-userlevel
make# User-level
./userlevel/click conf/myconfig.click
# Kernel module (deprecated for most uses)
sudo click-install conf/myconfig.clickcd test
./clicktest standard/*.clicktest
./clicktest -j4 standard/*.clicktest # parallel executionelements/- Element implementations organized by categorystandard/- Core elements (Queue, Discard, Tee, etc.)ip/- IP processing (IPRateMonitor, IPFragmenter, etc.)flow/- Flow-based elements (MiddleClick)userlevel/- DPDK elements (FromDPDKDevice, ToDPDKDevice)tcpudp/- TCP/UDP processing
include/click/- Public API headerselement.hh- Base Element classpacket.hh- Packet abstractionbatchelement.hh- Batching supportflow/- Flow subsystem headers
lib/- Core implementation (router, packet, element lifecycle)userlevel/- User-space driverlinuxmodule/- Linux kernel module (deprecated, use user-level)conf/- Example configurationstest/- Test infrastructure and test files
Every element needs a header (.hh) and implementation (.cc):
Header (elements/mypackage/myelement.hh):
#ifndef CLICK_MYELEMENT_HH
#define CLICK_MYELEMENT_HH
#include <click/batchelement.hh>
CLICK_DECLS
class MyElement : public BatchElement {
public:
MyElement() CLICK_COLD;
// Required metadata methods
const char *class_name() const override { return "MyElement"; }
const char *port_count() const override { return "1/1"; } // inputs/outputs
const char *processing() const override { return PUSH; }
// Lifecycle
int configure(Vector<String> &conf, ErrorHandler *errh) override;
int initialize(ErrorHandler *errh) override;
void cleanup(CleanupStage stage) override;
// Processing (implement at least one)
void push(int port, Packet *p) override;
#if HAVE_BATCH
void push_batch(int port, PacketBatch *batch) override;
#endif
private:
bool _active;
uint64_t _count;
};
CLICK_ENDDECLS
#endifImplementation (elements/mypackage/myelement.cc):
#include <click/config.h>
#include "myelement.hh"
#include <click/args.hh>
CLICK_DECLS
MyElement::MyElement() : _active(true), _count(0) { }
int MyElement::configure(Vector<String> &conf, ErrorHandler *errh) {
return Args(conf, this, errh)
.read_mp("REQUIRED_ARG", _var) // mandatory positional
.read_p("OPTIONAL_ARG", _opt) // optional positional
.read("KEYWORD", _keyword) // keyword argument
.complete();
}
void MyElement::push(int, Packet *p) {
_count++;
// Process packet
output(0).push(p);
}
#if HAVE_BATCH
void MyElement::push_batch(int, PacketBatch *batch) {
EXECUTE_FOR_EACH_PACKET(simple_action, batch);
output_push_batch(0, batch);
}
#endif
CLICK_ENDDECLS
EXPORT_ELEMENT(MyElement) // Register element
ELEMENT_MT_SAFE(MyElement) // Mark as thread-safe (if applicable)Port count format: "inputs/outputs" or "inputs-max_inputs/outputs-max_outputs"
"1/1"- exactly 1 input, 1 output"1-/1-"- at least 1 input/output, unlimitedPORTS_1_1- constant for"1/1"
Processing modes:
PUSH- push-only processingPULL- pull-only processingAGNOSTIC- can work in push or pullPROCESSING_A_AH- agnostic with additional hints
Batching macros:
FOR_EACH_PACKET(batch, p) { /* process p */ }
FOR_EACH_PACKET_SAFE(batch, p) { /* can modify batch structure for previous and current packet */ }
EXECUTE_FOR_EACH_PACKET(function, batch) //Function is called for each packet of the batch. The batch can't be modified
EXECUTE_FOR_EACH_PACKET_DROPPABLE(function, batch, on_drop) //Same but if function returns 0, then on_drop is called with the original packet- C++11 minimum (use
-std=c++11or-std=gnu++11) - C++14 for PacketMill (
-std=gnu++14) - Supports GCC and Clang
- Classes:
PascalCase(e.g.,IPRateMonitor,FromDPDKDevice) - Methods:
snake_case(e.g.,class_name(),push_batch()) - Private members:
_underscore_prefix(e.g.,_count,_active) - Macros:
UPPER_CASE(e.g.,CLICK_DECLS,HAVE_BATCH)
Header guards:
#ifndef CLICK_ELEMENTNAME_HH
#define CLICK_ELEMENTNAME_HH
// ... code ...
#endifNamespace declarations:
CLICK_DECLS
// ... declarations ...
CLICK_ENDDECLSLogging:
click_chatter("Debug message: %d", value);Error handling:
int MyElement::configure(Vector<String> &conf, ErrorHandler *errh) {
if (bad_config)
return errh->error("Invalid configuration");
errh->warning("Non-fatal warning");
return 0; // success
}Packet memory management:
p->kill(); // destroy packet
batch->fast_kill(); // batch destroy with atomic counter
batch->fast_kill_nonatomic(); // faster if single-threadedFromDPDKDevice- Receive packets from DPDK portToDPDKDevice- Send packets to DPDK portEnsureDPDKBuffer- Convert packets to DPDK buffersDPDKInfo- Query DPDK device information
// Multi-queue RSS (auto-assign threads)
FromDPDKDevice(0)
-> ... processing ...
-> ToDPDKDevice(1);PORT- DPDK port IDQUEUE- RX/TX queue IDN_QUEUES- Number of queues (-1 = one per thread)BURST- Max packets per batch (default: 32)PROMISC- Promiscuous mode (default: true)NDESC- Number of descriptors per queue
Flow support enables stateful packet processing with automatic flow tracking.
CTXManager/FlowIPManager_DPDK- Flow classification and state managementFlowIPNAT- Stateful NATFlowIPLoadBalancer- Per-flow load balancingFlowCounter- Per-flow countersFlowRateLimiter- Per-flow rate limitingTCPReorder- TCP stream reassembly
FromDPDKDevice(0)
-> CTXManager(BUILDER 1, CACHESIZE 65536)
-> FlowIPNAT(SIP 10.0.0.1)
-> ToDPDKDevice(1);./configure --enable-flow --enable-ctx --enable-batchNote: --enable-flow requires --enable-batch
- Enabled with
--enable-batch(required for flows) - Use
BatchElementbase class - Implement
push_batch()/pull_batch()methods - Reduces per-packet overhead significantly
- NIC-driven thread scheduler
- Automatically scales active threads based on load
- Element:
DeviceBalancer(METHOD rsspp) - Requires
--enable-dpdkand RSS support
- Generates optimized binaries by embedding configuration constants
- Enables:
--enable-dpdk-packet --disable-clone --disable-dpdk-softqueue - Use
click-devirtualizetool for specialization
- DPDK not found: Install dependencies with
./deps.shor manually install libelf-dev, libnuma-dev - Flow requires batch: Always enable
--enable-batchbefore--enable-flow - DPDK buffer conversion: Use
EnsureDPDKBufferbeforeToDPDKDevicewhen processing non-DPDK packets - Thread safety: Mark elements with
ELEMENT_MT_SAFE()only if truly thread-safe - Batch processing: Remember to call
batch->fast_kill()instead of killing packets individually - Configuration parsing: Always use
Argsclass, not manual parsing - Memory leaks: Always call
p->kill()or pass packets to output ports - Kernel module: Prefer user-level with DPDK over kernel module for modern deployments
Click configurations are directed graphs where elements are nodes and connections are edges.
Basic syntax:
// Element declaration
elem :: ElementName(PARAM value);
// Direct connection
Source -> Sink;
// Named port selection
elem[0] -> output_zero;
elem[1] -> output_one;
// Multi-output (duplicates)
Source -> Tee(2) -> [0]Path1; [1]Path2;Example configuration:
// Generator -> Classifier -> Counter -> Discard
InfiniteSource(LENGTH 64, LIMIT 1000000)
-> c :: Classifier(12/0806, -); // ARP classifier
c[0] -> counter0 :: Counter -> Discard; // ARP packets
c[1] -> counter1 :: Counter -> Discard; // Other packets- Wiki: https://github.com/tbarbette/fastclick/wiki
- Original Click Manual: http://read.cs.ucla.edu/click/
- Lost of all elements: https://github.com/tbarbette/fastclick/wiki/Elements
- Tool documentation:
doc/*.mdand inline in element source - DPDK documentation: http://doc.dpdk.org/
- README.md - Project overview and quick start
- INSTALL.md - Detailed installation instructions
- README.middleclick.md - Flow/session support details
- README.packetmill.md - Binary specialization
- conf/README.md - Example configurations
- High-Speed I/O Wiki - DPDK and Netmap setup
- GitHub Discussions - Community support
This file helps AI coding agents understand FastClick conventions and be productive immediately. For detailed feature documentation, see the linked resources above.