Skip to content

Commit 046350c

Browse files
fix(iosxr): correct interface mode handling and nil pointer checks
- Set interface mode to virtual for Bundle-Ether interfaces to ensure bundlemgr can find them - Fix mode configuration for subinterfaces (use ModeNoPhysical instead of Mode) - Add nil pointer checks for VRF and address families to prevent panics - Correct XPath queries by removing leading slash for proper YANG path resolution - Handle admin state (shutdown) configuration for all interface types Signed-off-by: Sven Rosenzweig <sven.rosenzweig@sap.com>
1 parent eb056e0 commit 046350c

7 files changed

Lines changed: 187 additions & 170 deletions

File tree

‎internal/provider/cisco/iosxr/intf.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,15 @@ type Iface struct {
8484
IPv6Neighbor IPv6Neighbor `json:"Cisco-IOS-XR-ipv6-nd-cfg:ipv6-neighbor,omitzero"`
8585
Shutdown gnmiext.Empty `json:"shutdown,omitzero"`
8686

87+
// Required for subinterfaces
8788
// Existence of this object causes the creation of the software subinterface
8889
ModeNoPhysical string `json:"interface-mode-non-physical,omitzero"`
8990

9091
// BundleMember configuration for Physical interface as member of a Bundle-Ether
9192
BundleMember BundleMember `json:"Cisco-IOS-XR-bundlemgr-cfg:bundle-member,omitzero"`
9293

93-
// Mode in which an interface is running (e.g., virtual for subinterfaces)
94+
// Required for bundle-interfaces
95+
// Existence of this object causes the creation of the interface within the bundlemgr database
9496
Mode gnmiext.Empty `json:"interface-virtual,omitzero"`
9597
Bundle Bundle `json:"Cisco-IOS-XR-bundlemgr-cfg:bundle,omitzero"`
9698
SubInterface VlanSubInterface `json:"Cisco-IOS-XR-l2-eth-infra-cfg:vlan-sub-configuration,omitzero"`

‎internal/provider/cisco/iosxr/provider.go‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,16 @@ func (p *Provider) EnsureInterface(ctx context.Context, req *provider.EnsureInte
220220
}
221221

222222
iface := Iface{
223-
Name: name,
224-
Description: req.Interface.Spec.Description,
225-
Active: "act",
226-
ModeNoPhysical: "default",
227-
Mode: gnmiext.Empty(false),
223+
Name: name,
224+
Description: req.Interface.Spec.Description,
225+
Active: "act",
226+
// Without this, bundlemgr cannot find the Bundle-Ether interface in its database
227+
Mode: gnmiext.Empty(true),
228+
}
229+
230+
iface.Shutdown = gnmiext.Empty(false)
231+
if req.Interface.Spec.AdminState == v1alpha1.AdminStateDown {
232+
iface.Shutdown = gnmiext.Empty(true)
228233
}
229234

230235
bundleID, subinterfaceID, err := ExtractBundleAndSubinterfaceID(name)
@@ -256,15 +261,18 @@ func (p *Provider) EnsureInterface(ctx context.Context, req *provider.EnsureInte
256261
return updateInterface(ctx, p.client, conf...)
257262
case v1alpha1.InterfaceTypeSubinterface:
258263

259-
// Set Interface mode to virtual is required for bundle interfaces
260264
iface := Iface{
261265
Name: name,
262266
Description: req.Interface.Spec.Description,
263267
Active: "act",
264-
Mode: gnmiext.Empty(false),
265268
ModeNoPhysical: "default",
266269
}
267270

271+
iface.Shutdown = gnmiext.Empty(false)
272+
if req.Interface.Spec.AdminState == v1alpha1.AdminStateDown {
273+
iface.Shutdown = gnmiext.Empty(true)
274+
}
275+
268276
_, subinterfaceID, err := ExtractBundleAndSubinterfaceID(name)
269277
if err != nil {
270278
return err
@@ -294,7 +302,7 @@ func (p *Provider) EnsureInterface(ctx context.Context, req *provider.EnsureInte
294302
}
295303
iface.IPv4Network = ipv4
296304

297-
if req.VRF.Spec.Name != "" {
305+
if req.VRF != nil && req.VRF.Spec.Name != "" {
298306
iface.Vrf = req.VRF.Spec.Name
299307
}
300308

@@ -469,7 +477,7 @@ func (p *Provider) EnsureBGPPeer(ctx context.Context, req *provider.EnsureBGPPee
469477
RD: rd,
470478
}
471479

472-
if req.BGPPeer.Spec.AddressFamilies.Ipv6Unicast != nil || req.BGPPeer.Spec.AddressFamilies.L2vpnEvpn != nil {
480+
if req.BGPPeer.Spec.AddressFamilies != nil && (req.BGPPeer.Spec.AddressFamilies.Ipv6Unicast != nil || req.BGPPeer.Spec.AddressFamilies.L2vpnEvpn != nil) {
473481
return errors.New("bgp peer: ipv6 unicast or l2vpnEvpn address family is currently not supported")
474482
}
475483

‎internal/provider/cisco/iosxr/provider_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ func Register(name string, val gnmiext.DataElement) {
3434
}
3535

3636
func removeRootElement(xpath string) string {
37-
parts := strings.Split(xpath, "/")
37+
parts := strings.Split(xpath, ":")
3838
if len(parts) == 1 {
3939
return xpath
4040
}
41-
return strings.Join(parts[1:], "/")
41+
return parts[1]
4242
}
4343

4444
func Test_Payload(t *testing.T) {

‎internal/provider/cisco/iosxr/system.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type BasicDeviceInfo struct {
2727

2828
func (*BasicDeviceInfo) XPath() string {
2929
// Rack name defines the physical chassis, which is 0 for single-chassis devices.
30-
return "Cisco-IOS-XR-platform-inventory-oper:/platform-inventory/racks/rack[name=0]/attributes/basic-info"
30+
return "Cisco-IOS-XR-platform-inventory-oper:platform-inventory/racks/rack[name=0]/attributes/basic-info"
3131
}
3232

3333
type SystemTime struct {
@@ -52,7 +52,7 @@ type Clock struct {
5252
}
5353

5454
func (*SystemTime) XPath() string {
55-
return "Cisco-IOS-XR-shellutil-oper:/system-time"
55+
return "Cisco-IOS-XR-shellutil-oper:system-time"
5656
}
5757

5858
func (c *Clock) ConvertToTime() time.Time {

‎internal/provider/cisco/iosxr/testdata/bgppeer.json‎

Lines changed: 62 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,73 @@
11
{
2-
"bgp": {
3-
"instances": {
4-
"instance": {
5-
"as": {
6-
"vrfs": {
7-
"vrf": {
8-
"address-families": {
9-
"address-family": [
10-
{
11-
"af-name": "ipv4-unicast",
12-
"redistribute": {
13-
"static": {}
2+
"router": {
3+
"bgp": {
4+
"instances": {
5+
"instance": {
6+
"as": {
7+
"vrfs": {
8+
"vrf": {
9+
"address-families": {
10+
"address-family": [
11+
{
12+
"af-name": "ipv4-unicast",
13+
"redistribute": {
14+
"static": {}
15+
}
1416
}
17+
]
18+
},
19+
"vrf-name": "testvrf",
20+
"rd": {
21+
"two-byte-as": {
22+
"two-byte-as-number": 1000,
23+
"asn2-index": 100
1524
}
16-
]
17-
},
18-
"vrf-name": "testvrf",
19-
"rd": {
20-
"two-byte-as": {
21-
"two-byte-as-number": 1000,
22-
"asn2-index": 100
23-
}
24-
},
25-
"neighbors": {
26-
"neighbor": [
27-
{
28-
"address": "127.0.0.1",
29-
"address-families": {
30-
"address-family": [
31-
{
32-
"af-name": "ipv4-unicast",
33-
"maximum-prefix": {
34-
"maximum-prefix-number": 100,
35-
"restart": 15,
36-
"threshold-value": 80
37-
},
38-
"route-policy": {
39-
"in": "RPL_testvrf",
40-
"out": "RPL_testvrf"
41-
},
42-
"send-community-ebgp": {},
43-
"send-community-gshut-ebgp": {},
44-
"send-extended-community-ebgp": {},
45-
"soft-reconfiguration": {
46-
"inbound": {
47-
"always": [
48-
null
49-
]
25+
},
26+
"neighbors": {
27+
"neighbor": [
28+
{
29+
"address": "127.0.0.1",
30+
"address-families": {
31+
"address-family": [
32+
{
33+
"af-name": "ipv4-unicast",
34+
"maximum-prefix": {
35+
"maximum-prefix-number": 100,
36+
"restart": 15,
37+
"threshold-value": 80
38+
},
39+
"route-policy": {
40+
"in": "RPL_testvrf",
41+
"out": "RPL_testvrf"
42+
},
43+
"send-community-ebgp": {},
44+
"send-community-gshut-ebgp": {},
45+
"send-extended-community-ebgp": {},
46+
"soft-reconfiguration": {
47+
"inbound": {
48+
"always": [
49+
null
50+
]
51+
}
5052
}
5153
}
54+
]
55+
},
56+
"local-as": {
57+
"as": {
58+
"as-number": 65000,
59+
"no-prepend": {
60+
"replace-as": {}
61+
}
5262
}
53-
]
54-
},
55-
"local-as": {
56-
"as": {
57-
"as-number": 65000,
58-
"no-prepend": {
59-
"replace-as": {}
60-
}
63+
},
64+
"remote-as": 65001,
65+
"use": {
66+
"session-group": "EBGP-CUSTOMER-DEFAULTS"
6167
}
62-
},
63-
"remote-as": 65001,
64-
"use": {
65-
"session-group": "EBGP-CUSTOMER-DEFAULTS"
6668
}
67-
}
68-
]
69+
]
70+
}
6971
}
7072
}
7173
}
Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,50 @@
11
{
2-
"interface-configuration": {
3-
"interface-name": "TwentyFiveGigE0/0/0/14",
4-
"description": "random interface test",
5-
"Cisco-IOS-XR-infra-statsd-cfg:statistics": {
6-
"load-interval": 30
7-
},
8-
"mtus": {
9-
"mtu": [
10-
{
11-
"mtu": 9026,
12-
"owner": "TwentyFiveGigE"
13-
}
14-
]
15-
},
16-
"active": "act",
17-
"Cisco-IOS-XR-infra-rsi-cfg:vrf": "default",
18-
"Cisco-IOS-XR-ipv4-io-cfg:ipv4-network": {
19-
"addresses": {
20-
"primary": {
21-
"address": "192.168.1.2",
22-
"netmask": "255.255.255.0"
23-
}
2+
"interface-configurations": {
3+
"interface-configuration": {
4+
"interface-name": "TwentyFiveGigE0/0/0/14",
5+
"description": "random interface test",
6+
"Cisco-IOS-XR-infra-statsd-cfg:statistics": {
7+
"load-interval": 30
8+
},
9+
"mtus": {
10+
"mtu": [
11+
{
12+
"mtu": 9026,
13+
"owner": "TwentyFiveGigE"
14+
}
15+
]
2416
},
25-
"mtu": 1000
26-
},
27-
"Cisco-IOS-XR-ipv6-ma-cfg:ipv6-network": {
28-
"mtu": 2100,
29-
"addresses": {
30-
"regular-addresses": {
31-
"regular-address": [
32-
{
33-
"address": "2001:db8::1",
34-
"prefix-length": 64,
35-
"zone": ""
36-
}
37-
]
17+
"active": "act",
18+
"Cisco-IOS-XR-infra-rsi-cfg:vrf": "default",
19+
"Cisco-IOS-XR-ipv4-io-cfg:ipv4-network": {
20+
"addresses": {
21+
"primary": {
22+
"address": "192.168.1.2",
23+
"netmask": "255.255.255.0"
24+
}
25+
},
26+
"mtu": 1000
27+
},
28+
"Cisco-IOS-XR-ipv6-ma-cfg:ipv6-network": {
29+
"mtu": 2100,
30+
"addresses": {
31+
"regular-addresses": {
32+
"regular-address": [
33+
{
34+
"address": "2001:db8::1",
35+
"prefix-length": 64,
36+
"zone": ""
37+
}
38+
]
39+
}
3840
}
39-
}
40-
},
41-
"Cisco-IOS-XR-ipv6-nd-cfg:ipv6-neighbor": {
42-
"ra-suppress": true
43-
},
44-
45-
"shutdown": [null]
41+
},
42+
"Cisco-IOS-XR-ipv6-nd-cfg:ipv6-neighbor": {
43+
"ra-suppress": true
44+
},
45+
"shutdown": [
46+
null
47+
]
48+
}
4649
}
4750
}

0 commit comments

Comments
 (0)