diff options
| author | Qiuwen Lu <[email protected]> | 2016-06-17 19:23:57 +0800 |
|---|---|---|
| committer | Qiuwen Lu <[email protected]> | 2016-06-17 19:23:57 +0800 |
| commit | 8c0ad9913d10c3fa42bd1aedaa73e7968da0cba1 (patch) | |
| tree | 80271cc0ff21be9bce3608e8e6dca6b878d436a3 | |
| parent | b5e4f0f06042c6efc8880384c5433106bed2ba32 (diff) | |
增加了无故ARP定时发送的功能。v3.1.8-20160617
| -rw-r--r-- | worker/init.c | 2 | ||||
| -rw-r--r-- | worker/runtime.c | 61 | ||||
| -rw-r--r-- | worker/udpstack.c | 44 |
3 files changed, 80 insertions, 27 deletions
diff --git a/worker/init.c b/worker/init.c index c6efae0..34eab0f 100644 --- a/worker/init.c +++ b/worker/init.c @@ -73,6 +73,7 @@ #include <rte_tcp.h> #include <rte_lpm.h> #include <rte_version.h> +#include <rte_timer.h> #include "main.h" #include "nstat.h" @@ -580,5 +581,6 @@ void app_init(void) thmgr_init(); biz_rawio_init(); + rte_timer_subsystem_init(); printf("Initialization completed.\n"); } diff --git a/worker/runtime.c b/worker/runtime.c index 90a5b4f..fab2854 100644 --- a/worker/runtime.c +++ b/worker/runtime.c @@ -80,6 +80,7 @@ #include <rte_ip.h> #include <rte_tcp.h> #include <rte_udp.h> +#include <rte_timer.h> #include "main.h" #include "watchdog.h" @@ -245,7 +246,7 @@ app_lcore_worker_forward(struct app_lcore_params_worker * lp, struct rte_mbuf * extern int marsio_application_entry(struct rte_mbuf * mbuf); -static inline void app_lcore_worker(struct app_lcore_params_worker *lp, +static inline void mr_lcore_worker(struct app_lcore_params_worker *lp, uint32_t bsz_rd, uint32_t bsz_wr) { uint32_t i; @@ -365,20 +366,20 @@ static inline void app_lcore_worker(struct app_lcore_params_worker *lp, } static inline void -app_lcore_worker_flush(struct app_lcore_params_worker *lp) +mr_lcore_worker_flush(struct app_lcore_params_worker *lp) { - uint32_t port; - uint8_t lcore_id = rte_lcore_id(); - - for (port = 0; port < APP_MAX_NIC_PORTS; port ++) { - int ret; - if (unlikely(lp->rings_out[port] == NULL)) { + uint8_t lcore_id = rte_lcore_id(); + for (uint32_t port = 0; port < APP_MAX_NIC_PORTS; port ++) + { + int ret = 0; + if (unlikely(lp->rings_out[port] == NULL)) + { continue; } - if (likely((lp->mbuf_out_flush[port] == 0) || - (lp->mbuf_out[port].n_mbufs == 0))) { + if (likely((lp->mbuf_out_flush[port] == 0) || (lp->mbuf_out[port].n_mbufs == 0))) + { lp->mbuf_out_flush[port] = 1; continue; } @@ -386,10 +387,11 @@ app_lcore_worker_flush(struct app_lcore_params_worker *lp) ret = rte_ring_enqueue_bulk(lp->rings_out[port], (void **) lp->mbuf_out[port].array, lp->mbuf_out[port].n_mbufs); - if (unlikely(ret < 0)) { + if (unlikely(ret < 0)) + { nstat_client_count_wk_drop(lp->mbuf_out[port].array,lp->mbuf_out[port].n_mbufs,lcore_id); - uint32_t k; - for (k = 0; k < lp->mbuf_out[port].n_mbufs; k ++) { + for (uint32_t k = 0; k < lp->mbuf_out[port].n_mbufs; k++) + { struct rte_mbuf *pkt_to_free = lp->mbuf_out[port].array[k]; rte_pktmbuf_free(pkt_to_free); } @@ -400,24 +402,41 @@ app_lcore_worker_flush(struct app_lcore_params_worker *lp) } } +#define TIMER_RESOLUTION_CYCLES 20000000ULL /* around 10ms at 2 Ghz */ + static void app_lcore_main_loop_worker(void) { uint32_t lcore = rte_lcore_id(); struct app_lcore_params_worker *lp = &app.lcore_params[lcore].worker; - uint64_t i = 0; + uint64_t flush_count = 0; uint32_t bsz_rd = app.burst_size_worker_read; uint32_t bsz_wr = app.burst_size_worker_write; - for ( ; ; ) { - if (APP_LCORE_WORKER_FLUSH && (unlikely(i == APP_LCORE_WORKER_FLUSH))) { - app_lcore_worker_flush(lp); - i = 0; + // Timer Manager + uint64_t prev_tsc = 0; + uint64_t cur_tsc, diff_tsc; + + while(1) + { + if (unlikely(flush_count == APP_LCORE_WORKER_FLUSH)) + { + mr_lcore_worker_flush(lp); + flush_count = 0; } - app_lcore_worker(lp, bsz_rd, bsz_wr); - i ++; + mr_lcore_worker(lp, bsz_rd, bsz_wr); + flush_count++; + + cur_tsc = rte_rdtsc(); + diff_tsc = cur_tsc - prev_tsc; + + if(diff_tsc > TIMER_RESOLUTION_CYCLES) + { + rte_timer_manage(); + prev_tsc = cur_tsc; + } } } @@ -437,6 +456,6 @@ mr_lcore_main_loop(__attribute__((unused)) void *arg) (unsigned) lp->worker.worker_id); app_lcore_main_loop_worker(); } - + return 0; } diff --git a/worker/udpstack.c b/worker/udpstack.c index 24ecfc9..ecc4179 100644 --- a/worker/udpstack.c +++ b/worker/udpstack.c @@ -33,6 +33,7 @@ #include <arpa/inet.h> #include <assert.h> #include <MESA_prof_load.h> +#include <rte_timer.h> #include "udpstack.h" #include "main.h" @@ -1015,12 +1016,12 @@ INLINE static uint16_t select_random_sport(struct udpstack_fd * port_index[], ui for (finally_port = base_port; finally_port < port_max; finally_port++) { - if (port_index[finally_port] == NULL) return finally_port; + if (port_index[finally_port] == NULL) return rte_cpu_to_be_16(finally_port); } for (finally_port = port_min; finally_port < base_port; finally_port++) { - if (port_index[finally_port] == NULL) return finally_port; + if (port_index[finally_port] == NULL) return rte_cpu_to_be_16(finally_port); } return 0; @@ -1368,8 +1369,8 @@ struct rte_mbuf * header, struct rte_mbuf * udp_data) // 构建头部 struct udp_hdr * udp_hdr = rte_pktmbuf_mtod(header, struct udp_hdr *); - udp_hdr->src_port = rte_cpu_to_be_16(src_port); - udp_hdr->dst_port = rte_cpu_to_be_16(dst_port); + udp_hdr->src_port = src_port; + udp_hdr->dst_port = dst_port; udp_hdr->dgram_len = rte_cpu_to_be_16(sizeof(struct udp_hdr) + rte_pktmbuf_pkt_len(udp_data)); udp_hdr->dgram_cksum = 0; @@ -1539,7 +1540,7 @@ INLINE static int udpstack_send_packet(struct rte_mbuf * mbuf, uint8_t port_id) return 0; } - int ret = rte_ring_sp_enqueue_bulk(lp->rings_out[port_id], (void **)lp->mbuf_out[port_id].array, bsz_wr); + int ret = rte_ring_enqueue_bulk(lp->rings_out[port_id], (void **)lp->mbuf_out[port_id].array, bsz_wr); if (unlikely(ret == -ENOBUFS)) { // TODO: 发包统计 @@ -1629,7 +1630,14 @@ int udpstack_route_send_burst(struct rte_mbuf * mbufs[], uint32_t dstip[], for (int i = 0; i < nb_mbufs; i++) { struct udpstack_route_table_rule * route_rule = route_result[i]; - if (unlikely(route_rule == NULL)) continue; //TODO: 丢包 + + //TODO: 丢包处理,暂时这样避免错误配置导致的mbuf池用光。 + if (unlikely(route_rule == NULL)) + { + __packet_drop(mbufs[i], 0); + continue; + } + struct rte_mbuf * header = mbufs[i]; struct ipv4_hdr * ipv4_hdr = rte_pktmbuf_mtod(header, struct ipv4_hdr *); @@ -1808,6 +1816,10 @@ drop: return ret; } +//TODO: 重构这一部分代码 +static struct rte_timer __garp_timer; +void udpstack_arp_timer_garp(struct rte_timer * timer, void * arg); + // ARP子系统初始化 int udpstack_arp_init() { @@ -1834,6 +1846,8 @@ int udpstack_arp_init() } } + uint64_t timer_hz = rte_get_timer_hz(); + rte_timer_reset(&__garp_timer, timer_hz, PERIODICAL, rte_lcore_id(),udpstack_arp_timer_garp, NULL); return 0; } @@ -2130,6 +2144,24 @@ int udpstack_packet_arp_entry(struct rte_mbuf * mbufs[], int nb_mbufs) return RET_CHAIN_DROP; } +/* 定时器事件,无故ARP事件处理 */ +void udpstack_arp_timer_garp(struct rte_timer * timer __rte_unused, void * arg __rte_unused) +{ + for (uint32_t port_id = 0; port_id < RTE_MAX_ETHPORTS; port_id++) + { + struct udpstack_iface * iface_desc = __get_iface_desc(port_id); + if (iface_desc->enable == 0) continue; + + // 对接口上的每一个IP地址,分别发送GARP请求。 + for (int ip_id = 0; ip_id < iface_desc->nb_ipaddr; ip_id++) + { + udpstack_arp_request_send(iface_desc->port_id, iface_desc->ipaddr[ip_id].ipaddr); + } + } + + return; +} + int udpstack_icmp_echo_request(struct rte_mbuf * mbuf, uint32_t srcip, uint32_t dstip) { struct icmp_hdr * icmp_hdr = rte_pktmbuf_mtod(mbuf, struct icmp_hdr *); |
