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-destination608849283943705241/.
  • Loading branch information
GGN Engprod Team authored and greg-dennis committed Oct 31, 2022
1 parent aa1f02d commit 4b34f15
Show file tree
Hide file tree
Showing 14 changed files with 88,291 additions and 88,596 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ additional flags to control the execution of the test:
time to wait.
* `-run_time` (*optional*): Timeout of the test run, excluding the wait time
for the testbed to be ready. If not specified, no limit is imposed.
* `-xml (*optional*): File path to write JUnit XML test results; disables
* `-xml` (*optional*): File path to write JUnit XML test results; disables
normal Go test logging.
* `-debug (*optional*): Whether the test is run in debug mode.
* `-debug` (*optional*): Whether the test is run in debug mode.

In addition, the binding implementation is free to define its own set of
optional or required flags.
Expand Down
84,123 changes: 42,063 additions & 42,060 deletions gnmi/oc/schema.go

Large diffs are not rendered by default.

87 changes: 49 additions & 38 deletions internal/ixgnmi/bgprib.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
// bgpLearnedInfo is the output of learned info for BGP from an Ixia device.
// This struct is used for ipv4 and ipv6 info.
type bgpLearnedInfo struct {
IPV4Prefix string `ixia:"IPv4 Prefix "`
IPV4Prefix string `ixia:"IPv4 Prefix"`
IPV6Prefix string `ixia:"IPv6 Prefix"`
PrefixLen int `ixia:"Prefix Length"`
PathID uint32 `ixia:"Path ID"`
Expand All @@ -43,59 +43,70 @@ type bgpLearnedInfo struct {
LargeCommunity string `ixia:"Large Community"`
}

func bgpRIBDevice(learnedBGP []bgpLearnedInfo, intf, protocol, neighbor string, v4 bool) (*telemetry.Device, error) {
func bgpRIBDevice(intf, protocol string, peer4Infos, peer6Infos map[string][]bgpLearnedInfo) (*telemetry.Device, error) {
dev := &telemetry.Device{}
rib := dev.GetOrCreateNetworkInstance(intf).
GetOrCreateProtocol(telemetry.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, protocol).
GetOrCreateBgp().
GetOrCreateRib()
var ipv4RIB *telemetry.NetworkInstance_Protocol_Bgp_Rib_AfiSafi_Ipv4Unicast_Neighbor_AdjRibInPre
var ipv6RIB *telemetry.NetworkInstance_Protocol_Bgp_Rib_AfiSafi_Ipv6Unicast_Neighbor_AdjRibInPre
if v4 {
ipv4RIB = rib.GetOrCreateAfiSafi(telemetry.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST).

for peer, infos := range peer4Infos {
ipv4RIB := rib.GetOrCreateAfiSafi(telemetry.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST).
GetOrCreateIpv4Unicast().
GetOrCreateNeighbor(neighbor).
GetOrCreateNeighbor(peer).
GetOrCreateAdjRibInPre()
} else {
ipv6RIB = rib.GetOrCreateAfiSafi(telemetry.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).
GetOrCreateIpv6Unicast().
GetOrCreateNeighbor(neighbor).
GetOrCreateAdjRibInPre()
}
attrLen := len(rib.AttrSet)
commLen := len(rib.Community)

attrLen := len(rib.AttrSet)
commLen := len(rib.Community)

for i, info := range learnedBGP {
if info == (bgpLearnedInfo{}) {
log.Infof("Skipping empty BGP learned info")
continue
}

attrIndex := uint64(i + attrLen)
commIndex := uint64(i + commLen)
if err := appendDetails(info, rib, attrIndex, commIndex, v4); err != nil {
return nil, fmt.Errorf("failed to append details for elem %d: %w", i, err)
}

var err error
if v4 {
err = ipv4RIB.AppendRoute(&telemetry.NetworkInstance_Protocol_Bgp_Rib_AfiSafi_Ipv4Unicast_Neighbor_AdjRibInPre_Route{
for i, info := range infos {
if info == (bgpLearnedInfo{}) {
log.Infof("Skipping empty BGP learned info")
continue
}
attrIndex := uint64(i + attrLen)
commIndex := uint64(i + commLen)
if err := appendDetails(info, rib, attrIndex, commIndex, true); err != nil {
return nil, fmt.Errorf("failed to append details for elem %d: %w", i, err)
}
route := &telemetry.NetworkInstance_Protocol_Bgp_Rib_AfiSafi_Ipv4Unicast_Neighbor_AdjRibInPre_Route{
Prefix: ygot.String(fmt.Sprintf("%s/%d", info.IPV4Prefix, info.PrefixLen)),
PathId: ygot.Uint32(info.PathID),
AttrIndex: &attrIndex,
CommunityIndex: &commIndex,
})
} else {
err = ipv6RIB.AppendRoute(&telemetry.NetworkInstance_Protocol_Bgp_Rib_AfiSafi_Ipv6Unicast_Neighbor_AdjRibInPre_Route{
}
if err := ipv4RIB.AppendRoute(route); err != nil {
return nil, fmt.Errorf("failed to append route for elem %d: %w", i, err)
}
}
}

for peer, infos := range peer6Infos {
ipv6RIB := rib.GetOrCreateAfiSafi(telemetry.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).
GetOrCreateIpv6Unicast().
GetOrCreateNeighbor(peer).
GetOrCreateAdjRibInPre()
attrLen := len(rib.AttrSet)
commLen := len(rib.Community)

for i, info := range infos {
if info == (bgpLearnedInfo{}) {
log.Infof("Skipping empty BGP learned info")
continue
}
attrIndex := uint64(i + attrLen)
commIndex := uint64(i + commLen)
if err := appendDetails(info, rib, attrIndex, commIndex, false); err != nil {
return nil, fmt.Errorf("failed to append details for elem %d: %w", i, err)
}
route := &telemetry.NetworkInstance_Protocol_Bgp_Rib_AfiSafi_Ipv6Unicast_Neighbor_AdjRibInPre_Route{
Prefix: ygot.String(fmt.Sprintf("%s/%d", info.IPV6Prefix, info.PrefixLen)),
PathId: ygot.Uint32(info.PathID),
AttrIndex: &attrIndex,
CommunityIndex: &commIndex,
})
}
if err != nil {
return nil, fmt.Errorf("failed to append route for elem %d: %w", i, err)
}
if err := ipv6RIB.AppendRoute(route); err != nil {
return nil, fmt.Errorf("failed to append route for elem %d: %w", i, err)
}
}
}
return dev, nil
Expand Down
69 changes: 39 additions & 30 deletions internal/ixgnmi/bgprib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,65 +25,75 @@ import (

func TestBGPRIBDevice(t *testing.T) {
tests := []struct {
desc string
info []bgpLearnedInfo
v4 bool
wantRIB *telemetry.NetworkInstance_Protocol_Bgp_Rib
wantErr string
desc string
infos4, infos6 map[string][]bgpLearnedInfo
wantRIB *telemetry.NetworkInstance_Protocol_Bgp_Rib
wantErr string
}{{
desc: "invalid attr set index",
info: []bgpLearnedInfo{{
infos4: map[string][]bgpLearnedInfo{"1.2.3.4": {{
IPV4NextHop: "localhost",
}},
}}},
wantErr: "failed to append details for elem 0",
}, {
desc: "invalid community index",
info: []bgpLearnedInfo{{
infos4: map[string][]bgpLearnedInfo{"1.2.3.4": {{
Community: "65532 : 10200",
}},
}}},
wantErr: "failed to append details for elem 0",
}, {
desc: "invalid origin type",
info: []bgpLearnedInfo{{
infos4: map[string][]bgpLearnedInfo{"1.2.3.4": {{
Origin: "foo",
}},
}}},
wantErr: "unknown origin type",
}, {
desc: "duplicate v4 route",
v4: true,
info: []bgpLearnedInfo{{
infos4: map[string][]bgpLearnedInfo{"1.2.3.4": {{
IPV4Prefix: "127.0.0.1",
PathID: 0,
Origin: "IGP",
}, {
IPV4Prefix: "127.0.0.1",
PathID: 0,
Origin: "IGP",
}},
}}},
wantErr: "failed to append route for elem 1",
}, {
desc: "duplicate v6 route",
info: []bgpLearnedInfo{{
infos6: map[string][]bgpLearnedInfo{"1:2:3:4:5:6:7:8": {{
IPV6Prefix: "::1",
PathID: 0,
Origin: "IGP",
}, {
IPV6Prefix: "::1",
PathID: 0,
Origin: "IGP",
}},
}}},
wantErr: "failed to append route for elem 1",
}, {
desc: "empty learned info",
info: []bgpLearnedInfo{{}},
desc: "empty learned info",
infos4: map[string][]bgpLearnedInfo{"1.2.3.4": {{}}},
infos6: map[string][]bgpLearnedInfo{"1:2:3:4:5:6:7:8": {{}}},
wantRIB: &telemetry.NetworkInstance_Protocol_Bgp_Rib{
AfiSafi: map[telemetry.E_BgpTypes_AFI_SAFI_TYPE]*telemetry.NetworkInstance_Protocol_Bgp_Rib_AfiSafi{
telemetry.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST: {
AfiSafiName: telemetry.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST,
Ipv4Unicast: &telemetry.NetworkInstance_Protocol_Bgp_Rib_AfiSafi_Ipv4Unicast{
Neighbor: map[string]*telemetry.NetworkInstance_Protocol_Bgp_Rib_AfiSafi_Ipv4Unicast_Neighbor{
"1.2.3.4": &telemetry.NetworkInstance_Protocol_Bgp_Rib_AfiSafi_Ipv4Unicast_Neighbor{
NeighborAddress: ygot.String("1.2.3.4"),
AdjRibInPre: &telemetry.NetworkInstance_Protocol_Bgp_Rib_AfiSafi_Ipv4Unicast_Neighbor_AdjRibInPre{},
},
},
},
},
telemetry.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST: {
AfiSafiName: telemetry.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST,
Ipv6Unicast: &telemetry.NetworkInstance_Protocol_Bgp_Rib_AfiSafi_Ipv6Unicast{
Neighbor: map[string]*telemetry.NetworkInstance_Protocol_Bgp_Rib_AfiSafi_Ipv6Unicast_Neighbor{
"neighbor": {
NeighborAddress: ygot.String("neighbor"),
"1:2:3:4:5:6:7:8": {
NeighborAddress: ygot.String("1:2:3:4:5:6:7:8"),
AdjRibInPre: &telemetry.NetworkInstance_Protocol_Bgp_Rib_AfiSafi_Ipv6Unicast_Neighbor_AdjRibInPre{},
},
},
Expand All @@ -93,8 +103,7 @@ func TestBGPRIBDevice(t *testing.T) {
},
}, {
desc: "v4 routes",
v4: true,
info: []bgpLearnedInfo{{
infos4: map[string][]bgpLearnedInfo{"1.2.3.4": {{
IPV4Prefix: "127.0.0.1",
PathID: 0,
IPV4NextHop: "127.0.0.2",
Expand All @@ -107,7 +116,7 @@ func TestBGPRIBDevice(t *testing.T) {
IPV4Prefix: "127.0.0.3",
IPV4NextHop: "127.0.0.4",
Origin: "EGP",
}},
}}},
wantRIB: &telemetry.NetworkInstance_Protocol_Bgp_Rib{
AttrSet: map[uint64]*telemetry.NetworkInstance_Protocol_Bgp_Rib_AttrSet{
0: {
Expand Down Expand Up @@ -139,8 +148,8 @@ func TestBGPRIBDevice(t *testing.T) {
AfiSafiName: telemetry.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST,
Ipv4Unicast: &telemetry.NetworkInstance_Protocol_Bgp_Rib_AfiSafi_Ipv4Unicast{
Neighbor: map[string]*telemetry.NetworkInstance_Protocol_Bgp_Rib_AfiSafi_Ipv4Unicast_Neighbor{
"neighbor": {
NeighborAddress: ygot.String("neighbor"),
"1.2.3.4": {
NeighborAddress: ygot.String("1.2.3.4"),
AdjRibInPre: &telemetry.NetworkInstance_Protocol_Bgp_Rib_AfiSafi_Ipv4Unicast_Neighbor_AdjRibInPre{
Route: map[telemetry.NetworkInstance_Protocol_Bgp_Rib_AfiSafi_Ipv4Unicast_Neighbor_AdjRibInPre_Route_Key]*telemetry.NetworkInstance_Protocol_Bgp_Rib_AfiSafi_Ipv4Unicast_Neighbor_AdjRibInPre_Route{
{Prefix: "127.0.0.1/0"}: {
Expand All @@ -165,7 +174,7 @@ func TestBGPRIBDevice(t *testing.T) {
},
}, {
desc: "v6 routes",
info: []bgpLearnedInfo{{
infos6: map[string][]bgpLearnedInfo{"1:2:3:4:5:6:7:8": {{
IPV6Prefix: "::1",
IPV6NextHop: "::2",
MED: 100,
Expand All @@ -176,7 +185,7 @@ func TestBGPRIBDevice(t *testing.T) {
IPV6Prefix: "::3",
IPV6NextHop: "::4",
Origin: "IGP",
}},
}}},
wantRIB: &telemetry.NetworkInstance_Protocol_Bgp_Rib{
AttrSet: map[uint64]*telemetry.NetworkInstance_Protocol_Bgp_Rib_AttrSet{
0: {
Expand Down Expand Up @@ -207,8 +216,8 @@ func TestBGPRIBDevice(t *testing.T) {
AfiSafiName: telemetry.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST,
Ipv6Unicast: &telemetry.NetworkInstance_Protocol_Bgp_Rib_AfiSafi_Ipv6Unicast{
Neighbor: map[string]*telemetry.NetworkInstance_Protocol_Bgp_Rib_AfiSafi_Ipv6Unicast_Neighbor{
"neighbor": {
NeighborAddress: ygot.String("neighbor"),
"1:2:3:4:5:6:7:8": {
NeighborAddress: ygot.String("1:2:3:4:5:6:7:8"),
AdjRibInPre: &telemetry.NetworkInstance_Protocol_Bgp_Rib_AfiSafi_Ipv6Unicast_Neighbor_AdjRibInPre{
Route: map[telemetry.NetworkInstance_Protocol_Bgp_Rib_AfiSafi_Ipv6Unicast_Neighbor_AdjRibInPre_Route_Key]*telemetry.NetworkInstance_Protocol_Bgp_Rib_AfiSafi_Ipv6Unicast_Neighbor_AdjRibInPre_Route{
{Prefix: "::1/0"}: {
Expand All @@ -234,7 +243,7 @@ func TestBGPRIBDevice(t *testing.T) {
}}
for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {
got, err := bgpRIBDevice(test.info, "interface", "protocol", "neighbor", test.v4)
got, err := bgpRIBDevice("interface", "protocol", test.infos4, test.infos6)
if d := errdiff.Substring(err, test.wantErr); d != "" {
t.Fatalf("bgpRIBDevice got unexpected error diff\n%s", d)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/ixgnmi/isislsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type isisLearnedInfo struct {
AgeSecs int `ixia:"Age (in secs)"`
}

func isisLSDBDevice(learnedISIS []isisLearnedInfo, intf, protocol string) (*telemetry.Device, error) {
func isisLSDBDevice(intf, protocol string, learnedISIS []isisLearnedInfo) (*telemetry.Device, error) {
dev := &telemetry.Device{}
isis := dev.GetOrCreateNetworkInstance(intf).
GetOrCreateProtocol(telemetry.PolicyTypes_INSTALL_PROTOCOL_TYPE_ISIS, protocol).
Expand Down
2 changes: 1 addition & 1 deletion internal/ixgnmi/isislsdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestISISLSDBDevice(t *testing.T) {
}}
for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {
got, err := isisLSDBDevice(test.info, "interface", "protocol")
got, err := isisLSDBDevice("interface", "protocol", test.info)
if d := errdiff.Substring(err, test.wantErr); d != "" {
t.Fatalf("isisLSDBDevice got unexpected error diff\n%s", d)
}
Expand Down
Loading

0 comments on commit 4b34f15

Please sign in to comment.