本文整理汇总了Python中ryu.lib.hub.sleep方法的典型用法代码示例。如果您正苦于以下问题:Python hub.sleep方法的具体用法?Python hub.sleep怎么用?Python hub.sleep使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ryu.lib.hub
的用法示例。
在下文中一共展示了hub.sleep方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: prefix_check_loop
# 需要导入模块: from ryu.lib import hub [as 别名]
# 或者: from ryu.lib.hub import sleep [as 别名]
def prefix_check_loop(self):
while True:
prefixs_to_install = self.hop_db.get_uninstalled_prefix_list()
self.logger.debug("prefix to install: %s", str(prefixs_to_install))
for prefix in prefixs_to_install:
prefix_nw = IPNetwork(prefix)
for internal_network in self.cfg_mgr.get_internal_networks():
int_nw = IPNetwork(internal_network)
if int_nw == prefix_nw:
self.logger.info('Internal network, ignored.')
continue
nexthop = self.hop_db.get_nexthop(prefix)
self.install_best_path(prefix, nexthop)
hub.sleep(3)
示例2: _monitor
# 需要导入模块: from ryu.lib import hub [as 别名]
# 或者: from ryu.lib.hub import sleep [as 别名]
def _monitor(self):
"""
Main entry method of monitoring traffic.
"""
while CONF.weight == 'bw':
self.stats['flow'] = {}
self.stats['port'] = {}
for dp in self.datapaths.values():
self.port_features.setdefault(dp.id, {})
self._request_stats(dp)
# Refresh data.
self.capabilities = None
self.best_paths = None
hub.sleep(setting.MONITOR_PERIOD)
if self.stats['flow'] or self.stats['port']:
self.show_stat('flow')
self.show_stat('port')
hub.sleep(1)
示例3: _send_loop
# 需要导入模块: from ryu.lib import hub [as 别名]
# 或者: from ryu.lib.hub import sleep [as 别名]
def _send_loop(self):
"""
A loop to proceed periodic BFD packet transmission.
"""
while self._enable_send:
hub.sleep(self._xmit_period)
# Send BFD packet. (RFC5880 Section 6.8.7.)
if self._remote_discr == 0 and not self._active_role:
continue
if self._remote_min_rx_interval == 0:
continue
if self._remote_demand_mode and \
self._session_state == bfd.BFD_STATE_UP and \
self._remote_session_state == bfd.BFD_STATE_UP and \
not self._is_polling:
continue
self._send()
示例4: _do_timeout_for_query
# 需要导入模块: from ryu.lib import hub [as 别名]
# 或者: from ryu.lib.hub import sleep [as 别名]
def _do_timeout_for_query(self, timeout, datapath):
"""the process when the QUERY from the querier timeout expired."""
dpid = datapath.id
hub.sleep(timeout)
outport = self._to_querier[dpid]['port']
remove_dsts = []
for dst in self._to_hosts[dpid]:
if not self._to_hosts[dpid][dst]['replied']:
# if no REPORT message sent from any members of
# the group, remove flow entries about the group and
# send a LEAVE message if exists.
self._remove_multicast_group(datapath, outport, dst)
remove_dsts.append(dst)
for dst in remove_dsts:
del self._to_hosts[dpid][dst]
示例5: _switch_request_async
# 需要导入模块: from ryu.lib import hub [as 别名]
# 或者: from ryu.lib.hub import sleep [as 别名]
def _switch_request_async(self, interval):
while self.is_active:
request = event.EventSwitchRequest()
LOG.debug('switch_request async %s thread(%s)',
request, id(hub.getcurrent()))
self.send_event(request.dst, request)
start = time.time()
busy = interval / 2
i = 0
while i < busy:
if time.time() > start + i:
i += 1
LOG.debug(' thread is busy... %s/%s thread(%s)',
i, busy, id(hub.getcurrent()))
LOG.debug(' thread yield to switch_reply handler. thread(%s)',
id(hub.getcurrent()))
# yield
hub.sleep(0)
LOG.debug(' thread get back. thread(%s)',
id(hub.getcurrent()))
hub.sleep(interval - busy)
示例6: test_0_call_error_notification
# 需要导入模块: from ryu.lib import hub [as 别名]
# 或者: from ryu.lib.hub import sleep [as 别名]
def test_0_call_error_notification(self):
l = []
def callback(n):
l.append(n)
c = rpc.Client(self._client_sock, notification_callback=callback)
c.send_notification(b'notify2', [b'notify_foo', []])
hub.sleep(0.5) # give the peer a chance to run
obj = b'hoge'
try:
c.call(b'err', [obj])
raise Exception("unexpected")
except rpc.RPCError as e:
assert e.get_value() == obj
assert len(l) == 1
n = l.pop(0)
method, params = n
assert method == b'notify_foo'
assert params == []
示例7: test_spawn_event3
# 需要导入模块: from ryu.lib import hub [as 别名]
# 或者: from ryu.lib.hub import sleep [as 别名]
def test_spawn_event3(self):
def _child(ev, ev2, result):
ev2.wait()
hub.sleep(0.5)
result.append(1)
ev.set()
ev = hub.Event()
ev2 = hub.Event()
result = []
with hub.Timeout(2):
hub.spawn(_child, ev, ev2, result)
hub.spawn(_child, ev, ev2, result)
hub.sleep(0.5)
ev2.set() # this should wake up the above created two threads
ev.wait(timeout=1)
assert len(result) == 2
示例8: test_spawn_joinall
# 需要导入模块: from ryu.lib import hub [as 别名]
# 或者: from ryu.lib.hub import sleep [as 别名]
def test_spawn_joinall(self):
def _child(ev2, result):
ev2.wait()
hub.sleep(0.5)
result.append(1)
raise BaseException("this exception should not be propagated")
ev2 = hub.Event()
threads = []
result = []
with hub.Timeout(2):
threads.append(hub.spawn(_child, ev2, result))
threads.append(hub.spawn(_child, ev2, result))
hub.sleep(0.5)
ev2.set() # this should wake up the above created two threads
hub.joinall(threads)
assert len(result) == 2
示例9: next
# 需要导入模块: from ryu.lib import hub [as 别名]
# 或者: from ryu.lib.hub import sleep [as 别名]
def next(self):
"""Pops and returns the first outgoing message from the list.
If message list currently has no messages, the calling thread will
be put to sleep until we have at-least one message in the list that
can be poped and returned.
"""
# We pick the first outgoing available and send it.
outgoing_msg = self.outgoing_msg_list.pop_first()
# If we do not have any outgoing msg., we wait.
if outgoing_msg is None:
self.outgoing_msg_event.clear()
self.outgoing_msg_event.wait()
outgoing_msg = self.outgoing_msg_list.pop_first()
return outgoing_msg
#
# Source
#
示例10: multipath_computation
# 需要导入模块: from ryu.lib import hub [as 别名]
# 或者: from ryu.lib.hub import sleep [as 别名]
def multipath_computation(self):
while True:
if not self.topo_shape.is_empty() and self.network_is_measured:
computation_start = time.time()
self.logger.info('Starting multipath computation sub-routine')
self.topo_shape.multipath_computation()
self.logger.info(
'Multipath computation finished in %f seconds',
time.time() - computation_start
)
self.MONITORING_PORT_STATS = True
if self.UPDATE_FORWARDING_CONTINOUSLY:
hub.sleep(10)
else:
break
示例11: _monitor
# 需要导入模块: from ryu.lib import hub [as 别名]
# 或者: from ryu.lib.hub import sleep [as 别名]
def _monitor(self):
"""
Main entry method of monitoring traffic.
"""
while CONF.weight == 'bw' or CONF.weight == 'hop':
# Refresh data.
self.stats['flow'] = {}
self.stats['port'] = {}
self.capabilities = None
self.best_paths = None
self.statRecord = []
self.flows = []
for dp in self.datapaths.values():
self.port_features.setdefault(dp.id, {})
self._request_stats(dp)
hub.sleep(setting.MONITOR_PERIOD)
if self.stats['flow'] or self.stats['port']:
self.show_stat('flow')
self.show_stat('port')
hub.sleep(1)
示例12: _link_request_async
# 需要导入模块: from ryu.lib import hub [as 别名]
# 或者: from ryu.lib.hub import sleep [as 别名]
def _link_request_async(self, interval):
while self.is_active:
request = event.EventLinkRequest()
LOG.debug('link_request async %s thread(%s)',
request, id(hub.getcurrent()))
self.send_event(request.dst, request)
start = time.time()
busy = interval / 2
i = 0
while i < busy:
if time.time() > start + i:
i += 1
LOG.debug(' thread is busy... %s/%s thread(%s)',
i, busy, id(hub.getcurrent()))
LOG.debug(' thread yield to link_reply handler. thread(%s)',
id(hub.getcurrent()))
# yield
hub.sleep(0)
LOG.debug(' thread get back. thread(%s)',
id(hub.getcurrent()))
hub.sleep(interval - busy)
示例13: test_0_call_error_notification
# 需要导入模块: from ryu.lib import hub [as 别名]
# 或者: from ryu.lib.hub import sleep [as 别名]
def test_0_call_error_notification(self):
l = []
def callback(n):
l.append(n)
c = rpc.Client(self._client_sock, notification_callback=callback)
c.send_notification('notify2', ['notify_foo', []])
hub.sleep(0.5) # give the peer a chance to run
obj = 'hoge'
try:
c.call('err', [obj])
raise Exception("unexpected")
except rpc.RPCError as e:
assert e.get_value() == obj
assert len(l) == 1
n = l.pop(0)
method, params = n
assert method == 'notify_foo'
assert params == []
示例14: test_spawn_kill_joinall
# 需要导入模块: from ryu.lib import hub [as 别名]
# 或者: from ryu.lib.hub import sleep [as 别名]
def test_spawn_kill_joinall(self):
def _child(ev2, result):
ev2.wait()
result.append(1)
ev2 = hub.Event()
threads = []
result = []
with hub.Timeout(2):
threads.append(hub.spawn(_child, ev2, result))
threads.append(hub.spawn(_child, ev2, result))
hub.sleep(0.5)
for t in threads:
hub.kill(t)
hub.joinall(threads)
assert len(result) == 0
示例15: next
# 需要导入模块: from ryu.lib import hub [as 别名]
# 或者: from ryu.lib.hub import sleep [as 别名]
def next(self):
"""Pops and returns the first outgoing message from the list.
If message list currently has no messages, the calling thread will
be put to sleep until we have at-least one message in the list that
can be popped and returned.
"""
# We pick the first outgoing available and send it.
outgoing_msg = self.outgoing_msg_list.pop_first()
# If we do not have any outgoing msg., we wait.
if outgoing_msg is None:
self.outgoing_msg_event.clear()
self.outgoing_msg_event.wait()
outgoing_msg = self.outgoing_msg_list.pop_first()
return outgoing_msg
# For Python 3 compatibility