Code Monkey home page Code Monkey logo

internetsimulation's Introduction

This application is a model of raw internet and it implemented in python. It is included simulator of interfaces, hosts , routers and raw protocols such as ARP,RIP,IP, and TCP. Routers and physics transfer medias are simulated by process. The rest of features are pretty close to real network protocols. However, I have to revise some protocols on link layer so that I it can run on top of the simulated virtual systems. The principle of network has been remained. Please refer simulators of models and processes from readme.pptx.

Note: Many details have been ignored due to time and effort, such as I have added fresh and expire on routing table but not on mac table. I have wrap TCP sockets but not for UDP since my UDP is just for send RIP packets. All IP addresses are set as C class addresses.

This simulation run on top of python2.7 and using python structs lib serialize packets and frame

Run:

  1. library install
    - sudo apt-get install python-tk # tk gui to draw chat window, no needed install Windows OS
    - pip install menu  # install text menu
    - pip install Enum  # install enumerate class
    - pip install netaddr # to manipulation ip and mac address
  1. run and command
python main.py

1. Create Router
2. Config Host IP   # input IPv4 after get in  the IP address are loaded from config file but can reconfig
3. config Router IP  
4. Show Routing Table  # view routing table and dynamic learning
5. Show MAC/ARP Table  # view MAC/ARP table and dynamic learning
6. Select Servers
7. Open Chat Window
>>> 1   # eg, choose 1 to creat routers and hosts

Process of the System

It will try to build a TCP connection with target server once we click the "connect to host.x" from a client simulator.
The socket simulators will wrap a TCP segments, IP packets and put it to interfaces then it will encapsulated as frame 
to send to next hop. In order to send the frame to next hop it will check shortest path on routing table and the 
learning Mac address before send it.

Simulated RIP and ARP will run as daemon thread constantly and update the routing table and the mac/arp tables.

Interface:

    - Simulate an NIC and hold an IPv4 address and MAC address
    - Hold a send queue to serve send packets or frame
    - Threads send and receive IP packets
    - Threads request and response ARP

Host:

    - Attached an chat window to represent source and destination
    - Hold an interface to simulate NIC 
    - Running a RIP to learn routing table from the network
    - Can send and receive messages(packets) 

Router:

    - Hold an interface to simulate NIC 
    - Running a RIP to learn routing table from the network
    - Fowaring IP packets
    - Connected with a host to represent source and destination 

IP header:

0                   1                   2                   3
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |Version|  IHL  |Type of Service|          Total Length         |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |         Identification        |Flags|      Fragment Offset    |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |  Time to Live |    Protocol   |         Header Checksum       |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                       Source Address                          |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                    Destination Address                        |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                    Options                    |    Padding    |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

TCP header:

0                   1                   2                   3   
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |          Source Port          |       Destination Port        |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                        Sequence Number                        |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                    Acknowledgment Number                      |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |  Data |           |U|A|P|R|S|F|                               |
   | Offset| Reserved  |R|C|S|S|Y|I|            Window             |
   |       |           |G|K|H|T|N|N|                               |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |           Checksum            |         Urgent Pointer        |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                    Options                    |    Padding    |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                             data                              |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

internetsimulation's People

Contributors

ainilaha avatar

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.