本文整理汇总了Python中mininet.node.Node.cmd方法的典型用法代码示例。如果您正苦于以下问题:Python Node.cmd方法的具体用法?Python Node.cmd怎么用?Python Node.cmd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mininet.node.Node
的用法示例。
在下文中一共展示了Node.cmd方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: connectToRootNS
# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import cmd [as 别名]
def connectToRootNS(network, switch, ip, routes):
root = Node('root', inNamespace=False)
intf = network.addLink(root, switch).intf1
root.setIP(ip, intf=intf)
network.start()
for route in routes:
root.cmd('route add -net {} dev {} '.format(route, intf))
示例2: startNetwork
# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import cmd [as 别名]
def startNetwork(network, switch, ip, routes):
root = Node('root', inNamespace=False)
intf = Link(root, switch).intf1
root.setIP(ip, intf=intf)
network.start()
for route in routes:
root.cmd( 'route add -net ' + route + ' dev ' + str( intf ) )
示例3: checkOVS
# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import cmd [as 别名]
def checkOVS(self):
root = Node('root', inNamespace=False)
modinfo = root.cmd("modinfo openvswitch | grep version: |awk -F':' '{print $2}' | awk '{ gsub (\" \", \"\", $0); print}'")
versions = modinfo.split("\n")
version = versions[0]
print "modinfo openviswitch : " + version
# SS 2017-10-21 I've disabled the version check because in the packaged openvswitch there is no version info
# modversion = float(version[:3])
# if modversion < 2.3:
# error( 'OVS Kernel Module does not respect version requirement\nPlease check your OVS installation\n' )
# exit( 1 )
vswitchdinfo = root.cmd("ovs-vswitchd --version | grep ovs-vswitchd |awk -F')' '{print $2}' | awk '{ gsub (\" \", \"\", $0); print}'")
versions = vswitchdinfo.split("\n")
version = versions[0]
print "ovs-vswitchd --version : " + version
#vswitchdversion = float(version[:3])
#if vswitchdversion < 2.3:
major = version.split(".")[0]
minor = version.split(".")[1]
if major < 2:
error( 'OVS vswitchd does not respect version requirement\nPlease check your OVS installation\n' )
exit( 1 )
if minor < 3:
error( 'OVS vswitchd does not respect version requirement\nPlease check your OVS installation\n' )
exit( 1 )
# SS 2017-10-21 I've disabled the version check because in the packaged openvswitch there is no version info
# if modversion != vswitchdversion:
# error( 'OVS Kernel module version and OVS vswitchd version are different\nPlease check your OVS installation\n' )
# exit( 1)
openvswitchd = root.cmd('ls %s 2> /dev/null | wc -l' % self.ovs_initd)
示例4: MyTopo
# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import cmd [as 别名]
class MyTopo(object):
def __init__(self, cname='onos', cips=['10.0.3.1']):
# Create network with multiple controllers
self.net = Mininet(controller=RemoteController, switch=OVSKernelSwitch,
build=False)
# Add controllers with input IPs to the network
ctrls = [RemoteController(cname, cip, 6633) for cip in cips]
for ctrl in ctrls:
print ctrl.ip
self.net.addController(ctrl)
# Add switch
self.s2 = self.net.addSwitch('s2', dpid='00000000000000a2')
# Connect root namespace to the switch
self.root = Node('root', inNamespace=False)
intf = self.net.addLink(self.root, self.s2).intf1
self.root.setIP('10.0.0.1/32', intf=intf)
# Add host
h2 = self.net.addHost('h2', ip='10.0.0.12/24', mac='00:00:00:00:00:02')
self.net.addLink(h2, self.s2)
def run(self):
self.net.build()
self.net.start()
self.s2.cmd('ovs-vsctl set bridge s2 protocols=OpenFlow13')
self.s2.cmd('ovs-vsctl add-port s2 vxlan2')
self.s2.cmd('ovs-vsctl set interface vxlan2 type=vxlan option:remote_ip=104.236.158.75 option:key=flow')
self.root.cmd('route add -net 10.0.0.0/24 dev root-eth0')
CLI(self.net)
self.net.stop()
示例5: start
# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import cmd [as 别名]
def start():
global net, attacker, running
if running:
return '\nServer already running.\n'
setLogLevel('info')
topo = MixTopo()
net = Mininet(topo=topo)
s1 = net['s1']
plc2 = net['plc2']
plc3 = net['plc3']
s2, rtu2a, scada = net.get('s2', 'rtu2a', 'scada')
rtu2b, attacker2 = net.get('rtu2b', 'attacker2')
s3 = net.get('s3')
# NOTE: root-eth0 interface on the host
root = Node('root', inNamespace=False)
intf = net.addLink(root, s3).intf1
print('DEBUG root intf: {}'.format(intf))
root.setIP('10.0.0.30', intf=intf)
# NOTE: all packet from root to the 10.0.0.0 network
root.cmd('route add -net ' + '10.0.0.0' + ' dev ' + str(intf))
net.start()
info('Welcome')
# NOTE: use for debugging
#s1.cmd('tcpdump -i s1-eth1 -w /tmp/s1-eth1.pcap &')
#s1.cmd('tcpdump -i s1-eth2 -w /tmp/s1-eth2.pcap &')
SLEEP = 0.5
# NOTE: swat challenge 1 and 2
plc3.cmd(sys.executable + ' plc3.py &')
sleep(SLEEP)
plc2.cmd(sys.executable + ' plc2.py &')
sleep(SLEEP)
# NOTE: wadi challenge 1
scada.cmd(sys.executable + ' scada.py &')
sleep(SLEEP)
rtu2a.cmd(sys.executable + ' rtu2a.py &')
sleep(SLEEP)
# NOTE: wadi challenge 2
rtu2b.cmd(sys.executable + ' rtu2b.py &')
sleep(SLEEP)
running = True
return '\nServer started.\n'
示例6: fixSwitchIntf
# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import cmd [as 别名]
def fixSwitchIntf(swi):
for i in range(0, len(swi)):
for obj in swi[i].nameToIntf:
if 'lo' not in obj:
fixNetworkManager(obj)
fixNetworkManager(swi[i])
root = Node( 'root', inNamespace=False )
print "Restarting Network Manager"
time.sleep(10)
root.cmd('service network-manager restart')
time.sleep(2)
示例7: configure_l2_accessnetwork
# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import cmd [as 别名]
def configure_l2_accessnetwork():
print "*** Configure L2 Access Networks"
root = Node( 'root', inNamespace=False )
print "*** Configure L2 Access Ports"
for key, value in ACCESS_TO_TAG.iteritems():
print "*** Configure", key, "As Access Port, TAG=", value
root.cmd("ovs-vsctl set port %s tag=%s" %(key, value))
print "*** Configure L2 Trunk Ports"
for key, value in TRUNK_TO_TAG.iteritems():
print "*** Configure", key, "As Trunk Port, TAG=", value
root.cmd("ovs-vsctl set port %s trunks=%s" %(key, value))
示例8: __init__
# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import cmd [as 别名]
def __init__(self, verbose=False):
self.checkPATHs()
Mininet.__init__(self, build=False)
self.cr_oshis = []
self.pe_oshis = []
self.ce_routers = []
self.ctrls = []
self.nodes_in_rn = []
self.node_to_data = defaultdict(list)
self.node_to_node = {}
self.node_to_default_via = {}
self.coex = {}
self.verbose = verbose
lg.setLogLevel('info')
self.vlls = []
self.node_to_pw_data = defaultdict(list)
self.pws = []
self.cer_to_customer = {}
self.customer_to_vtepallocator = {}
self.vsfs = []
self.pe_cer_to_vsf = {}
self.is_vs = False
self.vss = []
self.vss_data = []
self.id_peo_to_vs = {}
self.last_ipnet = IPv4Network(u'0.0.0.0/24')
self.id_to_node = {}
self.ip_to_mac = {}
self.overall_info = {}
self.mgmt = None
root = Node( 'root', inNamespace=False )
root.cmd('/etc/init.d/network-manager stop')
mylog("*** Stop Network Manager\n")
self.cluster_to_ctrl = defaultdict(list)
self.cluster_to_nodes = defaultdict(list)
self.nodes_to_cluster = {}
示例9: connectToRootNS
# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import cmd [as 别名]
def connectToRootNS( network, switch, ip, routes ):
"""Connect hosts to root namespace via switch. Starts network.
network: Mininet() network object
switch: switch to connect to root namespace
ip: IP address for root namespace node
routes: host networks to route to"""
# Create a node in root namespace and link to switch 0
root = Node( 'root', inNamespace=False )
intf = network.addLink( root, switch ).intf1
root.setIP( ip, intf=intf )
# Start network that now includes link to root namespace
network.start()
# Add routes from root ns to hosts
for route in routes:
root.cmd( 'route add -net ' + route + ' dev ' + str( intf ) )
示例10: connectToRootNS
# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import cmd [as 别名]
def connectToRootNS( network, switch, ip, prefixLen, routes ):
"Connect hosts to root namespace via switch. Starts network."
"network: Mininet() network object"
"switch: switch to connect to root namespace"
"ip: IP address for root namespace node"
"prefixLen: IP address prefix length (e.g. 8, 16, 24)"
"routes: host networks to route to"
# Create a node in root namespace and link to switch 0
root = Node( 'root', inNamespace=False )
intf = TCLink( root, switch ).intf1
root.setIP( ip, prefixLen, intf )
# Start network that now includes link to root namespace
network.start()
# Add routes from root ns to hosts
for route in routes:
root.cmd( 'route add -net ' + route + ' dev ' + str( intf ) )
示例11: checkQuagga
# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import cmd [as 别名]
def checkQuagga(self):
root = Node( 'root', inNamespace=False )
zebra = root.cmd('ls %s 2> /dev/null | wc -l' % OSHI.zebra_exec)
if '1' not in zebra:
OSHI.zebra_exec = OSHI.zebra_exec_2
zebra = root.cmd('ls %s 2> /dev/null | wc -l' % OSHI.zebra_exec)
if '1' not in zebra:
error( 'Cannot find required executable zebra\nPlease make sure that Zebra is properly installed in ' + OSHI.quaggaPath_msg + '\n'
'Otherwise change configuration in Dreamer-Mininet-Extensions/nodes.py \n' )
exit( 1 )
ospfd = root.cmd('ls %s 2> /dev/null | wc -l' % OSHI.ospfd_exec)
if '1' not in ospfd:
OSHI.ospfd_exec = OSHI.ospfd_exec_2
ospfd = root.cmd('ls %s 2> /dev/null | wc -l' % OSHI.ospfd_exec)
if '1' not in ospfd:
error( 'Cannot find required executable ospfd\nPlease make sure that OSPFD is properly installed in ' + OSHI.quaggaPath_msg + '\n'
'Otherwise change configuration in Dreamer-Mininet-Extensions/nodes.py \n' )
exit( 1 )
示例12: configure_vll_pusher
# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import cmd [as 别名]
def configure_vll_pusher(net):
print "*** Create Configuration File For Vll Pusher"
path = vll_path + "vll_pusher.cfg"
vll_pusher_cfg = open(path,"w")
for i in range(0, len(LHS_tunnel_aoshi)):
aoshi = LHS_tunnel_aoshi[i]
lhs_dpid = net.getNodeByName(aoshi).dpid
lhs_dpid = ':'.join(s.encode('hex') for s in lhs_dpid.decode('hex'))
port = LHS_tunnel_port[i]
lhs_port = port
aoshi = RHS_tunnel_aoshi[i]
rhs_dpid = net.getNodeByName(aoshi).dpid
rhs_dpid = ':'.join(s.encode('hex') for s in rhs_dpid.decode('hex'))
port = RHS_tunnel_port[i]
rhs_port = port
vll_pusher_cfg.write("%s|%s|%s|%s|%d|%d|\n" % (lhs_dpid, rhs_dpid, lhs_port, rhs_port, LHS_tunnel_vlan[i], RHS_tunnel_vlan[i]))
vll_pusher_cfg.close()
root = Node( 'root', inNamespace=False )
root.cmd("chmod 777 %s" %(path))
示例13: fixEnvironment
# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import cmd [as 别名]
def fixEnvironment(self):
mylog("*** Fix environment\n")
for node in self.nodes_in_rn:
fixIntf(node)
root = Node( 'root', inNamespace=False )
mylog("*** Stop unwanted traffic\n")
root.cmd('stop avahi-daemon')
#root.cmd('killall dhclient')
mylog("*** Kill old processes\n")
root.cmd('killall -r zebra')
root.cmd('killall -r ospfd')
root.cmd('killall sshd')
cfile = '/etc/environment'
line1 = 'VTYSH_PAGER=more\n'
config = open( cfile ).read()
if ( line1 ) not in config:
mylog( '*** Adding %s to %s\n' %(line1.strip(), cfile))
with open( cfile, 'a' ) as f:
f.write( line1 )
f.close();
if os.path.exists(self.temp_cfg):
os.remove(self.temp_cfg)
示例14: connectToInternet
# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import cmd [as 别名]
def connectToInternet( network, switch='s1', rootip='10.254', subnet='10.0/8'):
"""Connect the network to the internet
switch: switch to connect to root namespace
rootip: address for interface in root namespace
subnet: Mininet subnet"""
switch = network.get( switch )
prefixLen = subnet.split( '/' )[ 1 ]
routes = [ subnet ] # host networks to route to
# Create a node in root namespace
root = Node( 'root', inNamespace=False )
# Stop network-manager so it won't interfere
root.cmd( 'service network-manager stop' )
# Create link between root NS and switch
link = network.addLink( root, switch )
link.intf1.setIP( rootip, prefixLen )
# Start network that now includes link to root namespace
network.start()
# Start NAT and establish forwarding
startNAT( root )
# Establish routes from end hosts
for host in network.hosts:
host.cmd( 'ip route flush root 0/0' )
host.cmd( 'route add -net', subnet, 'dev', host.defaultIntf() )
host.cmd( 'route add default gw', rootip )
print "*** Hosts are running and should have internet connectivity"
print "*** Type 'exit' or control-D to shut down network"
CLI( network )
stopNAT( root )
示例15: connectToRootNS
# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import cmd [as 别名]
def connectToRootNS( net, ip='10.123.123.1', mac='00123456789A', prefixLen=8, routes=['10.0.0.0/8']):
print "*** Creating controller"
c0 = net.addController( 'c0', ip='127.0.0.1', port=6633 )
rootswitch = net.addSwitch('roots1',)
rootswitch.dpid = 'FFFFFFFFFFFFFFFF'
# Connect hosts to root namespace via switch. Starts network.
# network: Mininet() network object
# ip: IP address for root namespace node
# prefixLen: IP address prefix length (e.g. 8, 16, 24)
# routes: host networks to route to"
# Create a node in root namespace and link to switch 0
root = Node( 'root', inNamespace=False )
intf = Link( root, rootswitch ).intf1
intf.setMAC(mac)
root.setIP( ip, prefixLen, intf )
print "*** Added Interface", str(intf), "Connected To Root-NameSpace"
fixNetworkManager(str(intf))
for host in net.hosts:
net.addLink(host,rootswitch)
# Add routes from root ns to hosts
for route in routes:
root.cmd( 'route add -net ' + route + ' dev ' + str( intf ) )
root.cmd('service network-manager restart')
return rootswitch