Skip to content

Commit

Permalink
strategy: suppression
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsejet committed Dec 17, 2024
1 parent 4bc46e4 commit de42d54
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
17 changes: 13 additions & 4 deletions fw/bestroute.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
enc "github.com/zjkmxy/go-ndn/pkg/encoding"
)

const BestRouteSuppressionTime = 500 * time.Millisecond

// BestRoute is a forwarding strategy that forwards Interests
// to the nexthop with the lowest cost.
type BestRoute struct {
Expand Down Expand Up @@ -62,15 +64,22 @@ func (s *BestRoute) AfterReceiveInterest(
inFace uint64,
nexthops []*table.FibNextHopEntry,
) {
// If there is an out record less than suppression interval
// go, drop the retransmission to suppress it.
if len(nexthops) == 0 {
core.LogDebug(s, "AfterReceiveInterest: No nexthop for Interest=", packet.Name, " - DROP")
return
}

// If there is an out record less than suppression interval ago, drop the
// retransmission to suppress it (only if the nonce is different)
for _, outRecord := range pitEntry.OutRecords() {
if outRecord.LatestTimestamp.Add(500 * time.Millisecond).After(time.Now()) {
core.LogDebug(s, "AfterReceiveInterest: Suppressed retransmission of Interest=", packet.Name, " - DROP")
if outRecord.LatestNonce != *packet.L3.Interest.NonceV &&
outRecord.LatestTimestamp.Add(BestRouteSuppressionTime).After(time.Now()) {
core.LogDebug(s, "AfterReceiveInterest: Suppressed Interest=", packet.Name, " - DROP")
return
}
}

// Sort nexthops by cost and send to best-possible nexthop
sort.Slice(nexthops, func(i, j int) bool { return nexthops[i].Cost < nexthops[j].Cost })
for _, nh := range nexthops {
core.LogTrace(s, "AfterReceiveInterest: Forwarding Interest=", packet.Name, " to FaceID=", nh.Nexthop)
Expand Down
14 changes: 14 additions & 0 deletions fw/multicast.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ package fw

import (
"reflect"
"time"

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

const MulticastSuppressionTime = 500 * time.Millisecond

// Multicast is a forwarding strategy that forwards Interests to all nexthop faces.
type Multicast struct {
StrategyBase
Expand Down Expand Up @@ -64,6 +67,17 @@ func (s *Multicast) AfterReceiveInterest(
return
}

// If there is an out record less than suppression interval ago, drop the
// retransmission to suppress it (only if the nonce is different)
for _, outRecord := range pitEntry.OutRecords() {
if outRecord.LatestNonce != *packet.L3.Interest.NonceV &&
outRecord.LatestTimestamp.Add(MulticastSuppressionTime).After(time.Now()) {
core.LogDebug(s, "AfterReceiveInterest: Suppressed Interest=", packet.Name, " - DROP")
return
}
}

// Send interest to all nexthops
for _, nexthop := range nexthops {
core.LogTrace(s, "AfterReceiveInterest: Forwarding Interest=", packet.Name, " to FaceID=", nexthop.Nexthop)
s.SendInterest(packet, pitEntry, nexthop.Nexthop, inFace)
Expand Down

0 comments on commit de42d54

Please sign in to comment.