Skip to content

Conversation

@sureshanaparti
Copy link
Contributor

@sureshanaparti sureshanaparti commented Dec 29, 2025

Description

This PR has the following improvements for the MAC address assignment.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

How did you try to break this feature and the system with this change?

@codecov
Copy link

codecov bot commented Dec 29, 2025

Codecov Report

❌ Patch coverage is 8.77193% with 52 lines in your changes missing coverage. Please review.
✅ Project coverage is 16.23%. Comparing base (56a39e6) to head (7188a62).

Files with missing lines Patch % Lines
.../main/java/com/cloud/network/NetworkModelImpl.java 0.00% 16 Missing ⚠️
...com/cloud/network/router/NicProfileHelperImpl.java 0.00% 8 Missing ⚠️
.../src/main/java/com/cloud/network/NetworkModel.java 0.00% 6 Missing ⚠️
...va/com/cloud/network/guru/PodBasedNetworkGuru.java 0.00% 4 Missing ⚠️
...ava/com/cloud/network/guru/PrivateNetworkGuru.java 0.00% 4 Missing ⚠️
...ava/com/cloud/network/guru/StorageNetworkGuru.java 0.00% 4 Missing ⚠️
...ain/java/com/cloud/network/dao/NetworkDaoImpl.java 0.00% 2 Missing ⚠️
...ema/src/main/java/com/cloud/vm/dao/NicDaoImpl.java 0.00% 2 Missing ⚠️
...n/java/com/cloud/network/IpAddressManagerImpl.java 0.00% 2 Missing ⚠️
...src/main/java/com/cloud/network/addr/PublicIp.java 75.00% 0 Missing and 1 partial ⚠️
... and 3 more
Additional details and impacted files
@@             Coverage Diff              @@
##               4.20   #12349      +/-   ##
============================================
- Coverage     16.23%   16.23%   -0.01%     
- Complexity    13378    13379       +1     
============================================
  Files          5657     5657              
  Lines        498866   498899      +33     
  Branches      60545    60553       +8     
============================================
+ Hits          81011    81013       +2     
- Misses       408821   408851      +30     
- Partials       9034     9035       +1     
Flag Coverage Δ
uitests 4.00% <ø> (ø)
unittests 17.09% <8.77%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sureshanaparti sureshanaparti force-pushed the mac-address-improvements branch from e155985 to 3672fcd Compare December 29, 2025 18:24
@sureshanaparti
Copy link
Contributor Author

@blueorangutan package

@blueorangutan
Copy link

@sureshanaparti a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@sureshanaparti sureshanaparti force-pushed the mac-address-improvements branch from 3672fcd to 9f95521 Compare December 29, 2025 19:04
@sureshanaparti sureshanaparti force-pushed the mac-address-improvements branch from 9f95521 to 3b53055 Compare December 29, 2025 19:33
@sureshanaparti
Copy link
Contributor Author

@blueorangutan package

@blueorangutan
Copy link

@sureshanaparti a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 16198

@sureshanaparti
Copy link
Contributor Author

@blueorangutan test

@blueorangutan
Copy link

@sureshanaparti a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves MAC address assignment by introducing zone-level MAC identifier configuration and scoping MAC address uniqueness checks to individual networks rather than globally.

