Skip to content

vamsireddygaliveeti/sonic-l2l3-protocol-debugger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

SONiC L2/L3 Protocol Debugger (BGP-FRR-ECMP)

A hands-on, engineering-focused project that models how real SONiC-based switches behave internally.
This tool brings together the essential building blocks of a modern data-center switch: VLAN handling, routing, BGP/FRR neighbor logic, ARP behavior, next-hop selection, and ECMP load balancing.

Rather than replicating a full NOS, this project focuses on the parts engineers actually debug every day.


๐Ÿš€ What This Project Is About

This project started as a personal way to understand how SONiC and FRRouting manage L2/L3 control-plane behavior.
Everything hereโ€”from the BGP state machine to ECMP hashingโ€”is written with simplicity, clarity, and real switch behavior in mind.

The goal is not to be a simulator.
The goal is to think like a switch, debug like an engineer, and see how protocols interact internally.


๐Ÿ”ง Key Components

VLAN Manager

  • Builds VLANs and port memberships
  • Tracks MAC learning logic
  • Identifies mismatched FDB entries
  • Helps visualize L2 segmentation

Routing Engine

  • Longest-prefix match logic
  • Multi-path routing (ECMP) with round-robin rotation
  • Route origin tracking (static, connected, BGP)
  • Debug-friendly route history

BGP/FRR-Inspired Neighbor Logic

  • Simplified BGP FSM
  • Keepalive timers
  • Flap detection
  • Basic advertisement behavior
  • Neighbor stability score

ARP Behavior

  • Dynamic and static learning
  • ARP aging
  • Miss and retry logic
  • Pending state tracking

Debug Modules

  • VLAN mismatch detector
  • ECMP path-change observer
  • BGP flap analyzer
  • Route convergence tracker
  • State history viewer

C++ Flow Engine

  • Lightweight 5-tuple hashing
  • ECMP distribution simulation
  • Useful for checking load-balancing behavior

๐Ÿ“‚ Project Layout

sonic-l2l3-protocol-debugger/
โ”œโ”€โ”€ main.py
โ”œโ”€โ”€ build_and_run.ps1
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ .vscode/              # editor settings (optional to document)
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ vlan_manager.py
โ”‚   โ”œโ”€โ”€ routing_engine.py
โ”‚   โ”œโ”€โ”€ bgp_frr_neighbor.py
โ”‚   โ”œโ”€โ”€ arp_table.py
โ”‚   โ”œโ”€โ”€ cli.py
โ”‚   โ””โ”€โ”€ __pycache__/      # generated, not committed
โ”œโ”€โ”€ cpp/
โ”‚   โ””โ”€โ”€ packet_processor.cpp
โ””โ”€โ”€ docs/
    โ””โ”€โ”€ QUICKSTART.md

Everything is organized the same way a real NOS codebase is separated:
L2, L3, control-plane state machines, and tools.


โš™๏ธ Setup & Run

1. Python Environment

Requires Python 3.9+.

Install dependencies:

pip install -r requirements.txt

2. Run the Debugger CLI

python main.py

You will see the banner and can start issuing commands (e.g. show vlan).

3. PowerShell Helper Script (Optional)

On Windows you can use the included script:

./build_and_run.ps1

This can be extended to compile C++ or perform pre-run checks (currently lightweight).

4. C++ Flow Engine

To experiment with the ECMP hashing logic:

g++ -O2 -std=c++17 cpp/packet_processor.cpp -o packet_processor
./packet_processor

5. Housekeeping

__pycache__/ and .vscode/ are generated/editor-specific and intentionally excluded from conceptual docs.


๐ŸŽฎ CLI Highlights

The CLI behaves like a trimmed SONiC/FRR environment:

show vlan
show arp
show ip bgp summary
show ip bgp neighbors
show route
show ecmp paths
debug bgp events
debug vlan mismatch
debug route updates
help
exit

The initial environment loads with:

  • Prebuilt VLANs
  • Static + BGP-style routes
  • Neighbors in different FSM states
  • ARP entries that age naturally
  • ECMP routes to observe hashing behavior

It's meant to feel like a switch you can play with, without needing hardware


๐Ÿ” Engineering Notes

Routing Logic

Designed to be easy to follow but still realistic:

  • Longest prefix match
  • Multipath awareness
  • Hop rotation
  • Next-hop visibility

BGP State Machine

Imitates FRR's practical behavior:

  • State transitions
  • Keepalive timing
  • Flap counters
  • Basic advertising logic

ARP Table

Reflects real control planes:

  • Pending state
  • Retry tracking
  • Aging and cleanup
  • Static overrides

ECMP Engine (C++)

Useful for:

  • Testing per-flow distribution
  • Observing how hashing decisions behave
  • Validating path imbalance

๐Ÿ“Š Sample Output Snapshot

===============================================
 SONiC L2/L3 Protocol Debugger
 Type 'help' for available commands
===============================================

> show vlan

VLAN    Name        Ports
10      Users       Ethernet0, Ethernet4
20      Mgmt        Ethernet8
30      Storage     Ethernet12

Routes, BGP neighbors, and ARP tables show in a similar detailed format.


๐ŸŽฏ Why I Built This

I wanted a realistic environment to learn, test, and visualize how:

  • Control-plane states transition
  • ECMP makes decisions
  • BGP behaves under flaps
  • ARP interacts with routing
  • VLANs affect forwarding

This project gave me a way to explore these ideas without relying on vendor hardware.


๐Ÿ‘ค About Me

I'm Vamsi Reddy Galiveeti, a software engineer who enjoys building systems that behave like real networking platforms.
My interests revolve around C++, Python, system design, cloud networking, SONiC, FRR, and data-center routing.
I love writing clean, understandable code and recreating real-world scenarios in small, focused tools.

๐Ÿ“ง vamsigaliveetivr@gmail.com
๐Ÿ“ Dallas, TX
๐Ÿ”— LinkedIn


About

SONiC-style L2/L3 protocol debugger with VLAN switching, ARP handling, BGP-FRR state logic, and ECMP routing analysis.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors