diff --git a/bgp/config_test.go b/bgp/config_test.go index cb1e8afa..a7aa0060 100644 --- a/bgp/config_test.go +++ b/bgp/config_test.go @@ -82,6 +82,10 @@ func TestIntendedToGoBGPPolicies(t *testing.T) { v4Stmt.GetOrCreateActions().GetOrCreateBgpActions().GetOrCreateSetCommunity().SetOptions(oc.BgpPolicy_BgpSetCommunityOptionType_REPLACE) v4Stmt.GetOrCreateActions().SetPolicyResult(oc.RoutingPolicy_PolicyResultType_ACCEPT_ROUTE) + // origin + v4Stmt.GetOrCreateConditions().GetOrCreateBgpConditions().SetOriginEq(oc.BgpTypes_BgpOriginAttrType_EGP) + v4Stmt.GetOrCreateActions().GetOrCreateBgpActions().SetSetRouteOrigin(oc.BgpTypes_BgpOriginAttrType_IGP) + bgpoc.GetOrCreateNeighbor("1.1.1.1").GetOrCreateApplyPolicy().SetExportPolicy([]string{policyName}) bgpoc.GetOrCreateNeighbor("1.1.1.1").GetOrCreateApplyPolicy().SetImportPolicy([]string{policyName}) bgpoc.GetOrCreateNeighbor("1.1.1.1").GetOrCreateApplyPolicy().SetDefaultImportPolicy(oc.RoutingPolicy_DefaultPolicyType_ACCEPT_ROUTE) @@ -209,7 +213,7 @@ func TestIntendedToGoBGPPolicies(t *testing.T) { AsPathSet: "", MatchSetOptions: "any", }, MedEq: 0x0, - OriginEq: "", + OriginEq: "egp", NextHopInList: []string(nil), AfiSafiInList: []gobgpoc.AfiSafiType(nil), LocalPrefEq: 0x0, @@ -229,7 +233,7 @@ func TestIntendedToGoBGPPolicies(t *testing.T) { BgpActions: gobgpoc.BgpActions{SetAsPathPrepend: gobgpoc.SetAsPathPrepend{RepeatN: 0x0, As: "0"}, SetCommunity: gobgpoc.SetCommunity{SetCommunityMethod: gobgpoc.SetCommunityMethod{CommunitiesList: []string(nil), CommunitySetRef: ""}, Options: "replace"}, SetExtCommunity: gobgpoc.SetExtCommunity{SetExtCommunityMethod: gobgpoc.SetExtCommunityMethod{CommunitiesList: []string(nil), ExtCommunitySetRef: ""}, Options: ""}, - SetRouteOrigin: "", + SetRouteOrigin: "igp", SetLocalPref: 0x0, SetNextHop: "", SetMed: "", @@ -329,7 +333,7 @@ func TestIntendedToGoBGPPolicies(t *testing.T) { AsPathSet: "", MatchSetOptions: "any", }, MedEq: 0x0, - OriginEq: "", + OriginEq: "egp", NextHopInList: []string(nil), AfiSafiInList: []gobgpoc.AfiSafiType(nil), LocalPrefEq: 0x0, @@ -349,7 +353,7 @@ func TestIntendedToGoBGPPolicies(t *testing.T) { BgpActions: gobgpoc.BgpActions{SetAsPathPrepend: gobgpoc.SetAsPathPrepend{RepeatN: 0x0, As: "0"}, SetCommunity: gobgpoc.SetCommunity{SetCommunityMethod: gobgpoc.SetCommunityMethod{CommunitiesList: []string(nil), CommunitySetRef: ""}, Options: "replace"}, SetExtCommunity: gobgpoc.SetExtCommunity{SetExtCommunityMethod: gobgpoc.SetExtCommunityMethod{CommunitiesList: []string(nil), ExtCommunitySetRef: ""}, Options: ""}, - SetRouteOrigin: "", + SetRouteOrigin: "igp", SetLocalPref: 0x0, SetNextHop: "", SetMed: "", diff --git a/bgp/gobgp.go b/bgp/gobgp.go index 6dc818eb..cb224167 100644 --- a/bgp/gobgp.go +++ b/bgp/gobgp.go @@ -642,12 +642,12 @@ func (t *bgpTask) populateRIBAttrs(path *api.Path, rib *oc.NetworkInstance_Proto } case *api.OriginAttribute: hasOrigin = true - switch origin := m.GetOrigin(); origin { - case 0: + switch origin := m.GetOrigin(); int(origin) { + case gobgpoc.BGP_ORIGIN_ATTR_TYPE_IGP.ToInt(): attrSet.origin = oc.BgpTypes_BgpOriginAttrType_IGP - case 1: + case gobgpoc.BGP_ORIGIN_ATTR_TYPE_EGP.ToInt(): attrSet.origin = oc.BgpTypes_BgpOriginAttrType_EGP - case 2: + case gobgpoc.BGP_ORIGIN_ATTR_TYPE_INCOMPLETE.ToInt(): attrSet.origin = oc.BgpTypes_BgpOriginAttrType_INCOMPLETE default: log.Errorf("BGP: Unrecognized origin attribute value: %v", origin) diff --git a/bgp/ocgobgp.go b/bgp/ocgobgp.go index 8bbafa01..ee3a0001 100644 --- a/bgp/ocgobgp.go +++ b/bgp/ocgobgp.go @@ -113,6 +113,7 @@ func convertPolicyDefinition(policy *oc.RoutingPolicy_PolicyDefinition, neighAdd MatchSetOptions: convertMatchSetOptionsType(statement.GetConditions().GetBgpConditions().GetMatchAsPathSet().GetMatchSetOptions()), }, RouteType: convertRouteType(statement.GetConditions().GetBgpConditions().GetRouteType()), + OriginEq: convertOrigin(statement.GetConditions().GetBgpConditions().GetOriginEq()), }, }, Actions: gobgpoc.Actions{ @@ -130,6 +131,7 @@ func convertPolicyDefinition(policy *oc.RoutingPolicy_PolicyDefinition, neighAdd RepeatN: statement.GetActions().GetBgpActions().GetSetAsPathPrepend().GetRepeatN(), As: strconv.FormatUint(uint64(statement.GetActions().GetBgpActions().GetSetAsPathPrepend().GetAsn()), 10), }, + SetRouteOrigin: convertOrigin(statement.GetActions().GetBgpActions().GetSetRouteOrigin()), }, }, }) @@ -365,3 +367,16 @@ func convertSegmentTypeToOC(segmentType api.AsSegment_Type) oc.E_BgpTypes_AsPath return oc.BgpTypes_AsPathSegmentType_UNSET } } + +func convertOrigin(origin oc.E_BgpTypes_BgpOriginAttrType) gobgpoc.BgpOriginAttrType { + switch origin { + case oc.BgpTypes_BgpOriginAttrType_EGP: + return gobgpoc.BGP_ORIGIN_ATTR_TYPE_EGP + case oc.BgpTypes_BgpOriginAttrType_IGP: + return gobgpoc.BGP_ORIGIN_ATTR_TYPE_IGP + case oc.BgpTypes_BgpOriginAttrType_INCOMPLETE: + return gobgpoc.BGP_ORIGIN_ATTR_TYPE_INCOMPLETE + default: + return "" + } +} diff --git a/bgp/tests/local_tests/policy_test.go b/bgp/tests/local_tests/policy_test.go index da91c1bd..05252d67 100644 --- a/bgp/tests/local_tests/policy_test.go +++ b/bgp/tests/local_tests/policy_test.go @@ -206,6 +206,9 @@ func testPolicyAux(t *testing.T, testspec *PolicyTestCase, dut1, dut2, dut3, dut } for _, routeTest := range testspec.routeTests { + if routeTest.Input.ReachPrefix == "" { + continue + } if routeTest.RouteTest != nil { // Install regular test route into DUT1. route := &oc.NetworkInstance_Protocol_Static{ @@ -257,6 +260,9 @@ func testPolicyAux(t *testing.T, testspec *PolicyTestCase, dut1, dut2, dut3, dut } for _, routeTest := range testspec.routeTests { + if routeTest.Input.ReachPrefix == "" { + continue + } if routeTest.RouteTest != nil { testPropagation(t, routeTest.Input, routeTest.RouteTest, dut1, dut2, dut3) testCommunities(t, routeTest.Input, routeTest.RouteTest, dut1, dut2, dut3) diff --git a/bgp/tests/local_tests/set_attributes_test.go b/bgp/tests/local_tests/set_attributes_test.go index befa7d10..e76da0fe 100644 --- a/bgp/tests/local_tests/set_attributes_test.go +++ b/bgp/tests/local_tests/set_attributes_test.go @@ -48,14 +48,18 @@ func singletonPrefixSetName(route string) string { // TestSetAttributes tests setting BGP attributes. func TestSetAttributes(t *testing.T) { routesUnderTest := map[int]string{ - 0: "10.1.0.0/16", - 1: "10.2.0.0/16", - 2: "10.10.0.0/16", - 3: "10.11.0.0/16", - 4: "10.12.0.0/16", - 5: "10.13.0.0/16", - 6: "10.14.0.0/16", - 7: "10.15.0.0/16", + 0: "10.1.0.0/16", + 1: "10.2.0.0/16", + 2: "10.10.0.0/16", + 3: "10.11.0.0/16", + 4: "10.12.0.0/16", + 5: "10.13.0.0/16", + 6: "10.14.0.0/16", + 7: "10.15.0.0/16", + 30: "10.30.0.0/16", + 31: "10.31.0.0/16", + 32: "10.32.0.0/16", + 33: "10.33.0.0/16", } installDefinedSets := func(t *testing.T, dut1, dut2, dut5 *Device) { @@ -680,6 +684,98 @@ func TestSetAttributes(t *testing.T) { }, }, }, + }, { + Input: policytest.TestRoute{ + ReachPrefix: routesUnderTest[30], + }, + RouteTest: &policytest.RoutePathTestCase{ + Description: "Rejected route due to Origin Match", + ExpectedResult: policytest.RouteDiscarded, + PrevAdjRibOutPreAttrs: &oc.NetworkInstance_Protocol_Bgp_Rib_AttrSet{ + Origin: oc.BgpTypes_BgpOriginAttrType_IGP, + }, + PrevAdjRibOutPostAttrs: &oc.NetworkInstance_Protocol_Bgp_Rib_AttrSet{ + Origin: oc.BgpTypes_BgpOriginAttrType_EGP, + }, + AdjRibInPreAttrs: &oc.NetworkInstance_Protocol_Bgp_Rib_AttrSet{ + Origin: oc.BgpTypes_BgpOriginAttrType_EGP, + }, + }, + }, { + Input: policytest.TestRoute{ + ReachPrefix: routesUnderTest[31], + }, + RouteTest: &policytest.RoutePathTestCase{ + Description: "Rejected route due to Origin Match", + ExpectedResult: policytest.RouteDiscarded, + }, + }, { + Input: policytest.TestRoute{ + ReachPrefix: routesUnderTest[32], + }, + RouteTest: &policytest.RoutePathTestCase{ + Description: "Rejected route due to Origin Match", + ExpectedResult: policytest.RouteDiscarded, + PrevAdjRibOutPreAttrs: &oc.NetworkInstance_Protocol_Bgp_Rib_AttrSet{ + Origin: oc.BgpTypes_BgpOriginAttrType_IGP, + }, + PrevAdjRibOutPostAttrs: &oc.NetworkInstance_Protocol_Bgp_Rib_AttrSet{ + Origin: oc.BgpTypes_BgpOriginAttrType_INCOMPLETE, + }, + AdjRibInPreAttrs: &oc.NetworkInstance_Protocol_Bgp_Rib_AttrSet{ + Origin: oc.BgpTypes_BgpOriginAttrType_INCOMPLETE, + }, + }, + }, { + Input: policytest.TestRoute{ + ReachPrefix: routesUnderTest[33], + }, + RouteTest: &policytest.RoutePathTestCase{ + Description: "Accepted route due to Origin Mismatch", + ExpectedResult: policytest.RouteAccepted, + PrevAdjRibOutPreAttrs: &oc.NetworkInstance_Protocol_Bgp_Rib_AttrSet{ + Origin: oc.BgpTypes_BgpOriginAttrType_IGP, + }, + PrevAdjRibOutPostAttrs: &oc.NetworkInstance_Protocol_Bgp_Rib_AttrSet{ + Origin: oc.BgpTypes_BgpOriginAttrType_EGP, + }, + AdjRibInPreAttrs: &oc.NetworkInstance_Protocol_Bgp_Rib_AttrSet{ + Origin: oc.BgpTypes_BgpOriginAttrType_EGP, + }, + AdjRibInPostAttrs: &oc.NetworkInstance_Protocol_Bgp_Rib_AttrSet{ + Origin: oc.BgpTypes_BgpOriginAttrType_EGP, + }, + LocalRibAttrs: &oc.NetworkInstance_Protocol_Bgp_Rib_AttrSet{ + Origin: oc.BgpTypes_BgpOriginAttrType_EGP, + }, + AdjRibOutPreAttrs: &oc.NetworkInstance_Protocol_Bgp_Rib_AttrSet{ + Origin: oc.BgpTypes_BgpOriginAttrType_EGP, + }, + AdjRibOutPostAttrs: &oc.NetworkInstance_Protocol_Bgp_Rib_AttrSet{ + Origin: oc.BgpTypes_BgpOriginAttrType_EGP, + AsSegment: map[uint32]*oc.NetworkInstance_Protocol_Bgp_Rib_AttrSet_AsSegment{ + 0: {Index: ygot.Uint32(0), Member: []uint32{64500}, Type: oc.BgpTypes_AsPathSegmentType_AS_SEQ}, + }, + }, + NextAdjRibInPreAttrs: &oc.NetworkInstance_Protocol_Bgp_Rib_AttrSet{ + Origin: oc.BgpTypes_BgpOriginAttrType_EGP, + AsSegment: map[uint32]*oc.NetworkInstance_Protocol_Bgp_Rib_AttrSet_AsSegment{ + 0: {Index: ygot.Uint32(0), Member: []uint32{64500}, Type: oc.BgpTypes_AsPathSegmentType_AS_SEQ}, + }, + }, + NextAdjRibInPostAttrs: &oc.NetworkInstance_Protocol_Bgp_Rib_AttrSet{ + Origin: oc.BgpTypes_BgpOriginAttrType_EGP, + AsSegment: map[uint32]*oc.NetworkInstance_Protocol_Bgp_Rib_AttrSet_AsSegment{ + 0: {Index: ygot.Uint32(0), Member: []uint32{64500}, Type: oc.BgpTypes_AsPathSegmentType_AS_SEQ}, + }, + }, + NextLocalRibAttrs: &oc.NetworkInstance_Protocol_Bgp_Rib_AttrSet{ + Origin: oc.BgpTypes_BgpOriginAttrType_EGP, + AsSegment: map[uint32]*oc.NetworkInstance_Protocol_Bgp_Rib_AttrSet_AsSegment{ + 0: {Index: ygot.Uint32(0), Member: []uint32{64500}, Type: oc.BgpTypes_AsPathSegmentType_AS_SEQ}, + }, + }, + }, }} testPolicy(t, &PolicyTestCase{ @@ -796,6 +892,34 @@ func TestSetAttributes(t *testing.T) { installDut1ImportStmt = true dut1ImportStmt.GetOrCreateConditions().GetOrCreateBgpConditions().GetOrCreateMatchAsPathSet().SetAsPathSet(rejectASPathSetName2) dut1ImportStmt.GetOrCreateConditions().GetOrCreateBgpConditions().GetOrCreateMatchAsPathSet().SetMatchSetOptions(oc.PolicyTypes_MatchSetOptionsType_ANY) + case 30: + // Set Route Origin and then match on it for rejection. + installDut1ExportStmt = true + dut1ExportStmt.GetOrCreateActions().GetOrCreateBgpActions().SetSetRouteOrigin(oc.BgpTypes_BgpOriginAttrType_EGP) + + installDut1ImportStmt = true + dut1ImportStmt.GetOrCreateConditions().GetOrCreateBgpConditions().SetOriginEq(oc.BgpTypes_BgpOriginAttrType_EGP) + case 31: + // Set Route Origin and then match on it for rejection. + installDut1ExportStmt = true + dut1ExportStmt.GetOrCreateActions().GetOrCreateBgpActions().SetSetRouteOrigin(oc.BgpTypes_BgpOriginAttrType_IGP) + + installDut1ImportStmt = true + dut1ImportStmt.GetOrCreateConditions().GetOrCreateBgpConditions().SetOriginEq(oc.BgpTypes_BgpOriginAttrType_IGP) + case 32: + // Set Route Origin and then match on it for rejection. + installDut1ExportStmt = true + dut1ExportStmt.GetOrCreateActions().GetOrCreateBgpActions().SetSetRouteOrigin(oc.BgpTypes_BgpOriginAttrType_INCOMPLETE) + + installDut1ImportStmt = true + dut1ImportStmt.GetOrCreateConditions().GetOrCreateBgpConditions().SetOriginEq(oc.BgpTypes_BgpOriginAttrType_INCOMPLETE) + case 33: + // Set Route Origin and then match on a different one for rejection. + installDut1ExportStmt = true + dut1ExportStmt.GetOrCreateActions().GetOrCreateBgpActions().SetSetRouteOrigin(oc.BgpTypes_BgpOriginAttrType_EGP) + + installDut1ImportStmt = false + dut1ImportStmt.GetOrCreateConditions().GetOrCreateBgpConditions().SetOriginEq(oc.BgpTypes_BgpOriginAttrType_IGP) } if installDut1ExportStmt { dut1ExportStmt.GetOrCreateActions().SetPolicyResult(oc.RoutingPolicy_PolicyResultType_ACCEPT_ROUTE) diff --git a/go.mod b/go.mod index b03b6827..cb0b0b16 100644 --- a/go.mod +++ b/go.mod @@ -27,7 +27,7 @@ require ( github.com/openconfig/testt v0.0.0-20220311054427-efbb1a32ec07 github.com/openconfig/ygnmi v0.11.1 github.com/openconfig/ygot v0.29.19 - github.com/osrg/gobgp/v3 v3.27.1-0.20240606071546-dace87570846 + github.com/osrg/gobgp/v3 v3.27.1-0.20240613095719-0c8d2054ef43 github.com/p4lang/p4runtime v1.4.0-rc.5.0.20220728214547-13f0d02a521e github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.8.0 diff --git a/go.sum b/go.sum index d578d0b8..b361a27e 100644 --- a/go.sum +++ b/go.sum @@ -1797,8 +1797,8 @@ github.com/openconfig/ygot v0.10.4/go.mod h1:oCQNdXnv7dWc8scTDgoFkauv1wwplJn5Hsp github.com/openconfig/ygot v0.13.2/go.mod h1:kJN0yCXIH07dOXvNBEFm3XxXdnDD5NI6K99tnD5x49c= github.com/openconfig/ygot v0.29.19 h1:3bbAWbCBVjyjHgeROvT38LQ7pAxcjtm7C2vNVj/rvEE= github.com/openconfig/ygot v0.29.19/go.mod h1:8/FXt4tc5wSfYDEJbGGumxmxwJ55Xuv12oO/jCyEins= -github.com/osrg/gobgp/v3 v3.27.1-0.20240606071546-dace87570846 h1:lhc6n8L5Yqm1ZNca+21TQjpXBrl+O3sNwDgU0/407Ms= -github.com/osrg/gobgp/v3 v3.27.1-0.20240606071546-dace87570846/go.mod h1:ZGeSti9mURR/o5hf5R6T1FM5g1yiEBZbhP+TuqYJUpI= +github.com/osrg/gobgp/v3 v3.27.1-0.20240613095719-0c8d2054ef43 h1:HamaGNtGjbXR3iqXr2f5J4b9YXgLEz3DtItZuIVn0vk= +github.com/osrg/gobgp/v3 v3.27.1-0.20240613095719-0c8d2054ef43/go.mod h1:ZGeSti9mURR/o5hf5R6T1FM5g1yiEBZbhP+TuqYJUpI= github.com/p4lang/p4runtime v1.4.0-rc.5.0.20220728214547-13f0d02a521e h1:AfZKoikDXbZ7zWvO/lvCRzLo7i6lM+gNleYVMxPiWyQ= github.com/p4lang/p4runtime v1.4.0-rc.5.0.20220728214547-13f0d02a521e/go.mod h1:m9laObIMXM9N1ElGXijc66/MSM5eheZJLRLxg/TG+fU= github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= diff --git a/repositories.bzl b/repositories.bzl index 4e8c853c..98349b46 100644 --- a/repositories.bzl +++ b/repositories.bzl @@ -1512,8 +1512,8 @@ def go_repositories(): name = "com_github_osrg_gobgp_v3", build_file_proto_mode = "disable", importpath = "github.com/osrg/gobgp/v3", - sum = "h1:lhc6n8L5Yqm1ZNca+21TQjpXBrl+O3sNwDgU0/407Ms=", - version = "v3.27.1-0.20240606071546-dace87570846", + sum = "h1:HamaGNtGjbXR3iqXr2f5J4b9YXgLEz3DtItZuIVn0vk=", + version = "v3.27.1-0.20240613095719-0c8d2054ef43", ) go_repository( name = "com_github_patrickmn_go_cache",