1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Script for Xbox Live: Detect and Make QoS Changes

Discussion in 'Tomato Firmware' started by AaronCompNetSys, Jan 14, 2009.

  1. AaronCompNetSys

    AaronCompNetSys LI Guru Member

    Update:
    It turns out the best way to detect an Xbox is to check the ARP table on the router. Then you can run a command to limit something. This script assumes the following:
    • The Xbox 360 has a Static IP of 192.168.1.6
    • Anytime the Xbox unit is turned on the script will activate
    What the script does:
    1. Runs a "ip neighbor" command
    2. Searches the result for the IP address, setting the boolian result to "check"
    3. Runs a command if true or false
    Code:
    check=`ip neighbor | grep 192.168.1.6 > /dev/null; echo $?`
    if [ $check -eq "0" ]; then
    wget -O /dev/null http\://username\:password\@192.168.1.3:5190/gui/\?action\=setsetting\&s\=max_ul_rate\&v\=5\&s=max_dl_rate\&v=5 2> /dev/null
    else
    wget -O /dev/null http\://username\:password\@192.168.1.3:5190/gui/\?action\=setsetting\&s\=max_ul_rate\&v\=0\&s=max_dl_rate\&v=0 2> /dev/null
    fi
    Enjoy! :biggrin:

    I am a current Tomato user, and have been using it for its great QoS with HTTP, Bitorrent, SSH, and POP.

    I have noted that the QoS is not aggressive enough to ensure that my high rated connections (Xbox Live) are never strangled by my low connections (Bittorent). They are identified very fast, with IP defined rules, it just isn't good enough. The QoS does work as designed, but any time my utilization is over 50% my ping time also suffers, due to the crappy DSLness.

    I would like a script to run every 5 minutes to look for connections on an internal IP (hostname=Xbox360;192.168.7), and when detected limit the speed of Bittorrent (hostname=BitBox;192.168.1.3), or even if better SSH(cygwin) into it and send a term signal to uTorrent.exe When no connections are found, set a variable switch and try to restart the process or unlimit the IP bandwidth, checking again if possible to see if it started.

    I'm not all that skilled with linux scripting, but am very willing to learn. I assure you lots of people would be using a script like this :biggrin:

    Can someone create a script, or at least get me started? Thank you for your time, from the gaming community!
     
  2. AaronCompNetSys

    AaronCompNetSys LI Guru Member

  3. astehn

    astehn LI Guru Member

    I can't help you with the script because it's over my head, but I'd be happy to look over your QoS settings if you'd like to post them.
     
  4. AaronCompNetSys

    AaronCompNetSys LI Guru Member

    Thank you for the response, but my QoS settings work great, as the designers intended. My problem is a bit above and beyond shuffling some packets around, its more of a saturation problem. My DSL doesn't preform too well when saturated at near 100%. All the packets get though just fine, just at a slight delay. That is just unacceptable with modern gaming.

    But just to tickle your fancy here it is anyway:
    Code:
    Match Rule			Class		Description
    From 192.168.1.66		High		Xbox Live
    		
    Dst Port: 53			Highest		DNS
    Transferred: 0 - 2KB		
    		
    Dst Port: 80,443,22		Medium		WWW, VNC, HTTPS, SSH
    Transferred: 0 - 512KB		
    		
    Dst Port: 80,443,22		Low		WWW (25MB+), RSYNC
    Transferred: 25000KB+		
    		
    Dst Port: 53			E		DNS (2K+)
    Transferred: 2KB+		
    		
    Port: 5190,5894,30954		Lowest		Incoming Bittorrent
    From 192.168.1.93		
    Src Port: 1000-5200		Lowest		Outgoing Bittorrent
    		
    		
    L7: bittorrent			Lowest		Outgoing Bittorrent
    		
    IPP2P: BitTorrent		Lowest		Outgoing Bittorrent
    		
    From 192.168.1.95		Lowest		iMac Bittorrent
    
    Max Bandwidth	650kbit/s
     
    High	  520 - 650 kbit/s
    Highest	  65 - 650 kbit/s
    Medium	  32 - 650 kbit/s
    Low	  19 - 650 kbit/s
    Lowest	  13 - 585 kbit/s
    Class A	  6 - 325 kbit/s
    Class B	  6 - 260 kbit/s
    Class C	  6 - 195 kbit/s
    Class D	  6 - 130 kbit/s
    Class E	  13 - 163 kbit/s
    
     
  5. az2008

    az2008 Addicted to LI Member

    Set your QoS Max Bandwidth down to 90%? Or, 80%?

    Mark
     
  6. slow

    slow Addicted to LI Member

  7. kardzzz

    kardzzz Addicted to LI Member

    You should try moving all bit torrent classification down to your {A, B or C} from Lowest (try A first and move down as you test). Lowest has upto 90% of the incoming bandwidth and this could strangle your connection.
    All other non-classified traffic will then fall into Lowest; I would also put Lowest at 13-450.
     
  8. kardzzz

    kardzzz Addicted to LI Member

    This may work, although I haven't tested it. Insert into your scheduler.
    Code checks if the XBOX IP is active, if yes it IPTABLE 'inserts' a block on the BT IP, else it deletes the block...


    #Checks if IP is active and do some task
    if [ -n "`ping -c 1 -w 1 192.168.1.7`" ]; then
    iptables -I FORWARD --aaddr 192.168.1.3 -j DROP
    else
    iptables -D FORWARD --aaddr 192.168.1.3 -j DROP
    fi



    the following keep the BT box open but cuts the UDP and TCP limit right down


    if [ -n "`ping -c 1 -w 1 192.168.1.7`" ]; then
    iptables -I FORWARD --aaddr 192.168.1.3 -p ! tcp -m connlimit --connlimit-above 5 -j DROP
    iptables -I FORWARD -p tcp --syn --aaddr 192.168.1.3 -m connlimit --connlimit-above 30 -j DROP
    else
    iptables -D FORWARD --aaddr 192.168.1.3 -p ! tcp -m connlimit --connlimit-above 5 -j DROP
    iptables -D FORWARD -p tcp --syn --aaddr 192.168.1.3 -m connlimit --connlimit-above 30 -j DROP
    fi



    I'm sure a linux pro will help clean that code up.
     
  9. astehn

    astehn LI Guru Member

    You should really think about getting rid of your L7 and IPP2P rules altogether, as using these algorithms for QoS slows things down considerably by significantly increasing processor load (as explained in the Tomato Wiki http://en.wikibooks.org/wiki/Tomato_Firmware#QoS). It may be causing your increase in latency.

    A better strategy is usually to classify whatever is NOT Torrent traffic, i.e. whatever you want to give a performance boost to. You can arrange these things in order of preference, essentially like you've already done. Then everything that DOESN'T match these rules ends up in the default classification, which you can set to LOWEST and give a ceiling of, say, 75-80%. Alternatively, the Tomato defaults do this by assigning a priority of LOWEST to everything operating on ports 1024-65535 (that isn't already classified by rules above it). Either way, I second the recommendation above to set the cap for your torrents at no higher than 80%, precisely to avoid the saturation problem you're speaking of.
     
  10. AaronCompNetSys

    AaronCompNetSys LI Guru Member

    First, a few comments about those recommendations for changing my QoS settings:
    Changing Max bandwidth: you guys obviously don't use bittorrent much, how could I possibly use just part of my connection at all times? :biggrin:
    And the L7 and IPP2P rules unfortunately are required. If you have manually watched a swarm recently, you will notice some of the connections on goofy ports like 80 and 443 for bittorent, coming from China and other firewalled places. Clever huh? While I will gladly use their bandwidth, I still have to identify the connections eventually. And according to the wiki manual, the other rules use less CPU and quickly identify the connections I care about. Even if the rules don't work fast, the connections are default to medium or low, which is below High automatically.
    Setting the %to and %from for the lower levels: thats the same as capping max bandwidth in my setup.
    This looks very promising, thank you very much! I'll try it out soon. Disabling the IP won't work, I don't want to cut out all the other services running on the bitbox. I dunno if I can pick a number of connections that will correctly limit it, 'cause uTorrent is smart enough to utilize full bandwidth on just one connection if needed :(

    I wonder if I can get dual IP's working for one host, and force uTorrent to bind to a new IP. Then I can use your IP killer to cut off that IP temporarily. I'll work on that too.
     
  11. AaronCompNetSys

    AaronCompNetSys LI Guru Member

    Oh and another setting I have tried with limited success, is capping the download speed, because the saturation problem exists on the download side as well as the upload side! Its kind of funny how it acts exactly the same when under full saturation.

    Note: I know this doesn't work all that great. I just tried it anyway.
    Code:
    Inbound Limit
    Max Bandwidth	3900 kbit/s
     
    Lowest	 2,574 kbit/s
     
  12. jersully

    jersully LI Guru Member

    Yes, but they're communicating with your bittorrent client on the ports that you specified which would still allow for your outbound QoS to work properly.

    Bittorrent has been working well with my QoS without L7 or IPP2P for many months now.
     
  13. colinrocks

    colinrocks Addicted to LI Member

    If you're using uTorrent (a fine piece of software) then you might be interested in the webui it now has - a simple http call to your PC running uTorrent webui will cap your upload/download rates.

    For example, to limit your torrent bandwidth from a Tomato script to 10 kbyte/sec up and 20 kbyte/sec down, simply use:

    wget "http://utorrentmachineip:utorrentport/gui/?action=setsetting&s=max_ul_rate&v=10&s=max_dl_rate&v=20"

    To lift the limits, set 10 and 20 above to 0. You can change any setting, and (with a bit of logic) pause downloads, etc too. Very handy!

    Cheers,
    Colin
     
  14. AaronCompNetSys

    AaronCompNetSys LI Guru Member

    Holy cow, I didn't know you could send get HTTP commands to uTorrent! That would be perfect!
    I do use the excellent WebUI. I'll try it out, still haven't had time, but I expect good results with this one.
     
  15. AaronCompNetSys

    AaronCompNetSys LI Guru Member

    So I think I have it! So far with my simple test, it appears to be working. I haven't booted the Xbox, but I'll find out soon enough. Here she is:

    Scheduler: Run every 3 minutes
    Code:
    #Checks if IP is active and do some task
    if [ -n "`ping -c 1 -w 1 192.168.1.6`" ]; then
    wget -O /dev/null http\://username\:password\@192.168.1.3:999999/gui/\?action\=setsetting\&s\=max_ul_rate\&v\=5\&s=max_dl_rate\&v=5 2> /dev/null
    else
    wget -O /dev/null http\://username\:password\@192.168.1.3:999999/gui/\?action\=setsetting\&s\=max_ul_rate\&v\=0\&s=max_dl_rate\&v=0 2> /dev/null
    fi
     
  16. AaronCompNetSys

    AaronCompNetSys LI Guru Member

    Dang it. The Xbox 360 does not respond to pings. I wonder if I can get ARP to work.
     
  17. AaronCompNetSys

    AaronCompNetSys LI Guru Member

    So since it doesn't respond to ARP requests, it looks like I can check the ARP cache for entries it has made. Tomato has arping but not arp. This command below shows my 360 is powered up. How do I use this in a conditional statement, and how long does it take for the entry to clear, once the device is offline? I think the status switches to "Stale" and then "Delay" after its offline.
    Code:
    # ip neighbor
    192.168.1.6 dev br0 lladdr 00:1d:d8:48:73:bd REACHABLE
     
  18. AaronCompNetSys

    AaronCompNetSys LI Guru Member

    Here is what I am trying now, using the "ip neighbor" command. It appears that this list is updated pretty fast, so it shouldn't be a problem on reaction time. I'll try it out tonight.
    Code:
    check=`ip neighbor | grep 192.168.1.6 > /dev/null; echo $?`
    if [ $check -eq "0" ]; then
    wget -O /dev/null http\://username\:password\@192.168.1.3:5190/gui/\?action\=setsetting\&s\=max_ul_rate\&v\=5\&s=max_dl_rate\&v=5 2> /dev/null
    else
    wget -O /dev/null http\://username\:password\@192.168.1.3:5190/gui/\?action\=setsetting\&s\=max_ul_rate\&v\=0\&s=max_dl_rate\&v=0 2> /dev/null
    fi
     
  19. AaronCompNetSys

    AaronCompNetSys LI Guru Member

    Updated first post. I've been using this script successfully all week :)
     
  20. kardzzz

    kardzzz Addicted to LI Member

    Aaron, I'm using the same code for my uTorrent and it works perfect. I know bitcomet 1.16> has a webui, did you manage to find a way to control the u/l and d/l limits via script?
    thx
     
  21. AaronCompNetSys

    AaronCompNetSys LI Guru Member

    I only investigated using uTorrent, I didn't look into BitComet. The commands as shown only work for uTorrent, I'm sure they would work if you could figure out what the commands are for BitComet.
     
  22. david101

    david101 Addicted to LI Member

    although perhaps not the right thread i might as well add this here incase soemone else might want it. also, maybe for peopel to critisize it and maybe i can make it better haha

    it seemed that regardless of protocol, whenver my dl speed was more than 70% my ping times in games would increase by more than 10ms (yes i want it to be less than that) so i wrote the following script to detect when my game is runing (UT using port 7777 for 90% of servers) and then throttle back qos...and increase it otherwise (i found myself constantly turning qos on/off before this)

    i also disabled performing nvram commit in debugging so that i won't wear it out

    the code:
    Code:
    while sleep 60; do (if [ `grep -c 'dport=7777 ' /proc/net/ip_conntrack` -ge 1 -a `nvram get qos_ibw` -eq 9999 ]; then (nvram set qos_ibw=960;service qos restart) fi; if [ `grep -c 'dport=7777 ' /proc/net/ip_conntrack` -eq 0 -a `nvram get qos_ibw` -eq 960 ]; then (nvram set qos_ibw=9999;service qos restart) fi;); done
    obviously change dport to the game port your using and the qos limits to whatever your connection is (mine is 1Mbit)
     
  23. AaronCompNetSys

    AaronCompNetSys LI Guru Member

    Thanks David. More ideas for queries and commands to run, mix and match for your own gaming needs.
    FYI newbs: David's detects used ports and then changes internal Tomato QoS settings, which then requires a restart of the internal QoS service. I added some white space to David's script so you can read it better :)
     
  24. david101

    david101 Addicted to LI Member

    thanks Aaron! this was actually my first script and, since im a noob, the only way i was getting it to work was in that one big line haha.
     
  25. AaronCompNetSys

    AaronCompNetSys LI Guru Member

    So I have now deployed this at my friends house, and he has 2 Xbox360's! Should be simple right? Of course I screwed it up the first try. Here is what should work, I only tested it on my router.
    Code:
    check=`ip neighbor | grep 192.168.1.6 > /dev/null; echo $?`
    check2=`ip neighbor | grep 192.168.1.55 > /dev/null; echo $?`
    if [[ $check == "0" ||  $check2 == "0" ]]; then
    wget -O /dev/null http\://username\:password\@192.168.1.3:9999/gui/\?action\=setsetting\&s\=max_ul_rate\&v\=5\&s=max_dl_rate\&v=5 2> /dev/null
    else
    wget -O /dev/null http\://username\:password\@192.168.1.3:9999/gui/\?action\=setsetting\&s\=max_ul_rate\&v\=0\&s=max_dl_rate\&v=0 2> /dev/null
    fi
     
  26. AaronCompNetSys

    AaronCompNetSys LI Guru Member

    More complexities this week. We have switched to using Skype while on Xbox Live now, to increase the quality of voice. The strange thing was, that while there was a ton of bandwidth available, we still got lag on conference calls! Doing one call at a time is fine, but doing multiple calls or hopping around seemed to be slow. Closing uTorrent altogether seemed to help, when it dawned on me. I have experienced problems with DSL modems keeping tabs on lots of connections at the same time, and I personally crank up the number of connections on uTorrent freakishly high, to deal with troublesome torrent swarms. I did this at my friend's house as well as mine. So what to do? Decrease the number via script. This will give the modem some breathing room. How much of this is fact, I have no idea. I speak only from experience and common sense.

    Here is my modified wget statement, tested to work changing the setting. Not tested in generating results yet :)
    Code:
    wget -O /dev/null http\://username\:password\@192.168.1.3:9999/gui/\?action\=setsetting\&s\=max_ul_rate\&v\=5\&s=max_dl_rate\&v=5\&s=conns_globally\&v=50 2> /dev/null
    And a note to moderators:
    This thread appears to not be indexed by Google, as I and others have tried to find it, failing miserably. I had to sign in just to grab the link. Care to enable that if possible?
     
  27. AaronCompNetSys

    AaronCompNetSys LI Guru Member

    Update: uTorrent 2.x now enables a new authentication measure by default, which is not compatible with this script. Simply turn it off as mentioned in this thread. Access Options...Preferences...Advanced then set webui.token_auth to false.
     
  28. AaronCompNetSys

    AaronCompNetSys LI Guru Member

    My network has been de-evolving and needed a new version, this time running on my Ubuntu server. Here is my latest script. My Xbox resides on a different switch and doesn't see its MAC all the time until specifically requested. Invoking ping triggers its visibility without having to escalate privileges of the shell. The connection limit and the repeating of the script somehow hung up the utorrent process leaving open connections, I think this version fixed that. I've forgotten how and why, meh.

    Code:
    #!/bin/bash
    ping 192.168.1.147 -c 1
    check=`ip neighbor | grep 00:1d:d8:8e:JJ:Q7 > /dev/null; echo $?`
    if [[ $check == "0" ]]; then
    wget -O /dev/null http\://username\:password\@192.168.1.3:5190/gui/\?action\=setsetting\&s\=max_ul_rate\&v\=1\&s=max_dl_rate\&v=1 2> /dev/null
    else
    wget -O /dev/null http\://username\:password\@192.168.1.3:5190/gui/\?action\=setsetting\&s\=max_ul_rate\&v\=50\&s=max_dl_rate\&v=500 2> /dev/null
    fi
     

Share This Page