From 56c63dbb10e7830d7b74c8ef6752c0d755089d0a Mon Sep 17 00:00:00 2001 From: Arnaud Date: Thu, 17 Sep 2020 09:36:19 +0000 Subject: [PATCH 1/5] add the pimd troglobit daemon with the possibilities to specify the name of the config file --- ipmininet/router/config/__init__.py | 3 +- ipmininet/router/config/pimd_troglobit.py | 33 +++++++++++++++++++++ ipmininet/router/config/templates/pimd.mako | 23 -------------- 3 files changed, 35 insertions(+), 24 deletions(-) create mode 100644 ipmininet/router/config/pimd_troglobit.py diff --git a/ipmininet/router/config/__init__.py b/ipmininet/router/config/__init__.py index b96c9969..1dc97625 100644 --- a/ipmininet/router/config/__init__.py +++ b/ipmininet/router/config/__init__.py @@ -17,6 +17,7 @@ from .ripng import RIPng from .openrd import OpenrDaemon from .openr import Openr, OpenrDomain +from .pimd_troglobit import Pimd __all__ = ['BasicRouterConfig', 'NodeConfig', 'Zebra', 'OSPF', 'OSPF6', 'OSPFArea', 'BGP', 'AS', 'SHARE', 'CLIENT_PROVIDER', @@ -27,4 +28,4 @@ 'OpenrDaemon', 'Openr', 'OpenrDomain', 'AF_INET', 'AF_INET6', 'BorderRouterConfig', 'Rule', 'Chain', 'ChainRule', 'NOT', 'PortClause', 'InterfaceClause', 'AddressClause', 'Filter', - 'InputFilter', 'OutputFilter', 'TransitFilter', 'Allow', 'Deny'] + 'InputFilter', 'OutputFilter', 'TransitFilter', 'Allow', 'Deny','Pimd'] diff --git a/ipmininet/router/config/pimd_troglobit.py b/ipmininet/router/config/pimd_troglobit.py new file mode 100644 index 00000000..afdac145 --- /dev/null +++ b/ipmininet/router/config/pimd_troglobit.py @@ -0,0 +1,33 @@ +from .base import RouterDaemon + +class Pimd(RouterDaemon): + """ This class configure the pim Daemon which can be found here: + https://github.com/troglobit/pimd + """ + NAME = 'pimd' + KILL_PATTERNS = (NAME,) + + def __init__(self,node,*args,**kwargs): + super().__init__(node=node,*args,**kwargs) + if "cfg" in kwargs: + self.custom_config = kwargs["cfg"] + + + @property + def startup_line(self): + return '{name} -f --config={cfg}'.format(name=self.NAME,cfg=self.cfg_filename) + + @property + def dry_run(self): + #does not check te config file launch the daemon anyway + if hasattr(self,'custom_config'): + return '{name} --config={cfg}'.format(name=self.NAME,cfg=self.custom_config) + else: + return '{name} --config={cfg}'.format(name=self.NAME,cfg=self.cfg_filename) + + def set_defaults(self,defaults): + super().set_defaults(defaults) + + def build(self): + cfg = super().build() + return cfg diff --git a/ipmininet/router/config/templates/pimd.mako b/ipmininet/router/config/templates/pimd.mako index b9f4161b..e69de29b 100644 --- a/ipmininet/router/config/templates/pimd.mako +++ b/ipmininet/router/config/templates/pimd.mako @@ -1,23 +0,0 @@ -hostname ${node.name} -password ${node.password} - -% if node.pimd.logfile: - log file ${node.pimd.logfile} -% endif - -% for section in node.pimd.debug: - debug pimd ${section} -% endfor -! -ip multicast-routing -! -% for itf in node.pimd.interfaces: -interface ${itf.name} - % if itf.ssm: - ip pim ssm - % endif - % if itf.igmp: - ip igmp - % endif -! -% endfor From 4edd170584a87a18561dab1ea4c20c11336aae1e Mon Sep 17 00:00:00 2001 From: Arnaud Date: Fri, 18 Sep 2020 11:18:30 +0000 Subject: [PATCH 2/5] add the -f option to not have some pimd zombie process --- ipmininet/router/config/pimd_troglobit.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ipmininet/router/config/pimd_troglobit.py b/ipmininet/router/config/pimd_troglobit.py index afdac145..fa351984 100644 --- a/ipmininet/router/config/pimd_troglobit.py +++ b/ipmininet/router/config/pimd_troglobit.py @@ -15,7 +15,10 @@ def __init__(self,node,*args,**kwargs): @property def startup_line(self): - return '{name} -f --config={cfg}'.format(name=self.NAME,cfg=self.cfg_filename) + if hasattr(self,'custom_config'): + return '{name} -f --config={cfg}'.format(name=self.NAME,cfg=self.custom_config) + else: + return '{name} -f --config={cfg}'.format(name=self.NAME,cfg=self.cfg_filename) @property def dry_run(self): From 05efce640a15ccd08f2341ddb2c12b7fb4397ff8 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Fri, 18 Sep 2020 14:50:16 +0000 Subject: [PATCH 3/5] add the posibility to specify a file where the stderr of a daemon should be redirect --- ipmininet/router/__router.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ipmininet/router/__router.py b/ipmininet/router/__router.py index 963f06c5..b85c8c72 100644 --- a/ipmininet/router/__router.py +++ b/ipmininet/router/__router.py @@ -11,11 +11,14 @@ from ipmininet.link import IPIntf from .config import BasicRouterConfig, NodeConfig, RouterConfig + import mininet.clean from mininet.node import Node, Host from mininet.log import lg import shlex +import os + class ProcessHelper: """This class holds processes that are part of a given family, e.g. routing @@ -126,7 +129,11 @@ def start(self): self._old_sysctl[opt] = self._set_sysctl(opt, val) # Fire up all daemons for d in self.nconfig.daemons: - self._processes.popen(shlex.split(d.startup_line)) + if (hasattr(d,'logfile')): + with open(d.logfile,"w") as err: + self._processes.popen(shlex.split(d.startup_line),stderr=err) + else: + self._processes.popen(shlex.split(d.startup_line)) # Busy-wait if the daemon needs some time before being started while not d.has_started(): time.sleep(.001) From a70a25c6440427f454ff9be1f10523f696bc5906 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Fri, 18 Sep 2020 14:51:47 +0000 Subject: [PATCH 4/5] add the attr to specify where stderr should be redirect and the random dry_run since it's not useful for this daemon --- ipmininet/router/config/pimd_troglobit.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ipmininet/router/config/pimd_troglobit.py b/ipmininet/router/config/pimd_troglobit.py index fa351984..6b9119f9 100644 --- a/ipmininet/router/config/pimd_troglobit.py +++ b/ipmininet/router/config/pimd_troglobit.py @@ -9,8 +9,11 @@ class Pimd(RouterDaemon): def __init__(self,node,*args,**kwargs): super().__init__(node=node,*args,**kwargs) + # add some custom attr if "cfg" in kwargs: self.custom_config = kwargs["cfg"] + if "log_file" in kwargs: + self.logfile = kwargs["log_file"] @property @@ -22,11 +25,7 @@ def startup_line(self): @property def dry_run(self): - #does not check te config file launch the daemon anyway - if hasattr(self,'custom_config'): - return '{name} --config={cfg}'.format(name=self.NAME,cfg=self.custom_config) - else: - return '{name} --config={cfg}'.format(name=self.NAME,cfg=self.cfg_filename) + return 'echo 2BeOrNot2Be > /dev/null' def set_defaults(self,defaults): super().set_defaults(defaults) From 5f53baa0e9ffe51effbc5e6b9bbcbc0af7bda599 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Fri, 18 Sep 2020 15:08:59 +0000 Subject: [PATCH 5/5] remove unecessary import --- ipmininet/router/__router.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/ipmininet/router/__router.py b/ipmininet/router/__router.py index b85c8c72..bd7f5f10 100644 --- a/ipmininet/router/__router.py +++ b/ipmininet/router/__router.py @@ -17,8 +17,6 @@ from mininet.log import lg import shlex -import os - class ProcessHelper: """This class holds processes that are part of a given family, e.g. routing