码迷,mamicode.com
首页 > Web开发 > 详细

minnet sample

时间:2017-12-02 22:07:45      阅读:270      评论:0      收藏:0      [点我收藏+]

标签:过程   int   gre   soft   sign   switch   loss   inf   star   

In this assignment, your task is to create a simple tree topology. You will assume each level i.e., core, aggregation, edge and host to be composed of a single layer of switches/hosts with a configurable fanout value (k) looks like: 

技术分享图片

  代码:

技术分享图片
# CustomTopo.py
‘‘‘
Coursera:
- Software Defined Networking (SDN) course
-- Module 3 Programming Assignment

Professor: Nick Feamster
Teaching Assistant: Muhammad Shahbaz
‘‘‘

from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import CPULimitedHost
from mininet.link import TCLink
from mininet.util import irange,dumpNodeConnections
from mininet.log import setLogLevel

class CustomTopo(Topo):
    "Simple Data Center Topology"

    "linkopts - (1:c1, 2:aggregation, 3: edge) parameters"
    "fanout - number of child switch per parent switch"
    def __init__(self, linkopts1, linkopts2, linkopts3, fanout=2, **opts):
        # Initialize topology and default options
        Topo.__init__(self, **opts)
                        
        # Add your logic here ...
        self.fanout = fanout
        core = self.addSwitch(‘c1‘)
        for i in irange(1, fanout):
            aggregation = self.addSwitch(‘a%s‘ %i)
            self.addLink(core, aggregation, **linkopts1)
            for j in irange(1, fanout):
                edge = self.addSwitch(‘e%s‘ %(fanout*(i-1)+j))
                self.addLink(aggregation, edge, **linkopts2)
                for k in irange(1, fanout):
                    host = self.addHost(‘h%s‘ %((fanout*(fanout*(i-1)+j-1))+k))
                    self.addLink(edge, host, **linkopts3)
                   
topos = { ‘custom‘: ( lambda: CustomTopo() ) }

def simpleTest():
    "Create and test a simple network"
    linkopts1 = dict(bw=10, delay=‘3ms‘, use_htb=True)
    linkopts2 = dict(bw=8, delay=‘4ms‘, loss=1, max_queue_size=900, )
    linkopts3 = dict(bw=6, delay=‘5ms‘, loss=1, max_queue_size=800)
    topo = CustomTopo(linkopts1, linkopts2, linkopts3, fanout=2)
    net = Mininet(topo, host=CPULimitedHost, link=TCLink)
    net.start()
    print "Dumping host connections"
    dumpNodeConnections(net.hosts)
    print "Testing network connectivity"
    net.pingAll()
    net.stop()

if __name__ == ‘__main__‘:
   # Tell mininet to print useful information
   setLogLevel(‘info‘)
   simpleTest()
技术分享图片

在mininet虚拟机上执行下面操作即可创建自定义的网络拓扑。函数simpleTest()创建网络并进行了简单的ping测试,从屏幕输出可以看到创建的过程。

mininet@mininet-vm:~/mininet$ sudo python CustomTopo.py

 

minnet sample

标签:过程   int   gre   soft   sign   switch   loss   inf   star   

原文地址:http://www.cnblogs.com/soul-stone/p/7955562.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!