Mininet学习教程——创建Topo

使用Mininet创建Topo

Python脚本实现创建拓扑

#coding:utf-8
from mininet.net import Mininet
from mininet.topo import LinearTopo

# 四个交换机每个下边挂载一个主机

Linear4 = LinearTopo(k=4)
net = Mininet(topo=Linear4)
net.start()
net.pingAll()
net.stop()

# single,3

from mininet.topo import SingleSwitchTopo

Single3 = SingleSwitchTopo(k=3)
net = Mininet(topo=Single3)
net.start()
net.pingAll()
net.stop()


# tree,depth=2,fanout=2

from mininet.topolib import TreeTopo

Tree22 = TreeTopo(depth=2, fanout=2)
net = Mininet(topo=Tree22)
net.start()
net.pingAll()
net.stop()

# create 1 switch,2 host,set hosts IP

net = Mininet()

# Creating nodes in the network
c0 = net.addController()
h0 = net.addHost('h0')
s0 = net.addSwitch('s0')
h1 = net.addHost('h1')
# Creating links between nodes in network
net.addLink(h0, s0)
net.addLink(h1, s0)
# configuration of IP address in interfaces
h0.setIP('192.168.1.1', 24)
h1.setIP('192.168.1.2', 24)

net.start()
net.pingAll()
net.stop()

# add more limits to the host

from mininet.net import Mininet
from mininet.node import CPULimitedHost
from mininet.link import TCLink

net = Mininet(host=CPULimitedHost, link=TCLink)
# Creating nodes in the network
c0 = net.addController()
s0 = net.addSwitch('s0')
h0 = net.addHost('h0')
h1 = net.addHost('h1', cpu=0.5)
h2 = net.addHost('h2', cpu=0.5)
net.addLink(s0, h0, bw=10, delay='5ms',max_queue_size=1000, loss=10, use_htb=True)
net.addLink(s0, h1)
net.addLink(s0, h2)
net.start()
net.pingAll()
net.stop()

命令行创建topo

  • 最小拓扑,1s,2h
# sudo mn --topo minimal
  • linear 4s,4h
# sudo mn --topo linear,4
  • single,1s,3h
# sudo mn --topo single,3
  • tree,depth:2,fanout=2
# sudo mn --topo tree, fanout=2,depth=2

交互模式

# sudo mn
mininet>py net.addHost('h3')
mininet>py net.addLink(s1, net.get('h3'))
mininet>py s1.attach('s1-eth3')
mininet>py net.get('h3').cmd('ifconfig h3-eth0 10.3')
mininet>h1 ping -c1 10.3
mininet>px from mininet.util import dumpNodeConnections
mininet>py dumpNodeConnections(net.hosts)
mininet>py net.pingAll()
上一篇:10年后,阿里给千万开源人写了一封信


下一篇:Openstack_通用模块_Oslo_vmware 创建/删除 vCenter 虚拟机