aboutsummaryrefslogtreecommitdiff
path: root/ifstatd.py
diff options
context:
space:
mode:
authorSergey Nazaryev <sergey@nazaryev.ru>2018-11-07 02:10:32 +0000
committerSergey Nazaryev <sergey@nazaryev.ru>2018-11-07 02:10:32 +0000
commit5e002c132b7d93f98efadd419f40ae763dd475ab (patch)
tree6327e3a8136b90711ac7c362ffe83edbea4dcea6 /ifstatd.py
parentb61aab069d13670dce8eb06cb92a5de70061bd6f (diff)
downloadifstat-5e002c132b7d93f98efadd419f40ae763dd475ab.zip
ifstat-5e002c132b7d93f98efadd419f40ae763dd475ab.tar.gz
ifstat-5e002c132b7d93f98efadd419f40ae763dd475ab.tar.bz2
Для тестов добавил альтернативную реализацию ifstatd на Python
Diffstat (limited to 'ifstatd.py')
-rwxr-xr-xifstatd.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/ifstatd.py b/ifstatd.py
new file mode 100755
index 0000000..a6b4acc
--- /dev/null
+++ b/ifstatd.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+#
+# xdp_redirect_cpu.py Redirect the incoming packet to the specific CPU
+#
+# Copyright (c) 2018 Gary Lin
+# Licensed under the Apache License, Version 2.0 (the "License")
+
+from bcc import BPF
+import time
+import sys
+
+flags = 0
+def usage():
+ print("Usage: {0} <in ifdev>".format(sys.argv[0]))
+ print("e.g.: {0} eth0\n".format(sys.argv[0]))
+ exit(1)
+
+if len(sys.argv) != 2:
+ usage()
+
+in_if = sys.argv[1]
+
+# load BPF program
+b = BPF(src_file = "ifstat_kern.c", cflags = [
+ "-DANY=-1",
+ "-DFILTER0_ENABLED=1",
+ "-DFILTER0_SRC_IP=-1",
+ "-DFILTER0_DST_IP=-1",
+ "-DFILTER0_SRC_PORT=-1",
+ "-DFILTER0_DST_PORT=-1",
+ "-DFILTER0_IPPROTO=-1"
+])
+
+in_fn = b.load_func("xdp_packet_handler", BPF.XDP)
+b.attach_xdp(in_if, in_fn, flags)
+
+dropcnt = b.get_table("filter0")
+while 1:
+ try:
+ for k in dropcnt.keys():
+ print("abc", dropcnt[k])
+ time.sleep(1)
+ except KeyboardInterrupt:
+ print("Removing filter from device")
+ break;
+
+b.remove_xdp(in_if, flags)