Skip to content

Commit 5184b8c

Browse files
[NX-OS] Implement support for PrefixSet on Cisco NX-OS
1 parent ac4578a commit 5184b8c

File tree

5 files changed

+120
-0
lines changed

5 files changed

+120
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package nxos
5+
6+
import (
7+
"github.com/ironcore-dev/network-operator/internal/provider/cisco/gnmiext/v2"
8+
)
9+
10+
var _ gnmiext.Configurable = (*PrefixList)(nil)
11+
12+
type PrefixList struct {
13+
Name string `json:"name"`
14+
EntItems struct {
15+
EntryList gnmiext.List[int32, *PrefixEntry] `json:"Entry-list"`
16+
} `json:"ent-items"`
17+
// Is6 indicates whether this is an IPv6 prefix list. This field is not serialized to JSON
18+
// and is only used internally to determine the correct XPath for the prefix list.
19+
Is6 bool `json:"-"`
20+
}
21+
22+
func (*PrefixList) IsListItem() {}
23+
24+
func (p *PrefixList) XPath() string {
25+
if p.Is6 {
26+
return "System/rpm-items/pfxlistv6-items/RuleV6-list[name=" + p.Name + "]"
27+
}
28+
return "System/rpm-items/pfxlistv4-items/RuleV4-list[name=" + p.Name + "]"
29+
}
30+
31+
type PrefixEntry struct {
32+
Action Action `json:"action"`
33+
Criteria Criteria `json:"criteria"`
34+
FromPfxLen int8 `json:"fromPfxLen"`
35+
Order int32 `json:"order"`
36+
Pfx string `json:"pfx"`
37+
ToPfxLen int8 `json:"toPfxLen"`
38+
}
39+
40+
func (e *PrefixEntry) Key() int32 { return e.Order }
41+
42+
type Criteria string
43+
44+
const (
45+
CriteriaExact Criteria = "exact"
46+
CriteriaInexact Criteria = "inexact"
47+
)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package nxos
5+
6+
func init() {
7+
p := &PrefixList{}
8+
p.Name = "TEST"
9+
p.EntItems.EntryList.Set(&PrefixEntry{
10+
Order: 10,
11+
Action: ActionPermit,
12+
Criteria: CriteriaInexact,
13+
Pfx: "10.0.0.0/8",
14+
FromPfxLen: 24,
15+
ToPfxLen: 24,
16+
})
17+
Register("prefix", p)
18+
}

internal/provider/cisco/nxos/provider.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ var (
5151
_ provider.OSPFProvider = (*Provider)(nil)
5252
_ provider.PIMProvider = (*Provider)(nil)
5353
_ provider.SNMPProvider = (*Provider)(nil)
54+
_ provider.PrefixSetProvider = (*Provider)(nil)
5455
_ provider.SyslogProvider = (*Provider)(nil)
5556
_ provider.UserProvider = (*Provider)(nil)
5657
_ provider.VLANProvider = (*Provider)(nil)
@@ -1590,6 +1591,36 @@ func (p *Provider) DeletePIM(ctx context.Context, _ *provider.DeletePIMRequest)
15901591
return p.client.Delete(ctx, new(StaticRPItems), new(AnycastPeerItems), new(PIMIfItems))
15911592
}
15921593

1594+
func (p *Provider) EnsurePrefixSet(ctx context.Context, req *provider.PrefixSetRequest) error {
1595+
s := new(PrefixList)
1596+
s.Name = req.PrefixSet.Spec.Name
1597+
s.Is6 = req.PrefixSet.Is6()
1598+
for _, entry := range req.PrefixSet.Spec.Entries {
1599+
e := new(PrefixEntry)
1600+
e.Action = ActionPermit
1601+
e.Criteria = CriteriaExact
1602+
e.Order = entry.Sequence
1603+
e.Pfx = entry.Prefix.String()
1604+
bits := int8(entry.Prefix.Bits()) // #nosec G115
1605+
if entry.MaskLengthRange != nil && (entry.MaskLengthRange.Min != bits || entry.MaskLengthRange.Max != bits) {
1606+
e.Criteria = CriteriaInexact
1607+
e.ToPfxLen = entry.MaskLengthRange.Max
1608+
if entry.MaskLengthRange.Min != bits {
1609+
e.FromPfxLen = entry.MaskLengthRange.Min
1610+
}
1611+
}
1612+
s.EntItems.EntryList.Set(e)
1613+
}
1614+
return p.client.Update(ctx, s)
1615+
}
1616+
1617+
func (p *Provider) DeletePrefixSet(ctx context.Context, req *provider.PrefixSetRequest) error {
1618+
s := new(PrefixList)
1619+
s.Name = req.PrefixSet.Spec.Name
1620+
s.Is6 = req.PrefixSet.Is6()
1621+
return p.client.Delete(ctx, s)
1622+
}
1623+
15931624
func (p *Provider) EnsureUser(ctx context.Context, req *provider.EnsureUserRequest) error {
15941625
u := new(User)
15951626
u.AllowExpired = "no"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"rpm-items": {
3+
"pfxlistv4-items": {
4+
"RuleV4-list": [
5+
{
6+
"name": "TEST",
7+
"ent-items": {
8+
"Entry-list": [
9+
{
10+
"action": "permit",
11+
"criteria": "inexact",
12+
"fromPfxLen": 24,
13+
"order": 10,
14+
"pfx": "10.0.0.0/8",
15+
"toPfxLen": 24
16+
}
17+
]
18+
}
19+
}
20+
]
21+
}
22+
}
23+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ip prefix-list TEST seq 10 permit 10.0.0.0/8 eq 24

0 commit comments

Comments
 (0)