Skip to content

Commit

Permalink
workflow: add traceroute workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
dvandra committed Feb 15, 2019
1 parent b22dedb commit 2162ab2
Showing 1 changed file with 110 additions and 0 deletions.
110 changes: 110 additions & 0 deletions statics/workflows/traceroute.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
UUID: "9b598b28-b52e-488f-7b1c-402ac07e59b5"
name: "Traceroute"
description: "Traceroute"
parameters:
- name: protocol
description: Protocol
type: choice
default: icmp4
values:
- description: "Protocol : ICMPv4/Echo request"
value: icmp4
- description: "Protocol : TCP/IPv4"
value: tcp4
- name: source
description: Source Node
type: node
- name: destination
description: Destination Node
type: node
source: |
function Traceroute(protocol, from, to) {
var sources = [];
var result = {};
var From = {};
var G = client.gremlin.G()
G.V().Has('TID', from).ShortestPathTo(Metadata('TID', to)).then(function(nodes) {
for (var i in nodes) {
if (nodes[0][i].Metadata && nodes[0][i].Metadata.IPV4 && nodes[0][i].Metadata.MAC != null) {
sources.push(nodes[0][i].Metadata);
}else {
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)) {
sources.push(nodes[0][i].Metadata);
}
}
}
})
var capture = new Capture();
capture.GremlinQuery = "G.V().Has('TID', '" + from + "')";
var packetInjection = new PacketInjection();
return client.captures.create(capture).then(function (c) {
capture = c
}).then(function () {
return sleep(1000)
}).then(function () {
for (i=0, j=1; i+1<sources.length, j<sources.length; i++, j++) {
packetInjection.Src = "G.V().Has('TID', '" + sources[i].TID + "')"
packetInjection.Dst = "G.V().Has('TID', '" + sources[j].TID + "')"
packetInjection.Count = 3
if (sources[i].Neutron && sources[i].Neutron.IPV4) {
packetInjection.SrcIP = sources[i].Neutron.IPV4[0]
}
if (sources[i].ExtID && sources[i].ExtID["attached-mac"]) {
packetInjection.SrcMAC = sources[i].ExtID["attached-mac"]
}
if (protocol == "icmp4") {
packetInjection.Type = protocol;
packetInjection.ICMPID = Math.floor(Math.random() * 65535);
}
if (protocol == "tcp4" || protocol == "udp4") {
packetInjection.Type = protocol;
packetInjection.SrcPort = 1024 + Math.floor(Math.random() * (65535-1024));
packetInjection.DstPort = 1024 + Math.floor(Math.random() * (65535-1024));
}
if (sources[j].Neutron && sources[j].Neutron.IPV4) {
packetInjection.DstIP = sources[j].Neutron.IPV4[0]
}
if (sources[j].ExtID && sources[j].ExtID["attached-mac"]) {
packetInjection.DstMAC = sources[j].ExtID["attached-mac"]
} else {
packetInjection.SrcIP = sources[i].IPV4[0]
packetInjection.DstIP = sources[j].IPV4[0]
}
From[sources[j].TID] = packetInjection;
From[sources[j].TID].DstIP = From[sources[j].TID].DstIP.split("/")[0]
From[sources[j].TID].SrcIP = From[sources[j].TID].SrcIP.split("/")[0]
client.packetInjections.create(packetInjection)
}
}).then(function () {
return sleep(1000)
}).then(function () {
for (i=0, j=1; i+1<sources.length, j<sources.length; i++, j++) {
result[From[sources[j].TID].SrcIP + " -- " + From[sources[j].TID].DstIP] = {"Connected" : false};
if (protocol == "icmp4") {
client.G.Flows().Has("ICMP.ID", From[sources[j].TID].ICMPID, "Network.A", From[sources[j].TID].SrcIP, "Network.B", From[sources[j].TID].DstIP).then(function(flows) {
if (flows.length > 0 && flows[0].Metric.ABPackets > 0 && flows[0].Metric.BAPackets > 0) {
result[flows[0].Network.A + " -- " + flows[0].Network.B] = {"Connected" : true, "RTT" : (flows[0].RTT / 1000000).toFixed(3) + " ms" };
}
return result
})
} else {
client.G.Flows().Has("Transport.A", From[sources[j].TID].SrcPort, "Transport.B", From[sources[j].TID].DstPort, "Transport.Protocol", "TCP", "Network.A", From[sources[j].TID].SrcIP, "Network.B", From[sources[j].TID].DstIP).then(function(flows) {
if (flows.length > 0 && flows[0].Metric.ABPackets > 0 && flows[0].Metric.BAPackets > 0) {
result[flows[0].Network.A + " -- " + flows[0].Network.B] = {"Connected" : true, "RTT" : (flows[0].RTT / 1000000).toFixed(3) + " ms" };
}
return result
})
}
}
return result
}).then(function () {
return {
"Trace Route" : sources[0].IPV4[0] + " To " + sources[sources.length - 1].IPV4[0],
"Path" : result
}
}).finally(function () {
return client.captures.delete(capture.UUID)
}).catch(function () {
return client.captures.delete(capture.UUID)
});
}

0 comments on commit 2162ab2

Please sign in to comment.