samanwita pal | 18696f6 | 2015-07-17 13:15:43 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2014 Open Networking Laboratory |
| 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.dhcpserver; |
| 17 | |
| 18 | import org.onlab.packet.Ip4Address; |
| 19 | |
| 20 | import java.util.Date; |
| 21 | |
| 22 | /** |
| 23 | * Stores the MAC ID to IP Address mapping details. |
| 24 | */ |
| 25 | |
| 26 | // TODO Convert this into an immutable class using the builder pattern. |
| 27 | public class IPAssignment { |
| 28 | |
| 29 | private Ip4Address ipAddress; |
| 30 | |
| 31 | private Date timestamp; |
| 32 | |
| 33 | private long leasePeriod; |
| 34 | |
| 35 | private AssignmentStatus assignmentStatus; |
| 36 | |
| 37 | public enum AssignmentStatus { |
| 38 | Option_Requested, |
| 39 | Option_Assigned, |
| 40 | Option_Expired; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Default constructor for IPAssignment, where the timestamp is set to the current time. |
| 45 | */ |
| 46 | IPAssignment() { |
| 47 | timestamp = new Date(); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Constructor for IPAssignment, where the ipAddress, the lease period |
| 52 | * and assignment status is supplied. The timestamp is set to the current time. |
| 53 | * |
| 54 | * @param ipAddress |
| 55 | * @param leasePeriod |
| 56 | * @param assignmentStatus |
| 57 | */ |
| 58 | IPAssignment(Ip4Address ipAddress, long leasePeriod, AssignmentStatus assignmentStatus) { |
| 59 | this.ipAddress = ipAddress; |
| 60 | this.leasePeriod = leasePeriod; |
| 61 | this.assignmentStatus = assignmentStatus; |
| 62 | |
| 63 | this.timestamp = new Date(); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Sets the IP address for the IP assignment. |
| 68 | * |
| 69 | * @param ipaddress the assigned IP address |
| 70 | */ |
| 71 | public void setIpAddress(Ip4Address ipaddress) { |
| 72 | this.ipAddress = ipaddress; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Sets the Timestamp for the IP assignment when the assignment was made. |
| 77 | * |
| 78 | * @param timestamp timestamp when the assignment was made |
| 79 | */ |
| 80 | public void setTimestamp(Date timestamp) { |
| 81 | this.timestamp = timestamp; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Sets the assignment status for the IP assignment. |
| 86 | * |
| 87 | * @param assignmentStatus the assignment status |
| 88 | */ |
| 89 | public void setAssignmentStatus(AssignmentStatus assignmentStatus) { |
| 90 | this.assignmentStatus = assignmentStatus; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Sets the Lease period value when the argument supplied is in seconds. |
| 95 | * |
| 96 | * @param leasePeriod lease time in seconds |
| 97 | */ |
| 98 | public void setLeasePeriodinSeconds(long leasePeriod) { |
| 99 | this.leasePeriod = leasePeriod * 1000; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Sets the Lease period value when the argument supplied is in milliseconds. |
| 104 | * |
| 105 | * @param leasePeriod lease time in milliseconds |
| 106 | */ |
| 107 | public void setLeasePeriodinMilliseconds(long leasePeriod) { |
| 108 | this.leasePeriod = leasePeriod; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Returns the IP Address of the IP assignment. |
| 113 | * |
| 114 | * @return the IP address |
| 115 | */ |
| 116 | public Ip4Address getIpAddress() { |
| 117 | return this.ipAddress; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Returns the timestamp of the IP assignment. |
| 122 | * |
| 123 | * @return the timestamp |
| 124 | */ |
| 125 | public Date getTimestamp() { |
| 126 | return this.timestamp; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Returns the assignment status of the IP assignment. |
| 131 | * |
| 132 | * @return the assignment status |
| 133 | */ |
| 134 | public AssignmentStatus getAssignmentStatus() { |
| 135 | return this.assignmentStatus; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Returns the lease period of the IP assignment. |
| 140 | * |
| 141 | * @return the lease period |
| 142 | */ |
| 143 | public long getLeasePeriod() { |
| 144 | return this.leasePeriod; |
| 145 | } |
| 146 | } |