|
| 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: icmp |
| 13 | + - description: "Protocol : TCP/IPv4" |
| 14 | + value: tcp |
| 15 | + - description: "Protocol : UDP/IPv4" |
| 16 | + value: udp |
| 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, ...sources) { |
| 25 | + var result = {}; |
| 26 | + var From = {}; |
| 27 | + var capture = new Capture(); |
| 28 | + capture.GremlinQuery = "G.V().Has('TID', '" + to + "')"; |
| 29 | + var packetInjection = new PacketInjection(); |
| 30 | + return client.captures.create(capture).then(function (c) { |
| 31 | + capture = c |
| 32 | + }).then(function () { |
| 33 | + sources.forEach(function(source) { |
| 34 | + packetInjection.Src = "G.V().Has('TID', '" + source + "')" |
| 35 | + packetInjection.Dst = "G.V().Has('TID', '" + to + "')" |
| 36 | + packetInjection.Count = 5 |
| 37 | + return client.G.V().Has("TID", to).then( |
| 38 | + function (nodes) { |
| 39 | + if (nodes[0].Metadata.Neutron && nodes[0].Metadata.Neutron.IPV4) { |
| 40 | + packetInjection.DstIP = nodes[0].Metadata.Neutron.IPV4[0] |
| 41 | + } |
| 42 | + if (nodes[0].Metadata.ExtID && nodes[0].Metadata.ExtID["attached-mac"]) { |
| 43 | + packetInjection.DstMAC = nodes[0].Metadata.ExtID["attached-mac"] |
| 44 | + } |
| 45 | + if (protocol == "icmp") { |
| 46 | + packetInjection.Type = protocol + "4"; |
| 47 | + packetInjection.ICMPID = Math.floor(Math.random() * 65535); |
| 48 | + } |
| 49 | + if (protocol == "tcp" || "udp") { |
| 50 | + packetInjection.Type = protocol + "4"; |
| 51 | + packetInjection.SrcPort = 1024 + Math.floor(Math.random() * (65535-1024)); |
| 52 | + packetInjection.DstPort = 1024 + Math.floor(Math.random() * (65535-1024)); |
| 53 | + } |
| 54 | + }).then(function () { |
| 55 | + return client.G.V().Has("TID", source) |
| 56 | + }).then(function (nodes) { |
| 57 | + if (nodes[0].Metadata.Neutron && nodes[0].Metadata.Neutron.IPV4) { |
| 58 | + packetInjection.SrcIP = nodes[0].Metadata.Neutron.IPV4[0] |
| 59 | + } |
| 60 | + if (nodes[0].Metadata.ExtID && nodes[0].Metadata.ExtID["attached-mac"]) { |
| 61 | + packetInjection.SrcMAC = nodes[0].Metadata.ExtID["attached-mac"] |
| 62 | + From[source] = packetInjection; |
| 63 | + }else { |
| 64 | + From[source] = packetInjection; |
| 65 | + From[source].SrcIP = nodes[0].Metadata.IPV4[0] |
| 66 | + } |
| 67 | + From[source].SrcIP = From[source].SrcIP.split("/")[0] |
| 68 | + return client.packetInjections.create(packetInjection) |
| 69 | + }) |
| 70 | + }); |
| 71 | + }).then(function () { |
| 72 | + return sleep(2000) |
| 73 | + }).then(function () { |
| 74 | + sources.forEach(function(source) { |
| 75 | + if (protocol == "icmp") { |
| 76 | + return client.G.Flows().Has("ICMP.ID", From[source].ICMPID, "Network.A", From[source].SrcIP).then( |
| 77 | + function (flows) { |
| 78 | + result[source] = {"Connected" : flows.length > 0 && flows[0].Metric.ABPackets > 0, "Replied" : flows[0].Metric.BAPackets == 5}; |
| 79 | + return result |
| 80 | + }) |
| 81 | + } else { |
| 82 | + transport_protocol = protocol.toUpperCase(); |
| 83 | + 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( |
| 84 | + function (flows) { |
| 85 | + if (flows[0].Application != "UDP") { |
| 86 | + result[source] = {"Connected" : flows.length > 0 && flows[0].Metric.ABPackets > 0, "Replied" : flows[0].Metric.BAPackets == 5}; |
| 87 | + } else { |
| 88 | + result[source] = {"Connected" : flows.length > 0 && flows[0].Metric.ABPackets > 0, "Replied" : "UDP - No reply"}; |
| 89 | + } |
| 90 | + return result |
| 91 | + }) |
| 92 | + } |
| 93 | + }); |
| 94 | + return sleep(20) |
| 95 | + }).then(function () { |
| 96 | + return result |
| 97 | + }).finally(function () { |
| 98 | + client.captures.delete(capture.UUID) |
| 99 | + }) |
| 100 | + } |
0 commit comments