Send kea-dev mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
https://lists.isc.org/mailman/listinfo/kea-dev
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of kea-dev digest..."
Today's Topics:
1. Is there still any interest for a hook embedding python?
(Dave Cole)
2. Re: Is there still any interest for a hook embedding python?
(Dave Cole)
3. Re: Is there still any interest for a hook embedding python?
(Dave Cole)
4. Re: Is there still any interest for a hook embedding python?
(Francis Dupont)
----------------------------------------------------------------------
Message: 1
Date: Sat, 4 Jan 2020 12:28:54 +1100
From: Dave Cole <[email protected]>
To: [email protected]
Subject: [kea-dev] Is there still any interest for a hook embedding
python?
Message-ID:
<canwcxgtdtc5khb0jdlh3j-2ortrdh7jmwvcncw7blqd4djv...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
For people who have been around for a while, I am the Dave Cole who posted
this message:
https://lists.isc.org/pipermail/kea-dev/2017-November/000837.html
I tried multiple times while working at the nbn to convince them to
opensource the work I did embedding Python in Kea. While everyone was
enthusiastic about releasing the code, none of my managers ever seemed to
be able to make in progress along those lines.
I left the nbn close to a year ago and it has been annoying me ever since.
These Christmas holidays I decided to see if I could start from scratch and
embed Python 3. Turns out these things are a lot easier the second time
around.
In less than 2 weeks I have replicated the work I did at nbn and taken
things a little further. To ensure I was doing something useful I decided
to re-implement the lease-cmds example hook from the Kea source.
https://kea.readthedocs.io/en/latest/arm/hooks.html#lease-cmds-lease-commands
I am wondering if anyone is interested in playing with this work? Some
more information follows...
I have only been working on IPv4 for now, but have implemented all of the
IPv4 commands except lease4-add and lease4-update in 242 lines of Python.
The embedded interpreter can run Pythons threads. For a stress test I
wrote a simple hook that uses prometheus-client to export metrics like this:
from kea import *
from ipaddress import IPv4Address, IPv4Network
from prometheus_client import start_http_server, Counter
PKT_RECEIVE = Counter('dhcp4_pkt_receive_total', 'Packets received', ['type'
])
PKT_SEND = Counter('dhcp4_pkt_send_total', 'Packets sent', ['type'])
class Config:
def __init__(self, conf):
dhcp4 = conf['Dhcp4']
self.options = [Option(DHO_DHCP_LEASE_TIME).setUint32(dhcp4.get(
'valid-lifetime', 7200)),
Option(DHO_DHCP_RENEWAL_TIME).setUint32(dhcp4.get('renew-timer', 1800)),
Option(DHO_DHCP_REBINDING_TIME).setUint32(dhcp4.get('rebind-timer', 3600))]
# snip extra code
def load(handle):
global config, type_to_label
config = Config(CfgMgr().getStagingCfg().toElement())
type_to_label = dict([(v, k[4:].lower())
for k, v in globals().items()
if k.startswith('DHCP')])
start_http_server(9100)
return 0
def pkt4_receive(handle):
query = handle.getArgument('query4')
PKT_RECEIVE.labels(type=type_to_label.get(query.getType(), 'unknown')).inc()
# client must request address in Option 82, suboption 1.
o = query.getOption(DHO_DHCP_AGENT_OPTIONS)
if not o:
raise RuntimeError('client must send option %s' % DHO_DHCP_AGENT_OPTIONS)
o = o.getOption(1)
if not o:
raise RuntimeError('missing suboption 1 in option %s' %
DHO_DHCP_AGENT_OPTIONS)
handle.setContext('requested-addr', o.getString())
return 0
Then I run another program that runs dhtest (
https://github.com/saravana815/dhtest) many times in parallel sending the
address I want from Kea in option 82. This lets me confirm that the server
allocated the correct address.
Running the server and stress test on my laptop I get these results:
root@d95ea00a891d:/workdir# python3 examples/stress-test/stress_test.py
--parallel 50 --total 10000
00:01: 713 at 714/sec
00:02: 1564 at 782/sec
00:03: 2364 at 803/sec
00:04: 3042 at 773/sec
00:05: 3756 at 730/sec
00:06: 4470 at 702/sec
00:07: 5203 at 720/sec
00:08: 5929 at 726/sec
00:09: 6703 at 744/sec
00:10: 7368 at 722/sec
00:11: 8089 at 719/sec
00:12: 8809 at 702/sec
00:13: 9499 at 711/sec
total 10000 at 730/sec with 0 errors
In another shell I continuously query prometheus metrics like this:
root@f30313c2a09d:/workdir# while true; do curl -s http://localhost:9100/ |
grep ^dhcp && echo; sleep 0.2; done
This is to give me some confidence that my threading is working correctly.
As soon as the first request hits the server it start producing output a
bit like this:
dhcp4_pkt_receive_total{type="request"} 50.0
dhcp4_pkt_receive_total{type="discover"} 50.0
dhcp4_pkt_send_total{type="ack"} 50.0
dhcp4_pkt_send_total{type="offer"} 50.0
dhcp4_pkt_receive_total{type="request"} 211.0
dhcp4_pkt_receive_total{type="discover"} 211.0
dhcp4_pkt_send_total{type="ack"} 211.0
dhcp4_pkt_send_total{type="offer"} 211.0
dhcp4_pkt_receive_total{type="request"} 389.0
dhcp4_pkt_receive_total{type="discover"} 395.0
dhcp4_pkt_send_total{type="ack"} 389.0
dhcp4_pkt_send_total{type="offer"} 395.0
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<https://lists.isc.org/pipermail/kea-dev/attachments/20200104/f41b0729/attachment-0001.htm>
------------------------------
Message: 2
Date: Sat, 4 Jan 2020 12:55:30 +1100
From: Dave Cole <[email protected]>
To: [email protected]
Subject: Re: [kea-dev] Is there still any interest for a hook
embedding python?
Message-ID:
<canwcxgrr1jp2rqmfpbu8uto9i+sfla1uf+gwrxhctauyb90...@mail.gmail.com>
Content-Type: text/plain; charset="UTF-8"
Sorry about the broken formatting. I forgot mailman does not handle
mime text properly. Here is (I hope) the example code in slightly
more readable format:
- - %< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - -
from kea import *
from ipaddress import IPv4Address, IPv4Network
from prometheus_client import start_http_server, Counter
PKT_RECEIVE = Counter('dhcp4_pkt_receive_total', 'Packets received', ['type'])
PKT_SEND = Counter('dhcp4_pkt_send_total', 'Packets sent', ['type'])
class Config:
def __init__(self, conf):
dhcp4 = conf['Dhcp4']
self.options =
[Option(DHO_DHCP_LEASE_TIME).setUint32(dhcp4.get('valid-lifetime',
7200)),
Option(DHO_DHCP_RENEWAL_TIME).setUint32(dhcp4.get('renew-timer',
1800)),
Option(DHO_DHCP_REBINDING_TIME).setUint32(dhcp4.get('rebind-timer',
3600))]
self.subnet = IPv4Network('10.0.0.0/8')
self.options.append(Option(DHO_SUBNET_MASK).setBytes(self.subnet.netmask.packed))
# snip extra code
def load(handle):
global config, type_to_label
config = Config(CfgMgr().getStagingCfg().toElement())
type_to_label = dict([(v, k[4:].lower())
for k, v in globals().items()
if k.startswith('DHCP')])
start_http_server(9100)
return 0
def pkt4_receive(handle):
query = handle.getArgument('query4')
PKT_RECEIVE.labels(type=type_to_label.get(query.getType(), 'unknown')).inc()
# client must request address in Option 82, suboption 1.
o = query.getOption(DHO_DHCP_AGENT_OPTIONS)
if not o:
raise RuntimeError('client must send option %s' %
DHO_DHCP_AGENT_OPTIONS)
o = o.getOption(1)
if not o:
raise RuntimeError('missing suboption 1 in option %s' %
DHO_DHCP_AGENT_OPTIONS)
handle.setContext('requested-addr', o.getString())
return 0
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
------------------------------
Message: 3
Date: Sat, 4 Jan 2020 12:57:27 +1100
From: Dave Cole <[email protected]>
To: [email protected]
Subject: Re: [kea-dev] Is there still any interest for a hook
embedding python?
Message-ID:
<CANwCXGTVFYA-DaB=xTg4NeNt==1STzK=jyvnbzj2kfuqw1q...@mail.gmail.com>
Content-Type: text/plain; charset="UTF-8"
Now gmail is breaking the formatting why does this still happen in 2020...
------------------------------
Message: 4
Date: Sat, 04 Jan 2020 11:57:36 +0000
From: Francis Dupont <[email protected]>
To: Dave Cole <[email protected]>
Cc: [email protected]
Subject: Re: [kea-dev] Is there still any interest for a hook
embedding python?
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
I wrote a long time ago some hooks using scripting languages (vs C++)
starting of course with Python. I exported it to github (no gitlab at
that time) in the fdxhook branch. BTW if you can comment or complete
the src/hooks/external/NOTES it will be great.
Thanks
Francis Dupont <[email protected]>
PS: please note this is old and partial: the goal was to see if it is possible
(answer is yes) and to find and solve major issues so it is more than
experimental.
------------------------------
Subject: Digest Footer
_______________________________________________
kea-dev mailing list
[email protected]
https://lists.isc.org/mailman/listinfo/kea-dev
------------------------------
End of kea-dev Digest, Vol 66, Issue 2
**************************************