Skip to content

Commit bba2fe6

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 c2fd2ed commit bba2fe6

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
@@ -1440,13 +1440,17 @@ func (p *Provider) EnsureOSPF(ctx context.Context, req *provider.EnsureOSPFReque
14401440
}
14411441
}
14421442

1443+
conf := make([]gnmiext.Configurable, 0, 3)
1444+
14431445
f := new(Feature)
14441446
f.Name = "ospf"
14451447
f.AdminSt = AdminStEnabled
1448+
conf = append(conf, f)
14461449

14471450
o := new(OSPF)
14481451
o.AdminSt = AdminStEnabled
14491452
o.Name = req.OSPF.Spec.Instance
1453+
conf = append(conf, o)
14501454

14511455
dom := new(OSPFDom)
14521456
dom.Name = DefaultVRFName
@@ -1502,6 +1506,18 @@ func (p *Provider) EnsureOSPF(ctx context.Context, req *provider.EnsureOSPFReque
15021506
if iface.Passive == nil || !*iface.Passive {
15031507
intf.PassiveCtrl = PassiveControlDisabled
15041508
}
1509+
intf.BFDCtrl = OspfBfdCtrlUnspecified
1510+
if iface.Interface.Spec.BFD != nil {
1511+
fb := new(Feature)
1512+
fb.Name = "bfd"
1513+
fb.AdminSt = AdminStEnabled
1514+
conf = slices.Insert(conf, 1, gnmiext.Configurable(fb)) // insert before OSPF
1515+
1516+
intf.BFDCtrl = OspfBfdCtrlDisabled
1517+
if !iface.Interface.Spec.BFD.Enabled {
1518+
intf.BFDCtrl = OspfBfdCtrlEnabled
1519+
}
1520+
}
15051521
dom.IfItems.IfList.Set(intf)
15061522
}
15071523

@@ -1529,7 +1545,7 @@ func (p *Provider) EnsureOSPF(ctx context.Context, req *provider.EnsureOSPFReque
15291545
dom.MaxlsapItems.MaxLsa = cfg.MaxLSA
15301546
}
15311547

1532-
return p.client.Update(ctx, f, o)
1548+
return p.client.Update(ctx, conf...)
15331549
}
15341550

15351551
func (p *Provider) DeleteOSPF(ctx context.Context, req *provider.DeleteOSPFRequest) error {
@@ -1567,7 +1583,7 @@ func (p *Provider) GetOSPFStatus(ctx context.Context, req *provider.OSPFStatusRe
15671583
Address: adj.PeerIP,
15681584
Interface: i,
15691585
Priority: adj.Prio,
1570-
LastEstablishedTime: adj.AdjStatsItems.LastStChgTs,
1586+
LastEstablishedTime: adj.AdjStatsItems.LastStChgTS,
15711587
AdjacencyState: adj.OperSt.ToNeighborState(),
15721588
})
15731589
}

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)