Skip to content

Commit

Permalink
mgmt: Fix wrong encoding
Browse files Browse the repository at this point in the history
Add wrapper TLV block
Fix: #52
  • Loading branch information
zjkmxy committed Jul 8, 2023
1 parent 5bf27da commit b37bd7b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
.idea
publish/**
resource.syso
temp/
18 changes: 9 additions & 9 deletions mgmt/face.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,13 +560,13 @@ func (f *FaceModule) list(interest *spec.Interest, pitToken []byte, inFace uint6
}
// We have to sort these or they appear in a strange order
sort.Slice(faceIDs, func(a int, b int) bool { return faceIDs[a] < faceIDs[b] })
dataset := enc.Wire{}
for _, faceID := range faceIDs {
dataset = append(dataset, f.createDataset(faces[faceID])...)
dataset := &mgmt.FaceStatusMsg{}
for _, pos := range faceIDs {
dataset.Vals = append(dataset.Vals, f.createDataset(faces[pos]))
}

name, _ := enc.NameFromStr(f.manager.localPrefix.String() + "/faces/list")
segments := makeStatusDataset(name, f.nextFaceDatasetVersion, dataset)
segments := makeStatusDataset(name, f.nextFaceDatasetVersion, dataset.Encode())
f.manager.transport.Send(segments, pitToken, nil)

core.LogTrace(f, "Published face dataset version=", f.nextFaceDatasetVersion,
Expand Down Expand Up @@ -625,20 +625,20 @@ func (f *FaceModule) query(interest *spec.Interest, pitToken []byte, inFace uint
// We have to sort these or they appear in a strange order
//sort.Slice(matchingFaces, func(a int, b int) bool { return matchingFaces[a] < matchingFaces[b] })

dataset := enc.Wire{}
dataset := &mgmt.FaceStatusMsg{}
for _, pos := range matchingFaces {
dataset = append(dataset, f.createDataset(faces[pos])...)
dataset.Vals = append(dataset.Vals, f.createDataset(faces[pos]))
}

segments := makeStatusDataset(interest.Name(), f.nextFaceDatasetVersion, dataset)
segments := makeStatusDataset(interest.Name(), f.nextFaceDatasetVersion, dataset.Encode())
f.manager.transport.Send(segments, pitToken, nil)

core.LogTrace(f, "Published face query dataset version=", f.nextFaceDatasetVersion,
", containing ", len(segments), " segments")
f.nextFaceDatasetVersion++
}

func (f *FaceModule) createDataset(selectedFace face.LinkService) enc.Wire {
func (f *FaceModule) createDataset(selectedFace face.LinkService) *mgmt.FaceStatus {
faceDataset := &mgmt.FaceStatus{
FaceId: selectedFace.FaceID(),
Uri: selectedFace.RemoteURI().String(),
Expand Down Expand Up @@ -678,7 +678,7 @@ func (f *FaceModule) createDataset(selectedFace face.LinkService) enc.Wire {
}
}

return faceDataset.Encode()
return faceDataset
}

// func (f *FaceModule) channels(interest *spec.Interest, pitToken []byte, inFace uint64) {
Expand Down
7 changes: 3 additions & 4 deletions mgmt/fib.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (f *FIBModule) list(interest *spec.Interest, pitToken []byte, inFace uint64
// Generate new dataset
// TODO: For thread safety, we should lock the FIB from writes until we are done
entries := table.FibStrategyTable.GetAllFIBEntries()
dataset := enc.Wire{}
dataset := &mgmt.FibStatus{}
for _, fsEntry := range entries {
nextHops := fsEntry.GetNextHops()
fibEntry := &mgmt.FibEntry{
Expand All @@ -172,12 +172,11 @@ func (f *FIBModule) list(interest *spec.Interest, pitToken []byte, inFace uint64
}
}

wire := fibEntry.Encode()
dataset = append(dataset, wire...)
dataset.Entries = append(dataset.Entries, fibEntry)
}

name, _ := enc.NameFromStr(f.manager.localPrefix.String() + "/fib/list")
segments := makeStatusDataset(name, f.nextFIBDatasetVersion, dataset)
segments := makeStatusDataset(name, f.nextFIBDatasetVersion, dataset.Encode())
f.manager.transport.Send(segments, pitToken, nil)

core.LogTrace(f, "Published FIB dataset version=", f.nextFIBDatasetVersion,
Expand Down
7 changes: 3 additions & 4 deletions mgmt/rib.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (r *RIBModule) list(interest *spec.Interest, pitToken []byte, inFace uint64

// Generate new dataset
entries := table.Rib.GetAllEntries()
dataset := enc.Wire{}
dataset := &mgmt.RibStatus{}
for _, entry := range entries {
ribEntry := &mgmt.RibEntry{
Name: entry.Name,
Expand All @@ -248,12 +248,11 @@ func (r *RIBModule) list(interest *spec.Interest, pitToken []byte, inFace uint64
}
}

wire := ribEntry.Encode()
dataset = append(dataset, wire...)
dataset.Entries = append(dataset.Entries, ribEntry)
}

name, _ := enc.NameFromStr(interest.NameV[:r.manager.prefixLength()].String() + "/rib/list")
segments := makeStatusDataset(name, r.nextRIBDatasetVersion, dataset)
segments := makeStatusDataset(name, r.nextRIBDatasetVersion, dataset.Encode())
r.manager.transport.Send(segments, pitToken, nil)
core.LogTrace(r, "Published RIB dataset version=", r.nextRIBDatasetVersion,
", containing ", len(segments), " segments")
Expand Down

0 comments on commit b37bd7b

Please sign in to comment.