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

Routing analysis add rt details path #672

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions cmd/analyzer/subcmds/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func pairRoutingAnalysis(src, dst vpcmodel.Node, analyzer *ibmvpc.GlobalRTAnalyz
}
fmt.Printf("path for src %s, dst %s:\n", src.IPBlock().String(), dstIPBlock.String())
fmt.Println(path.String())
fmt.Println(path.StringRTPath())
fmt.Println("")
return nil
}
Expand Down
74 changes: 57 additions & 17 deletions pkg/ibmvpc/egress_routing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ func genConfig(vpc *VPC, subnets []*Subnet,
///////////////////////////////////////////////////////////////////////////////////////////////////

type routesPerSubnets struct {
routesMap map[string][]*route // map from list of subnets to routes in their egress RT
routesMap map[string]*tableSpecForTest // map from list of subnets to routes in their egress RT
}

type tableSpecForTest struct {
tableName string
routesList []*route
}

const comma = ","
Expand All @@ -72,8 +77,8 @@ func subnetsKeyToSubnets(key string, config *vpcmodel.VPCConfig) []*Subnet {
var emptyRoutes = []*route{} // default routing table is empty

var emptyRoutesAllSubnets = &routesPerSubnets{
routesMap: map[string][]*route{
strings.Join([]string{"subnet1", "subnet2", "subnet3"}, comma): emptyRoutes,
routesMap: map[string]*tableSpecForTest{
"subnet1,subnet2,subnet3": {routesList: emptyRoutes, tableName: "defaultEmptyTable"},
},
}

Expand All @@ -84,23 +89,38 @@ var routes1 = []*route{
newRouteNoErr("r4", "0.0.0.0/0", "10.10.1.5", deliver, 2, "zoneB"),
}

var routes2 = []*route{
newRouteNoErr("r1", "0.0.0.0/0", "10.10.1.5", deliver, 2, "zoneA"),
newRouteNoErr("r2", "10.10.0.0/16", "", drop, 2, "zoneA"),
newRouteNoErr("r3", "10.11.0.0/16", "", drop, 2, "zoneB"),
newRouteNoErr("r4", "0.0.0.0/0", "10.10.1.5", deliver, 2, "zoneB"),
}

var routes1PartialSubnets = &routesPerSubnets{
routesMap: map[string][]*route{
"subnet2" + "," + "subnet3": emptyRoutes,
"subnet1": routes1, // changes routing for this subnet
routesMap: map[string]*tableSpecForTest{
"subnet2,subnet3": {routesList: emptyRoutes, tableName: "defaultEmptyTable"},
"subnet1": {routesList: routes1, tableName: "routes1Table"}, // changes routing for this subnet
},
}

var routes2PartialSubnets = &routesPerSubnets{
routesMap: map[string]*tableSpecForTest{
"subnet2,subnet3": {routesList: emptyRoutes, tableName: "defaultEmptyTable"},
"subnet1": {routesList: routes2, tableName: "routes2Table"}, // changes routing for this subnet
},
}

func newEgressRTFromRoutes(rps *routesPerSubnets, config *vpcmodel.VPCConfig, vpc *VPC) []*egressRoutingTable {
res := []*egressRoutingTable{}
for subnetsKey, routes := range rps.routesMap {
for subnetsKey, tableSpec := range rps.routesMap {
egressRT := &egressRoutingTable{}
implicitRT := &systemImplicitRT{vpc: vpc, config: systemRTConfigFromVPCConfig(config), vpcConfig: config}
if rt, err := newRoutingTable(routes, implicitRT, &vpcmodel.VPCResource{}); err == nil {
if rt, err := newRoutingTable(tableSpec.routesList, implicitRT, &vpcmodel.VPCResource{}); err == nil {
egressRT.routingTable = *rt
}
egressRT.vpc = vpc
egressRT.subnets = subnetsKeyToSubnets(subnetsKey, config)
egressRT.ResourceName = tableSpec.tableName
res = append(res, egressRT)
}
return res
Expand Down Expand Up @@ -164,13 +184,16 @@ func (test *testRTAnalyzer) run(t *testing.T) {
require.Contains(t, err1.Error(), test.expectedErr)
}

rtPathStr := path1.StringRTPath()
fmt.Printf("%s, %s \n", test.testName, rtPathStr)

// check path
if test.expectedPath.Empty() {
require.Nil(t, path1)
require.Nil(t, path1.EndpointsPath)
} else {
require.NotNil(t, path1)
fmt.Printf("expected path: %s\n actual path: %s\n", test.expectedPath.String(), path1.String())
require.True(t, path1.Equal(test.expectedPath))
require.True(t, path1.EndpointsPath.Equal(test.expectedPath))
}
}

Expand All @@ -183,7 +206,8 @@ var testRTAnalyzerTests = []*testRTAnalyzer{
// good path tests - with emptyRoutesAllSubnets (default routing table to all subnets )
// TODO: identify dest as node (internal/external), and improve address/name str
{
testName: "path from internal src to internal dst in the same vpc, different subnet",
testName: "path from internal src to internal dst in the same vpc, different subnet",
// rt path: [rt:defaultEmptyTable, action: delegate, matched: false]
rps: emptyRoutesAllSubnets,
srcIP: "10.10.1.8",
dstIP: "10.10.3.8",
Expand All @@ -194,7 +218,8 @@ var testRTAnalyzerTests = []*testRTAnalyzer{
},

{
testName: "dest is public internet address, path is through pgw (implicit RT)",
testName: "dest is public internet address, path is through pgw (implicit RT)",
// rt path: [rt:defaultEmptyTable, action: delegate, matched: false]
rps: emptyRoutesAllSubnets,
srcIP: "10.10.1.8",
dstIP: "8.8.8.8",
Expand All @@ -205,7 +230,8 @@ var testRTAnalyzerTests = []*testRTAnalyzer{
},

{
testName: "dest is public internet address, path is through fip (implicit RT)",
testName: "dest is public internet address, path is through fip (implicit RT)",
// rt path: [rt:defaultEmptyTable, action: delegate, matched: false]
rps: emptyRoutesAllSubnets,
srcIP: "10.10.0.5",
dstIP: "8.8.8.8",
Expand All @@ -217,7 +243,8 @@ var testRTAnalyzerTests = []*testRTAnalyzer{

// good path tests - with routes1PartialSubnets (not only default routing table to all subnets )
{
testName: "dest is public internet address, path is redirected through subnet's RT (subnet1)",
testName: "dest is public internet address, path is redirected through subnet's RT (subnet1)",
// rt path: [rt:routes1Table, action: deliver, matched: true]
rps: routes1PartialSubnets,
srcIP: "10.10.1.8",
dstIP: "8.8.8.8",
Expand All @@ -228,7 +255,8 @@ var testRTAnalyzerTests = []*testRTAnalyzer{
// TODO: path from 10.10.1.5 -> external address : should be available via another network interface of the VSI (10.10.0.5) and then FIP ?
},
{
testName: "dest is vpc internal address, path is delegated through subnet's RT (subnet1)",
testName: "dest is vpc internal address, path is delegated through subnet's RT (subnet1)",
// rt path: [rt:routes1Table, action: delegate, matched: true]
rps: routes1PartialSubnets,
srcIP: "10.10.1.8",
dstIP: "10.10.3.8",
Expand All @@ -238,7 +266,18 @@ var testRTAnalyzerTests = []*testRTAnalyzer{
/*{IPBlock: newIPBlockFromCIDROrAddressWithoutValidation("10.10.3.8")}*/}), // (derived from system implicit RT )
},
{
testName: "dest is public internet address, path is through pgw (default RT) (subnet2)",
testName: "dest is vpc internal address, path is drop through subnet's RT (subnet1)",
// rt path: "[rt:routes2Table, action: drop, matched: true]"
rps: routes2PartialSubnets,
srcIP: "10.10.1.8",
dstIP: "10.10.3.8",
expectedErr: "",
expectedPath: vpcmodel.Path([]*vpcmodel.Endpoint{{VpcResource: newNetIntForTest("vsi1", "10.10.1.8", "node1")}}),
// (derived from system implicit RT )
},
{
testName: "dest is public internet address, path is through pgw (default RT) (subnet2)",
// rt path [rt:defaultEmptyTable, action: delegate, matched: false]
rps: routes1PartialSubnets,
srcIP: "10.10.3.8",
dstIP: "8.8.8.8",
Expand All @@ -251,7 +290,8 @@ var testRTAnalyzerTests = []*testRTAnalyzer{

// bad path tests
{
testName: "src is not a valid internal node by address",
testName: "src is not a valid internal node by address",
// rt path: empty
rps: emptyRoutesAllSubnets,
srcIP: "10.10.2.8",
dstIP: "10.10.3.8",
Expand Down
2 changes: 1 addition & 1 deletion pkg/ibmvpc/ingress_routing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ func (tga *testGlobalAnalyzer) run(t *testing.T, globalAnalyzer *GlobalRTAnalyze
path, err := globalAnalyzer.GetRoutingPath(srcNode, dstIPBlock)
fmt.Printf("path: %s\n", path.String())
require.Nil(t, err)
require.True(t, path.Equal(tga.expectedPath))
require.True(t, path.EndpointsPath.Equal(tga.expectedPath))
fmt.Println("done")
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/ibmvpc/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,13 @@ func getRoutes(rt *datamodel.RoutingTable) (res []*route, err error) {

func parseAction(action string) (routingAction, error) {
switch action {
case "deliver":
case deliverStr:
return deliver, nil
case "drop":
case dropStr:
return drop, nil
case "delegate":
case delegateStr:
return delegate, nil
case "delegate_vpc":
case delegateVPCStr:
return delegateVPC, nil
}
return drop, fmt.Errorf("unknown route action: %s", action)
Expand Down
Loading