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