Skip to main content

Event simulator for peer-to-peer experiments

Project description

p2psimpy

Tests

A simple simulator for peer-to-peer protocols based on SimPy.

The library provides means to simulate distributed or decentralized system run over a network. The simulation runs as a multi-agent system each running services and exchanging messages.

Installation

If you have pip installed, just type:

$ pip install p2psimpy 

Simulation example

For each simulation you should specify what each agent should run, the latency for the messages and the physical attributes on an agent.

Here is an example in which peers are connected in a random network, and each peer runs a connection manager. The connection manager periodically pings the connected peers and disconnects them if they are unresponsive.
The simulation looks like this:

import networkx as nx

from p2psimpy.config import Config, Dist, PeerType
from p2psimpy.consts import MBit
from p2psimpy.simulation import Simulation
from p2psimpy.services.connection_manager import BaseConnectionManager

# Locations and latency matrix between the locations 
class Locations(Config):
	locations = ['LocA', 'LocB']
	latencies = {
				 'LocB': {'LocB': Dist('gamma', (1, 1, 1))},
				 'LocA': {'LocB': Dist('norm', (12, 2)), 
						  'LocA': Dist('norm', (2, 0.5))},
				}

N = 10
# Generate network topology
G = nx.erdos_renyi_graph(N, 0.5)
nx.set_node_attributes(G, {k: 'basic' for k in G.nodes()}, 'type')	

# Physical properties of a peer. Peer will randomly get an attribute from a given distribution.
class PeerConfig(Config):
	location = Dist('sample', Locations.locations)
	bandwidth_ul = Dist( 'norm', (50*MBit, 10*MBit))
	bandwidth_dl = Dist( 'norm', (50*MBit, 10*MBit))

# Each basic peer runs a ConnectionManager: that will periodically ping neighbours and check if they are online
services = (BaseConnectionManager,)
peer_types = {'basic': PeerType(PeerConfig, services)}

sim = Simulation(Locations, G, peer_types)
# run the simulation for 1_000 milliseconds 
sim.run(1_000)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

p2psimpy-0.1.0.tar.gz (16.8 kB view hashes)

Uploaded Source

Built Distribution

p2psimpy-0.1.0-py3-none-any.whl (20.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page