Skip to content

Commit aa0cf39

Browse files
wenovusfujita
authored andcommitted
Export Generated BGP Configuration Code
Move internal/pkg/config -> pkg/config/oc Background: #2593
1 parent 8bfcc66 commit aa0cf39

30 files changed

+977
-977
lines changed

cmd/gobgp/neighbor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import (
3131
"golang.org/x/text/language"
3232

3333
api "github.com/osrg/gobgp/v3/api"
34-
"github.com/osrg/gobgp/v3/internal/pkg/config"
3534
"github.com/osrg/gobgp/v3/pkg/apiutil"
35+
"github.com/osrg/gobgp/v3/pkg/config/oc"
3636
"github.com/osrg/gobgp/v3/pkg/packet/bgp"
3737
)
3838

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

12841284
getNeighborAddress := func() (string, error) {
12851285
if unnumbered {
1286-
return config.GetIPv6LinkLocalNeighborAddress(m["interface"][0])
1286+
return oc.GetIPv6LinkLocalNeighborAddress(m["interface"][0])
12871287
}
12881288
return m[""][0], nil
12891289
}

cmd/gobgp/policy.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ import (
2828
"github.com/spf13/cobra"
2929

3030
api "github.com/osrg/gobgp/v3/api"
31-
"github.com/osrg/gobgp/v3/internal/pkg/config"
3231
"github.com/osrg/gobgp/v3/internal/pkg/table"
3332
"github.com/osrg/gobgp/v3/pkg/apiutil"
33+
"github.com/osrg/gobgp/v3/pkg/config/oc"
3434
"github.com/osrg/gobgp/v3/pkg/packet/bgp"
3535
)
3636

