Skip to content

Commit ac04262

Browse files
committed
Add dhcrelay related
1 parent df3148b commit ac04262

6 files changed

+130
-75
lines changed
-2.37 KB
Loading
Binary file not shown.
77.9 KB
Loading
153 KB
Loading
Loading

doc/dhcp_server/port_based_dhcp_server_high_level_design.md

+130-75
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,20 @@
2525
- [Generate Config](#generate-config)
2626
- [Update Lease](#update-lease)
2727
- [Customize DHCP Packet Options](#customize-dhcp-packet-options)
28+
- [DHCP Relay Daemon](#dhcp-relay-daemon)
2829
- [DB Changes](#db-changes)
2930
- [Config DB](#config-db)
30-
- [Yang Model](#yang-model)
3131
- [DB Objects](#db-objects)
32-
- [State DB](#state-db)
3332
- [Yang Model](#yang-model)
33+
- [State DB](#state-db)
3434
- [DB Objects](#db-objects)
35+
- [Yang Model](#yang-model)
3536
- [Flow Diagrams](#flow-diagrams)
3637
- [DHCP Server Flow](#dhcp-server-flow)
3738
- [Config Change Flow](#config-change-flow)
3839
- [Lease Update Flow](#lease-update-flow)
40+
- [Start flow of dhcprelayd](#start-flow-of-dhcprelayd)
41+
- [Work flow of dhcprelayd capture db change](#work-flow-of-dhcprelayd-capture-db-change)
3942
- [CLI](#cli)
4043
- [Config CLI](#config-cli)
4144
- [Show CLI](#show-cli)
@@ -48,6 +51,7 @@
4851

4952
<!-- /TOC -->
5053

54+
5155
# Revision
5256

5357
| Rev | Date | Author | Change Description |
@@ -98,12 +102,12 @@ Configuration of DHCP server feature can be done via:
98102
## Design Overview
99103
We use kea-dhcp-server to reply DHCP request packet. kea-dhcp-server natively supports to assign IPs by mac or contents in DHCP packet (like client id or other options), but in our scenario kea-dhcp-server need to know which interface this packet come from. And SONiC has integrated dhcrelay, which can add interface information to option82 in packet when it relay DHCP packet. So we use it to add interface information.
100104

101-
<div align="center"> <img src=images/overview_kea.png width=570 /> </div>
102-
103105
In our design, dhcp_relay container works on host network mode as before. And dhcp_server container works on bridge network mode, means that it can communicate with switch network only via eth0.
104106

105107
For broadcast packet (discover, request) sent by client, obviously it would be routed to the related DHCP interface. For unicast packet (release), client will get server IP from Option 54 (server identifier) in DHCP reply packet receivced previously. But in our scenario, server identifier is the ip of `eth0` inside dhcp_server container (240.127.1.2), packet with this destination IP cannot be routed successfully. So we need to specify that kea-dhcp-server replies DHCP request with Option 54 filled with IP of DHCP interface (which is the downstream interface IP of dhcrelay), to let client take relay as server and send unicast packet to relay, and relay would transfer this packet to the real server.
106108

109+
<div align="center"> <img src=images/overview_kea.png width=570 /> </div>
110+
107111
Belows are sample configurations for dhcrelay and kea-dhcp-server:
108112

109113
- dhcprelay:
@@ -134,9 +138,15 @@ Belows are sample configurations for dhcrelay and kea-dhcp-server:
134138
"pools": [
135139
{
136140
// Assign ip from this pool for packet tagged as "hostname-etp1"
137-
"pool": "192.168.0.1 - 192.168.0.1",
141+
"pool": "192.168.0.2 - 192.168.0.2",
138142
"client-class": "hostname-etp1"
139143
}
144+
],
145+
"option-data": [
146+
{
147+
"name": "dhcp-server-identifier",
148+
"data": "192.168.0.1"
149+
}
140150
]
141151
}
142152
]
@@ -166,7 +176,7 @@ A new container dhcp_server based on debian:bookworm, is created to hold DHCP Se
166176
## DHCP Server Daemon
167177
### Generate Config
168178

169-
dhcpservd is to generate configuration file for kea-dhcp-server while DHCP Server config in CONFIG_DB changed, and then send SIGHUP signal to kea-dhcp-server process to let new config take affect.
179+
dhcpservd is to generate configuration file for kea-dhcp-server while DHCP Server config in CONFIG_DB changed, and then send SIGHUP signal to kea-dhcp-server process to let new config take effect.
170180
<div align="center"> <img src=images/dhcp_server_block_new_diagram.png width=530 /> </div>
171181

172182
### Update Lease
@@ -177,6 +187,11 @@ kea-dhcp-server supports to specify a customize script (`/tmp/lease_update.sh`)
177187
```JSON
178188
{
179189
"Dhcp4": {
190+
"lease-database": {
191+
"type": "memfile",
192+
"persist": true,
193+
"name": "/tmp/kea-lease.csv"
194+
},
180195
"hooks-libraries": [
181196
{
182197
"library": "/usr/lib/x86_64-linux-gnu/kea/hooks/libdhcp_run_script.so",
@@ -189,12 +204,19 @@ kea-dhcp-server supports to specify a customize script (`/tmp/lease_update.sh`)
189204
}
190205
}
191206
```
207+
```
208+
address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context,pool_id
209+
192.168.0.2,aa:bb:cc:dd:ee:ff,,3600,1694000905,1,0,0,hostname,0,,0
210+
192.168.0.131,aa:aa:cc:dd:ee:ff,,3600,1694000909,1,0,0,hostname,0,,1
211+
192.168.0.131,aa:aa:cc:dd:ee:ff,,0,1693997309,1,0,0,hostname,0,,1
212+
192.168.0.131,aa:aa:cc:dd:ee:ff,,0,1693997309,1,0,0,,2,,1
213+
192.168.0.131,aa:aa:cc:dd:ee:ff,,3600,1694000915,1,0,0,hostname,0,,1
214+
192.168.0.2,aa:bb:cc:dd:ee:ff,,0,1693997305,1,0,0,hostname,0,,0
215+
```
192216

193217
## Customize DHCP Packet Options
194218

195-
We can customize DHCP Packet options per DHCP interface by kea-dhcp-server.
196-
197-
We can set customized options for each DHCP interface, all DHCP clients connected to this interface share one configuration, and DHCP server would add DHCP options by config to each DHCP packet sent to client.
219+
We can customize DHCP Packet options per DHCP interface by kea-dhcp-server, all DHCP clients connected to this interface share one configuration, and DHCP server would add DHCP options by config to each DHCP packet sent to client.
198220
```JSON
199221
{
200222
"Dhcp4": {
@@ -223,10 +245,15 @@ Have to be aware of is that below options are not supported to customize, becaus
223245

224246
Currently support text, ipv4-address, uint8, uint16, uint32.
225247

248+
## DHCP Relay Daemon
249+
For scenario of dhcp_server feature is enabled, we need a daemon process inside dhcp_relay container to manage dhcrelay processes. dhcprelayd would subcribe VLAN/VLAN_MEMBER/DHCP_SERVER_IPV4* table in config_db, and when dhcp_relay container restart or related config changed, dhcprelayd will kill/start/restart dhcrelay process.
250+
251+
<div align="center"> <img src=images/dhcprelayd_flow.png width=350 /> </div>
252+
226253
## DB Changes
227-
We have two mainly DB changes:
228-
- Configuration tables for the DHCP server entries.
229-
- State tables for the DHCP server lease entries.
254+
We have two main DB changes:
255+
- CONFIG_DB change.
256+
- STATE_DB change.
230257

231258
### Config DB
232259
Following table changes would be added in Config DB, including **DHCP_SERVER_IPV4** table, **DHCP_SERVER_IPV4_RANGE** table, **DHCP_SERVER_IPV4_PORT** table and **DHCP_SERVER_IPV4_CUSTOMIZED_OPTIONS** table.
@@ -236,6 +263,56 @@ These new tables are introduced to specify configuration of DHCP Server.
236263
Below is the sample:
237264
<div align="center"> <img src=images/config_example.png width=530 /> </div>
238265

266+
#### DB Objects
267+
```JSON
268+
{
269+
"DHCP_SERVER_IPV4": {
270+
"Vlan100": {
271+
"gateway": "100.1.1.1",
272+
"lease_time": "3600",
273+
"mode": "PORT",
274+
"netmask": "255.255.255.0",
275+
"customized_options": [
276+
"option60"
277+
],
278+
"state": "enabled"
279+
}
280+
},
281+
"DHCP_SERVER_IPV4_CUSTOMIZED_OPTIONS": {
282+
"option60": {
283+
"id": "60",
284+
"type": "text",
285+
"value": "dummy_value"
286+
}
287+
},
288+
"DHCP_SERVER_IPV4_RANGE": {
289+
"range1": {
290+
"ranges": [
291+
"100.1.1.3",
292+
"100.1.1.5"
293+
]
294+
}
295+
},
296+
"DHCP_SERVER_IPV4_PORT": {
297+
"Vlan100|PortChannel0003": {
298+
"ips": [
299+
"100.1.1.10"
300+
]
301+
},
302+
"Vlan100|PortChannel2": {
303+
"ranges": [
304+
"range1"
305+
]
306+
}
307+
},
308+
"DHCP_SERER_IPV4_IP": {
309+
"eth0": {
310+
"ip": "240.127.1.2"
311+
}
312+
}
313+
}
314+
```
315+
239316
#### Yang Model
240317
[[yang][dhcp_server] Add dhcp_server_ipv4 yang model](https://github.com/sonic-net/sonic-buildimage/pull/15955)
241318
```yang
@@ -434,56 +511,32 @@ module sonic-dhcp-server-ipv4 {
434511
}
435512
```
436513

514+
### State DB
515+
Following table changes would be added in State DB, including **DHCP_SERVER_IPV4_LEASE** table and **DHCP_SERVER_IPV4_SERVER_IP** table.
516+
437517
#### DB Objects
438518
```JSON
439519
{
440-
"DHCP_SERVER_IPV4": {
441-
"Vlan100": {
442-
"gateway": "100.1.1.1",
443-
"lease_time": "3600",
444-
"mode": "PORT",
445-
"netmask": "255.255.255.0",
446-
"customized_options": [
447-
"option60"
448-
],
449-
"state": "enabled"
450-
}
451-
},
452-
"DHCP_SERVER_IPV4_CUSTOMIZED_OPTIONS": {
453-
"option60": {
454-
"id": "60",
455-
"type": "text",
456-
"value": "dummy_value"
457-
}
458-
},
459-
"DHCP_SERVER_IPV4_RANGE": {
460-
"range1": {
461-
"ranges": [
462-
"100.1.1.3",
463-
"100.1.1.5"
464-
]
465-
}
520+
"DHCP_SERVER_IPV4_LEASE": {
521+
"Vlan1000|10:70:fd:b6:13:00": {
522+
"lease_start": "1677640581", // Start time of lease, unix time
523+
"lease_end": "1677641481", // End time of lease
524+
"ip": "192.168.0.1"
525+
},
526+
"Vlan1000|10:70:fd:b6:13:01": {
527+
"lease_start": "1677640581",
528+
"lease_end": "1677641481",
529+
"ip": "192.168.0.2"
530+
}
466531
},
467-
"DHCP_SERVER_IPV4_PORT": {
468-
"Vlan100|PortChannel0003": {
469-
"ips": [
470-
"100.1.1.10"
471-
]
472-
},
473-
"Vlan100|PortChannel2": {
474-
"ranges": [
475-
"range1"
476-
]
477-
}
532+
"DHCP_SERVER_IPV4_SERVER_IP": {
533+
"eth0": {
534+
"ip": "240.127.1.2"
535+
}
478536
}
479537
}
480538
```
481539

482-
### State DB
483-
Following table changes would be added in State DB, including table and **DHCP_SERVER_IPV4_LEASE** table.
484-
485-
These new tables are introduced to count different type of DHCP packet and record lease information.
486-
487540
#### Yang Model
488541
```yang
489542
module sonic-dhcp-server-ipv4 {
@@ -513,26 +566,21 @@ module sonic-dhcp-server-ipv4 {
513566
}
514567
}
515568
/* end of container DHCP_SERVER_IPV4_LEASE */
516-
}
517-
/* end of container sonic-dhcp-server-ipv4 */
518-
}
519-
```
520-
521-
#### DB Objects
522-
```JSON
523-
{
524-
"DHCP_SERVER_IPV4_LEASE": {
525-
"Vlan1000|10:70:fd:b6:13:00": {
526-
"lease_start": "1677640581", // Start time of lease, unix time
527-
"lease_end": "1677641481", // End time of lease
528-
"ip": "192.168.0.1"
529-
},
530-
"Vlan1000|10:70:fd:b6:13:01": {
531-
"lease_start": "1677640581",
532-
"lease_end": "1677641481",
533-
"ip": "192.168.0.2"
569+
container DHCP_SERVER_IPV4_SERVER_IP {
570+
description "DHCP_SERVER_IPV4_SERVER_IP part of state_db";
571+
list DHCP_SERVER_IPV4_SERVER_IP_list {
572+
key "name";
573+
leaf name {
574+
type string;
575+
}
576+
leaf ip {
577+
description "IP address of dhcp_server";
578+
type inet:ipv4-address
579+
}
580+
}
534581
}
535582
}
583+
/* end of container sonic-dhcp-server-ipv4 */
536584
}
537585
```
538586

@@ -542,15 +590,22 @@ This sequence figure describe the work flow for reply DHCP packet.
542590
<div align="center"> <img src=images/server_flow.png width=500 /> </div>
543591

544592
### Config Change Flow
545-
This sequence figure describe the work flow for config_db changed CLI.
593+
This sequence figure describe the work flow of dhcpservd detect config_db changed CLI.
546594
<div align="center"> <img src=images/config_change_new_flow.png width=600 /> </div>
547-
<div align="center"> <img src=images/config_change_new_flow_vlan.png width=680 /> </div>
548595

549596
### Lease Update Flow
550597
Below sequence figure describes the work flow how kea-dhcp-server updates lease table while new lease is created.
551598

552599
<div align="center"> <img src=images/lease_update_flow_new.png width=480 /> </div>
553600

601+
### Start flow of dhcprelayd
602+
This sequence figure describe the work flow of dhcprelayd start. (Under enabled dhcp_server feature)
603+
<div align="center"> <img src=images/dhcprelayd_sequence.png width=670 /> </div>
604+
605+
### Work flow of dhcprelayd capture db change
606+
This sequence figure describe the work flow of dhcprelayd capture DHCP_SERVER_IPV4 table change. (Under enabled dhcp_server feature)
607+
<div align="center"> <img src=images/dhcprelayd_sequence_disable.png width=650 /> </div>
608+
554609
# CLI
555610
* config CLI
556611
| CLI | Description |
@@ -854,7 +909,7 @@ This command is used to show dhcp_server lease.
854909
|Case Description|Expected res|
855910
|:-|:-|
856911
|Add with --infer_gw_nm, --mode=PORT|Add success, state is disabled|
857-
|Add with --mode=DYNAMIC |Add failed because port not supported|
912+
|Add with --mode=DYNAMIC |Add failed because mode not supported|
858913
|Add interface not exist|Add failed|
859914
|Add without --mode |Add failed because mode is missing|
860915
|Add without --infer_gw_nm, --gateway and --netmask |Add failed because netmask and gateway is not specified|

0 commit comments

Comments
 (0)