Skip to content
Snippets Groups Projects
Commit 4a8fd3ef authored by Daniel Czerwonk's avatar Daniel Czerwonk
Browse files

sending large communities

parent 372099e8
No related branches found
No related tags found
No related merge requests found
...@@ -22,6 +22,10 @@ func main() { ...@@ -22,6 +22,10 @@ func main() {
err := b.Start(&config.Global{ err := b.Start(&config.Global{
Listen: true, Listen: true,
LocalAddressList: []net.IP{
net.IPv4(169, 254, 100, 1),
net.IPv4(169, 254, 200, 0),
},
}) })
if err != nil { if err != nil {
logrus.Fatalf("Unable to start BGP server: %v", err) logrus.Fatalf("Unable to start BGP server: %v", err)
......
...@@ -566,7 +566,7 @@ func ParseASPathStr(asPathString string) (*PathAttribute, error) { ...@@ -566,7 +566,7 @@ func ParseASPathStr(asPathString string) (*PathAttribute, error) {
}, nil }, nil
} }
func largeCommunityAttributeForString(s string) (*PathAttribute, error) { func LargeCommunityAttributeForString(s string) (*PathAttribute, error) {
strs := strings.Split(s, " ") strs := strings.Split(s, " ")
coms := make([]LargeCommunity, len(strs)) coms := make([]LargeCommunity, len(strs))
......
package server
import (
"fmt"
"strings"
"github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/bio-rd/protocols/bgp/packet"
"github.com/bio-routing/bio-rd/route"
)
func updateMessageForPath(pfx net.Prefix, p *route.Path, fsm *FSM) (*packet.BGPUpdate, error) {
pathAttrs, err := pathAttribues(p, fsm)
if err != nil {
return nil, err
}
return &packet.BGPUpdate{
PathAttributes: pathAttrs,
NLRI: &packet.NLRI{
IP: pfx.Addr(),
Pfxlen: pfx.Pfxlen(),
},
}, nil
}
func pathAttribues(p *route.Path, fsm *FSM) (*packet.PathAttribute, error) {
asPathPA, err := packet.ParseASPathStr(strings.TrimRight(fmt.Sprintf("%d %s", fsm.localASN, p.BGPPath.ASPath), " "))
if err != nil {
return nil, fmt.Errorf("Unable to parse AS path: %v", err)
}
origin := &packet.PathAttribute{
TypeCode: packet.OriginAttr,
Value: p.BGPPath.Origin,
Next: asPathPA,
}
nextHop := &packet.PathAttribute{
TypeCode: packet.NextHopAttr,
Value: p.BGPPath.NextHop,
}
asPathPA.Next = nextHop
if p.BGPPath != nil {
err := addOptionalPathAttribues(p, nextHop)
if err != nil {
return nil, err
}
}
return origin, nil
}
func addOptionalPathAttribues(p *route.Path, parent *packet.PathAttribute) error {
current := parent
if len(p.BGPPath.LargeCommunities) > 0 {
largeCommunities, err := packet.LargeCommunityAttributeForString(p.BGPPath.LargeCommunities)
if err != nil {
return fmt.Errorf("Could not create large community attribute: %v", err)
}
current.Next = largeCommunities
current = largeCommunities
}
return nil
}
...@@ -2,12 +2,10 @@ package server ...@@ -2,12 +2,10 @@ package server
import ( import (
"fmt" "fmt"
"strings"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/bio-routing/bio-rd/net" "github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/bio-rd/protocols/bgp/packet"
"github.com/bio-routing/bio-rd/route" "github.com/bio-routing/bio-rd/route"
"github.com/bio-routing/bio-rd/routingtable" "github.com/bio-routing/bio-rd/routingtable"
) )
...@@ -26,28 +24,10 @@ func newUpdateSender(fsm *FSM) *UpdateSender { ...@@ -26,28 +24,10 @@ 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 {
asPathPA, err := packet.ParseASPathStr(strings.TrimRight(fmt.Sprintf("%d %s", u.fsm.localASN, p.BGPPath.ASPath), " ")) update, err := updateMessageForPath(pfx, p, u.fsm)
if err != nil { if err != nil {
return fmt.Errorf("Unable to parse AS path: %v", err) log.Errorf("Unable to create BGP Update: %v", err)
} return nil
update := &packet.BGPUpdate{
PathAttributes: &packet.PathAttribute{
TypeCode: packet.OriginAttr,
Value: p.BGPPath.Origin,
Next: &packet.PathAttribute{
TypeCode: packet.ASPathAttr,
Value: asPathPA.Value,
Next: &packet.PathAttribute{
TypeCode: packet.NextHopAttr,
Value: p.BGPPath.NextHop,
},
},
},
NLRI: &packet.NLRI{
IP: pfx.Addr(),
Pfxlen: pfx.Pfxlen(),
},
} }
updateBytes, err := update.SerializeUpdate() updateBytes, err := update.SerializeUpdate()
......
...@@ -2,12 +2,10 @@ package server ...@@ -2,12 +2,10 @@ package server
import ( import (
"fmt" "fmt"
"strings"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/bio-routing/bio-rd/net" "github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/bio-rd/protocols/bgp/packet"
"github.com/bio-routing/bio-rd/route" "github.com/bio-routing/bio-rd/route"
"github.com/bio-routing/bio-rd/routingtable" "github.com/bio-routing/bio-rd/routingtable"
) )
...@@ -26,29 +24,10 @@ func newUpdateSenderAddPath(fsm *FSM) *UpdateSenderAddPath { ...@@ -26,29 +24,10 @@ 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 {
asPathPA, err := packet.ParseASPathStr(strings.TrimRight(fmt.Sprintf("%d %s", u.fsm.localASN, p.BGPPath.ASPath), " ")) update, err := updateMessageForPath(pfx, p, u.fsm)
if err != nil { if err != nil {
return fmt.Errorf("Unable to parse AS path: %v", err) log.Errorf("Unable to create BGP Update: %v", err)
} return nil
update := &packet.BGPUpdateAddPath{
PathAttributes: &packet.PathAttribute{
TypeCode: packet.OriginAttr,
Value: p.BGPPath.Origin,
Next: &packet.PathAttribute{
TypeCode: packet.ASPathAttr,
Value: asPathPA.Value,
Next: &packet.PathAttribute{
TypeCode: packet.NextHopAttr,
Value: p.BGPPath.NextHop,
},
},
},
NLRI: &packet.NLRIAddPath{
PathIdentifier: p.BGPPath.PathIdentifier,
IP: pfx.Addr(),
Pfxlen: pfx.Pfxlen(),
},
} }
updateBytes, err := update.SerializeUpdate() updateBytes, err := update.SerializeUpdate()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment