Skip to content

[WIP]Support MAC_POOL allocation mode for SubnetPort#1356

Open
zhengxiexie wants to merge 1 commit intovmware-tanzu:mainfrom
zhengxiexie:topic/zhengxie/main/subnet_port_mac
Open

[WIP]Support MAC_POOL allocation mode for SubnetPort#1356
zhengxiexie wants to merge 1 commit intovmware-tanzu:mainfrom
zhengxiexie:topic/zhengxie/main/subnet_port_mac

Conversation

@zhengxiexie
Copy link
Contributor

@zhengxiexie zhengxiexie commented Jan 26, 2026

✨ What's Changed

SubnetPort MAC_POOL Support

  • Add support for allocating MAC addresses from NSX MAC Pool without specifying IP address in DHCP mode
  • Implement MAC_POOL allocation mode for DHCP-enabled subnets (DHCPServer/DHCPRelay)
  • Refactor allocateAddresses decision logic to distinguish DHCP mode from DHCPDeactivated mode
  • Follow Confluence specification for DHCPDeactivated+staticIPAllocation=false scenarios

Implementation Details

  • Modified pkg/nsx/services/subnetport/builder.go:
    • Added hasIPSpecified variable to determine if IP address is specified in addressBindings
    • Added isDHCPMode check to distinguish DHCP (DHCPServer/DHCPRelay) from DHCPDeactivated mode
    • Implemented comprehensive decision tree for allocateAddresses based on Subnet mode and user inputs
    • Added inline comments for each allocation scenario

🎯 Motivation

NSX supports allocating MAC addresses from MAC Pool independently, but nsx-operator's previous implementation always returned NONE for non-static IPAM modes, missing this capability in DHCP scenarios.

Issue: Users cannot leverage NSX MAC Pool to allocate MAC for DHCP-enabled ports without specifying MAC manually.

Solution: Implement proper MAC_POOL support for DHCP mode (DHCPServer/DHCPRelay) based on Subnet mode and user-provided addressBindings, following the Confluence specification.

Decision Tree

The implementation follows this allocation logic:

flowchart TD
    Start([SubnetPort Creation]) --> CheckMode{Subnet Mode?}
    
    CheckMode -->|Static IPAM<br/>staticIP=true| CheckIP1{IP Specified?}
    CheckMode -->|Non-Static IPAM<br/>staticIP=false| CheckDHCP{DHCP Mode?}
    
    %% Static IPAM Branch
    CheckIP1 -->|Yes| CheckMAC1{MAC Specified?}
    CheckIP1 -->|No| CheckMAC1b{MAC Specified?}
    
    CheckMAC1 -->|Yes| None1[allocateAddresses = NONE]
    CheckMAC1 -->|No| MacPool1[allocateAddresses = MAC_POOL ⭐]
    
    CheckMAC1b -->|Yes| IpPool[allocateAddresses = IP_POOL]
    CheckMAC1b -->|No| Both[allocateAddresses = BOTH]
    
    %% Non-Static IPAM Branch
    CheckDHCP -->|DHCPServer<br/>or DHCPRelay| CheckMAC2{MAC Specified?}
    CheckDHCP -->|DHCPDeactivated<br/>staticIP=false| None3[allocateAddresses = NONE]
    
    CheckMAC2 -->|Yes| None2[allocateAddresses = NONE]
    CheckMAC2 -->|No| MacPool2[allocateAddresses = MAC_POOL ⭐]
    
    None1 --> End([Create SubnetPort])
    MacPool1 --> End
    IpPool --> End
    Both --> End
    None2 --> End
    MacPool2 --> End
    None3 --> End
    
    style MacPool1 fill:#90EE90
    style MacPool2 fill:#90EE90
    style Start fill:#E6F3FF
    style End fill:#E6F3FF
    style None3 fill:#FFE6E6
Loading

Legend:

  • ⭐ = New functionality added in this PR
  • Green nodes = New MAC_POOL allocation scenarios
  • Red node = DHCPDeactivated+staticIP=false (no allocation per Confluence spec)

