ºìÁªLinuxÃÅ»§
Linux°ïÖú

SDN ÍøÂçϵͳ֮ Mininet

·¢²¼Ê±¼ä:2017-11-03 13:20:36À´Ô´:ºìÁª×÷Õß:Ronny
SDN Óë Mininet ¸ÅÊö
SDN È«ÃûΪ£¨Software Defined Network£©¼´Èí¼þ¶¨ÒåÍøÂ磬ÊÇÏÖ»¥ÁªÍøÖÐÒ»ÖÖÐÂÐ͵ÄÍøÂ紴мܹ¹,ÆäºËÐļ¼Êõ OpenFlow ͨ¹ýÍøÂçÉ豸¿ØÖÆÃæÓëÊý¾ÝÃæ·ÖÀ뿪À´,´Ó¶øʵÏÖÍøÂçÁ÷Á¿µÄÁé»î¿ØÖÆ,ΪÍøÂç¼°Ó¦ÓÃÌṩÁËÁ¼ºÃµÄƽ̨¡£¶ø Mininet ÊÇÒ»¸öÇáÁ¿¼¶Èí¼þ¶¨ÒåÍøÂçºÍ²âÊÔƽ̨£»Ëü²ÉÓÃÇáÁ¿¼¶µÄÐéÄ⻯¼¼Êõʹһ¸öµ¥Ò»µÄϵͳ¿´ÆðÀ´ÏñÒ»¸öÍêÕûµÄÍøÂçÔËÐÐÏë¹ýµÄÄÚºËϵͳºÍÓû§´úÂ룬Ҳ¿É¼òµ¥Àí½âΪ SDN ÍøÂçϵͳÖеÄÒ»ÖÖ»ùÓÚ½ø³ÌÐéÄ⻯ƽ̨£¬ËüÖ§³Ö OpenFlow¡¢OpenvSwith µÈ¸÷ÖÖЭÒ飬Mininet Ò²¿ÉÒÔÄ£ÄâÒ»¸öÍêÕûµÄÍøÂçÖ÷»ú¡¢Á´½ÓºÍ½»»»»úÔÚͬһ̨¼ÆËã»úÉÏÇÒÓÐÖúÓÚ»¥¶¯¿ª·¢¡¢²âÊÔºÍÑÝʾ£¬ÓÈÆäÊÇÄÇЩʹÓà OpenFlow ºÍ SDN ¼¼Êõ£»Í¬Ê±Ò²¿É½«´Ë½ø³ÌÐéÄ⻯µÄƽ̨Ï´úÂëǨÒƵ½ÕæʵµÄ»·¾³ÖС£

Mininet ʵÏÖµÄÌØÐÔ
Ö§³Ö OpenFlow¡¢OpenvSwitch µÈÈí¶¨ÒåÍø·²¿¼þ
Ö§³Öϵͳ¼¶µÄ»¹Ô­²âÊÔ£¬Ö§³Ö¸´ÔÓÍØÆË£¬×Ô¶¨ÒåÍØÆ˵È
Ìṩ Python API, ·½±ã¶àÈËЭ×÷¿ª·¢
ºÜºÃµÄÓ²¼þÒÆÖ²ÐÔÓë¸ßÀ©Õ¹ÐÔ
Ö§³ÖÊýǧ̨Ö÷»úµÄÍøÂç½á¹¹
Miniet ʵÏÖÓ빤×÷Á÷³Ì
Mininet µÄ°²×°·½Ê½±È½Ï¼òµ¥Í¨¹ý Git Ô´ÂëºÍ×Ô´øµÄ°²×°½Å±¾·½Ê½¼´¿É°²×°ÔÚ Linux ϵͳÖУ¬ÕâÀïÎÒ²ÉÓÃÁËĬÈÏ°²×°ËùÓÐ Mininet Ïà¹ØµÄÏà¹ØÌ×¼þ£¬È磺OpenFlow¡¢POX µÈ¹¤¾ß»áĬÈϱ£´æÔÚµ±Ç°Óû§µÄ¼ÒĿ¼¡£

