<commit_before>#!/usr/bin/python
# Author: <NAME>
# QoS for upload

import tools
from config import PUBLIC_IF, UPLOAD


def interactive_class():
    """
    Interactive Class, for low latency, high priority packets such as VOIP and
    DNS.

    Low priority, pass before everything else. Uses htb then pfifo.
    """
    parent = "1:1"
    classid = "1:100"
    prio = 10
    mark = 100
    rate = UPLOAD * 10/100
    ceil = UPLOAD * 75/100
    minimum_ping = 10/1000
    expected_ping = 20/1000

    tools.class_add(PUBLIC_IF, parent, classid, rate=rate, ceil=ceil,
                    burst=expected_ping * rate,
                    cburst=minimum_ping * ceil, prio=prio)
    tools.qdisc_add(PUBLIC_IF, parent=classid, handle="1100:",
                    algorithm="pfifo")
    tools.filter_add(PUBLIC_IF, parent="1:0", prio=prio, handle=mark,
                     flowid=classid)


def tcp_ack_class():
    """
    Class for TCP ACK.

    It's important to let the ACKs leave the network as fast
    as possible when a host of the network is downloading. Uses htb then sfq.
    """
    parent = "1:1"
    classid = "1:200"
    prio = 20
    mark = 200
    rate = UPLOAD * 50/100
    ceil = UPLOAD
    expected_ping = 30/1000

    tools.class_add(PUBLIC_IF, parent, classid, rate=rate, ceil=ceil,
                    burst=expected_ping * rate, prio=prio)
    tools.qdisc_add(PUBLIC_IF, parent=classid, handle="1200:",
                    algorithm="sfq", perturb=10)
    tools.filter_add(PUBLIC_IF, parent="1:0", prio=prio, handle=mark,
                     flowid=classid)


def ssh_class():
    """
    Class for SSH connections.

    We want the ssh connections to be smooth !
    SFQ will mix the packets if there are several SSH connections in parallel
    and ensure that none has the priority
    """
    parent = "1:1"
    classid = "1:300"
    prio = 30
    mark = 300
    rate = UPLOAD * 10/100
    ceil = UPLOAD
    expected_ping = 25/1000
    minimum_ping = 10/1000

    tools.class_add(PUBLIC_IF, parent, classid, rate=rate, ceil=ceil,
                    burst=expected_ping * rate,
                    cburst=minimum_ping * ceil, prio=prio)
    tools.qdisc_add(PUBLIC_IF, parent=classid, handle="1300:",
                    algorithm="sfq", perturb=10)
    tools.filter_add(PUBLIC_IF, parent="1:0", prio=prio, handle=mark,
                     flowid=classid)


def http_class():
    """
    Class for HTTP/HTTPS connections.
    """
    parent = "1:1"
    classid = "1:400"
    prio = 40
    mark = 400
    rate = UPLOAD * 20/100
    ceil = UPLOAD
    expected_ping = 40/1000

    tools.class_add(PUBLIC_IF, parent, classid, rate=rate, ceil=ceil,
                    burst=expected_ping * rate, prio=prio)
    tools.qdisc_add(PUBLIC_IF, parent=classid, handle="1400:",
                    algorithm="sfq", perturb=10)
    tools.filter_add(PUBLIC_IF, parent="1:0", prio=prio, handle=mark,
                     flowid=classid)


def default_class():
    """
    Default class
    """
    parent = "1:1"
    classid = "1:1000"
    prio = 100
    mark = 1000
    rate = UPLOAD * 60/100
    ceil = UPLOAD
    expected_ping = 40/1000

    tools.class_add(PUBLIC_IF, parent, classid, rate=rate, ceil=ceil,
                    burst=expected_ping * rate, prio=prio)
    tools.qdisc_add(PUBLIC_IF, parent=classid, handle="11000:",
                    algorithm="sfq", perturb=10)
    tools.filter_add(PUBLIC_IF, parent="1:0", prio=prio, handle=mark,
                     flowid=classid)


def apply_qos():
    """
    Apply the QoS for the OUTPUT
    """
    # Creating the HTB root qdisc
    tools.qdisc_add(PUBLIC_IF, "1:", "htb", default=1000)
    # Creating the main branch (htb)
    tools.class_add(PUBLIC_IF, parent="1:0", classid="1:1", rate=UPLOAD,
                    ceil=UPLOAD)
<commit_msg>Fix burst misunderstood<commit_after>#!/usr/bin/python
# Author: <NAME>
# QoS for upload

