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-destination2132942022286347102/.
  • Loading branch information
GGN Engprod Team authored and greg-dennis committed Nov 4, 2022
1 parent aab0ac6 commit 66d3c2d
Show file tree
Hide file tree
Showing 6 changed files with 81,835 additions and 81,617 deletions.
82,439 changes: 41,219 additions & 41,220 deletions gnmi/oc/schema.go

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions internal/ixgnmi/bgprib.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"golang.org/x/net/context"
"fmt"
"path"
"strconv"
"strings"

log "github.com/golang/glog"
Expand Down Expand Up @@ -197,6 +198,26 @@ func appendDetails(info bgpLearnedInfo, rib *telemetry.NetworkInstance_Protocol_
default:
return fmt.Errorf("unknown origin type: %q", info.Origin)
}

if len(info.ASPath) > 0 {
lastIdx := len(info.ASPath) - 1
if info.ASPath[0] != '<' || info.ASPath[lastIdx] != '>' {
return fmt.Errorf("invalid AS path string: %q", info.ASPath)
}
var members []uint32
for _, s := range strings.Split(info.ASPath[1:lastIdx], " ") {
member, err := strconv.ParseUint(s, 10, 32)
if err != nil {
return fmt.Errorf("invalid AS segment member: %q", s)
}
members = append(members, uint32(member))
}
as.AsSegment = []*telemetry.NetworkInstance_Protocol_Bgp_Rib_AttrSet_AsSegment{{
Member: members,
Type: telemetry.BgpTypes_AsPathSegmentType_AS_SEQ,
}}
}

if err := rib.AppendAttrSet(as); err != nil {
return err
}
Expand Down
42 changes: 36 additions & 6 deletions internal/ixgnmi/bgprib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,24 @@ func TestBGPRIBFromIxia(t *testing.T) {
}`,
},
wantErr: "duplicate key",
}, {
desc: "invalid AS path",
getRsps: map[string]string{
bgp4ID + "/learnedInfo/1/table/1": `{
"columns": ["Origin", "AS Path"],
"values": [["EGP", "foo"]]
}`,
},
wantErr: "invalid AS path",
}, {
desc: "invalid AS segment",
getRsps: map[string]string{
bgp4ID + "/learnedInfo/1/table/1": `{
"columns": ["Origin", "AS Path"],
"values": [["EGP", "<foo bar>"]]
}`,
},
wantErr: "invalid AS segment",
}, {
desc: "no data",
want: &telemetry.NetworkInstance{
Expand Down Expand Up @@ -142,18 +160,18 @@ func TestBGPRIBFromIxia(t *testing.T) {
getRsps: map[string]string{
bgp4ID + "/learnedInfo/1/table/1": `{
"id": 1,
"columns": ["IPv4 Prefix ", "Prefix Length", "Path ID", "IPv4 Next Hop", "Origin", "AIGP", "Local Preference", "MED", "Community"],
"columns": ["IPv4 Prefix ", "Prefix Length", "Path ID", "IPv4 Next Hop", "Origin", "AIGP", "Local Preference", "MED", "Community", "AS Path"],
"values": [
["127.0.0.1", "30", "1", "127.0.0.2", "IGP", "200", "1000", "100", "65532 : 10200, 65533 : 10100"],
["127.0.0.3", "24", "2", "127.0.0.4", "EGP", "", "", "", ""]
["127.0.0.1", "30", "1", "127.0.0.2", "IGP", "200", "1000", "100", "65532 : 10200, 65533 : 10100", "<65532 65533>"],
["127.0.0.3", "24", "2", "127.0.0.4", "EGP", "", "", "", "", ""]
]
}`,
bgp6ID + "/learnedInfo/1/table/1": `{
"id": 2,
"columns": ["IPv6 Prefix", "Prefix Length", "Path ID", "IPv6 Next Hop", "Origin", "AIGP", "Local Preference", "MED", "Community"],
"columns": ["IPv6 Prefix", "Prefix Length", "Path ID", "IPv6 Next Hop", "Origin", "AIGP", "Local Preference", "MED", "Community", "AS Path"],
"values": [
["::1", "28", "3", "::2", "Incomplete", "200", "1000", "100", ""],
["::3", "26", "4", "::4", "IGP", "", "", "", ""]
["::1", "28", "3", "::2", "Incomplete", "200", "1000", "100", "65534 : 10400, 65535 : 10300", "<65534 65535>"],
["::3", "26", "4", "::4", "IGP", "", "", "", "", ""]
]
}`,
},
Expand Down Expand Up @@ -229,6 +247,10 @@ func TestBGPRIBFromIxia(t *testing.T) {
Med: ygot.Uint32(100),
NextHop: ygot.String("127.0.0.2"),
Origin: telemetry.BgpTypes_BgpOriginAttrType_IGP,
AsSegment: []*telemetry.NetworkInstance_Protocol_Bgp_Rib_AttrSet_AsSegment{{
Member: []uint32{65532, 65533},
Type: telemetry.BgpTypes_AsPathSegmentType_AS_SEQ,
}},
},
1: &telemetry.NetworkInstance_Protocol_Bgp_Rib_AttrSet{
Aigp: ygot.Uint64(0),
Expand All @@ -245,6 +267,10 @@ func TestBGPRIBFromIxia(t *testing.T) {
Med: ygot.Uint32(100),
NextHop: ygot.String("::2"),
Origin: telemetry.BgpTypes_BgpOriginAttrType_INCOMPLETE,
AsSegment: []*telemetry.NetworkInstance_Protocol_Bgp_Rib_AttrSet_AsSegment{{
Member: []uint32{65534, 65535},
Type: telemetry.BgpTypes_AsPathSegmentType_AS_SEQ,
}},
},
3: &telemetry.NetworkInstance_Protocol_Bgp_Rib_AttrSet{
Aigp: ygot.Uint64(0),
Expand All @@ -268,6 +294,10 @@ func TestBGPRIBFromIxia(t *testing.T) {
},
2: &telemetry.NetworkInstance_Protocol_Bgp_Rib_Community{
Index: ygot.Uint64(2),
Community: []telemetry.NetworkInstance_Protocol_Bgp_Rib_Community_Community_Union{
telemetry.UnionString("65534 : 10400"),
telemetry.UnionString("65535 : 10300"),
},
},
3: &telemetry.NetworkInstance_Protocol_Bgp_Rib_Community{
Index: ygot.Uint64(3),
Expand Down
67 changes: 62 additions & 5 deletions otg/otg.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ func setRouteState(ctx context.Context, ate binding.ATE, routes []string, state
}

// EnableLACPMembers enables lacp member ports on the ATE.
func (o *OTG) EnableLACPMembers(t testing.TB, ports []string) {
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)
warns, err := setLACPMemberState(context.Background(), o.ate, gosnappi.LacpMemberStateState.UP, ports)
if err != nil {
t.Fatalf("EnableLACPMembers(t) on %s: %v", o.ate, err)
}
Expand All @@ -249,10 +249,10 @@ func (o *OTG) EnableLACPMembers(t testing.TB, ports []string) {
}

// DisableLACPMembers disables lacp member ports on the ATE.
func (o *OTG) DisableLACPMembers(t testing.TB, ports []string) {
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)
warns, err := setLACPMemberState(context.Background(), o.ate, gosnappi.LacpMemberStateState.DOWN, ports)
if err != nil {
t.Fatalf("DisableLACPMembers(t) on %s: %v", o.ate, err)
}
Expand All @@ -261,7 +261,7 @@ func (o *OTG) DisableLACPMembers(t testing.TB, ports []string) {
}
}

func setLACPMemberState(ctx context.Context, ate binding.ATE, lagMemberPorts []string, state gosnappi.LacpMemberStateStateEnum) ([]string, error) {
func setLACPMemberState(ctx context.Context, ate binding.ATE, state gosnappi.LacpMemberStateStateEnum, lagMemberPorts []string) ([]string, error) {
api, err := rawapis.FetchOTG(ctx, ate)
if err != nil {
return nil, err
Expand All @@ -273,6 +273,63 @@ func setLACPMemberState(ctx context.Context, ate binding.ATE, lagMemberPorts []s
return resp.Warnings(), nil
}

// StartCapture starts capturing bytes on the specified ports.
func (o *OTG) StartCapture(t *testing.T, portNames ...string) {
t.Helper()
debugger.ActionStarted(t, "StartCapture on %v", o.ate)
warns, err := setCaptureState(context.Background(), o.ate, gosnappi.CaptureStateState.START, portNames)
if err != nil {
t.Fatalf("StartCapture(t) on %s: %v", o.ate, err)
}
if len(warns) > 0 {
t.Logf("StartCapture(t) on %s non-fatal warnings: %v", o.ate, warns)
}
}

// StopCapture starts capturing bytes on the specified ports.
func (o *OTG) StopCapture(t *testing.T, portNames ...string) {
t.Helper()
debugger.ActionStarted(t, "StopCapture on %v", o.ate)
warns, err := setCaptureState(context.Background(), o.ate, gosnappi.CaptureStateState.STOP, portNames)
if err != nil {
t.Fatalf("StopCapture(t) on %s: %v", o.ate, err)
}
if len(warns) > 0 {
t.Logf("StopCapture(t) on %s non-fatal warnings: %v", o.ate, warns)
}
}

func setCaptureState(ctx context.Context, ate binding.ATE, state gosnappi.CaptureStateStateEnum, portNames []string) ([]string, error) {
api, err := rawapis.FetchOTG(ctx, ate)
if err != nil {
return nil, err
}
resp, err := api.SetCaptureState(api.NewCaptureState().SetState(state).SetPortNames(portNames))
if err != nil {
return nil, err
}
return resp.Warnings(), nil
}

// FetchCapture fetches the captured bytes on the specified port.
func (o *OTG) FetchCapture(t *testing.T, portName string) []byte {
t.Helper()
debugger.ActionStarted(t, "FetchCapture on %v", o.ate)
bytes, err := fetchCapture(context.Background(), o.ate, portName)
if err != nil {
t.Fatalf("FetchCapture(t) on %s: %v", o.ate, err)
}
return bytes
}

func fetchCapture(ctx context.Context, ate binding.ATE, postName string) ([]byte, error) {
api, err := rawapis.FetchOTG(ctx, ate)
if err != nil {
return nil, err
}
return api.GetCapture(api.NewCaptureRequest().SetPortName(postName))
}

// Telemetry returns a telemetry path root for the device.
func (o *OTG) Telemetry() *device.DevicePath {
root := device.DeviceRoot(o.ate.Name())
Expand Down
Loading

0 comments on commit 66d3c2d

Please sign in to comment.