Allocation Matrix

Subnet Mode staticIPAllocation addressBindings allocateAddresses Notes
Static IPAM true IP + MAC NONE User provides both
Static IPAM true IP only MAC_POOL ⭐ NSX allocates MAC
Static IPAM true MAC only IP_POOL NSX allocates IP
Static IPAM true Neither BOTH NSX allocates both
DHCP Mode - MAC specified NONE DHCP allocates IP
DHCP Mode - No MAC MAC_POOL ⭐ DHCP allocates IP, NSX allocates MAC
DHCPDeactivated false Any NONE No allocation (per spec)

✅ Testing

Compilation Verification

  • ✅ Code compiles without errors
  • ✅ No breaking changes to existing logic

Manual Testing Required

  • Test Case 1: DHCP mode (DHCPServer) without MAC specified → Verify MAC allocated from MAC Pool
  • Test Case 2: DHCP mode (DHCPRelay) without MAC specified → Verify MAC allocated from MAC Pool
  • Test Case 3: DHCPDeactivated + staticIPAllocation=false → Verify no MAC allocation (NONE)
  • Test Case 4: Existing scenarios (Static IPAM variations) → Verify no regression

📋 Changes Summary

 pkg/nsx/services/subnetport/builder.go | 30 +++++++++++++++++++-------
 1 file changed, 25 insertions(+), 5 deletions(-)

🔄 Backward Compatibility

This change is fully backward compatible:

  • Existing SubnetPort resources will continue to work as before
  • Only DHCP mode scenarios (DHCPServer/DHCPRelay) without MAC specified will use MAC_POOL
  • DHCPDeactivated+staticIPAllocation=false behavior unchanged (NONE per Confluence spec)
  • No changes to CRD or API contract

@zhengxiexie zhengxiexie changed the title Support MAC_POOL allocation mode for SubnetPort [WIP]Support MAC_POOL allocation mode for SubnetPort Jan 26, 2026
### SubnetPort MAC_POOL Support
- Add support for allocating MAC addresses from NSX MAC Pool without specifying IP address in DHCP mode
- Implement `MAC_POOL` allocation mode for DHCP-enabled subnets (DHCPServer/DHCPRelay)
- Refactor `allocateAddresses` decision logic to distinguish DHCP mode from DHCPDeactivated mode
- Follow Confluence specification for DHCPDeactivated+staticIPAllocation=false scenarios

### Implementation Details
- Modified `pkg/nsx/services/subnetport/builder.go`:
  - Added `hasIPSpecified` variable to determine if IP address is specified in addressBindings
  - Added `isDHCPMode` check to distinguish DHCP (DHCPServer/DHCPRelay) from DHCPDeactivated mode
  - Implemented comprehensive decision tree for `allocateAddresses` based on Subnet mode and user inputs
  - Added inline comments for each allocation scenario

## 🎯 Motivation

NSX supports allocating MAC addresses from MAC Pool independently, but nsx-operator's previous implementation always returned `NONE` for non-static IPAM modes, missing this capability in DHCP scenarios.

**Issue**: Users cannot leverage NSX MAC Pool to allocate MAC for DHCP-enabled ports without specifying MAC manually.

**Solution**: Implement proper `MAC_POOL` support for DHCP mode (DHCPServer/DHCPRelay) based on Subnet mode and user-provided addressBindings, following the Confluence specification.

### Decision Tree

The implementation follows this allocation logic:

