#include <rte_memcpy.h>
#include <rte_eal.h>
#include <rte_launch.h>
-#include <rte_atomic.h>
#include <rte_cycles.h>
#include <rte_prefetch.h>
#include <rte_lcore.h>
* by placing the low-order 23-bits of the IP address into the low-order
* 23 bits of the Ethernet multicast address 01-00-5E-00-00-00 (hex)."
*/
+
+/* Construct Ethernet multicast address from IPv4 multicast Address. 8< */
#define ETHER_ADDR_FOR_IPV4_MCAST(x) \
(rte_cpu_to_be_64(0x01005e000000ULL | ((x) & 0x7fffff)) >> 16)
+/* >8 End of Construction of multicast address from IPv4 multicast address. */
/*
* Configurable number of RX/TX ring descriptors
qconf->tx_mbufs[port].len = 0;
}
-/* Get number of bits set. */
+/* Get number of bits set. 8< */
static inline uint32_t
bitcnt(uint32_t v)
{
return n;
}
+/* >8 End of getting number of bits set. */
/**
* Create the output multicast packet based on the given input packet.
* - The pointer to the new outgoing packet.
* - NULL if operation failed.
*/
+
+/* mcast_out_pkt 8< */
static inline struct rte_mbuf *
mcast_out_pkt(struct rte_mbuf *pkt, int use_clone)
{
__rte_mbuf_sanity_check(hdr, 1);
return hdr;
}
+/* >8 End of mcast_out_kt. */
/*
* Write new Ethernet header to the outgoing packet,
* and put it into the outgoing queue for the given port.
*/
+
+/* Write new Ethernet header to outgoing packets. 8< */
static inline void
mcast_send_pkt(struct rte_mbuf *pkt, struct rte_ether_addr *dest_addr,
struct lcore_queue_conf *qconf, uint16_t port)
rte_pktmbuf_prepend(pkt, (uint16_t)sizeof(*ethdr));
RTE_ASSERT(ethdr != NULL);
- rte_ether_addr_copy(dest_addr, ðdr->d_addr);
- rte_ether_addr_copy(&ports_eth_addr[port], ðdr->s_addr);
+ rte_ether_addr_copy(dest_addr, ðdr->dst_addr);
+ rte_ether_addr_copy(&ports_eth_addr[port], ðdr->src_addr);
ethdr->ether_type = rte_be_to_cpu_16(RTE_ETHER_TYPE_IPV4);
/* Put new packet into the output queue */
if (unlikely(MAX_PKT_BURST == len))
send_burst(qconf, port);
}
+/* >8 End of writing new Ethernet headers. */
/* Multicast forward of the input packet */
static inline void
struct rte_ether_addr as_addr;
} dst_eth_addr;
- /* Remove the Ethernet header from the input packet */
+ /* Remove the Ethernet header from the input packet. 8< */
iphdr = (struct rte_ipv4_hdr *)
rte_pktmbuf_adj(m, (uint16_t)sizeof(struct rte_ether_hdr));
RTE_ASSERT(iphdr != NULL);
dest_addr = rte_be_to_cpu_32(iphdr->dst_addr);
+ /* >8 End of removing the Ethernet header from the input packet. */
/*
* Check that it is a valid multicast address and
* we have some active ports assigned to it.
*/
+
+ /* Check valid multicast address. 8< */
if (!RTE_IS_IPV4_MCAST(dest_addr) ||
(hash = rte_fbk_hash_lookup(mcast_hash, dest_addr)) <= 0 ||
(port_mask = hash & enabled_port_mask) == 0) {
rte_pktmbuf_free(m);
return;
}
+ /* >8 End of valid multicast address check. */
/* Calculate number of destination ports. */
port_num = bitcnt(port_mask);
- /* Should we use rte_pktmbuf_clone() or not. */
+ /* Should we use rte_pktmbuf_clone() or not. 8< */
use_clone = (port_num <= MCAST_CLONE_PORTS &&
m->nb_segs <= MCAST_CLONE_SEGS);
+ /* >8 End of using rte_pktmbuf_clone(). */
/* Mark all packet's segments as referenced port_num times */
if (use_clone == 0)
rte_pktmbuf_refcnt_update(m, (uint16_t)port_num);
- /* construct destination ethernet address */
+ /* Construct destination ethernet address. 8< */
dst_eth_addr.as_int = ETHER_ADDR_FOR_IPV4_MCAST(dest_addr);
+ /* >8 End of constructing destination ethernet address. */
+ /* Packets dispatched to destination ports. 8< */
for (port = 0; use_clone != port_mask; port_mask >>= 1, port++) {
/* Prepare output packet and send it out. */
rte_pktmbuf_free(m);
}
}
+ /* >8 End of packets dispatched to destination ports. */
/*
* If we making clone packets, then, for the last destination port,
printf("%s%s", name, buf);
}
+/* Hash object is created and loaded. 8< */
static int
init_mcast_hash(void)
{
return 0;
}
+/* >8 End of hash object is created and loaded. */
/* Check the link status of all ports in up to 9s, and print them finally */
static void
if (ret < 0)
rte_exit(EXIT_FAILURE, "Invalid IPV4_MULTICAST parameters\n");
- /* create the mbuf pools */
+ /* Create the mbuf pools. 8< */
packet_pool = rte_pktmbuf_pool_create("packet_pool", NB_PKT_MBUF, 32,
0, PKT_MBUF_DATA_SIZE, rte_socket_id());
if (clone_pool == NULL)
rte_exit(EXIT_FAILURE, "Cannot init clone mbuf pool\n");
+ /* >8 End of create mbuf pools. */
nb_ports = rte_eth_dev_count_avail();
if (nb_ports == 0)
return -1;
}
+ /* clean up the EAL */
+ rte_eal_cleanup();
+
return 0;
}