Skip to content

Commit a59b768

Browse files
committed
Workflow : Nto1CheckConnectivity
1 parent df7297d commit a59b768

File tree

3 files changed

+94
-3
lines changed

3 files changed

+94
-3
lines changed

js/api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,8 @@ export function REGEX(param: any): Predicate {
671671
return new Predicate("REGEX", param)
672672
}
673673

674-
export function WITHIN(...params: any[]): Predicate {
675-
return new Predicate("WITHIN", ...params)
674+
export function Within(...params: any[]): Predicate {
675+
return new Predicate("Within", ...params)
676676
}
677677

678678
export function WITHOUT(...params: any[]): Predicate {

js/browser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ window.GTE = apiLib.GTE
2626
window.LTE = apiLib.LTE
2727
window.IPV4RANGE = apiLib.IPV4RANGE
2828
window.REGEX = apiLib.REGEX
29-
window.WITHIN = apiLib.WITHIN
29+
window.Within = apiLib.Within
3030
window.WITHOUT = apiLib.WITHOUT
3131
window.INSIDE = apiLib.INSIDE
3232
window.OUTSIDE = apiLib.OUTSIDE
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
UUID: "18349e06-37d4-43c0-5882-d1aa4bf66133"
3+
Name: "Nto1CheckConnectivity"
4+
Title: "Test connectivity between N source to 1 Destination"
5+
Abstract: "This workflow aims to test the connectivity between N source to 1 Destination. It returns the status of the connection, true (with Flows) or false."
6+
Description: >
7+
# How to use:
8+
1. Enter the Gremlin Query for Source Nodes and Select the Destination Nodes to check the Connectivity between them
9+
2. Hit the 'Execute' button to run the workflow
10+
3. Result will be shown as status true or false along with flows between those interfaces.
11+
# How It Works:
12+
1. It will start capture on all Nodes from Source to Destination and injects 5 ICMP-Pkts from Source to Destination
13+
2. After 1 sec it will check for flows having the same capture-id created by this workflow
14+
3. If flows are there and the BA-Packtes in flow-metric > 0, then return 'Connectivity = ture' else 'Connectivity = false', along with this it also returns the flows
15+
4. For more information about Skydive workflows please follow - 'skydive.network/blog/introduction-to-workflows.html'
16+
Parameters:
17+
- Name: srcQuery
18+
Description: Gremlin Expression for Source-Nodes
19+
Type: string
20+
- Name: dstNode
21+
Description: Select Destination node
22+
Type: node
23+
Source: |
24+
function Nto1CheckConnectivity(srcQuery, to) {
25+
var result = {}
26+
try {
27+
sources = client.gremlin.query(srcQuery);
28+
dstNode = client.gremlin.G().V().Has('TID', to).result();
29+
dstNodeIP = (dstNode[0].Metadata.IPV4[0]).split("/");
30+
datNodeIP = dstNodeIP[0]
31+
var id = Math.floor(25000 + (Math.random() * 10000));
32+
var maxID = id + sources.length;
33+
34+
var getIP = function(sources) {
35+
var srcIP = [];
36+
for (var i = 0; i != sources.length; i++) {
37+
if (sources[i].Metadata.IPV4) {
38+
ip = (sources[i].Metadata.IPV4[0]).split("/");
39+
srcIP[i] = ip[0]
40+
}
41+
}
42+
return srcIP
43+
}
44+
45+
var srcIP = getIP(sources)
46+
47+
var capture = new Capture();
48+
capture.GremlinQuery = "G.V().Has('TID', '" + to + "')";
49+
var bpf = "icmp and (src " + datNodeIP + " or dst " + datNodeIP + ") and (icmp[4:2]>=" + id + " and icmp[4:2]<" + maxID + ")";
50+
capture.BPFFilter = "(" + bpf + ") " + "or (vlan and " + bpf + ")";
51+
52+
var packetInjection = new PacketInjection();
53+
packetInjection.Src = srcQuery
54+
packetInjection.Dst = "G.V().Has('TID', '" + to + "')";
55+
packetInjection.Type = "icmp4"
56+
packetInjection.ICMPID = id;
57+
packetInjection.Count = 5
58+
packetInjection.Mode = 0
59+
60+
capture = client.captures.create(capture)
61+
sleep(1000)
62+
client.packetInjections.create(packetInjection)
63+
sleep(1000)
64+
65+
var dstFlowCaptured = client.gremlin.G().Flows().Has('NodeTID', to, 'CaptureID', capture.UUID).result();
66+
67+
var flows = {};
68+
var noFlows = [];
69+
for (var i = 0; i != srcIP.length; i++) {
70+
var found = false;
71+
for (var j = 0; j != dstFlowCaptured.length; j++) {
72+
if (srcIP[i] == dstFlowCaptured[j].Network.A && dstFlowCaptured[j].Metric.ABPackets > 0 && dstFlowCaptured[j].Metric.BAPackets > 0) {
73+
found = true;
74+
flows[sources[i].Metadata.TID] = {"Connectivity" : true, "Flow" : dstFlowCaptured[j]}
75+
break;
76+
}
77+
}
78+
if (!found) {
79+
noFlows.push(i);
80+
flows[sources[i].Metadata.TID] = {"Connectivity" : false}
81+
}
82+
}
83+
84+
result["Connectivity"] = flows
85+
} catch (e) {
86+
console.log(e)
87+
result["Error"] = JSON.stringify(e)
88+
}
89+
if (capture && capture.UUID) client.captures.delete(capture.UUID)
90+
return result
91+
}

0 commit comments

Comments
 (0)