blob: 38180132ba9a4be7904734a59665d87bcd612de9 [file] [log] [blame]
Alexey Ivanovcc01a9c2019-01-16 09:50:46 -08001#!/usr/bin/python
Brenden Blanco09e77f72015-06-16 00:21:57 -07002# Copyright (c) PLUMgrid, Inc.
3# Licensed under the Apache License, Version 2.0 (the "License")
4
Brenden Blancoc35989d2015-09-02 18:04:07 -07005from bcc import BPF
Brenden Blanco09e77f72015-06-16 00:21:57 -07006from pyroute2 import IPRoute
7
Brenden Blanco09e77f72015-06-16 00:21:57 -07008ipr = IPRoute()
9
10text = """
11int hello(struct __sk_buff *skb) {
12 return 1;
13}
14"""
15
16try:
17 b = BPF(text=text, debug=0)
18 fn = b.load_func("hello", BPF.SCHED_CLS)
Gary Ching-Pang Lin7fdaa9c2019-03-08 01:52:06 +080019 ipr.link("add", ifname="t1a", kind="veth", peer="t1b")
Brenden Blanco09e77f72015-06-16 00:21:57 -070020 idx = ipr.link_lookup(ifname="t1a")[0]
21
22 ipr.tc("add", "ingress", idx, "ffff:")
23 ipr.tc("add-filter", "bpf", idx, ":1", fd=fn.fd,
24 name=fn.name, parent="ffff:", action="ok", classid=1)
25 ipr.tc("add", "sfq", idx, "1:")
26 ipr.tc("add-filter", "bpf", idx, ":1", fd=fn.fd,
27 name=fn.name, parent="1:", action="ok", classid=1)
28finally:
Gary Ching-Pang Lin7fdaa9c2019-03-08 01:52:06 +080029 if "idx" in locals(): ipr.link("del", index=idx)
Yonghong Song8bbf0622015-08-10 11:19:53 -070030print("BPF tc functionality - SCHED_CLS: OK")