5 Scan the VINI Central database and create topology "rspec" attributes for
6 slices that have an EGRE key. This script to be run from a cron job.
13 Links in the physical topology, gleaned from looking at the Internet2
14 and NLR topology maps. Link (a, b) connects sites with IDs a and b.
16 links = [(2, 12), # I2 Princeton - New York
17 (4, 5), # NLR Chicago - Houston
18 (4, 6), # NLR Chicago - Atlanta
19 (4, 7), # NLR Chicago - Seattle
20 (4, 9), # NLR Chicago - New York
21 (4, 10), # NLR Chicago - Wash DC
22 (5, 6), # NLR Houston - Atlanta
23 (5, 8), # NLR Houston - Los Angeles
24 (6, 10), # NLR Atlanta - Wash DC
25 (7, 8), # NLR Seattle - Los Angeles
26 (9, 10), # NLR New York - Wash DC
27 (11, 13), # I2 Chicago - Wash DC
28 (11, 15), # I2 Chicago - Atlanta
29 (11, 16), # I2 Chicago - CESNET
30 (11, 17), # I2 Chicago - Kansas City
31 (12, 13), # I2 New York - Wash DC
32 (13, 15), # I2 Wash DC - Atlanta
33 (15, 19), # I2 Atlanta - Houston
34 (17, 19), # I2 Kansas City - Houston
35 (17, 22), # I2 Kansas City - Salt Lake City
36 (19, 20), # I2 Houston - Los Angeles
37 (20, 21), # I2 Los Angeles - Seattle
38 (20, 22), # I2 Los Angeles - Salt Lake City
39 (21, 22)] # I2 Seattle - Salt Lake City
43 Generate site adjacency map from list of links
45 def gen_adjacencies(links):
60 Test whether two sites are adjacent to each other in the adjacency graph.
62 def is_adjacent(adjacencies, s1, s2):
63 set1 = set(adjacencies[s1])
64 set2 = set(adjacencies[s2])
66 if s1 in set2 and s2 in set1:
68 elif not s1 in set2 and not s2 in set1:
71 raise Exception("Adjacency mismatch, sites %d and %d." % (s1, s2))
75 Check the adjacency graph for discrepancies.
77 def check_adjacencies(adjacencies):
78 for site in adjacencies:
79 for adj in adjacencies[site]:
81 test = is_adjacent(adjacencies, site, adj)
83 print "Error: ", e, " Fix adjacencies!"
89 return nodes[nodeid]['site_id']
90 raise Exception("Nodeid %s not found." % nodeid)
93 def get_ipaddr(nodeid):
95 return socket.gethostbyname(nodes[nodeid]['hostname'])
96 raise Exception("Nodeid %s not found." % nodeid)
99 def get_sitenodes(siteid):
101 return sites[siteid]['node_ids']
102 raise Exception("Siteid %s not found." % siteid)
106 Find the IP address assigned to a virtual interface in the topology
107 (for creating /etc/hosts)
109 def get_virt_ip(myid, nodeid):
111 virtip = "10.%d.%d.2" % (myid, nodeid)
113 virtip = "10.%d.%d.3" % (nodeid, myid)
118 Create a dictionary of site records keyed by site ID
122 for site in GetSites():
123 t = site['site_id'], site
129 Create a dictionary of node records keyed by node ID
133 for node in GetNodes():
134 t = node['node_id'], node
138 adjacencies = gen_adjacencies(links)
139 check_adjacencies(adjacencies)
141 """ Need global topology information """
145 for slice in GetSlices():
146 """ Create dictionary of the slice's attributes """
149 for attribute in GetSliceAttributes(slice['slice_attribute_ids']):
150 attrs[attribute['name']] = attribute['slice_attribute_id']
151 if attribute['name'] == 'topo_rspec' and attribute['node_id']:
152 topo_attr[attribute['node_id']] = attribute['slice_attribute_id']
154 if 'egre_key' in attrs:
155 #print "Virtual topology for %s:" % slice['name']
156 slicenodes = set(slice['node_ids'])
157 hosts = "127.0.0.1\t\tlocalhost\n"
159 For each node in the slice, check whether nodes at adjacent sites
160 are also in the slice's node set. If so, add a virtual link to
163 for node in slicenodes:
165 for adj in adjacencies[get_site(node)]:
166 for adj_node in get_sitenodes(adj):
167 if node != adj_node and adj_node in slicenodes:
168 link = adj_node, get_ipaddr(adj_node), "1Mbit"
170 shortname = nodes[node]['hostname'].replace('.vini-veritas.net', '')
171 hosts += "%s\t\t%s\n" % (get_virt_ip(node, adj_node),
173 topo_str = "%s" % topo
174 #print node, topo_str
175 if node in topo_attr:
176 UpdateSliceAttribute(topo_attr[node], topo_str)
179 id = slice['slice_id']
180 AddSliceAttribute(id, 'topo_rspec', topo_str, node)
184 UpdateSliceAttribute(attrs['hosts'], hosts)
186 id = slice['slice_id']
187 AddSliceAttribute(id, 'hosts', hosts)
189 #print "No EGRE key for %s" % slice['name']
191 """ Remove old topo_rspec entries """
192 for node in topo_attr:
193 DeleteSliceAttribute(topo_attr[node])