<commit_before>.. contents:: Table of Contents
   :depth: 3

===================================
DHCP Server Dynamic Allocation Pool
===================================

[gerrit filter: https://git.opendaylight.org/gerrit/#/q/topic:dhcp_server_pool]

Extension of the ODL based DHCP server, which add support for dynamic address allocation to end
point users, that are not controlled (known) by OpenStack Neutron. Each DHCP pool can be configured
with additional information such as DNS servers, lease time (not yet), static allocations based on
MAC address, etc.

The feature supports IPv4 only.

Problem description
===================
In a non-neutron northbounds environment e.g. SD-WAN solution (unimgr), there is currently no
dynamic DHCP service for end-points or networks that are connected to OVS. Every DHCP packet that is
received by the controller, the controller finds the neutron port based on the inport of the packet,
extracts the ip which was allocated by neutron for that vm, and replies using that info. If the dhcp
packet is from a non-neutron port, the packet won't even reach the controller.

Use Cases
---------
a DHCP packet that is received by the odl, from a port that is managed by Netvirt and was configured
using the netvirt API, rather then the neutron API, in a way that there is no pre-allocated IP for
network interfaces behind that port - will be handled by the DHCP dynamic allocation pool that is
configured on the network associated with the receiving OVS port.

Proposed change
===============
We wish to forward to the controller, every dhcp packet coming from a non-neutron port as well (as
long as it is configured to use the controller dhcp). Once a DHCP packet is recieved by the
controller, the controller will check if there is already a pre-allocated address by checking if
packet came from a neutron port. if so, the controller will reply using the information from the
neutron port. Otherwise, the controller will find the allocation pool for the network which the
packet came from and will allocate the next free ip. The operation of each allocation pool will
be managed through the Genius ID Manager service that will support the allocation and release of IP
addresses (ids), persistent mapping across controller restarts and more. Neutron IP allocations will
be added to the relevant pools to avoid allocation of the same addresses.

Pipeline changes
----------------
This new rule in table 60 will be responsible for forwarding dhcp packets to the controller:

.. code-block:: bash

 cookie=0x6800000, duration=121472.576s, table=60, n_packets=1, n_bytes=342, priority=49,udp,tp_src=68,tp_dst=67 actions=CONTROLLER:65535


Yang changes
------------
New YANG model to support the configuration of the DHCP allocation pools and allocations, per
network and subnet.

* Allocation-Pool: configuration of allocation pool parameters like range, gateway and dns servers.
* Allocation-Instance: records of IP address allocation per MAC address. Records represent dynamic
  or static allocations, and Neutron pre-allocated addresses.

.. code-block:: none
   :caption: dhcp_allocation_pool.yang

    grouping dhcp_allocations {
        list allocation {
            key "subnet";
            leaf subnet {
                description "subnet for the dhcp to allocate ip addresses";
                type inet:ip-prefix;
            }

            list allocation-instance {
                key "mac";
                leaf mac {
                    description "requesting mac";
                    type yang:phys-address;
                }
                leaf allocated-ip {
                    description "allocated ip address";
                    type inet:ip-address;
                }
            }
        }
        list allocation-pool {
            key "subnet";
            leaf subnet {
                description "subnet for the dhcp to allocate ip addresses";
                type inet:ip-prefix;
            }
            leaf allocate-from {
                description "low allocation limit";
                type inet:ip-address;
            }
            leaf allocate-to {
                description "high allocation limit";
                type inet:ip-address;
            }
            leaf gateway {
                description "default gateway for dhcp allocation";
                type inet:ip-address;
            }
            list dns-servers {
                description "dns server list";
                leaf dns-server {
                    description "dns server entry";
                    type inet:ip-address;
                }
            }
        }
    }


    container dhcp_allocation_pool {
        config true;
        description "contains DHCP Server dynamic allocations";

        list network {
            key "network-id";
            leaf network-id {
                description "network (elan-instance) id";
                type string;
            }
            uses dhcp_allocations;
        }
    }


Configuration impact
--------------------
The feature is activated in the configuration (disabled by default).

adding **dhcp-dynamic-allocation-pool-enabled** leaf to dhcpservice-config:

.. code-block:: none
   :caption: dhcpservice-config.yang
<commit_msg>align dhcp yang model in the spec with implementation<commit_after>.. contents:: Table of Contents
   :depth: 3

===================================
DHCP Server Dynamic Allocation Pool
===================================

[gerrit filter: https://git.opendaylight.org/gerrit/#/q/topic:dhcp_server_pool]

Extension of the ODL based DHCP server, which add support for dynamic address allocation to end
point users, that are not controlled (known) by OpenStack Neutron. Each DHCP pool can be configured
with additional information such as DNS servers, lease time (not yet), static allocations based on
MAC address, etc.

The feature supports IPv4 only.

Problem description
===================
In a non-neutron northbounds environment e.g. SD-WAN solution (unimgr), there is currently no
dynamic DHCP service for end-points or networks that are connected to OVS. Every DHCP packet that is
received by the controller, the controller finds the neutron port based on the inport of the packet,
extracts the ip which was allocated by neutron for that vm, and replies using that info. If the dhcp
packet is from a non-neutron port, the packet won't even reach the controller.

Use Cases
---------
a DHCP packet that is received by the odl, from a port that is managed by Netvirt and was configured
using the netvirt API, rather then the neutron API, in a way that there is no pre-allocated IP for
network interfaces behind that port - will be handled by the DHCP dynamic allocation pool that is
configured on the network associated with the receiving OVS port.

Proposed change
===============
We wish to forward to the controller, every dhcp packet coming from a non-neutron port as well (as
long as it is configured to use the controller dhcp). Once a DHCP packet is recieved by the
controller, the controller will check if there is already a pre-allocated address by checking if
packet came from a neutron port. if so, the controller will reply using the information from the
neutron port. Otherwise, the controller will find the allocation pool for the network which the
packet came from and will allocate the next free ip. The operation of each allocation pool will
be managed through the Genius ID Manager service that will support the allocation and release of IP
addresses (ids), persistent mapping across controller restarts and more. Neutron IP allocations will
be added to the relevant pools to avoid allocation of the same addresses.

Pipeline changes
----------------
This new rule in table 60 will be responsible for forwarding dhcp packets to the controller:

.. code-block:: bash

 cookie=0x6800000, duration=121472.576s, table=60, n_packets=1, n_bytes=342, priority=49,udp,tp_src=68,tp_dst=67 actions=CONTROLLER:65535


Yang changes
------------
New YANG model to support the configuration of the DHCP allocation pools and allocations, per
network and subnet.

* Allocation-Pool: configuration of allocation pool parameters like range, gateway and dns servers.
* Allocation-Instance: records of IP address allocation per MAC address. Records represent dynamic
  or static allocations, and Neutron pre-allocated addresses.

.. code-block:: none
   :caption: dhcp_allocation_pool.yang

    container dhcp_allocation_pool {
        config true;
        description "contains DHCP Server dynamic allocations";

        list network {
            key "network-id";
            leaf network-id {
                description "network (elan-instance) id";
                type string;
            }
            list allocation {
                key "subnet";
                leaf subnet {
                    description "subnet for the dhcp to allocate ip addresses";
                    type inet:ip-prefix;
                }

                list allocation-instance {
                    key "mac";
                    leaf mac {
                        description "requesting mac";
                        type yang:phys-address;
                    }
                    leaf allocated-ip {
                        description "allocated ip address";
                        type inet:ip-address;
                    }
                }
            }
            list allocation-pool {
                key "subnet";
                leaf subnet {
                    description "subnet for the dhcp to allocate ip addresses";
                    type inet:ip-prefix;
                }
                leaf allocate-from {
                    description "low allocation limit";
                    type inet:ip-address;
                }
                leaf allocate-to {
                    description "high allocation limit";
                    type inet:ip-address;
                }
                leaf gateway {
                    description "default gateway for dhcp allocation";
                    type inet:ip-address;
                }
                list dns-servers {
                    description "dns server list";
                    leaf dns-server {
                        description "dns server entry";
                        type inet:ip-address;
                    }
                }
            }
        }
    }


Configuration impact
--------------------
The feature is activated in the configuration (disabled by default).

adding **dhcp-dynamic-allocation-pool-enabled** leaf to dhcpservice-config:

.. code-block:: none
   :caption: dhcpservice-config.yang

{'fraction_non_alphanumeric': 0.0786685419596812, 'fraction_numerical': 0.007126113455227379, 'mean_word_length': 2.2548062252059813, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7048362', 'n_tokens_mistral': 2670, 'n_tokens_neox': 2435, 'n_words': 1174}