Table unification #2

Merged
josh merged 6 commits from table-unification into main 2024-05-05 18:15:46 +10:00
3 changed files with 45 additions and 15 deletions
Showing only changes of commit 5f3bfe2f76 - Show all commits

View file

@ -318,7 +318,6 @@ func main() {
} }
peer := &router.AURPPeer{ peer := &router.AURPPeer{
Config: cfg,
Transport: &aurp.Transport{ Transport: &aurp.Transport{
LocalDI: localDI, LocalDI: localDI,
RemoteDI: aurp.IPDomainIdentifier(raddr.IP), RemoteDI: aurp.IPDomainIdentifier(raddr.IP),
@ -426,7 +425,6 @@ func main() {
} }
// New peer! // New peer!
pr = &router.AURPPeer{ pr = &router.AURPPeer{
Config: cfg,
Transport: &aurp.Transport{ Transport: &aurp.Transport{
LocalDI: localDI, LocalDI: localDI,
RemoteDI: dh.SourceDI, // platinum rule RemoteDI: dh.SourceDI, // platinum rule

View file

@ -94,9 +94,6 @@ func (ss SenderState) String() string {
// AURPPeer handles the peering with a peer AURP router. // AURPPeer handles the peering with a peer AURP router.
type AURPPeer struct { type AURPPeer struct {
// Whole router config.
Config *Config
// AURP-Tr state for producing packets. // AURP-Tr state for producing packets.
Transport *aurp.Transport Transport *aurp.Transport
@ -440,15 +437,17 @@ func (p *AURPPeer) Handle(ctx context.Context) error {
log.Printf("AURP Peer: Received RI-Req but was not expecting one (sender state was %v)", p.sstate) log.Printf("AURP Peer: Received RI-Req but was not expecting one (sender state was %v)", p.sstate)
} }
nets := aurp.NetworkTuples{ var nets aurp.NetworkTuples
{ for _, r := range p.RouteTable.ValidNonAURPRoutes() {
Extended: true, nets = append(nets, aurp.NetworkTuple{
RangeStart: p.Config.EtherTalk.NetStart, Extended: r.Extended,
RangeEnd: p.Config.EtherTalk.NetEnd, RangeStart: r.NetStart,
Distance: 0, RangeEnd: r.NetEnd,
}, Distance: r.Distance,
})
} }
p.Transport.LocalSeq = 1 p.Transport.LocalSeq = 1
// TODO: Split tuples across multiple packets as required
lastRISent = p.Transport.NewRIRspPacket(aurp.RoutingFlagLast, nets) lastRISent = p.Transport.NewRIRspPacket(aurp.RoutingFlagLast, nets)
if _, err := p.Send(lastRISent); err != nil { if _, err := p.Send(lastRISent); err != nil {
log.Printf("AURP Peer: Couldn't send RI-Rsp packet: %v", err) log.Printf("AURP Peer: Couldn't send RI-Rsp packet: %v", err)
@ -504,11 +503,28 @@ func (p *AURPPeer) Handle(ctx context.Context) error {
sendRetries = 0 sendRetries = 0
// If SZI flag is set, send ZI-Rsp (transaction) // If SZI flag is set, send ZI-Rsp (transaction)
// TODO: split ZI-Rsp packets similarly to ZIP Replies
if pkt.Flags&aurp.RoutingFlagSendZoneInfo != 0 { if pkt.Flags&aurp.RoutingFlagSendZoneInfo != 0 {
zones := map[ddp.Network][]string{ // Inspect last routing info packet sent to determine
p.Config.EtherTalk.NetStart: {p.Config.EtherTalk.ZoneName}, // networks to gather names for
var nets []ddp.Network
switch last := lastRISent.(type) {
case *aurp.RIRspPacket:
for _, nt := range last.Networks {
nets = append(nets, nt.RangeStart)
}
case *aurp.RIUpdPacket:
for _, et := range last.Events {
// Only networks that were added
if et.EventCode != aurp.EventCodeNA {
continue
}
nets = append(nets, et.RangeStart)
}
} }
zones := p.RouteTable.ZonesForNetworks(nets)
// TODO: split ZI-Rsp packets similarly to ZIP Replies
if _, err := p.Send(p.Transport.NewZIRspPacket(zones)); err != nil { if _, err := p.Send(p.Transport.NewZIRspPacket(zones)); err != nil {
log.Printf("AURP Peer: Couldn't send ZI-Rsp packet: %v", err) log.Printf("AURP Peer: Couldn't send ZI-Rsp packet: %v", err)
} }

View file

@ -227,3 +227,19 @@ func (rt *RouteTable) ValidRoutes() []*Route {
} }
return valid return valid
} }
func (rt *RouteTable) ValidNonAURPRoutes() []*Route {
rt.mu.Lock()
defer rt.mu.Unlock()
valid := make([]*Route, 0, len(rt.routes))
for r := range rt.routes {
if r.AURPPeer != nil {
continue
}
if !r.Valid() {
continue
}
valid = append(valid, r)
}
return valid
}