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
ARP_REQUEST 
ARP_REPLY 
RARP_REQUEST 
RARP_REPLY 
GRATUITOUS_ARP 

Definition at line 20 of file ARP.hpp.

◆ anonymous enum

anonymous enum
Enumerator
CLEAR_FAST_ALLOC_FLAG 
DO_TX_FLUSH 

Definition at line 29 of file ARP.hpp.

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

Function Documentation

◆ ethAddrSwap()

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

Definition at line 47 of file ARP.hpp.

47 {
48 uint16_t *d = (uint16_t *)t;
49 uint16_t *s = (uint16_t *)f;
50 uint16Swap(d++, s++);
51 uint16Swap(d++, s++);
52 uint16Swap(d, s);
53}
void uint16Swap(void *t, void *f)
Definition ARP.hpp:36

◆ 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 71 of file ARP.cpp.

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

◆ inetAddrCopy()

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

Definition at line 68 of file ARP.hpp.

68 {
69 uint32_t *d = (uint32_t *)t;
70 uint32_t *s = (uint32_t *)f;
71
72 *d = *s;
73}

◆ inetAddrSwap()

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

Definition at line 57 of file ARP.hpp.

57 {
58 uint32_t *d = (uint32_t *)t;
59 uint32_t *s = (uint32_t *)f;
60 uint32_t v;
61 v = *d;
62 *d = *s;
63 *s = v;
64}

◆ 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 77 of file ARP.cpp.

78{
79 struct rte_ether_hdr *eth = rte_pktmbuf_mtod(m, struct rte_ether_hdr *);
80 struct rte_arp_hdr *arp = (struct rte_arp_hdr *)&eth[1];
81
82 if (arp->arp_opcode == rte_cpu_to_be_16(RTE_ARP_OP_REQUEST)) {
83 arp->arp_opcode = rte_cpu_to_be_16(RTE_ARP_OP_REPLY);
84
85
86 /* Grab the source MAC addresses */
87 struct rte_ether_addr mac_addr;
88 rte_eth_macaddr_get(port_id, &mac_addr);
89
90 std::string srcaddr = dunedaq::dpdklibs::udp::get_ipv4_decimal_addr_str(dunedaq::dpdklibs::udp::ip_address_binary_to_dotdecimal(rte_be_to_cpu_32(arp->arp_data.arp_sip)));
91 TLOG_DEBUG(10) << "SRC IP: " << srcaddr;
92 std::string dstaddr = dunedaq::dpdklibs::udp::get_ipv4_decimal_addr_str(dunedaq::dpdklibs::udp::ip_address_binary_to_dotdecimal(rte_be_to_cpu_32(arp->arp_data.arp_tip)));
93 TLOG_DEBUG(10) << "DEST IP: " << dstaddr;
95 TLOG_DEBUG(10) << "LOCAL IP: " << localaddr;
96
97 // Bail out if not our ipaddress
98 if ( arp->arp_data.arp_tip != ip_add_bin) return;
99
100 TLOG_DEBUG(10) << "ARP Received " << dstaddr << " I'm the target " << localaddr;
101
102 /* Swap the two MAC addresses */
103 ethAddrSwap(&arp->arp_data.arp_sha, &arp->arp_data.arp_tha);
104
105 /* Swap the two IP addresses */
106 inetAddrSwap(&arp->arp_data.arp_tip, &arp->arp_data.arp_sip);
107
108 /* Set the packet to ARP reply */
109 arp->arp_opcode = htons(RTE_ARP_OP_REPLY);
110
111 /* Swap the MAC addresses */
112 ethAddrSwap(&eth->dst_addr, &eth->src_addr);
113
114 /* Copy in the MAC address for the reply. */
115 rte_memcpy(&arp->arp_data.arp_sha, &mac_addr, 6);
116 rte_memcpy(&eth->src_addr, &mac_addr, 6);
117
118 struct rte_mbuf *arp_tx_mbuf[1];
119 arp_tx_mbuf[0] = m;
120
121 rte_eth_tx_burst(port_id, 0, arp_tx_mbuf, 1);
122 TLOG_DEBUG(10) << "Sending ARP reply";
123
124 /* No need to free mbuf as it was reused */
125 return;
126 }
127}
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
void ethAddrSwap(void *t, void *f)
Definition ARP.hpp:47
void inetAddrSwap(void *t, void *f)
Definition ARP.hpp:57
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
38 memset(arp, 0, sizeof(struct rte_arp_hdr));
39 rte_memcpy(&arp->arp_data.arp_sha, &mac_addr, 6);
40
41 uint32_t addr = htonl(ip_add_bin);
42 inetAddrCopy(&arp->arp_data.arp_sip, &addr);
43
44 //if (likely(type == GRATUITOUS_ARP) ) {
45 rte_memcpy(&arp->arp_data.arp_tha, &mac_addr, 6);
46 inetAddrCopy(&arp->arp_data.arp_tip, &addr);
47 //} else {
48 // memset(&arp->arp_data.arp_tha, 0, 6);
49 // addr = htonl(pkt->ip_dst_addr.addr.ipv4.s_addr);
50 // inetAddrCopy(&arp->arp_data.arp_tip, &addr);
51 //}
52
53 /* Fill in the rest of the ARP packet header */
54 arp->arp_hardware = htons(RTE_ARP_HRD_ETHER);
55 arp->arp_protocol = htons(RTE_ETHER_TYPE_IPV4);
56 arp->arp_hlen = 6;
57 arp->arp_plen = 4;
58 arp->arp_opcode = htons(RTE_ARP_OP_REQUEST);
59
60 m->pkt_len = 60;
61 m->data_len = 60;
62
63 struct rte_mbuf *arp_tx_mbuf[1];
64 arp_tx_mbuf[0] = m;
65 rte_eth_tx_burst(port_id, 0, arp_tx_mbuf, 1);
66 //printf("Sending ARP reply\n");
67}
void inetAddrCopy(void *t, void *f)
Definition ARP.hpp:68

◆ uint16Swap()

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

Definition at line 36 of file ARP.hpp.

36 {
37 uint16_t *d = (uint16_t *)t;
38 uint16_t *s = (uint16_t *)f;
39 uint16_t v;
40 v = *d;
41 *d = *s;
42 *s = v;
43}