Skip to content

Commit

Permalink
send-max: respect configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Peim authored and fujita committed Apr 29, 2024
1 parent bbde806 commit 9fbc037
Show file tree
Hide file tree
Showing 22 changed files with 1,670 additions and 1,382 deletions.
2,381 changes: 1,196 additions & 1,185 deletions api/gobgp.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions api/gobgp.proto
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ message Path {
uint32 local_identifier = 19;
bytes nlri_binary = 20;
repeated bytes pattrs_binary = 21;
bool send_max_filtered = 22;
}

message Destination {
Expand Down
25 changes: 21 additions & 4 deletions cmd/gobgp/neighbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ func getPathAttributeString(nlri bgp.AddrPrefixInterface, attrs []bgp.PathAttrib
return fmt.Sprint(s)
}

func makeShowRouteArgs(p *api.Path, idx int, now time.Time, showAge, showBest, showLabel, showMUP bool, showIdentifier bgp.BGPAddPathMode) []interface{} {
func makeShowRouteArgs(p *api.Path, idx int, now time.Time, showAge, showBest, showLabel, showMUP, showSendMaxFiltered bool, showIdentifier bgp.BGPAddPathMode) []interface{} {
nlri, _ := apiutil.GetNativeNlri(p)

// Path Symbols (e.g. "*>")
Expand Down Expand Up @@ -650,17 +650,27 @@ func makeShowRouteArgs(p *api.Path, idx int, now time.Time, showAge, showBest, s
pattrstr := getPathAttributeString(nlri, attrs)
args = append(args, pattrstr)

if showSendMaxFiltered {
if p.SendMaxFiltered {
args = append(args, "send-max-filtered")
} else if p.Filtered {
args = append(args, "policy-filtered")
} else {
args = append(args, "not filtered")
}
}

updateColumnWidth(nlri.String(), nexthop, aspathstr, label, teid, qfi, endpoint)

return args
}

func showRoute(dsts []*api.Destination, showAge, showBest, showLabel, showMUP bool, showIdentifier bgp.BGPAddPathMode) {
func showRoute(dsts []*api.Destination, showAge, showBest, showLabel, showMUP, showSendMaxFiltered bool, showIdentifier bgp.BGPAddPathMode) {
pathStrs := make([][]interface{}, 0, len(dsts))
now := time.Now()
for _, dst := range dsts {
for idx, p := range dst.Paths {
pathStrs = append(pathStrs, makeShowRouteArgs(p, idx, now, showAge, showBest, showLabel, showMUP, showIdentifier))
pathStrs = append(pathStrs, makeShowRouteArgs(p, idx, now, showAge, showBest, showLabel, showMUP, showSendMaxFiltered, showIdentifier))
}
}

Expand Down Expand Up @@ -691,6 +701,11 @@ func showRoute(dsts []*api.Destination, showAge, showBest, showLabel, showMUP bo
headers = append(headers, "Attrs")
format += "%-s\n"

if showSendMaxFiltered {
headers = append(headers, "Filtered")
format += "%-s\n"
}

fmt.Printf(format, headers...)
for _, pathStr := range pathStrs {
fmt.Printf(format, pathStr...)
Expand Down Expand Up @@ -839,6 +854,7 @@ func showNeighborRib(r string, name string, args []string) error {
showAge := true
showLabel := false
showMUP := false
showSendMaxFiltered := false
showIdentifier := bgp.BGP_ADD_PATH_NONE
validationTarget := ""
rd := ""
Expand All @@ -852,6 +868,7 @@ func showNeighborRib(r string, name string, args []string) error {
showBest = true
case cmdAdjOut:
showAge = false
showSendMaxFiltered = true
case cmdVRF:
def = ipv4UC
showBest = true
Expand Down Expand Up @@ -1058,7 +1075,7 @@ func showNeighborRib(r string, name string, args []string) error {
}
}
if len(dsts) > 0 {
showRoute(dsts, showAge, showBest, showLabel, showMUP, showIdentifier)
showRoute(dsts, showAge, showBest, showLabel, showMUP, showSendMaxFiltered, showIdentifier)
} else {
fmt.Println("Network not in table")
}
Expand Down
5 changes: 1 addition & 4 deletions internal/pkg/table/destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,7 @@ func rsFilter(id string, as uint32, path *Path) bool {
return false
}

if id != GLOBAL_RIB_NAME && (path.GetSource().Address.String() == id || isASLoop(as, path)) {
return true
}
return false
return id != GLOBAL_RIB_NAME && (path.GetSource().Address.String() == id || isASLoop(as, path))
}

func (dd *Destination) GetKnownPathList(id string, as uint32) []*Path {
Expand Down
19 changes: 17 additions & 2 deletions internal/pkg/table/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ type Path struct {
IsNexthopInvalid bool
IsWithdraw bool
}
type FilteredType uint8

const (
NotFiltered FilteredType = 1 << iota
PolicyFiltered
SendMaxFiltered
)

type PathLocalKey string

var localSource = &PeerInfo{}

Expand Down Expand Up @@ -566,7 +575,7 @@ func (path *Path) String() string {
s.WriteString(fmt.Sprintf("{ %s EOR | src: %s }", path.GetRouteFamily(), path.GetSource()))
return s.String()
}
s.WriteString(fmt.Sprintf("{ %s | ", path.getPrefix()))
s.WriteString(fmt.Sprintf("{ %s | ", path.GetPrefix()))
s.WriteString(fmt.Sprintf("src: %s", path.GetSource()))
s.WriteString(fmt.Sprintf(", nh: %s", path.GetNexthop()))
if path.IsNexthopInvalid {
Expand All @@ -579,7 +588,13 @@ func (path *Path) String() string {
return s.String()
}

func (path *Path) getPrefix() string {
// GetLocalKey identifies the path in the local BGP server.
func (path *Path) GetLocalKey() PathLocalKey {
// return PathLocalKey(path.GetPrefix())
return PathLocalKey(fmt.Sprintf("%s:%s:%d", path.GetRouteFamily(), path.GetNlri(), path.GetNlri().PathLocalIdentifier()))
}

func (path *Path) GetPrefix() string {
return path.GetNlri().String()
}

Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/table/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestPathGetPrefix(t *testing.T) {
peerP := PathCreatePeer()
pathP := PathCreatePath(peerP)
prefix := "10.10.10.0/24"
r_prefix := pathP[0].getPrefix()
r_prefix := pathP[0].GetPrefix()
assert.Equal(t, r_prefix, prefix)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (t *Table) validatePath(path *Path) {
log.Fields{
"Topic": "Table",
"Key": t.routeFamily,
"Prefix": path.GetNlri().String(),
"Prefix": path.GetPrefix(),
"ReceivedRf": path.GetRouteFamily().String()})
}
if attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH); attr != nil {
Expand Down
52 changes: 26 additions & 26 deletions internal/pkg/table/table_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func TestProcessBGPUpdate_0_select_onlypath_ipv4(t *testing.T) {

// check destination
expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix())
assert.Equal(t, expectedPrefix, path.GetPrefix())
// check nexthop
expectedNexthop := "192.168.50.1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String())
Expand Down Expand Up @@ -169,7 +169,7 @@ func TestProcessBGPUpdate_0_select_onlypath_ipv6(t *testing.T) {

// check destination
expectedPrefix := "2001:123:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix())
assert.Equal(t, expectedPrefix, path.GetPrefix())
// check nexthop
expectedNexthop := "2001::192:168:50:1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String())
Expand Down Expand Up @@ -250,7 +250,7 @@ func TestProcessBGPUpdate_1_select_high_localpref_ipv4(t *testing.T) {

// check destination
expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix())
assert.Equal(t, expectedPrefix, path.GetPrefix())
// check nexthop
expectedNexthop := "192.168.50.1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String())
Expand Down Expand Up @@ -331,7 +331,7 @@ func TestProcessBGPUpdate_1_select_high_localpref_ipv6(t *testing.T) {

// check destination
expectedPrefix := "2001:123:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix())
assert.Equal(t, expectedPrefix, path.GetPrefix())
// check nexthop
expectedNexthop := "2001::192:168:100:1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String())
Expand Down Expand Up @@ -414,7 +414,7 @@ func TestProcessBGPUpdate_2_select_local_origin_ipv4(t *testing.T) {

// check destination
expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix())
assert.Equal(t, expectedPrefix, path.GetPrefix())
// check nexthop
expectedNexthop := "0.0.0.0"
assert.Equal(t, expectedNexthop, path.GetNexthop().String())
Expand Down Expand Up @@ -498,7 +498,7 @@ func TestProcessBGPUpdate_2_select_local_origin_ipv6(t *testing.T) {

// check destination
expectedPrefix := "2001:123:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix())
assert.Equal(t, expectedPrefix, path.GetPrefix())
// check nexthop
expectedNexthop := "::"
assert.Equal(t, expectedNexthop, path.GetNexthop().String())
Expand Down Expand Up @@ -554,7 +554,7 @@ func TestProcessBGPUpdate_3_select_aspath_ipv4(t *testing.T) {

// check destination
expectedPrefix := "20.20.20.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix())
assert.Equal(t, expectedPrefix, path.GetPrefix())
// check nexthop
expectedNexthop := "192.168.100.1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String())
Expand Down Expand Up @@ -610,7 +610,7 @@ func TestProcessBGPUpdate_3_select_aspath_ipv6(t *testing.T) {

// check destination
expectedPrefix := "2002:223:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix())
assert.Equal(t, expectedPrefix, path.GetPrefix())
// check nexthop
expectedNexthop := "2001::192:168:100:1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String())
Expand Down Expand Up @@ -691,7 +691,7 @@ func TestProcessBGPUpdate_4_select_low_origin_ipv4(t *testing.T) {

// check destination
expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix())
assert.Equal(t, expectedPrefix, path.GetPrefix())
// check nexthop
expectedNexthop := "192.168.100.1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String())
Expand Down Expand Up @@ -772,7 +772,7 @@ func TestProcessBGPUpdate_4_select_low_origin_ipv6(t *testing.T) {

// check destination
expectedPrefix := "2001:123:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix())
assert.Equal(t, expectedPrefix, path.GetPrefix())
// check nexthop
expectedNexthop := "2001::192:168:100:1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String())
Expand Down Expand Up @@ -853,7 +853,7 @@ func TestProcessBGPUpdate_5_select_low_med_ipv4(t *testing.T) {

// check destination
expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix())
assert.Equal(t, expectedPrefix, path.GetPrefix())
// check nexthop
expectedNexthop := "192.168.100.1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String())
Expand Down Expand Up @@ -934,7 +934,7 @@ func TestProcessBGPUpdate_5_select_low_med_ipv6(t *testing.T) {

// check destination
expectedPrefix := "2001:123:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix())
assert.Equal(t, expectedPrefix, path.GetPrefix())
// check nexthop
expectedNexthop := "2001::192:168:100:1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String())
Expand Down Expand Up @@ -1015,7 +1015,7 @@ func TestProcessBGPUpdate_6_select_ebgp_path_ipv4(t *testing.T) {

// check destination
expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix())
assert.Equal(t, expectedPrefix, path.GetPrefix())
// check nexthop
expectedNexthop := "192.168.100.1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String())
Expand Down Expand Up @@ -1096,7 +1096,7 @@ func TestProcessBGPUpdate_6_select_ebgp_path_ipv6(t *testing.T) {

// check destination
expectedPrefix := "2001:123:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix())
assert.Equal(t, expectedPrefix, path.GetPrefix())
// check nexthop
expectedNexthop := "2001::192:168:100:1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String())
Expand Down Expand Up @@ -1180,7 +1180,7 @@ func TestProcessBGPUpdate_7_select_low_routerid_path_ipv4(t *testing.T) {

// check destination
expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix())
assert.Equal(t, expectedPrefix, path.GetPrefix())
// check nexthop
expectedNexthop := "192.168.100.1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String())
Expand Down Expand Up @@ -1261,7 +1261,7 @@ func TestProcessBGPUpdate_7_select_low_routerid_path_ipv6(t *testing.T) {

// check destination
expectedPrefix := "2001:123:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix())
assert.Equal(t, expectedPrefix, path.GetPrefix())
// check nexthop
expectedNexthop := "2001::192:168:100:1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String())
Expand Down Expand Up @@ -1344,7 +1344,7 @@ func TestProcessBGPUpdate_8_withdraw_path_ipv4(t *testing.T) {
checkPattr(bgpMessage2, path)
// check destination
expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix())
assert.Equal(t, expectedPrefix, path.GetPrefix())
// check nexthop
expectedNexthop := "192.168.100.1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String())
Expand All @@ -1365,7 +1365,7 @@ func TestProcessBGPUpdate_8_withdraw_path_ipv4(t *testing.T) {
checkPattr(bgpMessage1, path)
// check destination
expectedPrefix = "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix())
assert.Equal(t, expectedPrefix, path.GetPrefix())
// check nexthop
expectedNexthop = "192.168.50.1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String())
Expand Down Expand Up @@ -1472,7 +1472,7 @@ func TestProcessBGPUpdate_8_mpunreach_path_ipv6(t *testing.T) {

// check destination
expectedPrefix := "2001:123:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix())
assert.Equal(t, expectedPrefix, path.GetPrefix())
// check nexthop
expectedNexthop := "2001::192:168:100:1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String())
Expand All @@ -1492,7 +1492,7 @@ func TestProcessBGPUpdate_8_mpunreach_path_ipv6(t *testing.T) {
checkPattr(bgpMessage1, path)
// check destination
expectedPrefix = "2001:123:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix())
assert.Equal(t, expectedPrefix, path.GetPrefix())
// check nexthop
expectedNexthop = "2001::192:168:50:1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String())
Expand Down Expand Up @@ -1567,7 +1567,7 @@ func TestProcessBGPUpdate_bestpath_lost_ipv4(t *testing.T) {
checkPattr(bgpMessage1, path)
// check destination
expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix())
assert.Equal(t, expectedPrefix, path.GetPrefix())
}

func TestProcessBGPUpdate_bestpath_lost_ipv6(t *testing.T) {
Expand Down Expand Up @@ -1637,7 +1637,7 @@ func TestProcessBGPUpdate_bestpath_lost_ipv6(t *testing.T) {

// check destination
expectedPrefix := "2001:123:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix())
assert.Equal(t, expectedPrefix, path.GetPrefix())
}

// test: implicit withdrawal case
Expand Down Expand Up @@ -1715,7 +1715,7 @@ func TestProcessBGPUpdate_implicit_withdrwal_ipv4(t *testing.T) {
checkPattr(bgpMessage2, path)
// check destination
expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix())
assert.Equal(t, expectedPrefix, path.GetPrefix())
// check nexthop
expectedNexthop := "192.168.50.1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String())
Expand Down Expand Up @@ -1821,7 +1821,7 @@ func TestProcessBGPUpdate_implicit_withdrwal_ipv6(t *testing.T) {

// check destination
expectedPrefix := "2001:123:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix())
assert.Equal(t, expectedPrefix, path.GetPrefix())
// check nexthop
expectedNexthop := "2001::192:168:50:1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String())
Expand Down Expand Up @@ -1876,7 +1876,7 @@ func TestProcessBGPUpdate_multiple_nlri_ipv4(t *testing.T) {
assert.Equal(t, p.GetRouteFamily(), rf)
checkPattr(m, p)
// check destination
assert.Equal(t, prefix, p.getPrefix())
assert.Equal(t, prefix, p.GetPrefix())
// check nexthop
assert.Equal(t, nexthop, p.GetNexthop().String())
}
Expand Down Expand Up @@ -2014,7 +2014,7 @@ func TestProcessBGPUpdate_multiple_nlri_ipv6(t *testing.T) {
assert.Equal(t, p.GetRouteFamily(), rf)
checkPattr(m, p)
// check destination
assert.Equal(t, prefix, p.getPrefix())
assert.Equal(t, prefix, p.GetPrefix())
// check nexthop
assert.Equal(t, nexthop, p.GetNexthop().String())
}
Expand Down
Loading

0 comments on commit 9fbc037

Please sign in to comment.