Skip to content

Commit

Permalink
Export Generated BGP Configuration Code
Browse files Browse the repository at this point in the history
Move internal/pkg/config -> pkg/config/oc

Background: #2593
  • Loading branch information
wenovus authored and fujita committed Sep 30, 2023
1 parent 8bfcc66 commit aa0cf39
Show file tree
Hide file tree
Showing 30 changed files with 977 additions and 977 deletions.
4 changes: 2 additions & 2 deletions cmd/gobgp/neighbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (
"golang.org/x/text/language"

api "github.com/osrg/gobgp/v3/api"
"github.com/osrg/gobgp/v3/internal/pkg/config"
"github.com/osrg/gobgp/v3/pkg/apiutil"
"github.com/osrg/gobgp/v3/pkg/config/oc"
"github.com/osrg/gobgp/v3/pkg/packet/bgp"
)

Expand Down Expand Up @@ -1283,7 +1283,7 @@ func modNeighbor(cmdType string, args []string) error {

getNeighborAddress := func() (string, error) {
if unnumbered {
return config.GetIPv6LinkLocalNeighborAddress(m["interface"][0])
return oc.GetIPv6LinkLocalNeighborAddress(m["interface"][0])
}
return m[""][0], nil
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/gobgp/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import (
"github.com/spf13/cobra"

api "github.com/osrg/gobgp/v3/api"
"github.com/osrg/gobgp/v3/internal/pkg/config"
"github.com/osrg/gobgp/v3/internal/pkg/table"
"github.com/osrg/gobgp/v3/pkg/apiutil"
"github.com/osrg/gobgp/v3/pkg/config/oc"
"github.com/osrg/gobgp/v3/pkg/packet/bgp"
)

Expand Down Expand Up @@ -251,7 +251,7 @@ func parsePrefixSet(args []string) (*api.DefinedSet, error) {
if len(args) > 1 {
mask = args[1]
}
min, max, err := config.ParseMaskLength(args[0], mask)
min, max, err := oc.ParseMaskLength(args[0], mask)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -779,11 +779,11 @@ func modCondition(name, op string, args []string) error {
}
switch strings.ToLower(args[0]) {
case "valid":
stmt.Conditions.RpkiResult = int32(config.RpkiValidationResultTypeToIntMap[config.RPKI_VALIDATION_RESULT_TYPE_VALID])
stmt.Conditions.RpkiResult = int32(oc.RpkiValidationResultTypeToIntMap[oc.RPKI_VALIDATION_RESULT_TYPE_VALID])
case "invalid":
stmt.Conditions.RpkiResult = int32(config.RpkiValidationResultTypeToIntMap[config.RPKI_VALIDATION_RESULT_TYPE_INVALID])
stmt.Conditions.RpkiResult = int32(oc.RpkiValidationResultTypeToIntMap[oc.RPKI_VALIDATION_RESULT_TYPE_INVALID])
case "not-found":
stmt.Conditions.RpkiResult = int32(config.RpkiValidationResultTypeToIntMap[config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND])
stmt.Conditions.RpkiResult = int32(oc.RpkiValidationResultTypeToIntMap[oc.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND])
default:
return fmt.Errorf("%s rpki { valid | invalid | not-found }", usage)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/pkg/table/destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import (
"net"
"sort"

"github.com/osrg/gobgp/v3/internal/pkg/config"
"github.com/osrg/gobgp/v3/pkg/config/oc"
"github.com/osrg/gobgp/v3/pkg/log"
"github.com/osrg/gobgp/v3/pkg/packet/bgp"
)

var SelectionOptions config.RouteSelectionOptionsConfig
var UseMultiplePaths config.UseMultiplePathsConfig
var SelectionOptions oc.RouteSelectionOptionsConfig
var UseMultiplePaths oc.UseMultiplePathsConfig

type BestPathReason uint8

Expand Down Expand Up @@ -118,7 +118,7 @@ func (i *PeerInfo) String() string {
return s.String()
}

func NewPeerInfo(g *config.Global, p *config.Neighbor) *PeerInfo {
func NewPeerInfo(g *oc.Global, p *oc.Neighbor) *PeerInfo {
clusterID := net.ParseIP(string(p.RouteReflector.State.RouteReflectorClusterId)).To4()
// exclude zone info
naddr, _ := net.ResolveIPAddr("ip", p.State.NeighborAddress)
Expand Down
18 changes: 9 additions & 9 deletions internal/pkg/table/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"sort"
"time"

"github.com/osrg/gobgp/v3/internal/pkg/config"
"github.com/osrg/gobgp/v3/pkg/config/oc"
"github.com/osrg/gobgp/v3/pkg/log"
"github.com/osrg/gobgp/v3/pkg/packet/bgp"
)
Expand Down Expand Up @@ -121,7 +121,7 @@ var IntToRpkiValidationReasonTypeMap = map[int]RpkiValidationReasonType{
}

type Validation struct {
Status config.RpkiValidationResultType
Status oc.RpkiValidationResultType
Reason RpkiValidationReasonType
Matched []*ROA
UnmatchedAs []*ROA
Expand Down Expand Up @@ -194,7 +194,7 @@ func cloneAsPath(asAttr *bgp.PathAttributeAsPath) *bgp.PathAttributeAsPath {
return bgp.NewPathAttributeAsPath(newASparams)
}

func UpdatePathAttrs(logger log.Logger, global *config.Global, peer *config.Neighbor, info *PeerInfo, original *Path) *Path {
func UpdatePathAttrs(logger log.Logger, global *oc.Global, peer *oc.Neighbor, info *PeerInfo, original *Path) *Path {
if peer.RouteServer.Config.RouteServerClient {
return original
}
Expand All @@ -208,7 +208,7 @@ func UpdatePathAttrs(logger log.Logger, global *config.Global, peer *config.Neig
} else {
switch a.GetType() {
case bgp.BGP_ATTR_TYPE_CLUSTER_LIST, bgp.BGP_ATTR_TYPE_ORIGINATOR_ID:
if !(peer.State.PeerType == config.PEER_TYPE_INTERNAL && peer.RouteReflector.Config.RouteReflectorClient) {
if !(peer.State.PeerType == oc.PEER_TYPE_INTERNAL && peer.RouteReflector.Config.RouteReflectorClient) {
// send these attributes to only rr clients
path.delPathAttr(a.GetType())
}
Expand All @@ -218,7 +218,7 @@ func UpdatePathAttrs(logger log.Logger, global *config.Global, peer *config.Neig

localAddress := info.LocalAddress
nexthop := path.GetNexthop()
if peer.State.PeerType == config.PEER_TYPE_EXTERNAL {
if peer.State.PeerType == oc.PEER_TYPE_EXTERNAL {
// NEXTHOP handling
if !path.IsLocal() || nexthop.IsUnspecified() {
path.SetNexthop(localAddress)
Expand All @@ -239,7 +239,7 @@ func UpdatePathAttrs(logger log.Logger, global *config.Global, peer *config.Neig
path.delPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
}

} else if peer.State.PeerType == config.PEER_TYPE_INTERNAL {
} else if peer.State.PeerType == oc.PEER_TYPE_INTERNAL {
// NEXTHOP handling for iBGP
// if the path generated locally set local address as nexthop.
// if not, don't modify it.
Expand Down Expand Up @@ -713,20 +713,20 @@ func isPrivateAS(as uint32) bool {
return (64512 <= as && as <= 65534) || (4200000000 <= as && as <= 4294967294)
}

func (path *Path) RemovePrivateAS(localAS uint32, option config.RemovePrivateAsOption) {
func (path *Path) RemovePrivateAS(localAS uint32, option oc.RemovePrivateAsOption) {
original := path.GetAsPath()
if original == nil {
return
}
switch option {
case config.REMOVE_PRIVATE_AS_OPTION_ALL, config.REMOVE_PRIVATE_AS_OPTION_REPLACE:
case oc.REMOVE_PRIVATE_AS_OPTION_ALL, oc.REMOVE_PRIVATE_AS_OPTION_REPLACE:
newASParams := make([]bgp.AsPathParamInterface, 0, len(original.Value))
for _, param := range original.Value {
asList := param.GetAS()
newASParam := make([]uint32, 0, len(asList))
for _, as := range asList {
if isPrivateAS(as) {
if option == config.REMOVE_PRIVATE_AS_OPTION_REPLACE {
if option == oc.REMOVE_PRIVATE_AS_OPTION_REPLACE {
newASParam = append(newASParam, localAS)
}
} else {
Expand Down
6 changes: 3 additions & 3 deletions internal/pkg/table/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
"time"

"github.com/osrg/gobgp/v3/internal/pkg/config"
"github.com/osrg/gobgp/v3/pkg/config/oc"
"github.com/osrg/gobgp/v3/pkg/packet/bgp"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -335,14 +335,14 @@ func TestRemovePrivateAS(t *testing.T) {
aspath := bgp.NewPathAttributeAsPath(aspathParam)
nlri := bgp.NewIPAddrPrefix(24, "30.30.30.0")
path := NewPath(nil, nlri, false, []bgp.PathAttributeInterface{aspath}, time.Now(), false)
path.RemovePrivateAS(10, config.REMOVE_PRIVATE_AS_OPTION_ALL)
path.RemovePrivateAS(10, oc.REMOVE_PRIVATE_AS_OPTION_ALL)
list := path.GetAsList()
assert.Equal(t, len(list), 2)
assert.Equal(t, list[0], uint32(1))
assert.Equal(t, list[1], uint32(2))

path = NewPath(nil, nlri, false, []bgp.PathAttributeInterface{aspath}, time.Now(), false)
path.RemovePrivateAS(10, config.REMOVE_PRIVATE_AS_OPTION_REPLACE)
path.RemovePrivateAS(10, oc.REMOVE_PRIVATE_AS_OPTION_REPLACE)
list = path.GetAsList()
assert.Equal(t, len(list), 4)
assert.Equal(t, list[0], uint32(10))
Expand Down
Loading

0 comments on commit aa0cf39

Please sign in to comment.