DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::dpdklibs::arp Namespace Reference

Enumerations

enum  {
  ARP_REQUEST = 1 , ARP_REPLY = 2 , RARP_REQUEST = 3 , RARP_REPLY = 4 ,
  GRATUITOUS_ARP = 5
}
enum  { CLEAR_FAST_ALLOC_FLAG = 0x00000001 , DO_TX_FLUSH = 0x00000002 }

Functions

void uint16Swap (void *t, void *f)
void ethAddrSwap (void *t, void *f)
void inetAddrSwap (void *t, void *f)
void inetAddrCopy (void *t, void *f)
void pktgen_send_garp (struct rte_mbuf *m, uint32_t port_id, rte_be32_t binary_ip_address)
void pktgen_process_arp (struct rte_mbuf *m, uint32_t pid, rte_be32_t binary_ip_address)
void hex_digits_to_stream (std::ostringstream &ostrs, int value, char separator=':', char fill='0', int digits=2)

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
CLEAR_FAST_ALLOC_FLAG 
DO_TX_FLUSH 

Definition at line 30 of file ARP.hpp.

31{
32 CLEAR_FAST_ALLOC_FLAG = 0x00000001, // < Clear the TX fast alloc flag
33 DO_TX_FLUSH = 0x00000002 // Do a TX Flush by sending all of the pkts in the queue
34};

◆ anonymous enum

anonymous enum
Enumerator
ARP_REQUEST 
ARP_REPLY 
RARP_REQUEST 
RARP_REPLY 
GRATUITOUS_ARP 

Definition at line 20 of file ARP.hpp.

Function Documentation

◆ ethAddrSwap()

void dunedaq::dpdklibs::arp::ethAddrSwap ( void * t,
void * f )
inline

Definition at line 50 of file ARP.hpp.

51{
52 uint16_t* d = (uint16_t*)t;
53 uint16_t* s = (uint16_t*)f;
54 uint16Swap(d++, s++);
55 uint16Swap(d++, s++);
56 uint16Swap(d, s);
57}
void uint16Swap(void *t, void *f)
Definition ARP.hpp:38

◆ hex_digits_to_stream()

void dunedaq::dpdklibs::arp::hex_digits_to_stream ( std::ostringstream & ostrs,
int value,
char separator = ':',
char fill = '0',
int digits = 2 )
inline

Definition at line 72 of file ARP.cpp.

72 :', char fill = '0', int digits = 2)
73{
74 ostrs << std::setfill(fill) << std::setw(digits) << std::hex << value << std::dec << separator;
75}

◆ inetAddrCopy()

void dunedaq::dpdklibs::arp::inetAddrCopy ( void * t,
void * f )
inline

Definition at line 73 of file ARP.hpp.

74{
75 uint32_t* d = (uint32_t*)t;
76 uint32_t* s = (uint32_t*)f;
77
78 *d = *s;
79}

◆ inetAddrSwap()

void dunedaq::dpdklibs::arp::inetAddrSwap ( void * t,
void * f )
inline

Definition at line 61 of file ARP.hpp.

62{
63 uint32_t* d = (uint32_t*)t;
64 uint32_t* s = (uint32_t*)f;
65 uint32_t v;
66 v = *d;
67 *d = *s;
68 *s = v;
69}
default char v[0]

◆ pktgen_process_arp()

void dunedaq::dpdklibs::arp::pktgen_process_arp ( struct rte_mbuf * m,
uint32_t pid,
rte_be32_t binary_ip_address )

Definition at line 78 of file ARP.cpp.

