|
| 1 | +/** |
| 2 | + * Broadcast forwarding strategy. |
| 3 | + * |
| 4 | + * Using this strategy, the interest packet will be forwarded to all nexthops. |
| 5 | + */ |
| 6 | + |
| 7 | +package fw |
| 8 | + |
| 9 | +import ( |
| 10 | + "github.com/named-data/ndnd/fw/core" |
| 11 | + "github.com/named-data/ndnd/fw/defn" |
| 12 | + "github.com/named-data/ndnd/fw/table" |
| 13 | +) |
| 14 | + |
| 15 | +// The strategy to forward interests to all nexthops. |
| 16 | +type Broadcast struct { |
| 17 | + StrategyBase |
| 18 | +} |
| 19 | + |
| 20 | +// (AI GENERATED DESCRIPTION): Registers the Broadcast strategy with version 1 in the strategy registry by appending its constructor to the init list. |
| 21 | +func init() { |
| 22 | + strategyInit = append(strategyInit, func() Strategy { return &Broadcast{} }) |
| 23 | + StrategyVersions["broadcast"] = []uint64{1} |
| 24 | +} |
| 25 | + |
| 26 | +// (AI GENERATED DESCRIPTION): Initializes the *Broadcast strategy by setting up its base with the name “broadcast” and priority 1 on the provided forwarding thread. |
| 27 | +func (s *Broadcast) Instantiate(fwThread *Thread) { |
| 28 | + s.NewStrategyBase(fwThread, "broadcast", 1) |
| 29 | +} |
| 30 | + |
| 31 | +// (AI GENERATED DESCRIPTION): Sends a cached Data packet (retrieved from the Content Store) back to the requester via the specified PIT entry, using the requesting face and indicating the Content Store as the data source. |
| 32 | +func (s *Broadcast) AfterContentStoreHit( |
| 33 | + packet *defn.Pkt, |
| 34 | + pitEntry table.PitEntry, |
| 35 | + inFace uint64, |
| 36 | +) { |
| 37 | + core.Log.Trace(s, "AfterContentStoreHit", "name", packet.Name, "faceid", inFace) |
| 38 | + s.SendData(packet, pitEntry, inFace, 0) // 0 indicates ContentStore is source |
| 39 | +} |
| 40 | + |
| 41 | +// (AI GENERATED DESCRIPTION): Forwards a received Data packet to every face recorded in the PIT entry, logging each forwarding step and invoking SendData for each destination. |
| 42 | +func (s *Broadcast) AfterReceiveData( |
| 43 | + packet *defn.Pkt, |
| 44 | + pitEntry table.PitEntry, |
| 45 | + inFace uint64, |
| 46 | +) { |
| 47 | + core.Log.Trace(s, "AfterReceiveData", "name", packet.Name, "inrecords", len(pitEntry.InRecords())) |
| 48 | + for faceID := range pitEntry.InRecords() { |
| 49 | + core.Log.Trace(s, "Forwarding Data", "name", packet.Name, "faceid", faceID) |
| 50 | + s.SendData(packet, pitEntry, faceID, inFace) |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +// Forwards an incoming Interest to all next-hops |
| 55 | +func (s *Broadcast) AfterReceiveInterest( |
| 56 | + packet *defn.Pkt, |
| 57 | + pitEntry table.PitEntry, |
| 58 | + inFace uint64, |
| 59 | + nexthops []StrategyCandidateHop, |
| 60 | +) { |
| 61 | + if len(nexthops) == 0 { |
| 62 | + core.Log.Debug(s, "No nexthop found - DROP", "name", packet.Name) |
| 63 | + return |
| 64 | + } |
| 65 | + |
| 66 | + successfulForward := false |
| 67 | + |
| 68 | + for _, nh := range nexthops { |
| 69 | + if sent := s.SendInterest(packet, pitEntry, nh.HopEntry.Nexthop, inFace); sent { |
| 70 | + core.Log.Trace(s, "Forwarded Interest", "name", packet.Name, "faceid", nh.HopEntry.Nexthop) |
| 71 | + successfulForward = true |
| 72 | + } else { |
| 73 | + core.Log.Trace(s, "Error forwarding interest", "name", packet.Name, "faceid", nh.HopEntry.Nexthop) |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + if !successfulForward { |
| 78 | + core.Log.Debug(s, "No usable nexthop for Interest - DROP", "name", packet.Name) |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +// (AI GENERATED DESCRIPTION): No‑op hook invoked before satisfying an Interest in the Broadcast strategy – it performs no action. |
| 83 | +func (s *Broadcast) BeforeSatisfyInterest(pitEntry table.PitEntry, inFace uint64) { |
| 84 | + // This does nothing in Broadcast |
| 85 | +} |
0 commit comments