Skip to content

Commit

Permalink
Project import generated by Copybara.
Browse files Browse the repository at this point in the history
FolderOrigin-RevId: /usr/local/google/home/gdennis/copybara/temp/folder-destination214996397719335914/.
  • Loading branch information
GGN Engprod Team authored and greg-dennis committed Jun 5, 2023
1 parent 15b391d commit d8fe3cc
Show file tree
Hide file tree
Showing 7 changed files with 46,708 additions and 46,547 deletions.
90,707 changes: 45,356 additions & 45,351 deletions gnmi/oc/schema.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions internal/ate/protocols.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ func (ix *ixATE) addISISProtocols(ifc *opb.InterfaceConfig) error {
level = "level1"
case opb.ISISConfig_L2:
level = "level2"
case opb.ISISConfig_L1L2:
level = "l1l2"
default:
return fmt.Errorf("unrecognized level %s", isis.GetLevel())
}
Expand Down
6 changes: 6 additions & 0 deletions ixnet/isis.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ func (i *ISIS) WithLevelL2() *ISIS {
return i
}

// WithLevelL1L2 sets the IS-IS level to L1/L2.
func (i *ISIS) WithLevelL1L2() *ISIS {
i.pb.Level = opb.ISISConfig_L1L2
return i
}

// WithNetworkTypeBroadcast sets the IS-IS network type to broadcast.
func (i *ISIS) WithNetworkTypeBroadcast() *ISIS {
i.pb.NetworkType = opb.ISISConfig_BROADCAST
Expand Down
37 changes: 24 additions & 13 deletions knebind/solver/solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ import (
opb "github.com/openconfig/ondatra/proto"
)

// KNEServiceMapKey is the key to look up the service map in the custom data of a ServiceDUT.
const KNEServiceMapKey = "$KEY_SERVICE_MAP"
const (
// KNEServiceMapKey is the key to look up the service map in the custom data of a ServiceDUT.
KNEServiceMapKey = "$KEY_SERVICE_MAP"

roleLabel = "ondatra-role"
roleDUT = "DUT"
roleATE = "ATE"
)

var (
ateVendors = map[tpb.Vendor]bool{
Expand All @@ -50,6 +56,16 @@ var (
}
)

func role(node *tpb.Node) string {
if role, ok := node.GetLabels()[roleLabel]; ok {
return role
}
if _, ok := ateVendors[node.GetVendor()]; ok {
return roleATE
}
return roleDUT
}

func filterTopology(topo *tpb.Topology) *tpb.Topology {
t := &tpb.Topology{Name: topo.GetName()}
for _, node := range topo.GetNodes() {
Expand Down Expand Up @@ -82,6 +98,7 @@ func filterTopology(topo *tpb.Topology) *tpb.Topology {
const (
// Attribute names mapping message fields to graph attributes/constraints.
vendorAttr = "vendor"
roleAttr = "role"
hwAttr = "hardware_model"
swAttr = "software_version"
speedAttr = "speed"
Expand All @@ -104,23 +121,14 @@ func testbedToAbstractGraph(tb *opb.Testbed, partial map[string]string) (*portgr
node2Dev := make(map[*portgraph.AbstractNode]*opb.Device)
port2Port := make(map[*portgraph.AbstractPort]*opb.Port)

var matchATE string
for v := range ateVendors {
if matchATE != "" {
matchATE += "|"
}
matchATE += deviceVendors[v].String()
}
reATE := regexp.MustCompile(matchATE)

// addDevice creates an AbstractNode from a Device.
// If the field is empty, there is not a Constraint on that field.
addDevice := func(dev *opb.Device, isATE bool) {
nodeConstraints := make(map[string]portgraph.NodeConstraint)
if isATE {
nodeConstraints[vendorAttr] = portgraph.Regex(reATE)
nodeConstraints[roleAttr] = portgraph.Equal(roleATE)
} else {
nodeConstraints[vendorAttr] = portgraph.NotRegex(reATE)
nodeConstraints[roleAttr] = portgraph.Equal(roleDUT)
}
if v := dev.GetVendor(); v != opb.Device_VENDOR_UNSPECIFIED {
nodeConstraints[vendorAttr] = portgraph.Equal(v.String())
Expand Down Expand Up @@ -324,6 +332,9 @@ func topoToConcreteGraph(topo *tpb.Topology) (*portgraph.ConcreteGraph, map[*por
if vendor, ok := deviceVendors[node.GetVendor()]; ok {
attrs[vendorAttr] = vendor.String()
}
if r := role(node); r != "" {
attrs[roleAttr] = r
}
if m := node.GetModel(); m != "" {
attrs[hwAttr] = m
}
Expand Down
164 changes: 148 additions & 16 deletions knebind/solver/solver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ func TestSolve(t *testing.T) {
value: {}
}
}
nodes: {
name: "node5"
vendor: OPENCONFIG
labels: {
key: "ondatra-role"
value: "ATE"
}
}
links: {
a_node: "node1"
a_int: "eth1"
Expand Down Expand Up @@ -135,10 +143,14 @@ func TestSolve(t *testing.T) {
SoftwareVersionValue: &opb.Device_SoftwareVersionRegex{"^evo$"},
Ports: []*opb.Port{{Id: "port1"}},
}
ate := &opb.Device{
Id: "ate",
ate1 := &opb.Device{
Id: "ate1",
Ports: []*opb.Port{{Id: "port1"}},
}
ate2 := &opb.Device{
Id: "ate2",
Vendor: opb.Device_OPENCONFIG,
}
link12 := &opb.Link{
A: "dut1:port1",
B: "dut2:port1",
Expand All @@ -149,7 +161,7 @@ func TestSolve(t *testing.T) {
}
link14 := &opb.Link{
A: "dut1:port2",
B: "ate:port1",
B: "ate1:port1",
}

wantDUTServices := map[string]*tpb.Service{
Expand Down Expand Up @@ -198,7 +210,7 @@ func TestSolve(t *testing.T) {
NodeVendor: tpb.Vendor_JUNIPER,
}
wantATEServices := make(map[string]*tpb.Service)
wantATE := &ServiceATE{
wantATE1 := &ServiceATE{
AbstractATE: &binding.AbstractATE{&binding.Dims{
Name: "node4",
Vendor: opb.Device_IXIA,
Expand All @@ -210,6 +222,16 @@ func TestSolve(t *testing.T) {
Services: wantATEServices,
NodeVendor: tpb.Vendor_KEYSIGHT,
}
wantATE2 := &ServiceATE{
AbstractATE: &binding.AbstractATE{&binding.Dims{
Name: "node5",
Vendor: opb.Device_OPENCONFIG,
Ports: map[string]*binding.Port{},
CustomData: map[string]any{KNEServiceMapKey: wantATEServices},
}},
Services: wantATEServices,
NodeVendor: tpb.Vendor_OPENCONFIG,
}

tests := []struct {
desc string
Expand Down Expand Up @@ -313,12 +335,24 @@ func TestSolve(t *testing.T) {
}, {
desc: "one ate",
tb: &opb.Testbed{
Ates: []*opb.Device{ate},
Ates: []*opb.Device{ate1},
},
wantRes: &binding.Reservation{
DUTs: map[string]binding.DUT{},
ATEs: map[string]binding.ATE{
"ate1": wantATE1,
},
},
}, {
desc: "two ates",
tb: &opb.Testbed{
Ates: []*opb.Device{ate1, ate2},
},
wantRes: &binding.Reservation{
DUTs: map[string]binding.DUT{},
ATEs: map[string]binding.ATE{
"ate": wantATE,
"ate1": wantATE1,
"ate2": wantATE2,
},
},
}, {
Expand All @@ -338,15 +372,15 @@ func TestSolve(t *testing.T) {
desc: "dut and ate",
tb: &opb.Testbed{
Duts: []*opb.Device{dut1},
Ates: []*opb.Device{ate},
Ates: []*opb.Device{ate1},
Links: []*opb.Link{link14},
},
wantRes: &binding.Reservation{
DUTs: map[string]binding.DUT{
"dut1": wantDUT1,
},
ATEs: map[string]binding.ATE{
"ate": wantATE,
"ate1": wantATE1,
},
},
}, {
Expand Down Expand Up @@ -697,31 +731,40 @@ func TestTopologyToConcreteGraph(t *testing.T) {
Os: "eos",
Interfaces: map[string]*tpb.Interface{"eth1": intf1},
}
ate := &tpb.Node{
Name: "ate",
ate1 := &tpb.Node{
Name: "ate1",
Vendor: tpb.Vendor_KEYSIGHT,
Interfaces: map[string]*tpb.Interface{"eth1": intf2},
}
ate2 := &tpb.Node{
Name: "ate2",
Vendor: tpb.Vendor_OPENCONFIG,
Labels: map[string]string{"ondatra-role": "ATE"},
}
topo := &tpb.Topology{
Nodes: []*tpb.Node{node, ate},
Nodes: []*tpb.Node{node, ate1, ate2},
}

wantNode := map[string]*tpb.Node{"node": node, "ate": ate}
wantIntf := map[string]*tpb.Interface{"node:eth1": intf1, "ate:eth1": intf2}
wantNode := map[string]*tpb.Node{"node": node, "ate1": ate1, "ate2": ate2}
wantIntf := map[string]*tpb.Interface{"node:eth1": intf1, "ate1:eth1": intf2}

graph, node2Node, _, err := topoToConcreteGraph(topo)
if err != nil {
t.Fatalf("topoToConcreteGraph() got error %v, want nil", err)
}
if len(graph.Nodes) != 2 {
t.Fatalf("topoToConcreteGraph() got %d nodes, want 2", len(graph.Nodes))
if len(graph.Nodes) != 3 {
t.Fatalf("topoToConcreteGraph() got %d nodes, want 3", len(graph.Nodes))
}
for _, node := range graph.Nodes {
if got, ok := node2Node[node]; !ok {
got, ok := node2Node[node]
if !ok {
t.Errorf("topoToConcreteGraph() got node %q not mapped to any device", node.Desc)
} else if diff := cmp.Diff(wantNode[node.Desc], got, protocmp.Transform()); diff != "" {
t.Errorf("topoToConcreteGraph() returned unexpected device diff (-want +got):\n%s", diff)
}
if gotRole, wantRole := node.Attrs["role"], role(got); gotRole != wantRole {
t.Errorf("node %q got role %q, want role %q", node.Desc, gotRole, wantRole)
}
for _, port := range node.Ports {
wantIntf, ok := wantIntf[port.Desc]
if !ok {
Expand All @@ -737,6 +780,61 @@ func TestTopologyToConcreteGraph(t *testing.T) {
}
}

func TestRole(t *testing.T) {
tests := []struct {
desc string
node *tpb.Node
want string
}{{
desc: "default DUT",
node: &tpb.Node{
Name: "node",
},
want: roleDUT,
}, {
desc: "vendor DUT",
node: &tpb.Node{
Name: "node",
Vendor: tpb.Vendor_ARISTA,
},
want: roleDUT,
}, {
desc: "vendor ATE",
node: &tpb.Node{
Name: "node",
Vendor: tpb.Vendor_KEYSIGHT,
},
want: roleATE,
}, {
desc: "label ATE",
node: &tpb.Node{
Name: "node",
Vendor: tpb.Vendor_ARISTA,
Labels: map[string]string{
roleLabel: roleATE,
},
},
want: roleATE,
}, {
desc: "label DUT",
node: &tpb.Node{
Name: "node",
Vendor: tpb.Vendor_KEYSIGHT,
Labels: map[string]string{
roleLabel: roleDUT,
},
},
want: roleDUT,
}}
for _, tc := range tests {
t.Run(tc.desc, func(t *testing.T) {
if got := role(tc.node); got != tc.want {
t.Errorf("role(%v) = %v, want %v", tc.node.GetName(), got, tc.want)
}
})
}
}

func TestSolveErrors(t *testing.T) {
tests := []struct {
desc string
Expand Down Expand Up @@ -819,6 +917,23 @@ func TestSolveErrors(t *testing.T) {
os: "bad"
}`,
wantErr: "Node \"dut1\" was not assigned",
}, {
desc: "no match for DUT - role label override",
tb: &opb.Testbed{
Duts: []*opb.Device{{
Id: "dut1",
}},
},
topo: `
nodes: {
name: "node1"
vendor: ARISTA
labels: {
key: "ondatra-role"
value: "ATE"
}
}`,
wantErr: "Node \"dut1\" was not assigned",
}, {
desc: "no match for ATE",
tb: &opb.Testbed{
Expand All @@ -832,6 +947,23 @@ func TestSolveErrors(t *testing.T) {
vendor: CISCO
}`,
wantErr: "Node \"ate1\" was not assigned",
}, {
desc: "no match for ATE - role label override",
tb: &opb.Testbed{
Ates: []*opb.Device{{
Id: "ate1",
}},
},
topo: `
nodes: {
name: "node1"
vendor: KEYSIGHT
labels: {
key: "ondatra-role"
value: "DUT"
}
}`,
wantErr: "Node \"ate1\" was not assigned",
}, {
desc: "no node combination",
tb: &opb.Testbed{
Expand Down
Loading

0 comments on commit d8fe3cc

Please sign in to comment.