Skip to content
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

313 explain add routing resources #320

Merged
merged 108 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 106 commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
120b132
init
haim-kermany Nov 29, 2023
0d800b2
go 20
haim-kermany Nov 29, 2023
3b05954
go 20
haim-kermany Nov 29, 2023
e75c3c0
not 1.2
haim-kermany Nov 29, 2023
a120861
Merge branch 'main' into subnet-grouping2
haim-kermany Dec 7, 2023
4d6a3a2
ShowOnSubnetMode for tgw
haim-kermany Dec 7, 2023
55a6259
use go-version-file
haim-kermany Dec 7, 2023
f056052
CR from Ziv
haim-kermany Dec 7, 2023
6d2840c
removing subnetMode flag
haim-kermany Dec 7, 2023
0fd51e2
does not work
haim-kermany Dec 7, 2023
85e53ff
another try
haim-kermany Dec 7, 2023
4290fdf
change subnetmode Location
haim-kermany Dec 7, 2023
d911f9b
test
haim-kermany Dec 7, 2023
ee96ef4
lint
haim-kermany Dec 7, 2023
d609bb7
code review
haim-kermany Dec 7, 2023
7d9baac
documenting
haim-kermany Dec 7, 2023
95daa44
using maps from golang 21
haim-kermany Dec 10, 2023
8d469d6
first implementation
haim-kermany Dec 11, 2023
16d6066
Merge branch 'main' into subnet-grouping2
haim-kermany Dec 12, 2023
ae50b61
code review
haim-kermany Dec 12, 2023
c47a06e
not use pointer to map
haim-kermany Dec 12, 2023
f85c7c8
handle pointers to string
haim-kermany Dec 12, 2023
a83e24b
Merge branch 'subnet-grouping2' into multi_vpc_output
haim-kermany Dec 13, 2023
7ee4065
single file for json
haim-kermany Dec 13, 2023
5141aaf
drawio
haim-kermany Dec 13, 2023
14839cc
update testing
haim-kermany Dec 14, 2023
e878c09
adding tests to main
haim-kermany Dec 18, 2023
2a0a03b
Merge branch 'main' into subnet-grouping2
haim-kermany Dec 18, 2023
f24c062
Merge branch 'subnet-grouping2' into multi_vpc_output
haim-kermany Dec 18, 2023
f37fdf3
support via main
haim-kermany Dec 18, 2023
53acd88
renaming
haim-kermany Dec 19, 2023
a52dc16
remove code
haim-kermany Dec 19, 2023
aa40f8c
lint
haim-kermany Dec 19, 2023
cee8d35
lint
haim-kermany Dec 19, 2023
b274811
lint
haim-kermany Dec 19, 2023
cda4390
lint
haim-kermany Dec 19, 2023
0404d65
aMapEntry
haim-kermany Dec 19, 2023
dc0aa0d
lint
haim-kermany Dec 19, 2023
9508e8c
TextualOutputFormatter
haim-kermany Dec 20, 2023
9fa3846
Merge branch 'main' into subnet-grouping2
haim-kermany Dec 20, 2023
e188ceb
Merge branch 'subnet-grouping2' into multi_vpc_output
haim-kermany Dec 20, 2023
3db9e2b
Merge branch 'main' into subnet-grouping2
haim-kermany Dec 21, 2023
2324b25
Merge branch 'subnet-grouping2' into multi_vpc_output
haim-kermany Dec 21, 2023
bf29ee0
Merge branch 'main' into subnet-grouping2
haim-kermany Dec 27, 2023
140c37c
merge from main
haim-kermany Dec 27, 2023
67fa0cc
fix for json
haim-kermany Dec 27, 2023
a1d301c
Merge branch 'main' into subnet-grouping2
haim-kermany Jan 1, 2024
4bb6229
Merge branch 'subnet-grouping2' into multi_vpc_output
haim-kermany Jan 1, 2024
4c3771e
moving a method to common
haim-kermany Jan 2, 2024
6e7fe21
from main
haim-kermany Jan 2, 2024
2843077
comments
haim-kermany Jan 2, 2024
cf9284b
removing writeoutputgeneric()
haim-kermany Jan 2, 2024
6221a91
lint
haim-kermany Jan 2, 2024
4eb6e8c
Merge branch 'main' into multi_vpc_output
haim-kermany Jan 4, 2024
b525dd2
comments
haim-kermany Jan 7, 2024
1b5c8c1
remove redundent code from main
haim-kermany Jan 7, 2024
d194e72
comment
haim-kermany Jan 7, 2024
c1eca55
added documentation - something took me time figuring out
ShiriMoran Jan 8, 2024
173a1f3
infrastructure for adding router resource to the explanation
ShiriMoran Jan 9, 2024
c4af826
extract code related to RoutingResource between src and dst to be use…
ShiriMoran Jan 9, 2024
13fd2de
more code extraction required for RoutingResource computation
ShiriMoran Jan 10, 2024
810e7c0
merge with main
ShiriMoran Jan 10, 2024
142a393
expanded explanation struct and added computation for RoutingResource…
ShiriMoran Jan 10, 2024
ba61ee5
spelling
ShiriMoran Jan 11, 2024
19ec5bc
renaming
ShiriMoran Jan 11, 2024
1f85980
code for computing actual rules
ShiriMoran Jan 11, 2024
a6a4109
spelling
ShiriMoran Jan 11, 2024
a18c9d5
router and filtersExternal should be in the src dst level
ShiriMoran Jan 11, 2024
bf0e9d7
router and filtersExternal should be in the src dst level
ShiriMoran Jan 11, 2024
8466566
fix error and use actual rules and connection details
ShiriMoran Jan 11, 2024
f15fb98
no containing node for external address implies that it has no router
ShiriMoran Jan 11, 2024
e089176
no use in passing interface by reference
ShiriMoran Jan 11, 2024
67b238a
committing for the weekend; needs to uncomment last changes in groupi…
ShiriMoran Jan 11, 2024
b6ce9c9
adding router details to the explaination and updated
ShiriMoran Jan 14, 2024
4f868e6
finalized
ShiriMoran Jan 14, 2024
2140504
updated TestQueryConnectionSGBasic for router explanation
ShiriMoran Jan 14, 2024
3eff438
added a test to TestSimpleExternalSG for router
ShiriMoran Jan 14, 2024
4aae058
lint comments
ShiriMoran Jan 14, 2024
38d3588
lint comments
ShiriMoran Jan 14, 2024
ec0a762
Merge remote-tracking branch 'origin/main' into 313_explain_add_routi…
ShiriMoran Jan 14, 2024
3044ad8
Merge branch 'main' into 313_explain_add_routingResources
ShiriMoran Jan 14, 2024
b98a515
CR
ShiriMoran Jan 17, 2024
f16fcbb
Update pkg/vpcmodel/nodesExplainability.go
ShiriMoran Jan 17, 2024
0e40040
Merge remote-tracking branch 'origin/313_explain_add_routingResources…
ShiriMoran Jan 17, 2024
4865040
Update pkg/vpcmodel/nodesExplainability.go
ShiriMoran Jan 17, 2024
f8a8dd2
Update pkg/vpcmodel/nodesExplainability.go
ShiriMoran Jan 17, 2024
b174b43
Merge remote-tracking branch 'origin/313_explain_add_routingResources…
ShiriMoran Jan 17, 2024
bf6dc78
Revert "Update pkg/vpcmodel/nodesExplainability.go"
ShiriMoran Jan 17, 2024
25a07e3
Revert "Update pkg/vpcmodel/nodesExplainability.go"
ShiriMoran Jan 17, 2024
c10ea91
CR
ShiriMoran Jan 17, 2024
3797fb0
CR
ShiriMoran Jan 17, 2024
da1956f
Merge branch 'main' into 313_explain_add_routingResources
ShiriMoran Jan 17, 2024
4abf3db
Update pkg/vpcmodel/nodesExplainability.go
ShiriMoran Jan 18, 2024
78ba6fc
CR comments
ShiriMoran Jan 18, 2024
abbd330
CR comments
ShiriMoran Jan 18, 2024
f5bf324
Merge remote-tracking branch 'origin/313_explain_add_routingResources…
ShiriMoran Jan 18, 2024
eb5cb6b
renaming
ShiriMoran Jan 18, 2024
bca592e
removed redundant code
ShiriMoran Jan 18, 2024
c47e804
more CR and renaming
ShiriMoran Jan 18, 2024
05a4b3b
lint comment
ShiriMoran Jan 18, 2024
93e81a8
lint comment
ShiriMoran Jan 18, 2024
0120e80
CR comment: do not use err to indicate some thing that is not actuall…
ShiriMoran Jan 18, 2024
659cd2e
Update pkg/vpcmodel/grouping.go
ShiriMoran Jan 18, 2024
998ffa6
CR comment
ShiriMoran Jan 18, 2024
352880a
Merge remote-tracking branch 'origin/313_explain_add_routingResources…
ShiriMoran Jan 18, 2024
2fcfc81
CR comment
ShiriMoran Jan 18, 2024
02f7bc8
CR comment
ShiriMoran Jan 18, 2024
47699cc
added ToDo
ShiriMoran Jan 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
219 changes: 122 additions & 97 deletions pkg/ibmvpc/explainability_test.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pkg/vpcmodel/abstractVPC.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func (n *VPCResource) VPC() VPCResourceIntf {
return n.VPCRef
}

