mininet

最後更新: 2018-04-17

介紹

 

http://mininet.org/

Mininet is a VM, also a great way to develop, share, and experiment with OpenFlow and Software-Defined Networking systems.

containers (network namespace)
Note that only the network is virtualized;
each host process sees the same set of processes

i.e.

mininet> h1 ps -a
mininet> s1 ps -a

By default, the hosts are put in their own namespace, while switches and the controller are in the root namespace.

 


mininet

 

Download

Mininet VM Images

https://github.com/mininet/mininet/wiki/Mininet-VM-Images

wget https://github.com/mininet/mininet/releases/download/2.2.2/mininet-2.2.2...

 

Boot VM

KVM

qemu-system-i386 -machine accel=kvm -m 2048 mininet-vm-disk1.vmdk \

  -net nic,model=virtio -net user,net=192.168.101.0/24,hostfwd=tcp::8022-:22

Libvirt

<disk type='file' device='disk'>
  <driver name='qemu' type='vmdk'/>
  <source file='/kvm/vm/mininet/mininet-vm-x86_64.vmdk'/>
  <target dev='vda' bus='virtio'/>
</disk>
<controller type='pci' index='0' model='pci-root'/>
<interface type='network'>
  <mac address='52:54:31:34:7c:05'/>
  <source network='default'/>
  <target dev='mininet-nic'/>
  <model type='e1000'/>
</interface>

 

Log in

mininet / mininet

 

Updating Mininet

cd ~/mininet
git checkout master # assuming you want to update to the current master branch
sudo make develop   # this only needs to be done initially and when mnexec.c changes
git fetch
git pull --rebase

 


mn Usage

 

# Mininet Benchmark

To record the time to set up and tear down a topology

mn --test none

 

# Start a minimal topology

# CLI (--topo=minimal)
# 1 switch connected to 2 hosts, 1 basic controller

$ sudo mn

*** Creating network
*** Adding controller
*** Adding hosts:
h1 h2
*** Adding switches:
s1
*** Adding links:
(h1, s1) (h2, s1)
*** Configuring hosts
h1 h2
*** Starting controller
c0
*** Starting 1 switches
s1 ...
*** Starting CLI:
mininet>

# Display nodes:

mininet> nodes

available nodes are:
c0 h1 h2 s1

# Display links:

mininet> net

h1 h1-eth0:s1-eth1
h2 h2-eth0:s1-eth2
s1 lo:  s1-eth1:h1-eth0 s1-eth2:h2-eth0
c0

# Dump information about all nodes:

mininet> dump

<Host h1: h1-eth0:10.0.0.1 pid=1283>
<Host h2: h2-eth0:10.0.0.2 pid=1285>
<OVSSwitch s1: lo:127.0.0.1,s1-eth1:None,s1-eth2:None pid=1290>
<Controller c0: 127.0.0.1:6653 pid=1276>

# Run a command on a host process:

mininet> h1 ifconfig -a

# Test connectivity between hosts

mininet> h1 ping -c 1 h2

# does an all-pairs ping

mininet> pingall

*** Ping: testing ping reachability
h1 -> h2
h2 -> h1
*** Results: 0% dropped (2/2 received)

# Run a simple web server and client

mininet> h1 python -m SimpleHTTPServer 80 &
mininet> h2 wget -O - h1
...
mininet> h1 kill %python

# Cleanup (If Mininet crashes for some reason)

mn -c

# Run a Regression Test

mn --test pingpair

....
completed in 5.247 seconds

mn --test iperf

...
*** Iperf: testing TCP bandwidth between h1 and h2
*** Results: ['49.3 Gbits/sec', '49.3 Gbits/sec']
...

# Link variations

# 10.00Mbit 10ms delay

mn --link tc,bw=10,delay=10ms

# Checking Speed

# Usage: iperf node1 node2

mininet> iperf

