Skip to main content

A simulation tool for microservices based SDN, with CloudSim Plus 7.3 as backend.

Project description

PySDNSim

This is a simulation tool for microservice based SDN. It uses a executable jar built upon CloudSim Plus (https://cloudsimplus.org/) as the backend.

The backend jar is available from https://drive.google.com/file/d/1PWtYCWDBRV02VcOD1kn_J-lLbsxyfXhT/view?usp=sharing.

The backend.jar must be put into the same directory as your program.

Example

import random
from copy import deepcopy
from typing import List

import pandas as pd
import plotly.graph_objects as go
import plotly.express as px
from dash import Dash, Input, Output, dcc, html
from PySDNSim.Backend import Backend
from PySDNSim.Config import Config
from PySDNSim.Experiment import Experiment
from PySDNSim.Host import Host
from PySDNSim.Job import Job
from PySDNSim.Microservice import Microservice
from PySDNSim.NetworkService import NetworkService, create_network_service
from treelib import Node, Tree

create simulation config

sim_config = Config(seed=1024, interval=1.0, step_size=0.01)

create host

host = Host(
    cpus=64,
    ram=102400,
    bw=100000,
    storage=1024000,
    max_power=1600.0,
    static_power=300.0,
    replicas=3,
)

create microservices

microservices: List[Microservice] = list()
ms_mqtt_broker = Microservice(
    name="mqtt_broker",
    size=512,
    cpus=2,
    replicas=1,
    max_replicas=3,
    cpu_ratio=25,
    ram_ratio=32,
    bw_ratio=25,
)
ms_mqtt_broker.add_auto_scale("cpu",0.5)
ms_mqtt_broker.add_auto_scale("ram",0.5)
ms_mqtt_broker.add_auto_scale("bw",0.5)
microservices.append(ms_mqtt_broker)
ms_chirpstack_gateway = Microservice(
    name="chirpstack_gateway",
    size=128,
    cpus=2,
    replicas=1,
    max_replicas=3,
    cpu_ratio=25,
    ram_ratio=32,
    bw_ratio=25,
)
ms_chirpstack_gateway.add_auto_scale("cpu",0.5)
ms_chirpstack_gateway.add_auto_scale("ram",0.5)
ms_chirpstack_gateway.add_auto_scale("bw",0.5)
microservices.append(ms_chirpstack_gateway)
ms_chirpstack = Microservice(
    name="chirpstack",
    size=128,
    cpus=4,
    replicas=1,
    max_replicas=3,
    cpu_ratio=10,
    ram_ratio=32,
    bw_ratio=25,
)
ms_chirpstack.add_auto_scale("cpu",0.5)
ms_chirpstack.add_auto_scale("ram",0.5)
ms_chirpstack.add_auto_scale("bw",0.5)
microservices.append(ms_chirpstack)
ms_chirpstack_rest_api = Microservice(
    name="chirpstack_rest_api",
    size=128,
    cpus=2,
    replicas=1,
    max_replicas=3,
    cpu_ratio=5,
    ram_ratio=128,
    bw_ratio=25,
)
ms_chirpstack_rest_api.add_auto_scale("cpu",0.5)
ms_chirpstack_rest_api.add_auto_scale("ram",0.5)
ms_chirpstack_rest_api.add_auto_scale("bw",0.5)
microservices.append(ms_chirpstack_rest_api)
ms_postgresql = Microservice(
    name="postgresql",
    size=2048,
    cpus=2,
    replicas=1,
    max_replicas=3,
    cpu_ratio=50,
    ram_ratio=128,
    bw_ratio=100,
)
ms_postgresql.add_auto_scale("cpu",0.5)
ms_postgresql.add_auto_scale("ram",0.5)
ms_postgresql.add_auto_scale("bw",0.5)
microservices.append(ms_postgresql)
ms_redis = Microservice(
    name="redis",
    size=2048,
    cpus=2,
    replicas=1,
    max_replicas=3,
    cpu_ratio=50,
    ram_ratio=128,
    bw_ratio=100,
)
ms_redis.add_auto_scale("cpu",0.5)
ms_redis.add_auto_scale("ram",0.5)
ms_redis.add_auto_scale("bw",0.5)
microservices.append(ms_redis)

create network services

ns_list = list()
register_device = create_network_service(
    name="register_device",
    microservices=["chirpstack", "redis", "chirpstack_gateway"],
    schdeule=[0, 1, 1],
    schedule_length=[10, 10, 10],
    ms_pool=microservices
)
ns_list.append(register_device)
read_data = create_network_service(
    name="receive_data",
    microservices=["chirpstack_gateway", "mqtt_broker", "chirpstack", "postgresql"],
    schdeule=[0, 1, 2, 3],
    schedule_length=[10, 10, 10, 10],
    ms_pool=microservices
)
ns_list.append(read_data)
retrive_data = create_network_service(
    name="retrive_data",
    microservices=["chirpstack_rest_api", "chirpstack", "postgresql", "chirpstack"],
    schdeule=[0, 1, 2, 3],
    schedule_length=[10, 10, 10, 10],
    ms_pool=microservices
)
ns_list.append(retrive_data)

start a simulation that randomly select network services at each iteration.

backend.start()
for iter in range(10):
    num_ns = random.randint(1, 20)
    chosen_ns: List[NetworkService] = deepcopy(random.choices(ns_list, k=num_ns))
    for ns in chosen_ns:
        ns.offset_schedule(random.randint(0, 5))
    experiment = Experiment(
        name=f"{iter}",
        config=sim_config,
        host=host,
        microservices=microservices,
        network_services=chosen_ns,
    )
    backend.add_experiment(experiment=experiment, output_path="./results")
backend.stop()

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

PySDNSim-1.1.6.tar.gz (21.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

PySDNSim-1.1.6-py3-none-any.whl (23.0 kB view details)

Uploaded Python 3

File details

Details for the file PySDNSim-1.1.6.tar.gz.

File metadata

  • Download URL: PySDNSim-1.1.6.tar.gz
  • Upload date:
  • Size: 21.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.0

File hashes

Hashes for PySDNSim-1.1.6.tar.gz
Algorithm Hash digest
SHA256 73253c420e7b63a2ecc703fcc1d83418354c7bf0640e4d10b8034bedc465c387
MD5 0c99c9eae4fcb44c522454267a8c723f
BLAKE2b-256 052e929e546099f6cb7dc989e8e5b24253f5034f7046ebaccc2ffe5957a995dc

See more details on using hashes here.

File details

Details for the file PySDNSim-1.1.6-py3-none-any.whl.

File metadata

  • Download URL: PySDNSim-1.1.6-py3-none-any.whl
  • Upload date:
  • Size: 23.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.0

File hashes

Hashes for PySDNSim-1.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 7db590835e5af28d62eacdba222571c15b640261edaadb41228dd20df025e3d3
MD5 65ee0252e374ab777f5c3ec61a36ad04
BLAKE2b-256 fec881231634e1495ad538ba182d2b96ed99715ae789ed5782c7112a544c10fb

See more details on using hashes here.

Supported by

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