5 VINI/Trellis NodeManager plugin.
6 Create virtual links from the topo_rspec slice attribute.
15 setup_link_cmd="/usr/share/vini/setup-egre-link"
16 teardown_link_cmd="/usr/share/vini/teardown-egre-link"
24 return subprocess.call(cmd, shell=True);
28 Check for existence of interface a<key>x<nodeid>
30 def virtual_link(key, nodeid):
31 name = "d%sx%s" % (key, nodeid)
39 Create a "virtual link" for slice between here and nodeid.
40 The key is used to create the EGRE tunnel.
42 def setup_virtual_link(slice, key, rate, myid, nodeid, ipaddr):
44 virtip = "10.%d.%d.2" % (myid, nodeid)
46 virtip = "10.%d.%d.3" % (nodeid, myid)
48 run(setup_link_cmd + " %s %s %s %s %s %s" % (slice, nodeid, ipaddr,
54 Tear down the "virtual link" for slice between here and nodeid.
56 def teardown_virtual_link(slice, key, nodeid):
57 logger.log("Tear down virtual link to node %d" % nodeid)
58 run(teardown_link_cmd + " %s %s %s" % (slice, nodeid, key))
63 Clean up old virtual links (e.g., to nodes that have been deleted
66 def clean_up_old_virtual_links(slice, key, nodelist):
67 pattern = "d%sx(.*)" % key
69 m = re.match(pattern, iface)
72 if not node in nodelist:
73 teardown_virtual_link(slice, key, node)
77 Not the safest thing to do, probably should use pickle() or something.
79 def convert_topospec_to_list(rspec):
84 Update virtual links for the slice
86 def update(slice, myid, topospec, key):
87 topolist = convert_topospec_to_list(topospec)
89 for (nodeid,ipaddr,rate) in topolist:
90 nodelist.append(nodeid)
91 if not virtual_link(key, nodeid):
92 setup_virtual_link(slice, key, rate, myid, nodeid, ipaddr)
94 logger.log("Virtual link to node %s exists" % nodeid)
96 clean_up_old_virtual_links(slice, key, nodelist)
99 def start(options, config):
104 Update the virtual links for a sliver if it has a 'netns' attribute,
105 an 'egre_key' attribute, and a 'topo_rspec' attribute.
107 def GetSlivers(data):
109 ifaces = sioc.gifconf()
111 for sliver in data['slivers']:
113 for attribute in sliver['attributes']:
114 attrs[attribute['name']] = attribute['value']
115 if 'netns' in attrs and 'egre_key' in attrs and 'topo_rspec' in attrs:
116 if attrs['netns'] > 0:
117 logger.log("Update topology for slice %s" % sliver['name'])
118 update(sliver['name'], data['node_id'],
119 attrs['topo_rspec'], attrs['egre_key'])