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