Commit c3f57e69 authored by 4ast's avatar 4ast

Merge pull request #25 from plumgrid/bblanco_dev

Rename files and a few functions
parents f197faf4 f178be9e
...@@ -62,7 +62,7 @@ class BPF(object): ...@@ -62,7 +62,7 @@ class BPF(object):
self.keytype = keytype self.keytype = keytype
self.leaftype = leaftype self.leaftype = leaftype
def get(self, key): def lookup(self, key):
key_p = ct.pointer(key) key_p = ct.pointer(key)
leaf = self.leaftype() leaf = self.leaftype()
leaf_p = ct.pointer(leaf) leaf_p = ct.pointer(leaf)
...@@ -73,7 +73,7 @@ class BPF(object): ...@@ -73,7 +73,7 @@ class BPF(object):
raise Exception("Could not lookup in table") raise Exception("Could not lookup in table")
return leaf return leaf
def put(self, key, leaf, flags=0): def update(self, key, leaf, flags=0):
key_p = ct.pointer(key) key_p = ct.pointer(key)
leaf_p = ct.pointer(leaf) leaf_p = ct.pointer(leaf)
res = lib.bpf_update_elem(self.map_fd, res = lib.bpf_update_elem(self.map_fd,
......
...@@ -2,4 +2,4 @@ configure_file(wrapper.sh.in "${CMAKE_CURRENT_BINARY_DIR}/wrapper.sh" @ONLY) ...@@ -2,4 +2,4 @@ configure_file(wrapper.sh.in "${CMAKE_CURRENT_BINARY_DIR}/wrapper.sh" @ONLY)
set(TEST_WRAPPER ${CMAKE_CURRENT_BINARY_DIR}/wrapper.sh) set(TEST_WRAPPER ${CMAKE_CURRENT_BINARY_DIR}/wrapper.sh)
add_subdirectory(jit) add_subdirectory(cc)
add_test(NAME py_test_stat1_b WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${TEST_WRAPPER} py_stat1_b namespace ${CMAKE_CURRENT_SOURCE_DIR}/test_stat1.py test_stat1.b proto.b)
add_test(NAME py_test_stat1_c WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${TEST_WRAPPER} py_stat1_c namespace ${CMAKE_CURRENT_SOURCE_DIR}/test_stat1.py test_stat1.c)
add_test(NAME py_test_xlate1_b WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${TEST_WRAPPER} py_xlate1_b namespace ${CMAKE_CURRENT_SOURCE_DIR}/test_xlate1.py test_xlate1.b proto.b)
add_test(NAME py_test_xlate1_c WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${TEST_WRAPPER} py_xlate1_c namespace ${CMAKE_CURRENT_SOURCE_DIR}/test_xlate1.py test_xlate1.c)
add_test(NAME py_test_call1 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${TEST_WRAPPER} py_call1_c namespace ${CMAKE_CURRENT_SOURCE_DIR}/test_call1.py test_call1.c)
add_test(NAME py_test_trace1 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${TEST_WRAPPER} py_trace1 sudo ${CMAKE_CURRENT_SOURCE_DIR}/test_trace1.py test_trace1.b kprobe.b)
add_test(NAME py_test_trace2 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${TEST_WRAPPER} py_trace2 sudo ${CMAKE_CURRENT_SOURCE_DIR}/test_trace2.py)
add_test(NAME py_test_trace3_c WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${TEST_WRAPPER} py_trace3_c sudo ${CMAKE_CURRENT_SOURCE_DIR}/test_trace3.py test_trace3.c)
...@@ -24,17 +24,17 @@ class TestBPFSocket(TestCase): ...@@ -24,17 +24,17 @@ class TestBPFSocket(TestCase):
eop_fn = b.load_func("eop", BPF.SCHED_CLS) eop_fn = b.load_func("eop", BPF.SCHED_CLS)
BPF.attach_classifier(ether_fn, "eth0") BPF.attach_classifier(ether_fn, "eth0")
self.jump = b.get_table("jump", c_int, c_int) self.jump = b.get_table("jump", c_int, c_int)
self.jump.put(c_int(S_ARP), c_int(arp_fn.fd)) self.jump.update(c_int(S_ARP), c_int(arp_fn.fd))
self.jump.put(c_int(S_IP), c_int(ip_fn.fd)) self.jump.update(c_int(S_IP), c_int(ip_fn.fd))
self.jump.put(c_int(S_EOP), c_int(eop_fn.fd)) self.jump.update(c_int(S_EOP), c_int(eop_fn.fd))
self.stats = b.get_table("stats", c_int, c_ulonglong) self.stats = b.get_table("stats", c_int, c_ulonglong)
def test_jumps(self): def test_jumps(self):
udp = socket(AF_INET, SOCK_DGRAM) udp = socket(AF_INET, SOCK_DGRAM)
udp.sendto(b"a" * 10, ("172.16.1.1", 5000)) udp.sendto(b"a" * 10, ("172.16.1.1", 5000))
self.assertGreater(self.stats.get(c_int(S_IP)).value, 0) self.assertGreater(self.stats.lookup(c_int(S_IP)).value, 0)
self.assertGreater(self.stats.get(c_int(S_ARP)).value, 0) self.assertGreater(self.stats.lookup(c_int(S_ARP)).value, 0)
self.assertGreater(self.stats.get(c_int(S_EOP)).value, 1) self.assertGreater(self.stats.lookup(c_int(S_EOP)).value, 1)
if __name__ == "__main__": if __name__ == "__main__":
main() main()
...@@ -33,11 +33,11 @@ class TestBPFSocket(TestCase): ...@@ -33,11 +33,11 @@ class TestBPFSocket(TestCase):
cmd = ["ping", "-f", "-c", "100", "172.16.1.1"] cmd = ["ping", "-f", "-c", "100", "172.16.1.1"]
check_call(cmd) check_call(cmd)
#for key in self.stats.iter(): #for key in self.stats.iter():
# leaf = self.stats.get(key) # leaf = self.stats.lookup(key)
# print(IPAddress(key.sip), "=>", IPAddress(key.dip), # print(IPAddress(key.sip), "=>", IPAddress(key.dip),
# "rx", leaf.rx_pkts, "tx", leaf.tx_pkts) # "rx", leaf.rx_pkts, "tx", leaf.tx_pkts)
key = Key(IPAddress("172.16.1.2").value, IPAddress("172.16.1.1").value) key = Key(IPAddress("172.16.1.2").value, IPAddress("172.16.1.1").value)
leaf = self.stats.get(key) leaf = self.stats.lookup(key)
self.assertEqual(leaf.rx_pkts, 100) self.assertEqual(leaf.rx_pkts, 100)
self.assertEqual(leaf.tx_pkts, 100) self.assertEqual(leaf.tx_pkts, 100)
......
...@@ -37,7 +37,7 @@ class TestKprobe(TestCase): ...@@ -37,7 +37,7 @@ class TestKprobe(TestCase):
for i in range(0, 200): for i in range(0, 200):
os.read(f.fileno(), 1) os.read(f.fileno(), 1)
for key in self.stats.iter(): for key in self.stats.iter():
leaf = self.stats.get(key) leaf = self.stats.lookup(key)
print("fd %x:" % key.fd, "stat1 %d" % leaf.stat1, "stat2 %d" % leaf.stat2) print("fd %x:" % key.fd, "stat1 %d" % leaf.stat1, "stat2 %d" % leaf.stat2)
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -37,7 +37,7 @@ class TestTracingEvent(TestCase): ...@@ -37,7 +37,7 @@ class TestTracingEvent(TestCase):
for i in range(0, 100): for i in range(0, 100):
sleep(0.01) sleep(0.01)
for key in self.stats.iter(): for key in self.stats.iter():
leaf = self.stats.get(key) leaf = self.stats.lookup(key)
print("ptr %x:" % key.ptr, "stat1 %x" % leaf.stat1) print("ptr %x:" % key.ptr, "stat1 %x" % leaf.stat1)
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -31,7 +31,7 @@ class TestBlkRequest(TestCase): ...@@ -31,7 +31,7 @@ class TestBlkRequest(TestCase):
subprocess.call(["sync"]) subprocess.call(["sync"])
os.unlink("/opt/trace3.txt") os.unlink("/opt/trace3.txt")
for key in self.latency.iter(): for key in self.latency.iter():
leaf = self.latency.get(key) leaf = self.latency.lookup(key)
print("latency %u:" % key.value, "count %u" % leaf.value) print("latency %u:" % key.value, "count %u" % leaf.value)
sys.stdout.flush() sys.stdout.flush()
......
...@@ -31,10 +31,10 @@ class TestBPFSocket(TestCase): ...@@ -31,10 +31,10 @@ class TestBPFSocket(TestCase):
def test_xlate(self): def test_xlate(self):
key = Key(IPAddress("172.16.1.1").value, IPAddress("172.16.1.2").value) key = Key(IPAddress("172.16.1.1").value, IPAddress("172.16.1.2").value)
leaf = Leaf(IPAddress("192.168.1.1").value, IPAddress("192.168.1.2").value, 0) leaf = Leaf(IPAddress("192.168.1.1").value, IPAddress("192.168.1.2").value, 0)
self.xlate.put(key, leaf) self.xlate.update(key, leaf)
udp = socket(AF_INET, SOCK_DGRAM) udp = socket(AF_INET, SOCK_DGRAM)
udp.sendto(b"a" * 10, ("172.16.1.1", 5000)) udp.sendto(b"a" * 10, ("172.16.1.1", 5000))
leaf = self.xlate.get(key) leaf = self.xlate.lookup(key)
self.assertGreater(leaf.xlated_pkts, 0) self.assertGreater(leaf.xlated_pkts, 0)
udp.close() udp.close()
......
add_test(NAME py_test1_b WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${TEST_WRAPPER} py_test1_b namespace ${CMAKE_CURRENT_SOURCE_DIR}/test1.py test1.b proto.b)
add_test(NAME py_test1_c WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${TEST_WRAPPER} py_test1_c namespace ${CMAKE_CURRENT_SOURCE_DIR}/test1.py test1.c)
add_test(NAME py_test2_b WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${TEST_WRAPPER} py_test2_b namespace ${CMAKE_CURRENT_SOURCE_DIR}/test2.py test2.b proto.b)
add_test(NAME py_test2_c WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${TEST_WRAPPER} py_test2_c namespace ${CMAKE_CURRENT_SOURCE_DIR}/test2.py test2.c)
add_test(NAME py_test3 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${TEST_WRAPPER} py_test3 namespace ${CMAKE_CURRENT_SOURCE_DIR}/test3.py test3.c)
add_test(NAME py_trace1 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${TEST_WRAPPER} py_trace1 sudo ${CMAKE_CURRENT_SOURCE_DIR}/trace1.py trace1.b kprobe.b)
add_test(NAME py_trace2 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${TEST_WRAPPER} py_trace2 sudo ${CMAKE_CURRENT_SOURCE_DIR}/trace2.py)
add_test(NAME py_trace3_c WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${TEST_WRAPPER} py_trace3_c sudo ${CMAKE_CURRENT_SOURCE_DIR}/trace3.py trace3.c)
#!/usr/bin/env python
import sys
from bpf import BPF
prog = BPF(sys.argv[1], sys.argv[2], sys.argv[3],
prog_type=int(sys.argv[4]), debug=int(sys.argv[5]))
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