forked from usnistgov/ndn-dpdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentry.go
70 lines (58 loc) · 1.78 KB
/
entry.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package cs
/*
#include "../../csrc/pcct/cs-entry.h"
static void* c_CsEntry_Data(CsEntry* entry) { return entry->data; }
*/
import "C"
import (
"unsafe"
"github.com/usnistgov/ndn-dpdk/dpdk/eal"
"github.com/usnistgov/ndn-dpdk/ndni"
"go.uber.org/zap"
)
// Entry represents a CS entry.
type Entry C.CsEntry
// EntryFromPtr converts *C.CsEntry to Entry.
func EntryFromPtr(ptr unsafe.Pointer) *Entry {
return (*Entry)(ptr)
}
func (entry *Entry) ptr() *C.CsEntry {
return (*C.CsEntry)(entry)
}
// Kind returns entry kind.
func (entry *Entry) Kind() EntryKind {
return EntryKind(entry.kind)
}
// ListIndirects returns a list of indirect entries associated with this direct entry.
// Panics if this is not a direct entry.
func (entry *Entry) ListIndirects() (indirects []*Entry) {
if entry.Kind() == EntryIndirect {
logger.Panic("Entry.ListIndirects is unavailable on indirect entry",
zap.Uintptr("entry", uintptr(unsafe.Pointer(entry))),
)
}
c := entry.ptr()
indirects = make([]*Entry, c.nIndirects)
for i := range indirects {
indirects[i] = (*Entry)(c.indirect[i])
}
return indirects
}
// Data returns the Data packet on this entry.
func (entry *Entry) Data() *ndni.Packet {
if kind := entry.Kind(); kind != EntryMemory {
logger.Panic("Entry.Data is only available on in-memory entry",
zap.Uintptr("entry", uintptr(unsafe.Pointer(entry))),
zap.Int("kind", int(kind)),
)
}
return ndni.PacketFromPtr(C.c_CsEntry_Data((*C.CsEntry)(entry)))
}
// FreshUntil returns a timestamp when this entry would become non-fresh.
func (entry *Entry) FreshUntil() eal.TscTime {
return eal.TscTime(C.CsEntry_GetDirect(entry.ptr()).freshUntil)
}
// IsFresh determines whether entry is fresh at the given time.
func (entry *Entry) IsFresh(now eal.TscTime) bool {
return entry.FreshUntil() > now
}