{"id":16161445,"url":"https://github.com/gamemann/the-dpdk-examples","last_synced_at":"2025-08-28T02:49:12.944Z","repository":{"id":92735866,"uuid":"430020388","full_name":"gamemann/The-DPDK-Examples","owner":"gamemann","description":"Program examples utilizing the DPDK. The DPDK is a kernel-bypass network library that allows for very fast network packet processing. This is great for (D)DoS mitigation and low-latency packet inspection, manipulation, and forwarding.","archived":false,"fork":false,"pushed_at":"2023-05-28T23:51:47.000Z","size":51,"stargazers_count":50,"open_issues_count":1,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T19:22:15.413Z","etag":null,"topics":["cyber","cyber-security","cybersecurity","data-plane","dpdk","dpdk-code","dpdk-examples","drop","fast","firewall","intel","low-level","networking","packet","processing","security","stats","udp"],"latest_commit_sha":null,"homepage":"https://deaconn.net/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gamemann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-20T05:48:39.000Z","updated_at":"2025-03-06T10:03:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"d2cbf197-eb53-4edd-8025-31899ea2213b","html_url":"https://github.com/gamemann/The-DPDK-Examples","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gamemann/The-DPDK-Examples","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gamemann%2FThe-DPDK-Examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gamemann%2FThe-DPDK-Examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gamemann%2FThe-DPDK-Examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gamemann%2FThe-DPDK-Examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gamemann","download_url":"https://codeload.github.com/gamemann/The-DPDK-Examples/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gamemann%2FThe-DPDK-Examples/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272424911,"owners_count":24932895,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-28T02:00:10.768Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cyber","cyber-security","cybersecurity","data-plane","dpdk","dpdk-code","dpdk-examples","drop","fast","firewall","intel","low-level","networking","packet","processing","security","stats","udp"],"created_at":"2024-10-10T02:25:17.026Z","updated_at":"2025-08-28T02:49:12.916Z","avatar_url":"https://github.com/gamemann.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# The DPDK Examples\n## Description\nA small repository I will be using to store my progress and test programs from [the DPDK](https://www.dpdk.org/), a kernel bypass library very useful for fast packet processing.\n\nThis repository uses my DPDK Common [project](https://github.com/gamemann/The-DPDK-Common) in an effort to make things simpler.\n\n**WARNING** - I am still adding more examples as time goes on and I need to test new functionality/methods.\n\n## Requirements\n* [The DPDK](https://dpdk.org) - Intel's Data Plane Development Kit which acts as a kernel bypass library which allows for fast network packet processing (one of the fastest libraries out there for packet processing).\n* [The DPDK Common](https://github.com/gamemann/The-DPDK-Common) - A project written by me aimed to make my DPDK projects simpler to setup/run.\n\n## Building The DPDK\nIf you want to build the DPDK using default options, the following should work assuming you have the requirements such as `ninja` and `meson`.\n\n```\ngit clone https://github.com/DPDK/dpdk.git\ncd dpdk/\nmeson build\ncd build\nninja\nsudo ninja install\nsudo ldconfig\n```\n\nAll needed header files from the DPDK will be stored inside of `/usr/local/include/`.\n\nYou may receive `ninja` and `meson` using the following.\n\n```\nsudo apt update\nsudo apt install python3 python3-pip\nsudo pip3 install meson # Pip3 is used because 'apt' has an outdated version of Meson usually.\nsudo apt install ninja-build\n```\n\n## Building The Source Files\nYou may use `git` and `make` to build the source files inside of this repository.\n\n```\ngit clone --recursive https://github.com/gamemann/The-DPDK-Examples.git\ncd The-DPDK-Examples/\nmake\n```\n\nExecutables will be built inside of the `build/` directory by default.\n\n## EAL Parameters\nAll DPDK applications in this repository supports DPDK's EAL paramters. These may be found [here](http://doc.dpdk.org/guides/linux_gsg/linux_eal_parameters.html).\n\nThis is useful for specifying the amount of l-cores and ports to configure for example.\n\n## Examples\n### Drop UDP Port 8080 (Tested And Working)\nIn this DPDK application, any packets arriving on UDP destination port 8080 will be dropped. Otherwise, if the packet's ethernet header type is IPv4 or VLAN, it will swap the source/destination MAC and IP addresses along with the UDP source/destination ports then send the packet out the TX path (basically forwarding the packet from where it came).\n\nIn additional to EAL parameters, the following is available specifically for this application.\n\n```\n-p --portmask =\u003e The port mask to configure (e.g. 0xFFFF).\n-P --portmap =\u003e The port map to configure (in '(x, y),(b,z)' format).\n-q --queues =\u003e The amount of RX and TX queues to setup per port (default and recommended value is 1).\n-x --promisc =\u003e Whether to enable promiscuous on all enabled ports.\n-s --stats =\u003e If specified, will print real-time packet counter stats to stdout.\n```\n\nHere's an example:\n\n```\n./dropudp8080 -l 0-1 -n 1 -- -q 1 -p 0xff -s\n```\n\n### Simple Layer 3 Forward (Tested And Working)\nIn this DPDK application, a simple routing hash table is created with the key being the destination IP address and the value being the MAC address to forward to.\n\nRoutes are read from the `/etc/l3fwd/routes.txt` file in the following format.\n\n```\n\u003cip address\u003e \u003cmac address in xx:xx:xx:xx:xx:xx\u003e\n```\n\nThe following is an example.\n\n```\n10.50.0.4 ae:21:14:4b:3a:6d\n10.50.0.5 d6:45:f3:b1:a4:3d\n```\n\nWhen a packet is processed, we ensure it is an IPv4 or VLAN packet (we offset the packet data by four bytes in this case so we can process the rest of the packet without issues). Afterwards, we perform a lookup with the destination IP being the key on the route hash table. If the lookup is successful, the source MAC address is replaced with the destination MAC address (packets will be going out the same port they arrive since we create a TX buffer and queue) and the destination MAC address is replaced with the MAC address the IP was assigned to from the routes file mentioned above. Otherwise, the packet is dropped and the packet dropped counter is incremented.\n\nIn additional to EAL parameters, the following is available specifically for this application.\n\n```\n-p --portmask =\u003e The port mask to configure (e.g. 0xFFFF).\n-P --portmap =\u003e The port map to configure (in '(x, y),(b,z)' format).\n-q --queues =\u003e The amount of RX and TX queues to setup per port (default and recommended value is 1).\n-x --promisc =\u003e Whether to enable promiscuous on all enabled ports.\n-s --stats =\u003e If specified, will print real-time packet counter stats to stdout.\n```\n\nHere's an example:\n\n```\n./simple_l3fwd -l 0-1 -n 1 -- -q 1 -p 0xff -s\n```\n\n### Rate Limit (Tested And Working)\nIn this application, if a source IP equals or exceeds the packets per second or bytes per second specified in the command line, the packets are dropped. Otherwise, the ethernet and IP addresses are swapped along with the TCP/UDP ports and the packet is forwarded back out the TX path.\n\nPacket stats are also included with the `-s` flag.\n\nThe following command line options are supported.\n\n```\n-p --portmask =\u003e The port mask to configure (e.g. 0xFFFF).\n-P --portmap =\u003e The port map to configure (in '(x, y),(b,z)' format).\n-q --queues =\u003e The amount of RX and TX queues to setup per port (default and recommended value is 1).\n-x --promisc =\u003e Whether to enable promiscuous on all enabled ports.\n-s --stats =\u003e If specified, will print real-time packet counter stats to stdout.\n--pps =\u003e The packets per second to limit each source IP to.\n--bps =\u003e The bytes per second to limit each source IP to.\n```\n\nHere's an example:\n\n```\n./ratelimit -l 0-1 -n 1 -- -q 1 -p 0xff -s\n```\n\n**NOTE** - This application supports LRU recyling via a custom function I made in the DPDK Common [project](https://github.com/gamemann/The-DPDK-Common), `check_and_del_lru_from_hash_table()`. Make sure to define `USE_HASH_TABLES` before including the DPDK Common header file when using this function.\n\n### Least Recently Used Test (Tested And Working)\nThis is a small application that implements a manual LRU method for hash tables. For a while I've been trying to get LRU tables to work from [these](http://code.dpdk.org/dpdk/latest/source/lib/table) libraries. However, I had zero success in actually getting the table initialized.\n\nTherefore, I decided to keep using [these](http://code.dpdk.org/dpdk/latest/source/lib/hash) libaries instead and implement my own LRU fuctionality. I basically use the `rte_hash_get_key_with_position()` function to retrieve the oldest key to delete. However, it appears the new entry is inserted at the position that was most recently deleted so you have to keep incrementing the position value up to the max entries of the table. With that said, once the position value exceeds the maximum table entries, you need to set it back to 0.\n\nNo command line options are needed, but EAL parameters are still supported. Though, they won't make a difference.\n\nHere's an example:\n\n```\n./ratelimit\n```\n\n## Credits\n* [Christian Deacon](https://github.com/gamemann)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgamemann%2Fthe-dpdk-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgamemann%2Fthe-dpdk-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgamemann%2Fthe-dpdk-examples/lists"}