Code Monkey home page Code Monkey logo

mint-dev's Introduction

mint

A Python library for computer network simulation. (Developing)

screenshoot

Example usage:

from mint import *

h1 = Host()
h2 = Host()
hub = Hub()
link(h1, hub.ports[0])
link(hub.ports[1], h2)

@proc
def _():
    h1.port.send('111')

@proc
def _():
    print h2.port.recv(8)

run()

Output:

00011100

Up to application layer, write application just as application:

# server.py
from mint import socket

listen_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listen_sock.bind(8080)
listen_sock.listen()
while True:
    sock, addr = listen_sock.accept()
    print 'Connection established with', addr
    msg = ''
    while True:
        ch = sock.recv(1)
        msg += ch
        if ch == '\n':
            break
    sock.send('You said: ' + msg)
    sock.close()

# client.py
from mint import socket

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect('192.168.0.2')
sock.send('hello server\n')
msg = ''
while True:
    ch = sock.recv(1)
    msg += ch
    if ch == '\n':
        break
print msg

Down to physical layer, model the link channal behaviour as you wish:

# main.py
from mint import *

a = Host(ip='192.168.0.2', script='server.py')
b = Host(ip='192.168.0.3', script='client.py', wait=1)
switch = Switch()

link(a, switch.ports[0])
link(b, switch.ports[1], latency=20, error_func=error.flip_bit(ith=3))

run()

mint-dev's People

Contributors

fans656 avatar

Stargazers

1Nuo avatar Luigi Vanfretti avatar

Watchers

James Cloos avatar  avatar Luigi Vanfretti avatar

Forkers

ver007

mint-dev's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.