Key changes:

  • Zone-level mac.identifier configuration is now retrieved from zone scope first, falling back to global scope, with the zone's database ID used when the value is 0
  • MAC address uniqueness is now checked within the scope of each network (not globally across all NICs)
  • MAC addresses generated via sequence-based logic are validated for uniqueness and regenerated using the fallback method if duplicates are detected

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
utils/src/main/java/com/cloud/utils/net/NetUtils.java Updated parameter name in createSequenceBasedMacAddress to macIdentifier and updated comment to reference zone-level config; fixed lowercase 'l' suffix to uppercase 'L'
api/src/main/java/com/cloud/network/NetworkModel.java Added isMACUnique and getMacIdentifier default methods to support network-scoped MAC uniqueness checks and zone-level MAC identifier retrieval
server/src/main/java/com/cloud/network/NetworkModelImpl.java Implemented getMacIdentifier to retrieve zone-level config and isMACUnique to check uniqueness within a network; updated getNextAvailableMacAddressInNetwork to use network-scoped uniqueness
engine/schema/src/main/java/com/cloud/vm/dao/NicDao.java Updated findByMacAddress signature to accept networkId parameter for network-scoped lookups
engine/schema/src/main/java/com/cloud/vm/dao/NicDaoImpl.java Implemented network-scoped MAC address lookup by adding networkId parameter to search criteria
engine/schema/src/main/java/com/cloud/network/dao/NetworkDaoImpl.java Code style improvements: changed .intValue() comparison to direct integer comparison and fixed uppercase 'L' suffix
server/src/main/java/com/cloud/network/guru/*.java Updated all network gurus (Storage, PodBased, Private, Direct) to use getMacIdentifier and validate/regenerate MAC addresses for uniqueness within the network
server/src/main/java/com/cloud/network/router/NicProfileHelper.java Added InsufficientAddressCapacityException to method signature
server/src/main/java/com/cloud/network/router/NicProfileHelperImpl.java Updated to use zone-level MAC identifier and validate/regenerate MAC addresses for private gateway NICs
server/src/main/java/com/cloud/network/IpAddressManagerImpl.java Added MAC uniqueness check before assigning MAC address to NICs
server/src/main/java/com/cloud/network/Ipv6AddressManagerImpl.java Added MAC uniqueness check in setNicPropertiesFromNetwork
engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java Added MAC uniqueness check in configureNicProfileBasedOnRequestedIp
engine/components-api/src/main/java/com/cloud/network/addr/PublicIp.java Updated createFromAddrAndVlan to use zone-level MAC identifier; removed trailing blank lines
server/src/test/java/com/cloud/network/Ipv6AddressManagerTest.java Updated test to mock network ID and MAC uniqueness check
engine/orchestration/src/test/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestratorTest.java Updated test to mock MAC uniqueness check

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

*/

return macAddress | prefix<<40 | globalConfig << 32 & 0x00ff00000000l | (long)s_rand.nextInt(255) << 24;
return macAddress | prefix << 40 | macIdentifier << 32 & 0x00ff00000000L | (long)s_rand.nextInt(255) << 24;
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The random number generation uses s_rand.nextInt(255) which generates values from 0 to 254 (exclusive upper bound). According to the comment on line 140, B3 should be "A randomly generated number between 0 - 255". To include 255, this should be s_rand.nextInt(256).

Suggested change
return macAddress | prefix << 40 | macIdentifier << 32 & 0x00ff00000000L | (long)s_rand.nextInt(255) << 24;
return macAddress | prefix << 40 | macIdentifier << 32 & 0x00ff00000000L | (long)s_rand.nextInt(256) << 24;

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

@sureshanaparti sureshanaparti Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weizhouapache @DaanHoogland can update this as per the comment here? previously, it used to generate till 254 only.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the previous programming has been either overly defensive or sloppy. But in general I’d rather see us iterate than randomly go through the range. After half is full the hit-and-miss rate becomes pretty high like this. Either way, it is functional as is, so address in another PR, i’d say.

@sureshanaparti
Copy link
Contributor Author

@blueorangutan package

@blueorangutan
Copy link

@sureshanaparti a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 16203

Copy link
Contributor

@DaanHoogland DaanHoogland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks generally good, two questions though.

Comment on lines +128 to +130
default boolean isMACUnique(String mac, long networkId) {
return true;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this default implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DaanHoogland there are some mock classes implementing it, not implemented it there (I think, we can return default true for them)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but it seems a logical error for anyone wanting to implement a new NetworkModel. They should be forced to implement it and not use this code by default.

Comment on lines +136 to +140
String macAddress = NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(result.getMacAddress(), _networkModel.getMacIdentifier(dest.getDataCenter().getId())));
if (!_networkModel.isMACUnique(macAddress, config.getId())) {
macAddress = _networkModel.getNextAvailableMacAddressInNetwork(config.getId());
}
nic.setMacAddress(macAddress);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern seems to be recurring (also in PrivateNetworkGuru, StorageNetworkGuru and NetProfileHelperImpl). Is it worth codifying it in a method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it's repeating. will check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants