[ 
https://issues.apache.org/jira/browse/VCL-909?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14969759#comment-14969759
 ] 

Andy Kurth commented on VCL-909:
--------------------------------

Are you certain get_random_mac_address() selected the same MACs?  It gets 
called from libvirt.pm without any arguments, meaning it generates a MAC 
starting with '52:54' and randomly selects the last 4 octets.

Perl's _rand_ function isn't perfect, but there are still 4,294,967,296 (256 ^ 
4) combinations.  I ran a test where I called get_random_mac_address() until a 
duplicate occurred, and repeated this 100 times:

{code}
ROUND: for (my $round=1; $round<=100; $round++) {
        my $macs = {};
        my $iteration = 0;
        while(1) {
                $iteration++;
                my $mac = get_random_mac_address();
                if (defined($macs->{$mac})) {
                        print "duplicate found on iteration $iteration\n";
                        next ROUND;
                }
                else {
                        $macs->{$mac} = $iteration;
                }
        }
}
{code}

On average, it took 82,063 iterations before a duplicate MAC address was 
selected.

> get_random_mac_address in utils.pm may generate the same mac for VMs
> --------------------------------------------------------------------
>
>                 Key: VCL-909
>                 URL: https://issues.apache.org/jira/browse/VCL-909
>             Project: VCL
>          Issue Type: Bug
>          Components: vcld (backend)
>    Affects Versions: 2.4.2
>            Reporter: Xianqing Yu
>
> We use get_random_mac_address() in libvirt.pm to generate random mac address 
> for VMs. However, we observe some of our reservations failed because some of 
> VMs have exactly the same mac (for both eth0 and eth1). Since reservations 
> are made by multiple users simultaneously, current design of 
> get_random_mac_address may return the same mac to multiple requests. 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to