Skip to content

Instantly share code, notes, and snippets.

@apwiggins
Last active April 13, 2024 13:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apwiggins/1a7cee85e23b218e903b264350545701 to your computer and use it in GitHub Desktop.
Save apwiggins/1a7cee85e23b218e903b264350545701 to your computer and use it in GitHub Desktop.
# babeld service for babeld v1.9.1
'''
babeld.py: babeld router model
'''
import os
import logging
from core.service import CoreService, addservice
from core.misc.utils import *
from core.constants import *
class BabeldService(CoreService):
_name = "Babel"
_group = "Routing"
_depends = ()
_dirs = ("/var/log/babeld",
"/usr/local/etc/babeld",
"/var/run/babeld")
_configs = ()
_startindex = 35
_shutdown = ("killall babeld", )
_validate = ("pidof babeld", )
@classmethod
def generateconfig(cls, node, filename, services):
return ""
class babeld(BabeldService):
_name = "Babeld"
_configs = ("babeld.sh",)
_startup = ("sh babeld.sh",)
_custom_needed = False
@classmethod
def generateconfig(cls, node, filename, services):
''' Use a startup script for launching Babeld Service
'''
if filename == cls._configs[0]:
return cls.generatebabeldsh(node, services)
else:
raise ValueError
@classmethod
def generatebabeldsh(cls, node, services):
cfg = """#!/bin/bash
# auto-generated by Babeld service (babeld.py)
### insert babeld.conf commands here
cat <<EOF >>/usr/local/etc/babeld/babeld.conf
debug 1
daemonise true
link-detect false
diversity false
EOF
### specific commands go into babeld.conf above
# to redistribute babel routes to kernel: redistribute metric 256
# to redistribute a specific subnetwork: redistribute ip 10.0.4.0/24
# https://www.irif.fr/~jch/software/babel/babeld.html#Global_options
# https://www.irif.fr/~jch/software/babel/babeld.html#Interface_configuration
# interface eth1 type wireless rxcost 256 hello-interval 5
#
BABELD=/usr/local/bin/babeld
HELLO_INTERVAL_WIRED=4
HELLO_INTERVAL_WIRELESS=10
TELNET_PORT=33123
$BABELD \\
-h $HELLO_INTERVAL_WIRELESS \\
-H $HELLO_INTERVAL_WIRED \\
-S /var/run/babeld/babel-state \\
-c /usr/local/etc/babeld/babeld.conf \\
-L /var/log/babeld/babeld.log \\
-I /var/run/babeld/babeld.pid \\
-g $TELNET_PORT \\
"""
for ifc in node.netifs():
cfg += " %s " % (ifc.name)
return cfg
addservice(babeld)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment