-
Notifications
You must be signed in to change notification settings - Fork 132
/
options.go
104 lines (92 loc) · 2.95 KB
/
options.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
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
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package binding
import (
"flag"
"fmt"
bindpb "github.com/openconfig/featureprofiles/topologies/proto/binding"
"github.com/openconfig/ondatra/binding/introspect"
"google.golang.org/protobuf/proto"
)
// IANA assigns 9339 for gNxI, 9559 for P4RT and 9340 for gRIBI.
var (
gnmiPort = flag.Int("gnmi_port", 9339, "default gNMI port")
gnoiPort = flag.Int("gnoi_port", 9339, "default gNOI port")
gnsiPort = flag.Int("gnsi_port", 9339, "default gNSI port")
gribiPort = flag.Int("gribi_port", 9340, "default gRIBI port")
p4rtPort = flag.Int("p4rt_port", 9559, "default P4RT part")
ateGNMIPort = flag.Int("ate_gnmi_port", 50051, "default ATE gNMI port")
ateOTGPort = flag.Int("ate_grpc_port", 40051, "default ATE OTG port")
dutSvcParams = map[introspect.Service]*svcParams{
introspect.GNMI: {
port: *gnmiPort,
optsFn: (*bindpb.Device).GetGnmi,
},
introspect.GNOI: {
port: *gnoiPort,
optsFn: (*bindpb.Device).GetGnoi,
},
introspect.GNSI: {
port: *gnsiPort,
optsFn: (*bindpb.Device).GetGnsi,
},
introspect.GRIBI: {
port: *gribiPort,
optsFn: (*bindpb.Device).GetGribi,
},
introspect.P4RT: {
port: *p4rtPort,
optsFn: (*bindpb.Device).GetP4Rt,
},
}
ateSvcParams = map[introspect.Service]*svcParams{
introspect.GNMI: {
port: *ateGNMIPort,
optsFn: (*bindpb.Device).GetGnmi,
},
introspect.OTG: {
port: *ateOTGPort,
optsFn: (*bindpb.Device).GetOtg,
},
}
)
type svcParams struct {
port int
optsFn func(*bindpb.Device) *bindpb.Options
}
// merge creates combines one or more options into one set of options.
func merge(bopts ...*bindpb.Options) *bindpb.Options {
result := &bindpb.Options{}
for _, bopt := range bopts {
if bopt != nil {
proto.Merge(result, bopt)
}
}
return result
}
type resolver struct {
*bindpb.Binding
}
func (r *resolver) grpc(dev *bindpb.Device, params *svcParams) *bindpb.Options {
targetOpts := &bindpb.Options{Target: fmt.Sprintf("%s:%d", dev.Name, params.port)}
return merge(targetOpts, r.Options, dev.Options, params.optsFn(dev))
}
func (r *resolver) ssh(dev *bindpb.Device) *bindpb.Options {
targetOpts := &bindpb.Options{Target: dev.Name}
return merge(targetOpts, r.Options, dev.Options, dev.Ssh)
}
func (r *resolver) ixnetwork(dev *bindpb.Device) *bindpb.Options {
targetOpts := &bindpb.Options{Target: dev.Name}
return merge(targetOpts, r.Options, dev.Options, dev.Ixnetwork)
}