// todo: define enum for filters
const (
// filter-resources layer names (grouping all vpc resources of that kind)
NaclLayer = "NaclLayer"
Expand Down
45 changes: 28 additions & 17 deletions pkg/vpcmodel/grouping.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ type groupedNodesInfo struct {
commonProperties *groupedCommonProperties
}

type explainDetails struct {
rules *rulesConnection
router RoutingResource
}

type groupedCommonProperties struct {
conn *common.ConnectionSet
connDiff *connectionDiff
rules *rulesConnection
conn *common.ConnectionSet
connDiff *connectionDiff
expDetails *explainDetails
// groupingStrKey is the key by which the grouping is done:
// the string of conn per grouping of conn lines, string of connDiff per grouping of diff lines
// and string of conn and rules for explainblity
// and string of conn and explainDetails for explainblity
groupingStrKey string // the key used for grouping per connectivity lines or diff lines
}

Expand Down Expand Up @@ -88,7 +93,7 @@ func newGroupConnLinesDiff(d *diffBetweenCfgs) (res *GroupConnLines, err error)
return res, err
}

func newGroupConnExplainability(c *VPCConfig, e *explainStruct) (res *GroupConnLines, err error) {
func newGroupConnExplainability(c *VPCConfig, e *rulesAndConnDetails) (res *GroupConnLines, err error) {
res = &GroupConnLines{
config: c,
explain: e,
Expand All @@ -107,7 +112,7 @@ type GroupConnLines struct {
nodesConn *VPCConnectivity
subnetsConn *VPCsubnetConnectivity
diff *diffBetweenCfgs
explain *explainStruct
explain *rulesAndConnDetails
srcToDst *groupingConnections
dstToSrc *groupingConnections
// a map to groupedEndpointsElems used by GroupedConnLine from a unified key of such elements
Expand Down Expand Up @@ -317,11 +322,12 @@ func (g *GroupConnLines) groupExternalAddressesForDiff(thisMinusOther bool) erro
// group public internet ranges for explainability lines
func (g *GroupConnLines) groupExternalAddressesForExplainability() error {
var res []*groupedConnLine
for _, rulesSrcDst := range *g.explain {
connStr := rulesSrcDst.conn.String() + semicolon
groupingStrKey := connStr + rulesSrcDst.rules.rulesEncode(g.config)
err := g.addLineToExternalGrouping(&res, rulesSrcDst.src, rulesSrcDst.dst,
&groupedCommonProperties{conn: rulesSrcDst.conn, rules: rulesSrcDst.rules, groupingStrKey: groupingStrKey})
for _, details := range *g.explain {
groupingStrKey := details.explanationEncode(g.config)
expDetails := &explainDetails{details.actualRules, details.router}
err := g.addLineToExternalGrouping(&res, details.src, details.dst,
&groupedCommonProperties{conn: details.conn, expDetails: expDetails,
groupingStrKey: groupingStrKey})
if err != nil {
return err
}
Expand Down Expand Up @@ -547,13 +553,18 @@ func connDiffEncode(src, dst VPCResourceIntf, connDiff *connectionDiff) string {
}

// encodes rulesConnection for grouping
func (rules *rulesConnection) rulesEncode(c *VPCConfig) string {
func (details *srcDstDetails) explanationEncode(c *VPCConfig) string {
connStr := details.conn.String() + semicolon
routingStr := ""
if details.router != nil {
routingStr = details.router.Name() + ";"
}
egressStr, ingressStr := "", ""
if len(rules.egressRules) > 0 {
egressStr = "egress:" + rules.egressRules.string(c) + semicolon
if len(details.actualRules.egressRules) > 0 {
egressStr = "egress:" + details.actualRules.egressRules.string(c) + semicolon
}
if len(rules.ingressRules) > 0 {
egressStr = "ingress:" + rules.ingressRules.string(c) + semicolon
if len(details.actualRules.ingressRules) > 0 {
egressStr = "ingress:" + details.actualRules.ingressRules.string(c) + semicolon
}
return egressStr + ingressStr
return connStr + routingStr + egressStr + ingressStr
}
22 changes: 6 additions & 16 deletions pkg/vpcmodel/nodesConnectivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,10 @@ func (c *VPCConfig) getAllowedConnsPerDirection(isIngress bool, capturedNode Nod
allLayersRes[peerNode] = allowedConnsBetweenCapturedAndPeerNode
} else {
// else : external node -> consider attached routing resources

allowedConnsBetweenCapturedAndPeerNode := NoConns()
// node is associated with either a pgw or a fip
var appliedRouter RoutingResource
for _, router := range c.RoutingResources {
routerConnRes := router.AllowedConnectivity(src, dst)
if !routerConnRes.IsEmpty() { // connection is allowed through router resource
// TODO: consider adding connection attribute with details of routing through this router resource
allowedConnsBetweenCapturedAndPeerNode = routerConnRes
appliedRouter = router
updatePerLayerRes(perLayerRes, router.Kind(), peerNode, routerConnRes)
}
}
if appliedRouter == nil {
appliedRouter, routerConnRes := c.getRoutingResource(src, dst)
if appliedRouter != nil {
updatePerLayerRes(perLayerRes, appliedRouter.Kind(), peerNode, routerConnRes)
} else {
// without fip/pgw there is no external connectivity
allLayersRes[peerNode] = NoConns()
continue
Expand All @@ -139,9 +129,9 @@ func (c *VPCConfig) getAllowedConnsPerDirection(isIngress bool, capturedNode Nod
// TODO: consider moving to pkg ibm-vpc
appliedFilters := appliedRouter.AppliedFiltersKinds()
for layer := range appliedFilters {
allowedConnsBetweenCapturedAndPeerNode = allowedConnsBetweenCapturedAndPeerNode.Intersection(perLayerRes[layer][peerNode])
routerConnRes = routerConnRes.Intersection(perLayerRes[layer][peerNode])
}
allLayersRes[peerNode] = allowedConnsBetweenCapturedAndPeerNode
allLayersRes[peerNode] = routerConnRes
}
}
return allLayersRes, perLayerRes, nil
Expand Down
Loading