All pastes #2467393 Raw Edit

Unnamed

public unlisted text v1 · immutable
#2467393 ·published 2013-10-16 22:40 UTC
rendered paste body

set -x
downlink=2000


dev=eth1
mod_command=modprobe



setup() {
    echo "    loading modules"
    for module in ifb sch_sfq sch_htb sch_ingress act_mirred xt_mark cls_u32 cls_fw;
    do
        if lsmod|grep $module 2>&1 >/dev/null; then
            echo "already loaded";
        else
            $mod_command $module;
        fi
    done

    echo "outgoing device" $dev
}








download() {
    ip link set dev $indev up
    tc qdisc add dev $dev handle ffff: ingress
    tc filter add dev $dev parent ffff: protocol ip prio 1 \
        u32 match u32 0 0 action mirred egress redirect dev $indev

    tc qdisc add dev $indev root handle 1: hfsc default 30
    tc class add dev $indev parent 1: classid 1:1 hfsc sc rate ${downlink}kbit ul rate ${downlink}kbit
    tc class add dev $indev parent 1:1 classid 1:20 hfsc sc rate $((2*$downlink/10))kbit ls rate $((5*$downlink/10))kbit
    tc class add dev $indev parent 1:1 classid 1:30 hfsc sc rate $((8*$downlink/10))kbit ls rate $((5*$downlink/10))kbit
}



download_filters() {
    #match scp
    tc filter add dev $indev parent 1:0 protocol ip u32 \
        match ip sport 22 0xffff flowid 1:20

    


   #league of legends ports
    target="1:20"
    tc filter add dev $indev parent 1:0 protocol ip u32 match ip sport 5000 0xfff8 flowid $target
    tc filter add dev $indev parent 1:0 protocol ip u32 match ip sport 5008 0xfff0 flowid $target
    tc filter add dev $indev parent 1:0 protocol ip u32 match ip sport 5024 0xffe0 flowid $target
    tc filter add dev $indev parent 1:0 protocol ip u32 match ip sport 5056 0xffc0 flowid $target
    tc filter add dev $indev parent 1:0 protocol ip u32 match ip sport 5120 0xff00 flowid $target
    tc filter add dev $indev parent 1:0 protocol ip u32 match ip sport 5376 0xffc0 flowid $target
    tc filter add dev $indev parent 1:0 protocol ip u32 match ip sport 5440 0xffe0 flowid $target
    tc filter add dev $indev parent 1:0 protocol ip u32 match ip sport 5472 0xfff0 flowid $target
    tc filter add dev $indev parent 1:0 protocol ip u32 match ip sport 5488 0xfff8 flowid $target
    tc filter add dev $indev parent 1:0 protocol ip u32 match ip sport 5496 0xfffc flowid $target
    tc filter add dev $indev parent 1:0 protocol ip u32 match ip sport 5500 0xffff flowid $target



        
}





start() {
    stop
    setup
    download
    download_filters
}



stop() {
    echo "    stop()"
    tc qdisc del dev $dev root    2> /dev/null > /dev/null
    tc qdisc del dev $dev ingress 2> /dev/null > /dev/null
    tc qdisc del dev $indev root    2> /dev/null > /dev/null
    tc qdisc del dev $indev ingress 2> /dev/null > /dev/null
}



restart() {
    stop
    sleep 1
    start

}





case "$1" in

    start)
        start
        ;;

    stop)
        stop
        ;;

    restart)
        restart
        ;;

    setup)
        setup
        ;;
    *)

        pwd=$(pwd)
        echo "Usage: test-ts.sh {start|stop|restart}"
        ;;

esac

exit 0








#script that calculates various times between packets
import scapy.all as scapy

import sys


packets = scapy.rdpcap("tmp/lol.pcap")


'''
    time between client and next server packet
   
'''
def timeBetweenClientAndServer():
    #first packet from client
    startTime = packets[0].getlayer("IP").time


    #we start with a client packets time and look for the next server packet
    client = False
    server = True
    for x in range(1,len(packets)):
        p = packets[x]
   
        if client:
            if p.getlayer("UDP").sport != 5106:
                #this is a packet from the client
                startTime = p.getlayer("IP").time
                server = True
                client = False
        if server:
            if p.getlayer("UDP").sport == 5106:
                #this is a packet from the server
                time = p.getlayer("IP").time
                print "time between client and server packet: %.6f " % (time - startTime)
                server = False
                client = True


'''
    time between packets from server:
'''
def timeBetweenPacketsFromServer():

    #packet[2] is network packet 3, first packet with data from server
    startTime = packets[2].getlayer("IP").time

    for x in range(3,len(packets)):
        p = packets[x]
   
        if p.getlayer("UDP").sport == 5106:
            #print "packet number: ", x+1
            #this is a packet from my client
            time = p.getlayer("IP").time
            #print "p.getlayer(IP).time , startTime  %.6f : %.6f: " % (p.getlayer("IP").time, startTime)
            timeNew = time - startTime
       
            print "server: %.6f" % timeNew
            startTime = time



'''
    time between packets from client:
'''
def timeBetweenPacketsFromClient():
    #packets[0] is the first client packet
    startTime = packets[0].getlayer("IP").time

    for x in range(1,len(packets)):
        p = packets[x]
   
        if p.getlayer("UDP").sport != 5106:
            #print "packet number: ", x+1
            #this is a packet from my client
            time = p.getlayer("IP").time
            print "p.getlayer(IP).time , startTime  %.6f : %.6f: " % (p.getlayer("IP").time, startTime)
            timeNew = time - startTime
            print "client: %.6f" % timeNew
            startTime = time

   
if __name__ == '__main__':
    timeBetweenClientAndServer()   
    #timeBetweenPacketsFromServer()
    #timeBetweenPacketsFromClient()