Skip to content

Commit 54bf4af

Browse files
dvandranplanel
authored andcommitted
workflow: add ping-mesh workflow
1 parent ddc21c0 commit 54bf4af

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

statics/workflows/ping-mesh.yaml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
UUID: "784c3329-0f47-449b-5c58-2d207bcfb501"
3+
name: "Ping Mesh (ICMP/TCP/UDP)"
4+
description: "Check Connectivity from Multiple Source to Single Destination"
5+
parameters:
6+
- name: protocol
7+
description: Protocol
8+
type: choice
9+
default: icmp
10+
values:
11+
- description: "Protocol : ICMPv4/Echo request"
12+
value: icmp4
13+
- description: "Protocol : TCP/IPv4"
14+
value: tcp4
15+
- description: "Protocol : UDP/IPv4"
16+
value: udp4
17+
- name: destination
18+
description: Destination Node
19+
type: node
20+
- name: sources
21+
description: Source Nodes
22+
type: node
23+
source: |
24+
function PingMesh(protocol, to, source) {
25+
var sources = [source];
26+
var result = {};
27+
var From = {};
28+
var capture = new Capture();
29+
capture.GremlinQuery = "G.V().Has('TID', '" + to + "')";
30+
var packetInjection = new PacketInjection();
31+
return client.captures.create(capture).then(function (c) {
32+
capture = c
33+
}).then(function () {
34+
return sleep(1000)
35+
}).then(function () {
36+
sources.forEach(function(source) {
37+
packetInjection.Src = "G.V().Has('TID', '" + source + "')"
38+
packetInjection.Dst = "G.V().Has('TID', '" + to + "')"
39+
packetInjection.Count = 5
40+
return client.G.V().Has("TID", to).then(
41+
function (nodes) {
42+
if (nodes[0].Metadata.Neutron && nodes[0].Metadata.Neutron.IPV4) {
43+
packetInjection.DstIP = nodes[0].Metadata.Neutron.IPV4[0]
44+
}
45+
if (nodes[0].Metadata.ExtID && nodes[0].Metadata.ExtID["attached-mac"]) {
46+
packetInjection.DstMAC = nodes[0].Metadata.ExtID["attached-mac"]
47+
}
48+
if (protocol == "icmp4") {
49+
packetInjection.Type = protocol;
50+
packetInjection.ICMPID = Math.floor(Math.random() * 65535);
51+
}
52+
if (protocol == "tcp4" || protocol == "udp4") {
53+
packetInjection.Type = protocol;
54+
packetInjection.SrcPort = 1024 + Math.floor(Math.random() * (65535-1024));
55+
packetInjection.DstPort = 1024 + Math.floor(Math.random() * (65535-1024));
56+
}
57+
}).then(function () {
58+
return client.G.V().Has("TID", source)
59+
}).then(function (nodes) {
60+
if (nodes[0].Metadata.Neutron && nodes[0].Metadata.Neutron.IPV4) {
61+
packetInjection.SrcIP = nodes[0].Metadata.Neutron.IPV4[0]
62+
}
63+
if (nodes[0].Metadata.ExtID && nodes[0].Metadata.ExtID["attached-mac"]) {
64+
packetInjection.SrcMAC = nodes[0].Metadata.ExtID["attached-mac"]
65+
} else {
66+
packetInjection.SrcIP = nodes[0].Metadata.IPV4[0]
67+
}
68+
From[source] = packetInjection;
69+
From[source].SrcIP = From[source].SrcIP.split("/")[0]
70+
return client.packetInjections.create(packetInjection)
71+
})
72+
});
73+
}).then(function () {
74+
return sleep(1000)
75+
}).then(function () {
76+
if (protocol == "icmp4") {
77+
return client.G.Flows().Has("ICMP.ID", From[source].ICMPID, "Network.A", From[source].SrcIP).then(function(flows) {
78+
result[source] = {"Connected" : flows.length > 0 && flows[0].Metric.ABPackets > 0, "Replied" : flows.length > 0 && flows[0].Metric.BAPackets > 0};
79+
}).then(function () {
80+
return result
81+
});
82+
} else {
83+
transport_protocol = protocol.toUpperCase();
84+
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) {
85+
result[source] = {"Connected" : flows.length > 0 && flows[0].Metric.ABPackets > 0, "Replied" : flows.length > 0 && flows[0].Metric.BAPackets > 0};
86+
}).then(function () {
87+
return result
88+
});
89+
}
90+
}).then(function () {
91+
return result
92+
}).finally(function () {
93+
return client.captures.delete(capture.UUID)
94+
}).catch(function () {
95+
return client.captures.delete(capture.UUID)
96+
});
97+
}

0 commit comments

Comments
 (0)