This repository has been archived by the owner on Sep 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,25 +160,56 @@ def get_parsed_path_simulation( | |
""" | ||
response = self.get_path_simulation(src_ip, dst_ip, src_port, dst_port, protocol, snapshot_id) | ||
graph = response.get("graph", {}) | ||
nodes = {graph_node["id"]: graph_node for graph_node in graph.get("nodes", {})} | ||
edges = {edge["id"]: edge for edge in graph.get("edges", {})} | ||
path = [] | ||
nodes = {graph_node["id"]: graph_node for graph_node in graph.get("nodes", {})} | ||
|
||
# ipfabric returns the source of the path as the last element in the nodes list | ||
for idx, node in enumerate(graph.get("nodes", [])[::-1]): | ||
edge_id = node["forwarding"][0]["dstIntList"][0]["id"] | ||
edge = edges.get(edge_id) | ||
if not edge or idx == len(nodes) - 1: | ||
continue # don't add to path as the edge for the penultimate node will contain the 'target' node | ||
for idx, edge in enumerate(graph.get("edges", [])[::-1]): | ||
forwarding_type = "" | ||
edge_id = edge.get("id") | ||
|
||
src_name = edge.get("source") | ||
src_node = nodes.get(src_name, {}) | ||
src_forwarding = src_node.get("forwarding") | ||
src_type = src_node.get("devType") | ||
src_fwd = edge.get("srcAddr", "") | ||
if src_forwarding: | ||
forwarding_type = src_forwarding[0].get("search") | ||
|
||
dst_name = edge.get("target") | ||
dst_node = nodes.get(dst_name, {}) | ||
dst_forwarding = dst_node.get("forwarding") | ||
dst_type = dst_node.get("devType") | ||
dst_fwd = edge.get("dstAddr", "") | ||
if dst_forwarding: | ||
forwarding_type = dst_forwarding[0].get("search") | ||
|
||
if src_forwarding and forwarding_type == "mpls": | ||
# edge src tag | ||
src_node_int_list = [*src_forwarding[0].get("srcIntList"), *src_forwarding[0].get("dstIntList")] | ||
for intf in src_node_int_list: | ||
if intf.get("id") == edge_id: | ||
src_fwd = intf.get("labelStack") | ||
|
||
if dst_forwarding and forwarding_type == "mpls": | ||
# edge dst tag | ||
dst_node_int_list = [*dst_forwarding[0].get("srcIntList"), *dst_forwarding[0].get("dstIntList")] | ||
for intf in dst_node_int_list: | ||
if edge.get("tlabel") and intf.get("int") == edge.get("tlabel"): | ||
dst_fwd = intf.get("labelStack") | ||
|
||
path.append( | ||
( | ||
idx + 1, | ||
node.get("hostname"), | ||
edge["slabel"], | ||
edge["srcAddr"], | ||
edge["dstAddr"], | ||
edge["tlabel"], | ||
nodes.get(edge["target"], {}).get("hostname"), | ||
forwarding_type or "(empty)", | ||
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. maybe use a CONSTANT instead of 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. yes, good one. Will update. |
||
src_node.get("hostname") or "(empty)", | ||
src_type or "(empty)", | ||
edge.get("slabel") or "(empty)", | ||
src_fwd or "(empty)", | ||
dst_fwd or "(empty)", | ||
edge.get("tlabel") or "(empty)", | ||
dst_type or "(empty)", | ||
dst_node.get("hostname") or "(empty)", | ||
) | ||
) | ||
return path | ||
|
@@ -201,21 +232,18 @@ def get_src_dst_endpoint( | |
""" | ||
response = self.get_path_simulation(src_ip, dst_ip, src_port, dst_port, protocol, snapshot_id) | ||
graph = response.get("graph", {}) | ||
|
||
endpoints = {} | ||
src_intf = "" | ||
dst_intf = "" | ||
src_node = "" | ||
dst_node = "" | ||
endpoints["src"] = "Unknown" | ||
endpoints["dst"] = "Unknown" | ||
|
||
# ipfabric returns the source of the path as the last element in the nodes list | ||
for idx, node in enumerate(graph.get("nodes", [])[::-1]): | ||
if idx == 0: | ||
src_intf = node["forwarding"][0]["srcIntList"][0]["int"] | ||
src_node = node.get("hostname") | ||
endpoints["src"] = f"{src_intf} - {src_node}" | ||
if idx == len(graph.get("nodes", [])) - 1: | ||
dst_intf = node["forwarding"][0]["dstIntList"][0]["int"] | ||
dst_node = node.get("hostname") | ||
endpoints["dst"] = f"{dst_intf} - {dst_node}" | ||
node_forwarding = node.get("forwarding") | ||
if node_forwarding: | ||
if idx == 0: | ||
src_intf = node_forwarding[0]["srcIntList"][0]["int"] | ||
endpoints["src"] = f"{src_intf} -- {node.get('hostname')}" | ||
elif idx == len(graph.get("nodes", [])) - 1: | ||
dst_intf = node_forwarding[0]["dstIntList"][0]["int"] | ||
endpoints["dst"] = f"{dst_intf} -- {node.get('hostname')}" | ||
return endpoints |
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
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.
I would group these 2
if statements
in one:just to group all the
mpls
stuff together