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-destination16677812753233736523/.
  • Loading branch information
GGN Engprod Team authored and greg-dennis committed Aug 8, 2022
1 parent 9c82dc1 commit 5528f19
Show file tree
Hide file tree
Showing 7 changed files with 81,829 additions and 81,627 deletions.
2 changes: 2 additions & 0 deletions device.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ const (
PMD100GFR = PMD(opb.Port_PMD_100G_FR)
// PMD100GLR4 is a PMD of 100G-LR4.
PMD100GLR4 = PMD(opb.Port_PMD_100G_LR4)
// PMD400GFR4 is a PMD of 400G-FR4.
PMD400GFR4 = PMD(opb.Port_PMD_400G_FR4)
)

func (pmd PMD) String() string {
Expand Down
81,621 changes: 40,815 additions & 40,806 deletions gnmi/oc/schema.go

Large diffs are not rendered by default.

76 changes: 76 additions & 0 deletions otg/otg.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,82 @@ func setTransmitState(ctx context.Context, ate binding.ATE, state gosnappi.Trans
return resp.Warnings(), nil
}

// AdvertiseRoutes advertises routes on the ATE.
func (o *OTG) AdvertiseRoutes(t testing.TB, routes []string) {
t.Helper()
debugger.ActionStarted(t, "Advertising routes on %v", o.ate)
warns, err := setRouteState(context.Background(), o.ate, routes, gosnappi.RouteStateState.ADVERTISE)
if err != nil {
t.Fatalf("AdvertiseRoutes(t) on %s: %v", o.ate, err)
}
if len(warns) > 0 {
t.Logf("AdvertiseRoutes(t) on %s non-fatal warnings: %v", o.ate, warns)
}
}

// WithdrawRoutes withdraws routes on the ATE.
func (o *OTG) WithdrawRoutes(t testing.TB, routes []string) {
t.Helper()
debugger.ActionStarted(t, "Withdrawing routes for %v", o.ate)
warns, err := setRouteState(context.Background(), o.ate, routes, gosnappi.RouteStateState.WITHDRAW)
if err != nil {
t.Fatalf("WithdrawRoutes(t) on %s: %v", o.ate, err)
}
if len(warns) > 0 {
t.Logf("WithdrawRoutes(t) on %s non-fatal warnings: %v", o.ate, warns)
}
}

func setRouteState(ctx context.Context, ate binding.ATE, routes []string, state gosnappi.RouteStateStateEnum) ([]string, error) {
api, err := fetchAPI(ctx, ate)
if err != nil {
return nil, err
}
resp, err := api.SetRouteState(api.NewRouteState().SetState(state).SetNames(routes))
if err != nil {
return nil, err
}
return resp.Warnings(), nil
}

// EnableLACPMembers enables lacp member ports on the ATE.
func (o *OTG) EnableLACPMembers(t testing.TB, ports []string) {
t.Helper()
debugger.ActionStarted(t, "EnableLACPMembers on %v", o.ate)
warns, err := setLACPMemberState(context.Background(), o.ate, ports, gosnappi.LacpMemberStateState.UP)
if err != nil {
t.Fatalf("EnableLACPMembers(t) on %s: %v", o.ate, err)
}
if len(warns) > 0 {
t.Logf("EnableLACPMembers(t) on %s non-fatal warnings: %v", o.ate, warns)
}
}

// DisableLACPMembers disables lacp member ports on the ATE.
func (o *OTG) DisableLACPMembers(t testing.TB, ports []string) {
t.Helper()
debugger.ActionStarted(t, "DisableLACPMembers on %v", o.ate)
warns, err := setLACPMemberState(context.Background(), o.ate, ports, gosnappi.LacpMemberStateState.DOWN)
if err != nil {
t.Fatalf("DisableLACPMembers(t) on %s: %v", o.ate, err)
}
if len(warns) > 0 {
t.Logf("DisableLACPMembers(t) on %s non-fatal warnings: %v", o.ate, warns)
}
}

func setLACPMemberState(ctx context.Context, ate binding.ATE, lagMemberPorts []string, state gosnappi.LacpMemberStateStateEnum) ([]string, error) {
api, err := fetchAPI(ctx, ate)
if err != nil {
return nil, err
}
resp, err := api.SetDeviceState(api.NewDeviceState().SetLacpMemberState(gosnappi.NewLacpMemberState().SetLagMemberPortNames(lagMemberPorts).SetState(state)))
if err != nil {
return nil, err
}
return resp.Warnings(), nil
}

func fetchAPI(ctx context.Context, ate binding.ATE) (gosnappi.GosnappiApi, error) {
mu.Lock()
defer mu.Unlock()
Expand Down
125 changes: 110 additions & 15 deletions otg/otg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"strings"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/open-traffic-generator/snappi/gosnappi"
"github.com/openconfig/ondatra/binding"
"github.com/openconfig/ondatra/fakebind"
Expand All @@ -29,9 +30,7 @@ var (
fakeSnappi = new(fakeGosnappi)
fakeATE = &fakebind.ATE{
AbstractATE: &binding.AbstractATE{&binding.Dims{
Ports: map[string]*binding.Port{
"port1": &binding.Port{},
},
Ports: map[string]*binding.Port{"port1": {}},
}},
DialOTGFn: func(context.Context) (gosnappi.GosnappiApi, error) {
return fakeSnappi, nil
Expand Down Expand Up @@ -79,42 +78,94 @@ func TestPushConfigBadPortName(t *testing.T) {
}

func TestStartProtocols(t *testing.T) {
fakeSnappi.protocol = gosnappi.ProtocolStateState.STOP
fakeSnappi.protocol = nil
otgAPI.StartProtocols(t)
if got, want := fakeSnappi.protocol, gosnappi.ProtocolStateState.START; got != want {
if got, want := fakeSnappi.protocol.state, gosnappi.ProtocolStateState.START; got != want {
t.Errorf("StartProtocols got unexpected protocol state %v, want %v", got, want)
}
}

func TestStopProtocols(t *testing.T) {
fakeSnappi.protocol = gosnappi.ProtocolStateState.START
fakeSnappi.protocol = nil
otgAPI.StopProtocols(t)
if got, want := fakeSnappi.protocol, gosnappi.ProtocolStateState.STOP; got != want {
if got, want := fakeSnappi.protocol.state, gosnappi.ProtocolStateState.STOP; got != want {
t.Errorf("StopProtocols got unexpected protocol state %v, want %v", got, want)
}
}

func TestStartTraffic(t *testing.T) {
fakeSnappi.transmit = gosnappi.TransmitStateState.STOP
fakeSnappi.transmit = nil
otgAPI.StartTraffic(t)
if got, want := fakeSnappi.transmit, gosnappi.TransmitStateState.START; got != want {
if got, want := fakeSnappi.transmit.state, gosnappi.TransmitStateState.START; got != want {
t.Errorf("StartTraffic got unexpected transmit state %v, want %v", got, want)
}
}

func TestStopTraffic(t *testing.T) {
fakeSnappi.transmit = gosnappi.TransmitStateState.START
fakeSnappi.transmit = nil
otgAPI.StopTraffic(t)
if got, want := fakeSnappi.transmit, gosnappi.TransmitStateState.STOP; got != want {
if got, want := fakeSnappi.transmit.state, gosnappi.TransmitStateState.STOP; got != want {
t.Errorf("StopTraffic got unexpected transmit state %v, want %v", got, want)
}
}

func TestAdvertiseRoutes(t *testing.T) {
fakeSnappi.route = nil
wantNames := []string{"peer1", "peer2"}
otgAPI.AdvertiseRoutes(t, wantNames)
got := fakeSnappi.route
if wantState := gosnappi.RouteStateState.ADVERTISE; got.state != wantState {
t.Errorf("AdvertiseRoutes got unexpected route state %v, want %v", got.state, wantState)
}
if !cmp.Equal(got.names, wantNames) {
t.Errorf("AdvertiseRoutes got unexpected route names %v, want %v", got.names, wantNames)
}
}

func TestWithdrawRoutes(t *testing.T) {
fakeSnappi.route = nil
wantNames := []string{"peer1", "peer2"}
otgAPI.WithdrawRoutes(t, wantNames)
got := fakeSnappi.route
if wantState := gosnappi.RouteStateState.WITHDRAW; got.state != wantState {
t.Errorf("WithdrawRoutes got unexpected route state %v, want %v", got.state, wantState)
}
if !cmp.Equal(got.names, wantNames) {
t.Errorf("WithdrawRoutes got unexpected route names %v, want %v", got.names, wantNames)
}
}

func TestEnableLACPMembers(t *testing.T) {
wantPorts := []string{"port1", "port2"}
otgAPI.EnableLACPMembers(t, wantPorts)
gotLACP := fakeSnappi.device.lacp
if wantState := gosnappi.LacpMemberStateState.UP; gotLACP.State() != wantState {
t.Errorf("EnableLACPMembers got unexpected LACP member state %v, want %v", gotLACP.State(), wantState)
}
if !cmp.Equal(gotLACP.LagMemberPortNames(), wantPorts) {
t.Errorf("EnableLACPMembers got unexpected LACP member ports %v, want %v", gotLACP.LagMemberPortNames(), wantPorts)
}
}

func TestDisableLACPMembers(t *testing.T) {
wantPorts := []string{"port1", "port2"}
otgAPI.DisableLACPMembers(t, wantPorts)
gotLACP := fakeSnappi.device.lacp
if wantState := gosnappi.LacpMemberStateState.DOWN; gotLACP.State() != wantState {
t.Errorf("DisableLACPMembers got unexpected LACP member state %v, want %v", gotLACP.State(), wantState)
}
if !cmp.Equal(gotLACP.LagMemberPortNames(), wantPorts) {
t.Errorf("DisableLACPMembers got unexpected LACP member ports %v, want %v", gotLACP.LagMemberPortNames(), wantPorts)
}
}

type fakeGosnappi struct {
gosnappi.GosnappiApi
cfg gosnappi.Config
protocol gosnappi.ProtocolStateStateEnum
transmit gosnappi.TransmitStateStateEnum
protocol *fakeProtocolState
transmit *fakeTransmitState
route *fakeRouteState
device *fakeDeviceState
}

func (fg *fakeGosnappi) NewConfig() gosnappi.Config {
Expand All @@ -135,7 +186,7 @@ func (fg *fakeGosnappi) NewProtocolState() gosnappi.ProtocolState {
}

func (fg *fakeGosnappi) SetProtocolState(state gosnappi.ProtocolState) (gosnappi.ResponseWarning, error) {
fg.protocol = state.(*fakeProtocolState).state
fg.protocol = state.(*fakeProtocolState)
return gosnappi.NewResponseWarning(), nil
}

Expand All @@ -144,7 +195,25 @@ func (fg *fakeGosnappi) NewTransmitState() gosnappi.TransmitState {
}

func (fg *fakeGosnappi) SetTransmitState(state gosnappi.TransmitState) (gosnappi.ResponseWarning, error) {
fg.transmit = state.(*fakeTransmitState).state
fg.transmit = state.(*fakeTransmitState)
return gosnappi.NewResponseWarning(), nil
}

func (fg *fakeGosnappi) NewRouteState() gosnappi.RouteState {
return new(fakeRouteState)
}

func (fg *fakeGosnappi) SetRouteState(state gosnappi.RouteState) (gosnappi.ResponseWarning, error) {
fg.route = state.(*fakeRouteState)
return gosnappi.NewResponseWarning(), nil
}

func (fg *fakeGosnappi) NewDeviceState() gosnappi.DeviceState {
return new(fakeDeviceState)
}

func (fg *fakeGosnappi) SetDeviceState(state gosnappi.DeviceState) (gosnappi.ResponseWarning, error) {
fg.device = state.(*fakeDeviceState)
return gosnappi.NewResponseWarning(), nil
}

Expand All @@ -167,3 +236,29 @@ func (ft *fakeTransmitState) SetState(state gosnappi.TransmitStateStateEnum) gos
ft.state = state
return ft
}

type fakeRouteState struct {
gosnappi.RouteState
state gosnappi.RouteStateStateEnum
names []string
}

func (fp *fakeRouteState) SetState(state gosnappi.RouteStateStateEnum) gosnappi.RouteState {
fp.state = state
return fp
}

func (fp *fakeRouteState) SetNames(names []string) gosnappi.RouteState {
fp.names = names
return fp
}

type fakeDeviceState struct {
gosnappi.DeviceState
lacp gosnappi.LacpMemberState
}

func (fd *fakeDeviceState) SetLacpMemberState(lacp gosnappi.LacpMemberState) gosnappi.DeviceState {
fd.lacp = lacp
return fd
}
22 changes: 13 additions & 9 deletions proto/testbed.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions proto/testbed.proto
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ message Port {
PMD_UNSPECIFIED = 0;
PMD_100G_FR = 1;
PMD_100G_LR4 = 2;
PMD_400G_FR4 = 3;
}
oneof pmd_value {
Pmd pmd = 4;
Expand Down
Loading

0 comments on commit 5528f19

Please sign in to comment.