Skip to content

Commit

Permalink
MGT-1: Updated the script with management vrf name and added deviatio…
Browse files Browse the repository at this point in the history
…n for table-connection config (openconfig#3009)

* Updated the script with management vrf name and added deviation for table-connection

* Added subinterface in Attributes

* Fixed static failure

* Fixing statci errors

* loopback intreface index

* Merged latest changes

* feature/system/management/otg_tests/management_ha_test/management_ha_test.go

* Updated management vrf name

* Update management_ha_test.go

Updated ifl number.

* Updated to add interface and assign to vrf in batch config

* Deleted the deviation table_connections_unsupported

---------

Co-authored-by: cprabha <[email protected]>
Co-authored-by: KandukuriSudheer <[email protected]>
  • Loading branch information
3 people authored Sep 4, 2024
1 parent 4c0bd06 commit 74155f6
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,24 @@ var (
IPv4Len: 32,
IPv6Len: 128,
}

mgmtVRF = "mvrf1"
mgmtVRF = map[ondatra.Vendor]string{
ondatra.JUNIPER: "mvrf1",
ondatra.ARISTA: "mvrf1",
ondatra.CISCO: "mgmtvrf1",
ondatra.NOKIA: "mgmtvrf1",
}
loopbackIntf = map[ondatra.Vendor]int{
ondatra.JUNIPER: 0,
ondatra.ARISTA: 1,
ondatra.CISCO: 1,
ondatra.NOKIA: 1,
}
loopbackSubIntf = map[ondatra.Vendor]int32{
ondatra.JUNIPER: 10,
ondatra.ARISTA: 0,
ondatra.CISCO: 0,
ondatra.NOKIA: 0,
}
bgpPorts = []string{"port1", "port2"}

lossTolerance = float64(1)
Expand All @@ -71,11 +87,10 @@ func TestManagementHA1(t *testing.T) {
p2 := dut.Port(t, "port2")
p3 := dut.Port(t, "port3")
p4 := dut.Port(t, "port4")
loopbackIntfName := netutil.LoopbackInterface(t, dut, 1)
createInterfaces(t, dut, []string{p1.Name(), p2.Name(), p3.Name(), p4.Name(), loopbackIntfName})
addInterfacesToVRF(t, dut, mgmtVRF, []string{p1.Name(), p2.Name(), p3.Name(), p4.Name(), loopbackIntfName})

bs := cfgplugins.NewBGPSession(t, cfgplugins.PortCount4, &mgmtVRF)
loopbackIntfName := netutil.LoopbackInterface(t, dut, loopbackIntf[dut.Vendor()])
mgmtVRFName := mgmtVRF[dut.Vendor()]
createAndAddInterfacesToVRF(t, dut, mgmtVRFName, []string{p1.Name(), p2.Name(), p3.Name(), p4.Name(), loopbackIntfName}, []uint32{0, 0, 0, 0, uint32(loopbackSubIntf[dut.Vendor()])})
bs := cfgplugins.NewBGPSession(t, cfgplugins.PortCount4, &mgmtVRFName)
bs.WithEBGP(
t,
[]oc.E_BgpTypes_AFI_SAFI_TYPE{oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST},
Expand All @@ -87,12 +102,12 @@ func TestManagementHA1(t *testing.T) {
g := bs.DUTConf.GetOrCreateNetworkInstance(deviations.DefaultNetworkInstance(dut)).GetOrCreateProtocol(cfgplugins.PTBGP, "BGP").GetOrCreateBgp().GetOrCreateGlobal()
g.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_L3VPN_IPV6_UNICAST).Enabled = ygot.Bool(true)
}
bgp := bs.DUTConf.GetOrCreateNetworkInstance(mgmtVRF).GetOrCreateProtocol(cfgplugins.PTBGP, "BGP").GetOrCreateBgp()
bgp := bs.DUTConf.GetOrCreateNetworkInstance(mgmtVRFName).GetOrCreateProtocol(cfgplugins.PTBGP, "BGP").GetOrCreateBgp()
bgp.GetOrCreateGlobal().GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).GetOrCreateUseMultiplePaths().GetOrCreateEbgp()

if deviations.SetNoPeerGroup(dut) || deviations.PeerGroupDefEbgpVrfUnsupported(dut) {
bs.DUTConf.GetOrCreateNetworkInstance(mgmtVRF).GetOrCreateProtocol(cfgplugins.PTBGP, "BGP").GetOrCreateBgp().PeerGroup = nil
neighbors := bs.DUTConf.GetOrCreateNetworkInstance(mgmtVRF).GetOrCreateProtocol(cfgplugins.PTBGP, "BGP").GetOrCreateBgp().Neighbor
bs.DUTConf.GetOrCreateNetworkInstance(mgmtVRFName).GetOrCreateProtocol(cfgplugins.PTBGP, "BGP").GetOrCreateBgp().PeerGroup = nil
neighbors := bs.DUTConf.GetOrCreateNetworkInstance(mgmtVRFName).GetOrCreateProtocol(cfgplugins.PTBGP, "BGP").GetOrCreateBgp().Neighbor
for _, neighbor := range neighbors {
neighbor.PeerGroup = nil
}
Expand All @@ -103,11 +118,11 @@ func TestManagementHA1(t *testing.T) {
if deviations.ExplicitEnableBGPOnDefaultVRF(dut) {
bs.DUTConf.GetOrCreateNetworkInstance(deviations.DefaultNetworkInstance(dut)).GetOrCreateProtocol(cfgplugins.PTBGP, "BGP").GetOrCreateBgp().GetOrCreateGlobal().SetAs(cfgplugins.DutAS)
}
if dut.Vendor() != ondatra.NOKIA {
bs.DUTConf.GetOrCreateNetworkInstance(mgmtVRF).SetRouteDistinguisher(fmt.Sprintf("%d:%d", cfgplugins.DutAS, 100))
if dut.Vendor() != ondatra.NOKIA && dut.Vendor() != ondatra.JUNIPER {
bs.DUTConf.GetOrCreateNetworkInstance(mgmtVRFName).SetRouteDistinguisher(fmt.Sprintf("%d:%d", cfgplugins.DutAS, 100))
}
bs.PushAndStart(t)
if verfied := verifyDUTBGPEstablished(t, bs.DUT, mgmtVRF); verfied {
if verfied := verifyDUTBGPEstablished(t, bs.DUT, mgmtVRFName); verfied {
t.Log("DUT BGP sessions established")
} else {
t.Fatalf("BGP sessions not established")
Expand Down Expand Up @@ -145,7 +160,8 @@ func TestManagementHA1(t *testing.T) {
otgutils.LogPortMetrics(t, bs.ATE.OTG(), bs.ATETop)
framesTx := gnmi.Get(t, bs.ATE.OTG(), gnmi.OTG().Port(bs.ATE.Port(t, "port4").ID()).Counters().OutFrames().State())
framesRx := gnmi.Get(t, bs.ATE.OTG(), gnmi.OTG().Port(bs.ATE.Port(t, "port2").ID()).Counters().InFrames().State())
if lossPct(float64(framesTx), float64(framesRx)) > lossTolerance {
lossV6 := otgutils.GetFlowLossPct(t, bs.ATE.OTG(), "v6Flow", 10*time.Second)
if lossV6 > lossTolerance || framesRx < framesTx {
t.Errorf("Frames sent/received: got: %d, want: %d", framesRx, framesTx)
}
})
Expand Down Expand Up @@ -178,13 +194,17 @@ func TestManagementHA1(t *testing.T) {
otgutils.LogPortMetrics(t, bs.ATE.OTG(), bs.ATETop)
framesTx := gnmi.Get(t, bs.ATE.OTG(), gnmi.OTG().Port(bs.ATE.Port(t, "port4").ID()).Counters().OutFrames().State())
framesRx := gnmi.Get(t, bs.ATE.OTG(), gnmi.OTG().Port(bs.ATE.Port(t, "port1").ID()).Counters().InFrames().State())
if lossPct(float64(framesTx), float64(framesRx)) > lossTolerance {
lossV6 := otgutils.GetFlowLossPct(t, bs.ATE.OTG(), "v6Flow", 10*time.Second)
if lossV6 > lossTolerance || framesRx < framesTx {
t.Errorf("Frames sent/received: got: %d, want: %d", framesRx, framesTx)
}
})

defer func() {
gnmi.Delete(t, dut, gnmi.OC().NetworkInstance(mgmtVRF).Config())
batchConfig := &gnmi.SetBatch{}
gnmi.BatchDelete(batchConfig, gnmi.OC().Interface(loopbackIntfName).Config())
gnmi.BatchDelete(batchConfig, gnmi.OC().NetworkInstance(mgmtVRFName).Config())
batchConfig.Set(t, dut)
}()
}

Expand Down Expand Up @@ -213,6 +233,7 @@ func createFlowV6(t *testing.T, bs *cfgplugins.BGPSession) {
}

func configureStaticRoute(t *testing.T, dut *ondatra.DUTDevice, nextHopIP string) {
mgmtVRFName := mgmtVRF[dut.Vendor()]
c := &oc.NetworkInstance_Protocol{
Identifier: oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_STATIC,
Name: ygot.String(deviations.StaticProtocolName(dut)),
Expand All @@ -225,7 +246,7 @@ func configureStaticRoute(t *testing.T, dut *ondatra.DUTDevice, nextHopIP string
} else {
nh.Preference = ygot.Uint32(220)
}
sp := gnmi.OC().NetworkInstance(mgmtVRF).Protocol(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_STATIC, deviations.StaticProtocolName(dut))
sp := gnmi.OC().NetworkInstance(mgmtVRFName).Protocol(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_STATIC, deviations.StaticProtocolName(dut))
gnmi.Update(t, dut, sp.Config(), c)
gnmi.Replace(t, dut, sp.Static(defaultRoute+"/0").Config(), s)
}
Expand All @@ -250,39 +271,39 @@ func configureEmulatedNetworks(bs *cfgplugins.BGPSession) {
}

func configureLoopbackOnDUT(t *testing.T, dut *ondatra.DUTDevice) {
loopbackIntfName := netutil.LoopbackInterface(t, dut, 1)
loopbackIntfName := netutil.LoopbackInterface(t, dut, loopbackIntf[dut.Vendor()])
dutlo0Attrs.Subinterface = uint32(loopbackSubIntf[dut.Vendor()])
loop := dutlo0Attrs.NewOCInterface(loopbackIntfName, dut)
loop.Type = oc.IETFInterfaces_InterfaceType_softwareLoopback
gnmi.Update(t, dut, gnmi.OC().Interface(loopbackIntfName).Config(), loop)
t.Logf("Got DUT IPv6 loopback address: %v", dutlo0Attrs.IPv6)
}

func createInterfaces(t *testing.T, dut *ondatra.DUTDevice, intfNames []string) {
func createAndAddInterfacesToVRF(t *testing.T, dut *ondatra.DUTDevice, vrfname string, intfNames []string, unit []uint32) {
root := &oc.Root{}
batchConfig := &gnmi.SetBatch{}
for index, intfName := range intfNames {
i := root.GetOrCreateInterface(intfName)
i.Type = oc.IETFInterfaces_InterfaceType_ethernetCsmacd
i.Description = ygot.String(fmt.Sprintf("Port %s", strconv.Itoa(index+1)))
if intfName == netutil.LoopbackInterface(t, dut, 1) {
if intfName == netutil.LoopbackInterface(t, dut, loopbackIntf[dut.Vendor()]) {
i.Type = oc.IETFInterfaces_InterfaceType_softwareLoopback
i.Description = ygot.String(fmt.Sprintf("Port %s", intfName))
}
si := i.GetOrCreateSubinterface(0)
si := i.GetOrCreateSubinterface(unit[index])
si.Enabled = ygot.Bool(true)
gnmi.Update(t, dut, gnmi.OC().Interface(intfName).Config(), i)
gnmi.BatchUpdate(batchConfig, gnmi.OC().Interface(intfName).Config(), i)
}
}

func addInterfacesToVRF(t *testing.T, dut *ondatra.DUTDevice, vrfname string, intfNames []string) {
root := &oc.Root{}
mgmtNI := root.GetOrCreateNetworkInstance(vrfname)
mgmtNI.Type = oc.NetworkInstanceTypes_NETWORK_INSTANCE_TYPE_L3VRF
for _, intfName := range intfNames {
for index, intfName := range intfNames {
vi := mgmtNI.GetOrCreateInterface(intfName)
vi.Interface = ygot.String(intfName)
vi.Subinterface = ygot.Uint32(0)
vi.Subinterface = ygot.Uint32(unit[index])
}
gnmi.Replace(t, dut, gnmi.OC().NetworkInstance(mgmtVRF).Config(), mgmtNI)
gnmi.BatchReplace(batchConfig, gnmi.OC().NetworkInstance(vrfname).Config(), mgmtNI)
batchConfig.Set(t, dut)
t.Logf("Added interface %v to VRF %s", intfNames, vrfname)
}

Expand All @@ -303,7 +324,7 @@ func verifyDUTBGPEstablished(t *testing.T, dut *ondatra.DUTDevice, ni string) bo

func advertiseDUTLoopbackToATE(t *testing.T, dut *ondatra.DUTDevice, bs *cfgplugins.BGPSession) {
t.Helper()

mgmtVRFName := mgmtVRF[dut.Vendor()]
batchSet := &gnmi.SetBatch{}

root := &oc.Root{}
Expand Down Expand Up @@ -333,35 +354,36 @@ func advertiseDUTLoopbackToATE(t *testing.T, dut *ondatra.DUTDevice, bs *cfgplug
if err != nil {
t.Fatalf("Failed to create CLI ygnmi query: %v", err)
}
cliCfg := getCiscoCLIRedisConfig("BGP", cfgplugins.DutAS, mgmtVRF)
cliCfg := getCiscoCLIRedisConfig("BGP", cfgplugins.DutAS, mgmtVRFName)
gnmi.BatchUpdate(batchSet, cliPath, cliCfg)
} else {
stmt.GetOrCreateConditions().SetInstallProtocolEq(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_DIRECTLY_CONNECTED)
}
stmt.GetOrCreateActions().PolicyResult = oc.RoutingPolicy_PolicyResultType_ACCEPT_ROUTE
for _, neighbor := range []string{bs.ATEPorts[0].IPv6, bs.ATEPorts[1].IPv6} {
pathV6 := gnmi.OC().NetworkInstance(mgmtVRF).Protocol(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, "BGP").Bgp().Neighbor(neighbor).AfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).ApplyPolicy()
policyV6 := root.GetOrCreateNetworkInstance(mgmtVRF).GetOrCreateProtocol(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, "BGP").GetOrCreateBgp().GetOrCreateNeighbor(neighbor).GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).GetOrCreateApplyPolicy()
policyV6.SetExportPolicy([]string{"rp"})
gnmi.BatchUpdate(batchSet, pathV6.Config(), policyV6)
stmt.GetOrCreateActions().PolicyResult = oc.RoutingPolicy_PolicyResultType_ACCEPT_ROUTE
for _, neighbor := range []string{bs.ATEPorts[0].IPv6, bs.ATEPorts[1].IPv6} {
pathV6 := gnmi.OC().NetworkInstance(mgmtVRFName).Protocol(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, "BGP").Bgp().Neighbor(neighbor).AfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).ApplyPolicy()
policyV6 := root.GetOrCreateNetworkInstance(mgmtVRFName).GetOrCreateProtocol(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, "BGP").GetOrCreateBgp().GetOrCreateNeighbor(neighbor).GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).GetOrCreateApplyPolicy()
policyV6.SetExportPolicy([]string{"rp"})
gnmi.BatchUpdate(batchSet, pathV6.Config(), policyV6)
}
}
} else {
tableConn := root.GetOrCreateNetworkInstance(mgmtVRF).GetOrCreateTableConnection(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_DIRECTLY_CONNECTED, oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, oc.Types_ADDRESS_FAMILY_IPV6)
tableConn := root.GetOrCreateNetworkInstance(mgmtVRFName).GetOrCreateTableConnection(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_DIRECTLY_CONNECTED, oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, oc.Types_ADDRESS_FAMILY_IPV6)
if !deviations.SkipSettingDisableMetricPropagation(dut) {
tableConn.SetDisableMetricPropagation(false)
}
tableConn.SetDefaultImportPolicy(oc.RoutingPolicy_DefaultPolicyType_REJECT_ROUTE)
tableConn.SetImportPolicy([]string{"rp"})
gnmi.BatchUpdate(batchSet, gnmi.OC().NetworkInstance(mgmtVRF).TableConnection(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_DIRECTLY_CONNECTED, oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, oc.Types_ADDRESS_FAMILY_IPV6).Config(), tableConn)
gnmi.BatchUpdate(batchSet, gnmi.OC().NetworkInstance(mgmtVRFName).TableConnection(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_DIRECTLY_CONNECTED, oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, oc.Types_ADDRESS_FAMILY_IPV6).Config(), tableConn)

tableConn1 := root.GetOrCreateNetworkInstance(mgmtVRF).GetOrCreateTableConnection(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_DIRECTLY_CONNECTED, oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, oc.Types_ADDRESS_FAMILY_IPV4)
tableConn1 := root.GetOrCreateNetworkInstance(mgmtVRFName).GetOrCreateTableConnection(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_DIRECTLY_CONNECTED, oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, oc.Types_ADDRESS_FAMILY_IPV4)
tableConn1.SetImportPolicy([]string{"rp"})
gnmi.BatchUpdate(batchSet, gnmi.OC().NetworkInstance(mgmtVRF).TableConnection(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_DIRECTLY_CONNECTED, oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, oc.Types_ADDRESS_FAMILY_IPV4).Config(), tableConn1)
gnmi.BatchUpdate(batchSet, gnmi.OC().NetworkInstance(mgmtVRFName).TableConnection(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_DIRECTLY_CONNECTED, oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, oc.Types_ADDRESS_FAMILY_IPV4).Config(), tableConn1)
}
batchSet.Set(t, dut)
}

func configureImportExportBGPPolicy(t *testing.T, bs *cfgplugins.BGPSession, dut *ondatra.DUTDevice) {
mgmtVRFName := mgmtVRF[dut.Vendor()]
root := &oc.Root{}
batchSet := &gnmi.SetBatch{}

Expand Down Expand Up @@ -405,8 +427,8 @@ func configureImportExportBGPPolicy(t *testing.T, bs *cfgplugins.BGPSession, dut
gnmi.BatchUpdate(batchSet, gnmi.OC().RoutingPolicy().Config(), rp)

for _, neighbor := range []string{bs.ATEPorts[0].IPv6, bs.ATEPorts[1].IPv6} {
pathV6 := gnmi.OC().NetworkInstance(mgmtVRF).Protocol(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, "BGP").Bgp().Neighbor(neighbor).AfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).ApplyPolicy()
policyV6 := root.GetOrCreateNetworkInstance(mgmtVRF).GetOrCreateProtocol(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, "BGP").GetOrCreateBgp().GetOrCreateNeighbor(neighbor).GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).GetOrCreateApplyPolicy()
pathV6 := gnmi.OC().NetworkInstance(mgmtVRFName).Protocol(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, "BGP").Bgp().Neighbor(neighbor).AfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).ApplyPolicy()
policyV6 := root.GetOrCreateNetworkInstance(mgmtVRFName).GetOrCreateProtocol(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, "BGP").GetOrCreateBgp().GetOrCreateNeighbor(neighbor).GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).GetOrCreateApplyPolicy()
policyV6.SetImportPolicy([]string{"importRoutePolicy"})
policyV6.SetExportPolicy([]string{"exportRoutePolicy"})
gnmi.BatchUpdate(batchSet, pathV6.Config(), policyV6)
Expand Down
25 changes: 13 additions & 12 deletions internal/attrs/attrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,18 @@ import (
// and for an ATETopology. All fields are optional; only those that are
// non-empty will be set when configuring an interface.
type Attributes struct {
IPv4 string
IPv4Sec string // Secondary IPv4 address
IPv6 string
MAC string
Name string // Interface name, only applied to ATE ports.
Desc string // Description, only applied to DUT interfaces.
IPv4Len uint8 // Prefix length for IPv4.
IPv4LenSec uint8 // Prefix length for Secondary IPv4 address.
IPv6Len uint8 // Prefix length for IPv6.
MTU uint16
ID uint32 // /interfaces/interface/state/id p4rt interface id
IPv4 string
IPv4Sec string // Secondary IPv4 address
IPv6 string
MAC string
Name string // Interface name, only applied to ATE ports.
Desc string // Description, only applied to DUT interfaces.
Subinterface uint32 //Subinterface
IPv4Len uint8 // Prefix length for IPv4.
IPv4LenSec uint8 // Prefix length for Secondary IPv4 address.
IPv6Len uint8 // Prefix length for IPv6.
MTU uint16
ID uint32 // /interfaces/interface/state/id p4rt interface id
}

// IPv4CIDR constructs the IPv4 CIDR notation with the given prefix
Expand Down Expand Up @@ -76,7 +77,7 @@ func (a *Attributes) ConfigOCInterface(intf *oc.Interface, dut *ondatra.DUTDevic
e.MacAddress = ygot.String(a.MAC)
}

s := intf.GetOrCreateSubinterface(0)
s := intf.GetOrCreateSubinterface(a.Subinterface)
if a.IPv4 != "" {
s4 := s.GetOrCreateIpv4()
if deviations.InterfaceEnabled(dut) && !deviations.IPv4MissingEnabled(dut) {
Expand Down

0 comments on commit 74155f6

Please sign in to comment.