-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
233 lines (224 loc) · 7.46 KB
/
Copy pathindex.html
File metadata and controls
233 lines (224 loc) · 7.46 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Distributed Mutual Exclusion Explorer (v0.3)</title>
<style>
:root {
--border: #d0d0d0;
--text: #111;
--muted: #666;
--bg: #fff;
--panel: #fafafa;
--ok: #0a7d00;
--bad: #a10000;
}
body {
font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
margin: 20px;
color: var(--text);
background: var(--bg);
}
header {
display: flex;
align-items: baseline;
gap: 12px;
flex-wrap: wrap;
}
h1 {
font-size: 20px;
margin: 0;
}
.pill {
padding: 2px 8px;
border-radius: 999px;
background: #eee;
font-size: 12px;
white-space: nowrap;
}
.note {
color: var(--muted);
font-size: 12px;
margin-top: 6px;
}
.grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 16px;
margin-top: 12px;
}
fieldset {
border: 1px solid var(--border);
border-radius: 10px;
padding: 12px;
background: var(--panel);
}
legend {
padding: 0 6px;
color: #444;
}
label { display: inline-block; margin: 2px 0; }
input[type=text], input[type=number], select {
padding: 6px;
border: 1px solid var(--border);
border-radius: 8px;
background: #fff;
}
button {
padding: 6px 10px;
margin: 2px;
border: 1px solid var(--border);
border-radius: 8px;
background: #fff;
cursor: pointer;
}
button:disabled {
opacity: 0.55;
cursor: not-allowed;
}
.row {
display: flex;
align-items: center;
gap: 8px;
flex-wrap: wrap;
}
table { border-collapse: collapse; width: 100%; background: #fff; border-radius: 10px; overflow: hidden; }
th, td { border: 1px solid #e3e3e3; padding: 8px; text-align: left; vertical-align: middle; }
th { background: #f3f3f3; }
.ok { color: var(--ok); font-weight: 700; }
.bad { color: var(--bad); font-weight: 700; }
#trace {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
background: #fff;
border: 1px solid #e3e3e3;
border-radius: 10px;
padding: 10px;
max-height: 220px;
overflow: auto;
white-space: pre;
}
#previewCanvas {
border: 1px dashed #bbb;
border-radius: 10px;
background: #fff;
max-width: 100%;
}
</style>
</head>
<body>
<header>
<h1>Distributed Mutual Exclusion Explorer (v0.3)</h1>
<span class="pill">token ring + Ricart–Agrawala · step/run · faults · JSON/PNG export</span>
</header>
<p class="note">
An interactive, browser-based simulator to visualise distributed mutual exclusion. Configure processes, issue requests for a critical section, and observe how tokens or messages enforce exclusivity. The prototype supports token loss, process crash/recovery, and basic message loss (RA).
</p>
<div class="grid">
<fieldset>
<legend>Configuration</legend>
<div class="row">
<label for="algorithmSelect">Algorithm:</label>
<select id="algorithmSelect">
<option value="TokenRing" selected>Token Ring (implemented)</option>
<option value="RA">Ricart–Agrawala (prototype)</option>
</select>
</div>
<div class="row">
<label for="procCount">Processes:</label>
<input id="procCount" type="number" min="2" max="12" value="4" />
<button id="applyConfigBtn">Apply (reset)</button>
<span class="pill" id="modePill">interactive</span>
</div>
<p class="note">Keep small numbers (3–8) for clarity. Apply resets the simulation state.</p>
</fieldset>
<fieldset>
<legend>Controls</legend>
<div class="row">
<button id="stepBtn">Step</button>
<button id="runBtn">Run</button>
<button id="pauseBtn" disabled>Pause</button>
<button id="resetBtn">Reset</button>
</div>
<div class="row">
<label for="speedMs">Run speed (ms):</label>
<input id="speedMs" type="number" min="50" max="2000" value="350" />
</div>
<div class="row">
<button id="dropTokenBtn">Drop token</button>
<button id="regenTokenBtn">Regenerate token</button>
<button id="dropNextMsgBtn">Drop next in-flight msg</button>
<button id="toggleDropNextSendBtn">Arm drop-next-send</button>
<button id="clearTraceBtn">Clear trace</button>
</div>
<div class="row">
<div>Safety: <strong id="safetyLabel">—</strong></div>
<span class="pill" id="metricsPill">—</span>
</div>
<p class="note">Token controls apply to Token Ring. For Ricart–Agrawala, “Drop next in-flight msg” removes the queue head; “drop-next-send” drops the next outgoing message.</p>
</fieldset>
</div>
<fieldset>
<legend>Processes</legend>
<table>
<thead>
<tr>
<th style="width: 120px;">Process</th>
<th>Status</th>
<th style="width: 80px;">Token</th>
<th style="width: 360px;">Actions</th>
</tr>
</thead>
<tbody id="procTable"></tbody>
</table>
<p class="note">Status shows whether a process is requesting access or is currently in the critical section.</p>
</fieldset>
<fieldset>
<legend>Network (messages)</legend>
<table>
<thead>
<tr>
<th style="width: 70px;">ID</th>
<th style="width: 90px;">Type</th>
<th style="width: 120px;">From</th>
<th style="width: 120px;">To</th>
<th style="width: 90px;">TS</th>
</tr>
</thead>
<tbody id="msgTable"></tbody>
</table>
<p class="note">For Ricart–Agrawala, each Step typically delivers one message from the queue.</p>
</fieldset>
<fieldset>
<legend>Scenarios</legend>
<div class="row">
<button id="exportBtn">Export JSON (state)</button>
<button id="exportTraceBtn">Export trace (txt)</button>
<button id="exportAllBtn">Export evidence (JSON+trace+PNG)</button>
<input id="importFile" type="file" accept="application/json" />
<button id="loadExampleInteractiveBtn">Load example (interactive)</button>
<button id="loadExampleScriptBtn">Load example (scripted)</button>
<button id="loadCrashDemoBtn">Load crash demo (scripted)</button>
<button id="loadRaDemoBtn">Load RA conflict demo (scripted)</button>
<button id="loadRaTieDemoBtn">Load RA tiebreak demo (scripted)</button>
<button id="exitScriptBtn" disabled>Exit script mode</button>
</div>
<p class="note">Interactive mode lets you issue requests manually. Scripted mode replays a predefined event sequence from a JSON scenario file. Exports use a session timestamp + snapshot counter for easier evidence management.</p>
</fieldset>
<fieldset>
<legend>Trace</legend>
<div id="trace">—</div>
</fieldset>
<fieldset>
<legend>Preview & Export PNG</legend>
<div class="row">
<button id="redrawBtn">Redraw</button>
<button id="exportPngBtn">Export PNG</button>
</div>
<canvas id="previewCanvas" width="900" height="520"></canvas>
<p class="note">The preview uses a circular layout. Token Ring shows token position; RA highlights the next message to be delivered.</p>
</fieldset>
<script type="module" src="./mutex_main.js"></script>
</body>
</html>