-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
385 lines (370 loc) · 24.7 KB
/
Copy pathindex.html
File metadata and controls
385 lines (370 loc) · 24.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Network Protocol Simulator — CSMA / CD / CA</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=DM+Mono:wght@300;400;500&family=Syne:wght@400;600;700;800&family=DM+Sans:ital,wght@0,300;0,400;0,500;1,300&display=swap" rel="stylesheet" />
<link rel="stylesheet" href="css/styles.css" />
</head>
<body>
<!-- ══════════════════════════════════════════
HEADER
══════════════════════════════════════════ -->
<header class="site-header">
<div class="header-inner">
<div class="header-brand">
<svg width="28" height="28" viewBox="0 0 28 28" fill="none" class="brand-icon">
<circle cx="14" cy="14" r="13" stroke="#eb5e28" stroke-width="1.5" />
<circle cx="14" cy="14" r="4" fill="#eb5e28" />
<line x1="14" y1="1" x2="14" y2="7" stroke="#eb5e28" stroke-width="1.5" />
<line x1="14" y1="21" x2="14" y2="27" stroke="#eb5e28" stroke-width="1.5" />
<line x1="1" y1="14" x2="7" y2="14" stroke="#eb5e28" stroke-width="1.5" />
<line x1="21" y1="14" x2="27" y2="14" stroke="#eb5e28" stroke-width="1.5" />
</svg>
<span class="brand-name">NetProto<span class="accent">Sim</span></span>
</div>
<nav class="header-nav">
<button class="nav-tab active" data-protocol="csma">CSMA</button>
<button class="nav-tab" data-protocol="csmacd">CSMA/CD</button>
<button class="nav-tab" data-protocol="csmaca">CSMA/CA</button>
</nav>
<div class="header-meta">
<span class="meta-label">MAC Layer Protocols</span>
</div>
</div>
</header>
<!-- ══════════════════════════════════════════
THEORY SECTION
══════════════════════════════════════════ -->
<section class="theory-section" id="theory-section">
<!-- CSMA Theory -->
<div class="theory-content active" id="theory-csma">
<div class="theory-inner">
<div class="theory-title-block">
<div class="theory-badge">Protocol 01</div>
<h1 class="theory-h1">CSMA <span class="dim">— Carrier Sense Multiple Access</span></h1>
</div>
<div class="theory-cols">
<div class="theory-col">
<p class="theory-p">
CSMA is a Media Access Control (MAC) protocol in which a node verifies the absence of other traffic before transmitting on a shared transmission medium. A sender first listens to the channel; only if it finds the channel idle does it proceed to transmit.
</p>
<p class="theory-p">The <strong>1-persistent</strong> variant transmits with probability 1 once the channel is sensed idle — the simplest approach but prone to collisions when multiple stations wait for a busy channel to clear.</p>
</div>
<div class="theory-col">
<div class="theory-facts">
<div class="fact-item">
<svg width="18" height="18" viewBox="0 0 18 18" fill="none">
<circle cx="9" cy="9" r="8" stroke="#eb5e28" stroke-width="1.2" />
<path d="M6 9l2 2 4-4" stroke="#eb5e28" stroke-width="1.2" stroke-linecap="round" />
</svg>
<span>Sense before transmit</span>
</div>
<div class="fact-item">
<svg width="18" height="18" viewBox="0 0 18 18" fill="none">
<circle cx="9" cy="9" r="8" stroke="#eb5e28" stroke-width="1.2" />
<path d="M6 9l2 2 4-4" stroke="#eb5e28" stroke-width="1.2" stroke-linecap="round" />
</svg>
<span>No collision detection</span>
</div>
<div class="fact-item">
<svg width="18" height="18" viewBox="0 0 18 18" fill="none">
<circle cx="9" cy="9" r="8" stroke="#eb5e28" stroke-width="1.2" />
<path d="M6 9l2 2 4-4" stroke="#eb5e28" stroke-width="1.2" stroke-linecap="round" />
</svg>
<span>Retry on failure</span>
</div>
<div class="fact-item">
<svg width="18" height="18" viewBox="0 0 18 18" fill="none">
<circle cx="9" cy="9" r="8" stroke="#eb5e28" stroke-width="1.2" />
<path d="M6 9l2 2 4-4" stroke="#eb5e28" stroke-width="1.2" stroke-linecap="round" />
</svg>
<span>Used in early Ethernet</span>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- CSMA/CD Theory -->
<div class="theory-content" id="theory-csmacd">
<div class="theory-inner">
<div class="theory-title-block">
<div class="theory-badge">Protocol 02</div>
<h1 class="theory-h1">CSMA/CD <span class="dim">— Collision Detection</span></h1>
</div>
<div class="theory-cols">
<div class="theory-col">
<p class="theory-p">CSMA/CD extends CSMA by adding the ability to detect collisions during transmission. When a collision is detected, a jamming signal is sent, transmission is aborted, and each station waits a random backoff time before retrying.</p>
<p class="theory-p">The <strong>binary exponential backoff</strong> algorithm doubles the contention window after each collision (K = 0..15), dramatically reducing repeat collisions. Maximum retries K<sub>max</sub> = 15; beyond that, the frame is aborted.</p>
</div>
<div class="theory-col">
<div class="theory-facts">
<div class="fact-item">
<svg width="18" height="18" viewBox="0 0 18 18" fill="none">
<circle cx="9" cy="9" r="8" stroke="#eb5e28" stroke-width="1.2" />
<path d="M6 9l2 2 4-4" stroke="#eb5e28" stroke-width="1.2" stroke-linecap="round" />
</svg>
<span>Detect collision mid-transmission</span>
</div>
<div class="fact-item">
<svg width="18" height="18" viewBox="0 0 18 18" fill="none">
<circle cx="9" cy="9" r="8" stroke="#eb5e28" stroke-width="1.2" />
<path d="M6 9l2 2 4-4" stroke="#eb5e28" stroke-width="1.2" stroke-linecap="round" />
</svg>
<span>Jam signal broadcast</span>
</div>
<div class="fact-item">
<svg width="18" height="18" viewBox="0 0 18 18" fill="none">
<circle cx="9" cy="9" r="8" stroke="#eb5e28" stroke-width="1.2" />
<path d="M6 9l2 2 4-4" stroke="#eb5e28" stroke-width="1.2" stroke-linecap="round" />
</svg>
<span>Binary exponential backoff</span>
</div>
<div class="fact-item">
<svg width="18" height="18" viewBox="0 0 18 18" fill="none">
<circle cx="9" cy="9" r="8" stroke="#eb5e28" stroke-width="1.2" />
<path d="M6 9l2 2 4-4" stroke="#eb5e28" stroke-width="1.2" stroke-linecap="round" />
</svg>
<span>IEEE 802.3 (Classic Ethernet)</span>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- CSMA/CA Theory -->
<div class="theory-content" id="theory-csmaca">
<div class="theory-inner">
<div class="theory-title-block">
<div class="theory-badge">Protocol 03</div>
<h1 class="theory-h1">CSMA/CA <span class="dim">— Collision Avoidance</span></h1>
</div>
<div class="theory-cols">
<div class="theory-col">
<p class="theory-p">CSMA/CA is designed for wireless networks where collision detection is impractical. Instead of detecting collisions, it actively avoids them by waiting an Inter-Frame Space (IFS) and a random backoff window before transmitting.</p>
<p class="theory-p">After transmission the sender awaits an <strong>ACK</strong> from the receiver. No ACK means the frame was lost (possibly via collision), triggering a retry with an incremented attempt counter K, up to K<sub>max</sub> = 15.</p>
</div>
<div class="theory-col">
<div class="theory-facts">
<div class="fact-item">
<svg width="18" height="18" viewBox="0 0 18 18" fill="none">
<circle cx="9" cy="9" r="8" stroke="#eb5e28" stroke-width="1.2" />
<path d="M6 9l2 2 4-4" stroke="#eb5e28" stroke-width="1.2" stroke-linecap="round" />
</svg>
<span>IFS wait before transmit</span>
</div>
<div class="fact-item">
<svg width="18" height="18" viewBox="0 0 18 18" fill="none">
<circle cx="9" cy="9" r="8" stroke="#eb5e28" stroke-width="1.2" />
<path d="M6 9l2 2 4-4" stroke="#eb5e28" stroke-width="1.2" stroke-linecap="round" />
</svg>
<span>Random backoff slots</span>
</div>
<div class="fact-item">
<svg width="18" height="18" viewBox="0 0 18 18" fill="none">
<circle cx="9" cy="9" r="8" stroke="#eb5e28" stroke-width="1.2" />
<path d="M6 9l2 2 4-4" stroke="#eb5e28" stroke-width="1.2" stroke-linecap="round" />
</svg>
<span>ACK-based confirmation</span>
</div>
<div class="fact-item">
<svg width="18" height="18" viewBox="0 0 18 18" fill="none">
<circle cx="9" cy="9" r="8" stroke="#eb5e28" stroke-width="1.2" />
<path d="M6 9l2 2 4-4" stroke="#eb5e28" stroke-width="1.2" stroke-linecap="round" />
</svg>
<span>IEEE 802.11 (Wi-Fi)</span>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- ══════════════════════════════════════════
MAIN SIMULATOR LAYOUT
══════════════════════════════════════════ -->
<main class="sim-layout">
<!-- ── LEFT: SIMULATION PANEL ── -->
<section class="sim-panel">
<div class="sim-panel-header">
<svg width="16" height="16" viewBox="0 0 16 16" fill="none">
<rect x="1" y="1" width="14" height="14" rx="2" stroke="#403d39" stroke-width="1.2" />
<circle cx="5" cy="8" r="1.5" fill="#403d39" />
<circle cx="8" cy="8" r="1.5" fill="#403d39" />
<circle cx="11" cy="8" r="1.5" fill="#403d39" />
</svg>
<span>Live Simulation</span>
<span class="clock-display">Tick: <span id="clock-val">0</span></span>
</div>
<!-- Controls -->
<div class="controls-grid">
<div class="controls-card nodea-controls">
<div class="controls-card-header">Node A Controls</div>
<div class="controls-row">
<div class="dest-selector">
<span class="dest-label">Destination</span>
<div class="pill-group">
<label class="pill active-pill"><input type="radio" name="dest" value="B" checked /> B</label>
<label class="pill"><input type="radio" name="dest" value="C" /> C</label>
<label class="pill"><input type="radio" name="dest" value="D" /> D</label>
</div>
</div>
<button class="btn-send" id="btn-send">
<svg width="14" height="14" viewBox="0 0 14 14" fill="none"><path d="M1 7h12M8 3l5 4-5 4" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" /></svg>
Send Frame from A
</button>
</div>
</div>
<div class="controls-card simulation-controls">
<div class="controls-card-header">Simulation Controls</div>
<div class="controls-row">
<button class="btn-playpause" id="btn-playpause" disabled aria-label="Play simulation">
<svg width="14" height="14" viewBox="0 0 14 14" fill="none">
<path d="M3 2l9 5-9 5V2z" fill="currentColor" />
</svg>
Play
</button>
<button class="btn-step" id="btn-step" disabled>
<svg width="14" height="14" viewBox="0 0 14 14" fill="none">
<path d="M3 2l8 5-8 5V2z" fill="currentColor" />
<line x1="11" y1="2" x2="11" y2="12" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" />
</svg>
Step
</button>
<div class="speed-control enhanced-select">
<svg width="13" height="13" viewBox="0 0 13 13" fill="none">
<circle cx="6.5" cy="6.5" r="5.5" stroke="#403d39" stroke-width="1.1" />
<path d="M6.5 3.5v3l2 1.5" stroke="#403d39" stroke-width="1.1" stroke-linecap="round" />
</svg>
<span class="select-prefix">Speed</span>
<div class="select-shell">
<select id="speed-select" class="speed-select" aria-label="Simulation speed">
<option value="1200">Slow</option>
<option value="600" selected>Normal</option>
<option value="300">Fast</option>
<option value="100">Turbo</option>
</select>
<svg class="select-caret" width="10" height="10" viewBox="0 0 10 10" fill="none" aria-hidden="true">
<path d="M2 3.5L5 6.5L8 3.5" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round" />
</svg>
</div>
</div>
<div class="speed-control enhanced-select">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none">
<path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" stroke="#403d39" stroke-width="2" stroke-linejoin="round" />
</svg>
<span class="select-prefix">Rate</span>
<div class="select-shell">
<select id="rate-select" class="speed-select" aria-label="Auto Tx Rate">
<option value="low">Low Rate</option>
<option value="normal" selected>Normal Rate</option>
<option value="high">High Rate</option>
</select>
<svg class="select-caret" width="10" height="10" viewBox="0 0 10 10" fill="none" aria-hidden="true">
<path d="M2 3.5L5 6.5L8 3.5" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round" />
</svg>
</div>
</div>
<button class="btn-reset" id="btn-reset">
<svg width="14" height="14" viewBox="0 0 14 14" fill="none">
<path d="M2 7a5 5 0 1 1 1.5 3.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" />
<path d="M2 11V7h4" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" />
</svg>
Reset
</button>
</div>
</div>
</div>
<!-- Channel visualizer -->
<div class="channel-area">
<div class="channel-label-row">
<span class="ch-label">Shared Medium</span>
<span class="channel-status-badge" id="channel-badge">IDLE</span>
</div>
<div class="channel-track" id="channel-track">
<div class="channel-line"></div>
<div class="frame-particle" id="frame-particle" style="display: none"></div>
<div class="jam-overlay" id="jam-overlay" style="display: none"></div>
</div>
<div class="node-row" id="node-row">
<!-- Nodes rendered by JS -->
</div>
</div>
<!-- Channel state info -->
<div class="channel-info-row">
<div class="ch-info-item" id="chinfo-idle">
<div class="ch-dot idle-dot"></div>
<span>Idle</span>
</div>
<div class="ch-info-item" id="chinfo-busy">
<div class="ch-dot busy-dot"></div>
<span>Busy</span>
</div>
<div class="ch-info-item" id="chinfo-collision">
<div class="ch-dot collision-dot"></div>
<span>Collision</span>
</div>
</div>
<!-- Node state legend -->
<div class="state-legend">
<span class="legend-item"><span class="ls idle"></span>Idle</span>
<span class="legend-item"><span class="ls sensing"></span>Sensing</span>
<span class="legend-item"><span class="ls transmitting"></span>Transmitting</span>
<span class="legend-item"><span class="ls backoff"></span>Backoff</span>
<span class="legend-item"><span class="ls collision"></span>Collision</span>
<span class="legend-item"><span class="ls receiving"></span>Receiving</span>
<span class="legend-item"><span class="ls waiting"></span>Waiting</span>
</div>
<!-- Event Log -->
<div class="log-panel">
<div class="log-header">
<svg width="14" height="14" viewBox="0 0 14 14" fill="none">
<rect x="1" y="2" width="12" height="10" rx="1.5" stroke="#403d39" stroke-width="1.1" />
<line x1="4" y1="5" x2="10" y2="5" stroke="#403d39" stroke-width="1.1" />
<line x1="4" y1="7.5" x2="10" y2="7.5" stroke="#403d39" stroke-width="1.1" />
<line x1="4" y1="10" x2="7" y2="10" stroke="#403d39" stroke-width="1.1" />
</svg>
<span>Event Log</span>
</div>
<div class="log-body" id="log-body"></div>
</div>
</section>
<!-- ── RIGHT: FLOWCHART PANEL ── -->
<section class="flow-panel">
<div class="flow-panel-header">
<svg width="16" height="16" viewBox="0 0 16 16" fill="none">
<rect x="4" y="1" width="8" height="4" rx="1" stroke="#403d39" stroke-width="1.1" />
<path d="M8 5v2.5" stroke="#403d39" stroke-width="1.1" />
<path d="M3 7.5h10l-5 4-5-4z" stroke="#403d39" stroke-width="1.1" stroke-linejoin="round" />
<path d="M8 11.5V15" stroke="#403d39" stroke-width="1.1" />
<rect x="4" y="15" width="8" height="0" rx="0" />
</svg>
<span>Protocol Flowchart</span>
</div>
<!-- CSMA Flowchart -->
<div class="flowchart-wrap active" id="fc-csma">
<svg id="svg-csma" viewBox="0 0 260 520" xmlns="http://www.w3.org/2000/svg" class="fc-svg"></svg>
</div>
<!-- CSMA/CD Flowchart -->
<div class="flowchart-wrap" id="fc-csmacd">
<svg id="svg-csmacd" viewBox="0 0 300 640" xmlns="http://www.w3.org/2000/svg" class="fc-svg"></svg>
</div>
<!-- CSMA/CA Flowchart -->
<div class="flowchart-wrap" id="fc-csmaca">
<svg id="svg-csmaca" viewBox="0 0 300 680" xmlns="http://www.w3.org/2000/svg" class="fc-svg"></svg>
</div>
</section>
</main>
<footer class="site-footer">
<span>Network Protocol Simulator · MAC Layer Protocols · CSMA / CSMA/CD / CSMA/CA</span>
<span>Educational Project</span>
</footer>
<script src="js/flowcharts.js"></script>
<script src="js/simulation.js"></script>
<script src="js/main.js"></script>
</body>
</html>