{"id":81,"date":"2014-10-06T12:46:42","date_gmt":"2014-10-06T04:46:42","guid":{"rendered":"http:\/\/140.128.102.245\/wordpress\/?p=81"},"modified":"2021-05-04T04:47:37","modified_gmt":"2021-05-04T04:47:37","slug":"mininet%e7%ad%86%e8%a8%98","status":"publish","type":"post","link":"https:\/\/blog.laszlo.tw\/?p=81","title":{"rendered":"Mininet\u7b46\u8a18"},"content":{"rendered":"<p>Default VM image user\/passwd : mininet\/mininet<\/p>\n<p><strong>\u555f\u52d5 mininet \u6a21\u64ec\u7db2\u8def\u74b0\u5883<\/strong><\/p>\n<p>sudo mn<\/p>\n<p><!--more--><\/p>\n<p><strong>mn\u74b0\u5883\u4e0b\u6307\u4ee4<\/strong><\/p>\n<p>nodes\u76ee\u524dfork\u51fa\u4e4b\u7bc0\u9ede( sN:switch hN:host )<br \/>\nnet \u76ee\u524d\u6a21\u64ec\u9023\u7dda\u72c0\u614b<br \/>\ndump \u865b\u64ec\u7bc0\u9ede\u8a73\u7d30\u72c0\u614b<br \/>\n$host_name$&nbsp;$bash_command \u4ee5\u7bc0\u9ede\u4e0b\u6307\u4ee4(EX: &#8220;s1 ifconfig&#8221;\u3001&#8221;h1 ping h2&#8243; \u3001&#8221;h1 ps aux&#8221; &#8230; )<br \/>\npingall \u5404\u7bc0\u9ede\u4e92ping<br \/>\niperf \u7bc0\u9ede\u50b3\u8f38\u983b\u5bec\u6e2c\u8a66<br \/>\nxterm $host $host2 &#8230; Xmode\u4e0b\u958b\u555fhost terminel<\/p>\n<p><strong>mn\u53c3\u6578<\/strong><\/p>\n<p>\u74b0\u5883\u6a21\u64ec\u5b8c\u6210\u5f8c\u6e2c\u8a66$mn_command\u4e26\u7d50\u675f\u6a21\u64ec<br \/>\nsudo mn &#8211; -test $mn_command<\/p>\n<p>\u4ee5$topo_name\u62d3\u6a38\u5efa\u7acb$number_nodes\u7bc0\u9ede\u6578\u91cf\u4e4b\u6a21\u64ec\u74b0\u5883<br \/>\nsudo mn &#8211; &#8211; topo={$topo_name},$number_nodes<br \/>\n$topo_name={ single\u3001linear\u3001tree }<\/p>\n<p>MAC_address=ID\u6a21\u5f0f<br \/>\nsudo mn &#8211; -mac<\/p>\n<p>GUI X Mode<br \/>\nsudo mn -x<\/p>\n<p>\u6307\u5b9aController (default port:6633)<br \/>\nsudo mn &#8211; -controller=remote,ip=$controller_ip,port=$controller_port<\/p>\n<p><strong>\u8a0a\u606f\u63a7\u5236<\/strong><\/p>\n<p>debug\u6a21\u5f0f<br \/>\nsudo mn -v debug<\/p>\n<p>output\u6a21\u5f0f<br \/>\nsudo mn -v output<\/p>\n<p>\u8cc7\u6599\u91cf<br \/>\noutput &gt; debug &gt; general<\/p>\n<p><strong>\u81ea\u8a02\u62d3\u6a38(\u756b\u5716\uff1aswitch\u3001host\u3001link)<\/strong><\/p>\n<p>\u62d3\u6a38\u7bc4\u4f8b<br \/>\ncustom\/topo-2sw-2host.py<\/p>\n<p>\u57f7\u884c<br \/>\nsudo mn &#8211; -custom custom\/topo-2sw-2host.py &#8211; &#8211; topo=mytopo<\/p>\n<p><strong>10\/26\u66f4\u65b0 : mininet\u9032\u968e\u7528\u6cd5\u7c21\u6613\u74b0\u5883\u7248 ( \u64b0\u5beb\u6210 .py \u5f8c\u4ee5python\u57f7\u884c )<\/strong><\/p>\n<p><em>#\u74b0\u5883\u8f09\u5165<\/em><br \/>\n#!\/usr\/bin\/env python2<br \/>\nfrom mininet.topo import Topo<br \/>\nfrom mininet.net import Mininet<br \/>\nfrom mininet.link import TCLink<br \/>\nfrom mininet.log import setLogLevel, info<br \/>\nfrom mininet.cli import CLI<br \/>\nfrom mininet.link import Intf<br \/>\nfrom mininet.util import dumpNodeConnections<br \/>\nREMOTE_CONTROLLER_IP=&#8221;192.168.18.151&#8243;<br \/>\ndef MininetTopo():<br \/>\nnet = Mininet (topo=None, build=False)<\/p>\n<p><em>#\u8a2d\u5b9aController<\/em><br \/>\ncontroller =net.addController(name=&#8217;controller0&#8242;,<br \/>\ncontroller=RemoteController,<br \/>\nip=REMOTE_CONTROLLER_IP,<br \/>\nport=6633)<\/p>\n<p><em>#\u7522\u751fSwitchs<\/em><br \/>\ninfo(&#8220;Create Switch node\\n&#8221;)<br \/>\nswitch = net.addSwitch(&#8216;s1&#8217;)<\/p>\n<p><em>#\u7522\u751fHosts<\/em><br \/>\n<span style=\"line-height: 1.5;\">info(&#8220;Create Host node\\n&#8221;)<br \/>\n<\/span><span style=\"line-height: 1.5;\">host1 = net.addHost(&#8216;h1&#8242;, ip=&#8217;10.0.0.1&#8217;)<br \/>\n<\/span><span style=\"line-height: 1.5;\">host2 = net.addHost(&#8216;h2&#8242;, ip=&#8217;10.0.0.2&#8217;)<\/span><\/p>\n<p><em>#\u7522\u751fLINKs<\/em><br \/>\ninfo(&#8220;Link switch to host\\n&#8221;)<br \/>\nnet.addLink(switch, host1)<br \/>\nnet.addLink(switch, host2)<\/p>\n<p><em>#\u555f\u52d5<\/em><br \/>\ninfo(&#8220;Start network\\n&#8221;)<br \/>\nnet.start()<\/p>\n<p><em>#\u589e\u52a0Flow<\/em><br \/>\ninfo(&#8220;Adding Flow\\n&#8221;)<br \/>\nswitch.cmdPrint(&#8216;ovs-ofctl add-flow s1 in_port=1,actions=output:2&#8217;)<br \/>\nswitch.cmdPrint(&#8216;ovs-ofctl add-flow s1 in_port=2,actions=output:1&#8217;)<\/p>\n<p><em>#Mininet CLI\u555f\u52d5<\/em><br \/>\nCLI(net)<\/p>\n<p><em>#MininetCLI\u7d50\u675f<\/em><br \/>\nnet.stop()<\/p>\n<p>if __name__ == &#8216;__main__&#8217;:<br \/>\nsetLogLevel(&#8216;info&#8217;)<br \/>\nMininetTopo()<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Default VM image user\/pas<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/blog.laszlo.tw\/?p=81\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">Mininet\u7b46\u8a18<\/span><\/a><\/div>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[5],"tags":[85,81,92],"class_list":["post-81","post","type-post","status-publish","format-standard","hentry","category-mininet","tag-cmd","tag-mininet","tag-sdn","entry"],"_links":{"self":[{"href":"https:\/\/blog.laszlo.tw\/index.php?rest_route=\/wp\/v2\/posts\/81","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.laszlo.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.laszlo.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.laszlo.tw\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.laszlo.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=81"}],"version-history":[{"count":6,"href":"https:\/\/blog.laszlo.tw\/index.php?rest_route=\/wp\/v2\/posts\/81\/revisions"}],"predecessor-version":[{"id":1207,"href":"https:\/\/blog.laszlo.tw\/index.php?rest_route=\/wp\/v2\/posts\/81\/revisions\/1207"}],"wp:attachment":[{"href":"https:\/\/blog.laszlo.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=81"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.laszlo.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=81"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.laszlo.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=81"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}