# git clone git://github.com/mininet/mininet
# cd mininet/util/
# ./install.sh -a
# ls
mininet of-dissector oflops oftest openflow pox
´´½¨ÍøÂç
ͼ 1.¼òµ¥ÍøÂçʾÀýͼ
SDN ÍøÂçϵͳ֮ MininetSDN ÍøÂçϵͳ֮ Mininet

ÓÉÓÚ Mininet Ö§³Ö×Ô¶¨ÒåÍøÂ磬ÕâÀïÏÈÒýÓÃÒ»¸ö¼òµ¥ÍøÂçʾÀýÈçͼ 1£¬ÔÚ Mininet ÍøÂçϵͳÖÐÖ±½ÓÊäÈë mn ÃüÁ¿ÉÒÔÔÚ´ËϵͳÖд´½¨µ¥²ãµÄÍØÆËÍøÂ磬´ÓÖÐĬÈÏ´´½¨ÁËÁ½Ì¨ host ºÍÒ»¸ö½»»»»ú£¬²¢ÇÒ¼¤»îÁË¿ØÖÆÆ÷ºÍ½»»»»ú¡£Í¬Ê±Ò²¿ÉÒÔͨ¹ýÃüÁî net ²é¿´µ½Á´Â·Çé¿ö£¬Ïȼòµ¥ÁгöÁËʾÀý£¬ÈçÔÚ Mininet ϵͳÖÐÆôÓà Web ·þÎñÆ÷Óë¿Í»§¶Ë¡£

# mn
*** Creating network
*** Adding controller
*** Adding hosts:
h1 h2
*** Adding switches:
s1
*** Adding links:
(h1, s1) (h2, s1)
*** Configuring hosts
h1 h2
*** Starting controller
*** Starting 1 switches
s1
*** Starting CLI:
mininet>
ÆôÓÃÓë¹Ø±Õ Web ·þÎñ

ÔÚ Mininet »·¾³Öпɷ½±ã½¨Á¢Ò»¸ö Web ·þÎñÆ÷£¬´ÓÏÂÃæʾÀýÖпÉÒÔ¿´µ½´Ó host1 ½¨Á¢ÁËÒ»¸ö Web ·þÎñÆ÷£¬²¢´ÓÁíÍâһ̨ Host Ö÷»úÏë Web ·þÎñÆ÷»ñÈ¡ HTTP ÇëÇó¡£