import tools
from config import PUBLIC_IF, UPLOAD


def interactive_class():
    """
    Interactive Class, for low latency, high priority packets such as VOIP and
    DNS.

    Low priority, pass before everything else. Uses htb then pfifo.
    """
    parent = "1:1"
    classid = "1:100"
    prio = 10
    mark = 100
    rate = UPLOAD * 10/100
    ceil = UPLOAD * 75/100
    burst = 0.3 * ceil/8   # ceil in bytes during 0.3 seconds

    tools.class_add(PUBLIC_IF, parent, classid, rate=rate, ceil=ceil,
                    burst=burst, prio=prio)
    tools.qdisc_add(PUBLIC_IF, parent=classid, handle="1100:",
                    algorithm="pfifo")
    tools.filter_add(PUBLIC_IF, parent="1:0", prio=prio, handle=mark,
                     flowid=classid)


def tcp_ack_class():
    """
    Class for TCP ACK.

    It's important to let the ACKs leave the network as fast
    as possible when a host of the network is downloading. Uses htb then sfq.
    """
    parent = "1:1"
    classid = "1:200"
    prio = 20
    mark = 200
    rate = UPLOAD * 50/100
    ceil = UPLOAD
    burst = 0.3 * ceil/8  # ceil in bytes during 0.3 seconds

    tools.class_add(PUBLIC_IF, parent, classid, rate=rate, ceil=ceil,
                    burst=burst, prio=prio)
    tools.qdisc_add(PUBLIC_IF, parent=classid, handle="1200:",
                    algorithm="sfq", perturb=10)
    tools.filter_add(PUBLIC_IF, parent="1:0", prio=prio, handle=mark,
                     flowid=classid)


def ssh_class():
    """
    Class for SSH connections.

    We want the ssh connections to be smooth !
    SFQ will mix the packets if there are several SSH connections in parallel
    and ensure that none has the priority
    """
    parent = "1:1"
    classid = "1:300"
    prio = 30
    mark = 300
    rate = UPLOAD * 10/100
    ceil = UPLOAD
    burst = ceil/8  # ceil in bytes during 1 second

    tools.class_add(PUBLIC_IF, parent, classid, rate=rate, ceil=ceil,
                    burst=burst, prio=prio)
    tools.qdisc_add(PUBLIC_IF, parent=classid, handle="1300:",
                    algorithm="sfq", perturb=10)
    tools.filter_add(PUBLIC_IF, parent="1:0", prio=prio, handle=mark,
                     flowid=classid)


def http_class():
    """
    Class for HTTP/HTTPS connections.
    """
    parent = "1:1"
    classid = "1:400"
    prio = 40
    mark = 400
    rate = UPLOAD * 20/100
    ceil = UPLOAD
    burst = ceil/8  # ceil in bytes during 1 second

    tools.class_add(PUBLIC_IF, parent, classid, rate=rate, ceil=ceil,
                    burst=burst, prio=prio)
    tools.qdisc_add(PUBLIC_IF, parent=classid, handle="1400:",
                    algorithm="sfq", perturb=10)
    tools.filter_add(PUBLIC_IF, parent="1:0", prio=prio, handle=mark,
                     flowid=classid)


def default_class():
    """
    Default class
    """
    parent = "1:1"
    classid = "1:1000"
    prio = 100
    mark = 1000
    rate = UPLOAD * 60/100
    ceil = UPLOAD

    tools.class_add(PUBLIC_IF, parent, classid, rate=rate, ceil=ceil,
                    prio=prio)
    tools.qdisc_add(PUBLIC_IF, parent=classid, handle="11000:",
                    algorithm="sfq", perturb=10)
    tools.filter_add(PUBLIC_IF, parent="1:0", prio=prio, handle=mark,
                     flowid=classid)


def apply_qos():
    """
    Apply the QoS for the OUTPUT
    """
    # Creating the HTB root qdisc
    tools.qdisc_add(PUBLIC_IF, "1:", "htb", default=1000)
    # Creating the main branch (htb)
    tools.class_add(PUBLIC_IF, parent="1:0", classid="1:1", rate=UPLOAD,
                    ceil=UPLOAD)

{'fraction_non_alphanumeric': 0.11235804943219772, 'fraction_numerical': 0.04382097528390114, 'mean_word_length': 2.3614728334081723, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5955256', 'n_tokens_mistral': 2844, 'n_tokens_neox': 2511, 'n_words': 638}