Skip to content

Commit

Permalink
Add multi-asic
Browse files Browse the repository at this point in the history
  • Loading branch information
yaqiangz committed Jan 2, 2025
1 parent 2badcec commit db744c6
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions doc/dhcp_relay/DHCPv4-per-interface-counter.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,41 @@ Currently, DHCPv4 counter in dhcpmon mainly focus on Vlan / PortChannel interfac

## Design Overview

To address above 2 issues, we propose below design, it could be devided into 3 parts: `Init`, `Per-interface counting` and `Persist`
To address above 2 issues, we propose below design, it could be devided into 4 parts: `Init`, `Per-interface counting`, `Persist` and `clear counter`.

### Init

<div align="center"> <img src=images/init.png width=530 /> </div>
<div align="center"> <img src=images/init_multi_thread.png width=550 /> </div>

1. There are **2 sockets for all interfaces** to capture DHCPv4 packets. We bind callback to the network events to process packets.
2. Read from `PORTCHANNEL_MEMBER` and `VLAN_MEMBER` table CONFIG_DB to construct mapping between physical interface and PortChannel/Vlan. It's used to query context interface by physical interface.
3. We have 2 kinds of counters, one is persisted in STATE_DB, another is stored in process memory, they are initialized when process startup.
4. Initialize a timer to periodically sync counter data from cache counter to DB counter.
4. A signal callback would be added to listen for counter cleaning signal to clear counter in process memory.
5. Initialize a timer to periodically sync counter data from cache counter to DB counter in another thread.

### Per-interface counting
With above structure, packets processing and all write actions to cache counter in process memory would be done in **main thread**, and all write actions to STATE_DB would be done in **DB update thread**.

### Per-interface counting (Main thread)

<div align="center"> <img src=images/per_intf_counting.png width=600 /> </div>

* From socket, we can fingure out which physical interface does the packet came from.
* Context interface name could be obtained by querying context interface counter.
* Then cache counter for corresponding physical interface and context would increase **immediately**.

### Persist
### Persist (DB update thread)

<div align="center"> <img src=images/persist_multi_thread.png width=400 /> </div>

DB update timer would be invoked periodically (**every 20s**) in another thread which is different with main thread, it will obtain the counter data increased during the statistical period from the cache counter **in batch**.

### Clear Counter

<div align="center"> <img src=images/clear_counter.png width=440 /> </div>

<div align="center"> <img src=images/persist.png width=450 /> </div>
When user invokes SONiC Cli to clear counter, it would directly clear corresponding data in STATE_DB, then write a temp file which contains counters of specified direction / packet type / interface need to be cleared, then a signal to clear cache counter would be sent to dhcpmon process.

DB update timer would be invoked periodically (**every 20s**), it will obtain the counter data increased during the statistical period from the cache counter
After receiving signal to clear cache, dhcpmon process would clear counter in process memory in `DB update thread`.

## Counter Logic

Expand Down
Binary file added doc/dhcp_relay/images/clear_counter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed doc/dhcp_relay/images/init.png
Binary file not shown.
Binary file added doc/dhcp_relay/images/init_multi_thread.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed doc/dhcp_relay/images/persist.png
Binary file not shown.
Binary file added doc/dhcp_relay/images/persist_multi_thread.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit db744c6

Please sign in to comment.