20220416-Mininet入门学习

Mininet入门学习

基本介绍,参见:官方说明

1. Mininet基本操作

  • Creating Topologies
  • Setting Performance Parameters
  • Running Programs in Hosts
  • New: popen()/pexec() interface
  • Host Configuration Methods
  • Naming in Mininet
  • Customizing mn using —custom files

2. Host Configuraton Methods

  • IP():return IP address of a host or specific interface.
  • MAC():return MAC address of a host or specific interface.
  • setARP():add a static ARP entry to a host’s ARP cache.
  • setIP():set the IP address for a host or specific interface.
  • setMAC():set the MAC address for a host or specific interface.

3. Customizing mn using --custom files

4. Understanding the Mininet API

  • 可以将Mininet的API划分为以下3个主要层级:

    • Low-level API: consists of the base node and link classes (such as Host, Switch, and Link and their subclasses) . Low-level API: nodes and links

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      h1 = Host( 'h1' )                                 
      h2 = Host( 'h2' )
      s1 = OVSSwitch( 's1', inNamespace=False )
      c0 = Controller( 'c0', inNamespace=False )
      Link( h1, s1 )
      Link( h2, s1 )
      h1.setIP( '10.1/8' )
      h2.setIP( '10.2/8' )
      c0.start()
      s1.start( [ c0 ] )
      print( h1.cmd( 'ping -c1', h2.IP() ) )
      s1.stop()
      c0.stop()
    • Mid-level API:adds the Mininet object which serves as a container for nodes and links. (such as addHost(), addSwitch(), and addLink()) , as well as network configuration, startup and shutdown (notably start() and stop()). Mid-level API: Network object

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      net = Mininet()
      h1 = net.addHost( 'h1' )
      h2 = net.addHost( 'h2' )
      s1 = net.addSwitch( 's1' )
      c0 = net.addController( 'c0' )
      net.addLink( h1, s1 )
      net.addLink( h2, s1 )
      net.start()
      print( h1.cmd( 'ping -c1', h2.IP() ) )
      CLI( net )
      net.stop()
    • High-level API:adds a topology template abstraction. The Topo class, which provides the ability to create reusable, parametrized topology templates. These templates can be passed to the mn command (via the --custom option) and used from the command line. High-level API: Topology templates

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      class SingleSwitchTopo( Topo ):                                     
      "Single Switch Topology"
      def build( self, count=1 ):
      hosts = [ self.addHost( 'h%d' % i )
      for i in range( 1, count + 1 ) ]
      s1 = self.addSwitch( 's1' )
      for h in hosts:
      self.addLink( h, s1 )

      net = Mininet( topo=SingleSwitchTopo( 3 ) )
      net.start()
      CLI( net )
      net.stop()

5. Measuring Performance

  • Bandwidth (bwm-ng, ethstats)
  • Latency (use ping)
  • Queues (use tc included in monitor.py)
  • TCP CWND statistics (tcp_probe, maybe we should add it to monitor.py)
  • CPU usage (global: top, or per-container cpuacct)

6. Mininet原理

  • 组成部分
    • Isolated Hosts
    • Emulated Links
    • Emulated Switches: default Linux bridge or Open vSwitch running in kernel model to switch packets across interfaces.