質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
Linux

Linuxは、Unixをベースにして開発されたオペレーティングシステムです。日本では「リナックス」と呼ばれています。 主にWebサーバやDNSサーバ、イントラネットなどのサーバ用OSとして利用されています。 上位500のスーパーコンピュータの90%以上はLinuxを使用しています。 携帯端末用のプラットフォームAndroidは、Linuxカーネル上に構築されています。

ネットワーク

ネットワークとは、複数のコンピューター間を接続する技術です。インターネットが最も主流なネットワークの形態で、TCP/IP・HTTP・DNSなどの様々なプロトコルや、ルータやサーバーなどの様々な機器の上に成り立っています。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Network Simulator

The Network Simulator

Q&A

0回答

1197閲覧

Mininetでstop()を実行した際にエラーが出力される。

man_

総合スコア45

Linux

Linuxは、Unixをベースにして開発されたオペレーティングシステムです。日本では「リナックス」と呼ばれています。 主にWebサーバやDNSサーバ、イントラネットなどのサーバ用OSとして利用されています。 上位500のスーパーコンピュータの90%以上はLinuxを使用しています。 携帯端末用のプラットフォームAndroidは、Linuxカーネル上に構築されています。

ネットワーク

ネットワークとは、複数のコンピューター間を接続する技術です。インターネットが最も主流なネットワークの形態で、TCP/IP・HTTP・DNSなどの様々なプロトコルや、ルータやサーバーなどの様々な機器の上に成り立っています。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Network Simulator

The Network Simulator

0グッド

0クリップ

投稿2021/08/12 15:29

編集2021/08/18 03:47

#やりたいこと
ネットワークエミュレータMininetを使用し以下のようなダンベルトポロジーを構築したい。
h1----r1----r2----h2

#困っている点
Mininetでネットワークトポロジーを構築しiperfを実行するpythonコードを書きました。
以下にコードを示します。
また、コードの下に出力結果を示します。

出力結果を見ると、net.stop()の部分でエラーが出力されるようです。
そこで、エラーの原因と解消方法を教えてください。

python

