Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
{'allTraffic': 2000})
# since our topology is "fake", provision our links and generate link capacities in our network
linkcaps = provisioning.provision_links(topo, trafficClasses, 1)
# these will be our link constraints: do not load links more than 50%
linkConstrCaps = {(u, v): .5 for u, v in topo.links()}
# ==============
# Optimization
# ==============
# Start our optimization.
# SOL automatically takes care of the path generation, but it needs the topology, traffic classes, path predicate
# and path selection strategy.
# nullPredicate means any path will do, no specific service chaining or policy requirements.
# Then, SOL will choose maximum of 5 shortest paths for each traffic class to route traffic on.
opt, pptc = initOptimization(topo, trafficClasses, nullPredicate, 'shortest', 5, backend='CPLEX')
# Now, our constraints.
# First, we must allocate some amount of flow (i.e, tell SOL to route things frorm ingress to egress)
opt.allocate_flow(pptc)
# Traffic must not overload links -- so cap links according to our link constraints (recall the 50%)
# linkcapfunc defines how bandwidth is consumed.
linkcapfunc = lambda link, tc, path, resource: tc.volBytes / linkcaps[link]
opt.capLinks(pptc, 'bandwidth', linkConstrCaps, linkcapfunc)
# Push as much traffic as we can
opt.maxFlow(pptc)
# Solve the optimization
opt.solve()
{'allTraffic': 2000})
# since our topology is "fake", provision our links and generate link capacities in our network
linkcaps = provisionLinks(topo, trafficClasses, 2)
# these will be our link constraints: do not load links more than 50%
linkConstrCaps = {(u, v): .5 for u, v in topo.links()}
# ==============
# Optimization
# ==============
# Start our optimization.
# SOL automatically takes care of the path generation, but it needs the topology, traffic classes, path predicate
# and path selection strategy.
# nullPredicate means any path will do, no specific service chaining or policy requirements.
# Then, SOL will choose maximum of 5 shortest paths for each traffic class to route traffic on.
opt, pptc = initOptimization(topo, trafficClasses, nullPredicate, 'shortest', 5, backend='CPLEX')
# Now, our constraints.
# First, we must allocate some amount of flow (i.e, tell SOL to route things frorm ingress to egress)
opt.allocate_flow(pptc)
# Traffic must not overload links -- so cap links according to our link constraints (recall the 50%)
# linkcapfunc defines how bandwidth is consumed.
linkcapfunc = lambda link, tc, path, resource: tc.volBytes / linkcaps[link]
opt.capLinks(pptc, 'bandwidth', linkConstrCaps, linkcapfunc)
# Route all the traffic
opt.route_all(pptc)
# Minimize the link load in the network (a pretty standard TE goal)
opt.min_link_load('bandwidth')
nodeFunc = functools.partial(nodeCapFunc, nodeCaps=nodeCaps)
linkFunc = functools.partial(linkCapFunc, linkCaps=linkCaps)
def TCAMCapFunc(node, tc, path, resource):
# it would be best to test if node is a switch here, but we know all nodes are switches in this example
if resource == 'tcam':
return 2 # two rules per path on each switch, just as an example.
else:
raise ValueError("wrong resource") # just in case
# ======================
# start our optimization
# ======================
# Get paths that conform to our path predicate, choose a subset of 5 randomly to route traffic on.
opt, pptc = initOptimization(topo, trafficClasses, path_predicate,
'random', 5, functools.partial(useMboxModifier, chainLength=2), 'CPLEX')
# Allocate and route all of the traffic
opt.allocate_flow(pptc)
opt.route_all(pptc)
# We know that we will need binary variables per path and node to model TCAM constraints
opt._add_binary_vars(pptc, topo, ['path', 'node'])
# Add TCAM capacities here
opt.capNodesPathResource(pptc, 'tcam', nodeCaps['tcam'], TCAMCapFunc)
# Now just add constraints for link capacities (use default Link Function, nothing fancy here)
opt.capLinks(pptc, 'bandwidth', linkCaps, linkFunc)
# And similarly node capacities
# Recall that we are normalizing the CPU node load to [0, 1], so capacities are now all 1.
opt.capNodes(pptc, 'cpu', {node: 1 for node in topo.nodes()
{'allTraffic': 2000})
# since our topology is "fake", provision our links and generate link capacities in our network
linkcaps = provisioning.provision_links(topo, trafficClasses, 1)
# these will be our link constraints: do not load links more than 50%
linkConstrCaps = {(u, v): .5 for u, v in topo.links()}
# ==============
# Optimization
# ==============
# Start our optimization.
# SOL automatically takes care of the path generation, but it needs the topology, traffic classes, path predicate
# and path selection strategy.
# nullPredicate means any path will do, no specific service chaining or policy requirements.
# Then, SOL will choose maximum of 5 shortest paths for each traffic class to route traffic on.
opt, pptc = initOptimization(topo, trafficClasses, nullPredicate, 'shortest', 5, backend='CPLEX')
# Now, our constraints.
# First, we must allocate some amount of flow (i.e, tell SOL to route things frorm ingress to egress)
opt.allocate_flow(pptc)
# Traffic must not overload links -- so cap links according to our link constraints (recall the 50%)
# linkcapfunc defines how bandwidth is consumed.
linkcapfunc = lambda link, tc, path, resource: tc.volBytes / linkcaps[link]
opt.capLinks(pptc, 'bandwidth', linkConstrCaps, linkcapfunc)
# Push as much traffic as we can
opt.maxFlow(pptc)
# Solve the optimization
opt.solve()