-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dominik Scholz
committed
May 4, 2016
1 parent
aac5303
commit 9542cf7
Showing
5 changed files
with
156 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ SET(FILES | |
src/namespaces.cpp | ||
src/ring.c | ||
src/rate_limiter.cpp | ||
src/kni.c | ||
) | ||
|
||
SET(DPDK_LIBS | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
local ffi = require "ffi" | ||
local dpdkc = require "dpdkc" | ||
local dpdk = require "dpdk" | ||
|
||
local mod = {} | ||
|
||
local mg_kni = {} | ||
mod.mg_kni = mg_kni | ||
mg_kni.__index = mg_kni | ||
|
||
ffi.cdef[[ | ||
struct rte_kni; | ||
struct rte_kni * mg_create_kni(uint8_t port_id, uint8_t core_id, void* mempool_ptr, const char name[]); | ||
unsigned rte_kni_tx_burst ( struct rte_kni * kni, | ||
struct rte_mbuf ** mbufs, | ||
unsigned num | ||
); | ||
unsigned rte_kni_rx_burst ( struct rte_kni * kni, | ||
struct rte_mbuf ** mbufs, | ||
unsigned num | ||
); | ||
int rte_kni_handle_request ( struct rte_kni * kni ); | ||
unsigned mg_kni_tx_single(struct rte_kni * kni, struct rte_mbuf * mbuf); | ||
void rte_kni_close ( void ); | ||
int rte_kni_release ( struct rte_kni * kni ); | ||
]] | ||
|
||
function mod.createKNI(core, device, mempool, name) | ||
--printf("kni C pointer print:") | ||
printPtr(mempool) | ||
core = core or 0 | ||
--printf("port id %d", device.id) | ||
--printf("in KNI ptr memp %p", mempool) | ||
--printPtr(mempool) | ||
local kni = ffi.C.mg_create_kni(device.id, core, mempool, name) | ||
--printPtr(mempool) | ||
--printf("KNI should be nil = %p ,, mempool = %p", kni, mempool) | ||
--if(kni == nil)then | ||
-- printf("KNI == NIL !!!") | ||
--else | ||
-- printf("KNI not nil") | ||
--end | ||
return setmetatable({ | ||
kni = kni, | ||
core = core, | ||
device = device | ||
}, mg_kni) | ||
end | ||
|
||
function mg_kni:rxBurst(bufs, nmax) | ||
return ffi.C.rte_kni_rx_burst(self.kni, bufs.array, nmax) | ||
end | ||
function mg_kni:txSingle(mbuf) | ||
ffi.C.mg_kni_tx_single(self.kni, mbuf) | ||
end | ||
function mg_kni:handleRequest() | ||
ffi.C.rte_kni_handle_request(self.kni) | ||
end | ||
|
||
function mg_kni:release() | ||
return ffi.C.rte_kni_release(self.kni) | ||
end | ||
|
||
function mod.close() | ||
ffi.C.rte_kni_close() | ||
end | ||
|
||
return mod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <rte_config.h> | ||
#include <rte_common.h> | ||
#include <rte_mempool.h> | ||
#include <rte_mbuf.h> | ||
#include <rte_kni.h> | ||
#include <rte_pci.h> | ||
#include <rte_ethdev.h> | ||
#include <stdint.h> | ||
|
||
/* Max size of a single packet */ | ||
#define MAX_PACKET_SZ 2048 | ||
|
||
static int kni_change_mtu(uint8_t port_id, unsigned new_mtu){ | ||
printf("change mtu\n"); | ||
return 0; | ||
} | ||
static int kni_config_network_interface(uint8_t port_id, uint8_t if_up){ | ||
printf("interface config\n"); | ||
return 0; | ||
} | ||
|
||
//struct rte_kni * mg_create_kni(uint8_t port_id, uint8_t core_id, struct rte_mempool* pktmbuf_pool){ | ||
struct rte_kni * mg_create_kni(uint8_t port_id, uint8_t core_id, void* mempool_ptr, const char name[]){ | ||
//printf("create kni\n"); | ||
//printf("mempool ptr 1 : %p\n", mempool_ptr); | ||
struct rte_kni *kni; | ||
struct rte_kni_conf conf; | ||
/* Clear conf at first */ | ||
memset(&conf, 0, sizeof(conf)); | ||
snprintf(conf.name, RTE_KNI_NAMESIZE, name); | ||
conf.core_id = core_id; | ||
conf.force_bind = 1; | ||
conf.group_id = (uint16_t)port_id; | ||
conf.mbuf_size = MAX_PACKET_SZ; | ||
|
||
struct rte_eth_dev_info dev_info; | ||
|
||
memset(&dev_info, 0, sizeof(dev_info)); | ||
//printf("get dev info\n"); | ||
rte_eth_dev_info_get(port_id, &dev_info); | ||
//printf("dev done\n"); | ||
//printf("pci dev: %p\n", dev_info.pci_dev); | ||
conf.addr = dev_info.pci_dev->addr; | ||
//printf("a\n"); | ||
conf.id = dev_info.pci_dev->id; | ||
//printf("b\n"); | ||
|
||
struct rte_kni_ops ops; | ||
//printf("c\n"); | ||
memset(&ops, 0, sizeof(ops)); | ||
//printf("d\n"); | ||
ops.port_id = port_id; | ||
//printf("e\n"); | ||
ops.change_mtu = kni_change_mtu; | ||
//printf("f\n"); | ||
ops.config_network_if = kni_config_network_interface; | ||
|
||
//printf("alloc\n"); | ||
struct rte_mempool * pktmbuf_pool = (struct rte_mempool *)(mempool_ptr); | ||
//printf("mempool pointer: %p\n", pktmbuf_pool); | ||
kni = rte_kni_alloc(pktmbuf_pool, &conf, &ops); | ||
//printf("done, kni = %p\n", kni); | ||
|
||
//rte_eth_dev_start(port_id); | ||
return kni; | ||
} | ||
|
||
unsigned mg_kni_tx_single(struct rte_kni * kni, struct rte_mbuf * mbuf){ | ||
return rte_kni_tx_burst(kni, &mbuf, 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters