Skip to content

Commit

Permalink
workflow: add ping-mesh workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
dvandra committed Feb 7, 2019
1 parent ddc21c0 commit 506df31
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions statics/workflows/ping-mesh.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
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: icmp
values:
- description: "Protocol : ICMPv4/Echo request"
value: icmp
- description: "Protocol : TCP/IPv4"
value: tcp
- description: "Protocol : UDP/IPv4"
value: udp
- name: destination
description: Destination Node
type: node
- name: sources
description: Source Nodes
type: node
source: |
function PingMesh(protocol, to, ...sources) {
var result = {};
var From = {};
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 () {
sources.forEach(function(source) {
packetInjection.Src = "G.V().Has('TID', '" + source + "')"
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 == "icmp") {
packetInjection.Type = protocol + "4";
packetInjection.ICMPID = Math.floor(Math.random() * 65535);
}
if (protocol == "tcp" || "udp") {
packetInjection.Type = protocol + "4";
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", source)
}).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"]
From[source] = packetInjection;
}else {
From[source] = packetInjection;
From[source].SrcIP = nodes[0].Metadata.IPV4[0]
}
From[source].SrcIP = From[source].SrcIP.split("/")[0]
return client.packetInjections.create(packetInjection)
})
});
}).then(function () {
return sleep(2000)
}).then(function () {
sources.forEach(function(source) {
if (protocol == "icmp") {
return client.G.Flows().Has("ICMP.ID", From[source].ICMPID, "Network.A", From[source].SrcIP).then(
function (flows) {
result[source] = {"Connected" : flows.length > 0 && flows[0].Metric.ABPackets > 0, "Replied" : flows[0].Metric.BAPackets == 5};
})
} else {
transport_protocol = protocol.toUpperCase();
return client.G.Flows().Has("Transport.A", From[source].SrcPort, "Transport.B", From[source].DstPort, "Transport.Protocol", transport_protocol, "Network.A", From[source].SrcIP).then(
function (flows) {
if (flows[0].Application != "UDP") {
result[source] = {"Connected" : flows.length > 0 && flows[0].Metric.ABPackets > 0, "Replied" : flows[0].Metric.BAPackets == 5};
} else {
result[source] = {"Connected" : flows.length > 0 && flows[0].Metric.ABPackets > 0, "Replied" : "UDP - No reply"};
}
})
}
});
return sleep(10)
}).then(function () {
return result
}).finally(function () {
client.captures.delete(capture.UUID)
})
}

0 comments on commit 506df31

Please sign in to comment.