简体   繁体   English

在一台计算机上模拟p2p网络流量

[英]Simulate p2p network traffic on a single computer

What is the best way to simulate a network in Java? 在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. 我正处于网络对等项目的早期阶段,并确定客户端的一些必要特性,我希望能够在我的PC上同时模拟100多个实例。

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. 最后,我将使用这些流进行数据传输,而不是仅仅在java对象之间移动数据,所以我想要模拟的是那种延迟,数据丢失以及您在实际网络中可能遇到的其他错误。

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. 理想情况下,这些模拟方法将非常接近java.net.*的实际流标准,因此我不需要进行大量重写以便从模拟转移到实际客户端。

Can anyone point me in the right direction? 谁能指出我正确的方向?

You can use Akka to create millions of Actors on a single machine, then organize communication between them similar to 'real' network. 你可以使用Akka在一台机器上创建数百万个Actors,然后在它们之间组织类似于“真实”网络的通信。

Here's an example project: https://github.com/adelbertc/scalanet 这是一个示例项目: https//github.com/adelbertc/scalanet

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. 您可以使用spring容器。您可以在容器中编写一些虚拟服务器套接字来模拟多个实例之间的对话,或者更好地使用Web容器来消除您的头痛。

For simulation purposes you may want to check Omnet++ , I'ts great for big scaled simulations with built in data analysis/statistics tools. 出于模拟目的,您可能需要检查Omnet ++ ,我非常适合使用内置数据分析/统计工具进行大规模模拟。 Writing is similar to c++, see the tutorials it's pretty straight-forward. 写作与c ++类似,请参阅教程,这非常简单。

Example 6 hosts network (Taken from Omnet++ tutorial) 示例6托管网络(摘自Omnet ++教程)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM