network-simulator
simulate a low-level computer network
one-way example
This network forwards connections along a one-way linear path:
var sim =for var i = 0; i < 20; i++ {var node = simnode}ifor var i = 1; i < 20; i++simlinki-1 + ':eth1' i + ':eth0'simnodes19simnodes4
ip example
This network sends IP messages for simple routing across a linear chain:
var sim =var ip =for var i = 1; i <= 20; i++ {var node = simnodenode{return {var packet = ipvar octets = packetdestinationIpif packetdestinationIp === '192.168.1.' + inodeelse if lt && i > octets3nodeelse if gt && i < octets3node}}}ifor var i = 1; i < 20; i++simlinki + ':eth1' i+1 + ':eth0'simnodes3simnodes16
api
var Simulator =
var sim = Simulator()
Create a new simulator instance sim
.
var node = sim.createNode(key, ifaces)
Create a network node identified by a string key
and an array of string
interface names ifaces
.
sim.nodes
Look up a previously created node by its key.
sim.link(a, b)
Wire the network interfaces for a
and b
together.
a
and b
should be strings with a colon separator: key:iface
.
node.send(iface, buf)
Send buf
out iface
. A 'message'
event is sent to any linked interfaces.
node.link(iface, target, targetIface)
Wire targetIface
on target
(a node instance) to the local iface
.
node.on('IFACE:message', function (buf) {})
When data is sent to IFACE, this event fires.
install
npm install network-simulator
license
MIT