#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
};
static struct mcast_group_params mcast_group_table[] = {
- {RTE_IPv4(224,0,0,101), 0x1},
- {RTE_IPv4(224,0,0,102), 0x2},
- {RTE_IPv4(224,0,0,103), 0x3},
- {RTE_IPv4(224,0,0,104), 0x4},
- {RTE_IPv4(224,0,0,105), 0x5},
- {RTE_IPv4(224,0,0,106), 0x6},
- {RTE_IPv4(224,0,0,107), 0x7},
- {RTE_IPv4(224,0,0,108), 0x8},
- {RTE_IPv4(224,0,0,109), 0x9},
- {RTE_IPv4(224,0,0,110), 0xA},
- {RTE_IPv4(224,0,0,111), 0xB},
- {RTE_IPv4(224,0,0,112), 0xC},
- {RTE_IPv4(224,0,0,113), 0xD},
- {RTE_IPv4(224,0,0,114), 0xE},
- {RTE_IPv4(224,0,0,115), 0xF},
+ {RTE_IPV4(224,0,0,101), 0x1},
+ {RTE_IPV4(224,0,0,102), 0x2},
+ {RTE_IPV4(224,0,0,103), 0x3},
+ {RTE_IPV4(224,0,0,104), 0x4},
+ {RTE_IPV4(224,0,0,105), 0x5},
+ {RTE_IPV4(224,0,0,106), 0x6},
+ {RTE_IPV4(224,0,0,107), 0x7},
+ {RTE_IPV4(224,0,0,108), 0x8},
+ {RTE_IPV4(224,0,0,109), 0x9},
+ {RTE_IPV4(224,0,0,110), 0xA},
+ {RTE_IPV4(224,0,0,111), 0xB},
+ {RTE_IPV4(224,0,0,112), 0xC},
+ {RTE_IPV4(224,0,0,113), 0xD},
+ {RTE_IPV4(224,0,0,114), 0xE},
+ {RTE_IPV4(224,0,0,115), 0xF},
};
-#define N_MCAST_GROUPS \
- (sizeof (mcast_group_table) / sizeof (mcast_group_table[0]))
-
-
/* Send burst of packets on an output interface */
static void
send_burst(struct lcore_queue_conf *qconf, uint16_t port)
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);
- ethdr->ether_type = rte_be_to_cpu_16(RTE_ETHER_TYPE_IPv4);
+ 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 */
len = qconf->tx_mbufs[port].len;
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 -1;
}
- for (i = 0; i < N_MCAST_GROUPS; i ++){
+ for (i = 0; i < RTE_DIM(mcast_group_table); i++) {
if (rte_fbk_hash_add_key(mcast_hash,
mcast_group_table[i].ip,
mcast_group_table[i].port_mask) < 0) {
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
uint16_t portid;
uint8_t count, all_ports_up, print_flag = 0;
struct rte_eth_link link;
+ int ret;
+ char link_status_text[RTE_ETH_LINK_MAX_STR_LEN];
printf("\nChecking link status");
fflush(stdout);
if ((port_mask & (1 << portid)) == 0)
continue;
memset(&link, 0, sizeof(link));
- rte_eth_link_get_nowait(portid, &link);
+ ret = rte_eth_link_get_nowait(portid, &link);
+ if (ret < 0) {
+ all_ports_up = 0;
+ if (print_flag == 1)
+ printf("Port %u link get failed: %s\n",
+ portid, rte_strerror(-ret));
+ continue;
+ }
/* print link status if flag set */
if (print_flag == 1) {
- if (link.link_status)
- printf(
- "Port%d Link Up. Speed %u Mbps - %s\n",
- portid, link.link_speed,
- (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
- ("full-duplex") : ("half-duplex\n"));
- else
- printf("Port %d Link Down\n", portid);
+ rte_eth_link_to_str(link_status_text,
+ sizeof(link_status_text),
+ &link);
+ printf("Port %d %s\n", portid,
+ link_status_text);
continue;
}
/* clear all_ports_up flag if any link down */
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)
qconf = &lcore_queue_conf[rx_lcore_id];
/* limit the frame size to the maximum supported by NIC */
- rte_eth_dev_info_get(portid, &dev_info);
+ ret = rte_eth_dev_info_get(portid, &dev_info);
+ if (ret != 0)
+ rte_exit(EXIT_FAILURE,
+ "Error during getting device (port %u) info: %s\n",
+ portid, strerror(-ret));
+
local_port_conf.rxmode.max_rx_pkt_len = RTE_MIN(
dev_info.max_rx_pktlen,
local_port_conf.rxmode.max_rx_pkt_len);
"Cannot adjust number of descriptors: err=%d, port=%d\n",
ret, portid);
- rte_eth_macaddr_get(portid, &ports_eth_addr[portid]);
+ ret = rte_eth_macaddr_get(portid, &ports_eth_addr[portid]);
+ if (ret < 0)
+ rte_exit(EXIT_FAILURE,
+ "Cannot get MAC address: err=%d, port=%d\n",
+ ret, portid);
+
print_ethaddr(" Address:", &ports_eth_addr[portid]);
printf(", ");
qconf->tx_queue_id[portid] = queueid;
queueid++;
}
- rte_eth_allmulticast_enable(portid);
+ ret = rte_eth_allmulticast_enable(portid);
+ if (ret < 0)
+ rte_exit(EXIT_FAILURE,
+ "rte_eth_allmulticast_enable: err=%d, port=%d\n",
+ ret, portid);
/* Start device */
ret = rte_eth_dev_start(portid);
if (ret < 0)
rte_exit(EXIT_FAILURE, "Cannot build the multicast hash\n");
/* launch per-lcore init on every lcore */
- rte_eal_mp_remote_launch(main_loop, NULL, CALL_MASTER);
- RTE_LCORE_FOREACH_SLAVE(lcore_id) {
+ rte_eal_mp_remote_launch(main_loop, NULL, CALL_MAIN);
+ RTE_LCORE_FOREACH_WORKER(lcore_id) {
if (rte_eal_wait_lcore(lcore_id) < 0)
return -1;
}
+ /* clean up the EAL */
+ rte_eal_cleanup();
+
return 0;
}