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

Support md output format with all_subnets analysis type #314

Merged
merged 6 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion cmd/analyzer/parse_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var supportedOutputFormatsMap = map[string]bool{
// supportedAnalysisTypesMap is a map from analysis type to its list of supported output formats
var supportedAnalysisTypesMap = map[string][]string{
allEndpoints: {TEXTFormat, MDFormat, JSONFormat, DRAWIOFormat, ARCHDRAWIOFormat, DEBUGFormat},
allSubnets: {TEXTFormat, JSONFormat, DRAWIOFormat, ARCHDRAWIOFormat},
allSubnets: {TEXTFormat, MDFormat, JSONFormat, DRAWIOFormat, ARCHDRAWIOFormat},
singleSubnet: {TEXTFormat},
allEndpointsDiff: {TEXTFormat, MDFormat},
allSubnetsDiff: {TEXTFormat, MDFormat},
Expand Down
10 changes: 10 additions & 0 deletions pkg/ibmvpc/analysis_output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ func (tt *vpcGeneralTest) initTest() {
}

var tests = []*vpcGeneralTest{
{
name: "acl_testing5",
useCases: []vpcmodel.OutputUseCase{vpcmodel.AllSubnets},
format: vpcmodel.MD,
},
{
name: "acl_testing5_old",
useCases: []vpcmodel.OutputUseCase{vpcmodel.AllSubnets},
format: vpcmodel.MD,
},
{
name: "acl_testing5",
useCases: []vpcmodel.OutputUseCase{vpcmodel.AllSubnets},
Expand Down
20 changes: 20 additions & 0 deletions pkg/ibmvpc/examples/acl_testing5_all_vpcs_subnetsBased_withPGW.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Connectivity for VPC test-vpc-ky1
## Subnets connectivity report
| src | dst | conn |
|-----|-----|------|
| sub1-1-ky | Public Internet 8.8.8.8/32 | protocol: UDP dst-ports: 53 |
| sub1-1-ky | sub1-2-ky | protocol: TCP |
| sub1-1-ky | sub1-3-ky | protocol: TCP |
| sub1-1-ky | sub3-1-ky | protocol: ICMP icmp-type: 0 icmp-code: 0 |
| sub1-2-ky | sub1-1-ky | protocol: TCP |
| sub1-2-ky | sub1-3-ky | protocol: TCP |
| sub1-3-ky | sub1-1-ky | protocol: TCP |
| sub1-3-ky | sub1-2-ky | protocol: TCP |
| sub2-1-ky | Public Internet 8.8.8.8/32 | protocol: UDP dst-ports: 53 |
| sub2-1-ky | sub2-2-ky | All Connections |
| sub2-1-ky | sub3-1-ky | protocol: ICMP icmp-type: 0 icmp-code: 0; protocol: TCP src-ports: 443 |
| sub2-2-ky | sub2-1-ky | All Connections |
| sub3-1-ky | sub1-1-ky | protocol: ICMP icmp-type: 0 icmp-code: 0 |
| sub3-1-ky | sub2-1-ky | protocol: ICMP icmp-type: 0 icmp-code: 0; protocol: TCP dst-ports: 443 |

connections are stateful unless marked with *
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Connectivity for VPC test-vpc-ky
## Subnets connectivity report
| src | dst | conn |
|-----|-----|------|
| sub1-1-ky | Public Internet 8.8.8.8/32 | protocol: UDP dst-ports: 53 |
| sub1-1-ky | sub1-2-ky | protocol: TCP |
| sub1-1-ky | sub1-3-ky | protocol: TCP |
| sub1-2-ky | sub1-1-ky | protocol: TCP |
| sub1-2-ky | sub1-3-ky | protocol: TCP |
| sub1-3-ky | sub1-1-ky | protocol: TCP |
| sub1-3-ky | sub1-2-ky | protocol: TCP |
| sub2-1-ky | Public Internet 8.8.8.8/32 | protocol: UDP dst-ports: 53 |
| sub2-1-ky | sub2-2-ky | All Connections |
| sub2-2-ky | sub2-1-ky | All Connections |

connections are stateful unless marked with *
25 changes: 14 additions & 11 deletions pkg/vpcmodel/mdOutput.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type MDoutputFormatter struct {

const (
mdDefaultTitle = "## Endpoint connectivity report"
mdSubnetsTitle = "## Subnets connectivity report"
mdDefaultHeader = "| src | dst | conn |\n|-----|-----|------|"
mdEndpointsDiffTitle = "## Endpoints diff report"
mdSubnetsDiffTitle = "## Subnets diff report"
Expand All @@ -38,11 +39,15 @@ func (m *MDoutputFormatter) WriteOutput(c1, c2 *VPCConfig,
return nil, err
}
out = "# " + out
var lines []string
var connLines []string
switch uc {
case AllEndpoints:
lines := []string{mdDefaultTitle, mdDefaultHeader}
connLines := m.getGroupedOutput(conn)
out += linesToOutput(connLines, lines)
lines = []string{mdDefaultTitle, mdDefaultHeader}
connLines = m.getGroupedOutput(conn.GroupedConnectivity)
case AllSubnets:
lines = []string{mdSubnetsTitle, mdDefaultHeader}
connLines = m.getGroupedOutput(subnetsConn.GroupedConnectivity)
case SubnetsDiff, EndpointsDiff:
var mdTitle, mdHeader string
if uc == EndpointsDiff {
Expand All @@ -52,14 +57,12 @@ func (m *MDoutputFormatter) WriteOutput(c1, c2 *VPCConfig,
mdTitle = mdSubnetsDiffTitle
mdHeader = mdSubnetsDiffHeader
}
lines := []string{mdTitle, mdHeader}
connLines := m.getGroupedDiffOutput(cfgsDiff)
out += linesToOutput(connLines, lines)
case AllSubnets:
return nil, errors.New("SubnetLevel use case not supported for md format currently ")
lines = []string{mdTitle, mdHeader}
connLines = m.getGroupedDiffOutput(cfgsDiff)
case SingleSubnet:
return nil, errors.New("DebugSubnet use case not supported for md format currently ")
}
out += linesToOutput(connLines, lines)

_, err = WriteToFile(out, outFile)
return &SingleAnalysisOutput{Output: out, VPC1Name: c1.VPC.Name(), VPC2Name: v2Name, format: MD}, err
Expand All @@ -73,9 +76,9 @@ func linesToOutput(connLines, lines []string) string {
return out
}

func (m *MDoutputFormatter) getGroupedOutput(conn *VPCConnectivity) []string {
lines := make([]string, len(conn.GroupedConnectivity.GroupedLines))
for i, line := range conn.GroupedConnectivity.GroupedLines {
func (m *MDoutputFormatter) getGroupedOutput(connLines *GroupConnLines) []string {
lines := make([]string, len(connLines.GroupedLines))
for i, line := range connLines.GroupedLines {
lines[i] = getGroupedMDLine(line)
}
return lines
Expand Down