Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
trafficClasses = generateTrafficClasses(trafficMatrix.keys(), trafficMatrix, {'allTraffic': 1},
{'allTraffic': 2000})
# assign flow processing cost for each traffic class
for t in trafficClasses:
t.cpuCost = 10
# Do some topology provisioning, instead of the real switch/link/middlebox capacities:
# provision the node cpu capacities (for the sake of example)
maxCPUCap = provisioning.compute_max_ingress_load(trafficClasses, {t: t.cpuCost for t in trafficClasses})
nodeCaps = dict()
nodeCaps['cpu'] = {node: maxCPUCap * 2 for node in topo.nodes()
if 'fw' or 'ids' in topo.get_service_types(node)}
# provision the TCAM capacities on the switch nodes
nodeCaps['tcam'] = {node: 1000 for node in topo.nodes()}
# similartly with link capacities
linkCaps = provisioning.provision_links(topo, trafficClasses, 3)
# =====================================
# Write our user defined capacity functions
# =====================================
def path_predicate(path, topology):
# Firewall followed by IDS is the requirement for the path to be valid
return any([s == ('fw', 'ids') for s in itertools.product(*[topology.get_service_types(node)
for node in path.useMBoxes])])
def nodeCapFunc(node, tc, path, resource, nodeCaps):
# this computes the cost of processing the traffic class at a given node
if resource == 'cpu' and node in nodeCaps['cpu']:
return tc.volFlows * tc.cpuCost / nodeCaps[resource][node]
# ==============
# Let's generate some example data; SOL has some functions to help with that.
# ==============
# A complete topology
topo = complete_topology(5)
# ingress-egress pairs, between which the traffic will flow
iePairs = [(0, 3)]
# generate a traffic matrix, in this case, a uniform traffic matrix with a million flows
trafficMatrix = provisioning.uniformTM(
iePairs, 10 ** 6)
# compute traffic classes. We will only have one class that encompasses all the traffic;
# assume that each flow consumes 2000 units of bandwidth
trafficClasses = generateTrafficClasses(iePairs, trafficMatrix, {'allTraffic': 1},
{'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)
# ==============
# Let's generate some example data; SOL has some functions to help with that.
# ==============
# A complete topology
topo = complete_topology(5)
# ingress-egress pairs, between which the traffic will flow
iePairs = [(0, 3)]
# generate a traffic matrix, in this case, a uniform traffic matrix with a million flows
trafficMatrix = provisioning.uniformTM(
iePairs, 10 ** 6)
# compute traffic classes. We will only have one class that encompasses all the traffic;
# assume that each flow consumes 2000 units of bandwidth
trafficClasses = generateTrafficClasses(iePairs, trafficMatrix, {'allTraffic': 1},
{'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)