Any good network simulators
Members - Reputation: 300
Posted 24 March 2011 - 04:59 PM
Preferably a software that hooks onto specific apps.
I tried netlimiter but that seems to only limit bandwidth and nothing else.
Anyone know any such software?
Moderators - Reputation: 10075
Posted 24 March 2011 - 05:06 PM
I need something to simulate lag/packet loss/dropped connections for windows.
Try running your Windows instance virtualized under KVM or VirtualBox, and use a Linux-based simulator?
I imagine you can use something like "detours" or a simple replacement of ws2_32 to hook into the applications at the API level, too, but I know of nothing that comes pre-rolled.
Crossbones+ - Reputation: 1782
Posted 25 March 2011 - 03:22 AM
I cant believe that something as simple as a simulator is so hard to do
It's not that hard actually.
All you have to do is write your own proxy that implements a man-in-the-middle attack to route traffic through. That gives you flexibility to:
- delay packets as needed
- drop connections
- modify/corrupt/inject data
The only "hooking" you need to do will be generic detours to make the application connect to your proxy rather than the remote host. That is assuming you cannot change it via a hosts edit or an application specific option.
If you are working with your own application, then you simply implement your protocol so you can process packets from the data stream then relay them to the remote host. If you are working with 3rd party applications, then you will need to know their protocol first to be able to work with their packets.
If that is not possible, then you will only be able to simulate dropped connections and delay the entire network stream without being able to process individual packets. As long as the application you are working with does not implement specific anti-man-in-the-middle attack logic, such as the things mentioned in the "defenses against the attack" section on Wikipedia, or does not employ anti-tamping mechanism like GameGuard, XTrap, Themida packing, etc... this method works very nicely.
Another potential pitfall is if you are working with a application (such as a game) that performs a connection hand off and you don't know the packet protocol, then you will have to do some messy hacks to be able to continue working with the traffic stream at each hand off. It's certainly possible and works, but it is nowhere as elegant as having full control over the protocol.
Once you have your basic proxy done, then you can just add a GUI (or console if you rather work that way) to allow you to do the stuff you need to simulate the network. It's all a matter of logic from there. For example, adding latency is as simple as buffering all packets to a queue rather than dispatching immediately to the other side then checking a timestamp to know when to send it. Connection dropping can be as simple as forcefully closing the socket, but you will not be able to simulate certain types of connection dropping unless you used other tools. I.e., to simulate a connection where the host simply has a power loss, you pretty much need to simulate that yourself on a different machine. That is why running a ritualized instance, such as VirtualBox is great, as hplus mentioned. Likewise for application crashes or network failures.
It might seem like a lot of work at first glance, but these are tools you should already have at your disposal when you are working on a network related project. Existing tools are certainly useful as well, but you can really get the most out of custom tools that cater to your needs exactly. Basically it's a large one time up front investment that pays for itself over time as you develop more and more stuff that you can reuse the tools on. I've had my own generic tools in the past that proved to be quite useful in this regards. Don't expect to be able to find the perfect solution right off the bat. I've played with different designs for this stuff for many years and am still trying new approaches and methods to find the perfect solution for my needs. Getting something that "just works" is simple enough though and the most practical approach to take in your situation.
That should get you pointed in the right way, I hope. Just code a simple traffic relay proxy in whatever language you are using first. Once that is done, you can add your protocol specific logic to break the data stream into packets. Finally, you can add your custom logic to do the tasks you want. You have it pretty easy if all you are working with is your own protocols. You do have to be careful of some 3rd party TCP protocols since they might not be implemented correctly. TCP has been around a very long time, but I still come across games (f2p mmos) that incorrectly treat TCP as a packet based protocol and it is very annoying to work with since everything breaks when you do not handle the stream the same way the client does (Nagle algo, send/recv buffer sizes, etc..). Hopefully your own protocol does not make those mistakes.
If you need any more ideas on architectures or whatever for such a program feel free to ask. I've been working with this stuff for the past 4 years now trying out different methods, languages, libraries, etc.. to try and come up with the 'ultimate' tool so I've learned a lot along the way. Right now, my focus has been C# (.Net 4.0) + IronPython + Construct and I am extremely pleased with results so far in my early progressions with it. While I can't recommend such experimental ideas for when you have real work to get done, if you are using C++ I'd strongly advise you to checkout boost::asio as your networking core.
The design model they use allows you to do a lot of useful things in the least amount of lines of code. Once you get used to the concepts and the large namespace and write your own wrapper (I talked about mine here) production is greatly increased since you are spending less time worrying about the things boost::asio does for you that you otherwise would if you rolled your own using native Winsock. I spent many years trying to do it myself and after wasting so much time and ending up with such limited code, I finally heeded the advice of people who knew a lot more than me and learned an existing library that took care of everything. I don't regret it one bit and make heavy use of it for my C++ stuff. For example, using my network wrapper my own basic traffic relay proxy code would look like this:
And it's ready to have the protocol processing object dropped in then the custom logic added. So all my work is focused on everything but the underlying network code I'd otherwise have to write if I didn't have my own wrapper already written and wasn't using an existing network library. The advantage of using boost vs rolling my own in this case would be I can easily add multithread support, it's cross platform, and it's a proven library that can be used for larger scale projects (although I can't recommend using my wrapper since there are a few bugs and some specific tradeoffs with the style I used, mostly related to overhead and lackof memory management).
As part of another recent enlightenment I had though reading these forums though, I'm transitioning my tool development to higher level languages because the solutions that I wanted to express through C++ were simply taking too much time, effort, and ended up so mediocre that I just got tired of it. I'll stop rambling, but keep in mind to find the best tools for the job rather than just force a solution through what's most known.You didn't mention what language(s) you are using or which network protocols, but TCP and C++ are what I've had the most experience with so far, so that's what I choose to talk about.
"But I, being poor, have only my dreams. I have spread my dreams under your feet; tread softly, because you tread on my dreams." - William Butler Yeats