Skip to content
Snippets Groups Projects
Commit fd89ee0f authored by Oliver Herms's avatar Oliver Herms
Browse files

Fixing AS path change on propagation

parent 902f3cad
No related branches found
No related tags found
No related merge requests found
...@@ -10,11 +10,19 @@ import ( ...@@ -10,11 +10,19 @@ import (
"github.com/bio-routing/bio-rd/config" "github.com/bio-routing/bio-rd/config"
"github.com/bio-routing/bio-rd/protocols/bgp/server" "github.com/bio-routing/bio-rd/protocols/bgp/server"
"github.com/bio-routing/bio-rd/route"
"github.com/bio-routing/bio-rd/routingtable" "github.com/bio-routing/bio-rd/routingtable"
"github.com/bio-routing/bio-rd/routingtable/filter" "github.com/bio-routing/bio-rd/routingtable/filter"
"github.com/bio-routing/bio-rd/routingtable/locRIB" "github.com/bio-routing/bio-rd/routingtable/locRIB"
bnet "github.com/bio-routing/bio-rd/net"
) )
func strAddr(s string) uint32 {
ret, _ := bnet.StrToAddr(s)
return ret
}
func main() { func main() {
logrus.Printf("This is a BGP speaker\n") logrus.Printf("This is a BGP speaker\n")
...@@ -32,6 +40,15 @@ func main() { ...@@ -32,6 +40,15 @@ func main() {
logrus.Fatalf("Unable to start BGP server: %v", err) logrus.Fatalf("Unable to start BGP server: %v", err)
} }
rib.AddPath(bnet.NewPfx(strAddr("10.0.0.0"), 8), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
NextHop: 100,
ASPath: "3320",
Origin: 1,
},
})
b.AddPeer(config.Peer{ b.AddPeer(config.Peer{
AdminEnabled: true, AdminEnabled: true,
LocalAS: 65200, LocalAS: 65200,
...@@ -50,7 +67,7 @@ func main() { ...@@ -50,7 +67,7 @@ func main() {
ExportFilter: filter.NewAcceptAllFilter(), ExportFilter: filter.NewAcceptAllFilter(),
}, rib) }, rib)
b.AddPeer(config.Peer{ /*b.AddPeer(config.Peer{
AdminEnabled: true, AdminEnabled: true,
LocalAS: 65200, LocalAS: 65200,
PeerAS: 65100, PeerAS: 65100,
...@@ -67,7 +84,7 @@ func main() { ...@@ -67,7 +84,7 @@ func main() {
AddPathRecv: true, AddPathRecv: true,
ImportFilter: filter.NewAcceptAllFilter(), ImportFilter: filter.NewAcceptAllFilter(),
ExportFilter: filter.NewDrainFilter(), ExportFilter: filter.NewDrainFilter(),
}, rib) }, rib)*/
go func() { go func() {
for { for {
......
...@@ -58,8 +58,10 @@ func (s *establishedState) init() { ...@@ -58,8 +58,10 @@ func (s *establishedState) init() {
s.fsm.adjRIBIn.Register(s.fsm.peer.importFilter) s.fsm.adjRIBIn.Register(s.fsm.peer.importFilter)
n := &routingtable.Neighbor{ n := &routingtable.Neighbor{
Type: route.BGPPathType, Type: route.BGPPathType,
Address: tnet.IPv4ToUint32(s.fsm.peer.addr), Address: tnet.IPv4ToUint32(s.fsm.peer.addr),
IBGP: s.fsm.peer.localASN == s.fsm.peer.peerASN,
LocalASN: s.fsm.peer.localASN,
} }
clientOptions := routingtable.ClientOptions{} clientOptions := routingtable.ClientOptions{}
......
...@@ -10,8 +10,8 @@ import ( ...@@ -10,8 +10,8 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
func pathAttribues(p *route.Path, fsm *FSM) (*packet.PathAttribute, error) { func pathAttribues(p *route.Path) (*packet.PathAttribute, error) {
asPathPA, err := packet.ParseASPathStr(strings.TrimRight(fmt.Sprintf("%d %s", fsm.peer.localASN, p.BGPPath.ASPath), " ")) asPathPA, err := packet.ParseASPathStr(strings.TrimRight(p.BGPPath.ASPath, " "))
if err != nil { if err != nil {
return nil, fmt.Errorf("Unable to parse AS path: %v", err) return nil, fmt.Errorf("Unable to parse AS path: %v", err)
} }
......
...@@ -28,7 +28,7 @@ func newUpdateSender(fsm *FSM) *UpdateSender { ...@@ -28,7 +28,7 @@ func newUpdateSender(fsm *FSM) *UpdateSender {
// AddPath serializes a new path and sends out a BGP update message // AddPath serializes a new path and sends out a BGP update message
func (u *UpdateSender) AddPath(pfx net.Prefix, p *route.Path) error { func (u *UpdateSender) AddPath(pfx net.Prefix, p *route.Path) error {
pathAttrs, err := pathAttribues(p, u.fsm) pathAttrs, err := pathAttribues(p)
if err != nil { if err != nil {
log.Errorf("Unable to create BGP Update: %v", err) log.Errorf("Unable to create BGP Update: %v", err)
return nil return nil
......
...@@ -25,7 +25,7 @@ func newUpdateSenderAddPath(fsm *FSM) *UpdateSenderAddPath { ...@@ -25,7 +25,7 @@ func newUpdateSenderAddPath(fsm *FSM) *UpdateSenderAddPath {
// AddPath serializes a new path and sends out a BGP update message // AddPath serializes a new path and sends out a BGP update message
func (u *UpdateSenderAddPath) AddPath(pfx net.Prefix, p *route.Path) error { func (u *UpdateSenderAddPath) AddPath(pfx net.Prefix, p *route.Path) error {
pathAttrs, err := pathAttribues(p, u.fsm) pathAttrs, err := pathAttribues(p)
if err != nil { if err != nil {
log.Errorf("Unable to create BGP Update: %v", err) log.Errorf("Unable to create BGP Update: %v", err)
......
...@@ -39,6 +39,11 @@ func (a *AdjRIBOut) AddPath(pfx net.Prefix, p *route.Path) error { ...@@ -39,6 +39,11 @@ func (a *AdjRIBOut) AddPath(pfx net.Prefix, p *route.Path) error {
return nil return nil
} }
p = p.Copy()
if !a.neighbor.IBGP {
p.BGPPath.ASPath = fmt.Sprintf("%d %s", a.neighbor.LocalASN, p.BGPPath.ASPath)
}
a.mu.Lock() a.mu.Lock()
defer a.mu.Unlock() defer a.mu.Unlock()
......
...@@ -41,6 +41,11 @@ func (a *AdjRIBOutAddPath) AddPath(pfx net.Prefix, p *route.Path) error { ...@@ -41,6 +41,11 @@ func (a *AdjRIBOutAddPath) AddPath(pfx net.Prefix, p *route.Path) error {
return nil return nil
} }
p = p.Copy()
if !a.neighbor.IBGP {
p.BGPPath.ASPath = fmt.Sprintf("%d %s", a.neighbor.LocalASN, p.BGPPath.ASPath)
}
a.mu.Lock() a.mu.Lock()
defer a.mu.Unlock() defer a.mu.Unlock()
......
...@@ -10,4 +10,7 @@ type Neighbor struct { ...@@ -10,4 +10,7 @@ type Neighbor struct {
// IBGP returns if local ASN is equal to remote ASN // IBGP returns if local ASN is equal to remote ASN
IBGP bool IBGP bool
// Local ASN of session
LocalASN uint32
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment