Newer
Older
"github.com/bio-routing/bio-rd/config"
"github.com/bio-routing/bio-rd/protocols/bgp/packet"
"github.com/bio-routing/bio-rd/routingtable"
addr net.IP
routerID uint32
addPathSend routingtable.ClientOptions
addPathRecv bool
reconnectInterval time.Duration
keepaliveTime time.Duration
holdTime time.Duration
optOpenParams []packet.OptParam
importFilter *filter.Filter
exportFilter *filter.Filter
}
func (p *Peer) collisionHandling(callingFSM *FSM) bool {
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
p.fsmsMu.Lock()
defer p.fsmsMu.Unlock()
for _, fsm := range p.fsms {
if callingFSM == fsm {
continue
}
fsm.stateMu.RLock()
isEstablished := isEstablishedState(fsm.state)
isOpenConfirm := isOpenConfirmState(fsm.state)
fsm.stateMu.RUnlock()
if isEstablished {
return true
}
if !isOpenConfirm {
continue
}
if p.routerID < callingFSM.neighborID {
fsm.cease()
} else {
return true
}
}
return false
}
func isOpenConfirmState(s state) bool {
switch s.(type) {
case openConfirmState:
return true
}
return false
}
func isEstablishedState(s state) bool {
switch s.(type) {
case establishedState:
return true
}
return false
// NewPeer creates a new peer with the given config. If an connection is established, the adjRIBIN of the peer is connected
// to the given rib. To actually connect the peer, call Start() on the returned peer.
func NewPeer(c config.Peer, rib routingtable.RouteTableClient, server *BGPServer) (*Peer, error) {
addr: c.PeerAddress,
rib: rib,
addPathSend: c.AddPathSend,
addPathRecv: c.AddPathRecv,
reconnectInterval: c.ReconnectInterval,
importFilter: filterOrDefault(c.ImportFilter),
exportFilter: filterOrDefault(c.ExportFilter),
caps := make([]packet.Capability, 0)
addPathEnabled, addPathCap := handleAddPathCapability(c)
if addPathEnabled {
caps = append(caps, addPathCap)
for _, cap := range caps {
p.optOpenParams = append(p.optOpenParams, packet.OptParam{
Type: packet.CapabilitiesParamType,
Value: cap,
})
}
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
func asn4Capability(c config.Peer) packet.Capability {
return packet.Capability{
Code: packet.ASN4CapabilityCode,
Value: packet.ASN4Capability{
ASN4: c.LocalAS,
},
}
}
func handleAddPathCapability(c config.Peer) (bool, packet.Capability) {
addPath := uint8(0)
if c.AddPathRecv {
addPath += packet.AddPathReceive
}
if !c.AddPathSend.BestOnly {
addPath += packet.AddPathSend
}
if addPath == 0 {
return false, packet.Capability{}
}
return true, packet.Capability{
Code: packet.AddPathCapabilityCode,
Value: packet.AddPathCapability{
AFI: packet.IPv4AFI,
SAFI: packet.UnicastSAFI,
SendReceive: addPath,
},
}
}
func filterOrDefault(f *filter.Filter) *filter.Filter {
if f != nil {
return f
}
return filter.NewDrainFilter()
}
// GetAddr returns the IP address of the peer
func (p *Peer) GetAddr() net.IP {
return p.addr
}
func (p *Peer) Start() {