7

What is the best way to simulate a network in Java?

I'm in the early stages of a networked peer to peer project, and to determine some of the required characteristics of the clients I'd like to be able to simulate 100+ instances concurrently on my PC.

Ideally I'd like to create a "simulation" version of the sockets, with their own inputs and output streams. Eventually, I'm going to use these streams for data transfer instead of just moving data around between java objects, so what I'm wanting to simulate is the kind of latency, data loss and other errors you might get in an actual network.

Ideally these simulation methods would be very close to the actual stream standards of java.net.*, so I wouldn't need to do much of a rewrite in order to move from simulation to the actual client.

Can anyone point me in the right direction?

Troy Alford
  • 26,660
  • 10
  • 64
  • 82
N. McA.
  • 4,796
  • 4
  • 35
  • 60

3 Answers3

3

You can use Akka to create millions of Actors on a single machine, then organize communication between them similar to 'real' network.

Here's an example project: https://github.com/adelbertc/scalanet

Arjan
  • 22,808
  • 11
  • 61
  • 71
vitalii
  • 3,335
  • 14
  • 18
  • What happened? Did you read the documentation? I see no emails on the mailinglist, don't be afraid to ask for help to get unstuck. The majority of Akka users are using it from Java, so I'm pretty sure it's not bs. Documentation: http://doc.akka.io/docs/akka/2.1.2/ – Viktor Klang May 11 '13 at 16:05
  • Sorry, I'm struggling to make sense of your comment. Indeed I have posted a question on mailing list some time ago, got an answer and more or less satisfied with it. Now when I do async IO I'm reading akka docs on regular basis, but because actors are in a sense a paradigm shift I have to read chapters more than once to obtain a complete understanding))) Also I'm using Akka with scala. – vitalii May 14 '13 at 11:19
1

Well you don't really need to use any tools but put your brains to design it better.

You need interfaces for the under lying communication framework.

All you need is to mock/substitute the real implementation with a dummy one once you have coded against the interfaces.This dummy implementation can introduce features like latency,dummy data etc.

You can go with spring container.You can write some dummy server sockets in the container to simulate conversations between multiple instances or better use a web container to take that headache away from you.

Rohitdev
  • 866
  • 6
  • 15
  • While this is the first thought that comes to my mind as well, the question states that he wishes to simulate latency and data loss. That'll be nontrivial if there's no actual network in between. – flup May 21 '13 at 22:45
  • 1
    And once you designed it good enough to be able to put a mock network behind it, you need to actually mock the network - and thus pretty much implement a tool like he asks for. – kutschkem May 23 '13 at 15:03
  • 1
    Latency and data loos is equivalent to putting a thread to sleep and deleting some data from the underlying data structure. If you simulate/mock you can test your implementation in a very fine tuned manner(i.e. highly configurable) but if you depend on real network for simulation i'm not sure you can do the same. – Rohitdev May 24 '13 at 09:45
0

For simulation purposes you may want to check Omnet++, I'ts great for big scaled simulations with built in data analysis/statistics tools. Writing is similar to c++, see the tutorials it's pretty straight-forward.

Example 6 hosts network (Taken from Omnet++ tutorial)

drtf
  • 1,886
  • 2
  • 21
  • 19