-
-
Notifications
You must be signed in to change notification settings - Fork 400
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
--- | ||
UUID: "784c3329-0f47-449b-5c58-2d207bcfb501" | ||
name: "Ping Mesh (ICMP/TCP/UDP)" | ||
description: "Check Connectivity from Multiple Source to Single Destination" | ||
parameters: | ||
- name: protocol | ||
description: Protocol | ||
type: choice | ||
default: icmp4 | ||
values: | ||
- description: "Protocol : ICMPv4/Echo request" | ||
value: icmp4 | ||
- description: "Protocol : TCP/IPv4" | ||
value: tcp4 | ||
- description: "Protocol : UDP/IPv4" | ||
value: udp4 | ||
- name: source | ||
description: Source Nodes (Enter a Gremlin Query to select Source Nodes) | ||
type: string | ||
- name: destination | ||
description: Destination Node (Select Destination Node) | ||
type: node | ||
source: | | ||
function PingMesh(protocol, source, to) { | ||
var sources = []; | ||
var result = {}; | ||
var From = {}; | ||
var query = source.slice(2,) | ||
client.gremlin.query(source).then(function(nodes) { | ||
nodes.forEach(function(node) { | ||
sources.push(node.Metadata.TID); | ||
}); | ||
}) | ||
var capture = new Capture(); | ||
capture.GremlinQuery = "G.V().Has('TID', '" + to + "')"; | ||
var packetInjection = new PacketInjection(); | ||
return client.captures.create(capture).then(function (c) { | ||
capture = c | ||
}).then(function () { | ||
return sleep(1000) | ||
}).then(function () { | ||
sources.forEach(function(s) { | ||
packetInjection.Src = "G.V().Has('TID', '" + s + "')" | ||
packetInjection.Dst = "G.V().Has('TID', '" + to + "')" | ||
packetInjection.Count = 5 | ||
return client.G.V().Has("TID", to).then( | ||
function (nodes) { | ||
if (nodes[0].Metadata.Neutron && nodes[0].Metadata.Neutron.IPV4) { | ||
packetInjection.DstIP = nodes[0].Metadata.Neutron.IPV4[0] | ||
} | ||
if (nodes[0].Metadata.ExtID && nodes[0].Metadata.ExtID["attached-mac"]) { | ||
packetInjection.DstMAC = nodes[0].Metadata.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)); | ||
} | ||
}).then(function () { | ||
return client.G.V().Has("TID", s) | ||
}).then(function (nodes) { | ||
if (nodes[0].Metadata.Neutron && nodes[0].Metadata.Neutron.IPV4) { | ||
packetInjection.SrcIP = nodes[0].Metadata.Neutron.IPV4[0] | ||
} | ||
if (nodes[0].Metadata.ExtID && nodes[0].Metadata.ExtID["attached-mac"]) { | ||
packetInjection.SrcMAC = nodes[0].Metadata.ExtID["attached-mac"] | ||
} else { | ||
packetInjection.SrcIP = nodes[0].Metadata.IPV4[0] | ||
} | ||
From[s] = packetInjection; | ||
From[s].SrcIP = From[s].SrcIP.split("/")[0] | ||
return client.packetInjections.create(packetInjection) | ||
}) | ||
}); | ||
}).then(function () { | ||
return sleep(1000) | ||
}).then(function () { | ||
sources.forEach(function(s) { | ||
if (protocol == "icmp4") { | ||
client.G.Flows().Has("ICMP.ID", From[s].ICMPID, "Network.A", From[s].SrcIP).then(function(flows) { | ||
result[s] = {"Connected" : flows.length > 0 && flows[0].Metric.ABPackets > 0, "Replied" : flows.length > 0 && flows[0].Metric.BAPackets > 0}; | ||
return result | ||
}) | ||
} else { | ||
transport_protocol = protocol.toUpperCase().split(4)[0]; | ||
client.G.Flows().Has("Transport.A", From[s].SrcPort, "Transport.B", From[s].DstPort, "Transport.Protocol", transport_protocol, "Network.A", From[s].SrcIP).then(function(flows) { | ||
result[s] = {"Connected" : flows.length > 0 && flows[0].Metric.ABPackets > 0, "Replied" : flows.length > 0 && flows[0].Metric.BAPackets > 0}; | ||
return result | ||
}) | ||
} | ||
}); | ||
}).then(function () { | ||
return result | ||
}).finally(function () { | ||
return client.captures.delete(capture.UUID) | ||
}).catch(function () { | ||
return client.captures.delete(capture.UUID) | ||
}); | ||
} |