Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def mock_min_latency_app(topo):
"""
Return a simple mock min latency app with a single traffic class.
The traffic class will be between two randomly chosen nodes
"""
# Application configuration
appconfig = {
'name': u'mockminLatencyApp',
'constraints': [ALLOCATE_FLOW, ROUTE_ALL],
'obj': OBJ_MIN_LATENCY,
'predicate': null_predicate,
'resource_cost': {RES_BANDWIDTH: 100}
}
# Create an application based on our config
app = App(_get_pptc(topo, appconfig), **appconfig)
return app
"""
Return a simple mock maxflow app with a single traffic class
The traffic class will be between two randomly chosen nodes
:return:
"""
appconfig = {
'name': u'mockmaxflowapp',
'constraints': [ALLOCATE_FLOW],
'obj': OBJ_MAX_ALL_FLOW,
'predicate': null_predicate,
'resource_cost': {RES_BANDWIDTH: 100}
}
# Create an application based on our config
app = App(_get_pptc(topo, appconfig), **appconfig)
return app
tc = TrafficClass(tcj.tcid, u'tc', tcj.src, tcj.dst,
numpy.array([tcj.vol_flows]))
tcs.append(tc)
pptc = assign_to_tc(tcs, _paths, aj.id)
# pptc = generate_paths_tc(topology, tcs, _predicatedict[aj.predicate], 20,
# float('inf'), name=aj.id)
# objective
if aj.objective.get('resource') is None:
objective = (aj.objective.name)
else:
objective = (aj.objective.name, aj.objective.resource)
# resource_cost
resource_cost = {r.resource: r.cost for r in map(AttrDict, aj.resource_costs)}
apps.append(App(pptc, list(aj.constraints), resource_cost, objective, name=aj.id))
fairness_mode = data.get('fairness', 'weighted')
opt = compose(apps, topology, obj_mode=fairness_mode,
globalcaps=[AttrDict(resource=r, cap=1) for r in resource_cost.keys()])
opt.solve()
result = []
for app in apps:
result_app = {"app": app.name, "tcs": []}
result_pptc = opt.get_paths(0)
for tc in app.pptc:
obj = {
"tcid": tc.ID,
"paths": []
}
for p in result_pptc[tc]:
if p.flow_fraction() != 0:
obj["paths"].append({
'name': u'minLatencyApp',
'constraints': [ALLOCATE_FLOW, ROUTE_ALL],
'obj': OBJ_MIN_LATENCY,
'predicate': null_predicate,
'resource_cost': {BANDWIDTH: 100}
}
# Generate a single traffic class:
# TrafficClass (id, name, source node, destination node)
# For now don't worry about IP addresses.
tc = [TrafficClass(1, u'classname', 0, 4)]
# Generate all paths for this traffic class
pptc = generate_paths_tc(topo, tc, appconfig['predicate'],
cutoff=100)
# Create an application based on our config
app = App(pptc, **appconfig)
# Create and solve an optimization based on the app
opt = from_app(topo, app)
opt.solve()
# Get and print the resulting paths
paths = opt.get_path_fractions(pptc)
print (paths)
wrap_objectives.append(Objective.MIN_LINK_LOAD)
elif objective[0] == u'minnodeload':
wrap_objectives.append(Objective.MIN_NODE_LOAD)
elif objective[0] == u'minlatency':
wrap_objectives.append(Objective.MIN_LATENCY)
elif objective[0] == u'maxflow':
wrap_objectives.append(Objective.MAX_FLOW)
elif objective[0] == u'minenablednodes':
wrap_objectives.append(Objective.MIN_ENABLED_NODES)
else:
logger.debug("Couldn't find Objective Name")
obj_name = None
wrap_objectives.append([objective[1]]) #*args
wrap_objectives.append({}) #**kwargs
apps.append(App(pptc, wrap_constraints, resource_cost, wrap_objectives, name=aj.id))
ncaps = NetworkCaps(topology)
for r in resource_cost.keys():
ncaps.add_cap(r,None,1)
opt = compose_apps(apps, topology, NetworkConfig(networkcaps=ncaps), epoch_mode=EpochComposition.WORST, fairness=Fairness.WEIGHTED, weights = None)
opt.solve()
result = []
for app in apps:
result_app = {"app": app.name, "tcs": []}
result_pptc = opt.get_paths(0)
it = (app.pptc).tcs()
while True:
try:
tc = it.next()
obj = {
"tcid": tc.ID,
"paths": []
def __init__(self, opt, apps):
# Extract paths (pptc), resource loads, binary variables, (app obectives?)
if isinstance(apps, App):
apps = [apps]
self.objectives = {app.name: opt.get_solved_objective(app) for app in apps}
self.objectives[ALLAPPS] = opt.get_solved_objective()
self.paths = opt.get_paths()
self.binvars = {
'nodes': opt.get_enabled_nodes(),
'links': opt.get_enabled_links(),
}
self.loads = opt.get_load_dict()