Skip to content

Commit 02229ab

Browse files
[NX-OS] Implement support for RoutedVLAN interfaces on Cisco NX-OS
1 parent fe8e28c commit 02229ab

File tree

4 files changed

+86
-4
lines changed

4 files changed

+86
-4
lines changed

internal/provider/cisco/nxos/intf.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ var (
2525
_ gnmiext.Defaultable = (*SpanningTree)(nil)
2626
_ gnmiext.Configurable = (*PortChannel)(nil)
2727
_ gnmiext.Configurable = (*PortChannelOperItems)(nil)
28+
_ gnmiext.Configurable = (*SwitchVirtualInterface)(nil)
29+
_ gnmiext.Configurable = (*SwitchVirtualInterfaceOperItems)(nil)
2830
_ gnmiext.Configurable = (*AddrItem)(nil)
2931
)
3032

@@ -190,6 +192,33 @@ func (p *PortChannelOperItems) XPath() string {
190192
return "System/intf-items/aggr-items/AggrIf-list[id=" + p.ID + "]/aggrif-items"
191193
}
192194

195+
type SwitchVirtualInterface struct {
196+
AdminSt AdminSt2 `json:"adminSt"`
197+
Descr string `json:"descr"`
198+
ID string `json:"id"`
199+
Medium SVIMedium `json:"medium"`
200+
MTU int32 `json:"mtu,omitempty"`
201+
RtvrfMbrItems *VrfMember `json:"rtvrfMbr-items,omitempty"`
202+
VlanID int16 `json:"vlanId"`
203+
}
204+
205+
func (*SwitchVirtualInterface) IsListItem() {}
206+
207+
func (s *SwitchVirtualInterface) XPath() string {
208+
return "System/intf-items/svi-items/If-list[id=" + s.ID + "]"
209+
}
210+
211+
type SwitchVirtualInterfaceOperItems struct {
212+
ID string `json:"-"`
213+
OperSt OperSt `json:"operSt"`
214+
}
215+
216+
func (*SwitchVirtualInterfaceOperItems) IsListItem() {}
217+
218+
func (s *SwitchVirtualInterfaceOperItems) XPath() string {
219+
return "System/intf-items/svi-items/If-list[id=" + s.ID + "]"
220+
}
221+
193222
// AddrItem represents the IP address configuration for an interface.
194223
// It can hold either IPv4 or IPv6 addresses, determined by the Is6 field.
195224
type AddrItem struct {
@@ -332,6 +361,13 @@ const (
332361
MediumPointToPoint Medium = "p2p"
333362
)
334363

364+
type SVIMedium string
365+
366+
const (
367+
SVIMediumBroadcast SVIMedium = "bcast"
368+
SVIMediumPointToPoint SVIMedium = "p2p"
369+
)
370+
335371
type SwitchportMode string
336372

337373
const (

internal/provider/cisco/nxos/provider.go

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,29 @@ func (p *Provider) EnsureInterface(ctx context.Context, req *provider.InterfaceR
614614

615615
conf = append(conf, pc)
616616

617+
case v1alpha1.InterfaceTypeRoutedVLAN:
618+
f := new(Feature)
619+
f.Name = "ifvlan"
620+
f.AdminSt = AdminStEnabled
621+
conf = append(conf, f)
622+
623+
svi := new(SwitchVirtualInterface)
624+
svi.ID = name
625+
svi.Descr = req.Interface.Spec.Description
626+
svi.AdminSt = AdminStDown
627+
if req.Interface.Spec.AdminState == v1alpha1.AdminStateUp {
628+
svi.AdminSt = AdminStUp
629+
}
630+
svi.Medium = SVIMediumBroadcast
631+
svi.MTU = DefaultMTU
632+
if req.Interface.Spec.MTU != 0 {
633+
svi.MTU = req.Interface.Spec.MTU
634+
}
635+
svi.VlanID = req.VLAN.Spec.ID
636+
svi.RtvrfMbrItems = NewVrfMember(name, DefaultVRFName)
637+
638+
conf = append(conf, svi)
639+
617640
default:
618641
return fmt.Errorf("unsupported interface type: %s", req.Interface.Spec.Type)
619642
}
@@ -670,6 +693,11 @@ func (p *Provider) DeleteInterface(ctx context.Context, req *provider.InterfaceR
670693
conf = append(conf, vpc)
671694
}
672695

696+
case v1alpha1.InterfaceTypeRoutedVLAN:
697+
svi := new(SwitchVirtualInterface)
698+
svi.ID = name
699+
conf = append(conf, svi)
700+
673701
default:
674702
return fmt.Errorf("unsupported interface type: %s", req.Interface.Spec.Type)
675703
}
@@ -715,10 +743,7 @@ func (p *Provider) GetInterfaceStatus(ctx context.Context, req *provider.Interfa
715743
if err := p.client.GetState(ctx, svi); err != nil && !errors.Is(err, gnmiext.ErrNil) {
716744
return provider.InterfaceStatus{}, err
717745
}
718-
operSt = OperStDown
719-
if svi.OperAutoState {
720-
operSt = OperStUp
721-
}
746+
operSt = svi.OperSt
722747

723748
default:
724749
return provider.InterfaceStatus{}, fmt.Errorf("unsupported interface type: %s", req.Interface.Spec.Type)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"intf-items": {
3+
"svi-items": {
4+
"If-list": [
5+
{
6+
"adminSt": "up",
7+
"descr": "Foo",
8+
"id": "vlan10",
9+
"medium": "bcast",
10+
"mtu": 1500,
11+
"vlanId": 10
12+
}
13+
]
14+
}
15+
}
16+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
interface Vlan10
2+
no shutdown
3+
mtu 1500
4+
description Foo
5+
medium broadcast

0 commit comments

Comments
 (0)