本文整理汇总了Python中ryu.lib.hub.spawn函数的典型用法代码示例。如果您正苦于以下问题:Python spawn函数的具体用法?Python spawn怎么用?Python spawn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了spawn函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, *args, **kwargs):
super(Generic_Agent_CHT, self).__init__(*args, **kwargs)
global CTRL_TYPE
hub.spawn(self.exit_detect_thread)
CTRL_TYPE = raw_input('Please input SDN Controller Type: ')
while True:
try:
# Get SYSTEM_NAME from Generic_LLDP_Module
response = self.session.post(GENERIC_URL_BASE + '/controllers/regist/' + CTRL_TYPE)
# if response code not 200, raise an exception
response.raise_for_status()
data = yaml.safe_load(response.text)
self.SYSTEM_NAME = data['system_name']
self.LLDP_FORMAT = data['LLDP_subtype']
break
except Exception as e:
print e
time.sleep(5)
self.datapaths = {}
self.links = {}
self.mac_to_port = {}
self.LLDP_recv_port = {}
self.hosts = {}
hub.spawn(self.lldp_thread)
示例2: __init__
def __init__(self,*args,**kwargs):
super(ForwardingBasic,self).__init__(args,kwargs)
self.CONF.register_opts([
cfg.StrOpt("topology",default = None,
help = "Specified network topology",
)
])
self.topo = "fattree"
self.topo = None
self.name = "Forwarding-Basic"
self.spanning_tree_done = True
self.spanning_tree_links = set([])
self.mac_to_port = {}
self.mac_to_port.setdefault(0,{})
self.install_port_events = True
self.total_links = 0
self.poll_port_stats = True
self.link_rate_out_file = open("logs/link_rate.out.%s" %time.strftime("%Y%m%d_%H%M%S") ,'w')
if self.topo is None:
self.logger.info("No topology specified.")
else:
self.logger.info("Specified topology is %s" %self.topo)
if self.topo == 'fattree':
self.expected_links = 64
self.fat_tree_k = 4
spawn(self.send_port_req_loop)
示例3: __init__
def __init__(self, *args, **kwargs):
super(Ryu,self).__init__(*args,**kwargs)
#--- register for configuration options
self.CONF.register_opts([
cfg.StrOpt('SciPassConfig',default='/etc/SciPass/SciPass.xml',
help='where to find the SciPass config file'),
])
self.logger.error("Starting SciPass")
self.datapaths = {}
self.isactive = 1
self.statsInterval = 5
self.balanceInterval = 15
self.bal = None
self.stats = {}
self.stats_thread = hub.spawn(self._stats_loop)
self.balance_thread = hub.spawn(self._balance_loop)
self.ports = defaultdict(dict);
self.prefix_bytes = defaultdict(lambda: defaultdict(int))
self.lastStatsTime = None
self.flowmods = {}
api = SciPass(logger = self.logger,
config_file = self.CONF.SciPassConfig )
api.registerForwardingStateChangeHandler(self.changeSwitchForwardingState)
self.api = api
wsgi = kwargs['wsgi']
wsgi.register(SciPassRest, {'api' : self.api})
示例4: _create_dot1x_speaker
def _create_dot1x_speaker(self, dot1x_intf, chewie_id, radius_ip, radius_port, radius_secret):
chewie = Chewie( # pylint: disable=too-many-function-args
dot1x_intf, self.logger,
self.auth_handler, self.failure_handler, self.logoff_handler,
radius_ip, radius_port, radius_secret, chewie_id)
hub.spawn(chewie.run)
return chewie
示例5: main
def main():
try:
CONF(project='ryu', version='ryu-manager %s' % version,
default_config_files=['/usr/local/etc/ryu/ryu.conf'])
except cfg.ConfigFilesNotFoundError:
CONF(project='ryu', version='ryu-manager %s' % version)
log.init_log()
# always enable ofp for now.
app_lists = CONF.app_lists + CONF.app + ['ryu.controller.ofp_handler']
app_mgr = AppManager()
app_mgr.load_apps(app_lists)
contexts = app_mgr.create_contexts()
app_mgr.instantiate_apps(**contexts)
services = []
ctlr = controller.OpenFlowController()
thr = hub.spawn(ctlr)
services.append(thr)
webapp = wsgi.start_service(app_mgr)
if webapp:
thr = hub.spawn(webapp)
services.append(thr)
try:
hub.joinall(services)
finally:
app_mgr.close()
示例6: start
def start(self):
super(RemoteOvsdb, self).start()
t = hub.spawn(self._run_thread, self._idl_loop)
self.threads.append(t)
t = hub.spawn(self._run_thread, self._event_proxy_loop)
self.threads.append(t)
示例7: _start_recv_nw_sock
def _start_recv_nw_sock(self, port):
self.nwsock = hub.socket.socket(hub.socket.AF_INET, hub.socket.SOCK_STREAM)
self.nwsock.bind(("0.0.0.0", port))
self.nwsock.listen(5)
hub.spawn(self._recv_loop_nw_sock)
示例8: __init__
def __init__(self, *args, **kwargs):
super(ProxyAccess, self).__init__(*args, **kwargs)
self.mac_to_port = {}
self.ip_to_mac = {}
self.dps = []
self.web_server_dp = None
hub.spawn(self._redirect)
示例9: start
def start(self):
super(RyuBGPSpeaker, self).start()
# If configuration file was provided and loaded successfully, we start
# BGPSpeaker using the given settings.
# If no configuration file is provided or if any minimum required
# setting is missing, BGPSpeaker will not be started.
if self.config_file:
LOG.debug('Loading config file %s...', self.config_file)
settings = load_config(self.config_file)
# Configure logging settings, if available.
if hasattr(settings, 'LOGGING'):
# Not implemented yet.
LOG.debug('Loading LOGGING settings... (NOT implemented yet)')
# from logging.config import dictConfig
# logging_settings = dictConfig(settings.LOGGING)
# Configure BGP settings, if available.
if hasattr(settings, 'BGP'):
LOG.debug('Loading BGP settings...')
self._start_speaker(settings.BGP)
# Configure SSH settings, if available.
if hasattr(settings, 'SSH'):
LOG.debug('Loading SSH settings...')
hub.spawn(SSH_CLI_CONTROLLER.start, **settings.SSH)
# Start RPC server with the given RPC settings.
rpc_settings = {
NC_RPC_BIND_PORT: CONF.rpc_port,
NC_RPC_BIND_IP: validate_rpc_host(CONF.rpc_host),
}
return hub.spawn(NET_CONTROLLER.start, **rpc_settings)
示例10: __init__
def __init__(self, *args, **kwargs):
super(SDNIP, self).__init__(*args, **kwargs)
self.fwd = kwargs['fwd']
self.hop_db = kwargs['hop_db']
self.cfg_mgr = SDNIPConfigManager()
self.waiters = {}
self.bgp_speaker =\
BGPSpeaker(self.cfg_mgr.as_number,
str(self.cfg_mgr.router_id),
bgp_server_port=self.cfg_mgr.listen_port,
best_path_change_handler=self.best_path_change_handler,
peer_down_handler=self.peer_down_handler,
peer_up_handler=self.peer_up_handler)
speaker_ids = self.cfg_mgr.get_all_speaker_id()
for speaker_id in speaker_ids:
self.bgp_speaker.neighbor_add(speaker_id,
self.cfg_mgr.as_number,
is_next_hop_self=True)
hub.spawn(self.prefix_check_loop)
if with_dk:
dk_plugin.DynamicLoader.register_custom_cmd('sdn-ip:info', self.cmd_self_info)
dk_plugin.DynamicLoader.register_custom_cmd('sdn-ip:routes', self.cmd_list_routes)
dk_plugin.DynamicLoader.register_custom_cmd('sdn-ip:flows', self.cmd_get_flows)
示例11: start
def start(self):
self.receive = True
self.queue = hub.Queue()
self.receive_thread = hub.spawn(self.receiver)
self.logger.info('server: receiver thread spawned')
self.processor_thread = hub.spawn(self.service_queue)
self.logger.info('server: processor thread spawned')
示例12: __init__
def __init__(self, *args, **kwargs):
super(Switches, self).__init__(*args, **kwargs)
self.name = 'switches'
self.dps = {} # datapath_id => Datapath class
self.port_state = {} # datapath_id => ports
self.ports = PortDataState() # Port class -> PortData class
self.links = LinkState() # Link class -> timestamp
self.is_active = True
# by jesse : for other controller link
self.cports = PortDataState()
self.clinks = LinkState()
# by jesse : for same switch port link (in_port == out_port)
self.sports = PortDataState()
self.slinks = LinkState()
# by jesse : add vlan
self.update_lldp_data_flag = False
self.link_discovery = self.CONF.observe_links
if self.link_discovery:
self.install_flow = self.CONF.install_lldp_flow
self.explicit_drop = self.CONF.explicit_drop
self.lldp_event = hub.Event()
self.link_event = hub.Event()
self.threads.append(hub.spawn(self.lldp_loop))
self.threads.append(hub.spawn(self.link_loop))
示例13: _create_bgp_speaker_for_vlan
def _create_bgp_speaker_for_vlan(self, vlan, bgp_speaker_key):
"""Set up BGP speaker for an individual VLAN if required.
Args:
vlan (valve VLAN): VLAN for BGP speaker.
Returns:
ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker: BGP speaker.
"""
route_handler = lambda x: self._bgp_route_handler(x, bgp_speaker_key)
server_address = sorted(vlan.bgp_server_addresses_by_ipv(bgp_speaker_key.ipv))[0]
beka = Beka(
local_address=str(server_address),
bgp_port=vlan.bgp_port,
local_as=vlan.bgp_as,
router_id=vlan.bgp_routerid,
peer_up_handler=self._bgp_up_handler,
peer_down_handler=self._bgp_down_handler,
route_handler=route_handler,
error_handler=self.logger.warning)
for ip_dst, ip_gw in self._vlan_prefixes_by_ipv(vlan, bgp_speaker_key.ipv):
beka.add_route(prefix=str(ip_dst), next_hop=str(ip_gw))
for bgp_neighbor_address in vlan.bgp_neighbor_addresses_by_ipv(bgp_speaker_key.ipv):
beka.add_neighbor(
connect_mode=vlan.bgp_connect_mode,
peer_ip=str(bgp_neighbor_address),
peer_as=vlan.bgp_neighbor_as)
hub.spawn(beka.run)
return beka
示例14: start
def start(self):
self.epl.listen(9999, "127.0.0.1")
self.icsq = self.epl.incoming_connection_status()
self.mql = message_queue(queuename, self.epl)
self.threads.append(hub.spawn(self._broker_loop))
self.logger.info("Started broker communication...")
self.threads.append(hub.spawn(self._event_loop))
示例15: _meter_stats_reply_handler
def _meter_stats_reply_handler(self, ev):
body = ev.msg.body
dpid = ev.msg.datapath.id
self.logger.info('datapath meter_id kbps ')
self.logger.info('---------------- -------- --------')
modified_ports = []
for stat in sorted(body, key=attrgetter('meter_id')):
if stat.meter_id in self.time_prev[dpid]:
sleep = float(stat.duration_sec) + (stat.duration_nsec / 10.0**9) - self.time_prev[dpid][stat.meter_id]
self.meter_speed[dpid][stat.meter_id] = self._get_speed(stat.byte_in_count, self.meter_prev[dpid][stat.meter_id], sleep)
else:
self.meter_speed[dpid][stat.meter_id] = 0
self.time_prev[dpid][stat.meter_id] = float(stat.duration_sec) + (stat.duration_nsec / 10.0**9)
self.meter_prev[dpid][stat.meter_id] = stat.byte_in_count
self.logger.info("%016x %08x %6.1f",dpid, stat.meter_id, self.meter_speed[dpid][stat.meter_id])
if stat.meter_id in self.meter_to_src[dpid]:
src = self.meter_to_src[dpid][stat.meter_id]
port = self.mac_to_port[dpid][src]
self.rate_used[dpid].setdefault(port, {})
self.rate_used_mod[dpid].setdefault(port, {})
self.rate_used[dpid][port][src] = self.meter_speed[dpid][stat.meter_id]
if (self.rate_used[dpid][port][src] >= int(self.rate_allocated[dpid][port][src]*0.7)
and (self.rate_allocated[dpid][port][src] < self.rate_request[dpid][port][src])):
if int(self.rate_allocated[dpid][port][src]*1.5) < self.rate_request[dpid][port][src]:
self.rate_used_mod[dpid][port][src] = int(self.rate_allocated[dpid][port][src]*1.5)
else:
self.rate_used_mod[dpid][port][src] = self.rate_request[dpid][port][src]
if port not in modified_ports:
modified_ports.append(port)
else:
self.rate_used_mod[dpid][port][src] = self.rate_used[dpid][port][src]
for port in modified_ports:
hub.spawn(self._mod_port_meters, dpid, port)