-
Notifications
You must be signed in to change notification settings - Fork 0
/
record.go
76 lines (64 loc) · 2.43 KB
/
record.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
71
72
73
74
75
76
package ndntdump
import (
"io"
"github.com/gopacket/gopacket"
"github.com/usnistgov/ndn-dpdk/ndn"
)
// Direction indicates traffic direction.
type Direction string
// Direction values.
const (
DirectionRX Direction = ">"
DirectionTX Direction = "<"
)
// PktType indicates NDN packet type.
type PktType string
// PktType values.
const (
PktTypeFragment PktType = "F"
PktTypeInterest PktType = "I"
PktTypeData PktType = "D"
PktTypeNack PktType = "N"
)
// Record describes a parsed NDN packet.
type Record struct {
Wire []byte `json:"-"`
CaptureInfo gopacket.CaptureInfo `json:"-"`
DirType string `json:"t"` // packet direction and type
Timestamp int64 `json:"ts"` // Unix epoch nanoseconds
Flow []byte `json:"flow"` // flow key
Size2 int `json:"size2"` // packet size at NDNLPv2 layer
Size3 int `json:"size3,omitempty"` // packet size at L3
NackReason int `json:"nackReason,omitempty"` // Nack reason
Name ndn.Name `json:"name,omitempty"` // packet name
CanBePrefix bool `json:"cbp,omitempty"` // Interest CanBePrefix
MustBeFresh bool `json:"mbf,omitempty"` // Interest MustBeFresh
FwHint []ndn.Name `json:"fwHint,omitempty"` // Interest ForwardingHint
Lifetime int `json:"lifetime,omitempty"` // Interest InterestLifetime (ms)
HopLimit int `json:"hopLimit,omitempty"` // Interest HopLimit
ContentType int `json:"contentType,omitempty"` // Data ContentType
Freshness int `json:"freshness,omitempty"` // Data FreshnessPeriod (ms)
FinalBlock bool `json:"finalBlock,omitempty"` // Data is final block
}
// SaveInterest saves Interest/Nack fields on this Record.
func (rec *Record) SaveInterest(interest ndn.Interest, nackReason uint8) {
rec.Name = interest.Name
rec.CanBePrefix = interest.CanBePrefix
rec.MustBeFresh = interest.MustBeFresh
rec.FwHint = interest.ForwardingHint
rec.Lifetime = int(interest.Lifetime.Milliseconds())
rec.HopLimit = int(interest.HopLimit)
rec.NackReason = int(nackReason)
}
// SaveData saves Data fields on this Record.
func (rec *Record) SaveData(data ndn.Data) {
rec.Name = data.Name
rec.ContentType = int(data.ContentType)
rec.Freshness = int(data.Freshness.Milliseconds())
rec.FinalBlock = data.IsFinalBlock()
}
// RecordOutput represents an output stream.
type RecordOutput interface {
io.Closer
Write(rec Record) error
}