Skip to content

Commit

Permalink
Merge pull request #75 from named-data/ranlsr
Browse files Browse the repository at this point in the history
First cut at `readvertise_nlsr`
  • Loading branch information
pulsejet authored Dec 19, 2024
2 parents 82be97a + d1b18cf commit cd9c03e
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 118 deletions.
6 changes: 3 additions & 3 deletions fw/core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ type Config struct {
} `json:"network_region"`

Rib struct {
// Enables or disables auto prefix propagation
AutoPrefixPropagation bool `json:"auto_prefix_propagation"`
// Enables or disables readvertising to the routing daemon
ReadvertiseNlsr bool `json:"readvertise_nlsr"`
} `json:"rib"`

Fib struct {
Expand Down Expand Up @@ -181,7 +181,7 @@ func DefaultConfig() *Config {

c.Tables.DeadNonceList.Lifetime = 6000
c.Tables.NetworkRegion.Regions = []string{}
c.Tables.Rib.AutoPrefixPropagation = false
c.Tables.Rib.ReadvertiseNlsr = true

c.Tables.Fib.Algorithm = "nametree"
c.Tables.Fib.Hashtable.M = 5
Expand Down
8 changes: 6 additions & 2 deletions fw/face/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ func init() {
go FaceTable.ExpirationHandler()
}

func (t *Table) String() string {
return "FaceTable"
}

// Add adds a face to the face table.
func (t *Table) Add(face LinkService) {
faceID := t.nextFaceID.Add(1) - 1
face.SetFaceID(faceID)
t.faces.Store(faceID, face)
dispatch.AddFace(faceID, face)
core.LogDebug("FaceTable", "Registered FaceID=", faceID)
core.LogDebug(t, "Registered FaceID=", faceID)
}

// Get gets the face with the specified ID (if any) from the face table.
Expand Down Expand Up @@ -80,7 +84,7 @@ func (t *Table) Remove(id uint64) {
t.faces.Delete(id)
dispatch.RemoveFace(id)
table.Rib.CleanUpFace(id)
core.LogDebug("FaceTable", "Unregistered FaceID=", id)
core.LogInfo(t, "Unregistered FaceID=", id)
}

// ExpirationHandler stops the faces that have expired
Expand Down
11 changes: 3 additions & 8 deletions fw/fw/thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ func HashNameToAllPrefixFwThreads(name enc.Name) []int {
return []int{0}
}

// Strings are likely better to work with for performance here than calling Name.prefix
// for nameString := (*name); len(nameString) > 1; nameString = nameString[:len(nameString)-1] {
// threadMap[int(xxhash.Sum64(nameString.Bytes())%uint64(len(Threads)))] = true
// }
threadList := make([]int, 0, len(Threads))
prefixHash := name.PrefixHash()
for i := 1; i < len(prefixHash); i++ {
Expand Down Expand Up @@ -221,9 +217,8 @@ func (t *Thread) processIncomingInterest(packet *defn.Pkt) {
}
}
if isReachingProducerRegion {
//interest.SetForwardingHint(nil)
//will need to add this back again!
// TODO: Unable to drop the forwarding hint for now.
// TODO: Drop the forwarding hint for now.
// No way without re-encoding Interest for now.
fhName = nil
}
}
Expand All @@ -241,7 +236,7 @@ func (t *Thread) processIncomingInterest(packet *defn.Pkt) {
}

// Check if any matching PIT entries (and if duplicate)
//read into this, looks like this one will have to be manually changed
// read into this, looks like this one will have to be manually changed
pitEntry, isDuplicate := t.pitCS.InsertInterest(interest, fhName, incomingFace.FaceID())
if isDuplicate {
// Interest loop - since we don't use Nacks, just drop
Expand Down
1 change: 0 additions & 1 deletion fw/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/named-data/YaNFD
go 1.23.0

require (
github.com/cornelk/hashmap v1.0.8
github.com/goccy/go-yaml v1.15.10
github.com/gorilla/websocket v1.5.3
github.com/stretchr/testify v1.10.0
Expand Down
2 changes: 0 additions & 2 deletions fw/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cornelk/hashmap v1.0.8 h1:nv0AWgw02n+iDcawr5It4CjQIAcdMMKRrs10HOJYlrc=
github.com/cornelk/hashmap v1.0.8/go.mod h1:RfZb7JO3RviW/rT6emczVuC/oxpdz4UsSB2LJSclR1k=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/goccy/go-yaml v1.15.10 h1:9exV2CDYm/FWHPptIIgcDiPQS+X/4uTR+HEl+GF9xJU=
Expand Down
89 changes: 89 additions & 0 deletions fw/mgmt/nlsr_readvertiser.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package mgmt

import (
"sync"

"github.com/named-data/YaNFD/core"
"github.com/named-data/YaNFD/table"
enc "github.com/zjkmxy/go-ndn/pkg/encoding"
ndn_mgmt "github.com/zjkmxy/go-ndn/pkg/ndn/mgmt_2022"
"github.com/zjkmxy/go-ndn/pkg/utils"
)

// Simple readvertiser that echoes the register command to NLSR.
// Currently the command is one-shot, and does not handle failures.
type NlsrReadvertiser struct {
m *Thread
// List of routes already advertised to NLSR
advertised map[uint64]int // hash -> count
// This is called from RIB (i.e. could be fw threads)
mutex sync.Mutex
}

func NewNlsrReadvertiser(m *Thread) *NlsrReadvertiser {
return &NlsrReadvertiser{
m: m,
advertised: make(map[uint64]int),
}
}

func (r *NlsrReadvertiser) String() string {
return "NlsrReadvertiser"
}

func (r *NlsrReadvertiser) Announce(name enc.Name, route *table.Route) {
if route.Origin != table.RouteOriginClient {
core.LogDebug(r, "skip advertise=", name, " origin=", route.Origin)
return
}
core.LogInfo(r, "advertise=", name)

r.mutex.Lock()
defer r.mutex.Unlock()
r.advertised[name.Hash()] += 1

params := &ndn_mgmt.ControlArgs{
Name: name,
Origin: utils.IdPtr(route.Origin),
Cost: utils.IdPtr(route.Cost),
}

iparams := &ndn_mgmt.ControlParameters{
Val: &ndn_mgmt.ControlArgs{Name: name},
}
cmd, _ := enc.NameFromStr("/localhost/nlsr/rib/register")
cmd = append(cmd, enc.NewBytesComponent(enc.TypeGenericNameComponent, iparams.Encode().Join()))

r.m.sendInterest(cmd, params.Encode())
}

func (r *NlsrReadvertiser) Withdraw(name enc.Name, route *table.Route) {
if route.Origin != table.RouteOriginClient {
core.LogDebug(r, "skip withdraw=", name, " origin=", route.Origin)
return
}

r.mutex.Lock()
defer r.mutex.Unlock()

nhash := name.Hash()
r.advertised[nhash] -= 1
if r.advertised[nhash] > 0 {
core.LogDebug(r, "skip withdraw=", name, " still advertised")
return
}
core.LogInfo(r, "withdraw=", name)

params := &ndn_mgmt.ControlArgs{
Name: name,
Origin: utils.IdPtr(route.Origin),
}

iparams := &ndn_mgmt.ControlParameters{
Val: &ndn_mgmt.ControlArgs{Name: name},
}
cmd, _ := enc.NameFromStr("/localhost/nlsr/rib/unregister")
cmd = append(cmd, enc.NewBytesComponent(enc.TypeGenericNameComponent, iparams.Encode().Join()))

r.m.sendInterest(cmd, params.Encode())
}
14 changes: 7 additions & 7 deletions fw/mgmt/rib.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,13 @@ func (r *RIBModule) register(interest *spec.Interest, pitToken []byte, inFace ui
*expirationPeriod = time.Duration(*params.ExpirationPeriod) * time.Millisecond
}

table.Rib.AddEncRoute(params.Name, faceID, origin, cost, flags, expirationPeriod)
table.Rib.AddEncRoute(params.Name, &table.Route{
FaceID: faceID,
Origin: origin,
Cost: cost,
Flags: flags,
ExpirationPeriod: expirationPeriod,
})
if expirationPeriod != nil {
core.LogInfo(r, "Created route for Prefix=", params.Name, ", FaceID=", faceID, ", Origin=", origin,
", Cost=", cost, ", Flags=0x", strconv.FormatUint(flags, 16), ", ExpirationPeriod=", expirationPeriod)
Expand Down Expand Up @@ -213,12 +219,6 @@ func (r *RIBModule) announce(interest *spec.Interest, pitToken []byte, inFace ui
if data != nil {
}

// prefix := data.Name()[:len(data.Name())-3]
// faceID := inFace
// origin := table.RouteOriginPrefixAnn
// cost := uint64(0)
// expirationPeriod := 0 * time.Millisecond // TODO: Wrong thing to do

core.LogError(r, "YaNFD does not support PrefixAnnouncement")
response = makeControlResponse(501, "YaNFD does not support PrefixAnnouncement", nil)
r.manager.sendResponse(response, interest, pitToken, inFace)
Expand Down
31 changes: 30 additions & 1 deletion fw/mgmt/thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
package mgmt

import (
"math/rand"
"time"

"github.com/named-data/YaNFD/core"
"github.com/named-data/YaNFD/face"
"github.com/named-data/YaNFD/table"
enc "github.com/zjkmxy/go-ndn/pkg/encoding"
basic_engine "github.com/zjkmxy/go-ndn/pkg/engine/basic"
"github.com/zjkmxy/go-ndn/pkg/ndn"
mgmt "github.com/zjkmxy/go-ndn/pkg/ndn/mgmt_2022"
spec "github.com/zjkmxy/go-ndn/pkg/ndn/spec_2022"
Expand All @@ -28,11 +30,14 @@ type Thread struct {
localPrefix enc.Name
nonLocalPrefix enc.Name
modules map[string]Module
timer ndn.Timer
}

// MakeMgmtThread creates a new management thread.
func MakeMgmtThread() *Thread {
m := new(Thread)
m.timer = basic_engine.NewTimer()

var err error
m.localPrefix, err = enc.NameFromStr("/localhost/nfd")
if err != nil {
Expand All @@ -42,13 +47,21 @@ func MakeMgmtThread() *Thread {
if err != nil {
core.LogFatal(m, "Unable to create name for management prefix: ", err)
}

m.modules = make(map[string]Module)
m.registerModule("cs", new(ContentStoreModule))
m.registerModule("faces", new(FaceModule))
m.registerModule("fib", new(FIBModule))
m.registerModule("rib", new(RIBModule))
m.registerModule("status", new(ForwarderStatusModule))
m.registerModule("strategy-choice", new(StrategyChoiceModule))

// readvertisers run in the management thread for ease of
// implementation, since they use the internal transport
if core.GetConfig().Tables.Rib.ReadvertiseNlsr {
table.AddReadvertiser(NewNlsrReadvertiser(m))
}

return m
}

Expand All @@ -65,6 +78,22 @@ func (m *Thread) prefixLength() int {
return len(m.localPrefix)
}

func (m *Thread) sendInterest(name enc.Name, params enc.Wire) {
config := ndn.InterestConfig{
MustBeFresh: true,
Nonce: utils.IdPtr(rand.Uint64()),
}
interestWire, _, finalName, err := spec.Spec{}.MakeInterest(
name, &config, params, sec.NewSha256IntSigner(m.timer))
if err != nil {
core.LogWarn(m, "Unable to encode Interest for ", name, ": ", err)
return
}

m.transport.Send(interestWire, nil, nil)
core.LogTrace(m, "Sent management Interest for ", finalName)
}

func (m *Thread) sendResponse(response *mgmt.ControlResponse, interest *spec.Interest, pitToken []byte, inFace uint64) {
encodedResponse := response.Encode()
dataWire, _, err := spec.Spec{}.MakeData(interest.NameV,
Expand Down Expand Up @@ -117,7 +146,7 @@ func (m *Thread) Run() {

// We only expect Interests, so drop Data packets
if pkt.Interest == nil {
core.LogWarn(m, "Dropping received non-Interest packet")
core.LogDebug(m, "Dropping received non-Interest packet")
continue
}
interest := pkt.Interest
Expand Down
74 changes: 0 additions & 74 deletions fw/table/measurements.go

This file was deleted.

Loading

0 comments on commit cd9c03e

Please sign in to comment.