Skip to content
Snippets Groups Projects
update_sender.go 1.54 KiB
Newer Older
  • Learn to ignore specific revisions
  • Oliver Herms's avatar
    Oliver Herms committed
    package server
    
    import (
    	"fmt"
    
    Oliver Herms's avatar
    Oliver Herms committed
    	"strings"
    
    Oliver Herms's avatar
    Oliver Herms committed
    
    	log "github.com/sirupsen/logrus"
    
    	"github.com/bio-routing/bio-rd/net"
    	"github.com/bio-routing/bio-rd/protocols/bgp/packet"
    
    Oliver Herms's avatar
    Oliver Herms committed
    	"github.com/bio-routing/bio-rd/route"
    	"github.com/bio-routing/bio-rd/routingtable"
    
    Oliver Herms's avatar
    Oliver Herms committed
    // UpdateSender converts table changes into BGP update messages
    
    Oliver Herms's avatar
    Oliver Herms committed
    type UpdateSender struct {
    
    Oliver Herms's avatar
    Oliver Herms committed
    	routingtable.ClientManager
    
    Oliver Herms's avatar
    Oliver Herms committed
    	fsm  *FSM2
    
    Oliver Herms's avatar
    Oliver Herms committed
    func newUpdateSender(fsm *FSM2) *UpdateSender {
    
    Oliver Herms's avatar
    Oliver Herms committed
    	return &UpdateSender{
    
    Oliver Herms's avatar
    Oliver Herms committed
    		iBGP: fsm.peer.localASN == fsm.peer.asn,
    
    Oliver Herms's avatar
    Oliver Herms committed
    // AddPath serializes a new path and sends out a BGP update message
    
    Oliver Herms's avatar
    Oliver Herms committed
    func (u *UpdateSender) AddPath(pfx net.Prefix, p *route.Path) error {
    
    Daniel Czerwonk's avatar
    Daniel Czerwonk committed
    	pathAttrs, err := pathAttribues(p, u.fsm)
    
    Oliver Herms's avatar
    Oliver Herms committed
    	if err != nil {
    
    		log.Errorf("Unable to create BGP Update: %v", err)
    		return nil
    
    Daniel Czerwonk's avatar
    Daniel Czerwonk committed
    		PathAttributes: pathAttrs,
    
    		NLRI: &packet.NLRI{
    			IP:     pfx.Addr(),
    			Pfxlen: pfx.Pfxlen(),
    
    	return serializeAndSendUpdate(u.fsm.con, update)
    
    Oliver Herms's avatar
    Oliver Herms committed
    // RemovePath withdraws prefix `pfx` from a peer
    
    Oliver Herms's avatar
    Oliver Herms committed
    func (u *UpdateSender) RemovePath(pfx net.Prefix, p *route.Path) bool {
    
    	err := withDrawPrefixes(u.fsm.con, pfx)
    	return err == nil
    
    Oliver Herms's avatar
    Oliver Herms committed
    // UpdateNewClient does nothing
    
    Oliver Herms's avatar
    Oliver Herms committed
    func (u *UpdateSender) UpdateNewClient(client routingtable.RouteTableClient) error {
    
    Oliver Herms's avatar
    Oliver Herms committed
    	log.Warningf("BGP Update Sender: UpdateNewClient() not supported")
    
    Oliver Herms's avatar
    Oliver Herms committed
    	return nil
    
    
    func asPathString(iBGP bool, localASN uint16, asPath string) string {
    	ret := ""
    	if iBGP {
    		ret = ret + fmt.Sprintf("%d ", localASN)
    	}
    	ret = ret + asPath
    	return strings.TrimRight(ret, " ")
    }