From c77e8889b059e2fa01d1391bd65b84352e54028d Mon Sep 17 00:00:00 2001 From: ola saadi <152963690+olasaadi99@users.noreply.github.com> Date: Sun, 14 Jan 2024 13:22:29 +0200 Subject: [PATCH] Support md output format with all_subnets analysis type (#314) --------- Signed-off-by: Ola Saadi --- cmd/analyzer/parse_args.go | 2 +- pkg/ibmvpc/analysis_output_test.go | 10 ++++++++ ..._testing5_all_vpcs_subnetsBased_withPGW.md | 20 +++++++++++++++ ...ting5_old_all_vpcs_subnetsBased_withPGW.md | 16 ++++++++++++ pkg/vpcmodel/mdOutput.go | 25 +++++++++++-------- 5 files changed, 61 insertions(+), 12 deletions(-) create mode 100644 pkg/ibmvpc/examples/acl_testing5_all_vpcs_subnetsBased_withPGW.md create mode 100644 pkg/ibmvpc/examples/acl_testing5_old_all_vpcs_subnetsBased_withPGW.md diff --git a/cmd/analyzer/parse_args.go b/cmd/analyzer/parse_args.go index e0c7862db..a0e24d541 100644 --- a/cmd/analyzer/parse_args.go +++ b/cmd/analyzer/parse_args.go @@ -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}, diff --git a/pkg/ibmvpc/analysis_output_test.go b/pkg/ibmvpc/analysis_output_test.go index cd3c0dcdf..077bf539a 100644 --- a/pkg/ibmvpc/analysis_output_test.go +++ b/pkg/ibmvpc/analysis_output_test.go @@ -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}, diff --git a/pkg/ibmvpc/examples/acl_testing5_all_vpcs_subnetsBased_withPGW.md b/pkg/ibmvpc/examples/acl_testing5_all_vpcs_subnetsBased_withPGW.md new file mode 100644 index 000000000..651d5bd9d --- /dev/null +++ b/pkg/ibmvpc/examples/acl_testing5_all_vpcs_subnetsBased_withPGW.md @@ -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 * diff --git a/pkg/ibmvpc/examples/acl_testing5_old_all_vpcs_subnetsBased_withPGW.md b/pkg/ibmvpc/examples/acl_testing5_old_all_vpcs_subnetsBased_withPGW.md new file mode 100644 index 000000000..c2f3eba91 --- /dev/null +++ b/pkg/ibmvpc/examples/acl_testing5_old_all_vpcs_subnetsBased_withPGW.md @@ -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 * diff --git a/pkg/vpcmodel/mdOutput.go b/pkg/vpcmodel/mdOutput.go index ad4994ceb..2cecf5e6f 100644 --- a/pkg/vpcmodel/mdOutput.go +++ b/pkg/vpcmodel/mdOutput.go @@ -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" @@ -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 { @@ -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 @@ -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