@@ -38,7 +38,6 @@ use omicron_common::api::external::Vni;
3838use omicron_common:: api:: internal:: shared:: NetworkInterface ;
3939use omicron_common:: api:: internal:: shared:: NetworkInterfaceKind ;
4040use rand:: rngs:: StdRng ;
41- use rand:: RngCore ;
4241use rand:: SeedableRng ;
4342use slog:: o;
4443use slog:: Logger ;
@@ -50,6 +49,7 @@ use std::net::Ipv4Addr;
5049use std:: net:: Ipv6Addr ;
5150use std:: net:: SocketAddrV6 ;
5251use thiserror:: Error ;
52+ use typed_rng:: UuidRng ;
5353use uuid:: Uuid ;
5454
5555/// Errors encountered while assembling blueprints
@@ -223,7 +223,7 @@ impl<'a> BlueprintBuilder<'a> {
223223 } )
224224 . collect :: < Result < _ , Error > > ( ) ?;
225225 Ok ( Blueprint {
226- id : rng. blueprint_rng . next_uuid ( ) ,
226+ id : rng. blueprint_rng . next ( ) ,
227227 blueprint_zones,
228228 parent_blueprint_id : None ,
229229 internal_dns_version,
@@ -375,7 +375,7 @@ impl<'a> BlueprintBuilder<'a> {
375375 let blueprint_zones =
376376 self . zones . into_zones_map ( self . policy . sleds . keys ( ) . copied ( ) ) ;
377377 Blueprint {
378- id : self . rng . blueprint_rng . next_uuid ( ) ,
378+ id : self . rng . blueprint_rng . next ( ) ,
379379 blueprint_zones,
380380 parent_blueprint_id : Some ( self . parent_blueprint . id ) ,
381381 internal_dns_version : self . internal_dns_version ,
@@ -452,7 +452,7 @@ impl<'a> BlueprintBuilder<'a> {
452452 . collect ( ) ;
453453
454454 let zone = OmicronZoneConfig {
455- id : self . rng . zone_rng . next_uuid ( ) ,
455+ id : self . rng . zone_rng . next ( ) ,
456456 underlay_address : ip,
457457 zone_type : OmicronZoneType :: InternalNtp {
458458 address : ntp_address. to_string ( ) ,
@@ -502,7 +502,7 @@ impl<'a> BlueprintBuilder<'a> {
502502 let port = omicron_common:: address:: CRUCIBLE_PORT ;
503503 let address = SocketAddrV6 :: new ( ip, port, 0 , 0 ) . to_string ( ) ;
504504 let zone = OmicronZoneConfig {
505- id : self . rng . zone_rng . next_uuid ( ) ,
505+ id : self . rng . zone_rng . next ( ) ,
506506 underlay_address : ip,
507507 zone_type : OmicronZoneType :: Crucible {
508508 address,
@@ -589,7 +589,7 @@ impl<'a> BlueprintBuilder<'a> {
589589 } ;
590590
591591 for _ in 0 ..num_nexus_to_add {
592- let nexus_id = self . rng . zone_rng . next_uuid ( ) ;
592+ let nexus_id = self . rng . zone_rng . next ( ) ;
593593 let external_ip = self
594594 . available_external_ips
595595 . next ( )
@@ -617,7 +617,7 @@ impl<'a> BlueprintBuilder<'a> {
617617 . next ( )
618618 . ok_or ( Error :: NoSystemMacAddressAvailable ) ?;
619619 NetworkInterface {
620- id : self . rng . network_interface_rng . next_uuid ( ) ,
620+ id : self . rng . network_interface_rng . next ( ) ,
621621 kind : NetworkInterfaceKind :: Service { id : nexus_id } ,
622622 name : format ! ( "nexus-{nexus_id}" ) . parse ( ) . unwrap ( ) ,
623623 ip,
@@ -739,14 +739,14 @@ struct BlueprintBuilderRng {
739739
740740impl BlueprintBuilderRng {
741741 fn new ( ) -> Self {
742- Self :: new_from_rng ( StdRng :: from_entropy ( ) )
742+ Self :: new_from_parent ( StdRng :: from_entropy ( ) )
743743 }
744744
745- fn new_from_rng ( mut root_rng : StdRng ) -> Self {
746- let blueprint_rng = UuidRng :: from_root_rng ( & mut root_rng , "blueprint" ) ;
747- let zone_rng = UuidRng :: from_root_rng ( & mut root_rng , "zone" ) ;
745+ fn new_from_parent ( mut parent : StdRng ) -> Self {
746+ let blueprint_rng = UuidRng :: from_parent_rng ( & mut parent , "blueprint" ) ;
747+ let zone_rng = UuidRng :: from_parent_rng ( & mut parent , "zone" ) ;
748748 let network_interface_rng =
749- UuidRng :: from_root_rng ( & mut root_rng , "network_interface" ) ;
749+ UuidRng :: from_parent_rng ( & mut parent , "network_interface" ) ;
750750
751751 BlueprintBuilderRng { blueprint_rng, zone_rng, network_interface_rng }
752752 }
@@ -755,40 +755,7 @@ impl BlueprintBuilderRng {
755755 // Important to add some more bytes here, so that builders with the
756756 // same seed but different purposes don't end up with the same UUIDs.
757757 const SEED_EXTRA : & str = "blueprint-builder" ;
758- let mut seeder = rand_seeder:: Seeder :: from ( ( seed, SEED_EXTRA ) ) ;
759- * self = Self :: new_from_rng ( seeder. make_rng :: < StdRng > ( ) ) ;
760- }
761- }
762-
763- #[ derive( Debug ) ]
764- pub ( crate ) struct UuidRng {
765- rng : StdRng ,
766- }
767-
768- impl UuidRng {
769- /// Returns a new `UuidRng` generated from the root RNG.
770- ///
771- /// `extra` is a string that should be unique to the purpose of the UUIDs.
772- fn from_root_rng ( root_rng : & mut StdRng , extra : & ' static str ) -> Self {
773- let seed = root_rng. next_u64 ( ) ;
774- let mut seeder = rand_seeder:: Seeder :: from ( ( seed, extra) ) ;
775- Self { rng : seeder. make_rng :: < StdRng > ( ) }
776- }
777-
778- /// `extra` is a string that should be unique to the purpose of the UUIDs.
779- pub ( crate ) fn from_seed < H : Hash > ( seed : H , extra : & ' static str ) -> Self {
780- let mut seeder = rand_seeder:: Seeder :: from ( ( seed, extra) ) ;
781- Self { rng : seeder. make_rng :: < StdRng > ( ) }
782- }
783-
784- /// Returns a new UUIDv4 generated from the RNG.
785- pub ( crate ) fn next_uuid ( & mut self ) -> Uuid {
786- let mut bytes = [ 0 ; 16 ] ;
787- self . rng . fill_bytes ( & mut bytes) ;
788- // Builder::from_random_bytes will turn the random bytes into a valid
789- // UUIDv4. (Parts of the system depend on the UUID actually being valid
790- // v4, so it's important that we don't just use `uuid::from_bytes`.)
791- uuid:: Builder :: from_random_bytes ( bytes) . into_uuid ( )
758+ * self = Self :: new_from_parent ( typed_rng:: from_seed ( seed, SEED_EXTRA ) ) ;
792759 }
793760}
794761
@@ -1013,7 +980,7 @@ pub mod test {
1013980 assert_eq ! ( diff. sleds_changed( ) . count( ) , 0 ) ;
1014981
1015982 // The next step is adding these zones to a new sled.
1016- let new_sled_id = example. sled_rng . next_uuid ( ) ;
983+ let new_sled_id = example. sled_rng . next ( ) ;
1017984 let _ =
1018985 example. system . sled ( SledBuilder :: new ( ) . id ( new_sled_id) ) . unwrap ( ) ;
1019986 let policy = example. system . to_policy ( ) . unwrap ( ) ;
0 commit comments