Skip to content

Commit

Permalink
Fix network examples (iovisor#2256)
Browse files Browse the repository at this point in the history
* examples/networking: remove the deprecated pyroute2 functions

link_create() and link_remove() are deprecated since pyroute2 0.5.2.
Replace them with the equivalent link() commands.

Signed-off-by: Gary Lin <[email protected]>
  • Loading branch information
lcp authored and yonghong-song committed Mar 7, 2019
1 parent 34cada1 commit 7fdaa9c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions examples/networking/simple_tc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
try:
b = BPF(text=text, debug=0)
fn = b.load_func("hello", BPF.SCHED_CLS)
ipr.link_create(ifname="t1a", kind="veth", peer="t1b")
ipr.link("add", ifname="t1a", kind="veth", peer="t1b")
idx = ipr.link_lookup(ifname="t1a")[0]

ipr.tc("add", "ingress", idx, "ffff:")
Expand All @@ -26,5 +26,5 @@
ipr.tc("add-filter", "bpf", idx, ":1", fd=fn.fd,
name=fn.name, parent="1:", action="ok", classid=1)
finally:
if "idx" in locals(): ipr.link_remove(idx)
if "idx" in locals(): ipr.link("del", index=idx)
print("BPF tc functionality - SCHED_CLS: OK")
2 changes: 1 addition & 1 deletion examples/networking/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def _ns_add_ifc(self, name, ns_ifc, ifc_base_name=None, in_ifc=None,
else:
# delete the potentially leaf-over veth interfaces
ipr = IPRoute()
for i in ipr.link_lookup(ifname='%sa' % ifc_base_name): ipr.link_remove(i)
for i in ipr.link_lookup(ifname='%sa' % ifc_base_name): ipr.link("del", index=i)
ipr.close()
try:
out_ifc = self.ipdb.create(ifname="%sa" % ifc_base_name, kind="veth",
Expand Down
7 changes: 5 additions & 2 deletions examples/networking/tc_perf_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ class SkbEvent(ct.Structure):
b["skb_events"].open_perf_buffer(print_skb_event)
print('Try: "ping6 ff02::1%me"\n')
print("%-3s %-32s %-12s %-10s" % ("CPU", "SRC IP", "DST IP", "Magic"))
while True:
b.perf_buffer_poll()
try:
while True:
b.perf_buffer_poll()
except KeyboardInterrupt:
pass
finally:
if "me" in locals(): ipr.link("del", index=me)
3 changes: 2 additions & 1 deletion examples/networking/xdp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
install(PROGRAMS xdp_drop_count.py DESTINATION share/bcc/examples/networking/xdp)
file(GLOB PY_FILES *.py)
install(PROGRAMS ${PY_FILES} DESTINATION share/bcc/examples/networking/xdp)

0 comments on commit 7fdaa9c

Please sign in to comment.