Send packets defined by ourselves with DPDK
[TOC]
How to send and receive dpdk packets?
We can do this by flowing three steps.
- Firstly, we should construct a dpdk-type packet struct.
- Then we can code by using dpdk-api to send them.
- At last we shoud also make a receiving program to get these packets.
Construct a packet
DPDK net head struct
- As we all know, we should using dpdk struct. For example, if we want to make a UDP packet, we should using Ether head,Ip head,and UDP head structs, which could be found in lib/librte_ehter/ and lib/librte_net/ folders.
/** |
- If we can using these structs correctly, it’s easy to get a packet
Using ether head struct.
- Generate a ether head as an example.
// we can using flowing codes to define a ether packet. |
Make a send program.
First we should know the mechanism of dpdk pkt sending.
- Initlize the runtime enviroment.
- Apply a mem-pool.
- Initlize the NIC ports. To get r/s queues, and locate memory to them.
- Define m_buf, and apply for mem from mem-pool.
- Write our pkt into m_buf.
- Move m_buf to tx queue.
- Send the pkt by using dpdk-api.
Now write this program
/*- |
Make a receive program
At the same case, we should know the machanism of receiving.
- Initlize the runtime enviroment.
- Apply a mem-pool.
- Initlize the NIC ports. To get r/s queues, and locate memory to them.
- Define m_buf, and apply for mem from mem-pool.
- Get pkt from NIC port to m_buf.
- Analyze the m_buf, and get the pkt;
- Print message in the pkt.
Now we get this program
/* |
Conclusion
I am studing dpdk, and this is just a example program by using eth head struct. I think it’s not a difficult thing to do the same effect on IP/UDP pkt head struct.
Actually, the idea of this program is to get a general understanding of dpdk send&receive machanism.
Let’s all, bye~