我想在mininet中使用“ net”将信息保存到文件中,但是最终文件中没有结果。怎么解决呢? 我在mininet / mininet下的globalv.py中设置了一个名为file2的全局变量,其上下文为:
file2 = open('net.txt ','w')
file2=file2.close()
然后我像这样修改CLI.py并导入globalv:
def do_net( self, _line ):
"List network connections."
globalv.file2=open('net.txt','w')
dumpNodeConnections( self.mn.values() )
globalv.file2.close()
和util.py修改如下:
def dumpNodeConnections( nodes ):
"Dump connections to/from nodes."
import globalv
def dumpConnections( node ):
"Helper function: dump connections to node"
for intf in node.intfList():
output( ' %s:' % intf )
globalv.file2.write("")
globalv.file2.write(str(intf))
globalv.file2.write(":")
if intf.link:
intfs = [ intf.link.intf1, intf.link.intf2 ]
intfs.remove( intf )
output( intfs[ 0 ] )
globalv.file2.write(str( intfs[ 0 ]))
else:
output( ' ' )
globalv.file2.write(" ")
for node in nodes:
output( node.name )
globalv.file2.write(node.name)
dumpConnections( node )
output( '\n' )
globalv.file2.write("\n")