diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/fsm.go | 12 | ||||
-rw-r--r-- | server/peer.go | 12 | ||||
-rw-r--r-- | server/server.go | 23 | ||||
-rw-r--r-- | server/server_test.go | 36 | ||||
-rw-r--r-- | server/zclient.go | 5 |
5 files changed, 36 insertions, 52 deletions
diff --git a/server/fsm.go b/server/fsm.go index 9951fe68..d65107df 100644 --- a/server/fsm.go +++ b/server/fsm.go @@ -23,14 +23,14 @@ import ( "strconv" "time" - "github.com/eapache/channels" - log "github.com/sirupsen/logrus" - "gopkg.in/tomb.v2" - "github.com/osrg/gobgp/config" "github.com/osrg/gobgp/packet/bgp" "github.com/osrg/gobgp/packet/bmp" "github.com/osrg/gobgp/table" + + "github.com/eapache/channels" + log "github.com/sirupsen/logrus" + "gopkg.in/tomb.v2" ) type PeerDownReason int @@ -1048,9 +1048,7 @@ func open2Cap(open *bgp.BGPOpen, n *config.Neighbor) (map[bgp.BGPCapabilityCode] if caps, y := capMap[bgp.BGP_CAP_ADD_PATH]; y { items := make([]*bgp.CapAddPathTuple, 0, len(caps)) for _, c := range caps { - for _, i := range c.(*bgp.CapAddPath).Tuples { - items = append(items, i) - } + items = append(items, c.(*bgp.CapAddPath).Tuples...) } capMap[bgp.BGP_CAP_ADD_PATH] = []bgp.ParameterCapabilityInterface{bgp.NewCapAddPath(items)} } diff --git a/server/peer.go b/server/peer.go index e3981024..3a43fac9 100644 --- a/server/peer.go +++ b/server/peer.go @@ -42,8 +42,8 @@ type PeerGroup struct { func NewPeerGroup(c *config.PeerGroup) *PeerGroup { return &PeerGroup{ Conf: c, - members: make(map[string]config.Neighbor, 0), - dynamicNeighbors: make(map[string]*config.DynamicNeighbor, 0), + members: make(map[string]config.Neighbor), + dynamicNeighbors: make(map[string]*config.DynamicNeighbor), } } @@ -293,7 +293,7 @@ func (peer *Peer) markLLGRStale(fs []bgp.RouteFamily) []*table.Path { for i, p := range paths { doStale := true for _, c := range p.GetCommunities() { - if c == bgp.COMMUNITY_NO_LLGR { + if c == uint32(bgp.COMMUNITY_NO_LLGR) { doStale = false p = p.Clone(true) break @@ -301,7 +301,7 @@ func (peer *Peer) markLLGRStale(fs []bgp.RouteFamily) []*table.Path { } if doStale { p = p.Clone(false) - p.SetCommunities([]uint32{bgp.COMMUNITY_LLGR_STALE}, false) + p.SetCommunities([]uint32{uint32(bgp.COMMUNITY_LLGR_STALE)}, false) } paths[i] = p } @@ -317,10 +317,6 @@ func (peer *Peer) stopPeerRestarting() { } -func (peer *Peer) getAccepted(rfList []bgp.RouteFamily) []*table.Path { - return peer.adjRibIn.PathList(rfList, true) -} - func (peer *Peer) filterPathFromSourcePeer(path, old *table.Path) *table.Path { if peer.ID() != path.GetSource().Address.String() { return path diff --git a/server/server.go b/server/server.go index 8198294d..c4e5f5de 100644 --- a/server/server.go +++ b/server/server.go @@ -242,10 +242,12 @@ func (server *BgpServer) Serve() { } return true }(peer.fsm.pConf.Transport.Config.LocalAddress) - if localAddrValid == false { + + if !localAddrValid { conn.Close() return } + log.WithFields(log.Fields{ "Topic": "Peer", }).Debugf("Accepted a new passive connection from:%s", remoteAddr) @@ -1375,7 +1377,6 @@ func (server *BgpServer) handleFSMMessage(peer *Peer, e *FsmMsg) { }).Panic("unknown msg type") } } - return } func (s *BgpServer) AddCollector(c *config.CollectorConfig) error { @@ -1828,7 +1829,7 @@ func (s *BgpServer) softResetOut(addr string, family bgp.RouteFamily, deferral b if len(pathList) > 0 { sendFsmOutgoingMsg(peer, pathList, nil, false) } - if deferral == false && len(filtered) > 0 { + if !deferral && len(filtered) > 0 { withdrawnList := make([]*table.Path, 0, len(filtered)) for _, p := range filtered { withdrawnList = append(withdrawnList, p.Clone(true)) @@ -2293,7 +2294,8 @@ func (s *BgpServer) updateNeighbor(c *config.Neighbor) (needsSoftResetIn bool, e if original.Config.AdminDown != c.Config.AdminDown { sub = bgp.BGP_ERROR_SUB_ADMINISTRATIVE_SHUTDOWN state := "Admin Down" - if c.Config.AdminDown == false { + + if !c.Config.AdminDown { state = "Admin Up" } log.WithFields(log.Fields{ @@ -2734,7 +2736,6 @@ type watchOptions struct { initPeerState bool tableName string recvMessage bool - sentMessage bool } type WatchOption func(*watchOptions) @@ -2859,16 +2860,10 @@ func (w *Watcher) notify(v WatchEvent) { } func (w *Watcher) loop() { - for { - select { - case ev, ok := <-w.ch.Out(): - if !ok { - close(w.realCh) - return - } - w.realCh <- ev.(WatchEvent) - } + for ev := range w.ch.Out() { + w.realCh <- ev.(WatchEvent) } + close(w.realCh) } func (w *Watcher) Stop() { diff --git a/server/server_test.go b/server/server_test.go index c75003ed..ff9bfd40 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -16,11 +16,14 @@ package server import ( + "context" "net" "runtime" "testing" "time" + "github.com/stretchr/testify/require" + log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" @@ -277,14 +280,8 @@ func process(rib *table.TableManager, l []*table.Path) (*table.Path, *table.Path if len(news) != 1 { panic("can't handle multiple paths") } - for idx, path := range news { - var old *table.Path - if olds != nil { - old = olds[idx] - } - return path, old - } - return nil, nil + + return news[0], olds[0] } func TestFilterpathWitheBGP(t *testing.T) { @@ -656,22 +653,25 @@ func TestGracefulRestartTimerExpired(t *testing.T) { // Create dummy session which does NOT send BGP OPEN message in order to // cause Graceful Restart timer expired. var conn net.Conn - for { - time.Sleep(time.Second) - var err error - conn, err = net.Dial("tcp", "127.0.0.1:10179") - if err != nil { - log.Warn("net.Dial:", err) - } - break - } + + conn, err = net.Dial("tcp", "127.0.0.1:10179") + require.NoError(t, err) defer conn.Close() + ctx, cancel := context.WithTimeout(context.Background(), time.Second*3) + defer cancel() + // Waiting for Graceful Restart timer expired and moving on to IDLE state. for { - time.Sleep(time.Second) if s1.GetNeighbor("", false)[0].State.SessionState == config.SESSION_STATE_IDLE { break } + + select { + case <-time.After(time.Second): + case <-ctx.Done(): + t.Fatalf("failed to enter IDLE state in the deadline") + return + } } } diff --git a/server/zclient.go b/server/zclient.go index d5b026ac..37281f7f 100644 --- a/server/zclient.go +++ b/server/zclient.go @@ -283,10 +283,6 @@ type zebraClient struct { dead chan struct{} } -func (z *zebraClient) stop() { - close(z.dead) -} - func (z *zebraClient) getPathListWithNexthopUpdate(body *zebra.NexthopUpdateBody) []*table.Path { rib := &table.TableManager{ Tables: make(map[bgp.RouteFamily]*table.Table), @@ -326,7 +322,6 @@ func (z *zebraClient) updatePathByNexthopCache(paths []*table.Path) { }).Error("failed to update nexthop reachability") } } - return } func (z *zebraClient) loop() { |