-
Notifications
You must be signed in to change notification settings - Fork 0
/
tst.py
39 lines (31 loc) · 992 Bytes
/
tst.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from pprint import pprint
from _pynetmap import lib, ffi
import select
import time
def insp(d):
return {k:getattr(d, k) for k in dir(d)}
IFNAME = 'netmap:ve0b'
def netmap_txring(nifp, index):
return ffi.cast('char*', ffi.cast('char*', nifp) + nifp.ring_ofs[index])
def netmap_rxring(nifp, index):
return ffi.cast('char*', ffi.cast('char*', nifp) + nifp.ring_ofs[index + nifp.ni_tx_rings + 1])
ifname = ffi.new('char[]', IFNAME)
nm_desc = lib.nm_open(ifname, ffi.NULL, 0, ffi.NULL)
nifp = nm_desc.nifp
rxr = lib.netmap_rxring(nifp, 0)
txr = lib.netmap_txring(nifp, 0)
print 'nm_desc:'
pprint(insp(nm_desc))
print 'netmap_if:'
pprint(insp(nifp))
index = 0
base_ptr = ffi.cast('char*', nifp)
rx_ptr = ffi.cast('char*', rxr)
tx_ptr = ffi.cast('char*', txr)
idx = 0
print netmap_rxring(nifp, 0)
print 'rx:', rx_ptr, rx_ptr - base_ptr, insp(rxr)
print netmap_txring(nifp, 0)
print 'tx:', tx_ptr, tx_ptr - base_ptr, insp(txr)
print 'rx-tx:', tx_ptr - rx_ptr
lib.nm_close(nm_desc)