Skip to content

Commit

Permalink
Edit command output parsing for IPv6 + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Valéria Frčková committed May 14, 2024
1 parent c0fb598 commit 2d06c2c
Show file tree
Hide file tree
Showing 13 changed files with 713 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/command/traceroute-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { isIpPrivate } from '../lib/private-ip.js';
import { scopedLogger } from '../lib/logger.js';
import { InvalidOptionsException } from './exception/invalid-options-exception.js';

export const NEW_LINE_REG_EXP = /\r?\n/;
const reHost = /(\S+)\s+\((?:((?:\d+\.){3}\d+)|([\da-fA-F:]+(?:::)?[\da-fA-F:]+))\)/; // /(\S+)\s+\((?:((?:\d+\.){3}\d+)|([\da-fA-F:]))\)/;
const reRtt = /(\d+(?:\.?\d+)?)\s+ms(!\S*)?/g;

Expand Down Expand Up @@ -231,7 +230,7 @@ export class TracerouteCommand implements CommandInterface<TraceOptions> {

return {
host: hostMatch[0] ?? '',
resolvedAddress: hostMatch[2],
resolvedAddress: hostMatch[2] !== undefined ? hostMatch[2] : (hostMatch.length >= 3 ? hostMatch[3] : ''),
};
}

Expand All @@ -241,7 +240,7 @@ export class TracerouteCommand implements CommandInterface<TraceOptions> {

return {
resolvedHostname: hostMatch?.[1] ?? '*',
resolvedAddress: hostMatch?.[2] ?? '*',
resolvedAddress: hostMatch?.[2] !== undefined ? hostMatch?.[2] : (hostMatch && hostMatch.length >= 3 ? (hostMatch?.[3] ?? '*') : '*'),
timings: rttList.map(rtt => ({ rtt })),
};
}
Expand Down
23 changes: 23 additions & 0 deletions test/mocks/ipv6-dns-success-ip.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"measurementId": "measurement",
"result": {
"answers": [
{
"class": "IN",
"name": "e.0.0.2.0.0.0.0.0.0.0.0.0.0.0.0.2.0.8.0.6.2.0.4.0.5.4.1.0.0.a.2.ip6.arpa.",
"ttl": 85385,
"type": "PTR",
"value": "hem09s02-in-x0e.1e100.net."
}
],
"rawOutput": "; <<>> DiG 9.18.18-0ubuntu0.22.04.2-Ubuntu <<>> -x 2a00:1450:4026:802::200e @2606:4700:4700::1111 -p 53 -6 +timeout=3 +tries=2 +nocookie +nosplit +nsid\n;; global options: +cmd\n;; Got answer:\n;;->>HEADER<<- opcode: QUERY, status: NOERROR, id: 47787\n;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1\n\n;; OPT PSEUDOSECTION:\n; EDNS: version: 0, flags:; udp: 1232\n; NSID: 37 39 6d 32 31 37 (\"79m217\")\n;; QUESTION SECTION:\n;e.0.0.2.0.0.0.0.0.0.0.0.0.0.0.0.2.0.8.0.6.2.0.4.0.5.4.1.0.0.a.2.ip6.arpa. IN PTR\n\n;; ANSWER SECTION:\ne.0.0.2.0.0.0.0.0.0.0.0.0.0.0.0.2.0.8.0.6.2.0.4.0.5.4.1.0.0.a.2.ip6.arpa. 85385 IN PTR hem09s02-in-x0e.1e100.net.\n\n;; Query time: 0 msec\n;; SERVER: 2606:4700:4700::1111#53(2606:4700:4700::1111) (UDP)\n;; WHEN: Tue May 14 17:36:02 UTC 2024\n;; MSG SIZE rcvd: 150\n",
"resolver": "UDP",
"status": "finished",
"statusCode": 0,
"statusCodeName": "NOERROR",
"timings": {
"total": 0
}
},
"testId": "test"
}
19 changes: 19 additions & 0 deletions test/mocks/ipv6-dns-success-ip.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
; <<>> DiG 9.18.18-0ubuntu0.22.04.2-Ubuntu <<>> -x 2a00:1450:4026:802::200e @2606:4700:4700::1111 -p 53 -6 +timeout=3 +tries=2 +nocookie +nosplit +nsid
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 47787
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
; NSID: 37 39 6d 32 31 37 ("79m217")
;; QUESTION SECTION:
;e.0.0.2.0.0.0.0.0.0.0.0.0.0.0.0.2.0.8.0.6.2.0.4.0.5.4.1.0.0.a.2.ip6.arpa. IN PTR

;; ANSWER SECTION:
e.0.0.2.0.0.0.0.0.0.0.0.0.0.0.0.2.0.8.0.6.2.0.4.0.5.4.1.0.0.a.2.ip6.arpa. 85385 IN PTR hem09s02-in-x0e.1e100.net.

;; Query time: 0 msec
;; SERVER: 2606:4700:4700::1111#53(2606:4700:4700::1111) (UDP)
;; WHEN: Tue May 14 17:36:02 UTC 2024
;; MSG SIZE rcvd: 150
2 changes: 1 addition & 1 deletion test/mocks/ipv6-dns-success.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"status": "finished",
"statusCodeName": "NOERROR",
"statusCode": 0,
"rawOutput": "; <<>> DiG 9.18.18-0ubuntu0.22.04.2-Ubuntu <<>> -t A google.com @2606:4700:4700::1111 -p 53 -6 +timeout=3 +tries=2 +nocookie +nosplit +nsid\r\n;; global options: +cmd\r\n;; Got answer:\r\n;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 47976\r\n;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1\r\n\r\n;; OPT PSEUDOSECTION:\r\n; EDNS: version: 0, flags:; udp: 1232\r\n; NSID: 37 39 6d 31 37 30 (\"79m170\")\r\n;; QUESTION SECTION:\r\n;google.com.\t\t\tIN\tA\r\n\r\n;; ANSWER SECTION:\r\ngoogle.com.\t\t112\tIN\tA\t216.58.211.238\r\n\r\n;; Query time: 0 msec\r\n;; SERVER: 2606:4700:4700::1111#53(2606:4700:4700::1111) (UDP)\r\n;; WHEN: Tue May 14 00:09:08 UTC 2024\r\n;; MSG SIZE rcvd: 65\r\n",
"rawOutput": "; <<>> DiG 9.18.18-0ubuntu0.22.04.2-Ubuntu <<>> -t A google.com @2606:4700:4700::1111 -p 53 -6 +timeout=3 +tries=2 +nocookie +nosplit +nsid\n;; global options: +cmd\n;; Got answer:\n;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 47976\n;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1\n\n;; OPT PSEUDOSECTION:\n; EDNS: version: 0, flags:; udp: 1232\n; NSID: 37 39 6d 31 37 30 (\"79m170\")\n;; QUESTION SECTION:\n;google.com.\t\t\tIN\tA\n\n;; ANSWER SECTION:\ngoogle.com.\t\t112\tIN\tA\t216.58.211.238\n\n;; Query time: 0 msec\n;; SERVER: 2606:4700:4700::1111#53(2606:4700:4700::1111) (UDP)\n;; WHEN: Tue May 14 00:09:08 UTC 2024\n;; MSG SIZE rcvd: 65\n",
"answers": [
{
"name": "google.com.",
Expand Down
317 changes: 317 additions & 0 deletions test/mocks/ipv6-mtr-success-ip.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,317 @@
{
"measurementId": "measurement",
"result": {
"hops": [
{
"asn": [],
"resolvedAddress": "fe80::",
"resolvedHostname": null,
"stats": {
"avg": 4.7,
"drop": 0,
"jAvg": 3,
"jMax": 5,
"jMin": 1,
"loss": 0,
"max": 5.156,
"min": 4.109,
"rcv": 3,
"stDev": 0.5,
"total": 3
},
"timings": [
{
"rtt": 5.156
},
{
"rtt": 4.109
},
{
"rtt": 4.967
}
]
},
{
"asn": [
123
],
"resolvedAddress": "2a01:4f9:0:c001::1536",
"resolvedHostname": "10942.your-cloud.host",
"stats": {
"avg": 0.7,
"drop": 0,
"jAvg": 0.7,
"jMax": 0.8,
"jMin": 0.6,
"loss": 0,
"max": 1.173,
"min": 0.401,
"rcv": 3,
"stDev": 0.3,
"total": 3
},
"timings": [
{
"rtt": 1.173
},
{
"rtt": 0.401
},
{
"rtt": 0.578
}
]
},
{
"asn": [
123
],
"resolvedAddress": "2a01:4f9:0:c001::1501",
"resolvedHostname": "2a01:4f9:0:c001::1501",
"stats": {
"avg": 16.4,
"drop": 0,
"jAvg": 13.3,
"jMax": 17.2,
"jMin": 9.4,
"loss": 0,
"max": 20.648,
"min": 11.273,
"rcv": 3,
"stDev": 3.9,
"total": 3
},
"timings": [
{
"rtt": 11.273
},
{
"rtt": 20.648
},
{
"rtt": 17.218
}
]
},
{
"asn": [
123
],
"resolvedAddress": "2a01:4f9:0:c001::a039",
"resolvedHostname": "2a01:4f9:0:c001::a039",
"stats": {
"avg": 1.3,
"drop": 0,
"jAvg": 0.8,
"jMax": 1.5,
"jMin": 0.2,
"loss": 0,
"max": 1.491,
"min": 1.115,
"rcv": 3,
"stDev": 0.2,
"total": 3
},
"timings": [
{
"rtt": 1.115
},
{
"rtt": 1.268
},
{
"rtt": 1.491
}
]
},
{
"asn": [
123
],
"resolvedAddress": "2a01:4f8:0:3::6d1",
"resolvedHostname": "spine15.cloud1.hel1.hetzner.com",
"stats": {
"avg": 0.6,
"drop": 0,
"jAvg": 0.4,
"jMax": 0.6,
"jMin": 0.1,
"loss": 0,
"max": 0.757,
"min": 0.582,
"rcv": 3,
"stDev": 0.1,
"total": 3
},
"timings": [
{
"rtt": 0.757
},
{
"rtt": 0.609
},
{
"rtt": 0.582
}
]
},
{
"asn": [
123
],
"resolvedAddress": "2a01:4f8:0:3::6b9",
"resolvedHostname": "core31.hel1.hetzner.com",
"stats": {
"avg": 0.7,
"drop": 0,
"jAvg": 0.4,
"jMax": 0.7,
"jMin": 0.2,
"loss": 0,
"max": 0.828,
"min": 0.66,
"rcv": 3,
"stDev": 0.1,
"total": 3
},
"timings": [
{
"rtt": 0.828
},
{
"rtt": 0.66
},
{
"rtt": 0.708
}
]
},
{
"asn": [
123
],
"resolvedAddress": "2a01:4f8:0:3::2b9",
"resolvedHostname": "juniper4.dc1.hel1.hetzner.com",
"stats": {
"avg": 0.9,
"drop": 0,
"jAvg": 0.7,
"jMax": 0.9,
"jMin": 0.5,
"loss": 0,
"max": 1.122,
"min": 0.655,
"rcv": 3,
"stDev": 0.2,
"total": 3
},
"timings": [
{
"rtt": 1.122
},
{
"rtt": 0.655
},
{
"rtt": 0.871
}
]
},
{
"asn": [
123
],
"resolvedAddress": "2001:4860:1:1::3212",
"resolvedHostname": "2001:4860:1:1::3212",
"stats": {
"avg": 1.8,
"drop": 0,
"jAvg": 0.9,
"jMax": 1.7,
"jMin": 0.1,
"loss": 0,
"max": 1.92,
"min": 1.704,
"rcv": 3,
"stDev": 0.1,
"total": 3
},
"timings": [
{
"rtt": 1.92
},
{
"rtt": 1.774
},
{
"rtt": 1.704
}
]
},
{
"asn": [
123
],
"resolvedAddress": "2a00:1450:80d2::1",
"resolvedHostname": "2a00:1450:80d2::1",
"stats": {
"avg": 1.3,
"drop": 0,
"jAvg": 0.8,
"jMax": 1.2,
"jMin": 0.3,
"loss": 0,
"max": 1.478,
"min": 1.195,
"rcv": 3,
"stDev": 0.1,
"total": 3
},
"timings": [
{
"rtt": 1.478
},
{
"rtt": 1.195
},
{
"rtt": 1.245
}
]
},
{
"asn": [
123
],
"resolvedAddress": "2a00:1450:4026:808::200f",
"resolvedHostname": "hem08s10-in-x0f.1e100.net",
"stats": {
"avg": 1.3,
"drop": 1,
"jAvg": 0.5,
"jMax": 0.5,
"jMin": 0.5,
"loss": 33.3,
"max": 1.562,
"min": 1.103,
"rcv": 2,
"stDev": 0.2,
"total": 3
},
"timings": [
{
"rtt": 1.562
},
{
"rtt": 1.103
}
]
}
],
"rawOutput": "Host Loss% Drop Rcv Avg StDev Javg \n 1. AS??? _gateway (fe80::) 0.0% 0 3 4.7 0.53.0\n 2. AS123 10942.your-cloud.host (2a01:4f9:0:c001::1536) 0.0% 0 3 0.7 0.3 0.7\n 3. AS123 2a01:4f9:0:c001::1501 (2a01:4f9:0:c001::1501) 0.0% 0 3 16.4 3.9 13.3\n 4. AS123 2a01:4f9:0:c001::a039 (2a01:4f9:0:c001::a039) 0.0% 0 3 1.3 0.2 0.8\n 5. AS123 spine15.cloud1.hel1.hetzner.com (2a01:4f8:0:3::6d1) 0.0% 0 3 0.6 0.1 0.4\n 6. AS123 core31.hel1.hetzner.com (2a01:4f8:0:3::6b9) 0.0% 0 3 0.7 0.1 0.4\n 7. AS123 juniper4.dc1.hel1.hetzner.com (2a01:4f8:0:3::2b9) 0.0% 0 3 0.9 0.2 0.7\n 8. AS123 2001:4860:1:1::3212 (2001:4860:1:1::3212)0.0% 0 3 1.8 0.1 0.9\n 9. AS123 2a00:1450:80d2::1 (2a00:1450:80d2::1) 0.0% 0 3 1.3 0.1 0.8\n10. AS123 hem08s10-in-x0f.1e100.net (2a00:1450:4026:808::200f) 33.3% 1 2 1.3 0.2 0.5\n",
"resolvedAddress": "2a00:1450:4026:808::200f",
"resolvedHostname": "hem08s10-in-x0f.1e100.net",
"status": "finished"
},
"testId": "test"
}
Loading

0 comments on commit 2d06c2c

Please sign in to comment.