-
Notifications
You must be signed in to change notification settings - Fork 4
/
srn.py
44 lines (38 loc) · 1.3 KB
/
srn.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from __future__ import print_function
import topology
from time import sleep
import pdb
# create a 2D grid of required size
mesh = topology.Mesh(10,10)
# initialise all connections
mesh.initialise()
# inject some random faults
topology.injectRandomLinkFaults(mesh, 10)
topology.injectRandomRouterFaults(mesh, 6)
# view the map health
topology.printTopologyMap(mesh,True)
'''
Working:
The algorithm follows a recursive approach, while keeping track of 3 global variables:
1. Index of routers already visited
2. Minimum hop-count
3. Corresponding stack (path)
The source is marked visited and neighbours are fetched.
1. Start with Source
2. If All links 0 == no path
3. Mark current router as visited; add 1 to hop count; update stack-trace
4. Get active neighbours
5. Check whether an active neighbour is destination.
6. If No, return True if at least one neighbour exists else return False; if Yes, go to 8
7. go to statement 2
8. Get hop-count and stack-trace.
'''
# define source and destination routers, note that
# router at (x,y) is accessed by routers[y][x]
source = mesh.routers[0][0]
destination = mesh.routers[9][8]
# fetch path
path = topology.findPath(mesh,source,destination)
print("Tracing path from {0}-->{1}".format(source.getPosition(),destination.getPosition()))
# display the path
topology.showPath(mesh,path)