samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 54dc352 | 2015-09-09 00:11:45 -0700 | [diff] [blame] | 2 | * Copyright 2015 Open Networking Laboratory |
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 | |
| 24 | /** |
| 25 | * DHCPStore Interface. |
| 26 | */ |
Thomas Vachuska | a1da42e | 2015-09-09 00:45:22 -0700 | [diff] [blame] | 27 | public interface DhcpStore { |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * Appends all the IPs in a given range to the free pool of IPs. |
| 31 | * |
| 32 | * @param startIP Start IP for the range |
| 33 | * @param endIP End IP for the range |
| 34 | */ |
| 35 | void populateIPPoolfromRange(Ip4Address startIP, Ip4Address endIP); |
| 36 | |
| 37 | /** |
| 38 | * Returns an IP Address for a Mac ID, in response to a DHCP DISCOVER message. |
| 39 | * |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 40 | * @param hostId Host ID of the client requesting an IP |
Ray Milkey | 9b36d81 | 2015-09-09 15:24:54 -0700 | [diff] [blame] | 41 | * @param requestedIP requested IP address |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 42 | * @return IP address assigned to the Mac ID |
| 43 | */ |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 44 | Ip4Address suggestIP(HostId hostId, Ip4Address requestedIP); |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 45 | |
| 46 | /** |
| 47 | * Assigns the requested IP to the Mac ID, in response to a DHCP REQUEST message. |
| 48 | * |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 49 | * @param hostId Host Id of the client requesting an IP |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 50 | * @param ipAddr IP Address being requested |
| 51 | * @param leaseTime Lease time offered by the server for this mapping |
| 52 | * @return returns true if the assignment was successful, false otherwise |
| 53 | */ |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 54 | boolean assignIP(HostId hostId, Ip4Address ipAddr, int leaseTime); |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * Sets the default time for which suggested IP mappings are valid. |
| 58 | * |
| 59 | * @param timeInSeconds default time for IP mappings to be valid |
| 60 | */ |
| 61 | void setDefaultTimeoutForPurge(int timeInSeconds); |
| 62 | |
| 63 | /** |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 64 | * Releases the IP assigned to a Mac ID into the free pool. |
| 65 | * |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 66 | * @param hostId the host ID for which the mapping needs to be changed |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 67 | */ |
samanwita pal | c40e5ed | 2015-09-24 11:01:51 -0700 | [diff] [blame] | 68 | Ip4Address releaseIP(HostId hostId); |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 69 | |
| 70 | /** |
samanwita pal | 0bff430 | 2015-09-15 13:37:00 -0700 | [diff] [blame] | 71 | * Returns a collection of all the MacAddress to IPAddress mapping assigned to the hosts. |
| 72 | * |
| 73 | * @return the collection of the mappings |
| 74 | */ |
| 75 | Map<HostId, IpAssignment> listAssignedMapping(); |
| 76 | |
| 77 | /** |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 78 | * Returns a collection of all the MacAddress to IPAddress mapping. |
| 79 | * |
| 80 | * @return the collection of the mappings |
| 81 | */ |
samanwita pal | 0bff430 | 2015-09-15 13:37:00 -0700 | [diff] [blame] | 82 | Map<HostId, IpAssignment> listAllMapping(); |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 83 | |
| 84 | /** |
| 85 | * Assigns the requested IP to the MAC ID (if available) for an indefinite period of time. |
| 86 | * |
| 87 | * @param macID macID of the client |
| 88 | * @param ipAddr IP Address requested for the client |
| 89 | * @return true if the mapping was successfully registered, false otherwise |
| 90 | */ |
| 91 | boolean assignStaticIP(MacAddress macID, Ip4Address ipAddr); |
| 92 | |
| 93 | /** |
| 94 | * Removes a static IP mapping associated with the given MAC ID from the DHCP Server. |
| 95 | * |
| 96 | * @param macID macID of the client |
| 97 | * @return true if the mapping was successfully registered, false otherwise |
| 98 | */ |
| 99 | boolean removeStaticIP(MacAddress macID); |
| 100 | |
| 101 | /** |
| 102 | * Returns the list of all the available IPs with the server. |
| 103 | * |
| 104 | * @return list of available IPs |
| 105 | */ |
| 106 | Iterable<Ip4Address> getAvailableIPs(); |
| 107 | |
| 108 | } |