Skip to content

Commit f29bfcc

Browse files
committed
Topology, cleanup
1 parent 864f3b4 commit f29bfcc

File tree

1 file changed

+5
-23
lines changed

1 file changed

+5
-23
lines changed

Protest/Tools/Topology.cs

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ internal static async Task WebSocketHandler(HttpListenerContext ctx) {
145145
if (options.Contains("vlan")) {
146146
IList<Variable> dot1q = Polling.SnmpQuery(ipAddress, snmpProfile, Oid.TOPOLOGY_DOT1Q, Polling.SnmpOperation.Walk);
147147
if (dot1q is not null && dot1q.Count > 0) {
148-
byte[] response = ComputeDotQ1Response(candidate.filename, dot1q);
148+
byte[] response = ComputeDot1QResponse(candidate.filename, dot1q);
149149
await wsWriteSemaphore.WaitAsync();
150150
try {
151151
await WebSocketHelper.WsWriteText(ws, response);
@@ -426,7 +426,7 @@ private static char ToHex(int value) {
426426
return (char)(value < 10 ? '0' + value : 'a' + (value - 10));
427427
}
428428

429-
private static byte[] ComputeDotQ1Response(string file, IList<Variable> dot1q) {
429+
private static byte[] ComputeDot1QResponse(string file, IList<Variable> dot1q) {
430430
Dictionary<int, string> names = new Dictionary<int, string>();
431431
Dictionary<int, string> egress = new Dictionary<int, string>();
432432
Dictionary<int, string> untagged = new Dictionary<int, string>();
@@ -444,7 +444,7 @@ private static byte[] ComputeDotQ1Response(string file, IList<Variable> dot1q) {
444444
int startIndex = GetPortBitmapStart(raw);
445445
if (startIndex == -1) continue;
446446

447-
int maxIndex = Math.Min(raw.Length, startIndex + Topology.GetPortBitmapLength(raw, startIndex));
447+
int maxIndex = Math.Min(raw.Length, startIndex + GetPortBitmapLength(raw, startIndex));
448448

449449
for (int j = maxIndex - 1; j >= 1; j--) {
450450
if (raw[j] != 0) break;
@@ -596,16 +596,7 @@ private static string GetChassisId(string subtype, ISnmpData value) {
596596
return $"{bytes[3]}.{bytes[4]}.{bytes[5]}.{bytes[6]}";
597597
}
598598
else if (bytes.Length - 3 == 16) {
599-
return $"""
600-
{bytes[3].ToString("x2")}{bytes[4].ToString("x2")}:
601-
{bytes[5].ToString("x2")}{bytes[6].ToString("x2")}:
602-
{bytes[7].ToString("x2")}{bytes[8].ToString("x2")}:
603-
{bytes[9].ToString("x2")}{bytes[10].ToString("x2")}:
604-
{bytes[11].ToString("x2")}{bytes[12].ToString("x2")}:
605-
{bytes[13].ToString("x2")}{bytes[14].ToString("x2")}:
606-
{bytes[15].ToString("x2")}{bytes[16].ToString("x2")}:
607-
{bytes[17].ToString("x2")}{bytes[18].ToString("x2")}
608-
""";
599+
return $"{bytes[3].ToString("x2")}{bytes[4].ToString("x2")}:{bytes[5].ToString("x2")}{bytes[6].ToString("x2")}:{bytes[7].ToString("x2")}{bytes[8].ToString("x2")}:{bytes[9].ToString("x2")}{bytes[10].ToString("x2")}:{bytes[11].ToString("x2")}{bytes[12].ToString("x2")}:{bytes[13].ToString("x2")}{bytes[14].ToString("x2")}:{bytes[15].ToString("x2")}{bytes[16].ToString("x2")}:{bytes[17].ToString("x2")}{bytes[18].ToString("x2")}";
609600
}
610601
return value.ToString();
611602

@@ -628,16 +619,7 @@ private static string GetPortId(string subtype, ISnmpData value) {
628619
return $"{bytes[3]}.{bytes[4]}.{bytes[5]}.{bytes[6]}";
629620
}
630621
else if (bytes.Length - 3 == 16) {
631-
return $"""
632-
{bytes[3].ToString("x2")}{bytes[4].ToString("x2")}:
633-
{bytes[5].ToString("x2")}{bytes[6].ToString("x2")}:
634-
{bytes[7].ToString("x2")}{bytes[8].ToString("x2")}:
635-
{bytes[9].ToString("x2")}{bytes[10].ToString("x2")}:
636-
{bytes[11].ToString("x2")}{bytes[12].ToString("x2")}:
637-
{bytes[13].ToString("x2")}{bytes[14].ToString("x2")}:
638-
{bytes[15].ToString("x2")}{bytes[16].ToString("x2")}:
639-
{bytes[17].ToString("x2")}{bytes[18].ToString("x2")}
640-
""";
622+
return $"{bytes[3].ToString("x2")}{bytes[4].ToString("x2")}:{bytes[5].ToString("x2")}{bytes[6].ToString("x2")}:{bytes[7].ToString("x2")}{bytes[8].ToString("x2")}:{bytes[9].ToString("x2")}{bytes[10].ToString("x2")}:{bytes[11].ToString("x2")}{bytes[12].ToString("x2")}:{bytes[13].ToString("x2")}{bytes[14].ToString("x2")}:{bytes[15].ToString("x2")}{bytes[16].ToString("x2")}:{bytes[17].ToString("x2")}{bytes[18].ToString("x2")}";
641623
}
642624
return value.ToString();
643625

0 commit comments

Comments
 (0)