本文整理汇总了Python中mininet.node.Node类的典型用法代码示例。如果您正苦于以下问题:Python Node类的具体用法?Python Node怎么用?Python Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Node类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: connectToRootNS
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: stop
def stop( self, deleteIntfs=False ):
dev_null = open(os.devnull, 'w')
subprocess.call( [ 'docker rm -f ' + self.name ],
stdin=dev_null, stdout=dev_null,
stderr=dev_null, shell=True )
dev_null.close()
Node.stop( self, deleteIntfs )
示例3: checkOVS
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
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: __init__
def __init__(self, name, inMountNamespace=False, inPIDNamespace=False,
inUTSNamespace=False, **params):
"""name: name of node
inNamespace: in network namespace?
inMountNamespace: has private mountspace?
inPIDNamespace: has private PID namespace?
params: Node parameters (see config() for details)"""
# PID and Mount Namespace handling
self.inPIDNamespace = inPIDNamespace
self.inUTSNamespace = inUTSNamespace
self.inMountNamespace = inMountNamespace
# Private config monitoring
self.hasPrivateLogs = False
self.hasPrivateRun = False
# Sanity check on namespace config
if self.inPIDNamespace is True and self.inMountNamespace is False:
raise Exception('PID namespaces require mount namespace for /proc')
# Stash extended configuration information
self.services = {} # dict of services and parameters for this node
self.privateMounts = {} # dict of private mounts for this node
# Network information
self.loIntfs = {}
# Request initialization of the BaseNode
BaseNode.__init__(self, name, **params)
示例6: startNetwork
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 ) )
示例7: connectToInternet
def connectToInternet( network ):
"Connect the network to the internet"
switch = network.switches[ 0 ] # switch to use
ip = '10.0.0.254' # our IP address on host network
routes = [ '10.0.0.0/24' ] # host networks to route to
prefixLen = 24 # subnet mask length
inetIface = "eth0" # host interface for internet connectivity
# Create a node in root namespace and link to switch 0
root = Node( 'root', inNamespace=False )
intf = Link( root, switch ).intf1
#intf = createLink( root, switch )[ 0 ]
#root.setIP( intf, ip, prefixLen )
root.setIP( ip, prefixLen, intf)
# Start network that now includes link to root namespace
network.start()
# Start NAT and establish forwarding
startNAT( inetIface, root )
# Establish routes from end hosts
for host in network.hosts:
host.cmd( 'ip route flush root 0/0' )
#host.cmd( 'route add -net 10.0.0.0/24 dev ' + host.intfs[0] )
host.cmd( 'route add -net 10.0.0.0/24 dev ' + host.intfs[0].name )
host.cmd( 'route add default gw ' + ip )
return root
示例8: start
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'
示例9: sendInt
def sendInt(self, sig=signal.SIGINT):
"""Interrupt running command."""
if self.lastPid and self.inPIDNamespace:
# Cannot kill via os.kill (wrong PID namespace)
# Instead, we kill by running 'kill -SIGNAL pid
# inside of the namespace itself....
killStr = "kill -%d %d" % (sig, self.lastPid)
self.pexec(killStr)
else:
BaseNode.sendInt(self)
示例10: configure_l2_accessnetwork
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))
示例11: __init__
def __init__(self, name, image=None, port_map=None, fs_map=None, **kwargs):
if image is None:
raise UnboundLocalError('Docker image is not specified')
img_id = subprocess.check_output(['docker', 'images', '-q', image])
if not img_id:
raise ValueError('Docker image "%s" does not exist' % image)
self.docker_image = image
self.port_map = port_map
self.fs_map = fs_map
kwargs['inNamespace'] = True
Node.__init__(self, name, **kwargs)
示例12: fixSwitchIntf
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)
示例13: sshd_connectToRootNS
def sshd_connectToRootNS(args,network):
#we create node root and attach it to a swtich
switch = network.getNodeByName(args.names.sw_sshd[0])
#ip of root
ip = '172.16.255.1/32'
root = Node( 'root', inNamespace=False )
intf = Link( root, switch ).intf1
root.setIP( ip, intf=intf )
return root,intf
示例14: __init__
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 = {}
示例15: connectToRootNS
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 ) )