1#!/usr/bin/python 2 3from mininet.topo import Topo 4from mininet.net import Mininet 5from mininet.node import CPULimitedHost 6from mininet.link import TCLink 7from mininet.util import dumpNodeConnections 8from mininet.log import setLogLevel 9from mininet.cli import CLI 10 11import time 12import subprocess 13import sys 14import threading 15import csv 16from argparse import ArgumentParser 17 18from time import sleep, time 19import re 20 21pid = None 22 23def get_option(): 24 parser = ArgumentParser(description='explanation of program') 25 26 parser.add_argument('-c', '--cc', help="name of cc schemes", type=str, default='none') 27 28 return parser.parse_args() 29 30 31 32class SingleSwitchTopo(Topo): 33 "Single switch connected to n hosts." 34 def __init__(self, n=2, **opts): 35 Topo.__init__(self, **opts) 36 hosts=[] 37 routers=[] 38 39 for h in range(2): 40 routers.append(self.addHost('h%s' % (h + 1))) 41 self.addLink(routers[0], routers[1], intfName1='r1-eth0', intfName2='r2-eth0', 42 bw=100, delay='5ms', loss=0,max_queue_size=79,use_tbf=True) 43 44 for h in range(n): 45 print(h) 46 # Each host gets 50%/n of system CPU 47 hosts.append(self.addHost('h%s' % str(2*(h + 1)-1))) 48 hosts.append(self.addHost('h%s' % str(2*(h + 1)))) 49 # 10 Mbps, 5ms delay, 10% loss, 1000 packet queue 50 51 self.addLink(hosts[2*(h)], routers[0], intfName1='h'+str(2*(h)+1)+'-eth0', intfName2='r1-eth'+str(h+1), 52 bw=200, delay='5ms', loss=0,max_queue_size=1000,use_tbf=True) 53 54 self.addLink(hosts[2*(h)+1], routers[1], intfName1='h'+str(2*(h+1))+'-eth0', intfName2='r2-eth'+str(h+1), 55 bw=200, delay='5ms', loss=0,max_queue_size=1000,use_tbf=True) 56 57 58 59 60def monitor_qlen(node,interval_sec=0.1): 61 pat_queued =re.compile(r'backlog\s[^\s]+\s([\d]+)p') 62 63 cmd = "tc -s qdisc show dev h1-eth0" 64 65 ret = [] 66 open("dump/qlen.csv","w").write('') 67 t0 = "%f" % time() 68 69 while 1: 70 # p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) 71 p = node.popen(cmd, shell=True, stdout=subprocess.PIPE) 72 output = p.stdout.read() 73 74 matches = pat_queued.findall(output) 75 76 if matches and len(matches) > 1: 77 ret.append(matches[1]) 78 t1 = "%f" % time() 79 #print str(float(t1)-float(t0)), matches[1] 80 open("dump/qlen.csv","a").write(str(float(t1)-float(t0))+','+matches[1]+'\n') 81 82 sleep(interval_sec) 83 84def run_ccp(): 85 global pid 86 pid = subprocess.Popen(['sudo', '/home/maeta/eval-scripts/generic-cong-avoid/target/release/cubic', '--ipc=netlink'],stdout=subprocess.PIPE,stderr = subprocess.STDOUT) 87 with open('dump/cwnd.csv', 'w') as f: 88 for line in iter(pid.stdout.readline, b''): 89 #print(line.rstrip().decode('utf8')) 90 output = (line.rstrip().decode('utf8').split(',')) 91 output_str = [str(n) for n in output] 92 if (output_str[0].isdigit()): 93 writer = csv.writer(f) 94 writer.writerow(output_str) 95 sys.stdout.flush() 96 97 98def perfTest(cc): 99 global pid 100 "Create network and run simple performance test" 101 topo = SingleSwitchTopo(n=1) 102 net = Mininet(topo=topo, 103 host=CPULimitedHost, link=TCLink,controller=None) 104 h1, h2 = net.get('h1', 'h2') 105 106 #h1_tx = h1.cmd('ip l set dev h1-eth0 txqueue 1' ) 107 #h2_tx = h2.cmd('ip l set dev h2-eth0 txqueue 1' ) 108 109 net.start() 110 #CLI(net) 111 h1_eth = h1.cmd('ethtool -K h1-eth0 tx off sg off tso off ufo off' ) 112 h2_eth = h2.cmd('ethtool -K h2-eth0 tx off sg off tso off ufo off' ) 113 114 thread2 = threading.Thread(target=monitor_qlen, args=(h2,)) 115 thread2.setDaemon(True) 116 thread2.start() 117 118 h1_dmp = h1.popen('tcpdump', '-x', '-tt', '-nn', '-Z', 'root', '-B', '1000', '-w', 'dump/receiver.pcap') 119 h2_dmp = h2.popen('tcpdump', '-x', '-tt', '-nn', '-Z', 'root', '-B', '1000', '-w', 'dump/sender.pcap') 120 121 122 h2_pid = h2.popen('iperf', '-s', '-p', '5001') 123 h1_pid = h1.popen(['iperf', '-c', h2.IP(), '-p', '5001', '-t', '5','-i', '1','-Z', args.cc],stdout=subprocess.PIPE,stderr = subprocess.STDOUT) 124 125 try: 126 for line in iter(h1_pid.stdout.readline, b''): 127 print(line.rstrip().decode('utf8')) 128 sys.stdout.flush() 129 130 finally: 131 h1_pid.kill() 132 h1_dmp.kill() 133 h2_pid.kill() 134 h2_dmp.kill() 135 if (cc == 'ccp'): 136 pid.kill() 137 138 net.stop() 139 140 141if __name__ == '__main__': 142 143 args = get_option() 144 setLogLevel('info') 145 if (args.cc == 'ccp'): 146 thread1 = threading.Thread(target=run_ccp) 147 thread1.setDaemon(True) 148 thread1.start() 149 150 sleep(1) 151 perfTest(args.cc) 152 sys.exit() 153 # thread1.join()
*** Creating network *** Adding hosts: h1 h2 *** Adding switches: *** Adding links: (200.00Mbit 5ms delay 0.00000% loss) (200.00Mbit 5ms delay 0.00000% loss) (h1, h1) (100.00Mbit 5ms delay 0.00000% loss) (100.00Mbit 5ms delay 0.00000% loss) (h1, h2) (200.00Mbit 5ms delay 0.00000% loss) (200.00Mbit 5ms delay 0.00000% loss) (h2, h2) *** Configuring hosts h1 (cfs -1/100000us) h2 (cfs -1/100000us) *** Starting controller *** Starting 0 switches ------------------------------------------------------------ Client connecting to 10.0.0.2, TCP port 5001 TCP window size: 85.3 KByte (default) ------------------------------------------------------------ [ 9] local 10.0.0.1 port 34624 connected with 10.0.0.2 port 5001 [ ID] Interval Transfer Bandwidth [ 9] 0.0- 1.0 sec 11.1 MBytes 93.3 Mbits/sec [ 9] 1.0- 2.0 sec 9.50 MBytes 79.7 Mbits/sec [ 9] 2.0- 3.0 sec 9.00 MBytes 75.5 Mbits/sec [ 9] 3.0- 4.0 sec 10.2 MBytes 86.0 Mbits/sec [ 9] 4.0- 5.0 sec 8.88 MBytes 74.4 Mbits/sec [ 9] 0.0- 5.1 sec 48.8 MBytes 80.9 Mbits/sec *** Stopping 0 controllers *** Stopping 3 links .Traceback (most recent call last): File "dumbbell.py", line 151, in <module> perfTest(args.cc) File "dumbbell.py", line 138, in perfTest net.stop() File "/usr/local/lib/python2.7/dist-packages/mininet/net.py", line 581, in stop link.stop() File "/usr/local/lib/python2.7/dist-packages/mininet/link.py", line 513, in stop self.delete() File "/usr/local/lib/python2.7/dist-packages/mininet/link.py", line 508, in delete self.intf2.delete() File "/usr/local/lib/python2.7/dist-packages/mininet/link.py", line 213, in delete self.node.delIntf( self ) File "/usr/local/lib/python2.7/dist-packages/mininet/node.py", line 471, in delIntf del self.intfs[ port ] KeyError: 1

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問