mininet> h1 python -m SimpleHTTPServer 80 & #ÔÚÖ÷»ú h1 ¿ªÆô Web ·þÎñ
mininet> h2 wget -O - h1 #Ö÷»ú h2 ÉÏÏÂÔØ h1 web Õ¾µãÄÚÈÝ
--2013-11-04 00:05:40-- http://10.0.0.1/
Connecting to 10.0.0.1:80... connected.
HTTP request sent, awaiting response... 200 OK
¡­¡­¡­¡­
Length: 760 [text/html
< !DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
Directory listing for /
  • .bash_history
  • .wireshark/
  • install-mininet-vm.sh
  • mininet/
  • of-dissector/
  • oflops/
  • oftest/
  • openflow/
  • pox/






  • 0K 100% 1.65M=0s
    2013-11-04 00:05:40 (1.65 MB/s) - written to stdout [760/760]

    mininet> h1 kill %python # ɱµô web ½ø³Ì
    10.0.0.2 - - [04/Nov/2013 00:05:40] "GET / HTTP/1.1" 200 -
    bash: line 23: kill: python: ambiguous job spec
    Ping ²âÊÔ
    ÔÚ Mininet ϵͳÉÏ£¬ÊµÏÖÁ½Ö÷»ú»¥Á¬²âÊÔ¡£

    mininet> h1 ping -c4 h2
    PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
    64 bytes from 10.0.0.2: icmp_req=1 ttl=64 time=1.55 ms
    64 bytes from 10.0.0.2: icmp_req=2 ttl=64 time=0.094 ms
    64 bytes from 10.0.0.2: icmp_req=3 ttl=64 time=0.075 ms
    64 bytes from 10.0.0.2: icmp_req=4 ttl=64 time=0.071 ms

    --- 10.0.0.2 ping statistics ---
    4 packets transmitted, 4 received, 0% packet loss, time 3006ms
    rtt min/avg/max/mdev = 0.071/0.448/1.553/0.638 ms
    ²é¿´½ÚµãÓëÁ´½Ó

    mininet> nodes
    available nodes are:
    c0 h1 h2 s1
    mininet> net
    h1 h1-eth0:s1-eth1
    h2 h2-eth0:s1-eth2
    s1 lo: s1-eth1:h1-eth0 s1-eth2:h2-eth0
    c0
    ×Ô¶¨ÒåÍØÆË
    Mininet Ö§³Ö×Ô¶¨ÒåÍØÆ˽ṹ£¬ÔÚ mininet/custom Ŀ¼Ï¸ø³öÁËÒ»¸öʵÀý£¬ÈçÔÚ topo-2sw-2host.py ÎļþÖж¨ÒåÁËÒ»¸ö mytopo£¬Ôò¿ÉÒÔͨ¹ý--topo Ñ¡ÏîÀ´Ö¸¶¨Ê¹ÓÃÕâÒ»ÍØÆË:
    ͼ 2. ×Ô¶¨ÍØÆËʾÀý
    SDN ÍøÂçϵͳ֮ MininetSDN ÍøÂçϵͳ֮ Mininet
    ÓÉÓÚ Mininet Ò²Ö§³Ö²ÎÊý»¯ÍØÆË£¬Í¨¹ý Python ´úÂëÒ²¿ÉÒÔ´´½¨Ò»¸öÁé»îµÄÍØÆ˽ṹ,Ò²¿É¸ù¾Ý×Ô¶¨Òå´«µÝ½øÈ¥µÄ²ÎÊý½øÐÐÅäÖ㬲¢ÇÒ¿ÉÖØÓõ½¶à¸ö»·¾³ÖУ¬ÏÂÃæ¼ò¶ÌÁгöÆä´úÂëµÄ´óÖ½ṹ¼°º¬Òå¡£

    #!/usr/bin/python

    from mininet.topo import Topo
    from mininet.net import Mininet
    from mininet.util import dumpNodeConnections
    from mininet.log import setLogLevel

    class SingleSwitchTopo(Topo):
    def __init__(self, n=2, **opts):
    Topo.__init__(self, **opts)
    switch = self.addSwitch('s1') #Ìí¼ÓÒ»¸ö½»»»»úÔÚÍØÆËÖÐ
    for h in range(n):
    host = self.addHost('h%s' % (h + 1)) #Ìí¼ÓÖ÷»úµ½ÍØÆËÖÐ
    self.addLink(host, switch) #Ìí¼ÓË«ÏòÁ¬½ÓÍØÆË

    def simpleTest():
    topo = SingleSwitchTopo(n=4)
    net = Mininet(topo) #Ö÷ÒªÀàÀ´´´½¨ºÍ¹ÜÀíÍøÂç
    net.start() #Æô¶¯ÄúµÄÍØÆËÍøÂç
    print "Dumping host connections"
    dumpNodeConnections(net.hosts) #ת´æÎļþÁ¬½Ó
    print "Testing network connectivity"
    net.pingAll() #ËùÓнڵã±Ë´Ë²âÊÔ»¥Á¬
    net.stop() #Í£Ö¹ÄúµÄÍøÂç

    if __name__ == '__main__':
    setLogLevel('info') # ÉèÖà Mininet ĬÈÏÊä³ö¼¶±ð£¬ÉèÖà info Ëü½«ÌṩһЩÓÐÓõÄÐÅÏ¢
    simpleTest()
    ÑéÖ¤²ÎÊý»¯ÍØÆ˽ṹ
    # python test-single.py
    *** Creating network
    *** Adding controller
    *** Adding hosts:
    h1 h2 h3 h4
    *** Adding switches:
    s1
    *** Adding links:
    (h1, s1) (h2, s1) (h3, s1) (h4, s1)
    *** Configuring hosts
    h1 h2 h3 h4
    *** Starting controller
    *** Starting 1 switches
    s1
    Dumping host connections
    h1 h1-eth0:s1-eth1
    h2 h2-eth0:s1-eth2
    h3 h3-eth0:s1-eth3
    h4 h4-eth0:s1-eth4
    Testing network connectivity
    *** Ping: testing ping reachability
    h1 -> h2 h3 h4
    h2 -> h1 h3 h4
    h3 -> h1 h2 h4
    h4 -> h1 h2 h3
    *** Results: 0% dropped (12/12 received)
    Ãû×Ö¿Õ¼ä namespace
    ͨ³£Çé¿öÏ£¬Ö÷»ú½çÃæÓÐÓöÀÁ¢µÄÃû×Ö¿Õ¼ä namespace£¬¶ø¿ØÖƽڵã¸ú½»»»½Úµã¶¼ÔÚ¸ùÃû×ֿռ䣨root namespace£©ÖС£Èç¹ûÏëÒªÈÃËùÓнڵãÓµÓи÷×ÔµÄÃû×ֿռ䣬ÐèÒªÌí¼Ó --innamespace ²ÎÊý£¬¼´Ö´ÐУºmn --innamespace

    # mn --innamespace --switch user
    *** Creating network
    *** Adding controller
    *** Adding hosts:
    h1 h2
    *** Adding switches:
    s1
    *** Adding links:
    (h1, s1) (h2, s1)
    c0 < -> s1
    *** Testing control network
    s1 -> c0
    c0 -> s1
    *** Results: 0% dropped (2/2 received)

    *** Configuring hosts
    h1 h2
    *** Starting controller
    *** Starting 1 switches
    s1
    *** Starting CLI:
    Mininet ³£ÓòÙ×÷
    ±í 1.Mininet ³£ÓÃÖ¸Áî

    Ãû³Æ ×÷ÓÃ
    nodes ²é¿´È«²¿½Úµã
    net ²é¿´Á´Â·ÐÅÏ¢
    dump Êä³ö¸÷½ÚµãµÄÐÅÏ¢
    h1 ping -c 4 h2 ²âÊÔÖ÷»úÖ®¼äµÄÁ¬Í¨ÐÔ
    iperf Á½¸ö½ÚµãÖ®¼äÓÃÖ¸¶¨¼òµ¥µÄ TCP ²âÊÔ
    iperfudp Á½¸ö½ÚµãÖ®¼äÓÃÖ¸¶¨¿îµ¥ udp ½øÐвâÊÔ
    noecho ÔËÐн»»¥´°¿Ú£¬¹Ø±Õ»ØÓ¦
    pingpair Á½¸öÖ÷»ú½«»¥ ping
    help ÁгöÃüÁîÎĵµ£¬²é¿´ÃüÁî°ïÖú£º help command
    dpctl ÔÚËùÓнн»»»»ú
    exit/quit Í˳ö mininet ÃüÁîÐÐ
    hX ifconfig ²é¿´µ±Ç°ÄÇÖ÷»úµÄ ip µØÖ·£¬È磺 h1 ifconfig
    py/sh Ö´ÐÐ python ±í´ïʽ»òÔËÐÐÍⲿ shell ³ÌÐò
    ±¾ÎÄתÔØ×Ô£ºhttp://www.linuxprobe.com/sdn-mininet.html

    Ãâ·ÑÌṩ×îÐÂLinux¼¼Êõ½Ì³ÌÊé¼®£¬Îª¿ªÔ´¼¼Êõ°®ºÃÕßŬÁ¦×öµÃ¸ü¶à¸üºÃ£¬¿ªÔ´Õ¾µã£ºhttp://www.linuxprobe.com/
    ÎÄÕÂÆÀÂÛ

    ¹²ÓÐ 0 ÌõÆÀÂÛ