```mermaid
flowchart TD
    Start([SubnetPort Creation]) --> CheckMode{Subnet Mode?}

    CheckMode -->|Static IPAM<br/>staticIP=true| CheckIP1{IP Specified?}
    CheckMode -->|Non-Static IPAM<br/>staticIP=false| CheckDHCP{DHCP Mode?}

    %% Static IPAM Branch
    CheckIP1 -->|Yes| CheckMAC1{MAC Specified?}
    CheckIP1 -->|No| CheckMAC1b{MAC Specified?}

    CheckMAC1 -->|Yes| None1[allocateAddresses = NONE]
    CheckMAC1 -->|No| MacPool1[allocateAddresses = MAC_POOL ⭐]

    CheckMAC1b -->|Yes| IpPool[allocateAddresses = IP_POOL]
    CheckMAC1b -->|No| Both[allocateAddresses = BOTH]

    %% Non-Static IPAM Branch
    CheckDHCP -->|DHCPServer<br/>or DHCPRelay| CheckMAC2{MAC Specified?}
    CheckDHCP -->|DHCPDeactivated<br/>staticIP=false| None3[allocateAddresses = NONE]

    CheckMAC2 -->|Yes| None2[allocateAddresses = NONE]
    CheckMAC2 -->|No| MacPool2[allocateAddresses = MAC_POOL ⭐]

    None1 --> End([Create SubnetPort])
    MacPool1 --> End
    IpPool --> End
    Both --> End
    None2 --> End
    MacPool2 --> End
    None3 --> End

    style MacPool1 fill:#90EE90
    style MacPool2 fill:#90EE90
    style Start fill:#E6F3FF
    style End fill:#E6F3FF
    style None3 fill:#FFE6E6
```

**Legend**:
- ⭐ = New functionality added in this PR
- Green nodes = New MAC_POOL allocation scenarios
- Red node = DHCPDeactivated+staticIP=false (no allocation per Confluence spec)

### Allocation Matrix

| Subnet Mode | staticIPAllocation | addressBindings | allocateAddresses | Notes |
|-------------|-------------------|-----------------|-------------------|-------|
| **Static IPAM** | true | IP + MAC | NONE | User provides both |
| **Static IPAM** | true | IP only | MAC_POOL ⭐ | NSX allocates MAC |
| **Static IPAM** | true | MAC only | IP_POOL | NSX allocates IP |
| **Static IPAM** | true | Neither | BOTH | NSX allocates both |
| **DHCP Mode** | - | MAC specified | NONE | DHCP allocates IP |
| **DHCP Mode** | - | No MAC | MAC_POOL ⭐ | DHCP allocates IP, NSX allocates MAC |
| **DHCPDeactivated** | false | Any | NONE | No allocation (per spec) |

## ✅ Testing

### Compilation Verification
- ✅ Code compiles without errors
- ✅ No breaking changes to existing logic

### Manual Testing Required
- Test Case 1: DHCP mode (DHCPServer) without MAC specified → Verify MAC allocated from MAC Pool
- Test Case 2: DHCP mode (DHCPRelay) without MAC specified → Verify MAC allocated from MAC Pool
- Test Case 3: DHCPDeactivated + staticIPAllocation=false → Verify no MAC allocation (NONE)
- Test Case 4: Existing scenarios (Static IPAM variations) → Verify no regression

## 📋 Changes Summary

```
 pkg/nsx/services/subnetport/builder.go | 30 +++++++++++++++++++-------
 1 file changed, 25 insertions(+), 5 deletions(-)
```

## 🔄 Backward Compatibility

This change is fully backward compatible:
- Existing SubnetPort resources will continue to work as before
- Only DHCP mode scenarios (DHCPServer/DHCPRelay) without MAC specified will use MAC_POOL
- DHCPDeactivated+staticIPAllocation=false behavior unchanged (NONE per Confluence spec)
- No changes to CRD or API contract

## 📚 References

- Confluence Spec: https://vmw-confluence.broadcom.net/spaces/NSBU/pages/2282219328/SubnetPort+CR+spec+and+status
- Implementation strictly follows the specification for all subnet modes

Co-Authored-By: Warp <agent@warp.dev>
Change-Id: I34ceaf7c93861db5aa7a59da5c22bb1ae52f4403
@zhengxiexie zhengxiexie force-pushed the topic/zhengxie/main/subnet_port_mac branch from bd246bb to a0ae36e Compare January 26, 2026 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant