Skip to content

Commit 0e3448b

Browse files
committed
workflow: add traceroute workflow
1 parent 113744d commit 0e3448b

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

statics/workflows/traceroute.yaml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
UUID: "9b598b28-b52e-488f-7b1c-402ac07e59b5"
2+
Name: "Traceroute"
3+
Description: "Traceroute"
4+
Parameters:
5+
- Name: protocol
6+
Description: Protocol
7+
Type: choice
8+
Default: icmp4
9+
Values:
10+
- Description: "Protocol : ICMPv4/Echo request"
11+
Value: icmp4
12+
- Description: "Protocol : TCP/IPv4"
13+
Value: tcp4
14+
- Name: source
15+
Description: Source Node
16+
Type: node
17+
- Name: destination
18+
Description: Destination Node
19+
Type: node
20+
Source: |
21+
function Traceroute(protocol, src, dst) {
22+
var sources = [];
23+
var result = {};
24+
var pktform = {};
25+
var G = client.gremlin.G()
26+
G.V().Has('TID', src).ShortestPathTo(Metadata('TID', dst)).then(function(nodes) {
27+
for (var i in nodes) {
28+
if (nodes[0][i].Metadata && nodes[0][i].Metadata.IPV4 && nodes[0][i].Metadata.MAC != null) {
29+
sources.push(nodes[0][i].Metadata);
30+
}else {
31+
if ((nodes[0][i].Metadata && nodes[0][i].Metadata.Neutron && nodes[0][i].Metadata.Neutron.IPV4 != null) && (nodes[0][i].Metadata && nodes[0][i].Metadata.ExtID && nodes[0][i].Metadata.ExtID["attached-mac"] != null)) {
32+
sources.push(nodes[0][i].Metadata);
33+
}
34+
}
35+
}
36+
})
37+
var capture = new Capture();
38+
capture.GremlinQuery = "G.V().Has('TID', '" + src + "')";
39+
return client.captures.create(capture).then(function (c) {
40+
capture = c
41+
}).then(function () {
42+
return sleep(1000)
43+
}).then(function () {
44+
for (i=0; i+1<sources.length; i++) {
45+
var packetInjection = new PacketInjection();
46+
packetInjection.Src = "G.V().Has('TID', '" + sources[i].TID + "')"
47+
packetInjection.Dst = "G.V().Has('TID', '" + sources[i+1].TID + "')"
48+
packetInjection.Count = 3
49+
if (sources[i].Neutron && sources[i].Neutron.IPV4) {
50+
packetInjection.SrcIP = sources[i].Neutron.IPV4[0]
51+
}
52+
if (sources[i].ExtID && sources[i].ExtID["attached-mac"]) {
53+
packetInjection.SrcMAC = sources[i].ExtID["attached-mac"]
54+
}
55+
if (protocol == "icmp4") {
56+
packetInjection.Type = protocol;
57+
packetInjection.ICMPID = Math.floor(Math.random() * 65535);
58+
}
59+
if (protocol == "tcp4" || protocol == "udp4") {
60+
packetInjection.Type = protocol;
61+
packetInjection.SrcPort = 1024 + Math.floor(Math.random() * (65535-1024));
62+
packetInjection.DstPort = 1024 + Math.floor(Math.random() * (65535-1024));
63+
}
64+
if (sources[i+1].Neutron && sources[i+1].Neutron.IPV4) {
65+
packetInjection.DstIP = sources[i+1].Neutron.IPV4[0]
66+
}
67+
if (sources[i+1].ExtID && sources[i+1].ExtID["attached-mac"]) {
68+
packetInjection.DstMAC = sources[i+1].ExtID["attached-mac"]
69+
} else {
70+
packetInjection.SrcIP = sources[i].IPV4[0]
71+
packetInjection.DstIP = sources[i+1].IPV4[0]
72+
}
73+
pktform[sources[i+1].TID] = packetInjection;
74+
pktform[sources[i+1].TID].DstIP = pktform[sources[i+1].TID].DstIP.split("/")[0]
75+
pktform[sources[i+1].TID].SrcIP = pktform[sources[i+1].TID].SrcIP.split("/")[0]
76+
client.packetInjections.create(packetInjection)
77+
}
78+
}).then(function () {
79+
return sleep(1000)
80+
}).then(function () {
81+
for (i=0; i+1<sources.length; i++) {
82+
result[pktform[sources[i+1].TID].SrcIP + "- To -" + pktform[sources[i+1].TID].DstIP] = {"Connected" : false};
83+
if (protocol == "icmp4") {
84+
client.G.Flows().Has("ICMP.ID", pktform[sources[i+1].TID].ICMPID, "Network.A", pktform[sources[i+1].TID].SrcIP, "Network.B", pktform[sources[i+1].TID].DstIP).then(function(flows) {
85+
if (flows.length > 0 && flows[0].Metric.ABPackets > 0 && flows[0].Metric.BAPackets > 0) {
86+
result[flows[0].Network.A + "- To -" + flows[0].Network.B] = {"Connected" : true, "RTT" : (flows[0].RTT / 1000000).toFixed(3) + " ms" };
87+
}
88+
return result
89+
})
90+
} else {
91+
client.G.Flows().Has("Transport.A", pktform[sources[i+1].TID].SrcPort, "Transport.B", pktform[sources[i+1].TID].DstPort, "Transport.Protocol", "TCP", "Network.A", pktform[sources[i+1].TID].SrcIP, "Network.B", pktform[sources[i+1].TID].DstIP).then(function(flows) {
92+
if (flows.length > 0 && flows[0].Metric.ABPackets > 0 && flows[0].Metric.BAPackets > 0) {
93+
result[flows[0].Network.A + "- To -" + flows[0].Network.B] = {"Connected" : true, "RTT" : (flows[0].RTT / 1000000).toFixed(3) + " ms" };
94+
}
95+
return result
96+
})
97+
}
98+
}
99+
return result
100+
}).then(function () {
101+
return {
102+
"Trace Route" : sources[0].IPV4[0] + "- To -" + sources[sources.length - 1].IPV4[0],
103+
"Path" : result
104+
}
105+
}).finally(function () {
106+
return client.captures.delete(capture.UUID)
107+
}).catch(function () {
108+
return client.captures.delete(capture.UUID)
109+
});
110+
}

0 commit comments

Comments
 (0)