0x00 Mininet

尝试理解一下mininet,话说mininet是基于python编写的,代码结构清晰,简直清醒脱俗((≧▽≦)/啦啦啦),附上链接mininet,mark一下。

0x01 Important classes, methods, functions

简单记录一下比较重要的类和方法

Important classes, methods, functions and variables in the above code include:

Topo: the base class for Mininet topologies

build(): The method to override in your topology class. Constructor parameters (n) will be passed through to it automatically by Topo.__init__().

addSwitch(): adds a switch to a topology and returns the switch name

addHost(): adds a host to a topology and returns the host name

addLink(): adds a bidirectional link to a topology (and returns a link key, but this is not important). Links in Mininet are bidirectional unless noted otherwise.

Mininet: main class to create and manage a network

start(): starts your network

pingAll(): tests connectivity by trying to have all nodes ping each other

stop(): stops your network

net.hosts: all the hosts in a network

dumpNodeConnections(): dumps connections to/from a set of nodes.

setLogLevel( 'info' | 'debug' | 'output' ): set Mininet's default output level; 'info' is recommended as it provides useful information.

0x02 Sample

自己写了一个简单的,h1~h5链接到s1, h6~h10链接到s2,然后s1和s2互联

一开始想着SingleSwitchTopo的方法来写LinearTopo,结果一直报错,╮(╯_╰)╭,明明人家代码都写好了

SingleSwitchTopoSingle switch connected to k hosts,而Linear topology of k switches, with n hosts per switch

#!/usr/bin/python

from mininet.topo import Topo
from mininet.net import Mininet
from mininet.util import irange,dumpNodeConnections
from mininet.log import setLogLevel class LinearTopo(Topo):
""
"""Linear topology of k switches, with n hosts per switch."""
""
def __init__(self, k=2, n=5,**opts): """k:number of switches (and hosts)"""
"""hconf: host configuration options"""
"""lconf: ling configuration options"""
super(LinearTopo, self).__init__(**opts)
self.n = n
self.k = k
"""creates 2 switchs"""
switch1 = self.addSwitch('s1')
switch2 = self.addSwitch('s2') """creates h1~h5 and addLink switch1""" for i in irange(1,n):
host = self.addHost('h%s' %i)
self.addLink(host,switch1) """creates h6~h10 and addLink switch2""" for i in irange(n+1,n+5):
host =self.addHost('h%s' %i)
self.addLink(host,switch2) """addLink switch1 and switch2"""
self.addLink(switch1,switch2) def simpleTest():
"Create and test a simple network"
topo = LinearTopo(k=2,n=5)
net = Mininet(topo)
#start the network
net.start()
print "Dumping host connections"
dumpNodeConnections(net.hosts) #test the connections of the network
print "Testing network connectivity"
net.pingAll() #Test the bandwidth of the h* and h*
print "Testing bandwidth between h1 and h2"
h1, h2 = net.get('h1', 'h2')
net.iperf((h1,h2)) print "Testing bandwidth between h10 and h1"
h10, h1 = net.get('h10', 'h1')
net.iperf((h10,h1)) #stop the network
net.stop() if __name__== '__main__':
# Tell mininet to print useful information
setLogLevel('info')
simpleTest()

0x04 run in shell

命令行直接运行

#将代码保存到一个文件中
sudo vi test.py #运行
sudo python test.py

0x05 Output

