1+ ---
2+ UUID : " 5230f319-7ccb-4e92-5e55-23a75e474ee6"
3+ name : " PingMesh(ICMP/TCP/UDP)"
4+ description : " Check Connectivity from Multiple Source to Single Destination"
5+ parameters :
6+ - name : source
7+ description : Source node
8+ type : node
9+ - name : destination
10+ description : Destination node
11+ type : node
12+ - name : protocol
13+ description : Protocol
14+ type : choice
15+ default : ICMPv4
16+ values :
17+ - description : " Protocol : ICMPv4/Echo request"
18+ value : ICMPv4
19+ - description : " Protocol : TCP/IPv4"
20+ value : TCP
21+ - description : " Protocol : UDP/IPv4"
22+ value : UDP
23+ source : |
24+ function PingMesh(from, to, protocol) {
25+ var dict = {};
26+ var From = {};
27+ var sources = [];
28+ sources.push(from);
29+ var capture = new Capture();
30+ capture.GremlinQuery = "G.V().Has('TID', '" + to + "')";
31+ var packetInjection = new PacketInjection();
32+ return client.captures.create(capture).then(function (c) {
33+ capture = c
34+ }).then(function () {
35+ sources.forEach(function(source) {
36+ packetInjection.Src = "G.V().Has('TID', '" + source + "')"
37+ packetInjection.Dst = "G.V().Has('TID', '" + to + "')"
38+ packetInjection.Count = 5
39+ return client.G.V().Has("TID", to).then(
40+ function (nodes) {
41+ if (nodes[0].Metadata.Neutron && nodes[0].Metadata.Neutron.IPV4) {
42+ packetInjection.DstIP = nodes[0].Metadata.Neutron.IPV4[0]
43+ }
44+ if (nodes[0].Metadata.ExtID && nodes[0].Metadata.ExtID["attached-mac"]) {
45+ packetInjection.DstMAC = nodes[0].Metadata.ExtID["attached-mac"]
46+ }
47+ if (protocol == "ICMPv4") {
48+ packetInjection.Type = "icmp4"
49+ packetInjection.ICMPID = Math.floor(Math.random() * 65535);
50+ i += Math.floor(Math.random() * 1000);
51+ }
52+ if (protocol == "TCP") {
53+ packetInjection.Type = "tcp4"
54+ packetInjection.SrcPort = 1024 + Math.floor(Math.random() * (65535-1024));
55+ packetInjection.DstPort = 1024 + Math.floor(Math.random() * (65535-1024));
56+ }
57+ if (protocol == "UDP") {
58+ packetInjection.Type = "udp4"
59+ packetInjection.SrcPort = 1024 + Math.floor(Math.random() * (65535-1024));
60+ packetInjection.DstPort = 1024 + Math.floor(Math.random() * (65535-1024));
61+ }
62+ }).then(function () {
63+ return client.G.V().Has("TID", source)
64+ }).then(function (nodes) {
65+ if (nodes[0].Metadata.Neutron && nodes[0].Metadata.Neutron.IPV4) {
66+ packetInjection.SrcIP = nodes[0].Metadata.Neutron.IPV4[0]
67+ }
68+ if (nodes[0].Metadata.ExtID && nodes[0].Metadata.ExtID["attached-mac"]) {
69+ packetInjection.SrcMAC = nodes[0].Metadata.ExtID["attached-mac"]
70+ From[source] = packetInjection;
71+ }else {
72+ From[source] = packetInjection;
73+ From[source].SrcIP = nodes[0].Metadata.IPV4[0]
74+ From[source].SrcMAC = nodes[0].Metadata.MAC
75+ }
76+ From[source].SrcIP = From[source].SrcIP.split("/")[0]
77+ return client.packetInjections.create(packetInjection)
78+ })
79+ });
80+ }).then(function () {
81+ return sleep(2000)
82+ }).then(function () {
83+ sources.forEach(function(source) {
84+ if (protocol == "ICMPv4") {
85+ return client.G.Flows().Has("ICMP.ID", From[source].ICMPID, "Link.A", From[source].SrcMAC, "Network.A", From[source].SrcIP).then(
86+ function (flows) {
87+ dict[source] = flows.length > 0;
88+ })
89+ }
90+ if (protocol == "TCP") {
91+ return client.G.Flows().Has("Transport.A", From[source].SrcPort, "Transport.B", From[source].DstPort, "Transport.Protocol", "TCP", "Link.A", From[source].SrcMAC, "Network.A", From[source].SrcIP).then(
92+ function (flows) {
93+ dict[source] = flows.length > 0;
94+ })
95+ }
96+ if (protocol == "UDP") {
97+ return client.G.Flows().Has("Transport.A", From[source].SrcPort, "Transport.B", From[source].DstPort, "Transport.Protocol", "UDP", "Link.A", From[source].SrcMAC, "Network.A", From[source].SrcIP).then(
98+ function (flows) {
99+ dict[source] = flows.length > 0;
100+ })
101+ }
102+ });
103+ return sleep(1000)
104+ }).then(function () {
105+ return dict
106+ }).finally(function () {
107+ client.captures.delete(capture.UUID)
108+ })
109+ }
0 commit comments