github.com/osrg/gobgp@v2.0.0+incompatible/internal/pkg/table/adj_test.go (about)

     1  // Copyright (C) 2018 Nippon Telegraph and Telephone Corporation.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //    http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
    12  // implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  
    16  package table
    17  
    18  import (
    19  	"testing"
    20  	"time"
    21  
    22  	"github.com/osrg/gobgp/pkg/packet/bgp"
    23  
    24  	"github.com/stretchr/testify/assert"
    25  )
    26  
    27  func TestStaleAll(t *testing.T) {
    28  	pi := &PeerInfo{}
    29  	attrs := []bgp.PathAttributeInterface{bgp.NewPathAttributeOrigin(0)}
    30  
    31  	nlri1 := bgp.NewIPAddrPrefix(24, "20.20.20.0")
    32  	nlri1.SetPathIdentifier(1)
    33  	p1 := NewPath(pi, nlri1, false, attrs, time.Now(), false)
    34  	nlri2 := bgp.NewIPAddrPrefix(24, "20.20.20.0")
    35  	nlri2.SetPathIdentifier(2)
    36  	p2 := NewPath(pi, nlri2, false, attrs, time.Now(), false)
    37  	family := p1.GetRouteFamily()
    38  	families := []bgp.RouteFamily{family}
    39  
    40  	adj := NewAdjRib(families)
    41  	adj.Update([]*Path{p1, p2})
    42  	assert.Equal(t, len(adj.table[family]), 2)
    43  
    44  	adj.StaleAll(families)
    45  
    46  	for _, p := range adj.table[family] {
    47  		assert.True(t, p.IsStale())
    48  	}
    49  
    50  	adj.DropStale(families)
    51  	assert.Equal(t, len(adj.table[family]), 0)
    52  }