1
0
mirror of https://github.com/CumulusNetworks/ifupdown2.git synced 2024-05-06 15:54:50 +00:00

Merge pull request #106 from BarbarossaTM/batman-routing-algo

addons: batman_adv: Add support to set B.A.T.M.A.N. advanced routing_algo
This commit is contained in:
Julien Fortin
2019-05-22 02:04:31 +08:00
committed by GitHub

View File

@@ -64,6 +64,13 @@ class batman_adv (moduleBase):
'required' : False,
'batman-attr' : True,
},
'batman-routing-algo' : {
'help' : 'B.A.T.M.A.N. routing algo',
'validvals' : [ 'BATMAN_IV', 'BATMAN_V' ],
'required' : False,
'batman-attr' : False,
},
}
}
@@ -116,12 +123,17 @@ class batman_adv (moduleBase):
return None
def _read_current_batman_attr (self, ifaceobj, attr):
if attr not in self._batman_attrs:
raise ValueError ("_read_current_batman_attr: Invalid or unsupported B.A.T.M.A.N. adv. attribute: %s" % attr)
def _read_current_batman_attr (self, ifaceobj, attr, dont_map = False):
# 'routing_algo' needs special handling, D'oh.
if dont_map:
attr_file_path = "/sys/class/net/%s/mesh/%s" % (ifaceobj.name, attr)
else:
if attr not in self._batman_attrs:
raise ValueError ("_read_current_batman_attr: Invalid or unsupported B.A.T.M.A.N. adv. attribute: %s" % attr)
attr_file_name = self._batman_attrs[attr]['filename']
attr_file_path = "/sys/class/net/%s/mesh/%s" % (ifaceobj.name, attr_file_name)
attr_file_name = self._batman_attrs[attr]['filename']
attr_file_path = "/sys/class/net/%s/mesh/%s" % (ifaceobj.name, attr_file_name)
try:
with open (attr_file_path, "r") as fh:
return fh.readline ().strip ()
@@ -156,6 +168,18 @@ class batman_adv (moduleBase):
except Exception as e:
raise Exception ("_batctl_if: %s" % e)
def _set_routing_algo (self, routing_algo):
if routing_algo not in ['BATMAN_IV', 'BATMAN_V']:
raise Exception ("_set_routing_algo() called with invalid \"routing_algo\" value: %s" % routing_algo)
try:
self.logger.debug ("Running batctl ra %s" % routing_algo)
batctl_output = subprocess.check_output (["batctl", "ra", routing_algo], stderr = subprocess.STDOUT)
except subprocess.CalledProcessError as c:
raise Exception ("Command \"batctl ra %s\" failed: %s" % (routing_algo, c.output))
except Exception as e:
raise Exception ("_set_routing_algo: %s" % e)
def _find_member_ifaces (self, ifaceobj, ignore = True):
members = []
@@ -199,6 +223,11 @@ class batman_adv (moduleBase):
if len (batman_ifaces) == 0:
raise Exception ("None of the configured batman interfaces are available!")
routing_algo = ifaceobj.get_attr_value_first ('batman-routing-algo')
if routing_algo:
self._set_routing_algo (routing_algo)
if_ignore_re = self._get_batman_ifaces_ignore_regex (ifaceobj)
# Is the batman main interface already present?
if self.ipcmd.link_exists (ifaceobj.name):
@@ -289,6 +318,16 @@ class batman_adv (moduleBase):
ifaceobjcurr.update_config_with_status ('batman-%s' % attr, value_curr, value_ok)
routing_algo = ifaceobj.get_attr_value_first ('batman-routing-algo')
if routing_algo:
value_curr = self._read_current_batman_attr (ifaceobj, "routing_algo", dont_map = True)
value_ok = 0
if routing_algo != value_curr:
value_ok = 1
ifaceobjcurr.update_config_with_status ('batman-routing-algo', value_curr, value_ok)
def _query_running (self, ifaceobjrunning):
if not self.ipcmd.link_exists (ifaceobjrunning.name):