samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
samanwita pal | f28207b | 2015-09-04 10:41:56 -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 | package org.onosproject.dhcp; |
| 17 | |
| 18 | import org.onlab.packet.Ip4Address; |
| 19 | import org.onlab.packet.MacAddress; |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 20 | import org.onosproject.net.HostId; |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 21 | |
| 22 | import java.util.Map; |
| 23 | |
daniel | cd9deed | 2015-10-30 17:16:16 +0900 | [diff] [blame] | 24 | |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 25 | /** |
| 26 | * DHCPStore Interface. |
| 27 | */ |
Thomas Vachuska | a1da42e | 2015-09-09 00:45:22 -0700 | [diff] [blame] | 28 | public interface DhcpStore { |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * Appends all the IPs in a given range to the free pool of IPs. |
| 32 | * |
| 33 | * @param startIP Start IP for the range |
| 34 | * @param endIP End IP for the range |
| 35 | */ |
| 36 | void populateIPPoolfromRange(Ip4Address startIP, Ip4Address endIP); |
| 37 | |
| 38 | /** |
| 39 | * Returns an IP Address for a Mac ID, in response to a DHCP DISCOVER message. |
| 40 | * |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 41 | * @param hostId Host ID of the client requesting an IP |
Ray Milkey | 9b36d81 | 2015-09-09 15:24:54 -0700 | [diff] [blame] | 42 | * @param requestedIP requested IP address |
Hyunsun Moon | 04b1fe9 | 2016-05-18 21:28:06 -0700 | [diff] [blame] | 43 | * @return IP address assigned to the Mac address; null if no available IP |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 44 | */ |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 45 | Ip4Address suggestIP(HostId hostId, Ip4Address requestedIP); |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 46 | |
daniel | cd9deed | 2015-10-30 17:16:16 +0900 | [diff] [blame] | 47 | |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 48 | /** |
| 49 | * Assigns the requested IP to the Mac ID, in response to a DHCP REQUEST message. |
| 50 | * |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 51 | * @param hostId Host Id of the client requesting an IP |
Hyunsun Moon | 04b1fe9 | 2016-05-18 21:28:06 -0700 | [diff] [blame] | 52 | * @param ipAssignment ip assignment |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 53 | * @return returns true if the assignment was successful, false otherwise |
| 54 | */ |
Hyunsun Moon | 04b1fe9 | 2016-05-18 21:28:06 -0700 | [diff] [blame] | 55 | boolean assignIP(HostId hostId, IpAssignment ipAssignment); |
daniel | cd9deed | 2015-10-30 17:16:16 +0900 | [diff] [blame] | 56 | |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 57 | |
| 58 | /** |
| 59 | * Sets the default time for which suggested IP mappings are valid. |
| 60 | * |
| 61 | * @param timeInSeconds default time for IP mappings to be valid |
| 62 | */ |
| 63 | void setDefaultTimeoutForPurge(int timeInSeconds); |
| 64 | |
| 65 | /** |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 66 | * Releases the IP assigned to a Mac ID into the free pool. |
| 67 | * |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 68 | * @param hostId the host ID for which the mapping needs to be changed |
Brian O'Connor | 5251562 | 2015-10-09 17:03:44 -0700 | [diff] [blame] | 69 | * @return released ip |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 70 | */ |
samanwita pal | c40e5ed | 2015-09-24 11:01:51 -0700 | [diff] [blame] | 71 | Ip4Address releaseIP(HostId hostId); |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 72 | |
| 73 | /** |
samanwita pal | 0bff430 | 2015-09-15 13:37:00 -0700 | [diff] [blame] | 74 | * Returns a collection of all the MacAddress to IPAddress mapping assigned to the hosts. |
| 75 | * |
| 76 | * @return the collection of the mappings |
| 77 | */ |
| 78 | Map<HostId, IpAssignment> listAssignedMapping(); |
| 79 | |
| 80 | /** |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 81 | * Returns a collection of all the MacAddress to IPAddress mapping. |
| 82 | * |
| 83 | * @return the collection of the mappings |
| 84 | */ |
samanwita pal | 0bff430 | 2015-09-15 13:37:00 -0700 | [diff] [blame] | 85 | Map<HostId, IpAssignment> listAllMapping(); |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 86 | |
| 87 | /** |
| 88 | * Assigns the requested IP to the MAC ID (if available) for an indefinite period of time. |
| 89 | * |
Hyunsun Moon | 04b1fe9 | 2016-05-18 21:28:06 -0700 | [diff] [blame] | 90 | * @param macAddress mac address of the client |
| 91 | * @param ipAssignment ip address and dhcp options requested for the client |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 92 | * @return true if the mapping was successfully registered, false otherwise |
| 93 | */ |
Hyunsun Moon | 04b1fe9 | 2016-05-18 21:28:06 -0700 | [diff] [blame] | 94 | boolean assignStaticIP(MacAddress macAddress, IpAssignment ipAssignment); |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 95 | |
| 96 | /** |
| 97 | * Removes a static IP mapping associated with the given MAC ID from the DHCP Server. |
| 98 | * |
Hyunsun Moon | 04b1fe9 | 2016-05-18 21:28:06 -0700 | [diff] [blame] | 99 | * @param macAddress mac address of the client |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 100 | * @return true if the mapping was successfully registered, false otherwise |
| 101 | */ |
Hyunsun Moon | 04b1fe9 | 2016-05-18 21:28:06 -0700 | [diff] [blame] | 102 | boolean removeStaticIP(MacAddress macAddress); |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 103 | |
| 104 | /** |
| 105 | * Returns the list of all the available IPs with the server. |
| 106 | * |
| 107 | * @return list of available IPs |
| 108 | */ |
| 109 | Iterable<Ip4Address> getAvailableIPs(); |
| 110 | |
daniel | cd9deed | 2015-10-30 17:16:16 +0900 | [diff] [blame] | 111 | /** |
Jian Li | dfba739 | 2016-01-22 16:46:58 -0800 | [diff] [blame] | 112 | * Returns IpAssignment from map. |
daniel | cd9deed | 2015-10-30 17:16:16 +0900 | [diff] [blame] | 113 | * |
Jian Li | dfba739 | 2016-01-22 16:46:58 -0800 | [diff] [blame] | 114 | * @param hostId host identification |
| 115 | * @return IpAssignment |
daniel | cd9deed | 2015-10-30 17:16:16 +0900 | [diff] [blame] | 116 | */ |
| 117 | IpAssignment getIpAssignmentFromAllocationMap(HostId hostId); |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 118 | } |