diff --git a/fw/defn/pkt.go b/fw/defn/pkt.go index b970ffa8..df115845 100644 --- a/fw/defn/pkt.go +++ b/fw/defn/pkt.go @@ -9,6 +9,7 @@ package defn import ( enc "github.com/named-data/ndnd/std/encoding" + "github.com/named-data/ndnd/std/ndn" spec "github.com/named-data/ndnd/std/ndn/spec_2022" ) @@ -16,7 +17,7 @@ import ( // received on the link, plus any associated metadata. type Pkt struct { Name enc.Name - L3 *spec.Packet + L3 PacketIntf Raw []byte PitToken []byte @@ -25,3 +26,9 @@ type Pkt struct { NextHopFaceID *uint64 CachePolicy *uint64 } + +type PacketIntf struct { + LpPacket *spec.LpPacket + Interest ndn.Interest + Data ndn.Data +} diff --git a/fw/face/link-service.go b/fw/face/link-service.go index 579c9cd0..22f6003e 100644 --- a/fw/face/link-service.go +++ b/fw/face/link-service.go @@ -226,7 +226,7 @@ func (l *linkServiceBase) dispatchInterest(pkt *defn.Pkt) { } // Store name for easy access - pkt.Name = pkt.L3.Interest.NameV + pkt.Name = pkt.L3.Interest.Name() // Hash name to thread thread := fw.HashNameToFwThread(pkt.Name) @@ -240,7 +240,7 @@ func (l *linkServiceBase) dispatchData(pkt *defn.Pkt) { } // Store name for easy access - pkt.Name = pkt.L3.Data.NameV + pkt.Name = pkt.L3.Data.Name() // Decode PitToken. If it's for us, it's a uint16 + uint32. if len(pkt.PitToken) == 6 { diff --git a/fw/face/ndnlp-link-service.go b/fw/face/ndnlp-link-service.go index b64c7014..75d3738f 100644 --- a/fw/face/ndnlp-link-service.go +++ b/fw/face/ndnlp-link-service.go @@ -444,8 +444,21 @@ func (op *NDNLPLinkServiceOptions) Flags() (ret uint64) { } // Reads a packet without validating the internal fields -func ReadPacketUnverified(reader enc.ParseReader) (*spec.Packet, error) { +func ReadPacketUnverified(reader enc.ParseReader) (ret defn.PacketIntf, err error) { context := spec.PacketParsingContext{} context.Init() - return context.Parse(reader, false) + packet, err := context.Parse(reader, false) + if err != nil { + return + } + + if packet.LpPacket != nil { + ret.LpPacket = packet.LpPacket + } else if packet.Interest != nil { + ret.Interest = packet.Interest + } else if packet.Data != nil { + ret.Data = packet.Data + } + + return ret, nil } diff --git a/fw/fw/bestroute.go b/fw/fw/bestroute.go index fd856cb6..c38c017d 100644 --- a/fw/fw/bestroute.go +++ b/fw/fw/bestroute.go @@ -73,7 +73,7 @@ func (s *BestRoute) AfterReceiveInterest( // 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 && + if outRecord.LatestNonce != *packet.L3.Interest.Nonce() && outRecord.LatestTimestamp.Add(BestRouteSuppressionTime).After(time.Now()) { core.LogDebug(s, "AfterReceiveInterest: Suppressed Interest=", packet.Name, " - DROP") return diff --git a/fw/fw/multicast.go b/fw/fw/multicast.go index 8642b3fb..d5b25118 100644 --- a/fw/fw/multicast.go +++ b/fw/fw/multicast.go @@ -71,7 +71,7 @@ func (s *Multicast) AfterReceiveInterest( // 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 && + if outRecord.LatestNonce != *packet.L3.Interest.Nonce() && outRecord.LatestTimestamp.Add(MulticastSuppressionTime).After(time.Now()) { core.LogDebug(s, "AfterReceiveInterest: Suppressed Interest=", packet.Name, " - DROP") return diff --git a/fw/fw/thread.go b/fw/fw/thread.go index 081190cb..8ca29e3b 100644 --- a/fw/fw/thread.go +++ b/fw/fw/thread.go @@ -184,12 +184,12 @@ func (t *Thread) processIncomingInterest(packet *defn.Pkt) { return } - if interest.HopLimitV != nil { - core.LogTrace(t, "Interest ", packet.Name, " has HopLimit=", *interest.HopLimitV) - if *interest.HopLimitV == 0 { + if interest.HopLimit() != nil { + core.LogTrace(t, "Interest ", packet.Name, " has HopLimit=", *interest.HopLimit()) + if *interest.HopLimit() == 0 { return } - *interest.HopLimitV -= 1 + *interest.HopLimit() -= 1 } // Log PIT token (if any) @@ -197,8 +197,8 @@ func (t *Thread) processIncomingInterest(packet *defn.Pkt) { // Check if violates /localhost if incomingFace.Scope() == defn.NonLocal && - len(interest.NameV) > 0 && - bytes.Equal(interest.NameV[0].Val, LOCALHOST) { + len(interest.Name()) > 0 && + bytes.Equal(interest.Name()[0].Val, LOCALHOST) { core.LogWarn(t, "Interest ", packet.Name, " from non-local face=", incomingFace.FaceID(), " violates /localhost scope - DROP") return } @@ -208,10 +208,10 @@ func (t *Thread) processIncomingInterest(packet *defn.Pkt) { // Check for forwarding hint and, if present, determine if reaching producer region (and then strip forwarding hint) isReachingProducerRegion := true var fhName enc.Name = nil - hint := interest.ForwardingHintV - if hint != nil && len(hint.Names) > 0 { + hint := interest.ForwardingHint() + if hint != nil && len(hint) > 0 { isReachingProducerRegion = false - for _, fh := range hint.Names { + for _, fh := range hint { if table.NetworkRegion.IsProducer(fh) { isReachingProducerRegion = true break @@ -227,14 +227,14 @@ func (t *Thread) processIncomingInterest(packet *defn.Pkt) { } // Drop packet if no nonce is found - if interest.NonceV == nil { + if interest.Nonce() == nil { core.LogDebug(t, "Interest ", packet.Name, " is missing Nonce - DROP") return } // Check if packet is in dead nonce list - if exists := t.deadNonceList.Find(interest.NameV, *interest.NonceV); exists { - core.LogDebug(t, "Interest ", packet.Name, " is dropped by DeadNonce: ", *interest.NonceV) + if exists := t.deadNonceList.Find(interest.Name(), *interest.Nonce()); exists { + core.LogDebug(t, "Interest ", packet.Name, " is dropped by DeadNonce: ", *interest.Nonce()) return } @@ -248,7 +248,7 @@ func (t *Thread) processIncomingInterest(packet *defn.Pkt) { } // Get strategy for name - strategyName := table.FibStrategyTable.FindStrategyEnc(interest.NameV) + strategyName := table.FibStrategyTable.FindStrategyEnc(interest.Name()) strategy := t.strategies[strategyName.Hash()] // Add in-record and determine if already pending @@ -271,7 +271,7 @@ func (t *Thread) processIncomingInterest(packet *defn.Pkt) { packet.L3.Data = csData packet.L3.Interest = nil packet.Raw = csWire - packet.Name = csData.NameV + packet.Name = csData.Name() strategy.AfterContentStoreHit(packet, pitEntry, incomingFace.FaceID()) return } else if err != nil { @@ -287,7 +287,7 @@ func (t *Thread) processIncomingInterest(packet *defn.Pkt) { // Add the previous nonce to the dead nonce list to prevent further looping // TODO: review this design, not specified in NFD dev guide - t.deadNonceList.Insert(interest.NameV, prevNonce) + t.deadNonceList.Insert(interest.Name(), prevNonce) } // Update PIT entry expiration timer @@ -309,7 +309,7 @@ func (t *Thread) processIncomingInterest(packet *defn.Pkt) { } // Use forwarding hint if present - lookupName := interest.NameV + lookupName := interest.Name() if fhName != nil { lookupName = fhName } @@ -356,7 +356,7 @@ func (t *Thread) processOutgoingInterest( } // Drop if HopLimit (if present) on Interest going to non-local face is 0. If so, drop - if interest.HopLimitV != nil && int(*interest.HopLimitV) == 0 && + if interest.HopLimit() != nil && int(*interest.HopLimit()) == 0 && outgoingFace.Scope() == defn.NonLocal { core.LogDebug(t, "Attempting to send Interest=", packet.Name, " with HopLimit=0 to non-local face - DROP") return false @@ -424,7 +424,7 @@ func (t *Thread) processIncomingData(packet *defn.Pkt) { // Check if violates /localhost if incomingFace.Scope() == defn.NonLocal && len(packet.Name) > 0 && - bytes.Equal(data.NameV[0].Val, LOCALHOST) { + bytes.Equal(data.Name()[0].Val, LOCALHOST) { core.LogWarn(t, "Data ", packet.Name, " from non-local FaceID=", *packet.IncomingFaceID, " violates /localhost scope - DROP") return } @@ -443,7 +443,7 @@ func (t *Thread) processIncomingData(packet *defn.Pkt) { } // Get strategy for name - strategyName := table.FibStrategyTable.FindStrategyEnc(data.NameV) + strategyName := table.FibStrategyTable.FindStrategyEnc(data.Name()) strategy := t.strategies[strategyName.Hash()] if len(pitEntries) == 1 { @@ -463,7 +463,7 @@ func (t *Thread) processIncomingData(packet *defn.Pkt) { // Insert into dead nonce list for _, outRecord := range pitEntry.OutRecords() { - t.deadNonceList.Insert(data.NameV, outRecord.LatestNonce) + t.deadNonceList.Insert(data.Name(), outRecord.LatestNonce) } // Clear out records from PIT entry @@ -496,7 +496,7 @@ func (t *Thread) processIncomingData(packet *defn.Pkt) { // Insert into dead nonce list for _, outRecord := range pitEntries[0].GetOutRecords() { - t.deadNonceList.Insert(data.NameV, outRecord.LatestNonce) + t.deadNonceList.Insert(data.Name(), outRecord.LatestNonce) } // Clear PIT entry's in- and out-records @@ -533,7 +533,7 @@ func (t *Thread) processOutgoingData( } // Check if violates /localhost - if outgoingFace.Scope() == defn.NonLocal && len(data.NameV) > 0 && bytes.Equal(data.NameV[0].Val, LOCALHOST) { + if outgoingFace.Scope() == defn.NonLocal && len(data.Name()) > 0 && bytes.Equal(data.Name()[0].Val, LOCALHOST) { core.LogWarn(t, "Data ", packet.Name, " cannot be sent to non-local FaceID=", nexthop, " since violates /localhost scope - DROP") return } diff --git a/fw/table/cs-lru.go b/fw/table/cs-lru.go index 6bd1f228..1b3a0506 100644 --- a/fw/table/cs-lru.go +++ b/fw/table/cs-lru.go @@ -10,7 +10,7 @@ package table import ( "container/list" - spec "github.com/named-data/ndnd/std/ndn/spec_2022" + "github.com/named-data/ndnd/std/ndn" ) // CsLRU is a least recently used (LRU) replacement policy for the Content Store. @@ -30,12 +30,12 @@ func NewCsLRU(cs PitCsTable) *CsLRU { } // AfterInsert is called after a new entry is inserted into the Content Store. -func (l *CsLRU) AfterInsert(index uint64, wire []byte, data *spec.Data) { +func (l *CsLRU) AfterInsert(index uint64, wire []byte, data ndn.Data) { l.locations[index] = l.queue.PushBack(index) } // AfterRefresh is called after a new data packet refreshes an existing entry in the Content Store. -func (l *CsLRU) AfterRefresh(index uint64, wire []byte, data *spec.Data) { +func (l *CsLRU) AfterRefresh(index uint64, wire []byte, data ndn.Data) { if location, ok := l.locations[index]; ok { l.queue.Remove(location) } diff --git a/fw/table/cs-replacement.go b/fw/table/cs-replacement.go index 3b0677ba..80543604 100644 --- a/fw/table/cs-replacement.go +++ b/fw/table/cs-replacement.go @@ -7,15 +7,17 @@ package table -import spec "github.com/named-data/ndnd/std/ndn/spec_2022" +import ( + "github.com/named-data/ndnd/std/ndn" +) // CsReplacementPolicy represents a cache replacement policy for the Content Store. type CsReplacementPolicy interface { // AfterInsert is called after a new entry is inserted into the Content Store. - AfterInsert(index uint64, wire []byte, data *spec.Data) + AfterInsert(index uint64, wire []byte, data ndn.Data) // AfterRefresh is called after a new data packet refreshes an existing entry in the Content Store. - AfterRefresh(index uint64, wire []byte, data *spec.Data) + AfterRefresh(index uint64, wire []byte, data ndn.Data) // BeforeErase is called before an entry is erased from the Content Store through management. BeforeErase(index uint64, wire []byte) diff --git a/fw/table/dead-nonce-list.go b/fw/table/dead-nonce-list.go index 75872d15..03051c35 100644 --- a/fw/table/dead-nonce-list.go +++ b/fw/table/dead-nonce-list.go @@ -31,15 +31,15 @@ func NewDeadNonceList() *DeadNonceList { } // Find returns whether the specified name and nonce combination are present in the Dead Nonce List. -func (d *DeadNonceList) Find(name enc.Name, nonce uint32) bool { - _, ok := d.list[name.Hash()+uint64(nonce)] +func (d *DeadNonceList) Find(name enc.Name, nonce uint64) bool { + _, ok := d.list[name.Hash()+nonce] return ok } // Insert inserts an entry in the Dead Nonce List with the specified name and nonce. // Returns whether nonce already present. -func (d *DeadNonceList) Insert(name enc.Name, nonce uint32) bool { - hash := name.Hash() + uint64(nonce) +func (d *DeadNonceList) Insert(name enc.Name, nonce uint64) bool { + hash := name.Hash() + nonce _, exists := d.list[hash] if !exists { diff --git a/fw/table/pit-cs-tree.go b/fw/table/pit-cs-tree.go index e9b90a89..9e3722fd 100644 --- a/fw/table/pit-cs-tree.go +++ b/fw/table/pit-cs-tree.go @@ -6,7 +6,7 @@ import ( "github.com/named-data/ndnd/fw/core" enc "github.com/named-data/ndnd/std/encoding" - spec "github.com/named-data/ndnd/std/ndn/spec_2022" + "github.com/named-data/ndnd/std/ndn" pq "github.com/named-data/ndnd/std/utils/priority_queue" ) @@ -131,14 +131,14 @@ func (e *nameTreePitEntry) PitCs() PitCsTable { // InsertInterest inserts an entry in the PIT upon receipt of an Interest. // Returns tuple of PIT entry and whether the Nonce is a duplicate. -func (p *PitCsTree) InsertInterest(interest *spec.Interest, hint enc.Name, inFace uint64) (PitEntry, bool) { - name := interest.NameV.Clone() +func (p *PitCsTree) InsertInterest(interest ndn.Interest, hint enc.Name, inFace uint64) (PitEntry, bool) { + name := interest.Name().Clone() node := p.root.fillTreeToPrefixEnc(name) var entry *nameTreePitEntry for _, curEntry := range node.pitEntries { - if curEntry.CanBePrefix() == interest.CanBePrefixV && - curEntry.MustBeFresh() == interest.MustBeFreshV && + if curEntry.CanBePrefix() == interest.CanBePrefix() && + curEntry.MustBeFresh() == interest.MustBeFresh() && ((hint == nil && curEntry.ForwardingHintNew() == nil) || hint.Equal(curEntry.ForwardingHintNew())) { entry = curEntry break @@ -151,8 +151,8 @@ func (p *PitCsTree) InsertInterest(interest *spec.Interest, hint enc.Name, inFac entry.node = node entry.pitCsTable = p entry.encname = name - entry.canBePrefix = interest.CanBePrefixV - entry.mustBeFresh = interest.MustBeFreshV + entry.canBePrefix = interest.CanBePrefix() + entry.mustBeFresh = interest.MustBeFresh() entry.forwardingHintNew = hint entry.inRecords = make(map[uint64]*PitInRecord) entry.outRecords = make(map[uint64]*PitOutRecord) @@ -166,7 +166,7 @@ func (p *PitCsTree) InsertInterest(interest *spec.Interest, hint enc.Name, inFac // Only considered a duplicate (loop) if from different face since // is just retransmission and not loop if same face for face, inRecord := range entry.inRecords { - if face != inFace && inRecord.LatestNonce == *interest.NonceV { + if face != inFace && inRecord.LatestNonce == *interest.Nonce() { return entry, true } } @@ -205,12 +205,12 @@ func (p *PitCsTree) RemoveInterest(pitEntry PitEntry) bool { // by the given data. // Example: If we have interests /a and /a/b, a prefix search for data with name /a/b // will return PitEntries for both /a and /a/b -func (p *PitCsTree) FindInterestExactMatchEnc(interest *spec.Interest) PitEntry { - node := p.root.findExactMatchEntryEnc(interest.NameV) +func (p *PitCsTree) FindInterestExactMatchEnc(interest ndn.Interest) PitEntry { + node := p.root.findExactMatchEntryEnc(interest.Name()) if node != nil { for _, curEntry := range node.pitEntries { - if curEntry.CanBePrefix() == interest.CanBePrefixV && - curEntry.MustBeFresh() == interest.MustBeFreshV { + if curEntry.CanBePrefix() == interest.CanBePrefix() && + curEntry.MustBeFresh() == interest.MustBeFresh() { return curEntry } } @@ -222,14 +222,14 @@ func (p *PitCsTree) FindInterestExactMatchEnc(interest *spec.Interest) PitEntry // by the given data. // Example: If we have interests /a and /a/b, a prefix search for data with name /a/b // will return PitEntries for both /a and /a/b -func (p *PitCsTree) FindInterestPrefixMatchByDataEnc(data *spec.Data, token *uint32) []PitEntry { +func (p *PitCsTree) FindInterestPrefixMatchByDataEnc(data ndn.Data, token *uint32) []PitEntry { if token != nil { if entry, ok := p.pitTokenMap[*token]; ok && entry.Token() == *token { return []PitEntry{entry} } return nil } - return p.findInterestPrefixMatchByNameEnc(data.NameV) + return p.findInterestPrefixMatchByNameEnc(data.Name()) } func (p *PitCsTree) findInterestPrefixMatchByNameEnc(name enc.Name) []PitEntry { @@ -267,7 +267,7 @@ func (p *PitCsTree) IsCsServing() bool { // InsertOutRecord inserts an outrecord for the given interest, updating the // preexisting one if it already occcurs. -func (e *nameTreePitEntry) InsertOutRecord(interest *spec.Interest, face uint64) *PitOutRecord { +func (e *nameTreePitEntry) InsertOutRecord(interest ndn.Interest, face uint64) *PitOutRecord { lifetime := time.Millisecond * 4000 if interest.Lifetime() != nil { lifetime = *interest.Lifetime() @@ -278,18 +278,18 @@ func (e *nameTreePitEntry) InsertOutRecord(interest *spec.Interest, face uint64) if record, ok = e.outRecords[face]; !ok { record := new(PitOutRecord) record.Face = face - record.LatestNonce = *interest.NonceV + record.LatestNonce = *interest.Nonce() record.LatestTimestamp = time.Now() - record.LatestInterest = interest.NameV.Clone() + record.LatestInterest = interest.Name().Clone() record.ExpirationTime = time.Now().Add(lifetime) e.outRecords[face] = record return record } // Existing record - record.LatestNonce = *interest.NonceV + record.LatestNonce = *interest.Nonce() record.LatestTimestamp = time.Now() - record.LatestInterest = interest.NameV.Clone() + record.LatestInterest = interest.Name().Clone() record.ExpirationTime = time.Now().Add(lifetime) return record } @@ -375,12 +375,12 @@ func (p *PitCsTree) generateNewPitToken() uint32 { // FindMatchingDataFromCS finds the best matching entry in the CS (if any). // If MustBeFresh is set to true in the Interest, only non-stale CS entries // will be returned. -func (p *PitCsTree) FindMatchingDataFromCS(interest *spec.Interest) CsEntry { - node := p.root.findExactMatchEntryEnc(interest.NameV) +func (p *PitCsTree) FindMatchingDataFromCS(interest ndn.Interest) CsEntry { + node := p.root.findExactMatchEntryEnc(interest.Name()) if node != nil { - if !interest.CanBePrefixV { + if !interest.CanBePrefix() { if node.csEntry != nil && - (!interest.MustBeFreshV || time.Now().Before(node.csEntry.staleTime)) { + (!interest.MustBeFresh() || time.Now().Before(node.csEntry.staleTime)) { p.csReplacement.BeforeUse(node.csEntry.index, node.csEntry.wire) return node.csEntry } @@ -394,11 +394,12 @@ func (p *PitCsTree) FindMatchingDataFromCS(interest *spec.Interest) CsEntry { } // InsertData inserts a Data packet into the Content Store. -func (p *PitCsTree) InsertData(data *spec.Data, wire []byte) { - index := data.NameV.Hash() +func (p *PitCsTree) InsertData(data ndn.Data, wire []byte) { + dataName := data.Name() + index := dataName.Hash() staleTime := time.Now() - if data.MetaInfo != nil && data.MetaInfo.FreshnessPeriod != nil { - staleTime = staleTime.Add(*data.MetaInfo.FreshnessPeriod) + if data.Freshness() != nil { + staleTime = staleTime.Add(*data.Freshness()) } store := make([]byte, len(wire)) @@ -413,7 +414,7 @@ func (p *PitCsTree) InsertData(data *spec.Data, wire []byte) { } else { // New entry p.nCsEntries++ - node := p.root.fillTreeToPrefixEnc(data.NameV) + node := p.root.fillTreeToPrefixEnc(data.Name()) node.csEntry = &nameTreeCsEntry{ node: node, baseCsEntry: baseCsEntry{ @@ -446,15 +447,15 @@ func (p *PitCsTree) eraseCsDataFromReplacementStrategy(index uint64) { // the interest as far as possible with the nodes components in the PitCSTree. // For example, if we have data for /a/b/v=10 and the interest is /a/b, // p should be the `b` node, not the root node. -func (p *pitCsTreeNode) findMatchingDataCSPrefix(interest *spec.Interest) CsEntry { - if p.csEntry != nil && (!interest.MustBeFreshV || time.Now().Before(p.csEntry.staleTime)) { +func (p *pitCsTreeNode) findMatchingDataCSPrefix(interest ndn.Interest) CsEntry { + if p.csEntry != nil && (!interest.MustBeFresh() || time.Now().Before(p.csEntry.staleTime)) { // A csEntry exists at this node and is acceptable to satisfy the interest return p.csEntry } // No csEntry at current node, look farther down the tree // We must have already matched the entire interest name - if p.depth >= len(interest.NameV) { + if p.depth >= len(interest.Name()) { for _, child := range p.children { potentialMatch := child.findMatchingDataCSPrefix(interest) if potentialMatch != nil { diff --git a/fw/table/pit-cs-tree_test.go b/fw/table/pit-cs-tree_test.go index a286a463..b24386c0 100644 --- a/fw/table/pit-cs-tree_test.go +++ b/fw/table/pit-cs-tree_test.go @@ -405,25 +405,25 @@ func TestInsertOutRecord(t *testing.T) { outRecord := pitEntry.InsertOutRecord(interest, inFace) assert.Equal(t, outRecord.Face, inFace) assert.Equal(t, outRecord.LatestInterest, interest.NameV) - assert.True(t, outRecord.LatestNonce == *interest.NonceV) + assert.True(t, outRecord.LatestNonce == *interest.Nonce()) // Update existing outrecord - oldNonce := new(uint32) + oldNonce := new(uint64) *oldNonce = 2 - *interest.NonceV = *oldNonce + *interest.NonceV = uint32(*oldNonce) *interest.NonceV = 3 outRecord = pitEntry.InsertOutRecord(interest, inFace) assert.Equal(t, outRecord.Face, inFace) assert.Equal(t, outRecord.LatestInterest, interest.NameV) - assert.True(t, outRecord.LatestNonce == *interest.NonceV) + assert.True(t, outRecord.LatestNonce == *interest.Nonce()) assert.False(t, outRecord.LatestNonce == *oldNonce) // Add new outrecord on a different face inFace2 := uint64(2222) outRecord = pitEntry.InsertOutRecord(interest, inFace2) assert.Equal(t, outRecord.Face, inFace2) - assert.Equal(t, outRecord.LatestInterest, interest.NameV) - assert.True(t, outRecord.LatestNonce == *interest.NonceV) + assert.Equal(t, outRecord.LatestInterest, interest.Name()) + assert.True(t, outRecord.LatestNonce == *interest.Nonce()) } func TestGetOutRecords(t *testing.T) { @@ -441,8 +441,8 @@ func TestGetOutRecords(t *testing.T) { outRecords := pitEntry.GetOutRecords() assert.Equal(t, len(outRecords), 1) assert.Equal(t, outRecords[0].Face, inFace) - assert.Equal(t, outRecords[0].LatestInterest, interest.NameV) - assert.True(t, outRecords[0].LatestNonce == *interest.NonceV) + assert.Equal(t, outRecords[0].LatestInterest, interest.Name()) + assert.True(t, outRecords[0].LatestNonce == *interest.Nonce()) // Update existing outrecord oldNonce := new(uint32) @@ -453,8 +453,8 @@ func TestGetOutRecords(t *testing.T) { outRecords = pitEntry.GetOutRecords() assert.Equal(t, len(outRecords), 1) assert.Equal(t, outRecords[0].Face, inFace) - assert.Equal(t, outRecords[0].LatestInterest, interest.NameV) - assert.True(t, outRecords[0].LatestNonce == *interest.NonceV) + assert.Equal(t, outRecords[0].LatestInterest, interest.Name()) + assert.True(t, outRecords[0].LatestNonce == *interest.Nonce()) // Add new outrecord on a different face inFace2 := uint64(2222) @@ -467,12 +467,12 @@ func TestGetOutRecords(t *testing.T) { assert.Equal(t, len(outRecords), 2) assert.Equal(t, outRecords[0].Face, inFace) - assert.Equal(t, outRecords[0].LatestInterest, interest.NameV) - assert.True(t, outRecords[0].LatestNonce == *interest.NonceV) + assert.Equal(t, outRecords[0].LatestInterest, interest.Name()) + assert.True(t, outRecords[0].LatestNonce == *interest.Nonce()) assert.Equal(t, outRecords[1].Face, inFace2) - assert.Equal(t, outRecords[1].LatestInterest, interest.NameV) - assert.True(t, outRecords[1].LatestNonce == *interest.NonceV) + assert.Equal(t, outRecords[1].LatestInterest, interest.Name()) + assert.True(t, outRecords[1].LatestNonce == *interest.Nonce()) } func FindMatchingDataFromCS(t *testing.T) { diff --git a/fw/table/pit-cs.go b/fw/table/pit-cs.go index b12aaf3a..b68846f8 100644 --- a/fw/table/pit-cs.go +++ b/fw/table/pit-cs.go @@ -11,20 +11,21 @@ import ( "time" enc "github.com/named-data/ndnd/std/encoding" + "github.com/named-data/ndnd/std/ndn" spec "github.com/named-data/ndnd/std/ndn/spec_2022" ) // PitCsTable dictates what functionality a Pit-Cs table should implement // Warning: All functions must be called in the same forwarding goroutine as the creation of the table. type PitCsTable interface { - InsertInterest(interest *spec.Interest, hint enc.Name, inFace uint64) (PitEntry, bool) + InsertInterest(interest ndn.Interest, hint enc.Name, inFace uint64) (PitEntry, bool) RemoveInterest(pitEntry PitEntry) bool - FindInterestExactMatchEnc(interest *spec.Interest) PitEntry - FindInterestPrefixMatchByDataEnc(data *spec.Data, token *uint32) []PitEntry + FindInterestExactMatchEnc(interest ndn.Interest) PitEntry + FindInterestPrefixMatchByDataEnc(data ndn.Data, token *uint32) []PitEntry PitSize() int - InsertData(data *spec.Data, wire []byte) - FindMatchingDataFromCS(interest *spec.Interest) CsEntry + InsertData(data ndn.Data, wire []byte) + FindMatchingDataFromCS(interest ndn.Interest) CsEntry CsSize() int IsCsAdmitting() bool IsCsServing() bool @@ -60,8 +61,8 @@ type PitEntry interface { Token() uint32 - InsertInRecord(interest *spec.Interest, face uint64, incomingPitToken []byte) (*PitInRecord, bool, uint32) - InsertOutRecord(interest *spec.Interest, face uint64) *PitOutRecord + InsertInRecord(interest ndn.Interest, face uint64, incomingPitToken []byte) (*PitInRecord, bool, uint64) + InsertOutRecord(interest ndn.Interest, face uint64) *PitOutRecord GetOutRecords() []*PitOutRecord ClearOutRecords() @@ -90,7 +91,7 @@ type PitInRecord struct { Face uint64 LatestTimestamp time.Time LatestInterest enc.Name - LatestNonce uint32 + LatestNonce uint64 ExpirationTime time.Time PitToken []byte } @@ -100,7 +101,7 @@ type PitOutRecord struct { Face uint64 LatestTimestamp time.Time LatestInterest enc.Name - LatestNonce uint32 + LatestNonce uint64 ExpirationTime time.Time } @@ -108,7 +109,7 @@ type PitOutRecord struct { type CsEntry interface { Index() uint64 // the hash of the entry, for fast lookup StaleTime() time.Time - Copy() (*spec.Data, []byte, error) + Copy() (ndn.Data, []byte, error) } type baseCsEntry struct { @@ -121,10 +122,10 @@ type baseCsEntry struct { // metadata and returning whether there was already an in-record in the entry. // The third return value is the previous nonce if the in-record already existed. func (bpe *basePitEntry) InsertInRecord( - interest *spec.Interest, + interest ndn.Interest, face uint64, incomingPitToken []byte, -) (*PitInRecord, bool, uint32) { +) (*PitInRecord, bool, uint64) { lifetime := time.Millisecond * 4000 if interest.Lifetime() != nil { lifetime = *interest.Lifetime() @@ -135,9 +136,9 @@ func (bpe *basePitEntry) InsertInRecord( if record, ok = bpe.inRecords[face]; !ok { record := new(PitInRecord) record.Face = face - record.LatestNonce = *interest.NonceV + record.LatestNonce = *interest.Nonce() record.LatestTimestamp = time.Now() - record.LatestInterest = interest.NameV.Clone() + record.LatestInterest = interest.Name().Clone() record.ExpirationTime = time.Now().Add(lifetime) record.PitToken = append([]byte{}, incomingPitToken...) bpe.inRecords[face] = record @@ -146,9 +147,9 @@ func (bpe *basePitEntry) InsertInRecord( // Existing record previousNonce := record.LatestNonce - record.LatestNonce = *interest.NonceV + record.LatestNonce = *interest.Nonce() record.LatestTimestamp = time.Now() - record.LatestInterest = interest.NameV.Clone() + record.LatestInterest = interest.Name().Clone() record.ExpirationTime = time.Now().Add(lifetime) return record, true, previousNonce } @@ -241,7 +242,7 @@ func (bce *baseCsEntry) StaleTime() time.Time { return bce.staleTime } -func (bce *baseCsEntry) Copy() (*spec.Data, []byte, error) { +func (bce *baseCsEntry) Copy() (ndn.Data, []byte, error) { wire := make([]byte, len(bce.wire)) copy(wire, bce.wire) diff --git a/fw/table/pit-cs_test.go b/fw/table/pit-cs_test.go index ffb5c182..d87a9513 100644 --- a/fw/table/pit-cs_test.go +++ b/fw/table/pit-cs_test.go @@ -102,8 +102,8 @@ func TestInsertInRecord(t *testing.T) { inRecord, alreadyExists, _ := bpe.InsertInRecord(interest, faceID, pitToken) assert.False(t, alreadyExists) assert.Equal(t, inRecord.Face, faceID) - assert.Equal(t, inRecord.LatestNonce == *interest.NonceV, true) - assert.Equal(t, inRecord.LatestInterest, interest.NameV) + assert.Equal(t, inRecord.LatestNonce == *interest.Nonce(), true) + assert.Equal(t, inRecord.LatestInterest, interest.Name()) assert.Equal(t, bytes.Compare(inRecord.PitToken, pitToken), 0) assert.Equal(t, len(bpe.InRecords()), 1) @@ -117,8 +117,8 @@ func TestInsertInRecord(t *testing.T) { assert.True(t, alreadyExists) assert.Equal(t, prevNonce, uint32(1)) assert.Equal(t, inRecord.Face, faceID) - assert.Equal(t, inRecord.LatestNonce == *interest.NonceV, true) - assert.Equal(t, inRecord.LatestInterest, interest.NameV) + assert.Equal(t, inRecord.LatestNonce == *interest.Nonce(), true) + assert.Equal(t, inRecord.LatestInterest, interest.Name()) assert.Equal(t, bytes.Compare(inRecord.PitToken, pitToken), 0) assert.Equal(t, len(bpe.InRecords()), 1) // should update the original record in place record, ok = bpe.InRecords()[faceID] @@ -138,8 +138,8 @@ func TestInsertInRecord(t *testing.T) { inRecord, alreadyExists, _ = bpe.InsertInRecord(interest2, faceID2, pitToken2) assert.False(t, alreadyExists) assert.Equal(t, inRecord.Face, faceID2) - assert.Equal(t, inRecord.LatestNonce == *interest2.NonceV, true) - assert.Equal(t, inRecord.LatestInterest, interest2.NameV) + assert.Equal(t, inRecord.LatestNonce == *interest2.Nonce(), true) + assert.Equal(t, inRecord.LatestInterest, interest2.Name()) assert.Equal(t, bytes.Compare(inRecord.PitToken, pitToken2), 0) assert.Equal(t, len(bpe.InRecords()), 2) // should be a new inRecord record, ok = bpe.InRecords()[faceID2] @@ -164,6 +164,6 @@ func TestBaseCsEntryGetters(t *testing.T) { assert.Equal(t, bpe.StaleTime(), currTime) csData, csWire, _ := bpe.Copy() - assert.Equal(t, csData.NameV, name) + assert.Equal(t, csData.Name(), name) assert.Equal(t, csWire, VALID_DATA_1) } diff --git a/std/ndn/spec.go b/std/ndn/spec.go index b2f59991..c9b31c8c 100644 --- a/std/ndn/spec.go +++ b/std/ndn/spec.go @@ -33,7 +33,7 @@ type Interest interface { // Lifetime of the Interest Lifetime() *time.Duration // Max number of hops the Interest can traverse - HopLimit() *uint + HopLimit() *byte // Application parameters of the Interest (optional) AppParam() enc.Wire // Signature on the Interest (optional) diff --git a/std/ndn/spec_2022/spec.go b/std/ndn/spec_2022/spec.go index d39fe02a..b0a5d544 100644 --- a/std/ndn/spec_2022/spec.go +++ b/std/ndn/spec_2022/spec.go @@ -217,12 +217,8 @@ func (t *Interest) Lifetime() *time.Duration { return t.InterestLifetimeV } -func (t *Interest) HopLimit() *uint { - if t.HopLimitV == nil { - return nil - } else { - return utils.IdPtr(uint(*t.HopLimitV)) - } +func (t *Interest) HopLimit() *byte { + return t.HopLimitV } func (t *Interest) AppParam() enc.Wire {