*** Creating network
*** Adding controller
*** Adding hosts:
h1 h2 h3 h4 h5 h6 h7 h8 h9 h10
*** Adding switches:
s1 s2
*** Adding links:
(h1, s1) (h2, s1) (h3, s1) (h4, s1) (h5, s1) (h6, s2) (h7, s2) (h8, s2) (h9, s2) (h10, s2) (s1, s2)
*** Configuring hosts
h1 h2 h3 h4 h5 h6 h7 h8 h9 h10
*** Starting controller
c0
*** Starting 2 switches
s1 s2 ...
Dumping host connections
h1 h1-eth0:s1-eth1
h2 h2-eth0:s1-eth2
h3 h3-eth0:s1-eth3
h4 h4-eth0:s1-eth4
h5 h5-eth0:s1-eth5
h6 h6-eth0:s2-eth1
h7 h7-eth0:s2-eth2
h8 h8-eth0:s2-eth3
h9 h9-eth0:s2-eth4
h10 h10-eth0:s2-eth5
Testing network connectivity
*** Ping: testing ping reachability
h1 -> h2 h3 h4 h5 h6 h7 h8 h9 h10
h2 -> h1 h3 h4 h5 h6 h7 h8 h9 h10
h3 -> h1 h2 h4 h5 h6 h7 h8 h9 h10
h4 -> h1 h2 h3 h5 h6 h7 h8 h9 h10
h5 -> h1 h2 h3 h4 h6 h7 h8 h9 h10
h6 -> h1 h2 h3 h4 h5 h7 h8 h9 h10
h7 -> h1 h2 h3 h4 h5 h6 h8 h9 h10
h8 -> h1 h2 h3 h4 h5 h6 h7 h9 h10
h9 -> h1 h2 h3 h4 h5 h6 h7 h8 h10
h10 -> h1 h2 h3 h4 h5 h6 h7 h8 h9
*** Results: 0% dropped (90/90 received)
Testing bandwidth between h1 and h2
*** Iperf: testing TCP bandwidth between h1 and h2
*** Results: ['35.8 Gbits/sec', '35.8 Gbits/sec']
Testing bandwidth between h10 and h1
*** Iperf: testing TCP bandwidth between h10 and h1
*** Results: ['36.4 Gbits/sec', '36.4 Gbits/sec']
*** Stopping 1 controllers
c0
*** Stopping 11 links
...........
*** Stopping 2 switches
s1 s2
*** Stopping 10 hosts
h1 h2 h3 h4 h5 h6 h7 h8 h9 h10
*** Done

0x06 Problems

遇到的问题:

一.Mininet只能使用python2使用python3不行,即使用外部库也不行

二.PyCharm配置root运行文件

一开始我没有使用shell来运行,而是使用了PyCharm来跑,然后出现了一个问题,就是Mininet must run as a root,即必须以管理员身份进行,所以需要在PyCharm上设置管理员运行,具体做法:

  • 1.在/usr/bin/目录下新建文件 python_sudo.sh :
sudo gedit /usr/bin/python_sudo.sh

在文件中写入下列代码:

#! /bin/bash
sudo python $*
  • 2.给sh文件赋予权限:
cd /usr/bin/
sudo chmod a+x python_sudo.sh
  • 3.编辑visudo(其他工具有点问题):
sudo visudo
  • 4.在最后一行输入,然后保存:
%sudo ALL=NOPASSWD: /usr/bin/python
  • 5.将pycharm 中的

File→Settings→Project Interpreter

置换为自己写的python_sudo.sh,在下图选中框右边有个小齿轮,点那个进行Add就OK了

  • 6.同理可以对python3等进行设定,只要在将python改成对应版本就可以(前提是在这个目录下已安装)

0x07 Paint

一个能用画图工具

sudo apt-get install kolourpaint4

然后搜paint就OK了

