-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "feat: remove optimizer from main repo"
This reverts commit 57768db
- Loading branch information
Showing
12 changed files
with
535 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/natesales/pathvector/pkg/optimizer" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(optimizerCmd) | ||
} | ||
|
||
var optimizerCmd = &cobra.Command{ | ||
Use: "optimizer", | ||
Short: "Start optimization daemon", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
c, err := loadConfig() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
log.Infof("Starting optimizer") | ||
sourceMap := map[string][]string{} // peer name to list of source addresses | ||
for peerName, peerData := range c.Peers { | ||
if peerData.OptimizerProbeSources != nil && len(*peerData.OptimizerProbeSources) > 0 { | ||
sourceMap[fmt.Sprintf("%d%s%s", *peerData.ASN, optimizer.Delimiter, peerName)] = *peerData.OptimizerProbeSources | ||
} | ||
} | ||
log.Debugf("Optimizer probe sources: %v", sourceMap) | ||
if len(sourceMap) == 0 { | ||
log.Fatal("No peers have optimization enabled, exiting now") | ||
} | ||
if err := optimizer.StartProbe(c.Optimizer, sourceMap, c, noConfigure, dryRun); err != nil { | ||
log.Fatal(err) | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestOptimizer(t *testing.T) { | ||
args := []string{ | ||
"--verbose", | ||
} | ||
files, err := filepath.Glob("../tests/probe-*.yml") | ||
assert.Nil(t, err) | ||
assert.GreaterOrEqual(t, 1, len(files)) | ||
|
||
for _, testFile := range files { | ||
// Run pathvector to generate config first, so there is a config to modify | ||
rootCmd.SetArgs(append(args, []string{ | ||
"generate", | ||
"--config", testFile, | ||
}...)) | ||
t.Logf("Running pre-optimizer generate: %v", args) | ||
assert.Nil(t, rootCmd.Execute()) | ||
|
||
args = append(args, []string{ | ||
"optimizer", | ||
"--config", testFile, | ||
}...) | ||
t.Logf("running probe integration with args %v", args) | ||
rootCmd.SetArgs(args) | ||
assert.Nil(t, rootCmd.Execute()) | ||
|
||
// Check if local pref is lowered | ||
checkFile, err := os.ReadFile("test-cache/AS65510_EXAMPLE.conf") | ||
assert.Nil(t, err) | ||
if !strings.Contains(string(checkFile), "bgp_local_pref = 80; # pathvector:localpref") { | ||
t.Errorf("expected bgp_local_pref = 80 but not found in file") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.