Newer
Older
Christoph Petrausch
committed
"io"
"github.com/bio-routing/bio-rd/protocols/bgp/packet"
"github.com/bio-routing/bio-rd/route"
Christoph Petrausch
committed
log "github.com/sirupsen/logrus"
func pathAttribues(p *route.Path) (*packet.PathAttribute, error) {
asPath := &packet.PathAttribute{
TypeCode: packet.ASPathAttr,
Value: p.BGPPath.ASPath,
}
origin := &packet.PathAttribute{
TypeCode: packet.OriginAttr,
Value: p.BGPPath.Origin,
}
nextHop := &packet.PathAttribute{
TypeCode: packet.NextHopAttr,
Value: p.BGPPath.NextHop,
}
localPref := &packet.PathAttribute{
TypeCode: packet.LocalPrefAttr,
Value: p.BGPPath.LocalPref,
}
nextHop.Next = localPref
if err != nil {
return nil, err
}
}
}
func addOptionalPathAttribues(p *route.Path, parent *packet.PathAttribute) error {
current := parent
communities := &packet.PathAttribute{
TypeCode: packet.CommunitiesAttr,
Value: p.BGPPath.Communities,
}
current.Next = communities
current = communities
}
largeCommunities := &packet.PathAttribute{
TypeCode: packet.LargeCommunitiesAttr,
Value: p.BGPPath.LargeCommunities,
}
current.Next = largeCommunities
current = largeCommunities
}
return nil
}
Christoph Petrausch
committed
type serializeAbleUpdate interface {
SerializeUpdate(opt *packet.Options) ([]byte, error)
Christoph Petrausch
committed
}
func serializeAndSendUpdate(out io.Writer, update serializeAbleUpdate, opt *packet.Options) error {
updateBytes, err := update.SerializeUpdate(opt)
Christoph Petrausch
committed
if err != nil {
log.Errorf("Unable to serialize BGP Update: %v", err)
return nil
}
_, err = out.Write(updateBytes)
if err != nil {
return fmt.Errorf("Failed sending Update: %v", err)
}
return nil
}