add support for limiting queue len

This commit is contained in:
trinity-1686a 2022-08-31 21:29:18 +02:00
parent 5a8be6fc73
commit 30643ca50d
2 changed files with 7 additions and 3 deletions

8
mknet
View file

@ -87,19 +87,21 @@ class Bandwidth:
class LinkInfo: class LinkInfo:
def __init__(self, bandwidth, latency, jitter = None, offset = None, **kwargs): def __init__(self, bandwidth, latency, jitter = None, offset = None, limit = None, **kwargs):
self.bandwidth = Bandwidth(bandwidth) self.bandwidth = Bandwidth(bandwidth)
self.latency = Latency(latency, offset) self.latency = Latency(latency, offset)
self.jitter = Latency(jitter or 0) self.jitter = Latency(jitter or 0)
self.limit = limit
def __eq__(self, o): def __eq__(self, o):
return (isinstance(o, LinkInfo) and return (isinstance(o, LinkInfo) and
o.bandwidth == self.bandwidth and o.bandwidth == self.bandwidth and
o.latency == self.latency and o.latency == self.latency and
o.jitter == self.jitter) o.jitter == self.jitter and
o.limit == self.limit)
def __str__(self): def __str__(self):
return f'LinkInfo{{bw: {self.bandwidth}, latency: {self.latency}, jitter: {self.jitter}}}' return f'LinkInfo{{bw: {self.bandwidth}, latency: {self.latency}, jitter: {self.jitter}, limit: {self.limit}}}'
class Server: class Server:
def __init__(self, name, link): def __init__(self, name, link):

2
net.py
View file

@ -66,4 +66,6 @@ def tc(namespace, name, link, invert=False):
options += ["rate", str(link.bandwidth.down)] options += ["rate", str(link.bandwidth.down)]
else: else:
options += ["rate", str(link.bandwidth.up)] options += ["rate", str(link.bandwidth.up)]
if link.limit:
options += ["limit", str(link.limit)]
run_netns("exec", namespace, "tc", "qdisc", "add", "dev", name, "root", "netem", *options) run_netns("exec", namespace, "tc", "qdisc", "add", "dev", name, "root", "netem", *options)