Skip to content

Commit 5eb7c66

Browse files
committed
Topology, SNMP
1 parent 233f119 commit 5eb7c66

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

Protest/Front/topology.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
.topology-selected > rect:first-child {
3232
fill: color-mix(in srgb, var(--clr-select) 60%, transparent 40%);
33+
stroke: var(--clr-select);
34+
stroke-width: 2px;
3335
}
3436

3537
.topology-loading {

Protest/Front/topology.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ class Topology extends Window {
7474

7575
this.dragging.element.x = x;
7676
this.dragging.element.y = y;
77+
78+
this.AdjustSvgSize();
7779
};
7880

7981
this.content.onmouseup = ()=> {
@@ -84,6 +86,10 @@ class Topology extends Window {
8486
this.stopButton.onclick = ()=> this.Stop();
8587
}
8688

89+
AfterResize() { //override
90+
this.AdjustSvgSize();
91+
}
92+
8793
InitializeSvg() {
8894
this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
8995
this.svg.setAttribute("width", 1);
@@ -103,7 +109,7 @@ class Topology extends Window {
103109

104110
const loadingStop1 = document.createElementNS("http://www.w3.org/2000/svg", "stop");
105111
loadingStop1.setAttribute("offset", ".15");
106-
loadingStop1.setAttribute("stop-color", "#c0c0c080");
112+
loadingStop1.setAttribute("stop-color", "#c0c0c060");
107113
loadGradient.appendChild(loadingStop1);
108114

109115
const loadingStop2 = document.createElementNS("http://www.w3.org/2000/svg", "stop");
@@ -118,7 +124,7 @@ class Topology extends Window {
118124

119125
const loadingStop4 = document.createElementNS("http://www.w3.org/2000/svg", "stop");
120126
loadingStop4.setAttribute("offset", ".85");
121-
loadingStop4.setAttribute("stop-color", "#c0c0c080");
127+
loadingStop4.setAttribute("stop-color", "#c0c0c060");
122128
loadGradient.appendChild(loadingStop4);
123129

124130
const animateTransform = document.createElementNS("http://www.w3.org/2000/svg", "animateTransform");
@@ -386,7 +392,7 @@ class Topology extends Window {
386392

387393
const label = document.createElementNS("http://www.w3.org/2000/svg", "text");
388394
label.innerHTML = options.name;
389-
label.setAttribute("y", 104);
395+
label.setAttribute("y", 106);
390396
label.setAttribute("x", 48);
391397
label.setAttribute("font-size", "11");
392398
label.setAttribute("font-weight", "600");
@@ -408,8 +414,7 @@ class Topology extends Window {
408414
this.SelectDevice(options.file);
409415
});
410416

411-
this.svg.setAttribute("width", Math.max(this.workspace.offsetWidth, options.x + 150));
412-
this.svg.setAttribute("height", Math.max(this.workspace.offsetHeight, options.y + 150));
417+
this.AdjustSvgSize();
413418

414419
return {
415420
root: g,
@@ -458,4 +463,15 @@ class Topology extends Window {
458463
ipLabel.textContent = initial.ip;
459464
grid.appendChild(ipLabel);
460465
}
466+
467+
AdjustSvgSize() {
468+
let maxX = this.workspace.offsetWidth, maxY = this.workspace.offsetHeight;
469+
for (const file in this.devices) {
470+
if (this.devices[file].element.x + 100 > maxX) maxX = this.devices[file].element.x + 100;
471+
if (this.devices[file].element.y + 128 > maxY) maxY = this.devices[file].element.y + 128;
472+
}
473+
474+
this.svg.setAttribute("width", maxX === this.workspace.offsetWidth ? Math.max(maxX - 20, 1) : maxX);
475+
this.svg.setAttribute("height", maxY === this.workspace.offsetHeight ? Math.max(maxY - 20, 1) : maxY);
476+
}
461477
}

Protest/Tools/Topology.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,14 @@ private static byte[] ComputeSnmpResponse(string file, Dictionary<string, string
166166
}
167167
}
168168

169-
//TODO:
170-
return System.Text.Encoding.UTF8.GetBytes($"{{\"snmp\":\"{file}\"}}");
169+
byte[] payload = JsonSerializer.SerializeToUtf8Bytes(new {
170+
switchInfo = new {
171+
localPortIdSuptype = localPortIdSuptype,
172+
localPortId = localPortId
173+
}
174+
});
175+
176+
return payload;
171177
}
172178

173179
}

0 commit comments

Comments
 (0)