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 d<key>x<nodeid>
30 def virtual_link(key, nodeid):
31 name = "d%sx%s" % (key, nodeid)
32 # logger.log("Looking for iface %s" % name)
40 Create a "virtual link" for slice between here and nodeid.
41 The key is used to create the EGRE tunnel.
43 def setup_virtual_link(slice, key, rate, myid, nodeid, ipaddr):
44 logger.log("Set up virtual link to node %d" % nodeid)
46 virtip = "10.%d.%d.2" % (myid, nodeid)
48 virtip = "10.%d.%d.3" % (nodeid, myid)
50 run(setup_link_cmd + " %s %s %s %s %s %s" % (slice, nodeid, ipaddr,
56 Tear down the "virtual link" for slice between here and nodeid.
58 def teardown_virtual_link(slice, key, nodeid):
59 logger.log("Tear down virtual link to node %s" % nodeid)
60 run(teardown_link_cmd + " %s %s %s" % (slice, nodeid, key))
65 Clean up old virtual links (e.g., to nodes that have been deleted
68 def clean_up_old_virtual_links(slice, key, nodelist):
69 pattern = "d%sx(.*)" % key
71 m = re.match(pattern, iface)
73 node = int(m.group(1))
74 if not node in nodelist:
75 logger.log("%s" % nodelist)
76 teardown_virtual_link(slice, key, node)
80 Not the safest thing to do, probably should use pickle() or something.
82 def convert_topospec_to_list(rspec):
87 Update virtual links for the slice
89 def update(slice, myid, topospec, key):
90 topolist = convert_topospec_to_list(topospec)
92 for (nodeid,ipaddr,rate) in topolist:
93 nodelist.append(nodeid)
94 if not virtual_link(key, nodeid):
95 setup_virtual_link(slice, key, rate, myid, nodeid, ipaddr)
97 logger.log("Virtual link to node %s exists" % nodeid)
99 clean_up_old_virtual_links(slice, key, nodelist)
102 def start(options, config):
107 Update the virtual links for a sliver if it has a 'netns' attribute,
108 an 'egre_key' attribute, and a 'topo_rspec' attribute.
110 def GetSlivers(data):
112 ifaces = sioc.gifconf()
114 for sliver in data['slivers']:
116 for attribute in sliver['attributes']:
117 attrs[attribute['name']] = attribute['value']
118 if 'netns' in attrs and 'egre_key' in attrs and 'topo_rspec' in attrs:
119 if attrs['netns'] > 0:
120 logger.log("Update topology for slice %s" % sliver['name'])
121 update(sliver['name'], data['node_id'],
122 attrs['topo_rspec'], attrs['egre_key'])