Commit e9e0d67e authored by Leonardo Lai's avatar Leonardo Lai

cleanup

parent 89fa8cef
......@@ -43,6 +43,7 @@ UDPDK_CORE_SRCS+= \
udpdk_globals.c \
udpdk_init.c \
udpdk_bind_table.c \
udpdk_monitor.c \
udpdk_poller.c \
udpdk_syscall.c \
......
......@@ -88,6 +88,7 @@ static inline bool btable_can_bind(struct in_addr ip, int port, int opts)
return can_bind;
}
/* Bind a socket to a (IP, port) pair */
int btable_add_binding(int s, struct in_addr ip, int port, int opts)
{
struct bind_info *b;
......@@ -129,7 +130,7 @@ void btable_del_binding(int s, int port) {
list_node_t *node;
list_iterator_t *it;
// Remove the binding from the lsit
// Remove the binding from the list
it = list_iterator_new(sock_bind_table[port], LIST_HEAD);
while ((node = list_iterator_next(it))) {
if (((struct bind_info *)(node->val))->sockfd == s) {
......
......@@ -25,6 +25,7 @@
#include "udpdk_args.h"
#include "udpdk_constants.h"
#include "udpdk_bind_table.h"
#include "udpdk_monitor.h"
#include "udpdk_poller.h"
#include "udpdk_types.h"
......@@ -63,7 +64,7 @@ static inline const char * get_exch_ring_name(unsigned id, enum exch_ring_func f
static int init_mbuf_pools(void)
{
const unsigned int num_mbufs_rx = NUM_RX_DESC_DEFAULT;
const unsigned int num_mbufs_tx = NUM_TX_DESC_DEFAULT; // TODO why sized like this?
const unsigned int num_mbufs_tx = NUM_TX_DESC_DEFAULT; // TODO size properly
const unsigned int num_mbufs_cache = 2 * MBUF_CACHE_SIZE;
const unsigned int num_mbufs = num_mbufs_rx + num_mbufs_tx + num_mbufs_cache;
const int socket = rte_socket_id();
......@@ -76,21 +77,21 @@ static int init_mbuf_pools(void)
}
tx_pktmbuf_pool = rte_pktmbuf_pool_create(PKTMBUF_POOL_TX_NAME, num_mbufs, MBUF_CACHE_SIZE, 0,
RTE_MBUF_DEFAULT_BUF_SIZE, socket); // used by the app (sendto) TODO size properly
RTE_MBUF_DEFAULT_BUF_SIZE, socket); // used by the app (sendto) // TODO size properly
if (tx_pktmbuf_pool == NULL) {
RTE_LOG(ERR, INIT, "Failed to allocate TX pool: %s\n", rte_strerror(rte_errno));
return -1;
}
tx_pktmbuf_direct_pool = rte_pktmbuf_pool_create(PKTMBUF_POOL_DIRECT_TX_NAME, num_mbufs, MBUF_CACHE_SIZE, 0,
RTE_MBUF_DEFAULT_BUF_SIZE, socket); // used by the poller TODO size properly
RTE_MBUF_DEFAULT_BUF_SIZE, socket); // used by the poller // TODO size properly
if (tx_pktmbuf_direct_pool == NULL) {
RTE_LOG(ERR, INIT, "Failed to allocate TX direct pool: %s\n", rte_strerror(rte_errno));
return -1;
}
tx_pktmbuf_indirect_pool = rte_pktmbuf_pool_create(PKTMBUF_POOL_INDIRECT_TX_NAME, num_mbufs, MBUF_CACHE_SIZE, 0,
RTE_MBUF_DEFAULT_BUF_SIZE, socket); // used by the poller TODO size properly
RTE_MBUF_DEFAULT_BUF_SIZE, socket); // used by the poller // TODO size properly
if (tx_pktmbuf_indirect_pool == NULL) {
RTE_LOG(ERR, INIT, "Failed to allocate TX indirect pool: %s\n", rte_strerror(rte_errno));
return -1;
......@@ -175,53 +176,6 @@ static int init_port(uint16_t port_num)
return 0;
}
static void check_port_link_status(uint16_t portid) {
#define CHECK_INTERVAL 100 // 100ms
#define MAX_CHECK_TIME 90 // how many times
uint8_t count, all_ports_up, print_flag = 0;
struct rte_eth_link link;
int ret;
RTE_LOG(INFO, INIT, "Checking link status of port %d.\n", portid);
for (count = 0; count <= MAX_CHECK_TIME; count++) {
all_ports_up = 1;
memset(&link, 0, sizeof(link));
ret = rte_eth_link_get_nowait(portid, &link);
if (ret < 0) {
all_ports_up = 0;
if (print_flag == 1)
RTE_LOG(WARNING, INIT, "Port %u link get failed: %s\n", portid, rte_strerror(-ret));
continue;
}
if (print_flag == 1) {
if (link.link_status) {
RTE_LOG(INFO, INIT, "Port %d Link Up - speed %u Mbps - %s\n", portid, (unsigned) link.link_speed,
(link.link_duplex == ETH_LINK_FULL_DUPLEX) ? ("full-duplex") : ("half-duplex\n"));
break;
} else {
RTE_LOG(INFO, INIT, "Port %d Link Down\n", (uint8_t) portid);
}
continue;
}
if (link.link_status == ETH_LINK_DOWN) {
all_ports_up = 0;
break;
}
if (print_flag == 1)
return;
if (all_ports_up == 0) {
printf(".");
fflush(stdout);
rte_delay_ms(CHECK_INTERVAL);
}
if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) {
print_flag = 1;
}
}
}
/* Initialize a shared memory region to contain descriptors for the exchange slots */
static int init_exch_memzone(void)
{
......
//
// Created by leoll2 on 11/05/20.
// Copyright (c) 2020 Leonardo Lai. All rights reserved.
//
#include <stdlib.h>
#include <unistd.h>
#include <rte_common.h>
#include <rte_eal.h>
#include <rte_errno.h>
#include <rte_ethdev.h>
#include <rte_log.h>
#include "udpdk_monitor.h"
#define RTE_LOGTYPE_MONITOR RTE_LOGTYPE_USER1
/* Show information about the current state of a DPDK port */
void check_port_link_status(uint16_t portid) {
#define CHECK_INTERVAL 100 // 100ms
#define MAX_CHECK_TIME 90 // how many times
uint8_t count, all_ports_up, print_flag = 0;
struct rte_eth_link link;
int ret;
RTE_LOG(INFO, MONITOR, "Checking link status of port %d.\n", portid);
for (count = 0; count <= MAX_CHECK_TIME; count++) {
all_ports_up = 1;
memset(&link, 0, sizeof(link));
ret = rte_eth_link_get_nowait(portid, &link);
if (ret < 0) {
all_ports_up = 0;
if (print_flag == 1)
RTE_LOG(WARNING, MONITOR, "Port %u link get failed: %s\n", portid, rte_strerror(-ret));
continue;
}
if (print_flag == 1) {
if (link.link_status) {
RTE_LOG(INFO, MONITOR, "Port %d Link Up - speed %u Mbps - %s\n", portid, (unsigned) link.link_speed,
(link.link_duplex == ETH_LINK_FULL_DUPLEX) ? ("full-duplex") : ("half-duplex\n"));
break;
} else {
RTE_LOG(INFO, MONITOR, "Port %d Link Down\n", (uint8_t) portid);
}
continue;
}
if (link.link_status == ETH_LINK_DOWN) {
all_ports_up = 0;
break;
}
if (print_flag == 1)
return;
if (all_ports_up == 0) {
printf(".");
fflush(stdout);
rte_delay_ms(CHECK_INTERVAL);
}
if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) {
print_flag = 1;
}
}
}
//
// Created by leoll2 on 11/05/20.
// Copyright (c) 2020 Leonardo Lai. All rights reserved.
//
#ifndef UDPDK_MONITOR_H
#define UDPDK_MONITOR_H
void check_port_link_status(uint16_t portid);
#endif // UDPDK_MONITOR_H
......@@ -27,6 +27,7 @@
enum exch_ring_func {EXCH_RING_RX, EXCH_RING_TX};
/* Descriptor for a binding of a socket to (IP, port) */
struct bind_info {
int sockfd; // socket fd of the (addr, port) pair
struct in_addr ip_addr; // IPv4 address associated to the socket
......@@ -35,20 +36,23 @@ struct bind_info {
bool closed; // mark this binding as closed
};
/* Descriptor of a socket (current state and options) */
struct exch_slot_info {
int used; // used by an open socket
int bound; // used by a socket that did 'bind'
int sockfd; // TODO redundant because it matches the slot index in this implementation
int sockfd; // NOTE: redundant atm because it matches the slot index in the current impl
int udp_port; // UDP port associated to the socket (only if bound)
struct in_addr ip_addr; // IPv4 address associated to the socket (only if bound)
int so_options; // socket options
} __rte_cache_aligned;
/* Descriptor of the zone in shared memory where packets are exchanged between app and poller */
struct exch_zone_info {
uint64_t n_zones_active;
struct exch_slot_info slots[NUM_SOCKETS_MAX];
};
/* Descriptor of the exchange zone queues and buffers for a socket */
struct exch_slot {
struct rte_ring *rx_q; // RX queue
struct rte_ring *tx_q; // TX queue
......@@ -56,6 +60,7 @@ struct exch_slot {
uint16_t rx_count; // current number of packets in the rx buffer
} __rte_cache_aligned;
/* Global configuration (parsed from file) */
typedef struct {
struct rte_ether_addr src_mac_addr;
struct rte_ether_addr dst_mac_addr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment