Skip to content
Snippets Groups Projects
update_sender_add_path.go 1.48 KiB
Newer Older
Oliver Herms's avatar
Oliver Herms committed
package server

import (
	log "github.com/sirupsen/logrus"

	"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/routingtable"
)

Oliver Herms's avatar
Oliver Herms committed
// UpdateSenderAddPath converts table changes into BGP update messages with add path
Oliver Herms's avatar
Oliver Herms committed
type UpdateSenderAddPath struct {
	routingtable.ClientManager
Oliver Herms's avatar
Oliver Herms committed
	fsm  *FSM
Oliver Herms's avatar
Oliver Herms committed
func newUpdateSenderAddPath(fsm *FSM) *UpdateSenderAddPath {
Oliver Herms's avatar
Oliver Herms committed
	return &UpdateSenderAddPath{
Oliver Herms's avatar
Oliver Herms committed
		iBGP: fsm.peer.localASN == fsm.peer.peerASN,
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 *UpdateSenderAddPath) 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
Oliver Herms's avatar
Oliver Herms committed
	}
Daniel Czerwonk's avatar
Daniel Czerwonk committed
		PathAttributes: pathAttrs,
		NLRI: &packet.NLRIAddPath{
			PathIdentifier: p.BGPPath.PathIdentifier,
			IP:             pfx.Addr(),
			Pfxlen:         pfx.Pfxlen(),
Oliver Herms's avatar
Oliver Herms committed
		},
	}
	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 *UpdateSenderAddPath) RemovePath(pfx net.Prefix, p *route.Path) bool {
	err := withDrawPrefixesAddPath(u.fsm.con, pfx, p)
	return err == nil
Oliver Herms's avatar
Oliver Herms committed
// UpdateNewClient does nothing
Oliver Herms's avatar
Oliver Herms committed
func (u *UpdateSenderAddPath) UpdateNewClient(client routingtable.RouteTableClient) error {
Oliver Herms's avatar
Oliver Herms committed
	log.Warningf("BGP Update Sender: UpdateNewClient not implemented")
Oliver Herms's avatar
Oliver Herms committed
	return nil
}