Skip to content

Commit aa97bd6

Browse files
[NX-OS] Add ospf enablement to ospf interface reference
This patch automatically infers the configuration for bfd on an ospf link according to the following config based on the `.spec.bfd.enabled` field in the `Interface` resource. ``` interface Ethernet1/1 ip ospf bfd ```
1 parent eb197bf commit aa97bd6

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

internal/provider/cisco/nxos/ospf.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ type OSPFInterface struct {
8181
ID string `json:"id"`
8282
NwT NtwType `json:"nwT"`
8383
PassiveCtrl PassiveControl `json:"passiveCtrl"`
84+
BFDCtrl OspfBfdCtrl `json:"bfdCtrl"`
8485
}
8586

8687
func (i *OSPFInterface) Key() string { return i.ID }
@@ -112,7 +113,7 @@ type OSPFIfAdjEpGroup struct {
112113
OperSt AdjOperSt `json:"operSt"` // Adjacency neighbor state
113114
Prio uint8 `json:"prio"` // Priority, used in determining the designated router on this network
114115
AdjStatsItems struct {
115-
LastStChgTs time.Time `json:"lastStChgTs"` // Timestamp of the last state change
116+
LastStChgTS time.Time `json:"lastStChgTs"` // Timestamp of the last state change
116117
} `json:"adjstats-items,omitzero"`
117118
}
118119

@@ -202,3 +203,11 @@ const (
202203
PassiveControlEnabled PassiveControl = "enabled"
203204
PassiveControlDisabled PassiveControl = "disabled"
204205
)
206+
207+
type OspfBfdCtrl string
208+
209+
const (
210+
OspfBfdCtrlUnspecified OspfBfdCtrl = "unspecified"
211+
OspfBfdCtrlEnabled OspfBfdCtrl = "enabled"
212+
OspfBfdCtrlDisabled OspfBfdCtrl = "disabled"
213+
)

internal/provider/cisco/nxos/ospf_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func init() {
2323
Area: "0.0.0.0",
2424
NwT: NtwTypeUnspecified,
2525
PassiveCtrl: PassiveControlUnspecified,
26+
BFDCtrl: OspfBfdCtrlUnspecified,
2627
}
2728
if strings.HasPrefix(name, "eth") {
2829
intf.NwT = NtwTypePointToPoint

internal/provider/cisco/nxos/provider.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,13 +1430,17 @@ func (p *Provider) EnsureOSPF(ctx context.Context, req *provider.EnsureOSPFReque
14301430
}
14311431
}
14321432

1433+
conf := make([]gnmiext.Configurable, 0, 3)
1434+
14331435
f := new(Feature)
14341436
f.Name = "ospf"
14351437
f.AdminSt = AdminStEnabled
1438+
conf = append(conf, f)
14361439

14371440
o := new(OSPF)
14381441
o.AdminSt = AdminStEnabled
14391442
o.Name = req.OSPF.Spec.Instance
1443+
conf = append(conf, o)
14401444

14411445
dom := new(OSPFDom)
14421446
dom.Name = DefaultVRFName
@@ -1492,6 +1496,18 @@ func (p *Provider) EnsureOSPF(ctx context.Context, req *provider.EnsureOSPFReque
14921496
if iface.Passive == nil || !*iface.Passive {
14931497
intf.PassiveCtrl = PassiveControlDisabled
14941498
}
1499+
intf.BFDCtrl = OspfBfdCtrlUnspecified
1500+
if iface.Interface.Spec.BFD != nil {
1501+
fb := new(Feature)
1502+
fb.Name = "bfd"
1503+
fb.AdminSt = AdminStEnabled
1504+
conf = slices.Insert(conf, 1, gnmiext.Configurable(fb)) // insert before OSPF
1505+
1506+
intf.BFDCtrl = OspfBfdCtrlDisabled
1507+
if !iface.Interface.Spec.BFD.Enabled {
1508+
intf.BFDCtrl = OspfBfdCtrlEnabled
1509+
}
1510+
}
14951511
dom.IfItems.IfList.Set(intf)
14961512
}
14971513

@@ -1519,7 +1535,7 @@ func (p *Provider) EnsureOSPF(ctx context.Context, req *provider.EnsureOSPFReque
15191535
dom.MaxlsapItems.MaxLsa = cfg.MaxLSA
15201536
}
15211537

1522-
return p.client.Update(ctx, f, o)
1538+
return p.client.Update(ctx, conf...)
15231539
}
15241540

15251541
func (p *Provider) DeleteOSPF(ctx context.Context, req *provider.DeleteOSPFRequest) error {
@@ -1557,7 +1573,7 @@ func (p *Provider) GetOSPFStatus(ctx context.Context, req *provider.OSPFStatusRe
15571573
Address: adj.PeerIP,
15581574
Interface: i,
15591575
Priority: adj.Prio,
1560-
LastEstablishedTime: adj.AdjStatsItems.LastStChgTs,
1576+
LastEstablishedTime: adj.AdjStatsItems.LastStChgTS,
15611577
AdjacencyState: adj.OperSt.ToNeighborState(),
15621578
})
15631579
}

internal/provider/cisco/nxos/testdata/ospf.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"area": "0.0.0.0",
2424
"id": "eth1/1",
2525
"nwT": "p2p",
26-
"passiveCtrl": "unspecified"
26+
"passiveCtrl": "unspecified",
27+
"bfdCtrl": "unspecified"
2728
}
2829
]
2930
},

0 commit comments

Comments
 (0)