@@ -251,7 +251,7 @@ func parsePrefixSet(args []string) (*api.DefinedSet, error) {
251251
if len(args) > 1 {
252252
mask = args[1]
253253
}
254-
min, max, err := config.ParseMaskLength(args[0], mask)
254+
min, max, err := oc.ParseMaskLength(args[0], mask)
255255
if err != nil {
256256
return nil, err
257257
}
@@ -779,11 +779,11 @@ func modCondition(name, op string, args []string) error {
779779
}
780780
switch strings.ToLower(args[0]) {
781781
case "valid":
782-
stmt.Conditions.RpkiResult = int32(config.RpkiValidationResultTypeToIntMap[config.RPKI_VALIDATION_RESULT_TYPE_VALID])
782+
stmt.Conditions.RpkiResult = int32(oc.RpkiValidationResultTypeToIntMap[oc.RPKI_VALIDATION_RESULT_TYPE_VALID])
783783
case "invalid":
784-
stmt.Conditions.RpkiResult = int32(config.RpkiValidationResultTypeToIntMap[config.RPKI_VALIDATION_RESULT_TYPE_INVALID])
784+
stmt.Conditions.RpkiResult = int32(oc.RpkiValidationResultTypeToIntMap[oc.RPKI_VALIDATION_RESULT_TYPE_INVALID])
785785
case "not-found":
786-
stmt.Conditions.RpkiResult = int32(config.RpkiValidationResultTypeToIntMap[config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND])
786+
stmt.Conditions.RpkiResult = int32(oc.RpkiValidationResultTypeToIntMap[oc.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND])
787787
default:
788788
return fmt.Errorf("%s rpki { valid | invalid | not-found }", usage)
789789
}

internal/pkg/table/destination.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ import (
2323
"net"
2424
"sort"
2525

26-
"github.com/osrg/gobgp/v3/internal/pkg/config"
26+
"github.com/osrg/gobgp/v3/pkg/config/oc"
2727
"github.com/osrg/gobgp/v3/pkg/log"
2828
"github.com/osrg/gobgp/v3/pkg/packet/bgp"
2929
)
3030

31-
var SelectionOptions config.RouteSelectionOptionsConfig
32-
var UseMultiplePaths config.UseMultiplePathsConfig
31+
var SelectionOptions oc.RouteSelectionOptionsConfig
32+
var UseMultiplePaths oc.UseMultiplePathsConfig
3333

3434
type BestPathReason uint8
3535

@@ -118,7 +118,7 @@ func (i *PeerInfo) String() string {
118118
return s.String()
119119
}
120120

121-
func NewPeerInfo(g *config.Global, p *config.Neighbor) *PeerInfo {
121+
func NewPeerInfo(g *oc.Global, p *oc.Neighbor) *PeerInfo {
122122
clusterID := net.ParseIP(string(p.RouteReflector.State.RouteReflectorClusterId)).To4()
123123
// exclude zone info
124124
naddr, _ := net.ResolveIPAddr("ip", p.State.NeighborAddress)

internal/pkg/table/path.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"sort"
2525
"time"
2626

27-
"github.com/osrg/gobgp/v3/internal/pkg/config"
27+
"github.com/osrg/gobgp/v3/pkg/config/oc"
2828
"github.com/osrg/gobgp/v3/pkg/log"
2929
"github.com/osrg/gobgp/v3/pkg/packet/bgp"
3030
)
@@ -121,7 +121,7 @@ var IntToRpkiValidationReasonTypeMap = map[int]RpkiValidationReasonType{
121121
}
122122

123123
type Validation struct {
124-
Status config.RpkiValidationResultType
124+
Status oc.RpkiValidationResultType
125125
Reason RpkiValidationReasonType
126126
Matched []*ROA
127127
UnmatchedAs []*ROA
@@ -194,7 +194,7 @@ func cloneAsPath(asAttr *bgp.PathAttributeAsPath) *bgp.PathAttributeAsPath {
194194
return bgp.NewPathAttributeAsPath(newASparams)
195195
}
196196

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

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

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

716-
func (path *Path) RemovePrivateAS(localAS uint32, option config.RemovePrivateAsOption) {
716+
func (path *Path) RemovePrivateAS(localAS uint32, option oc.RemovePrivateAsOption) {
717717
original := path.GetAsPath()
718718
if original == nil {
719719
return
720720
}
721721
switch option {
722-
case config.REMOVE_PRIVATE_AS_OPTION_ALL, config.REMOVE_PRIVATE_AS_OPTION_REPLACE:
722+
case oc.REMOVE_PRIVATE_AS_OPTION_ALL, oc.REMOVE_PRIVATE_AS_OPTION_REPLACE:
723723
newASParams := make([]bgp.AsPathParamInterface, 0, len(original.Value))
724724
for _, param := range original.Value {
725725
asList := param.GetAS()
726726
newASParam := make([]uint32, 0, len(asList))
727727
for _, as := range asList {
728728
if isPrivateAS(as) {
729-
if option == config.REMOVE_PRIVATE_AS_OPTION_REPLACE {
729+
if option == oc.REMOVE_PRIVATE_AS_OPTION_REPLACE {
730730
newASParam = append(newASParam, localAS)
731731
}
732732
} else {

internal/pkg/table/path_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"testing"
77
"time"
88

9-
"github.com/osrg/gobgp/v3/internal/pkg/config"
9+
"github.com/osrg/gobgp/v3/pkg/config/oc"
1010
"github.com/osrg/gobgp/v3/pkg/packet/bgp"
1111

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

344344
path = NewPath(nil, nlri, false, []bgp.PathAttributeInterface{aspath}, time.Now(), false)
345-
path.RemovePrivateAS(10, config.REMOVE_PRIVATE_AS_OPTION_REPLACE)
345+
path.RemovePrivateAS(10, oc.REMOVE_PRIVATE_AS_OPTION_REPLACE)
346346
list = path.GetAsList()
347347
assert.Equal(t, len(list), 4)
348348
assert.Equal(t, list[0], uint32(10))

0 commit comments

Comments
 (0)