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