初试mininet(可选PyCharm)的更多相关文章

  1. Pycharm 使用

    Pycharm基本使用http://edu.51cto.com/index.php?do=lession&id=118722   Pycharm的基本使用 在Pycharm下为你的Python ...

  2. 配置Windows 2008 R2 64位 Odoo 8.0 源码PyCharm开发调试环境

    安装过程中,需要互联网连接下载python依赖库: 1.安装: Windows Server 2008 R2 x64标准版 2.安装: Python 2.7.10 amd64 到C:\Python27 ...

  3. [Python] Magic editor in Pycharm

    From: http://blog.csdn.net/u013088062/article/details/50249751 From:http://blog.csdn.net/u013088062/ ...

  4. [Python] Interpreter setting in Pycharm

    From: http://blog.csdn.net/u013088062/article/details/50135135 From: http://blog.csdn.net/u013088062 ...

  5. 基于OpenDaylight和Mininet的试验床平台搭建

    ##########################################平台架构######################################### 一.虚拟机安装和镜像加载 ...

  6. Mininet VM设置笔记

    Mininet VM是为了加快Mininet安装,而且可以很容易在linux平台上运行. VM运行在Windows,Mac,Linux,通过VMware.VirtualBox,QEMU和KVM. 下载 ...

  7. (原+转)pycharm中传入命令行参数

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5670821.html 参考网址: http://zhidao.baidu.com/question/5 ...

  8. PyCharm基本使用

    调节PyCharm的背景颜色 File>Settings>Appearance&Behavior>Appearance 在PyCharm中切换Python解释器版本 File ...

  9. pycharm 安装与基本设置

    一.下载及安装 打开官网下载:https://www.jetbrains.com/pycharm/download/#section=windows 下载完毕之后可直接双击可执行文件,然后点击&quo ...

随机推荐

  1. H5禁止手机自带键盘弹出

    一个功能中用到这个, 调用软键盘,  不想弹出手机默认的输入法 网上找了个 http://blog.csdn.net/qq_24147051/article/details/52958610 处理方式 ...

  2. Spring Boot框架搭建

    用idea搭建Springboot还是很方便的 环境变量是JDK1.8 SpringBoot自带了Tomcat启动也很方便 1.创建项目 2. 3.选择SpringBoot的版本以及组件 4.创建完成 ...

  3. CentOS随笔 - 修改CentOS7的IP

    前言 转帖请注明出处: http://www.cnblogs.com/Troy-Lv5/ 在使用CentOS时经常我们需要固定一个IP, 因为服务器嘛,不固定IP. 难道每次都要配置开发环境的地址.? ...

  4. 使用.Net访问Office编程接口(PIA和IA的区别)

    在这篇文章里面,我将向大家介绍如何在.Net中访问Office所公开的编程接口.其实,不管是使用哪种具体的技术来针对Office进行开发(比如VSTO,或者用C#编写一个Office Add-in,或 ...

  5. SQL insert语句中插入带有特殊符号

    1.插入数据库字符串中海油单引号,需要转义处理,例如插入“I‘m OK!” SQL语句: INSERT INTO tableTest(FileTXT) VALUES('I''m OK!') 2.如果S ...

  6. Linux下的Mysql的双向同步

    在主从复制的基础上实现双向同步 [更多参考] https://www.cnblogs.com/shuidao/p/3551238.html http://blog.csdn.net/i_bruce/a ...

  7. 【转】深入理解 Session 与 Cookie

    Session 与 Cookie 不管是对 Java Web 的初学者还是熟练使用者来说都是一个令人头疼的问题.在初入职场时恐怕很多程序员在面试的时候都被问到过这个问题.其实这个问题回答起来既简单又复 ...

  8. MapReduce Design Patterns(chapter 2(part 1))(二)

    随着每天都有更多的数据加载进系统,数据量变得很庞大.这一章专注于对你的数据顶层的,概括性意见的设计模式,从而使你能扩展思路,但可能对局部数据是不适用的.概括性的分析都是关于对相似数据的分组和执行统计运 ...

  9. 类库文件引用web服务报错解决方法-在 ServiceModel 客户端配置部分中,找不到引用协定的默认终结点元素

    由于需求,需要改造原有应用,因原有应用是写在console下面的,现在需要开放至web下, 想到BIZ层应用代码都是一样的,又不想在web下在添加引用,而重复写代码,故将原有的console下的服务和 ...

  10. angularJs的run方法操作

    省掉了控制器 <!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv= ...