-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f032d9
commit 3359094
Showing
8 changed files
with
2,149 additions
and
83 deletions.
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
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
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,74 @@ | ||
/* | ||
Copyright 2023- IBM Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package collector | ||
|
||
|
||
type treeNode interface { | ||
parent(resources *ResourcesContainerModel) treeNode | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////// | ||
|
||
func (v *VirtualNetworkInterface) parent(resources *ResourcesContainerModel) treeNode { | ||
if v.LportAttachmentId == nil { | ||
return nil | ||
} | ||
s := resources.GetSegmentPort(*v.LportAttachmentId) | ||
if s == nil { | ||
return nil | ||
} | ||
return s | ||
} | ||
func (s *SegmentPort) parent(resources *ResourcesContainerModel) treeNode { | ||
return resources.GetSegment(*s.ParentPath) | ||
} | ||
func (s *Segment) parent(resources *ResourcesContainerModel) treeNode { | ||
if s.ConnectivityPath == nil { | ||
return nil | ||
} | ||
if t1 := resources.GetTier1(*s.ConnectivityPath); t1 != nil { | ||
return t1 | ||
} | ||
return resources.GetTier0(*s.ConnectivityPath) | ||
} | ||
func (t *Tier1) parent(resources *ResourcesContainerModel) treeNode { | ||
return resources.GetTier0(*t.Tier0Path) | ||
} | ||
func (t *Tier0) parent(resources *ResourcesContainerModel) treeNode { return nil } | ||
|
||
|
||
// ////////////////////////////////////////////////////////////////////// | ||
type treeNodeBranch []treeNode | ||
|
||
func branch(resources *ResourcesContainerModel, n treeNode) treeNodeBranch { | ||
if n == nil { | ||
return treeNodeBranch{} | ||
} | ||
p := n.parent(resources) | ||
return append(branch(resources, p), n) | ||
} | ||
|
||
func treeNodesPath(got *ResourcesContainerModel, t1, t2 treeNode) (bool, treeNode, treeNodeBranch, treeNodeBranch) { | ||
b1 := branch(got, t1) | ||
b2 := branch(got, t2) | ||
if b1[0] != b2[0] { | ||
return false, nil, nil, nil | ||
} | ||
rootIndex := 0 | ||
for i := range b1 { | ||
if b1[i] != b2[i] { | ||
break | ||
} | ||
rootIndex = i | ||
} | ||
return true, b1[rootIndex], b1[rootIndex+1:], b2[rootIndex+1:] | ||
} | ||
|
||
func IsConnected(got *ResourcesContainerModel, t1, t2 treeNode) bool { | ||
c, _,_,_ := treeNodesPath(got, t1, t2); | ||
return c | ||
} |
Oops, something went wrong.