-
-
Notifications
You must be signed in to change notification settings - Fork 402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
workflow: add ping-mesh workflow #1640
Open
dvandra
wants to merge
1
commit into
skydive-project:master
Choose a base branch
from
dvandra:workflows_pingmesh
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
--- | ||
UUID: "784c3329-0f47-449b-5c58-2d207bcfb501" | ||
Name: "Ping Mesh (ICMP/TCP/UDP)" | ||
Description: "Check Connectivity from Multiple Source to Single Destination" | ||
Parameters: | ||
- Name: protocol | ||
Description: Protocol | ||
Type: choice | ||
Default: icmp4 | ||
Values: | ||
- Description: "Protocol : ICMPv4/Echo request" | ||
Value: icmp4 | ||
- Description: "Protocol : TCP/IPv4" | ||
Value: tcp4 | ||
- Description: "Protocol : UDP/IPv4" | ||
Value: udp4 | ||
- Name: source | ||
Description: Source Nodes (Enter a Gremlin Query to select Source Nodes) | ||
Type: string | ||
- Name: destination | ||
Description: Destination Node (Select Destination Node) | ||
Type: node | ||
Source: | | ||
function PingMesh(protocol, src, dst) { | ||
var sources = []; | ||
var result = {}; | ||
var pktform = {}; | ||
client.gremlin.query(src).then(function(nodes) { | ||
nodes.forEach(function(node) { | ||
if (node.Metadata.TID == dst) { return; } | ||
sources.push(node.Metadata.TID); | ||
}); | ||
}) | ||
var capture = new Capture(); | ||
capture.GremlinQuery = "G.V().Has('TID', '" + dst + "')"; | ||
return client.captures.create(capture).then(function (c) { | ||
capture = c | ||
}).then(function () { | ||
return sleep(1000) | ||
}).then(function () { | ||
sources.forEach(function(s) { | ||
var packetInjection = new PacketInjection(); | ||
packetInjection.Src = "G.V().Has('TID', '" + s + "')" | ||
dvandra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
packetInjection.Dst = "G.V().Has('TID', '" + dst + "')" | ||
packetInjection.Count = 5 | ||
return client.G.V().Has("TID", dst).then( | ||
function (nodes) { | ||
if (nodes[0].Metadata.Neutron && nodes[0].Metadata.Neutron.IPV4) { | ||
packetInjection.DstIP = nodes[0].Metadata.Neutron.IPV4[0] | ||
} | ||
if (nodes[0].Metadata.ExtID && nodes[0].Metadata.ExtID["attached-mac"]) { | ||
packetInjection.DstMAC = nodes[0].Metadata.ExtID["attached-mac"] | ||
} | ||
if (protocol == "icmp4") { | ||
packetInjection.Type = protocol; | ||
packetInjection.ICMPID = Math.floor(Math.random() * 65535); | ||
} | ||
if (protocol == "tcp4" || protocol == "udp4") { | ||
packetInjection.Type = protocol; | ||
packetInjection.SrcPort = 1024 + Math.floor(Math.random() * (65535-1024)); | ||
packetInjection.DstPort = 1024 + Math.floor(Math.random() * (65535-1024)); | ||
} | ||
}).then(function () { | ||
return client.G.V().Has("TID", s) | ||
}).then(function (nodes) { | ||
if (nodes[0].Metadata.Neutron && nodes[0].Metadata.Neutron.IPV4) { | ||
packetInjection.SrcIP = nodes[0].Metadata.Neutron.IPV4[0] | ||
} | ||
if (nodes[0].Metadata.ExtID && nodes[0].Metadata.ExtID["attached-mac"]) { | ||
packetInjection.SrcMAC = nodes[0].Metadata.ExtID["attached-mac"] | ||
} else { | ||
packetInjection.SrcIP = nodes[0].Metadata.IPV4[0] | ||
} | ||
pktform[s] = packetInjection; | ||
pktform[s].SrcIP = pktform[s].SrcIP.split("/")[0] | ||
return client.packetInjections.create(packetInjection) | ||
}) | ||
}); | ||
}).then(function () { | ||
return sleep(1000) | ||
dvandra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}).then(function () { | ||
sources.forEach(function(s) { | ||
if (protocol == "icmp4") { | ||
client.G.Flows().Has("ICMP.ID", pktform[s].ICMPID, "Network.A", pktform[s].SrcIP).then(function(flows) { | ||
result[s] = {"Connected" : flows.length > 0 && flows[0].Metric.ABPackets > 0, "Replied" : flows.length > 0 && flows[0].Metric.BAPackets > 0}; | ||
return result | ||
}) | ||
} else { | ||
transport_protocol = protocol.toUpperCase().split(4)[0]; | ||
client.G.Flows().Has("Transport.A", pktform[s].SrcPort, "Transport.B", pktform[s].DstPort, "Transport.Protocol", transport_protocol, "Network.A", pktform[s].SrcIP).then(function(flows) { | ||
result[s] = {"Connected" : flows.length > 0 && flows[0].Metric.ABPackets > 0, "Replied" : flows.length > 0 && flows[0].Metric.BAPackets > 0}; | ||
return result | ||
}) | ||
} | ||
}); | ||
}).then(function () { | ||
return result | ||
}).finally(function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the order should be catch and finally |
||
return client.captures.delete(capture.UUID) | ||
}).catch(function () { | ||
return client.captures.delete(capture.UUID) | ||
}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can just avoid to add the node in sources when dst == node.Metadata.T