npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

netsim

v1.0.4

Published

Basic Network Simulator for Javascript

Downloads

2

Readme

NetSim.JS

NetSim is a network simulator for Javascript.

Installation

Add the project to your current npm project with

npm install netsim --save

Creating a Simulation

In order to create a network simulation, you must first create a network topology to simulate. Then you define app logic at given nodes in the network. Finally you run the simulation!

Defining a network

A network is simply a list of edges in the network where an edge is a Javascript object with src and dst string attributes. All nodes in the network are inferred by netsim from the edges.

Optionally, you can define packetLoss, latencyMean and latencySigma for each edge. packetLoss denotes the likelihood of a packet being dropped while latencyMean and latencySigma define the normal distribution defining the latency of the given edge.

Example network definition:

[
{src: 'node1', dst: 'node2'},
{src: 'node2', dst: 'node3', packetLoss: 0.5},
{src: 'node3', dst: 'node4', latencyMean: 100, latencySigma: 7}
{src: 'node1', dst: 'node4', packetLoss: 0.4, latencyMean: 100, latencySigma: 0}
]

Adding apps

All apps must have a uuid. The uuid corresponds to the given node in the network topology where this app logic is to be run.

Along with a uuid, apps can optionally define onStart and onMessageReceived methods. onStart is a function to be called at the start of the simulation while onMessageReceived is the event handler for receiving messages.

Example app:

node1 = netsim.addNode({uuid: 'node1',
                        onStart: function() {
                            this.sendMessage('node4', 'Marco!');
                        },
                        onMessageReceived: function(id, msg) {
                            console.log(this.uuid+' received msg: '+msg);
                        } });

Running the Simulation

After defining the network, the simulation can be run with

netsim.simulate();

Examples

var NetSim = require('netsim');
var netsim = new NetSim(topology);

netsim.addNode({uuid: 'node1',
               onStart: function() {
                   this.sendMessage('node4', 'Marco!');
               },
               onMessageReceived: function(id, msg) {
                   console.log(this.uuid+' received msg: '+msg);
               } });

netsim.addNode({uuid: 'node4',
               onMessageReceived: function(id, msg) {
                   console.log(this.uuid+' received msg: '+msg);
                   this.sendMessage('node1', 'Polo!');
               } });

netsim.simulate();

More examples can be found in examples/ on the github page!