本文整理匯總了Python中mininet.node.Controller方法的典型用法代碼示例。如果您正苦於以下問題:Python node.Controller方法的具體用法?Python node.Controller怎麽用?Python node.Controller使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mininet.node
的用法示例。
在下文中一共展示了node.Controller方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: apply
# 需要導入模塊: from mininet import node [as 別名]
# 或者: from mininet.node import Controller [as 別名]
def apply(self):
self.result = { 'hostname': self.hostnameEntry.get(),
'remoteIP': self.e1.get(),
'remotePort': int(self.e2.get())}
controllerType = self.var.get()
if controllerType == 'Remote Controller':
self.result['controllerType'] = 'remote'
elif controllerType == 'In-Band Controller':
self.result['controllerType'] = 'inband'
elif controllerType == 'OpenFlow Reference':
self.result['controllerType'] = 'ref'
else:
self.result['controllerType'] = 'ovsc'
controllerProtocol = self.protcolvar.get()
if controllerProtocol == 'SSL':
self.result['controllerProtocol'] = 'ssl'
else:
self.result['controllerProtocol'] = 'tcp'
開發者ID:PacktPublishing,項目名稱:Python-Network-Programming-Cookbook-Second-Edition,代碼行數:21,代碼來源:miniedit.py
示例2: deleteNode
# 需要導入模塊: from mininet import node [as 別名]
# 或者: from mininet.node import Controller [as 別名]
def deleteNode( self, item ):
"Delete node (and its links) from model."
widget = self.itemToWidget[ item ]
tags = self.canvas.gettags(item)
if 'Controller' in tags:
# remove from switch controller lists
for serachwidget in self.widgetToItem:
name = serachwidget[ 'text' ]
tags = self.canvas.gettags( self.widgetToItem[ serachwidget ] )
if 'Switch' in tags:
if widget['text'] in self.switchOpts[name]['controllers']:
self.switchOpts[name]['controllers'].remove(widget['text'])
for link in widget.links.values():
# Delete from view and model
self.deleteItem( link )
del self.itemToWidget[ item ]
del self.widgetToItem[ widget ]
開發者ID:PacktPublishing,項目名稱:Python-Network-Programming-Cookbook-Second-Edition,代碼行數:21,代碼來源:miniedit.py
示例3: createNet
# 需要導入模塊: from mininet import node [as 別名]
# 或者: from mininet.node import Controller [as 別名]
def createNet(
self,
nswitches=0, ndatacenter=0, nhosts=0, ndockers=0,
autolinkswitches=False, controller=Controller, **kwargs):
"""
Creates a Mininet instance and automatically adds some
nodes to it.
Attention, we should always use Mininet's default controller
for our tests. Only use other controllers if you want to test
specific controller functionality.
"""
self.net = DCNetwork(controller=controller, **kwargs)
# add some switches
# start from s1 because ovs does not like to have dpid = 0
# and switch name-number is being used by mininet to set the dpid
for i in range(1, nswitches + 1):
self.s.append(self.net.addSwitch('s%d' % i))
# if specified, chain all switches
if autolinkswitches:
for i in range(0, len(self.s) - 1):
self.net.addLink(self.s[i], self.s[i + 1])
# add some data centers
for i in range(0, ndatacenter):
self.dc.append(
self.net.addDatacenter(
'datacenter%d' % i,
metadata={"unittest_dc": i}))
# add some hosts
for i in range(0, nhosts):
self.h.append(self.net.addHost('h%d' % i))
# add some dockers
for i in range(0, ndockers):
self.d.append(self.net.addDocker('d%d' %
i, dimage="ubuntu:trusty"))
示例4: createNet
# 需要導入模塊: from mininet import node [as 別名]
# 或者: from mininet.node import Controller [as 別名]
def createNet(
self,
nswitches=0, ndatacenter=0, nhosts=0, ndockers=0,
autolinkswitches=False, controller=Controller, **kwargs):
"""
Creates a Mininet instance and automatically adds some
nodes to it.
Attention, we should always use Mininet's default controller
for our tests. Only use other controllers if you want to test
specific controller functionality.
"""
self.net = DCNetwork(controller=controller, **kwargs)
self.api = RestApiEndpoint("127.0.0.1", 5001, self.net)
# add some switches
# start from s1 because ovs does not like to have dpid = 0
# and switch name-number is being used by mininet to set the dpid
for i in range(1, nswitches + 1):
self.s.append(self.net.addSwitch('s%d' % i))
# if specified, chain all switches
if autolinkswitches:
for i in range(0, len(self.s) - 1):
self.net.addLink(self.s[i], self.s[i + 1])
# add some data centers
for i in range(0, ndatacenter):
self.dc.append(
self.net.addDatacenter(
'datacenter%d' % i,
metadata={"unittest_dc": i}))
# connect data centers to the endpoint
for i in range(0, ndatacenter):
self.api.connectDatacenter(self.dc[i])
# add some hosts
for i in range(0, nhosts):
self.h.append(self.net.addHost('h%d' % i))
# add some dockers
for i in range(0, ndockers):
self.d.append(self.net.addDocker('d%d' %
i, dimage="ubuntu:trusty"))
示例5: addNode
# 需要導入模塊: from mininet import node [as 別名]
# 或者: from mininet.node import Controller [as 別名]
def addNode( self, node, nodeNum, x, y, name=None):
"Add a new node to our canvas."
if 'Switch' == node:
self.switchCount += 1
if 'Host' == node:
self.hostCount += 1
if 'Controller' == node:
self.controllerCount += 1
if name is None:
name = self.nodePrefixes[ node ] + nodeNum
self.addNamedNode(node, name, x, y)
開發者ID:PacktPublishing,項目名稱:Python-Network-Programming-Cookbook-Second-Edition,代碼行數:13,代碼來源:miniedit.py
示例6: clickController
# 需要導入模塊: from mininet import node [as 別名]
# 或者: from mininet.node import Controller [as 別名]
def clickController( self, event ):
"Add a new Controller to our canvas."
self.newNode( 'Controller', event )
開發者ID:PacktPublishing,項目名稱:Python-Network-Programming-Cookbook-Second-Edition,代碼行數:5,代碼來源:miniedit.py
示例7: controllerDetails
# 需要導入模塊: from mininet import node [as 別名]
# 或者: from mininet.node import Controller [as 別名]
def controllerDetails( self ):
if ( self.selection is None or
self.net is not None or
self.selection not in self.itemToWidget ):
return
widget = self.itemToWidget[ self.selection ]
name = widget[ 'text' ]
tags = self.canvas.gettags( self.selection )
oldName = name
if 'Controller' not in tags:
return
ctrlrBox = ControllerDialog(self, title='Controller Details', ctrlrDefaults=self.controllers[name])
if ctrlrBox.result:
# debug( 'Controller is ' + ctrlrBox.result[0], '\n' )
if len(ctrlrBox.result['hostname']) > 0:
name = ctrlrBox.result['hostname']
widget[ 'text' ] = name
else:
ctrlrBox.result['hostname'] = name
self.controllers[name] = ctrlrBox.result
info( 'New controller details for ' + name + ' = ' + str(self.controllers[name]), '\n' )
# Find references to controller and change name
if oldName != name:
for widget in self.widgetToItem:
switchName = widget[ 'text' ]
tags = self.canvas.gettags( self.widgetToItem[ widget ] )
if 'Switch' in tags:
switch = self.switchOpts[switchName]
if oldName in switch['controllers']:
switch['controllers'].remove(oldName)
switch['controllers'].append(name)
開發者ID:PacktPublishing,項目名稱:Python-Network-Programming-Cookbook-Second-Edition,代碼行數:34,代碼來源:miniedit.py
示例8: deleteLink
# 需要導入模塊: from mininet import node [as 別名]
# 或者: from mininet.node import Controller [as 別名]
def deleteLink( self, link ):
"Delete link from model."
pair = self.links.get( link, None )
if pair is not None:
source=pair['src']
dest=pair['dest']
del source.links[ dest ]
del dest.links[ source ]
stags = self.canvas.gettags( self.widgetToItem[ source ] )
# dtags = self.canvas.gettags( self.widgetToItem[ dest ] )
ltags = self.canvas.gettags( link )
if 'control' in ltags:
controllerName = ''
switchName = ''
if 'Controller' in stags:
controllerName = source[ 'text' ]
switchName = dest[ 'text' ]
else:
controllerName = dest[ 'text' ]
switchName = source[ 'text' ]
if controllerName in self.switchOpts[switchName]['controllers']:
self.switchOpts[switchName]['controllers'].remove(controllerName)
if link is not None:
del self.links[ link ]
開發者ID:PacktPublishing,項目名稱:Python-Network-Programming-Cookbook-Second-Edition,代碼行數:30,代碼來源:miniedit.py
示例9: __init__
# 需要導入模塊: from mininet import node [as 別名]
# 或者: from mininet.node import Controller [as 別名]
def __init__(self,
router: Type[Router] = Router,
config: Type[RouterConfig] = BasicRouterConfig,
use_v4=True,
ipBase='192.168.0.0/16',
max_v4_prefixlen=24,
use_v6=True,
ip6Base='fc00::/7',
allocate_IPs=True,
max_v6_prefixlen=48,
igp_metric=MIN_IGP_METRIC,
igp_area=OSPF_DEFAULT_AREA,
host: Type[IPHost] = IPHost,
link: Type[IPLink] = IPLink,
intf: Type[IPIntf] = IPIntf,
switch: Type[IPSwitch] = IPSwitch,
controller: Optional[Type[Controller]] = None,
*args, **kwargs):
"""Extends Mininet by adding IP-related ivars/functions and
configuration knobs.
:param router: The class to use to build routers
:param config: The default configuration for the routers
:param use_v4: Enable IPv4
:param max_v4_prefixlen: The maximal IPv4 prefix for the auto-allocated
broadcast domains
:param use_v6: Enable IPv6
:param ip6Base: Base prefix to use for IPv6 allocations
:param max_v6_prefixlen: Maximal IPv6 prefixlen to auto-allocate
:param allocate_IPs: whether to auto-allocate subnets in the network
:param igp_metric: The default IGP metric for the links
:param igp_area: The default IGP area for the links"""
self.router = router
self.config = config
self.routers = [] # type: List[Router]
# We need this to be able to do inverse-lookups
self._ip_allocs = {} # type: Dict[str, Node]
self.max_v4_prefixlen = max_v4_prefixlen
self._unallocated_ipbase = [ip_network(ipBase)]
self.use_v4 = use_v4
self.use_v6 = use_v6
self.ip6Base = ip6Base
self.max_v6_prefixlen = max_v6_prefixlen
self._unallocated_ip6base = [ip_network(ip6Base)]
self.broadcast_domains = None
self.igp_metric = igp_metric
self.igp_area = igp_area
self.allocate_IPs = allocate_IPs
self.physical_interface = {} # type: Dict[IPIntf, Node]
super().__init__(ipBase=ipBase, host=host, switch=switch, link=link,
intf=intf, controller=controller, *args, **kwargs)
示例10: createNet
# 需要導入模塊: from mininet import node [as 別名]
# 或者: from mininet.node import Controller [as 別名]
def createNet(
self,
nswitches=0, ndatacenter=0, nhosts=0, ndockers=0,
autolinkswitches=False, controller=Controller, **kwargs):
"""
Creates a Mininet instance and automatically adds some
nodes to it.
Attention, we should always use Mininet's default controller
for our tests. Only use other controllers if you want to test
specific controller functionality.
"""
self.net = DCNetwork(controller=controller, **kwargs)
for i in range(0, ndatacenter):
self.api.append(OpenstackApiEndpoint("0.0.0.0", 15000 + i))
# add some switches
# start from s1 because ovs does not like to have dpid = 0
# and switch name-number is being used by mininet to set the dpid
for i in range(1, nswitches + 1):
self.s.append(self.net.addSwitch('s%d' % i))
# if specified, chain all switches
if autolinkswitches:
for i in range(0, len(self.s) - 1):
self.net.addLink(self.s[i], self.s[i + 1])
# link switches s1, s2 and s3
self.net.addLink(self.s[2], self.s[0])
# add some data centers
for i in range(0, ndatacenter):
self.dc.append(
self.net.addDatacenter(
'dc%d' % i,
metadata={"unittest_dc": i}))
# link switches dc0.s1 with s1
self.net.addLink(self.dc[0].switch, self.s[0])
# connect data centers to the endpoint
for i in range(0, ndatacenter):
self.api[i].connect_datacenter(self.dc[i])
self.api[i].connect_dc_network(self.net)
# add some hosts
for i in range(0, nhosts):
self.h.append(self.net.addHost('h%d' % i))
# add some dockers
for i in range(0, ndockers):
self.d.append(self.net.addDocker('d%d' %
i, dimage="ubuntu:trusty"))
示例11: start
# 需要導入模塊: from mininet import node [as 別名]
# 或者: from mininet.node import Controller [as 別名]
def start(self, controllers):
# Transcluded from Mininet source, since need to insert
# controller parameters at switch creation time.
int(self.dpid, 16) # DPID must be a hex string
switch_intfs = [intf for intf in self.intfList() if self.ports[intf] and not intf.IP()]
# Command to add interfaces
intfs = ' '.join(' -- add-port %s %s' % (self, intf) +
self.intfOpts(intf)
for intf in switch_intfs)
# Command to create controller entries
clist = [(self.name + c.name, '%s:%s:%d' %
(c.protocol, c.IP(), c.port))
for c in controllers]
if self.listenPort:
clist.append((self.name + '-listen',
'ptcp:%s' % self.listenPort))
ccmd = '-- --id=@%s create Controller target=\\"%s\\"'
if self.reconnectms:
ccmd += ' max_backoff=%d' % self.reconnectms
for param, value in self.controller_params.items():
ccmd += ' %s=%s' % (param, value)
cargs = ' '.join(ccmd % (name, target)
for name, target in clist)
# Controller ID list
cids = ','.join('@%s' % name for name, _target in clist)
# Try to delete any existing bridges with the same name
if not self.isOldOVS():
cargs += ' -- --if-exists del-br %s' % self
# One ovs-vsctl command to rule them all!
self.vsctl(cargs +
' -- add-br %s' % self +
' -- set bridge %s controller=[%s]' % (self, cids) +
self.bridgeOpts() +
intfs)
# switch interfaces on mininet host, must have no IP config.
for intf in switch_intfs:
for ipv in (4, 6):
self.cmd('ip -%u addr flush dev %s' % (ipv, intf))
assert self.cmd('echo 1 > /proc/sys/net/ipv6/conf/%s/disable_ipv6' % intf) == ''
# If necessary, restore TC config overwritten by OVS
if not self.batch:
for intf in self.intfList():
self.TCReapply(intf)
示例12: emulate
# 需要導入模塊: from mininet import node [as 別名]
# 或者: from mininet.node import Controller [as 別名]
def emulate():
# Setting the position of nodes and providing mobility
# Create a network.
net = Mininet(controller=Controller, link=TCLink, accessPoint=OVSKernelAP)
print ("*** Creating nodes")
# Add the host
h1 = net.addHost('h1', mac='00:00:00:00:00:01', ip='10.0.0.1/8')
# Add 3 mobile stations, sta1, sta2, sta3.
sta1 = net.addStation('sta1', mac='00:00:00:00:00:02', ip='10.0.0.2/8')
sta2 = net.addStation('sta2', mac='00:00:00:00:00:03', ip='10.0.0.3/8')
sta3 = net.addStation('sta3', mac='00:00:00:00:00:04', ip='10.0.0.4/8')
# Add an access point
ap1 = net.addAccessPoint('ap1', ssid='new-ssid', mode='g', channel='1', position='45,40,30')
# Add a controller
c1 = net.addController('c1', controller=Controller)
print ("*** Configuring wifi nodes")
net.configureWifiNodes()
print ("*** Associating and Creating links")
net.addLink(ap1, h1)
net.addLink(ap1, sta1)
net.addLink(ap1, sta2)
net.addLink(ap1, sta3)
print ("*** Starting network")
net.build()
c1.start()
ap1.start([c1])
# Plot a 3-dimensional graph.
net.plotGraph(max_x=100, max_y=100, max_z=200)
# Start the mobility at the start of the emulation.
net.startMobility(time=0)
# Start the mobile stations from their initial positions.
net.mobility(sta1, 'start', time=1, position='40.0,30.0,20.0')
net.mobility(sta2, 'start', time=2, position='40.0,40.0,90.0')
net.mobility(sta3, 'start', time=3, position='50.0,50.0,160.0')
# Indicate the final destination of the mobile stations during the emulation.
net.mobility(sta1, 'stop', time=12, position='31.0,10.0,50.0')
net.mobility(sta2, 'stop', time=22, position='55.0,31.0,30.0')
net.mobility(sta3, 'stop', time=32, position='75.0,99.0,120.0')
# Stop the mobility at certain time.
net.stopMobility(time=33)
print ("*** Running CLI")
CLI(net)
print ("*** Stopping network")
net.stop()
開發者ID:PacktPublishing,項目名稱:Python-Network-Programming-Cookbook-Second-Edition,代碼行數:61,代碼來源:9_4_mininet_wifi_emulation.py
示例13: body
# 需要導入模塊: from mininet import node [as 別名]
# 或者: from mininet.node import Controller [as 別名]
def body(self, master):
self.var = StringVar(master)
self.protcolvar = StringVar(master)
rowCount=0
# Field for Hostname
Label(master, text="Name:").grid(row=rowCount, sticky=E)
self.hostnameEntry = Entry(master)
self.hostnameEntry.grid(row=rowCount, column=1)
self.hostnameEntry.insert(0, self.ctrlrValues['hostname'])
rowCount+=1
# Field for Remove Controller Port
Label(master, text="Controller Port:").grid(row=rowCount, sticky=E)
self.e2 = Entry(master)
self.e2.grid(row=rowCount, column=1)
self.e2.insert(0, self.ctrlrValues['remotePort'])
rowCount+=1
# Field for Controller Type
Label(master, text="Controller Type:").grid(row=rowCount, sticky=E)
controllerType = self.ctrlrValues['controllerType']
self.o1 = OptionMenu(master, self.var, "Remote Controller", "In-Band Controller", "OpenFlow Reference", "OVS Controller")
self.o1.grid(row=rowCount, column=1, sticky=W)
if controllerType == 'ref':
self.var.set("OpenFlow Reference")
elif controllerType == 'inband':
self.var.set("In-Band Controller")
elif controllerType == 'remote':
self.var.set("Remote Controller")
else:
self.var.set("OVS Controller")
rowCount+=1
# Field for Controller Protcol
Label(master, text="Protocol:").grid(row=rowCount, sticky=E)
if 'controllerProtocol' in self.ctrlrValues:
controllerProtocol = self.ctrlrValues['controllerProtocol']
else:
controllerProtocol = 'tcp'
self.protcol = OptionMenu(master, self.protcolvar, "TCP", "SSL")
self.protcol.grid(row=rowCount, column=1, sticky=W)
if controllerProtocol == 'ssl':
self.protcolvar.set("SSL")
else:
self.protcolvar.set("TCP")
rowCount+=1
# Field for Remove Controller IP
remoteFrame= LabelFrame(master, text='Remote/In-Band Controller', padx=5, pady=5)
remoteFrame.grid(row=rowCount, column=0, columnspan=2, sticky=W)
Label(remoteFrame, text="IP Address:").grid(row=0, sticky=E)
self.e1 = Entry(remoteFrame)
self.e1.grid(row=0, column=1)
self.e1.insert(0, self.ctrlrValues['remoteIP'])
rowCount+=1
return self.hostnameEntry # initial focus
開發者ID:PacktPublishing,項目名稱:Python-Network-Programming-Cookbook-Second-Edition,代碼行數:62,代碼來源:miniedit.py