summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSatoshi Fujimoto <satoshi.fujimoto7@gmail.com>2017-11-09 10:43:06 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2017-11-26 21:44:29 +0900
commit4ed3691432a977e17ef6eefd1e0b652ca4204335 (patch)
treeef4da22d95fcd668feab0ff53897d9e87f45e542
parent68d2478e2ea1d8607f85e6ab3d4a792e054ce6c2 (diff)
cmd/neighbor: Separate Show RPKI info logic from Show RIB logic
For readability and maintainability, this commit separates these non-directly related logics. Signed-off-by: Satoshi Fujimoto <satoshi.fujimoto7@gmail.com>
-rw-r--r--gobgp/cmd/neighbor.go90
1 files changed, 49 insertions, 41 deletions
diff --git a/gobgp/cmd/neighbor.go b/gobgp/cmd/neighbor.go
index 8e18cfa3..4f15ce7b 100644
--- a/gobgp/cmd/neighbor.go
+++ b/gobgp/cmd/neighbor.go
@@ -407,7 +407,7 @@ type AsPathFormat struct {
separator string
}
-func ShowRoute(pathList []*table.Path, showAge, showBest, showLabel, isMonitor, printHeader bool, showIdentifier bgp.BGPAddPathMode) {
+func showRoute(pathList []*table.Path, showAge, showBest, showLabel, isMonitor, printHeader bool, showIdentifier bgp.BGPAddPathMode) {
var pathStrs [][]interface{}
maxPrefixLen := 20
@@ -596,10 +596,16 @@ func checkOriginAsWasNotShown(p *table.Path, shownAs map[uint32]struct{}) bool {
return true
}
-func ShowValidationInfo(p *table.Path) {
+func showValidationInfo(p *table.Path, shownAs map[uint32]struct{}) error {
+ asPath := p.GetAsPath().Value
+ if len(asPath) == 0 {
+ return fmt.Errorf("The path to %s was locally generated.\n", p.GetNlri().String())
+ } else if !checkOriginAsWasNotShown(p, shownAs) {
+ return nil
+ }
+
status := p.Validation().Status
reason := p.Validation().Reason
- asPath := p.GetAsPath().Value
aslist := asPath[len(asPath)-1].(*bgp.As4PathParam).AS
origin := aslist[len(aslist)-1]
@@ -643,6 +649,8 @@ func ShowValidationInfo(p *table.Path) {
printVRPs(p.Validation().UnmatchedAs)
fmt.Println(" Unmatched Length VRPs: ")
printVRPs(p.Validation().UnmatchedLength)
+
+ return nil
}
func showRibInfo(r, name string) error {
@@ -793,51 +801,51 @@ func showNeighborRib(r string, name string, args []string) error {
return nil
}
- shownAs := make(map[uint32]struct{})
- counter := 0
- for _, d := range rib.GetSortedDestinations() {
- if validationTarget != "" && d.GetNlri().String() != validationTarget {
- continue
+ if validationTarget != "" {
+ // show RPKI validation info
+ d := rib.GetDestination(validationTarget)
+ if d == nil {
+ fmt.Println("Network not in table")
+ return nil
}
- var ps []*table.Path
- if r == CMD_ACCEPTED || r == CMD_REJECTED {
- for _, p := range d.GetAllKnownPathList() {
- switch r {
- case CMD_ACCEPTED:
- if p.Filtered("") > table.POLICY_DIRECTION_NONE {
- continue
- }
- case CMD_REJECTED:
- if p.Filtered("") == table.POLICY_DIRECTION_NONE {
- continue
+ shownAs := make(map[uint32]struct{})
+ for _, p := range d.GetAllKnownPathList() {
+ if err := showValidationInfo(p, shownAs); err != nil {
+ return err
+ }
+ }
+ } else {
+ // show RIB
+ counter := 0
+ for _, d := range rib.GetSortedDestinations() {
+ var ps []*table.Path
+ if r == CMD_ACCEPTED || r == CMD_REJECTED {
+ for _, p := range d.GetAllKnownPathList() {
+ switch r {
+ case CMD_ACCEPTED:
+ if p.Filtered("") > table.POLICY_DIRECTION_NONE {
+ continue
+ }
+ case CMD_REJECTED:
+ if p.Filtered("") == table.POLICY_DIRECTION_NONE {
+ continue
+ }
}
+ ps = append(ps, p)
}
- ps = append(ps, p)
+ } else {
+ ps = d.GetAllKnownPathList()
}
- } else {
- ps = d.GetAllKnownPathList()
+ showHeader := false
+ if counter == 0 {
+ showHeader = true
+ }
+ showRoute(ps, showAge, showBest, showLabel, false, showHeader, showIdentifier)
+ counter++
}
- showHeader := false
if counter == 0 {
- showHeader = true
+ fmt.Println("Network not in table")
}
- if validationTarget != "" {
- for _, p := range ps {
- asPath := p.GetAsPath().Value
- if len(asPath) == 0 {
- fmt.Printf("The path to %s was locally generated.\n", p.GetNlri().String())
- } else if checkOriginAsWasNotShown(p, shownAs) {
- ShowValidationInfo(p)
- }
- }
- } else {
- ShowRoute(ps, showAge, showBest, showLabel, false, showHeader, showIdentifier)
- }
- counter++
- }
-
- if counter == 0 {
- fmt.Println("Network not in table")
}
return nil
}