-
Notifications
You must be signed in to change notification settings - Fork 1.3k
MAC address assignment improvements #12349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.20
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
e155985 to
3672fcd
Compare
|
@blueorangutan package |
|
@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. |
3672fcd to
9f95521
Compare
9f95521 to
3b53055
Compare
|
@blueorangutan package |
|
@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. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 16198 |
|
@blueorangutan test |
|
@sureshanaparti a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
There was a problem hiding this 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.identifierconfiguration 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.
server/src/main/java/com/cloud/network/router/NicProfileHelperImpl.java
Outdated
Show resolved
Hide resolved
server/src/main/java/com/cloud/network/guru/PodBasedNetworkGuru.java
Outdated
Show resolved
Hide resolved
server/src/main/java/com/cloud/network/guru/PrivateNetworkGuru.java
Outdated
Show resolved
Hide resolved
| */ | ||
|
|
||
| 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; |
Copilot
AI
Dec 30, 2025
There was a problem hiding this comment.
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).
| 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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
server/src/main/java/com/cloud/network/guru/StorageNetworkGuru.java
Outdated
Show resolved
Hide resolved
engine/schema/src/main/java/com/cloud/network/dao/NetworkDaoImpl.java
Outdated
Show resolved
Hide resolved
server/src/main/java/com/cloud/network/router/NicProfileHelperImpl.java
Outdated
Show resolved
Hide resolved
|
@blueorangutan package |
|
@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. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 16203 |
DaanHoogland
left a comment
There was a problem hiding this 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.
| default boolean isMACUnique(String mac, long networkId) { | ||
| return true; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this default implementation?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
| 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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Description
This PR has the following improvements for the MAC address assignment.
cloudstack/api/src/main/java/com/cloud/network/NetworkModel.java
Lines 94 to 95 in 56a39e6
[1]
https://github.com/apache/cloudstack/blob/4.20/utils/src/main/java/com/cloud/utils/net/NetUtils.java#L134-L145
[2]
https://github.com/apache/cloudstack/blob/4.20/engine/schema/src/main/java/com/cloud/network/dao/NetworkDaoImpl.java#L432-L439
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?
How did you try to break this feature and the system with this change?