mininet python api

本文介绍了Mininet的低级、中级和高级API,用于控制节点、开关以及构建网络。低级API直接操作节点和链接,中级API常用于启动和停止网络,而高级API(如Topo)则简化了网络创建。虽然中级API更简单,但低级和中级API提供了更多灵活性。注意,Mininet 2.2.0之前的版本,高级Topo不支持节点间多链接,而低级API则可以。在中级和低级API中,可以手动指定控制器控制的交换机。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Mininet’s API is built at three primary levels:

* Low-level API: The low-level API consists of the base node and link classes (such as Host,Switch, and Link and their subclasses) which can actually be instantiated individually and used to create a network, but it is a bit unwieldy.


* Mid-level API: The mid-level API adds the Mininet object which serves as a container for nodes and links. It provides a number of methods (such as addHost(), addSwitch(), andaddLink()) for adding nodes and links to a network, as well as network configuration, startup and shutdown (notably start() and stop().)mininet 对象作为一个容器提供了几个功能,如方便的添加节点,链路,配置网络,开启关闭网络等。


* High-level API: The 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.

It is valuable to understand each of the API levels. In general when you want to control nodes and switches directly, you use the low-level API. When you want to start or stop a network, you usually use the mid-level API (notably the Mininet class.)
Things become interesting when you start thinking about creating full networks. Full networks can be created using any of the API levels (as seen in the examples), but usually you will want to pick either the mid-level API (e.g. Mininet.add*()) or the high-level API (Topo.add*()) to create your networks.
Here are examples of creating networks using each API level:
Low-level API: nodes and links

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: Network object

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: Topology templates

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()   

As you can see, the mid-level API is a bit simpler because it doesn’t require creation of a topology class. The low-level and mid-level APIs are flexible and powerful, but may be less convenient to reuse compared to the high-level Topo API.
Note also that in Mininet versions before 2.2.0 the high-level Topo doesn’t support multiple links between nodes, but the lower level APIs do. Currently Topo also doesn’t concern itself with which switches are controlled by which controllers (you can use a custom Switch subclass to do this, as described above.) With the mid-level and low-level APIs, you can manually start the switches if desired, passing the appropriate list of controllers to each switch.
每一个控制器控制哪些交换机用顶级api暂时无法完成。

文档生成

sudo apt-get install doxypy
cd ~/mininet
make doc
cd doc
python -m SimpleHTTPServer

参考网址
http://api.mininet.org.
https://github.com/mininet/mininet/wiki/Introduction-to-Mininet#examples

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值