|
| 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 | + } |
| 51 | + if (protocol == "TCP") { |
| 52 | + packetInjection.Type = "tcp4" |
| 53 | + packetInjection.SrcPort = 1024 + Math.floor(Math.random() * (65535-1024)); |
| 54 | + packetInjection.DstPort = 1024 + Math.floor(Math.random() * (65535-1024)); |
| 55 | + } |
| 56 | + if (protocol == "UDP") { |
| 57 | + packetInjection.Type = "udp4" |
| 58 | + packetInjection.SrcPort = 1024 + Math.floor(Math.random() * (65535-1024)); |
| 59 | + packetInjection.DstPort = 1024 + Math.floor(Math.random() * (65535-1024)); |
| 60 | + } |
| 61 | + }).then(function () { |
| 62 | + return client.G.V().Has("TID", source) |
| 63 | + }).then(function (nodes) { |
| 64 | + if (nodes[0].Metadata.Neutron && nodes[0].Metadata.Neutron.IPV4) { |
| 65 | + packetInjection.SrcIP = nodes[0].Metadata.Neutron.IPV4[0] |
| 66 | + } |
| 67 | + if (nodes[0].Metadata.ExtID && nodes[0].Metadata.ExtID["attached-mac"]) { |
| 68 | + packetInjection.SrcMAC = nodes[0].Metadata.ExtID["attached-mac"] |
| 69 | + From[source] = packetInjection; |
| 70 | + }else { |
| 71 | + From[source] = packetInjection; |
| 72 | + From[source].SrcIP = nodes[0].Metadata.IPV4[0] |
| 73 | + From[source].SrcMAC = nodes[0].Metadata.MAC |
| 74 | + } |
| 75 | + From[source].SrcIP = From[source].SrcIP.split("/")[0] |
| 76 | + return client.packetInjections.create(packetInjection) |
| 77 | + }) |
| 78 | + }); |
| 79 | + }).then(function () { |
| 80 | + return sleep(2000) |
| 81 | + }).then(function () { |
| 82 | + sources.forEach(function(source) { |
| 83 | + if (protocol == "ICMPv4") { |
| 84 | + return client.G.Flows().Has("ICMP.ID", From[source].ICMPID, "Link.A", From[source].SrcMAC, "Network.A", From[source].SrcIP).then( |
| 85 | + function (flows) { |
| 86 | + dict[source] = flows.length > 0; |
| 87 | + }) |
| 88 | + } |
| 89 | + if (protocol == "TCP") { |
| 90 | + 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( |
| 91 | + function (flows) { |
| 92 | + dict[source] = flows.length > 0; |
| 93 | + }) |
| 94 | + } |
| 95 | + if (protocol == "UDP") { |
| 96 | + 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( |
| 97 | + function (flows) { |
| 98 | + dict[source] = flows.length > 0; |
| 99 | + }) |
| 100 | + } |
| 101 | + }); |
| 102 | + return sleep(1000) |
| 103 | + }).then(function () { |
| 104 | + return dict |
| 105 | + }).finally(function () { |
| 106 | + client.captures.delete(capture.UUID) |
| 107 | + }) |
| 108 | + } |
0 commit comments