-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathnet.py
30 lines (20 loc) · 936 Bytes
/
net.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import logging
from ether.core import Flow
logger = logging.getLogger(__name__)
class LowBandwidthException(BaseException):
pass
def SafeFlow(*args, bw_threshold=0.1, **kwargs):
"""
Creates a new ether.core.Flow but throws a LowBandwidthException if the allocatable bandwidth in the flow is less
than the given threshold. This is used to terminate simulations that produce infeasible function placements.
:param args: the arguments for the ether.core.Flow
:param bw_threshold: the minimal bandwidth threshold (default 0.1)
:param kwargs: the kwargs for ether.core.Flow
:return: a flow
"""
flow = Flow(*args, **kwargs)
bottleneck = min(flow.route.hops, key=lambda l: l.max_allocatable)
if bottleneck.max_allocatable <= bw_threshold:
logger.error('potential for flow %s: %.4f', flow.route, bottleneck.max_allocatable)
raise LowBandwidthException()
return flow