Allow integrationUISProutes.csv to override default costs in UISP route determination.

Requested by D. Denson.

Now that the UISP network tree is built as a spanning tree, with 10
cost per hop we can reliably flip the tree from A->B->C to C->B->A
depending upon root positioning.

This addition allows you to specify additional routes (that MUST
exist!) e.g. A->C and specify a cost to use instead of the default
10. This allows for topologies in which A-B-C is actually faster
than a direct A-C route (for example, becuase of short 60ghz
hops).
This commit is contained in:
Herbert Wolverson 2023-04-11 15:30:47 +00:00
parent 2d3874e812
commit 6df648e299
2 changed files with 27 additions and 3 deletions

View File

@ -192,9 +192,14 @@ def debugSpaces(n):
spaces = spaces + " "
return spaces
def walkGraphOutwards(siteList, root):
def walkGraphOutwards(siteList, root, routeOverrides):
def walkGraph(node, parent, cost, backPath):
site = findInSiteListById(siteList, node)
routeName = parent['name'] + "->" + site['name']
if routeName in routeOverrides:
# We have an overridden cost for this route, so use it instead
#print("--> Using overridden cost for " + routeName + ". New cost: " + str(routeOverrides[routeName]) + ".")
cost = routeOverrides[routeName]
if cost < site['cost']:
# It's cheaper to get here this way, so update the cost and parent.
site['cost'] = cost
@ -213,7 +218,20 @@ def walkGraphOutwards(siteList, root):
# Force the parent since we're at the top
site = findInSiteListById(siteList, connection)
site['parent'] = root['id']
walkGraph(connection, root, 20, [root['id']])
walkGraph(connection, root, 10, [root['id']])
def loadRoutingOverrides():
# Loads integrationUISProutes.csv and returns a set of "from", "to", "cost"
overrides = {}
if os.path.isfile("integrationUISProutes.csv"):
with open("integrationUISProutes.csv", "r") as f:
reader = csv.reader(f)
for row in reader:
if not row[0].startswith("#") and len(row) == 3:
fromSite, toSite, cost = row
overrides[fromSite.strip() + "->" + toSite.strip()] = int(cost)
#print(overrides)
return overrides
def buildFullGraph():
# Attempts to build a full network graph, incorporating as much of the UISP
@ -235,10 +253,11 @@ def buildFullGraph():
# Create a list of just network sites
siteList = buildSiteList(sites, dataLinks)
rootSite = findInSiteList(siteList, uispSite)
routeOverrides = loadRoutingOverrides()
if rootSite is None:
print("ERROR: Unable to find root site in UISP")
return
walkGraphOutwards(siteList, rootSite)
walkGraphOutwards(siteList, rootSite, routeOverrides)
# Debug code: dump the list of site parents
# for s in siteList:
# if s['parent'] == "":

View File

@ -0,0 +1,5 @@
# Allows you to override route costs in the UISP integration, to better
# represent your network. Costs by default increment 10 at each hop.
# So if you want to skip 10 links, put a cost of 100 in.
# From Site Name, To Site Name, New Cost
# MYCORE, MYTOWER, 100
1 # Allows you to override route costs in the UISP integration, to better
2 # represent your network. Costs by default increment 10 at each hop.
3 # So if you want to skip 10 links, put a cost of 100 in.
4 # From Site Name, To Site Name, New Cost
5 # MYCORE, MYTOWER, 100