Net-runner

Overloading network switch with 20 TCP clients

1 year ago by Seva D. (sabrinarempel7@gmail.com)

In this short example, we're gonna see what happens if we connect 20 hosts with TCP client installed on each of them and the one with TCP server to a single switch and see how it buffers network packets.

Besides the research reasons, this example looks quite amazing, so I dedicated the whole post to it:

const Simulator = require('net-runner-engine');
const path = require('path');

const { Network, Switch, Host, TCPClient, TCPServer } = Simulator;

const dstDir = path.resolve(__dirname, 'files/current');

const net = new Network({
  animeLen: 3, // seconds, default is 10
  populateIP: true,
});

const swtch = new Switch(net, { name: 'Switch' });

const hosts = Array.from({ length: 20 }, (_, i) => new Host(net, { name: `Hosts${i}` }));

hosts.map((e, i) => e.connect(swtch, { sourceIP: `192.168.1.${i}` }));

hosts.slice(1).map(e => e.setupApplication(new TCPClient({
  addr: '192.168.1.0',
  port: 8080,
})));

hosts[0].setupApplication(new TCPServer({
  port: 8080,
}));

net.run(dstDir, { upload: true }).then(url => console.log('[*] uploaded', url));



You can go crazy and replace the switch with a hub and see how it affects the network performance.