79{
80 struct rte_ether_hdr* eth = rte_pktmbuf_mtod(m, struct rte_ether_hdr*);
81 struct rte_arp_hdr* arp = (struct rte_arp_hdr*)&eth[1];
82
83 if (arp->arp_opcode == rte_cpu_to_be_16(RTE_ARP_OP_REQUEST)) {
84 arp->arp_opcode = rte_cpu_to_be_16(RTE_ARP_OP_REPLY);
85
86 /* Grab the source MAC addresses */
87 struct rte_ether_addr mac_addr;
88 rte_eth_macaddr_get(port_id, &mac_addr);
89
91 dunedaq::dpdklibs::udp::ip_address_binary_to_dotdecimal(rte_be_to_cpu_32(arp->arp_data.arp_sip)));
93 dunedaq::dpdklibs::udp::ip_address_binary_to_dotdecimal(rte_be_to_cpu_32(arp->arp_data.arp_tip)));
96
97 TLOG_DEBUG(10) << "ARP SRC IP: " << srcaddr;
98 TLOG_DEBUG(10) << "ARP DEST IP: " << dstaddr;
99 TLOG_DEBUG(10) << "ARP LOCAL IP: " << localaddr;
100
101 // Bail out if not our ipaddress
102 if (arp->arp_data.arp_tip != ip_add_bin)
103 return;
104
105 TLOG_DEBUG(10) << "ARP Received " << dstaddr << " I'm the target " << localaddr << " (port id = " << port_id << ")";
106
107 /* Swap the two MAC addresses */
108 ethAddrSwap(&arp->arp_data.arp_sha, &arp->arp_data.arp_tha);
109
110 /* Swap the two IP addresses */
111 inetAddrSwap(&arp->arp_data.arp_tip, &arp->arp_data.arp_sip);
112
113 /* Set the packet to ARP reply */
114 arp->arp_opcode = htons(RTE_ARP_OP_REPLY);
115
116 /* Swap the MAC addresses */
117 ethAddrSwap(&eth->dst_addr, &eth->src_addr);
118
119 /* Copy in the MAC address for the reply. */
120 rte_memcpy(&arp->arp_data.arp_sha, &mac_addr, 6);
121 rte_memcpy(&eth->src_addr, &mac_addr, 6);
122
123 struct rte_mbuf* arp_tx_mbuf[1];
124 arp_tx_mbuf[0] = m;
125
126 rte_eth_tx_burst(port_id, 0, arp_tx_mbuf, 1);
127 TLOG_DEBUG(10) << "Sending ARP reply";
128
129 /* No need to free mbuf as it was reused */
130 return;
131 }
132}
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:116
void ethAddrSwap(void *t, void *f)
Definition ARP.hpp:50
void inetAddrSwap(void *t, void *f)
Definition ARP.hpp:61
std::string get_ipv4_decimal_addr_str(struct ipaddr ipv4_address)
Definition Utils.cpp:56
struct ipaddr ip_address_binary_to_dotdecimal(rte_le32_t binary_ipv4_address)
Definition Utils.cpp:48

◆ pktgen_send_garp()

void dunedaq::dpdklibs::arp::pktgen_send_garp ( struct rte_mbuf * m,
uint32_t port_id,
rte_be32_t binary_ip_address )

Definition at line 23 of file ARP.cpp.

24{
25 struct rte_ether_hdr* eth = rte_pktmbuf_mtod(m, struct rte_ether_hdr*);
26 struct rte_arp_hdr* arp = (struct rte_arp_hdr*)&eth[1];
27
28 /* src and dest addr */
29 memset(&eth->dst_addr, 0xFF, 6);
30 // MAC addr of port
31 struct rte_ether_addr mac_addr;
32 rte_eth_macaddr_get(port_id, &mac_addr);
33 rte_ether_addr_copy(&mac_addr, &eth->src_addr);
34 // Set ETH type
35 eth->ether_type = htons(RTE_ETHER_TYPE_ARP);
36
37 memset(arp, 0, sizeof(struct rte_arp_hdr));
38 rte_memcpy(&arp->arp_data.arp_sha, &mac_addr, 6);
39
40 inetAddrCopy(&arp->arp_data.arp_sip, &ip_add_bin);
41
42 rte_memcpy(&arp->arp_data.arp_tha, &mac_addr, 6);
43 inetAddrCopy(&arp->arp_data.arp_tip, &ip_add_bin);
44
45 /* Fill in the rest of the ARP packet header */
46 arp->arp_hardware = htons(RTE_ARP_HRD_ETHER);
47 arp->arp_protocol = htons(RTE_ETHER_TYPE_IPV4);
48 arp->arp_hlen = 6;
49 arp->arp_plen = 4;
50 arp->arp_opcode = htons(RTE_ARP_OP_REQUEST);
51
52 m->pkt_len = 60;
53 m->data_len = 60;
54
55 struct rte_mbuf* arp_tx_mbuf[1];
56 arp_tx_mbuf[0] = m;
57
59 dunedaq::dpdklibs::udp::ip_address_binary_to_dotdecimal(rte_be_to_cpu_32(arp->arp_data.arp_sip)));
61 dunedaq::dpdklibs::udp::ip_address_binary_to_dotdecimal(rte_be_to_cpu_32(arp->arp_data.arp_tip)));
64 TLOG_DEBUG(10) << "GARP SRC IP: " << srcaddr;
65 TLOG_DEBUG(10) << "GARP DEST IP: " << dstaddr;
66 TLOG_DEBUG(10) << "LOCAL IP: " << localaddr;
67
68 rte_eth_tx_burst(port_id, 0, arp_tx_mbuf, 1);
69}
void inetAddrCopy(void *t, void *f)
Definition ARP.hpp:73

◆ uint16Swap()

void dunedaq::dpdklibs::arp::uint16Swap ( void * t,
void * f )
inline

Definition at line 38 of file ARP.hpp.

39{
40 uint16_t* d = (uint16_t*)t;
41 uint16_t* s = (uint16_t*)f;
42 uint16_t v;
43 v = *d;
44 *d = *s;
45 *s = v;
46}