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

Toastman - need to add delay/latency to specific ip - help

Discussion in 'Tomato Firmware' started by Shane, Nov 8, 2012.

  1. Shane

    Shane Serious Server Member

    As the title says, I need to add latency (not constrict bandwidth) to a specific ip. Like say 200-300ms. I would assume that the bandwidth limiter would be the most logical place for this. Should I be using the TCP Limiter and UDP Limiter to achieve this? If so, can someone give me some tips on how? Thanks much in advanceā€¦
     
  2. koitsu

    koitsu Network Guru Member

    First the less technical part: what exactly are you trying to solve/accomplish by this? I'm not questioning your need for it, but knowing what the situation matters. For example, if you're trying to limit a single person on your LAN who's being a brat, there are specific ways to solve that (technically and socially :) ). But if you're trying to, say, "induce latency" for someone attacking you on the Internet, solving that is done very very differently (not to mention rate-limiting and packet loss rules aren't going to necessarily help you, since you have no control over how much traffic they send your router).

    Now for the technical parts:

    I'm not sure how to do this via GUI -- I'm absolutely certain folks here on the forum can provide some details on how to do that -- but the CLI command you probably want to use to accomplish this is tc. There is also an alternate option (keep reading).

    http://linux.die.net/man/8/tc

    Here's an example, but please do not just blindly run these commands -- you will need to have some familiarity with the existing rules and configurations, plus network interface names:

    http://serverfault.com/questions/389290/using-tc-to-delay-packets-to-only-a-single-ip-address
    http://stackoverflow.com/questions/614795/simulate-delayed-and-dropped-packets-on-linux

    Like I said, it can get complex:

    http://www.cyberciti.biz/faq/linux-traffic-shaping-using-tc-to-control-http-traffic/

    As for the alternat option: at the stackoverflow.com URL, there's a comment there that talks about using iptables instead to induce packet loss (which is effectively a form of latency/delay), so that might also work for you. Since I'm not familiar with tc myself (I'm more familiar with FreeBSD's pf and how to induce this kind of latency/delay), I can't really say which is the better choice. In both cases you can limit on a per-IP basis.
     
  3. gutsman7

    gutsman7 Networkin' Nut Member

    You need netem for this but it is not included in the current set of tables used in tomato.
     
  4. Shane

    Shane Serious Server Member

    First, thank you both for replying. Second, I saw tc and netem today while researching this and now I know that neither is included in tomato While I'm not a complete moron, I don't have the networking technical prowess to go mucking around. I could run a command to turn on/off the delay though, no problem, if someone gave it to me, heh.

    The reason I'm asking, and this may seem trivial, is for gaming on xbox. I play Battlefield 3 quite a lot and I have a very good but not great connection. The latency compensation system that is implemented in the game punishes people with good connections. I simply want to do some testing to see if I can affect how the system is applied so I can avoid so many insta-deaths. It seems I am 1 or 2 seconds behind in the game most of the time, even when the xbox is connected directly to the modem.

    Tonight, I turned on the bandwidth limiter and this time used the TCP and UDP limit, but I'm not exactly sure how those work. For TCP limit I used 60 and UDP 2/s (2 connections per second?). I'm pretty sure only the UDP matters for xbox gaming. It seemed to be a bit better but who knows, I'll have to try it several nights in a row to see. It's difficult to explain but it gets very frustrating dying instantly when you have a 30/5 ~30ms connection that should be fine for gaming.
     
  5. rs232

    rs232 Network Guru Member

  6. rs232

    rs232 Network Guru Member

    P.S. without netem the only think I can think about is to put the traffic into a QoS class and limit the bandwidth of that specific class. The indirect effect of this action will add latency but it's difficult to quantify as throughput/latency relate in a non linear functions.
     
  7. gutsman7

    gutsman7 Networkin' Nut Member

    Games use a burst udp method and run mainly on udp. when you boot your game on at so called start screen what happens is the game servers generally shoot gamestate packets with updates and patches attached. After that lobby and matchmaking to interactive gameplay, tc is definetly in tomato its how you summoned bandwith limiter and qos standard. Also xbox's main port for its so called open nat and gaming is udp 3074. All others follow but this is the main one so one alternative way to change your online expirience to improve force recieve a set amount of packets intead of say 40 to 50 carrying 50bytes a pop. First remove all your current limits to your console especially the tcp udp limits you mentioned. those can effect other maybe vital online browsing. Then give high prio to in qos to udp 3074 both src and dst. Next insert this script in your Firewall commands, iptables -t nat -I PREROUTING -p udp --dport 3074 -m connlimit --connlimit-above 1 -j DROP then proceed to run service firewall restart in command box. If 1 is to drastic then increase this to no more than 3 to 6 and youll improve your online expirience dramatically.
     
  8. Shane

    Shane Serious Server Member

    I fooled with limiting the bandwidth but I know that has very little to with it. I'm sure there's a way of running QOS low priority and then saturating the line to achieve some sort of latency or udp flooding my router but you're right, it's not quantifiable.
     
  9. Shane

    Shane Serious Server Member

    Thanks for the info. I inserted the script and added the port to my xbox QOS rule, but won't be able to test it until later. Can you elaborate just a bit on the script so I can understand/learn? How does this affect gaming? I assume that we are limiting udp 3074 connections to 1, and all others drop. Also, how much overhead does QOS add? I've been avoiding using it since there isn't much other traffic on my lan when I play (late at night).
     
  10. Porter

    Porter LI Guru Member

    Shane:
    Sorry to hear that the BF3 developers think this is a good idea. I think they mean well but it might not be as fair as intended, judging from what I've been reading.
    What you want to do is something very unusual, as you might imagine. Enabling netem in the kernel certainly leads to larger firmware images. This is a problem since routers are always short on storage. All the other features in Tomato need storage, too, but most of them are being use by a lot of people. Sometimes there are even different builds for people with different needs because of the limited storage. I'm not saying it is impossible to enable netem. I'm just saying that it probably won't be integrated into Tomato because it's something rather exotic. If you want to get a firmware with netem enabled you will have to enable netem in the kernelconfig as described here: http://www.linuxfoundation.org/collaborate/workgroups/networking/netem and then compile your own firmware.
    From what you are saying I get the impression that you might not be able to do this yourself, so maybe somebody else (rs232?) might help you.

    While the above might be very complex let me suggest something that's almost too obvious: why not induce some lag simply by doing what usually causes lag? Start a download, use a download manager and tweak your download just right so that you get the desired lag... I would recommend a torrent client with some big Ubuntu isos. If you get it right you might not even experience packet loss.
     
  11. koitsu

    koitsu Network Guru Member

    I'm not sure why there is a focus on netem here when I've already mentioned and provided references to two tools which are already included in TomatoUSB (at least Toastman build tomato-K26USB-1.28.0500.5MIPSR2Toastman-RT-N-Ext.trx) -- tc and iptables -- which both offer inducing latency on a per-IP basis. Can someone explain why netem is needed?
     
  12. Shane

    Shane Serious Server Member

    I guess I could run torrents to saturate the line but I would end up using a ton of bandwidth. It will be worth a try as a last-ditch though. Wouldn't it be easier/better to semi-ddos my router with a udp flooder? Seems like that would be more controllable.

    I understand that my situation is outside the norm. Compiling my own probably isn't feasible for me and I wouldn't want someone to spend time doing it if there are other ways to achieve this.
     
  13. Shane

    Shane Serious Server Member


    I'm not focusing on netem at all, just trying to learn from you guys a bit. I re-read those links you sent after looking over the tc man pages and gutsman7's post. Now they make sense slightly more and I know enough to be dangerous :) I assume these tc commands are run in Tools>System>Execute System Commands.

    Are you saying that I can run this command as-is (with the correct ip of course)?
    tc qdisc del dev eth0 root
    tc qdisc add dev eth0 root handle 1: prio
    tc qdisc add dev eth0 parent 1:1 handle 2: netem delay 250ms
    tc filter add dev eth0 parent 1:0 protocol ip pref 55 handle ::55 u32 match ip dst 192.168.1.10 flowid 2:1

    What command would I run to undo the above?
    tc qdisc del dev eth0 root
    tc qdisc add dev eth0 root handle 1: prio
    tc qdisc add dev eth0 parent 1:1 handle 2: netem delay 0ms
    tc filter add dev eth0 parent 1:0 protocol ip pref 55 handle ::55 u32 match ip dst 192.168.1.10 flowid 2:1
     
  14. Porter

    Porter LI Guru Member

    I could be wrong, but where does tc offer adding a specific delay on packets? As far as I know it doesn't. Sure, tc does delay packets but not in a controllable manner. Normally traffic is shaped to a specific bandwidth and to achieve this the qdisc delays traffic so it doesn't use more bandwidth than configured. I didn't find something like: add 200ms of delay to my packets. Therefore netem is needed and what's already in Tomato isn't sufficient.
     
  15. koitsu

    koitsu Network Guru Member

    Edit: Oh, I see, tc actually has the "netem" command in it. Cute. Christ I love how Linux "shims" all this stuff together (what could possibly go wrong?)

    Okay, I guess in the case of tc, yes, it does look like some netem thing does need to be built. So much for using that then. :(
     
  16. Porter

    Porter LI Guru Member

    Ok, using a lot of bandwidth might not be the best idea. But then let's improve on that thought: put your torrent traffic and your BF3 traffic in the same class and limit this class to some lower kbit value, maybe 400kbit/s (outbound and inbound) and see how that goes. Don't forget to tell your torrent client to use a specific port.

    Instead of using a torrent client you could upload a file to a specific host. But make sure that the client doesn't use a standard port so you can classify the traffic. This might be an even better solution, because torrent traffic can be volatile - at least to some extend.
     
  17. gutsman7

    gutsman7 Networkin' Nut Member

    tc qdisc del dev command is correct to undo these parent class. I heard battlefield 3 gives you a option to select a server, if so select the most furthest ones possible.
     
  18. Shane

    Shane Serious Server Member

    Thanks for the help guys. I guess this is going to take some trial and error.
     

Share This Page