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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file p2psimpy-0.1.0.tar.gz.

File metadata

  • Download URL: p2psimpy-0.1.0.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.9 Linux/5.11.0-1022-azure

File hashes

Hashes for p2psimpy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 39961fd688f0f712578db3dcfd8de7325c3b1f6708489e3542696436a466cba4
MD5 56fc524c628017d73a2ce7be7a12d080
BLAKE2b-256 2559f80a8fcffd622316663d8a8f99172859ab307e477c18cf3effcf0b4b258f

See more details on using hashes here.

File details

Details for the file p2psimpy-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: p2psimpy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.9 Linux/5.11.0-1022-azure

File hashes

Hashes for p2psimpy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 87d1c1084a4c6ec6f78a0181eb66589e3083530291d87ae400515feb04ef0a19
MD5 6260d3457b87f96075b023cd5562a8cd
BLAKE2b-256 516526c4f3fd76ee4658cd0220dbd009420e2732db8c1b8f5dceabaa05048529

See more details on using hashes here.

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