-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaths.go
More file actions
107 lines (92 loc) · 2.59 KB
/
paths.go
File metadata and controls
107 lines (92 loc) · 2.59 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package parts
import (
"context"
"sort"
"strings"
"github.com/scionproto/scion/pkg/addr"
"github.com/scionproto/scion/pkg/snet"
)
var Serializers map[string]*SCIONPacketSerializer
func init() {
Serializers = make(map[string]*SCIONPacketSerializer)
}
type PartsPath struct {
Internal snet.Path
Interfaces []string
Id uint32
Sorter string
MTU int
PayloadSize int
}
func IdFromSnetPath(path snet.Path) string {
s := ""
for i, p := range path.Metadata().Interfaces {
s += p.String()
if i < len(path.Metadata().Interfaces)-1 {
s += "-"
}
}
return s
}
func QueryRawPaths(remote addr.IA) ([]snet.Path, error) {
hc := host()
return hc.queryPaths(context.Background(), remote)
}
func QueryPaths(remote addr.IA) ([]PartsPath, error) {
hc := host()
paths, err := hc.queryPaths(context.Background(), remote)
if err != nil {
return nil, err
}
PartsPaths := make([]PartsPath, 0)
for i, path := range paths {
// Print interfaces
// Log.Info("Interfaces:")
//for _, intf := range path.Metadata().Interfaces {
// Log.Info(intf)
//}
PartsPath := PartsPath{
Internal: path,
Interfaces: InterfacesToIds(path.Metadata().Interfaces),
Id: uint32(i), // IdFromSnetPath(path),
MTU: 1472,
PayloadSize: 1400,
}
PartsPath.Sorter = strings.Join(PartsPath.Interfaces, ",")
PartsPaths = append(PartsPaths, PartsPath)
}
SortPartsPaths(PartsPaths)
return PartsPaths, nil
}
func InterfacesToIds(intfs []snet.PathInterface) []string {
ids := make([]string, 0)
for _, intf := range intfs {
it := strings.ReplaceAll(intf.String(), "#", "-")
ids = append(ids, it)
}
return ids
}
// SortPartsPaths sorts a slice of PartsPath structs based on the length of the Sorter string,
// and then alphabetically by the Sorter string.
func SortPartsPaths(paths []PartsPath) {
sort.Slice(paths, func(i, j int) bool {
// First compare the length of the Sorter strings
if len(paths[i].Sorter) != len(paths[j].Sorter) {
return len(paths[i].Sorter) < len(paths[j].Sorter)
}
// If lengths are equal, sort alphabetically
return paths[i].Sorter < paths[j].Sorter
})
}
// SortPartsPaths sorts a slice of PartsPath structs based on the length of the Sorter string,
// and then alphabetically by the Sorter string.
func SortPartsPathsP(paths []*PartsPath) {
sort.Slice(paths, func(i, j int) bool {
// First compare the length of the Sorter strings
if len(paths[i].Sorter) != len(paths[j].Sorter) {
return len(paths[i].Sorter) < len(paths[j].Sorter)
}
// If lengths are equal, sort alphabetically
return paths[i].Sorter < paths[j].Sorter
})
}