Skip to content

Commit

Permalink
98 grouping with self loops (#152)
Browse files Browse the repository at this point in the history
added an optimization to grouping in which self loops are treated as don't cares
  • Loading branch information
ShiriMoran authored Sep 28, 2023
1 parent 27c4955 commit 4af4337
Show file tree
Hide file tree
Showing 5 changed files with 555 additions and 21 deletions.
4 changes: 1 addition & 3 deletions pkg/ibmvpc/examples/acl_testing3_with_grouping.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ vsi1-ky[10.240.10.4] => Public Internet 161.26.0.0/16 : protocol: UDP *
vsi1-ky[10.240.10.4] => vsi2-ky[10.240.20.4] : protocol: TCP,UDP
vsi2-ky[10.240.20.4] => Public Internet (all ranges) : All Connections
vsi2-ky[10.240.20.4] => vsi1-ky[10.240.10.4] : All Connections *
vsi3a-ky[10.240.30.5],vsi3b-ky[10.240.30.6] => vsi3c-ky[10.240.30.4] : All Connections
vsi3a-ky[10.240.30.5],vsi3b-ky[10.240.30.6],vsi3c-ky[10.240.30.4] => vsi1-ky[10.240.10.4] : All Connections *
vsi3a-ky[10.240.30.5],vsi3c-ky[10.240.30.4] => vsi3b-ky[10.240.30.6] : All Connections
vsi3b-ky[10.240.30.6],vsi3c-ky[10.240.30.4] => vsi3a-ky[10.240.30.5] : All Connections
vsi3a-ky[10.240.30.5],vsi3b-ky[10.240.30.6],vsi3c-ky[10.240.30.4] => vsi3a-ky[10.240.30.5],vsi3b-ky[10.240.30.6],vsi3c-ky[10.240.30.4] : All Connections

connections are stateful unless marked with *
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
combined connections between subnets:
subnet1-ky => Public Internet (all ranges) : All Connections
subnet1-ky => subnet2-ky,subnet3-ky : All Connections
subnet2-ky => subnet1-ky,subnet3-ky : All Connections
subnet3-ky => subnet1-ky,subnet2-ky : All Connections
subnet1-ky,subnet2-ky,subnet3-ky => subnet1-ky,subnet2-ky,subnet3-ky : All Connections

connections are stateful unless marked with *
43 changes: 28 additions & 15 deletions pkg/vpcmodel/grouping.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ func (g *groupingConnections) addPublicConnectivity(ep EndpointElem, conn string
(*g)[ep][conn] = append((*g)[ep][conn], targetNode)
}

// vsiGroupingBySubnets returns a slice of EndpointElem objects produced from an input slice, by grouping
// set of elements that represent network interface nodes from the same subnet into a single groupedNetworkInterfaces object
// vsiGroupingBySubnets returns a slice of EndpointElem objects, by grouping set of elements that
// represent network interface nodes from the same subnet into a single groupedNetworkInterfaces object
func vsiGroupingBySubnets(groupedConnLines *GroupConnLines,
elemsList []EndpointElem, c *CloudConfig) []EndpointElem {
res := []EndpointElem{}
Expand Down Expand Up @@ -174,7 +174,8 @@ func vsiGroupingBySubnets(groupedConnLines *GroupConnLines,
return res
}

// subnetGrouping returns a slice of EndpointElem objects produced from an input slice, by grouping EndpointElem that represents a subnet
// subnetGrouping returns a slice of EndpointElem objects produced from an input slice, by grouping
// set of elements that represent subnets into a single groupedNetworkInterfaces object
func subnetGrouping(groupedConnLines *GroupConnLines,
elemsList []EndpointElem) []EndpointElem {
res := []EndpointElem{}
Expand Down Expand Up @@ -244,6 +245,20 @@ func (g *GroupConnLines) groupExternalAddressesForSubnets() {
g.GroupedLines = res
}

// aux func, returns true iff the EndpointElem is Node if grouping vsis or NodeSet if grouping subnets
func isInternalOfRequiredType(ep EndpointElem, groupVsi bool) bool {
if groupVsi { // groups vsis Nodes
if _, ok := ep.(Node); !ok {
return false
}
} else { // groups subnets NodeSets
if _, ok := ep.(NodeSet); !ok {
return false
}
}
return true
}

// groups src/targets for either Vsis or Subnets
func (g *GroupConnLines) groupLinesByKey(srcGrouping, groupVsi bool) (res []*GroupedConnLine,
groupingSrcOrDst map[string][]*GroupedConnLine) {
Expand All @@ -253,24 +268,22 @@ func (g *GroupConnLines) groupLinesByKey(srcGrouping, groupVsi bool) (res []*Gro
// populate map groupingSrcOrDst
for _, line := range g.GroupedLines {
srcOrDst, dstOrSrc := line.getSrcOrDst(srcGrouping), line.getSrcOrDst(!srcGrouping)
if groupVsi { // groups vsis Nodes
if _, ok := srcOrDst.(Node); !ok {
res = append(res, line)
continue
}
} else { // groups subnets NodeSets
if _, ok := srcOrDst.(NodeSet); !ok {
res = append(res, line)
continue
}
if !isInternalOfRequiredType(srcOrDst, groupVsi) {
res = append(res, line)
continue
}
key := dstOrSrc.Name() + ";" + line.Conn
key := getKeyOfGroupConnLines(dstOrSrc, line.Conn)
if _, ok := groupingSrcOrDst[key]; !ok {
groupingSrcOrDst[key] = []*GroupedConnLine{}
}
groupingSrcOrDst[key] = append(groupingSrcOrDst[key], line)
}
return res, groupingSrcOrDst
newGroupingSrcOrDst := g.extendGroupingSelfLoops(groupingSrcOrDst, srcGrouping)
return res, newGroupingSrcOrDst
}

func getKeyOfGroupConnLines(ep EndpointElem, connection string) string {
return ep.Name() + commaSeparator + connection
}

// assuming the g.groupedLines was already initialized by previous step groupExternalAddresses()
Expand Down
Loading

0 comments on commit 4af4337

Please sign in to comment.