khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package common |
| 17 | |
| 18 | import ( |
| 19 | "fmt" |
| 20 | "math/rand" |
| 21 | "time" |
| 22 | ) |
| 23 | |
| 24 | //GetRandomSerialNumber returns a serial number formatted as "HOST:PORT" |
| 25 | func GetRandomSerialNumber() string { |
khenaidoo | 731697e | 2019-01-29 16:03:29 -0500 | [diff] [blame] | 26 | rand.Seed(time.Now().UnixNano()) |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 27 | return fmt.Sprintf("%d.%d.%d.%d:%d", |
| 28 | rand.Intn(255), |
| 29 | rand.Intn(255), |
| 30 | rand.Intn(255), |
| 31 | rand.Intn(255), |
| 32 | rand.Intn(9000)+1000, |
| 33 | ) |
| 34 | } |
| 35 | |
| 36 | //GetRandomMacAddress returns a random mac address |
| 37 | func GetRandomMacAddress() string { |
khenaidoo | 731697e | 2019-01-29 16:03:29 -0500 | [diff] [blame] | 38 | rand.Seed(time.Now().UnixNano()) |
khenaidoo | d2b6df9 | 2018-12-13 16:37:20 -0500 | [diff] [blame] | 39 | return fmt.Sprintf("%02x:%02x:%02x:%02x:%02x:%02x", |
| 40 | rand.Intn(128), |
| 41 | rand.Intn(128), |
| 42 | rand.Intn(128), |
| 43 | rand.Intn(128), |
| 44 | rand.Intn(128), |
| 45 | rand.Intn(128), |
| 46 | ) |
| 47 | } |