Matteo Scandolo | 90d08f6 | 2020-10-29 12:06:55 -0700 | [diff] [blame] | 1 | /* |
Joey Armstrong | 3881b73 | 2022-12-27 07:55:37 -0500 | [diff] [blame^] | 2 | * Copyright 2018-2023 Open Networking Foundation (ONF) and the ONF Contributors |
Matteo Scandolo | 90d08f6 | 2020-10-29 12:06:55 -0700 | [diff] [blame] | 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 | |
| 17 | package dhcp |
| 18 | |
| 19 | import ( |
| 20 | "gotest.tools/assert" |
| 21 | "net" |
| 22 | "testing" |
| 23 | ) |
| 24 | |
| 25 | func TestCreateIpFromMacAddress(t *testing.T) { |
| 26 | dhcpServer := NewDHCPServer() |
| 27 | |
| 28 | mac1 := net.HardwareAddr{0x2e, 0x60, 0x00, 0x0c, 0x0f, 0x02} |
| 29 | ip1 := dhcpServer.createIpFromMacAddress(mac1) |
| 30 | assert.Equal(t, "10.12.15.2", ip1.String()) |
| 31 | |
| 32 | mac2 := net.HardwareAddr{0x2e, 0x60, 0x00, 0x00, 0x00, 0x00} |
| 33 | ip2 := dhcpServer.createIpFromMacAddress(mac2) |
| 34 | assert.Equal(t, "10.0.0.0", ip2.String()) |
| 35 | } |