# sachinites/tcpip_stack architecture

> Architecture diagram of the GitHub repository sachinites/tcpip_stack, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sachinites/tcpip_stack
- Repository: https://github.com/sachinites/tcpip_stack

## Overview

tcpip_stack is an educational, in-process network-topology emulator for routers and switches. The principal workflow is to configure a topology through its CLI, start its packet-receive machinery, and exercise packet forwarding across Ethernet/ARP, switching/VLAN, and IP-routing stages; ping provides an end-to-end demonstration. The graph preserves the README’s project capabilities, while showing only relationships supported by excerpts, indexed references, or README statements. Unsampled modules are represented only where the tree and documentation support their role.

Main entry points: [`Layer3/layer3.c`](https://github.com/sachinites/tcpip_stack/blob/master/Layer3/layer3.c) (IP routing), [`nwcli.c`](https://github.com/sachinites/tcpip_stack/blob/master/nwcli.c) (Network CLI), [`graph.c`](https://github.com/sachinites/tcpip_stack/blob/master/graph.c) (Network graph), [`comm.c`](https://github.com/sachinites/tcpip_stack/blob/master/comm.c) (Packet transport)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["CLI and Configuration"]
  node_cli["CLI command tree<br/>[cmd_hier.c]"]
  node_parser["Command parser<br/>[parser.c]"]
  node_tlv["Command TLV<br/>[cmdtlv.h]"]
  node_nwcli["Network CLI<br/>[nwcli.c]"]
end

subgraph group_topology["Topology and Transport"]
  node_topologies["Topology setup<br/>[topologies.c]"]
  node_graph["Network graph<br/>[graph.c]"]
  node_netprops["Node properties<br/>[net.c]"]
  node_transport["Packet transport<br/>[comm.c]"]
end

subgraph group_forwarding["Packet Forwarding"]
  node_l2["Ethernet and ARP<br/>[layer2.c]"]
  node_switch["MAC and VLAN switching<br/>[l2switch.c]"]
  node_l3["IP routing<br/>[layer3.c]"]
  node_l4["Layer 4<br/>[layer4.c]"]
  node_l5["Layer 5 app<br/>[layer5.c]"]
  node_ping["Ping application<br/>[ping.c]"]
end

subgraph group_support["Runtime Support"]
  node_timer["Wheel timer<br/>[WheelTimer.c]"]
  node_lists["Glue-thread lists<br/>[glthread.c]"]
  node_packetgen["Packet generator<br/>[pkt_gen.c]"]
end

node_user(("Network operator"))

node_user -->|"issues commands"| node_nwcli
node_nwcli -->|"uses CLI"| node_cli
node_nwcli -->|"encodes commands"| node_tlv
node_nwcli -->|"configures topology"| node_graph
node_cli -->|"parses commands"| node_parser
node_parser -->|"collects values"| node_tlv
node_topologies -->|"builds topology"| node_graph
node_topologies -->|"starts receiver"| node_transport
node_graph -->|"stores properties"| node_netprops
node_transport -->|"uses node links"| node_graph
node_l2 -->|"sends frames"| node_transport
node_switch -->|"forwards frames"| node_transport
node_l3 -->|"demotes packets"| node_l2
node_l3 -->|"promotes packets"| node_l4
node_l3 -->|"promotes packets"| node_l5
node_ping -->|"uses IP routing"| node_l3
node_l2 -->|"uses lists"| node_lists
node_l3 -->|"uses lists"| node_lists
node_timer -->|"uses lists"| node_lists
node_packetgen -.->|"creates packets"| node_l3

click node_cli "https://github.com/sachinites/tcpip_stack/blob/master/CommandParser/cmd_hier.c"
click node_parser "https://github.com/sachinites/tcpip_stack/blob/master/CommandParser/parser.c"
click node_tlv "https://github.com/sachinites/tcpip_stack/blob/master/CommandParser/cmdtlv.h"
click node_nwcli "https://github.com/sachinites/tcpip_stack/blob/master/nwcli.c"
click node_topologies "https://github.com/sachinites/tcpip_stack/blob/master/topologies.c"
click node_graph "https://github.com/sachinites/tcpip_stack/blob/master/graph.c"
click node_netprops "https://github.com/sachinites/tcpip_stack/blob/master/net.c"
click node_transport "https://github.com/sachinites/tcpip_stack/blob/master/comm.c"
click node_l2 "https://github.com/sachinites/tcpip_stack/blob/master/Layer2/layer2.c"
click node_switch "https://github.com/sachinites/tcpip_stack/blob/master/Layer2/l2switch.c"
click node_l3 "https://github.com/sachinites/tcpip_stack/blob/master/Layer3/layer3.c"
click node_l4 "https://github.com/sachinites/tcpip_stack/blob/master/Layer4/layer4.c"
click node_l5 "https://github.com/sachinites/tcpip_stack/blob/master/Layer5/layer5.c"
click node_ping "https://github.com/sachinites/tcpip_stack/blob/master/Layer5/ping.c"
click node_timer "https://github.com/sachinites/tcpip_stack/blob/master/WheelTimer/WheelTimer.c"
click node_lists "https://github.com/sachinites/tcpip_stack/blob/master/gluethread/glthread.c"
click node_packetgen "https://github.com/sachinites/tcpip_stack/blob/master/pkt_gen.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_parser,node_tlv,node_nwcli toneBlue
class node_topologies,node_graph,node_netprops,node_transport toneAmber
class node_l2,node_switch,node_l3,node_l4,node_l5,node_ping toneMint
class node_timer,node_lists,node_packetgen toneRose
class node_user toneIndigo
```

## Components

### CLI and Configuration

- [CLI command tree](https://github.com/sachinites/tcpip_stack/blob/master/CommandParser/cmd_hier.c): `CommandParser/cmd_hier.c`
- [Command parser](https://github.com/sachinites/tcpip_stack/blob/master/CommandParser/parser.c): `CommandParser/parser.c`
- [Command TLV](https://github.com/sachinites/tcpip_stack/blob/master/CommandParser/cmdtlv.h): `CommandParser/cmdtlv.h`
- [Network CLI](https://github.com/sachinites/tcpip_stack/blob/master/nwcli.c): `nwcli.c`

### Topology and Transport

- [Topology setup](https://github.com/sachinites/tcpip_stack/blob/master/topologies.c): `topologies.c`
- [Network graph](https://github.com/sachinites/tcpip_stack/blob/master/graph.c): `graph.c`
- [Node properties](https://github.com/sachinites/tcpip_stack/blob/master/net.c): `net.c`
- [Packet transport](https://github.com/sachinites/tcpip_stack/blob/master/comm.c): `comm.c`

### Packet Forwarding

- [Ethernet and ARP](https://github.com/sachinites/tcpip_stack/blob/master/Layer2/layer2.c): `Layer2/layer2.c`
- [MAC and VLAN switching](https://github.com/sachinites/tcpip_stack/blob/master/Layer2/l2switch.c): `Layer2/l2switch.c`
- [IP routing](https://github.com/sachinites/tcpip_stack/blob/master/Layer3/layer3.c): `Layer3/layer3.c`
- [Layer 4](https://github.com/sachinites/tcpip_stack/blob/master/Layer4/layer4.c): `Layer4/layer4.c`
- [Layer 5 app](https://github.com/sachinites/tcpip_stack/blob/master/Layer5/layer5.c): `Layer5/layer5.c`
- [Ping application](https://github.com/sachinites/tcpip_stack/blob/master/Layer5/ping.c): `Layer5/ping.c`

### Runtime Support

- [Wheel timer](https://github.com/sachinites/tcpip_stack/blob/master/WheelTimer/WheelTimer.c): `WheelTimer/WheelTimer.c`
- [Glue-thread lists](https://github.com/sachinites/tcpip_stack/blob/master/gluethread/glthread.c): `gluethread/glthread.c`
- [Packet generator](https://github.com/sachinites/tcpip_stack/blob/master/pkt_gen.c): `pkt_gen.c`

### Other components

- **Network operator**

## Connections

- Network operator → Network CLI: issues commands
- Network CLI → CLI command tree: uses CLI (evidence: `nwcli.c`)
- Network CLI → Command TLV: encodes commands (evidence: `nwcli.c`)
- Network CLI → Network graph: configures topology (evidence: `nwcli.c`)
- CLI command tree → Command parser: parses commands
- Command parser → Command TLV: collects values (evidence: `CommandParser/parser.c`)
- Topology setup → Network graph: builds topology (evidence: `topologies.c`)
- Topology setup → Packet transport: starts receiver (evidence: `topologies.c`)
- Network graph → Node properties: stores properties
- Packet transport → Network graph: uses node links (evidence: `comm.c`)
- Ethernet and ARP → Packet transport: sends frames (evidence: `Layer2/layer2.c`)
- MAC and VLAN switching → Packet transport: forwards frames (evidence: `Layer2/l2switch.c`)
- IP routing → Ethernet and ARP: demotes packets (evidence: `Layer3/layer3.c`)
- IP routing → Layer 4: promotes packets (evidence: `Layer3/layer3.c`)
- IP routing → Layer 5 app: promotes packets (evidence: `Layer3/layer3.c`)
- Ping application → IP routing: uses IP routing (evidence: `Layer5/ping.c`)
- Ethernet and ARP → Glue-thread lists: uses lists (evidence: `Layer2/layer2.c`)
- IP routing → Glue-thread lists: uses lists
- Wheel timer → Glue-thread lists: uses lists
- Packet generator → IP routing: creates packets