*** Iperf: testing TCP bandwidth between h1 and h2
*** Results: ['93.1 Mbits/sec', '108 Mbits/sec']

mininet> h1 ping -c10 h2

# ID = MAC

By default, hosts start with randomly assigned MAC addresses.

sudo mn --mac

mininet> h1 ifconfig

h1-eth0   Link encap:Ethernet  HWaddr 00:00:00:00:00:01
          inet addr:10.0.0.1  Bcast:10.255.255.255  Mask:255.0.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

# Switch Types

# user

# much lower TCP iperf-reported bandwidth

sudo mn --switch user --test iperf

# Open vSwitch (OVS)

sudo mn --switch ovsk --test iperf

* Default: OpenFlow kernel module

# one switch and three hosts

--topo single,3

# linear topology

--topo linear,4

# Custom Topologies

sudo mn --custom ~/mininet/custom/topo-2sw-2host.py --topo mytopo --test pingall

"""Custom topology example
   host --- switch --- switch --- host
"""

from mininet.topo import Topo

class MyTopo( Topo ):
    "Simple topology example."

    def __init__( self ):
        "Create custom topo."

        # Initialize topology
        Topo.__init__( self )

        # Add hosts and switches
        leftHost = self.addHost( 'h1' )
        rightHost = self.addHost( 'h2' )
        leftSwitch = self.addSwitch( 's3' )
        rightSwitch = self.addSwitch( 's4' )

        # Add links
        self.addLink( leftHost, leftSwitch )
        self.addLink( leftSwitch, rightSwitch )
        self.addLink( rightSwitch, rightHost )

topos = { 'mytopo': ( lambda: MyTopo() ) }

# To display an xterm for h1 and h2:

mininet> xterm h1 h2


Python Interpreter

 

If the first phrase on the Mininiet command line is py, then that command is executed with Python.

# Print the accessible local variables:

mininet> py locals()

{'h2': <Host h2: h2-eth0:10.0.0.2 pid=3197> , 
'net': <mininet.net.Mininet object at 0x7f38e3a3a250>, 
'h1': <Host h1: h1-eth0:10.0.0.1 pid=3195> , 
'c0': <Controller c0: 127.0.0.1:6653 pid=3188> , 
's1': <OVSSwitch s1: lo:127.0.0.1,s1-eth1:None,s1-eth2:None pid=3202> }

# see the methods and properties available for a node

mininet> py dir(s1)

# read the on-line documentation for methods available on a node

mininet> py help(h1)

# Evaluate methods of variables

mininet> py h1.IP()

10.0.0.1

py h1.MAC()

00:00:00:00:00:01

# Link Up/Down

# Usage: link node1 node2 [up/down]

mininet> link s1 h1 down

# dpctl program can create, modify, and delete Open vSwitch data‐paths.
# Prints to the console all flow entries in datapath

dpctl dump-flows tcp:127.0.0.1:6634

mininet> h1 ping -c 1 h2

mininet> h1 ping -c 1 h2

# SSH daemon per host

sudo ~/mininet/examples/sshd.py

# Using a Remote Controller

sudo mn --controller=remote,ip=[controller IP],port=[controller listening port]

# To start an xterm for every host and switch

mn -x


OpenFlow

 

OpenFlow is a communications protocol that gives access to the forwarding plane of a network switch or router over the network

forwarding plane

it refers to a table in which the router looks up the destination address of the incoming packet and retrieves the information necessary to determine the path from the receiving element, through the internal forwarding fabric of the router, and to the proper outgoing interface(s).

 


Doc

 

https://github.com/mininet/openflow-tutorial/wiki
https://github.com/mininet/mininet/wiki/FAQ
https://github.com/mininet/mininet/wiki/Introduction-to-Mininet
http://www.openvswitch.org/support/dist-docs/
https://github.com/mininet/mininet/tree/master/examples

 

 

Creative Commons license icon Creative Commons license icon