Committed by
Gerrit Code Review
DHCP Config changes + null pointer checks + ONOS-2881
Change-Id: Ice391f539ae816329fde7970d762380a36fd7661
Showing
13 changed files
with
312 additions
and
369 deletions
... | @@ -17,6 +17,7 @@ package org.onosproject.dhcp; | ... | @@ -17,6 +17,7 @@ package org.onosproject.dhcp; |
17 | 17 | ||
18 | import org.onlab.packet.Ip4Address; | 18 | import org.onlab.packet.Ip4Address; |
19 | import org.onlab.packet.MacAddress; | 19 | import org.onlab.packet.MacAddress; |
20 | +import org.onosproject.net.HostId; | ||
20 | 21 | ||
21 | import java.util.Map; | 22 | import java.util.Map; |
22 | 23 | ||
... | @@ -30,7 +31,7 @@ public interface DhcpService { | ... | @@ -30,7 +31,7 @@ public interface DhcpService { |
30 | * | 31 | * |
31 | * @return collection of mappings. | 32 | * @return collection of mappings. |
32 | */ | 33 | */ |
33 | - Map<MacAddress, IpAssignment> listMapping(); | 34 | + Map<HostId, IpAssignment> listMapping(); |
34 | 35 | ||
35 | /** | 36 | /** |
36 | * Returns the default lease time granted by the DHCP Server. | 37 | * Returns the default lease time granted by the DHCP Server. | ... | ... |
... | @@ -17,6 +17,7 @@ package org.onosproject.dhcp; | ... | @@ -17,6 +17,7 @@ package org.onosproject.dhcp; |
17 | 17 | ||
18 | import org.onlab.packet.Ip4Address; | 18 | import org.onlab.packet.Ip4Address; |
19 | import org.onlab.packet.MacAddress; | 19 | import org.onlab.packet.MacAddress; |
20 | +import org.onosproject.net.HostId; | ||
20 | 21 | ||
21 | import java.util.Map; | 22 | import java.util.Map; |
22 | 23 | ||
... | @@ -36,21 +37,21 @@ public interface DhcpStore { | ... | @@ -36,21 +37,21 @@ public interface DhcpStore { |
36 | /** | 37 | /** |
37 | * Returns an IP Address for a Mac ID, in response to a DHCP DISCOVER message. | 38 | * Returns an IP Address for a Mac ID, in response to a DHCP DISCOVER message. |
38 | * | 39 | * |
39 | - * @param macID Mac ID of the client requesting an IP | 40 | + * @param hostId Host ID of the client requesting an IP |
40 | * @param requestedIP requested IP address | 41 | * @param requestedIP requested IP address |
41 | * @return IP address assigned to the Mac ID | 42 | * @return IP address assigned to the Mac ID |
42 | */ | 43 | */ |
43 | - Ip4Address suggestIP(MacAddress macID, Ip4Address requestedIP); | 44 | + Ip4Address suggestIP(HostId hostId, Ip4Address requestedIP); |
44 | 45 | ||
45 | /** | 46 | /** |
46 | * Assigns the requested IP to the Mac ID, in response to a DHCP REQUEST message. | 47 | * Assigns the requested IP to the Mac ID, in response to a DHCP REQUEST message. |
47 | * | 48 | * |
48 | - * @param macID Mac Id of the client requesting an IP | 49 | + * @param hostId Host Id of the client requesting an IP |
49 | * @param ipAddr IP Address being requested | 50 | * @param ipAddr IP Address being requested |
50 | * @param leaseTime Lease time offered by the server for this mapping | 51 | * @param leaseTime Lease time offered by the server for this mapping |
51 | * @return returns true if the assignment was successful, false otherwise | 52 | * @return returns true if the assignment was successful, false otherwise |
52 | */ | 53 | */ |
53 | - boolean assignIP(MacAddress macID, Ip4Address ipAddr, int leaseTime); | 54 | + boolean assignIP(HostId hostId, Ip4Address ipAddr, int leaseTime); |
54 | 55 | ||
55 | /** | 56 | /** |
56 | * Sets the default time for which suggested IP mappings are valid. | 57 | * Sets the default time for which suggested IP mappings are valid. |
... | @@ -60,25 +61,18 @@ public interface DhcpStore { | ... | @@ -60,25 +61,18 @@ public interface DhcpStore { |
60 | void setDefaultTimeoutForPurge(int timeInSeconds); | 61 | void setDefaultTimeoutForPurge(int timeInSeconds); |
61 | 62 | ||
62 | /** | 63 | /** |
63 | - * Sets the delay after which the dhcp server will purge expired entries. | ||
64 | - * | ||
65 | - * @param timeInSeconds default time | ||
66 | - */ | ||
67 | - void setTimerDelay(int timeInSeconds); | ||
68 | - | ||
69 | - /** | ||
70 | * Releases the IP assigned to a Mac ID into the free pool. | 64 | * Releases the IP assigned to a Mac ID into the free pool. |
71 | * | 65 | * |
72 | - * @param macID the macID for which the mapping needs to be changed | 66 | + * @param hostId the host ID for which the mapping needs to be changed |
73 | */ | 67 | */ |
74 | - void releaseIP(MacAddress macID); | 68 | + void releaseIP(HostId hostId); |
75 | 69 | ||
76 | /** | 70 | /** |
77 | * Returns a collection of all the MacAddress to IPAddress mapping. | 71 | * Returns a collection of all the MacAddress to IPAddress mapping. |
78 | * | 72 | * |
79 | * @return the collection of the mappings | 73 | * @return the collection of the mappings |
80 | */ | 74 | */ |
81 | - Map<MacAddress, IpAssignment> listMapping(); | 75 | + Map<HostId, IpAssignment> listMapping(); |
82 | 76 | ||
83 | /** | 77 | /** |
84 | * Assigns the requested IP to the MAC ID (if available) for an indefinite period of time. | 78 | * Assigns the requested IP to the MAC ID (if available) for an indefinite period of time. | ... | ... |
... | @@ -100,10 +100,19 @@ public final class IpAssignment { | ... | @@ -100,10 +100,19 @@ public final class IpAssignment { |
100 | /** | 100 | /** |
101 | * Returns the lease period of the IP assignment. | 101 | * Returns the lease period of the IP assignment. |
102 | * | 102 | * |
103 | - * @return the lease period | 103 | + * @return the lease period in seconds |
104 | */ | 104 | */ |
105 | public int leasePeriod() { | 105 | public int leasePeriod() { |
106 | - return (int) this.leasePeriod / 1000; | 106 | + return (int) this.leasePeriod; |
107 | + } | ||
108 | + | ||
109 | + /** | ||
110 | + * Returns the lease period of the IP assignment. | ||
111 | + * | ||
112 | + * @return the lease period in milliseconds | ||
113 | + */ | ||
114 | + public int leasePeriodMs() { | ||
115 | + return (int) this.leasePeriod * 1000; | ||
107 | } | 116 | } |
108 | 117 | ||
109 | @Override | 118 | @Override |
... | @@ -155,7 +164,7 @@ public final class IpAssignment { | ... | @@ -155,7 +164,7 @@ public final class IpAssignment { |
155 | private Builder(IpAssignment ipAssignment) { | 164 | private Builder(IpAssignment ipAssignment) { |
156 | ipAddress = ipAssignment.ipAddress(); | 165 | ipAddress = ipAssignment.ipAddress(); |
157 | timeStamp = ipAssignment.timestamp(); | 166 | timeStamp = ipAssignment.timestamp(); |
158 | - leasePeriod = ipAssignment.leasePeriod() * 1000; | 167 | + leasePeriod = ipAssignment.leasePeriod(); |
159 | assignmentStatus = ipAssignment.assignmentStatus(); | 168 | assignmentStatus = ipAssignment.assignmentStatus(); |
160 | } | 169 | } |
161 | 170 | ||
... | @@ -178,7 +187,7 @@ public final class IpAssignment { | ... | @@ -178,7 +187,7 @@ public final class IpAssignment { |
178 | } | 187 | } |
179 | 188 | ||
180 | public Builder leasePeriod(int leasePeriodinSeconds) { | 189 | public Builder leasePeriod(int leasePeriodinSeconds) { |
181 | - leasePeriod = leasePeriodinSeconds * 1000; | 190 | + leasePeriod = leasePeriodinSeconds; |
182 | return this; | 191 | return this; |
183 | } | 192 | } |
184 | 193 | ... | ... |
... | @@ -16,10 +16,10 @@ | ... | @@ -16,10 +16,10 @@ |
16 | package org.onosproject.dhcp.cli; | 16 | package org.onosproject.dhcp.cli; |
17 | 17 | ||
18 | import org.apache.karaf.shell.commands.Command; | 18 | import org.apache.karaf.shell.commands.Command; |
19 | -import org.onlab.packet.MacAddress; | ||
20 | import org.onosproject.cli.AbstractShellCommand; | 19 | import org.onosproject.cli.AbstractShellCommand; |
21 | import org.onosproject.dhcp.DhcpService; | 20 | import org.onosproject.dhcp.DhcpService; |
22 | import org.onosproject.dhcp.IpAssignment; | 21 | import org.onosproject.dhcp.IpAssignment; |
22 | +import org.onosproject.net.HostId; | ||
23 | 23 | ||
24 | import java.util.Map; | 24 | import java.util.Map; |
25 | 25 | ||
... | @@ -35,9 +35,9 @@ public class DhcpListAllMappings extends AbstractShellCommand { | ... | @@ -35,9 +35,9 @@ public class DhcpListAllMappings extends AbstractShellCommand { |
35 | protected void execute() { | 35 | protected void execute() { |
36 | 36 | ||
37 | DhcpService dhcpService = AbstractShellCommand.get(DhcpService.class); | 37 | DhcpService dhcpService = AbstractShellCommand.get(DhcpService.class); |
38 | - Map<MacAddress, IpAssignment> allocationMap = dhcpService.listMapping(); | 38 | + Map<HostId, IpAssignment> allocationMap = dhcpService.listMapping(); |
39 | 39 | ||
40 | - for (Map.Entry<MacAddress, IpAssignment> entry : allocationMap.entrySet()) { | 40 | + for (Map.Entry<HostId, IpAssignment> entry : allocationMap.entrySet()) { |
41 | print(DHCP_MAPPING_FORMAT, entry.getKey().toString(), entry.getValue().ipAddress().toString()); | 41 | print(DHCP_MAPPING_FORMAT, entry.getKey().toString(), entry.getValue().ipAddress().toString()); |
42 | } | 42 | } |
43 | } | 43 | } | ... | ... |
... | @@ -15,6 +15,8 @@ | ... | @@ -15,6 +15,8 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.dhcp.impl; | 16 | package org.onosproject.dhcp.impl; |
17 | 17 | ||
18 | +import org.onlab.packet.Ip4Address; | ||
19 | +import org.onlab.packet.MacAddress; | ||
18 | import org.onosproject.core.ApplicationId; | 20 | import org.onosproject.core.ApplicationId; |
19 | import org.onosproject.net.config.Config; | 21 | import org.onosproject.net.config.Config; |
20 | import org.onosproject.net.config.basics.BasicElementConfig; | 22 | import org.onosproject.net.config.basics.BasicElementConfig; |
... | @@ -34,14 +36,19 @@ public class DhcpConfig extends Config<ApplicationId> { | ... | @@ -34,14 +36,19 @@ public class DhcpConfig extends Config<ApplicationId> { |
34 | public static final String LEASE_TIME = "lease"; | 36 | public static final String LEASE_TIME = "lease"; |
35 | public static final String RENEW_TIME = "renew"; | 37 | public static final String RENEW_TIME = "renew"; |
36 | public static final String REBIND_TIME = "rebind"; | 38 | public static final String REBIND_TIME = "rebind"; |
39 | + public static final String TIMER_DELAY = "delay"; | ||
40 | + public static final String DEFAULT_TIMEOUT = "timeout"; | ||
41 | + public static final String START_IP = "startip"; | ||
42 | + public static final String END_IP = "endip"; | ||
37 | 43 | ||
38 | /** | 44 | /** |
39 | * Returns the dhcp server ip. | 45 | * Returns the dhcp server ip. |
40 | * | 46 | * |
41 | * @return ip address or null if not set | 47 | * @return ip address or null if not set |
42 | */ | 48 | */ |
43 | - public String ip() { | 49 | + public Ip4Address ip() { |
44 | - return get(MY_IP, null); | 50 | + String ip = get(MY_IP, null); |
51 | + return ip != null ? Ip4Address.valueOf(ip) : null; | ||
45 | } | 52 | } |
46 | 53 | ||
47 | /** | 54 | /** |
... | @@ -59,8 +66,9 @@ public class DhcpConfig extends Config<ApplicationId> { | ... | @@ -59,8 +66,9 @@ public class DhcpConfig extends Config<ApplicationId> { |
59 | * | 66 | * |
60 | * @return server mac or null if not set | 67 | * @return server mac or null if not set |
61 | */ | 68 | */ |
62 | - public String mac() { | 69 | + public MacAddress mac() { |
63 | - return get(MY_MAC, null); | 70 | + String mac = get(MY_MAC, null); |
71 | + return mac != null ? MacAddress.valueOf(mac) : null; | ||
64 | } | 72 | } |
65 | 73 | ||
66 | /** | 74 | /** |
... | @@ -78,8 +86,9 @@ public class DhcpConfig extends Config<ApplicationId> { | ... | @@ -78,8 +86,9 @@ public class DhcpConfig extends Config<ApplicationId> { |
78 | * | 86 | * |
79 | * @return subnet mask or null if not set | 87 | * @return subnet mask or null if not set |
80 | */ | 88 | */ |
81 | - public String subnetMask() { | 89 | + public Ip4Address subnetMask() { |
82 | - return get(SUBNET_MASK, null); | 90 | + String ip = get(SUBNET_MASK, null); |
91 | + return ip != null ? Ip4Address.valueOf(ip) : null; | ||
83 | } | 92 | } |
84 | 93 | ||
85 | /** | 94 | /** |
... | @@ -97,8 +106,9 @@ public class DhcpConfig extends Config<ApplicationId> { | ... | @@ -97,8 +106,9 @@ public class DhcpConfig extends Config<ApplicationId> { |
97 | * | 106 | * |
98 | * @return broadcast address or null if not set | 107 | * @return broadcast address or null if not set |
99 | */ | 108 | */ |
100 | - public String broadcastAddress() { | 109 | + public Ip4Address broadcastAddress() { |
101 | - return get(BROADCAST_ADDRESS, null); | 110 | + String ip = get(BROADCAST_ADDRESS, null); |
111 | + return ip != null ? Ip4Address.valueOf(ip) : null; | ||
102 | } | 112 | } |
103 | 113 | ||
104 | /** | 114 | /** |
... | @@ -116,8 +126,8 @@ public class DhcpConfig extends Config<ApplicationId> { | ... | @@ -116,8 +126,8 @@ public class DhcpConfig extends Config<ApplicationId> { |
116 | * | 126 | * |
117 | * @return ttl or null if not set | 127 | * @return ttl or null if not set |
118 | */ | 128 | */ |
119 | - public String ttl() { | 129 | + public int ttl() { |
120 | - return get(TTL, null); | 130 | + return get(TTL, 0); |
121 | } | 131 | } |
122 | 132 | ||
123 | /** | 133 | /** |
... | @@ -126,7 +136,7 @@ public class DhcpConfig extends Config<ApplicationId> { | ... | @@ -126,7 +136,7 @@ public class DhcpConfig extends Config<ApplicationId> { |
126 | * @param ttl new ttl; null to clear | 136 | * @param ttl new ttl; null to clear |
127 | * @return self | 137 | * @return self |
128 | */ | 138 | */ |
129 | - public BasicElementConfig ttl(String ttl) { | 139 | + public BasicElementConfig ttl(int ttl) { |
130 | return (BasicElementConfig) setOrClear(TTL, ttl); | 140 | return (BasicElementConfig) setOrClear(TTL, ttl); |
131 | } | 141 | } |
132 | 142 | ||
... | @@ -135,8 +145,8 @@ public class DhcpConfig extends Config<ApplicationId> { | ... | @@ -135,8 +145,8 @@ public class DhcpConfig extends Config<ApplicationId> { |
135 | * | 145 | * |
136 | * @return lease time or null if not set | 146 | * @return lease time or null if not set |
137 | */ | 147 | */ |
138 | - public String leaseTime() { | 148 | + public int leaseTime() { |
139 | - return get(LEASE_TIME, null); | 149 | + return get(LEASE_TIME, 0); |
140 | } | 150 | } |
141 | 151 | ||
142 | /** | 152 | /** |
... | @@ -145,7 +155,7 @@ public class DhcpConfig extends Config<ApplicationId> { | ... | @@ -145,7 +155,7 @@ public class DhcpConfig extends Config<ApplicationId> { |
145 | * @param lease new lease time; null to clear | 155 | * @param lease new lease time; null to clear |
146 | * @return self | 156 | * @return self |
147 | */ | 157 | */ |
148 | - public BasicElementConfig leaseTime(String lease) { | 158 | + public BasicElementConfig leaseTime(int lease) { |
149 | return (BasicElementConfig) setOrClear(LEASE_TIME, lease); | 159 | return (BasicElementConfig) setOrClear(LEASE_TIME, lease); |
150 | } | 160 | } |
151 | 161 | ||
... | @@ -154,8 +164,8 @@ public class DhcpConfig extends Config<ApplicationId> { | ... | @@ -154,8 +164,8 @@ public class DhcpConfig extends Config<ApplicationId> { |
154 | * | 164 | * |
155 | * @return renew time or null if not set | 165 | * @return renew time or null if not set |
156 | */ | 166 | */ |
157 | - public String renewTime() { | 167 | + public int renewTime() { |
158 | - return get(RENEW_TIME, null); | 168 | + return get(RENEW_TIME, 0); |
159 | } | 169 | } |
160 | 170 | ||
161 | /** | 171 | /** |
... | @@ -164,7 +174,7 @@ public class DhcpConfig extends Config<ApplicationId> { | ... | @@ -164,7 +174,7 @@ public class DhcpConfig extends Config<ApplicationId> { |
164 | * @param renew new renew time; null to clear | 174 | * @param renew new renew time; null to clear |
165 | * @return self | 175 | * @return self |
166 | */ | 176 | */ |
167 | - public BasicElementConfig renewTime(String renew) { | 177 | + public BasicElementConfig renewTime(int renew) { |
168 | return (BasicElementConfig) setOrClear(RENEW_TIME, renew); | 178 | return (BasicElementConfig) setOrClear(RENEW_TIME, renew); |
169 | } | 179 | } |
170 | 180 | ||
... | @@ -173,8 +183,8 @@ public class DhcpConfig extends Config<ApplicationId> { | ... | @@ -173,8 +183,8 @@ public class DhcpConfig extends Config<ApplicationId> { |
173 | * | 183 | * |
174 | * @return rebind time or null if not set | 184 | * @return rebind time or null if not set |
175 | */ | 185 | */ |
176 | - public String rebindTime() { | 186 | + public int rebindTime() { |
177 | - return get(REBIND_TIME, null); | 187 | + return get(REBIND_TIME, 0); |
178 | } | 188 | } |
179 | 189 | ||
180 | /** | 190 | /** |
... | @@ -183,7 +193,7 @@ public class DhcpConfig extends Config<ApplicationId> { | ... | @@ -183,7 +193,7 @@ public class DhcpConfig extends Config<ApplicationId> { |
183 | * @param rebind new rebind time; null to clear | 193 | * @param rebind new rebind time; null to clear |
184 | * @return self | 194 | * @return self |
185 | */ | 195 | */ |
186 | - public BasicElementConfig rebindTime(String rebind) { | 196 | + public BasicElementConfig rebindTime(int rebind) { |
187 | return (BasicElementConfig) setOrClear(REBIND_TIME, rebind); | 197 | return (BasicElementConfig) setOrClear(REBIND_TIME, rebind); |
188 | } | 198 | } |
189 | 199 | ||
... | @@ -192,8 +202,9 @@ public class DhcpConfig extends Config<ApplicationId> { | ... | @@ -192,8 +202,9 @@ public class DhcpConfig extends Config<ApplicationId> { |
192 | * | 202 | * |
193 | * @return router address or null if not set | 203 | * @return router address or null if not set |
194 | */ | 204 | */ |
195 | - public String routerAddress() { | 205 | + public Ip4Address routerAddress() { |
196 | - return get(ROUTER_ADDRESS, null); | 206 | + String ip = get(ROUTER_ADDRESS, null); |
207 | + return ip != null ? Ip4Address.valueOf(ip) : null; | ||
197 | } | 208 | } |
198 | 209 | ||
199 | /** | 210 | /** |
... | @@ -211,8 +222,9 @@ public class DhcpConfig extends Config<ApplicationId> { | ... | @@ -211,8 +222,9 @@ public class DhcpConfig extends Config<ApplicationId> { |
211 | * | 222 | * |
212 | * @return domain server address or null if not set | 223 | * @return domain server address or null if not set |
213 | */ | 224 | */ |
214 | - public String domainServer() { | 225 | + public Ip4Address domainServer() { |
215 | - return get(DOMAIN_SERVER, null); | 226 | + String ip = get(DOMAIN_SERVER, null); |
227 | + return ip != null ? Ip4Address.valueOf(ip) : null; | ||
216 | } | 228 | } |
217 | 229 | ||
218 | /** | 230 | /** |
... | @@ -224,4 +236,82 @@ public class DhcpConfig extends Config<ApplicationId> { | ... | @@ -224,4 +236,82 @@ public class DhcpConfig extends Config<ApplicationId> { |
224 | public BasicElementConfig domainServer(String domain) { | 236 | public BasicElementConfig domainServer(String domain) { |
225 | return (BasicElementConfig) setOrClear(DOMAIN_SERVER, domain); | 237 | return (BasicElementConfig) setOrClear(DOMAIN_SERVER, domain); |
226 | } | 238 | } |
239 | + | ||
240 | + /** | ||
241 | + * Returns the delay after which the dhcp server will purge expired entries. | ||
242 | + * | ||
243 | + * @return time delay or null if not set | ||
244 | + */ | ||
245 | + public int timerDelay() { | ||
246 | + return get(TIMER_DELAY, 0); | ||
247 | + } | ||
248 | + | ||
249 | + /** | ||
250 | + * Sets the delay after which the dhcp server will purge expired entries. | ||
251 | + * | ||
252 | + * @param delay new time delay; null to clear | ||
253 | + * @return self | ||
254 | + */ | ||
255 | + public BasicElementConfig timerDelay(int delay) { | ||
256 | + return (BasicElementConfig) setOrClear(TIMER_DELAY, delay); | ||
257 | + } | ||
258 | + | ||
259 | + /** | ||
260 | + * Returns the default timeout for pending assignments. | ||
261 | + * | ||
262 | + * @return default timeout or null if not set | ||
263 | + */ | ||
264 | + public int defaultTimeout() { | ||
265 | + return get(DEFAULT_TIMEOUT, 0); | ||
266 | + } | ||
267 | + | ||
268 | + /** | ||
269 | + * Sets the default timeout for pending assignments. | ||
270 | + * | ||
271 | + * @param defaultTimeout new default timeout; null to clear | ||
272 | + * @return self | ||
273 | + */ | ||
274 | + public BasicElementConfig defaultTimeout(int defaultTimeout) { | ||
275 | + return (BasicElementConfig) setOrClear(DEFAULT_TIMEOUT, defaultTimeout); | ||
276 | + } | ||
277 | + | ||
278 | + /** | ||
279 | + * Returns the start IP for the available IP Range. | ||
280 | + * | ||
281 | + * @return start IP or null if not set | ||
282 | + */ | ||
283 | + public Ip4Address startIp() { | ||
284 | + String ip = get(START_IP, null); | ||
285 | + return ip != null ? Ip4Address.valueOf(ip) : null; | ||
286 | + } | ||
287 | + | ||
288 | + /** | ||
289 | + * Sets the start IP for the available IP Range. | ||
290 | + * | ||
291 | + * @param startIp new start IP; null to clear | ||
292 | + * @return self | ||
293 | + */ | ||
294 | + public BasicElementConfig startIp(String startIp) { | ||
295 | + return (BasicElementConfig) setOrClear(START_IP, startIp); | ||
296 | + } | ||
297 | + | ||
298 | + /** | ||
299 | + * Returns the end IP for the available IP Range. | ||
300 | + * | ||
301 | + * @return end IP or null if not set | ||
302 | + */ | ||
303 | + public Ip4Address endIp() { | ||
304 | + String ip = get(END_IP, null); | ||
305 | + return ip != null ? Ip4Address.valueOf(ip) : null; | ||
306 | + } | ||
307 | + | ||
308 | + /** | ||
309 | + * Sets the end IP for the available IP Range. | ||
310 | + * | ||
311 | + * @param endIp new end IP; null to clear | ||
312 | + * @return self | ||
313 | + */ | ||
314 | + public BasicElementConfig endIp(String endIp) { | ||
315 | + return (BasicElementConfig) setOrClear(END_IP, endIp); | ||
316 | + } | ||
227 | } | 317 | } | ... | ... |
... | @@ -22,6 +22,8 @@ import org.apache.felix.scr.annotations.Deactivate; | ... | @@ -22,6 +22,8 @@ import org.apache.felix.scr.annotations.Deactivate; |
22 | import org.apache.felix.scr.annotations.Reference; | 22 | import org.apache.felix.scr.annotations.Reference; |
23 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 23 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
24 | import org.apache.felix.scr.annotations.Service; | 24 | import org.apache.felix.scr.annotations.Service; |
25 | +import org.jboss.netty.util.Timeout; | ||
26 | +import org.jboss.netty.util.TimerTask; | ||
25 | import org.onlab.packet.ARP; | 27 | import org.onlab.packet.ARP; |
26 | import org.onlab.packet.DHCP; | 28 | import org.onlab.packet.DHCP; |
27 | import org.onlab.packet.DHCPOption; | 29 | import org.onlab.packet.DHCPOption; |
... | @@ -34,20 +36,20 @@ import org.onlab.packet.MacAddress; | ... | @@ -34,20 +36,20 @@ import org.onlab.packet.MacAddress; |
34 | import org.onlab.packet.TpPort; | 36 | import org.onlab.packet.TpPort; |
35 | import org.onlab.packet.UDP; | 37 | import org.onlab.packet.UDP; |
36 | import org.onlab.packet.VlanId; | 38 | import org.onlab.packet.VlanId; |
39 | +import org.onlab.util.Timer; | ||
37 | import org.onosproject.core.ApplicationId; | 40 | import org.onosproject.core.ApplicationId; |
38 | import org.onosproject.core.CoreService; | 41 | import org.onosproject.core.CoreService; |
39 | import org.onosproject.dhcp.DhcpService; | 42 | import org.onosproject.dhcp.DhcpService; |
40 | import org.onosproject.dhcp.DhcpStore; | 43 | import org.onosproject.dhcp.DhcpStore; |
41 | import org.onosproject.dhcp.IpAssignment; | 44 | import org.onosproject.dhcp.IpAssignment; |
42 | -import org.onosproject.net.config.ConfigFactory; | ||
43 | -import org.onosproject.net.config.NetworkConfigEvent; | ||
44 | -import org.onosproject.net.config.NetworkConfigListener; | ||
45 | -import org.onosproject.net.config.NetworkConfigRegistry; | ||
46 | - | ||
47 | import org.onosproject.net.ConnectPoint; | 45 | import org.onosproject.net.ConnectPoint; |
48 | import org.onosproject.net.Host; | 46 | import org.onosproject.net.Host; |
49 | import org.onosproject.net.HostId; | 47 | import org.onosproject.net.HostId; |
50 | import org.onosproject.net.HostLocation; | 48 | import org.onosproject.net.HostLocation; |
49 | +import org.onosproject.net.config.ConfigFactory; | ||
50 | +import org.onosproject.net.config.NetworkConfigEvent; | ||
51 | +import org.onosproject.net.config.NetworkConfigListener; | ||
52 | +import org.onosproject.net.config.NetworkConfigRegistry; | ||
51 | import org.onosproject.net.flow.DefaultTrafficSelector; | 53 | import org.onosproject.net.flow.DefaultTrafficSelector; |
52 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 54 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
53 | import org.onosproject.net.flow.TrafficSelector; | 55 | import org.onosproject.net.flow.TrafficSelector; |
... | @@ -68,10 +70,12 @@ import org.slf4j.LoggerFactory; | ... | @@ -68,10 +70,12 @@ import org.slf4j.LoggerFactory; |
68 | 70 | ||
69 | import java.nio.ByteBuffer; | 71 | import java.nio.ByteBuffer; |
70 | import java.util.ArrayList; | 72 | import java.util.ArrayList; |
73 | +import java.util.Date; | ||
71 | import java.util.HashSet; | 74 | import java.util.HashSet; |
72 | import java.util.List; | 75 | import java.util.List; |
73 | import java.util.Map; | 76 | import java.util.Map; |
74 | import java.util.Set; | 77 | import java.util.Set; |
78 | +import java.util.concurrent.TimeUnit; | ||
75 | 79 | ||
76 | import static org.onlab.packet.MacAddress.valueOf; | 80 | import static org.onlab.packet.MacAddress.valueOf; |
77 | import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY; | 81 | import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY; |
... | @@ -96,14 +100,6 @@ public class DhcpManager implements DhcpService { | ... | @@ -96,14 +100,6 @@ public class DhcpManager implements DhcpService { |
96 | public DhcpConfig createConfig() { | 100 | public DhcpConfig createConfig() { |
97 | return new DhcpConfig(); | 101 | return new DhcpConfig(); |
98 | } | 102 | } |
99 | - }, | ||
100 | - new ConfigFactory<ApplicationId, DhcpStoreConfig>(APP_SUBJECT_FACTORY, | ||
101 | - DhcpStoreConfig.class, | ||
102 | - "dhcpstore") { | ||
103 | - @Override | ||
104 | - public DhcpStoreConfig createConfig() { | ||
105 | - return new DhcpStoreConfig(); | ||
106 | - } | ||
107 | } | 103 | } |
108 | ); | 104 | ); |
109 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 105 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
... | @@ -125,11 +121,13 @@ public class DhcpManager implements DhcpService { | ... | @@ -125,11 +121,13 @@ public class DhcpManager implements DhcpService { |
125 | 121 | ||
126 | protected HostProviderService hostProviderService; | 122 | protected HostProviderService hostProviderService; |
127 | 123 | ||
124 | + private final HostProvider hostProvider = new InternalHostProvider(); | ||
125 | + | ||
128 | private ApplicationId appId; | 126 | private ApplicationId appId; |
129 | 127 | ||
130 | // Hardcoded values are default values. | 128 | // Hardcoded values are default values. |
131 | 129 | ||
132 | - private static String myIP = "10.0.0.2"; | 130 | + private static Ip4Address myIP = Ip4Address.valueOf("10.0.0.2"); |
133 | 131 | ||
134 | private static MacAddress myMAC = valueOf("4f:4f:4f:4f:4f:4f"); | 132 | private static MacAddress myMAC = valueOf("4f:4f:4f:4f:4f:4f"); |
135 | 133 | ||
... | @@ -147,14 +145,17 @@ public class DhcpManager implements DhcpService { | ... | @@ -147,14 +145,17 @@ public class DhcpManager implements DhcpService { |
147 | 145 | ||
148 | private static byte packetTTL = (byte) 127; | 146 | private static byte packetTTL = (byte) 127; |
149 | 147 | ||
150 | - private static String subnetMask = "255.0.0.0"; | 148 | + private static Ip4Address subnetMask = Ip4Address.valueOf("255.0.0.0"); |
151 | 149 | ||
152 | - private static String broadcastAddress = "10.255.255.255"; | 150 | + private static Ip4Address broadcastAddress = Ip4Address.valueOf("10.255.255.255"); |
153 | 151 | ||
154 | - private static String routerAddress = "10.0.0.2"; | 152 | + private static Ip4Address routerAddress = Ip4Address.valueOf("10.0.0.2"); |
155 | 153 | ||
156 | - private static String domainServer = "10.0.0.2"; | 154 | + private static Ip4Address domainServer = Ip4Address.valueOf("10.0.0.2"); |
157 | - private final HostProvider hostProvider = new InternalHostProvider(); | 155 | + |
156 | + protected Timeout timeout; | ||
157 | + | ||
158 | + protected static int timerDelay = 2; | ||
158 | 159 | ||
159 | @Activate | 160 | @Activate |
160 | protected void activate() { | 161 | protected void activate() { |
... | @@ -164,11 +165,11 @@ public class DhcpManager implements DhcpService { | ... | @@ -164,11 +165,11 @@ public class DhcpManager implements DhcpService { |
164 | cfgService.addListener(cfgListener); | 165 | cfgService.addListener(cfgListener); |
165 | factories.forEach(cfgService::registerConfigFactory); | 166 | factories.forEach(cfgService::registerConfigFactory); |
166 | cfgListener.reconfigureNetwork(cfgService.getConfig(appId, DhcpConfig.class)); | 167 | cfgListener.reconfigureNetwork(cfgService.getConfig(appId, DhcpConfig.class)); |
167 | - cfgListener.reconfigureStore(cfgService.getConfig(appId, DhcpStoreConfig.class)); | ||
168 | 168 | ||
169 | hostProviderService = hostProviderRegistry.register(hostProvider); | 169 | hostProviderService = hostProviderRegistry.register(hostProvider); |
170 | packetService.addProcessor(processor, PacketProcessor.director(0)); | 170 | packetService.addProcessor(processor, PacketProcessor.director(0)); |
171 | requestPackets(); | 171 | requestPackets(); |
172 | + timeout = Timer.getTimer().newTimeout(new PurgeListTask(), timerDelay, TimeUnit.MINUTES); | ||
172 | log.info("Started"); | 173 | log.info("Started"); |
173 | } | 174 | } |
174 | 175 | ||
... | @@ -180,6 +181,7 @@ public class DhcpManager implements DhcpService { | ... | @@ -180,6 +181,7 @@ public class DhcpManager implements DhcpService { |
180 | hostProviderRegistry.unregister(hostProvider); | 181 | hostProviderRegistry.unregister(hostProvider); |
181 | hostProviderService = null; | 182 | hostProviderService = null; |
182 | cancelPackets(); | 183 | cancelPackets(); |
184 | + timeout.cancel(); | ||
183 | log.info("Stopped"); | 185 | log.info("Stopped"); |
184 | } | 186 | } |
185 | 187 | ||
... | @@ -217,7 +219,7 @@ public class DhcpManager implements DhcpService { | ... | @@ -217,7 +219,7 @@ public class DhcpManager implements DhcpService { |
217 | } | 219 | } |
218 | 220 | ||
219 | @Override | 221 | @Override |
220 | - public Map<MacAddress, IpAssignment> listMapping() { | 222 | + public Map<HostId, IpAssignment> listMapping() { |
221 | return dhcpStore.listMapping(); | 223 | return dhcpStore.listMapping(); |
222 | } | 224 | } |
223 | 225 | ||
... | @@ -261,9 +263,7 @@ public class DhcpManager implements DhcpService { | ... | @@ -261,9 +263,7 @@ public class DhcpManager implements DhcpService { |
261 | * @param outgoingMessageType the message type of the outgoing packet | 263 | * @param outgoingMessageType the message type of the outgoing packet |
262 | * @return the Ethernet reply frame | 264 | * @return the Ethernet reply frame |
263 | */ | 265 | */ |
264 | - private Ethernet buildReply(Ethernet packet, String ipOffered, byte outgoingMessageType) { | 266 | + private Ethernet buildReply(Ethernet packet, Ip4Address ipOffered, byte outgoingMessageType) { |
265 | - Ip4Address myIPAddress = Ip4Address.valueOf(myIP); | ||
266 | - Ip4Address ipAddress; | ||
267 | 267 | ||
268 | // Ethernet Frame. | 268 | // Ethernet Frame. |
269 | Ethernet ethReply = new Ethernet(); | 269 | Ethernet ethReply = new Ethernet(); |
... | @@ -275,9 +275,8 @@ public class DhcpManager implements DhcpService { | ... | @@ -275,9 +275,8 @@ public class DhcpManager implements DhcpService { |
275 | // IP Packet | 275 | // IP Packet |
276 | IPv4 ipv4Packet = (IPv4) packet.getPayload(); | 276 | IPv4 ipv4Packet = (IPv4) packet.getPayload(); |
277 | IPv4 ipv4Reply = new IPv4(); | 277 | IPv4 ipv4Reply = new IPv4(); |
278 | - ipv4Reply.setSourceAddress(myIPAddress.toInt()); | 278 | + ipv4Reply.setSourceAddress(myIP.toInt()); |
279 | - ipAddress = Ip4Address.valueOf(ipOffered); | 279 | + ipv4Reply.setDestinationAddress(ipOffered.toInt()); |
280 | - ipv4Reply.setDestinationAddress(ipAddress.toInt()); | ||
281 | ipv4Reply.setTtl(packetTTL); | 280 | ipv4Reply.setTtl(packetTTL); |
282 | 281 | ||
283 | // UDP Datagram. | 282 | // UDP Datagram. |
... | @@ -291,9 +290,8 @@ public class DhcpManager implements DhcpService { | ... | @@ -291,9 +290,8 @@ public class DhcpManager implements DhcpService { |
291 | DHCP dhcpReply = new DHCP(); | 290 | DHCP dhcpReply = new DHCP(); |
292 | dhcpReply.setOpCode(DHCP.OPCODE_REPLY); | 291 | dhcpReply.setOpCode(DHCP.OPCODE_REPLY); |
293 | 292 | ||
294 | - ipAddress = Ip4Address.valueOf(ipOffered); | 293 | + dhcpReply.setYourIPAddress(ipOffered.toInt()); |
295 | - dhcpReply.setYourIPAddress(ipAddress.toInt()); | 294 | + dhcpReply.setServerIPAddress(myIP.toInt()); |
296 | - dhcpReply.setServerIPAddress(myIPAddress.toInt()); | ||
297 | 295 | ||
298 | dhcpReply.setTransactionId(dhcpPacket.getTransactionId()); | 296 | dhcpReply.setTransactionId(dhcpPacket.getTransactionId()); |
299 | dhcpReply.setClientHardwareAddress(dhcpPacket.getClientHardwareAddress()); | 297 | dhcpReply.setClientHardwareAddress(dhcpPacket.getClientHardwareAddress()); |
... | @@ -315,7 +313,7 @@ public class DhcpManager implements DhcpService { | ... | @@ -315,7 +313,7 @@ public class DhcpManager implements DhcpService { |
315 | option = new DHCPOption(); | 313 | option = new DHCPOption(); |
316 | option.setCode(DHCP.DHCPOptionCode.OptionCode_DHCPServerIp.getValue()); | 314 | option.setCode(DHCP.DHCPOptionCode.OptionCode_DHCPServerIp.getValue()); |
317 | option.setLength((byte) 4); | 315 | option.setLength((byte) 4); |
318 | - option.setData(myIPAddress.toOctets()); | 316 | + option.setData(myIP.toOctets()); |
319 | optionList.add(option); | 317 | optionList.add(option); |
320 | 318 | ||
321 | // IP Address Lease Time. | 319 | // IP Address Lease Time. |
... | @@ -343,32 +341,28 @@ public class DhcpManager implements DhcpService { | ... | @@ -343,32 +341,28 @@ public class DhcpManager implements DhcpService { |
343 | option = new DHCPOption(); | 341 | option = new DHCPOption(); |
344 | option.setCode(DHCP.DHCPOptionCode.OptionCode_SubnetMask.getValue()); | 342 | option.setCode(DHCP.DHCPOptionCode.OptionCode_SubnetMask.getValue()); |
345 | option.setLength((byte) 4); | 343 | option.setLength((byte) 4); |
346 | - ipAddress = Ip4Address.valueOf(subnetMask); | 344 | + option.setData(subnetMask.toOctets()); |
347 | - option.setData(ipAddress.toOctets()); | ||
348 | optionList.add(option); | 345 | optionList.add(option); |
349 | 346 | ||
350 | // Broadcast Address. | 347 | // Broadcast Address. |
351 | option = new DHCPOption(); | 348 | option = new DHCPOption(); |
352 | option.setCode(DHCP.DHCPOptionCode.OptionCode_BroadcastAddress.getValue()); | 349 | option.setCode(DHCP.DHCPOptionCode.OptionCode_BroadcastAddress.getValue()); |
353 | option.setLength((byte) 4); | 350 | option.setLength((byte) 4); |
354 | - ipAddress = Ip4Address.valueOf(broadcastAddress); | 351 | + option.setData(broadcastAddress.toOctets()); |
355 | - option.setData(ipAddress.toOctets()); | ||
356 | optionList.add(option); | 352 | optionList.add(option); |
357 | 353 | ||
358 | // Router Address. | 354 | // Router Address. |
359 | option = new DHCPOption(); | 355 | option = new DHCPOption(); |
360 | option.setCode(DHCP.DHCPOptionCode.OptionCode_RouterAddress.getValue()); | 356 | option.setCode(DHCP.DHCPOptionCode.OptionCode_RouterAddress.getValue()); |
361 | option.setLength((byte) 4); | 357 | option.setLength((byte) 4); |
362 | - ipAddress = Ip4Address.valueOf(routerAddress); | 358 | + option.setData(routerAddress.toOctets()); |
363 | - option.setData(ipAddress.toOctets()); | ||
364 | optionList.add(option); | 359 | optionList.add(option); |
365 | 360 | ||
366 | // DNS Server Address. | 361 | // DNS Server Address. |
367 | option = new DHCPOption(); | 362 | option = new DHCPOption(); |
368 | option.setCode(DHCP.DHCPOptionCode.OptionCode_DomainServer.getValue()); | 363 | option.setCode(DHCP.DHCPOptionCode.OptionCode_DomainServer.getValue()); |
369 | option.setLength((byte) 4); | 364 | option.setLength((byte) 4); |
370 | - ipAddress = Ip4Address.valueOf(domainServer); | 365 | + option.setData(domainServer.toOctets()); |
371 | - option.setData(ipAddress.toOctets()); | ||
372 | optionList.add(option); | 366 | optionList.add(option); |
373 | 367 | ||
374 | // End Option. | 368 | // End Option. |
... | @@ -418,12 +412,11 @@ public class DhcpManager implements DhcpService { | ... | @@ -418,12 +412,11 @@ public class DhcpManager implements DhcpService { |
418 | 412 | ||
419 | if (dhcpPayload != null) { | 413 | if (dhcpPayload != null) { |
420 | 414 | ||
421 | - // TODO Convert this to enum value. | 415 | + DHCPPacketType incomingPacketType = DHCPPacketType.getType(0); |
422 | - byte incomingPacketType = 0; | ||
423 | for (DHCPOption option : dhcpPayload.getOptions()) { | 416 | for (DHCPOption option : dhcpPayload.getOptions()) { |
424 | if (option.getCode() == DHCP.DHCPOptionCode.OptionCode_MessageType.getValue()) { | 417 | if (option.getCode() == DHCP.DHCPOptionCode.OptionCode_MessageType.getValue()) { |
425 | byte[] data = option.getData(); | 418 | byte[] data = option.getData(); |
426 | - incomingPacketType = data[0]; | 419 | + incomingPacketType = DHCPPacketType.getType(data[0]); |
427 | } | 420 | } |
428 | if (option.getCode() == DHCP.DHCPOptionCode.OptionCode_RequestedIP.getValue()) { | 421 | if (option.getCode() == DHCP.DHCPOptionCode.OptionCode_RequestedIP.getValue()) { |
429 | byte[] data = option.getData(); | 422 | byte[] data = option.getData(); |
... | @@ -436,37 +429,39 @@ public class DhcpManager implements DhcpService { | ... | @@ -436,37 +429,39 @@ public class DhcpManager implements DhcpService { |
436 | flagIfServerIP = true; | 429 | flagIfServerIP = true; |
437 | } | 430 | } |
438 | } | 431 | } |
439 | - | ||
440 | - String ipOffered = ""; | ||
441 | DHCPPacketType outgoingPacketType; | 432 | DHCPPacketType outgoingPacketType; |
442 | MacAddress clientMAC = new MacAddress(dhcpPayload.getClientHardwareAddress()); | 433 | MacAddress clientMAC = new MacAddress(dhcpPayload.getClientHardwareAddress()); |
434 | + VlanId vlanId = VlanId.vlanId(packet.getVlanID()); | ||
435 | + HostId hostId = HostId.hostId(clientMAC, vlanId); | ||
443 | 436 | ||
444 | - if (incomingPacketType == DHCPPacketType.DHCPDISCOVER.getValue()) { | 437 | + if (incomingPacketType.getValue() == DHCPPacketType.DHCPDISCOVER.getValue()) { |
445 | 438 | ||
446 | outgoingPacketType = DHCPPacketType.DHCPOFFER; | 439 | outgoingPacketType = DHCPPacketType.DHCPOFFER; |
447 | - ipOffered = dhcpStore.suggestIP(clientMAC, requestedIP).toString(); | 440 | + Ip4Address ipOffered = dhcpStore.suggestIP(hostId, requestedIP); |
448 | - | 441 | + if (ipOffered != null) { |
449 | - Ethernet ethReply = buildReply(packet, ipOffered, (byte) outgoingPacketType.getValue()); | 442 | + Ethernet ethReply = buildReply(packet, ipOffered, |
450 | - sendReply(context, ethReply); | 443 | + (byte) outgoingPacketType.getValue()); |
444 | + sendReply(context, ethReply); | ||
445 | + } | ||
451 | 446 | ||
452 | - } else if (incomingPacketType == DHCPPacketType.DHCPREQUEST.getValue()) { | 447 | + } else if (incomingPacketType.getValue() == DHCPPacketType.DHCPREQUEST.getValue()) { |
453 | 448 | ||
454 | outgoingPacketType = DHCPPacketType.DHCPACK; | 449 | outgoingPacketType = DHCPPacketType.DHCPACK; |
455 | 450 | ||
456 | if (flagIfServerIP && flagIfRequestedIP) { | 451 | if (flagIfServerIP && flagIfRequestedIP) { |
457 | // SELECTING state | 452 | // SELECTING state |
458 | - if (myIP.equals(serverIP.toString()) && | 453 | + if (myIP.equals(serverIP) && |
459 | - dhcpStore.assignIP(clientMAC, requestedIP, leaseTime)) { | 454 | + dhcpStore.assignIP(hostId, requestedIP, leaseTime)) { |
460 | 455 | ||
461 | - Ethernet ethReply = buildReply(packet, requestedIP.toString(), | 456 | + Ethernet ethReply = buildReply(packet, requestedIP, |
462 | (byte) outgoingPacketType.getValue()); | 457 | (byte) outgoingPacketType.getValue()); |
463 | sendReply(context, ethReply); | 458 | sendReply(context, ethReply); |
464 | discoverHost(context, requestedIP); | 459 | discoverHost(context, requestedIP); |
465 | } | 460 | } |
466 | } else if (flagIfRequestedIP) { | 461 | } else if (flagIfRequestedIP) { |
467 | // INIT-REBOOT state | 462 | // INIT-REBOOT state |
468 | - if (dhcpStore.assignIP(clientMAC, requestedIP, leaseTime)) { | 463 | + if (dhcpStore.assignIP(hostId, requestedIP, leaseTime)) { |
469 | - Ethernet ethReply = buildReply(packet, requestedIP.toString(), | 464 | + Ethernet ethReply = buildReply(packet, requestedIP, |
470 | (byte) outgoingPacketType.getValue()); | 465 | (byte) outgoingPacketType.getValue()); |
471 | sendReply(context, ethReply); | 466 | sendReply(context, ethReply); |
472 | discoverHost(context, requestedIP); | 467 | discoverHost(context, requestedIP); |
... | @@ -476,16 +471,16 @@ public class DhcpManager implements DhcpService { | ... | @@ -476,16 +471,16 @@ public class DhcpManager implements DhcpService { |
476 | int ciaadr = dhcpPayload.getClientIPAddress(); | 471 | int ciaadr = dhcpPayload.getClientIPAddress(); |
477 | if (ciaadr != 0) { | 472 | if (ciaadr != 0) { |
478 | Ip4Address clientIaddr = Ip4Address.valueOf(ciaadr); | 473 | Ip4Address clientIaddr = Ip4Address.valueOf(ciaadr); |
479 | - if (dhcpStore.assignIP(clientMAC, clientIaddr, leaseTime)) { | 474 | + if (dhcpStore.assignIP(hostId, clientIaddr, leaseTime)) { |
480 | - Ethernet ethReply = buildReply(packet, clientIaddr.toString(), | 475 | + Ethernet ethReply = buildReply(packet, clientIaddr, |
481 | (byte) outgoingPacketType.getValue()); | 476 | (byte) outgoingPacketType.getValue()); |
482 | sendReply(context, ethReply); | 477 | sendReply(context, ethReply); |
483 | discoverHost(context, clientIaddr); | 478 | discoverHost(context, clientIaddr); |
484 | } | 479 | } |
485 | } | 480 | } |
486 | } | 481 | } |
487 | - } else if (incomingPacketType == DHCPPacketType.DHCPRELEASE.getValue()) { | 482 | + } else if (incomingPacketType.getValue() == DHCPPacketType.DHCPRELEASE.getValue()) { |
488 | - dhcpStore.releaseIP(clientMAC); | 483 | + dhcpStore.releaseIP(hostId); |
489 | } | 484 | } |
490 | } | 485 | } |
491 | } | 486 | } |
... | @@ -564,7 +559,7 @@ public class DhcpManager implements DhcpService { | ... | @@ -564,7 +559,7 @@ public class DhcpManager implements DhcpService { |
564 | ARP arpPacket = (ARP) packet.getPayload(); | 559 | ARP arpPacket = (ARP) packet.getPayload(); |
565 | 560 | ||
566 | if ((arpPacket.getOpCode() == ARP.OP_REQUEST) && | 561 | if ((arpPacket.getOpCode() == ARP.OP_REQUEST) && |
567 | - (Ip4Address.valueOf(arpPacket.getTargetProtocolAddress()).toString().equals(myIP))) { | 562 | + (myIP).equals(Ip4Address.valueOf(arpPacket.getTargetProtocolAddress()))) { |
568 | 563 | ||
569 | processARPPacket(context, packet); | 564 | processARPPacket(context, packet); |
570 | 565 | ||
... | @@ -588,7 +583,7 @@ public class DhcpManager implements DhcpService { | ... | @@ -588,7 +583,7 @@ public class DhcpManager implements DhcpService { |
588 | myIP = cfg.ip(); | 583 | myIP = cfg.ip(); |
589 | } | 584 | } |
590 | if (cfg.mac() != null) { | 585 | if (cfg.mac() != null) { |
591 | - myMAC = MacAddress.valueOf(cfg.mac()); | 586 | + myMAC = cfg.mac(); |
592 | } | 587 | } |
593 | if (cfg.subnetMask() != null) { | 588 | if (cfg.subnetMask() != null) { |
594 | subnetMask = cfg.subnetMask(); | 589 | subnetMask = cfg.subnetMask(); |
... | @@ -602,57 +597,40 @@ public class DhcpManager implements DhcpService { | ... | @@ -602,57 +597,40 @@ public class DhcpManager implements DhcpService { |
602 | if (cfg.domainServer() != null) { | 597 | if (cfg.domainServer() != null) { |
603 | domainServer = cfg.domainServer(); | 598 | domainServer = cfg.domainServer(); |
604 | } | 599 | } |
605 | - if (cfg.ttl() != null) { | 600 | + if (cfg.ttl() != 0) { |
606 | - packetTTL = Byte.valueOf(cfg.ttl()); | 601 | + packetTTL = (byte) cfg.ttl(); |
607 | } | 602 | } |
608 | - if (cfg.leaseTime() != null) { | 603 | + if (cfg.leaseTime() != 0) { |
609 | - leaseTime = Integer.valueOf(cfg.leaseTime()); | 604 | + leaseTime = cfg.leaseTime(); |
610 | } | 605 | } |
611 | - if (cfg.renewTime() != null) { | 606 | + if (cfg.renewTime() != 0) { |
612 | - renewalTime = Integer.valueOf(cfg.renewTime()); | 607 | + renewalTime = cfg.renewTime(); |
613 | } | 608 | } |
614 | - if (cfg.rebindTime() != null) { | 609 | + if (cfg.rebindTime() != 0) { |
615 | - rebindingTime = Integer.valueOf(cfg.rebindTime()); | 610 | + rebindingTime = cfg.rebindTime(); |
616 | } | 611 | } |
617 | - } | 612 | + if (cfg.defaultTimeout() != 0) { |
618 | - | 613 | + dhcpStore.setDefaultTimeoutForPurge(cfg.defaultTimeout()); |
619 | - /** | ||
620 | - * Reconfigures the DHCP Store according to the configuration parameters passed. | ||
621 | - * | ||
622 | - * @param cfg configuration object | ||
623 | - */ | ||
624 | - private void reconfigureStore(DhcpStoreConfig cfg) { | ||
625 | - if (cfg == null) { | ||
626 | - return; | ||
627 | } | 614 | } |
628 | - | 615 | + if (cfg.timerDelay() != 0) { |
629 | - if (cfg.defaultTimeout() != null) { | 616 | + timerDelay = cfg.timerDelay(); |
630 | - dhcpStore.setDefaultTimeoutForPurge(Integer.valueOf(cfg.defaultTimeout())); | ||
631 | } | 617 | } |
632 | - if (cfg.timerDelay() != null) { | 618 | + if ((cfg.startIp() != null) && (cfg.endIp() != null)) { |
633 | - dhcpStore.setTimerDelay(Integer.valueOf(cfg.defaultTimeout())); | 619 | + dhcpStore.populateIPPoolfromRange(cfg.startIp(), cfg.endIp()); |
634 | - } | ||
635 | - if ((cfg.startIP() != null) && (cfg.endIP() != null)) { | ||
636 | - dhcpStore.populateIPPoolfromRange(Ip4Address.valueOf(cfg.startIP()), | ||
637 | - Ip4Address.valueOf(cfg.endIP())); | ||
638 | } | 620 | } |
639 | } | 621 | } |
640 | 622 | ||
623 | + | ||
641 | @Override | 624 | @Override |
642 | public void event(NetworkConfigEvent event) { | 625 | public void event(NetworkConfigEvent event) { |
643 | 626 | ||
644 | if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED || | 627 | if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED || |
645 | - event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED)) { | 628 | + event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED) && |
646 | - if (event.configClass().equals(DhcpConfig.class)) { | 629 | + event.configClass().equals(DhcpConfig.class)) { |
647 | - DhcpConfig cfg = cfgService.getConfig(appId, DhcpConfig.class); | 630 | + |
648 | - reconfigureNetwork(cfg); | 631 | + DhcpConfig cfg = cfgService.getConfig(appId, DhcpConfig.class); |
649 | - log.info("Reconfigured Manager"); | 632 | + reconfigureNetwork(cfg); |
650 | - } | 633 | + log.info("Reconfigured"); |
651 | - if (event.configClass().equals(DhcpStoreConfig.class)) { | ||
652 | - DhcpStoreConfig cfg = cfgService.getConfig(appId, DhcpStoreConfig.class); | ||
653 | - reconfigureStore(cfg); | ||
654 | - log.info("Reconfigured Store"); | ||
655 | - } | ||
656 | } | 634 | } |
657 | } | 635 | } |
658 | } | 636 | } |
... | @@ -671,4 +649,27 @@ public class DhcpManager implements DhcpService { | ... | @@ -671,4 +649,27 @@ public class DhcpManager implements DhcpService { |
671 | // nothing to do | 649 | // nothing to do |
672 | } | 650 | } |
673 | } | 651 | } |
652 | + | ||
653 | + private class PurgeListTask implements TimerTask { | ||
654 | + | ||
655 | + @Override | ||
656 | + public void run(Timeout to) { | ||
657 | + IpAssignment ipAssignment; | ||
658 | + Date dateNow = new Date(); | ||
659 | + | ||
660 | + Map<HostId, IpAssignment> ipAssignmentMap = dhcpStore.listMapping(); | ||
661 | + for (Map.Entry<HostId, IpAssignment> entry: ipAssignmentMap.entrySet()) { | ||
662 | + ipAssignment = entry.getValue(); | ||
663 | + | ||
664 | + long timeLapsed = dateNow.getTime() - ipAssignment.timestamp().getTime(); | ||
665 | + if ((ipAssignment.assignmentStatus() != IpAssignment.AssignmentStatus.Option_Expired) && | ||
666 | + (ipAssignment.leasePeriod() > 0) && (timeLapsed > (ipAssignment.leasePeriodMs()))) { | ||
667 | + | ||
668 | + dhcpStore.releaseIP(entry.getKey()); | ||
669 | + hostProviderService.hostVanished(entry.getKey()); | ||
670 | + } | ||
671 | + } | ||
672 | + timeout = Timer.getTimer().newTimeout(new PurgeListTask(), timerDelay, TimeUnit.MINUTES); | ||
673 | + } | ||
674 | + } | ||
674 | } | 675 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
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.dhcp.impl; | ||
17 | - | ||
18 | -import org.onosproject.core.ApplicationId; | ||
19 | -import org.onosproject.net.config.Config; | ||
20 | -import org.onosproject.net.config.basics.BasicElementConfig; | ||
21 | - | ||
22 | -/** | ||
23 | - * DHCP Store Config class. | ||
24 | - */ | ||
25 | -public class DhcpStoreConfig extends Config<ApplicationId> { | ||
26 | - | ||
27 | - // FIXME: combine with the other config and properly type the values | ||
28 | - | ||
29 | - public static final String TIMER_DELAY = "delay"; | ||
30 | - public static final String DEFAULT_TIMEOUT = "timeout"; | ||
31 | - public static final String START_IP = "startip"; | ||
32 | - public static final String END_IP = "endip"; | ||
33 | - | ||
34 | - /** | ||
35 | - * Returns the delay after which the dhcp server will purge expired entries. | ||
36 | - * | ||
37 | - * @return time delay or null if not set | ||
38 | - */ | ||
39 | - public String timerDelay() { | ||
40 | - return get(TIMER_DELAY, null); | ||
41 | - } | ||
42 | - | ||
43 | - /** | ||
44 | - * Sets the delay after which the dhcp server will purge expired entries. | ||
45 | - * | ||
46 | - * @param delay new time delay; null to clear | ||
47 | - * @return self | ||
48 | - */ | ||
49 | - public BasicElementConfig timerDelay(String delay) { | ||
50 | - return (BasicElementConfig) setOrClear(TIMER_DELAY, delay); | ||
51 | - } | ||
52 | - | ||
53 | - /** | ||
54 | - * Returns the default timeout for pending assignments. | ||
55 | - * | ||
56 | - * @return default timeout or null if not set | ||
57 | - */ | ||
58 | - public String defaultTimeout() { | ||
59 | - return get(DEFAULT_TIMEOUT, null); | ||
60 | - } | ||
61 | - | ||
62 | - /** | ||
63 | - * Sets the default timeout for pending assignments. | ||
64 | - * | ||
65 | - * @param defaultTimeout new default timeout; null to clear | ||
66 | - * @return self | ||
67 | - */ | ||
68 | - public BasicElementConfig defaultTimeout(String defaultTimeout) { | ||
69 | - return (BasicElementConfig) setOrClear(DEFAULT_TIMEOUT, defaultTimeout); | ||
70 | - } | ||
71 | - | ||
72 | - /** | ||
73 | - * Returns the start IP for the available IP Range. | ||
74 | - * | ||
75 | - * @return start IP or null if not set | ||
76 | - */ | ||
77 | - public String startIP() { | ||
78 | - return get(START_IP, null); | ||
79 | - } | ||
80 | - | ||
81 | - /** | ||
82 | - * Sets the start IP for the available IP Range. | ||
83 | - * | ||
84 | - * @param startIP new start IP; null to clear | ||
85 | - * @return self | ||
86 | - */ | ||
87 | - public BasicElementConfig startIP(String startIP) { | ||
88 | - return (BasicElementConfig) setOrClear(START_IP, startIP); | ||
89 | - } | ||
90 | - | ||
91 | - /** | ||
92 | - * Returns the end IP for the available IP Range. | ||
93 | - * | ||
94 | - * @return end IP or null if not set | ||
95 | - */ | ||
96 | - public String endIP() { | ||
97 | - return get(END_IP, null); | ||
98 | - } | ||
99 | - | ||
100 | - /** | ||
101 | - * Sets the end IP for the available IP Range. | ||
102 | - * | ||
103 | - * @param endIP new end IP; null to clear | ||
104 | - * @return self | ||
105 | - */ | ||
106 | - public BasicElementConfig endIP(String endIP) { | ||
107 | - return (BasicElementConfig) setOrClear(END_IP, endIP); | ||
108 | - } | ||
109 | -} |
... | @@ -17,10 +17,10 @@ package org.onosproject.dhcp.impl; | ... | @@ -17,10 +17,10 @@ package org.onosproject.dhcp.impl; |
17 | 17 | ||
18 | import com.fasterxml.jackson.databind.node.ObjectNode; | 18 | import com.fasterxml.jackson.databind.node.ObjectNode; |
19 | import com.google.common.collect.ImmutableSet; | 19 | import com.google.common.collect.ImmutableSet; |
20 | -import org.onlab.packet.MacAddress; | ||
21 | import org.onosproject.cli.AbstractShellCommand; | 20 | import org.onosproject.cli.AbstractShellCommand; |
22 | import org.onosproject.dhcp.DhcpService; | 21 | import org.onosproject.dhcp.DhcpService; |
23 | import org.onosproject.dhcp.IpAssignment; | 22 | import org.onosproject.dhcp.IpAssignment; |
23 | +import org.onosproject.net.HostId; | ||
24 | import org.onosproject.ui.RequestHandler; | 24 | import org.onosproject.ui.RequestHandler; |
25 | import org.onosproject.ui.UiMessageHandler; | 25 | import org.onosproject.ui.UiMessageHandler; |
26 | import org.onosproject.ui.table.TableModel; | 26 | import org.onosproject.ui.table.TableModel; |
... | @@ -39,12 +39,12 @@ public class DhcpViewMessageHandler extends UiMessageHandler { | ... | @@ -39,12 +39,12 @@ public class DhcpViewMessageHandler extends UiMessageHandler { |
39 | private static final String DHCP_DATA_RESP = "dhcpDataResponse"; | 39 | private static final String DHCP_DATA_RESP = "dhcpDataResponse"; |
40 | private static final String DHCP = "dhcps"; | 40 | private static final String DHCP = "dhcps"; |
41 | 41 | ||
42 | - private static final String MAC = "mac"; | 42 | + private static final String HOST = "host"; |
43 | private static final String IP = "ip"; | 43 | private static final String IP = "ip"; |
44 | private static final String LEASE = "lease"; | 44 | private static final String LEASE = "lease"; |
45 | 45 | ||
46 | private static final String[] COL_IDS = { | 46 | private static final String[] COL_IDS = { |
47 | - MAC, IP, LEASE | 47 | + HOST, IP, LEASE |
48 | }; | 48 | }; |
49 | 49 | ||
50 | @Override | 50 | @Override |
... | @@ -63,7 +63,7 @@ public class DhcpViewMessageHandler extends UiMessageHandler { | ... | @@ -63,7 +63,7 @@ public class DhcpViewMessageHandler extends UiMessageHandler { |
63 | 63 | ||
64 | @Override | 64 | @Override |
65 | protected String defaultColumnId() { | 65 | protected String defaultColumnId() { |
66 | - return MAC; | 66 | + return HOST; |
67 | } | 67 | } |
68 | 68 | ||
69 | @Override | 69 | @Override |
... | @@ -74,21 +74,21 @@ public class DhcpViewMessageHandler extends UiMessageHandler { | ... | @@ -74,21 +74,21 @@ public class DhcpViewMessageHandler extends UiMessageHandler { |
74 | @Override | 74 | @Override |
75 | protected void populateTable(TableModel tm, ObjectNode payload) { | 75 | protected void populateTable(TableModel tm, ObjectNode payload) { |
76 | DhcpService dhcpService = AbstractShellCommand.get(DhcpService.class); | 76 | DhcpService dhcpService = AbstractShellCommand.get(DhcpService.class); |
77 | - Map<MacAddress, IpAssignment> allocationMap = dhcpService.listMapping(); | 77 | + Map<HostId, IpAssignment> allocationMap = dhcpService.listMapping(); |
78 | 78 | ||
79 | - for (Map.Entry<MacAddress, IpAssignment> entry : allocationMap.entrySet()) { | 79 | + for (Map.Entry<HostId, IpAssignment> entry : allocationMap.entrySet()) { |
80 | populateRow(tm.addRow(), entry); | 80 | populateRow(tm.addRow(), entry); |
81 | } | 81 | } |
82 | } | 82 | } |
83 | 83 | ||
84 | - private void populateRow(TableModel.Row row, Map.Entry<MacAddress, IpAssignment> entry) { | 84 | + private void populateRow(TableModel.Row row, Map.Entry<HostId, IpAssignment> entry) { |
85 | if (entry.getValue().leasePeriod() > 0) { | 85 | if (entry.getValue().leasePeriod() > 0) { |
86 | Date now = new Date(entry.getValue().timestamp().getTime() + entry.getValue().leasePeriod()); | 86 | Date now = new Date(entry.getValue().timestamp().getTime() + entry.getValue().leasePeriod()); |
87 | - row.cell(MAC, entry.getKey()) | 87 | + row.cell(HOST, entry.getKey()) |
88 | .cell(IP, entry.getValue().ipAddress()) | 88 | .cell(IP, entry.getValue().ipAddress()) |
89 | .cell(LEASE, now.toString()); | 89 | .cell(LEASE, now.toString()); |
90 | } else { | 90 | } else { |
91 | - row.cell(MAC, entry.getKey()) | 91 | + row.cell(HOST, entry.getKey()) |
92 | .cell(IP, entry.getValue().ipAddress()) | 92 | .cell(IP, entry.getValue().ipAddress()) |
93 | .cell(LEASE, "Infinite Static Lease"); | 93 | .cell(LEASE, "Infinite Static Lease"); |
94 | } | 94 | } | ... | ... |
... | @@ -22,14 +22,12 @@ import org.apache.felix.scr.annotations.Deactivate; | ... | @@ -22,14 +22,12 @@ import org.apache.felix.scr.annotations.Deactivate; |
22 | import org.apache.felix.scr.annotations.Reference; | 22 | import org.apache.felix.scr.annotations.Reference; |
23 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 23 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
24 | import org.apache.felix.scr.annotations.Service; | 24 | import org.apache.felix.scr.annotations.Service; |
25 | -import org.jboss.netty.util.Timeout; | ||
26 | -import org.jboss.netty.util.TimerTask; | ||
27 | import org.onlab.packet.Ip4Address; | 25 | import org.onlab.packet.Ip4Address; |
28 | import org.onlab.packet.MacAddress; | 26 | import org.onlab.packet.MacAddress; |
29 | import org.onlab.util.KryoNamespace; | 27 | import org.onlab.util.KryoNamespace; |
30 | -import org.onlab.util.Timer; | ||
31 | import org.onosproject.dhcp.DhcpStore; | 28 | import org.onosproject.dhcp.DhcpStore; |
32 | import org.onosproject.dhcp.IpAssignment; | 29 | import org.onosproject.dhcp.IpAssignment; |
30 | +import org.onosproject.net.HostId; | ||
33 | import org.onosproject.store.serializers.KryoNamespaces; | 31 | import org.onosproject.store.serializers.KryoNamespaces; |
34 | import org.onosproject.store.service.ConsistentMap; | 32 | import org.onosproject.store.service.ConsistentMap; |
35 | import org.onosproject.store.service.DistributedSet; | 33 | import org.onosproject.store.service.DistributedSet; |
... | @@ -42,7 +40,6 @@ import org.slf4j.LoggerFactory; | ... | @@ -42,7 +40,6 @@ import org.slf4j.LoggerFactory; |
42 | import java.util.Date; | 40 | import java.util.Date; |
43 | import java.util.HashMap; | 41 | import java.util.HashMap; |
44 | import java.util.Map; | 42 | import java.util.Map; |
45 | -import java.util.concurrent.TimeUnit; | ||
46 | 43 | ||
47 | /** | 44 | /** |
48 | * Manages the pool of available IP Addresses in the network and | 45 | * Manages the pool of available IP Addresses in the network and |
... | @@ -58,25 +55,21 @@ public class DistributedDhcpStore implements DhcpStore { | ... | @@ -58,25 +55,21 @@ public class DistributedDhcpStore implements DhcpStore { |
58 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 55 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
59 | protected StorageService storageService; | 56 | protected StorageService storageService; |
60 | 57 | ||
61 | - private ConsistentMap<MacAddress, IpAssignment> allocationMap; | 58 | + private ConsistentMap<HostId, IpAssignment> allocationMap; |
62 | 59 | ||
63 | private DistributedSet<Ip4Address> freeIPPool; | 60 | private DistributedSet<Ip4Address> freeIPPool; |
64 | 61 | ||
65 | - private Timeout timeout; | ||
66 | - | ||
67 | private static Ip4Address startIPRange; | 62 | private static Ip4Address startIPRange; |
68 | 63 | ||
69 | private static Ip4Address endIPRange; | 64 | private static Ip4Address endIPRange; |
70 | 65 | ||
71 | // Hardcoded values are default values. | 66 | // Hardcoded values are default values. |
72 | 67 | ||
73 | - private static int timerDelay = 2; | ||
74 | - | ||
75 | private static int timeoutForPendingAssignments = 60; | 68 | private static int timeoutForPendingAssignments = 60; |
76 | 69 | ||
77 | @Activate | 70 | @Activate |
78 | protected void activate() { | 71 | protected void activate() { |
79 | - allocationMap = storageService.<MacAddress, IpAssignment>consistentMapBuilder() | 72 | + allocationMap = storageService.<HostId, IpAssignment>consistentMapBuilder() |
80 | .withName("onos-dhcp-assignedIP") | 73 | .withName("onos-dhcp-assignedIP") |
81 | .withSerializer(Serializer.using( | 74 | .withSerializer(Serializer.using( |
82 | new KryoNamespace.Builder() | 75 | new KryoNamespace.Builder() |
... | @@ -94,23 +87,20 @@ public class DistributedDhcpStore implements DhcpStore { | ... | @@ -94,23 +87,20 @@ public class DistributedDhcpStore implements DhcpStore { |
94 | .withSerializer(Serializer.using(KryoNamespaces.API)) | 87 | .withSerializer(Serializer.using(KryoNamespaces.API)) |
95 | .build(); | 88 | .build(); |
96 | 89 | ||
97 | - timeout = Timer.getTimer().newTimeout(new PurgeListTask(), timerDelay, TimeUnit.MINUTES); | ||
98 | - | ||
99 | log.info("Started"); | 90 | log.info("Started"); |
100 | } | 91 | } |
101 | 92 | ||
102 | @Deactivate | 93 | @Deactivate |
103 | protected void deactivate() { | 94 | protected void deactivate() { |
104 | - timeout.cancel(); | ||
105 | log.info("Stopped"); | 95 | log.info("Stopped"); |
106 | } | 96 | } |
107 | 97 | ||
108 | @Override | 98 | @Override |
109 | - public Ip4Address suggestIP(MacAddress macID, Ip4Address requestedIP) { | 99 | + public Ip4Address suggestIP(HostId hostId, Ip4Address requestedIP) { |
110 | 100 | ||
111 | IpAssignment assignmentInfo; | 101 | IpAssignment assignmentInfo; |
112 | - if (allocationMap.containsKey(macID)) { | 102 | + if (allocationMap.containsKey(hostId)) { |
113 | - assignmentInfo = allocationMap.get(macID).value(); | 103 | + assignmentInfo = allocationMap.get(hostId).value(); |
114 | IpAssignment.AssignmentStatus status = assignmentInfo.assignmentStatus(); | 104 | IpAssignment.AssignmentStatus status = assignmentInfo.assignmentStatus(); |
115 | Ip4Address ipAddr = assignmentInfo.ipAddress(); | 105 | Ip4Address ipAddr = assignmentInfo.ipAddress(); |
116 | 106 | ||
... | @@ -131,7 +121,7 @@ public class DistributedDhcpStore implements DhcpStore { | ... | @@ -131,7 +121,7 @@ public class DistributedDhcpStore implements DhcpStore { |
131 | .assignmentStatus(IpAssignment.AssignmentStatus.Option_Requested) | 121 | .assignmentStatus(IpAssignment.AssignmentStatus.Option_Requested) |
132 | .build(); | 122 | .build(); |
133 | if (freeIPPool.remove(ipAddr)) { | 123 | if (freeIPPool.remove(ipAddr)) { |
134 | - allocationMap.put(macID, assignmentInfo); | 124 | + allocationMap.put(hostId, assignmentInfo); |
135 | return ipAddr; | 125 | return ipAddr; |
136 | } | 126 | } |
137 | } | 127 | } |
... | @@ -148,7 +138,7 @@ public class DistributedDhcpStore implements DhcpStore { | ... | @@ -148,7 +138,7 @@ public class DistributedDhcpStore implements DhcpStore { |
148 | .assignmentStatus(IpAssignment.AssignmentStatus.Option_Requested) | 138 | .assignmentStatus(IpAssignment.AssignmentStatus.Option_Requested) |
149 | .build(); | 139 | .build(); |
150 | if (freeIPPool.remove(requestedIP)) { | 140 | if (freeIPPool.remove(requestedIP)) { |
151 | - allocationMap.put(macID, assignmentInfo); | 141 | + allocationMap.put(hostId, assignmentInfo); |
152 | return requestedIP; | 142 | return requestedIP; |
153 | } | 143 | } |
154 | } | 144 | } |
... | @@ -156,24 +146,26 @@ public class DistributedDhcpStore implements DhcpStore { | ... | @@ -156,24 +146,26 @@ public class DistributedDhcpStore implements DhcpStore { |
156 | 146 | ||
157 | // Allocate a new IP from the server's pool of available IP. | 147 | // Allocate a new IP from the server's pool of available IP. |
158 | Ip4Address nextIPAddr = fetchNextIP(); | 148 | Ip4Address nextIPAddr = fetchNextIP(); |
159 | - assignmentInfo = IpAssignment.builder() | 149 | + if (nextIPAddr != null) { |
160 | - .ipAddress(nextIPAddr) | 150 | + assignmentInfo = IpAssignment.builder() |
161 | - .timestamp(new Date()) | 151 | + .ipAddress(nextIPAddr) |
162 | - .leasePeriod(timeoutForPendingAssignments) | 152 | + .timestamp(new Date()) |
163 | - .assignmentStatus(IpAssignment.AssignmentStatus.Option_Requested) | 153 | + .leasePeriod(timeoutForPendingAssignments) |
164 | - .build(); | 154 | + .assignmentStatus(IpAssignment.AssignmentStatus.Option_Requested) |
155 | + .build(); | ||
165 | 156 | ||
166 | - allocationMap.put(macID, assignmentInfo); | 157 | + allocationMap.put(hostId, assignmentInfo); |
158 | + } | ||
167 | return nextIPAddr; | 159 | return nextIPAddr; |
168 | 160 | ||
169 | } | 161 | } |
170 | 162 | ||
171 | @Override | 163 | @Override |
172 | - public boolean assignIP(MacAddress macID, Ip4Address ipAddr, int leaseTime) { | 164 | + public boolean assignIP(HostId hostId, Ip4Address ipAddr, int leaseTime) { |
173 | 165 | ||
174 | IpAssignment assignmentInfo; | 166 | IpAssignment assignmentInfo; |
175 | - if (allocationMap.containsKey(macID)) { | 167 | + if (allocationMap.containsKey(hostId)) { |
176 | - assignmentInfo = allocationMap.get(macID).value(); | 168 | + assignmentInfo = allocationMap.get(hostId).value(); |
177 | if ((assignmentInfo.ipAddress().toInt() == ipAddr.toInt()) && | 169 | if ((assignmentInfo.ipAddress().toInt() == ipAddr.toInt()) && |
178 | (ipAddr.toInt() >= startIPRange.toInt()) && (ipAddr.toInt() <= endIPRange.toInt())) { | 170 | (ipAddr.toInt() >= startIPRange.toInt()) && (ipAddr.toInt() <= endIPRange.toInt())) { |
179 | 171 | ||
... | @@ -183,7 +175,7 @@ public class DistributedDhcpStore implements DhcpStore { | ... | @@ -183,7 +175,7 @@ public class DistributedDhcpStore implements DhcpStore { |
183 | .leasePeriod(leaseTime) | 175 | .leasePeriod(leaseTime) |
184 | .assignmentStatus(IpAssignment.AssignmentStatus.Option_Assigned) | 176 | .assignmentStatus(IpAssignment.AssignmentStatus.Option_Assigned) |
185 | .build(); | 177 | .build(); |
186 | - allocationMap.put(macID, assignmentInfo); | 178 | + allocationMap.put(hostId, assignmentInfo); |
187 | return true; | 179 | return true; |
188 | } | 180 | } |
189 | } else if (freeIPPool.contains(ipAddr)) { | 181 | } else if (freeIPPool.contains(ipAddr)) { |
... | @@ -194,7 +186,7 @@ public class DistributedDhcpStore implements DhcpStore { | ... | @@ -194,7 +186,7 @@ public class DistributedDhcpStore implements DhcpStore { |
194 | .assignmentStatus(IpAssignment.AssignmentStatus.Option_Assigned) | 186 | .assignmentStatus(IpAssignment.AssignmentStatus.Option_Assigned) |
195 | .build(); | 187 | .build(); |
196 | if (freeIPPool.remove(ipAddr)) { | 188 | if (freeIPPool.remove(ipAddr)) { |
197 | - allocationMap.put(macID, assignmentInfo); | 189 | + allocationMap.put(hostId, assignmentInfo); |
198 | return true; | 190 | return true; |
199 | } | 191 | } |
200 | } | 192 | } |
... | @@ -202,14 +194,16 @@ public class DistributedDhcpStore implements DhcpStore { | ... | @@ -202,14 +194,16 @@ public class DistributedDhcpStore implements DhcpStore { |
202 | } | 194 | } |
203 | 195 | ||
204 | @Override | 196 | @Override |
205 | - public void releaseIP(MacAddress macID) { | 197 | + public void releaseIP(HostId hostId) { |
206 | - if (allocationMap.containsKey(macID)) { | 198 | + if (allocationMap.containsKey(hostId)) { |
207 | - IpAssignment newAssignment = IpAssignment.builder(allocationMap.get(macID).value()) | 199 | + IpAssignment newAssignment = IpAssignment.builder(allocationMap.get(hostId).value()) |
208 | .assignmentStatus(IpAssignment.AssignmentStatus.Option_Expired) | 200 | .assignmentStatus(IpAssignment.AssignmentStatus.Option_Expired) |
209 | .build(); | 201 | .build(); |
210 | Ip4Address freeIP = newAssignment.ipAddress(); | 202 | Ip4Address freeIP = newAssignment.ipAddress(); |
211 | - allocationMap.put(macID, newAssignment); | 203 | + allocationMap.put(hostId, newAssignment); |
212 | - freeIPPool.add(freeIP); | 204 | + if ((freeIP.toInt() > startIPRange.toInt()) && (freeIP.toInt() < endIPRange.toInt())) { |
205 | + freeIPPool.add(freeIP); | ||
206 | + } | ||
213 | } | 207 | } |
214 | } | 208 | } |
215 | 209 | ||
... | @@ -219,15 +213,10 @@ public class DistributedDhcpStore implements DhcpStore { | ... | @@ -219,15 +213,10 @@ public class DistributedDhcpStore implements DhcpStore { |
219 | } | 213 | } |
220 | 214 | ||
221 | @Override | 215 | @Override |
222 | - public void setTimerDelay(int timeInSeconds) { | 216 | + public Map<HostId, IpAssignment> listMapping() { |
223 | - timerDelay = timeInSeconds; | ||
224 | - } | ||
225 | - | ||
226 | - @Override | ||
227 | - public Map<MacAddress, IpAssignment> listMapping() { | ||
228 | 217 | ||
229 | - Map<MacAddress, IpAssignment> allMapping = new HashMap<>(); | 218 | + Map<HostId, IpAssignment> allMapping = new HashMap<>(); |
230 | - for (Map.Entry<MacAddress, Versioned<IpAssignment>> entry: allocationMap.entrySet()) { | 219 | + for (Map.Entry<HostId, Versioned<IpAssignment>> entry: allocationMap.entrySet()) { |
231 | IpAssignment assignment = entry.getValue().value(); | 220 | IpAssignment assignment = entry.getValue().value(); |
232 | if (assignment.assignmentStatus() == IpAssignment.AssignmentStatus.Option_Assigned) { | 221 | if (assignment.assignmentStatus() == IpAssignment.AssignmentStatus.Option_Assigned) { |
233 | allMapping.put(entry.getKey(), assignment); | 222 | allMapping.put(entry.getKey(), assignment); |
... | @@ -239,17 +228,21 @@ public class DistributedDhcpStore implements DhcpStore { | ... | @@ -239,17 +228,21 @@ public class DistributedDhcpStore implements DhcpStore { |
239 | 228 | ||
240 | @Override | 229 | @Override |
241 | public boolean assignStaticIP(MacAddress macID, Ip4Address ipAddr) { | 230 | public boolean assignStaticIP(MacAddress macID, Ip4Address ipAddr) { |
242 | - return assignIP(macID, ipAddr, -1); | 231 | + HostId host = HostId.hostId(macID); |
232 | + return assignIP(host, ipAddr, -1); | ||
243 | } | 233 | } |
244 | 234 | ||
245 | @Override | 235 | @Override |
246 | public boolean removeStaticIP(MacAddress macID) { | 236 | public boolean removeStaticIP(MacAddress macID) { |
247 | - if (allocationMap.containsKey(macID)) { | 237 | + HostId host = HostId.hostId(macID); |
248 | - IpAssignment assignment = allocationMap.get(macID).value(); | 238 | + if (allocationMap.containsKey(host)) { |
239 | + IpAssignment assignment = allocationMap.get(host).value(); | ||
249 | Ip4Address freeIP = assignment.ipAddress(); | 240 | Ip4Address freeIP = assignment.ipAddress(); |
250 | if (assignment.leasePeriod() < 0) { | 241 | if (assignment.leasePeriod() < 0) { |
251 | - allocationMap.remove(macID); | 242 | + allocationMap.remove(host); |
252 | - freeIPPool.add(freeIP); | 243 | + if ((freeIP.toInt() > startIPRange.toInt()) && (freeIP.toInt() < endIPRange.toInt())) { |
244 | + freeIPPool.add(freeIP); | ||
245 | + } | ||
253 | return true; | 246 | return true; |
254 | } | 247 | } |
255 | } | 248 | } |
... | @@ -289,36 +282,4 @@ public class DistributedDhcpStore implements DhcpStore { | ... | @@ -289,36 +282,4 @@ public class DistributedDhcpStore implements DhcpStore { |
289 | } | 282 | } |
290 | return null; | 283 | return null; |
291 | } | 284 | } |
292 | - | ||
293 | - /** | ||
294 | - * Purges the IP allocation map to remove expired entries and returns the freed IPs to the free pool. | ||
295 | - */ | ||
296 | - private class PurgeListTask implements TimerTask { | ||
297 | - | ||
298 | - @Override | ||
299 | - public void run(Timeout to) { | ||
300 | - IpAssignment ipAssignment, newAssignment; | ||
301 | - Date dateNow = new Date(); | ||
302 | - for (Map.Entry<MacAddress, Versioned<IpAssignment>> entry: allocationMap.entrySet()) { | ||
303 | - ipAssignment = entry.getValue().value(); | ||
304 | - long timeLapsed = dateNow.getTime() - ipAssignment.timestamp().getTime(); | ||
305 | - if ((ipAssignment.assignmentStatus() != IpAssignment.AssignmentStatus.Option_Expired) && | ||
306 | - (ipAssignment.leasePeriod() > 0) && (timeLapsed > (ipAssignment.leasePeriod()))) { | ||
307 | - Ip4Address freeIP = ipAssignment.ipAddress(); | ||
308 | - | ||
309 | - newAssignment = IpAssignment.builder(ipAssignment) | ||
310 | - .assignmentStatus(IpAssignment.AssignmentStatus.Option_Expired) | ||
311 | - .build(); | ||
312 | - allocationMap.put(entry.getKey(), newAssignment); | ||
313 | - | ||
314 | - if ((freeIP.toInt() > startIPRange.toInt()) && (freeIP.toInt() < endIPRange.toInt())) { | ||
315 | - freeIPPool.add(freeIP); | ||
316 | - } | ||
317 | - } | ||
318 | - } | ||
319 | - timeout = Timer.getTimer().newTimeout(new PurgeListTask(), timerDelay, TimeUnit.MINUTES); | ||
320 | - } | ||
321 | - | ||
322 | - } | ||
323 | - | ||
324 | } | 285 | } | ... | ... |
... | @@ -22,6 +22,7 @@ import org.onlab.packet.Ip4Address; | ... | @@ -22,6 +22,7 @@ import org.onlab.packet.Ip4Address; |
22 | import org.onlab.packet.MacAddress; | 22 | import org.onlab.packet.MacAddress; |
23 | import org.onosproject.dhcp.DhcpService; | 23 | import org.onosproject.dhcp.DhcpService; |
24 | import org.onosproject.dhcp.IpAssignment; | 24 | import org.onosproject.dhcp.IpAssignment; |
25 | +import org.onosproject.net.HostId; | ||
25 | import org.onosproject.rest.AbstractWebResource; | 26 | import org.onosproject.rest.AbstractWebResource; |
26 | 27 | ||
27 | import javax.ws.rs.Consumes; | 28 | import javax.ws.rs.Consumes; |
... | @@ -72,10 +73,10 @@ public class DHCPWebResource extends AbstractWebResource { | ... | @@ -72,10 +73,10 @@ public class DHCPWebResource extends AbstractWebResource { |
72 | public Response listMappings() { | 73 | public Response listMappings() { |
73 | ObjectNode root = mapper().createObjectNode(); | 74 | ObjectNode root = mapper().createObjectNode(); |
74 | 75 | ||
75 | - final Map<MacAddress, IpAssignment> intents = service.listMapping(); | 76 | + final Map<HostId, IpAssignment> intents = service.listMapping(); |
76 | ArrayNode arrayNode = root.putArray("mappings"); | 77 | ArrayNode arrayNode = root.putArray("mappings"); |
77 | intents.entrySet().forEach(i -> arrayNode.add(mapper().createObjectNode() | 78 | intents.entrySet().forEach(i -> arrayNode.add(mapper().createObjectNode() |
78 | - .put("mac", i.getKey().toString()) | 79 | + .put("host", i.getKey().toString()) |
79 | .put("ip", i.getValue().ipAddress().toString()))); | 80 | .put("ip", i.getValue().ipAddress().toString()))); |
80 | 81 | ||
81 | return ok(root.toString()).build(); | 82 | return ok(root.toString()).build(); |
... | @@ -125,10 +126,10 @@ public class DHCPWebResource extends AbstractWebResource { | ... | @@ -125,10 +126,10 @@ public class DHCPWebResource extends AbstractWebResource { |
125 | } | 126 | } |
126 | } | 127 | } |
127 | 128 | ||
128 | - final Map<MacAddress, IpAssignment> intents = service.listMapping(); | 129 | + final Map<HostId, IpAssignment> intents = service.listMapping(); |
129 | ArrayNode arrayNode = root.putArray("mappings"); | 130 | ArrayNode arrayNode = root.putArray("mappings"); |
130 | intents.entrySet().forEach(i -> arrayNode.add(mapper().createObjectNode() | 131 | intents.entrySet().forEach(i -> arrayNode.add(mapper().createObjectNode() |
131 | - .put("mac", i.getKey().toString()) | 132 | + .put("host", i.getKey().toString()) |
132 | .put("ip", i.getValue().ipAddress().toString()))); | 133 | .put("ip", i.getValue().ipAddress().toString()))); |
133 | } catch (IOException e) { | 134 | } catch (IOException e) { |
134 | throw new IllegalArgumentException(e.getMessage()); | 135 | throw new IllegalArgumentException(e.getMessage()); |
... | @@ -152,10 +153,10 @@ public class DHCPWebResource extends AbstractWebResource { | ... | @@ -152,10 +153,10 @@ public class DHCPWebResource extends AbstractWebResource { |
152 | if (!service.removeStaticMapping(MacAddress.valueOf(macID))) { | 153 | if (!service.removeStaticMapping(MacAddress.valueOf(macID))) { |
153 | throw new IllegalArgumentException("Static Mapping Removal Failed."); | 154 | throw new IllegalArgumentException("Static Mapping Removal Failed."); |
154 | } | 155 | } |
155 | - final Map<MacAddress, IpAssignment> intents = service.listMapping(); | 156 | + final Map<HostId, IpAssignment> intents = service.listMapping(); |
156 | ArrayNode arrayNode = root.putArray("mappings"); | 157 | ArrayNode arrayNode = root.putArray("mappings"); |
157 | intents.entrySet().forEach(i -> arrayNode.add(mapper().createObjectNode() | 158 | intents.entrySet().forEach(i -> arrayNode.add(mapper().createObjectNode() |
158 | - .put("mac", i.getKey().toString()) | 159 | + .put("host", i.getKey().toString()) |
159 | .put("ip", i.getValue().ipAddress().toString()))); | 160 | .put("ip", i.getValue().ipAddress().toString()))); |
160 | 161 | ||
161 | return ok(root.toString()).build(); | 162 | return ok(root.toString()).build(); | ... | ... |
... | @@ -17,7 +17,7 @@ | ... | @@ -17,7 +17,7 @@ |
17 | <div class="table-header" onos-sortable-header> | 17 | <div class="table-header" onos-sortable-header> |
18 | <table> | 18 | <table> |
19 | <tr> | 19 | <tr> |
20 | - <td colId="mac" sortable>MAC Address</td> | 20 | + <td colId="host" sortable>Host ID</td> |
21 | <td colId="ip" sortable>IP Address</td> | 21 | <td colId="ip" sortable>IP Address</td> |
22 | <td colId="lease" sortable>Lease Expiry</td> | 22 | <td colId="lease" sortable>Lease Expiry</td> |
23 | </tr> | 23 | </tr> |
... | @@ -25,7 +25,7 @@ | ... | @@ -25,7 +25,7 @@ |
25 | </div> | 25 | </div> |
26 | 26 | ||
27 | <div class="table-body"> | 27 | <div class="table-body"> |
28 | - <table onos-flash-changes id-prop="mac"> | 28 | + <table onos-flash-changes id-prop="host"> |
29 | <tr ng-if="!tableData.length" class="no-data"> | 29 | <tr ng-if="!tableData.length" class="no-data"> |
30 | <td colspan="2"> | 30 | <td colspan="2"> |
31 | No mappings found | 31 | No mappings found |
... | @@ -34,8 +34,8 @@ | ... | @@ -34,8 +34,8 @@ |
34 | 34 | ||
35 | <tr ng-repeat="dhcp in tableData track by $index" | 35 | <tr ng-repeat="dhcp in tableData track by $index" |
36 | ng-click="selectCallback($event, dhcp)" | 36 | ng-click="selectCallback($event, dhcp)" |
37 | - ng-repeat-complete row-id="{{dhcp.mac}}"> | 37 | + ng-repeat-complete row-id="{{dhcp.host}}"> |
38 | - <td>{{dhcp.mac}}</td> | 38 | + <td>{{dhcp.host}}</td> |
39 | <td>{{dhcp.ip}}</td> | 39 | <td>{{dhcp.ip}}</td> |
40 | <td>{{dhcp.lease}}</td> | 40 | <td>{{dhcp.lease}}</td> |
41 | </tr> | 41 | </tr> | ... | ... |
... | @@ -72,7 +72,7 @@ public class DhcpManagerTest { | ... | @@ -72,7 +72,7 @@ public class DhcpManagerTest { |
72 | 72 | ||
73 | protected HostProviderService hostProviderService; | 73 | protected HostProviderService hostProviderService; |
74 | 74 | ||
75 | - private static final MacAddress CLIENT1_MAC = MacAddress.valueOf("1a:1a:1a:1a:1a:1a"); | 75 | + private static final HostId CLIENT1_HOST = HostId.hostId(MacAddress.valueOf("1a:1a:1a:1a:1a:1a")); |
76 | 76 | ||
77 | private static final String EXPECTED_IP = "10.2.0.2"; | 77 | private static final String EXPECTED_IP = "10.2.0.2"; |
78 | 78 | ||
... | @@ -141,7 +141,7 @@ public class DhcpManagerTest { | ... | @@ -141,7 +141,7 @@ public class DhcpManagerTest { |
141 | 141 | ||
142 | // Ethernet Frame. | 142 | // Ethernet Frame. |
143 | Ethernet ethReply = new Ethernet(); | 143 | Ethernet ethReply = new Ethernet(); |
144 | - ethReply.setSourceMACAddress(CLIENT1_MAC); | 144 | + ethReply.setSourceMACAddress(CLIENT1_HOST.mac()); |
145 | ethReply.setDestinationMACAddress(MacAddress.BROADCAST); | 145 | ethReply.setDestinationMACAddress(MacAddress.BROADCAST); |
146 | ethReply.setEtherType(Ethernet.TYPE_IPV4); | 146 | ethReply.setEtherType(Ethernet.TYPE_IPV4); |
147 | ethReply.setVlanID((short) 2); | 147 | ethReply.setVlanID((short) 2); |
... | @@ -165,7 +165,7 @@ public class DhcpManagerTest { | ... | @@ -165,7 +165,7 @@ public class DhcpManagerTest { |
165 | dhcpReply.setServerIPAddress(0); | 165 | dhcpReply.setServerIPAddress(0); |
166 | 166 | ||
167 | dhcpReply.setTransactionId(TRANSACTION_ID); | 167 | dhcpReply.setTransactionId(TRANSACTION_ID); |
168 | - dhcpReply.setClientHardwareAddress(CLIENT1_MAC.toBytes()); | 168 | + dhcpReply.setClientHardwareAddress(CLIENT1_HOST.mac().toBytes()); |
169 | dhcpReply.setHardwareType(DHCP.HWTYPE_ETHERNET); | 169 | dhcpReply.setHardwareType(DHCP.HWTYPE_ETHERNET); |
170 | dhcpReply.setHardwareAddressLength((byte) 6); | 170 | dhcpReply.setHardwareAddressLength((byte) 6); |
171 | 171 | ||
... | @@ -209,7 +209,7 @@ public class DhcpManagerTest { | ... | @@ -209,7 +209,7 @@ public class DhcpManagerTest { |
209 | */ | 209 | */ |
210 | private void validatePacket(Ethernet packet) { | 210 | private void validatePacket(Ethernet packet) { |
211 | DHCP dhcpPacket = (DHCP) packet.getPayload().getPayload().getPayload(); | 211 | DHCP dhcpPacket = (DHCP) packet.getPayload().getPayload().getPayload(); |
212 | - assertEquals(MacAddress.valueOf(dhcpPacket.getClientHardwareAddress()), CLIENT1_MAC); | 212 | + assertEquals(MacAddress.valueOf(dhcpPacket.getClientHardwareAddress()), CLIENT1_HOST.mac()); |
213 | assertEquals(Ip4Address.valueOf(dhcpPacket.getYourIPAddress()), Ip4Address.valueOf(EXPECTED_IP)); | 213 | assertEquals(Ip4Address.valueOf(dhcpPacket.getYourIPAddress()), Ip4Address.valueOf(EXPECTED_IP)); |
214 | assertEquals(dhcpPacket.getTransactionId(), TRANSACTION_ID); | 214 | assertEquals(dhcpPacket.getTransactionId(), TRANSACTION_ID); |
215 | } | 215 | } |
... | @@ -223,32 +223,29 @@ public class DhcpManagerTest { | ... | @@ -223,32 +223,29 @@ public class DhcpManagerTest { |
223 | public void populateIPPoolfromRange(Ip4Address startIP, Ip4Address endIP) { | 223 | public void populateIPPoolfromRange(Ip4Address startIP, Ip4Address endIP) { |
224 | } | 224 | } |
225 | 225 | ||
226 | - public Ip4Address suggestIP(MacAddress macID, Ip4Address requestedIP) { | 226 | + public Ip4Address suggestIP(HostId hostId, Ip4Address requestedIP) { |
227 | return Ip4Address.valueOf(EXPECTED_IP); | 227 | return Ip4Address.valueOf(EXPECTED_IP); |
228 | } | 228 | } |
229 | 229 | ||
230 | - public boolean assignIP(MacAddress macID, Ip4Address ipAddr, int leaseTime) { | 230 | + public boolean assignIP(HostId hostId, Ip4Address ipAddr, int leaseTime) { |
231 | return true; | 231 | return true; |
232 | } | 232 | } |
233 | 233 | ||
234 | public void setDefaultTimeoutForPurge(int timeInSeconds) { | 234 | public void setDefaultTimeoutForPurge(int timeInSeconds) { |
235 | } | 235 | } |
236 | 236 | ||
237 | - public void setTimerDelay(int timeInSeconds) { | 237 | + public void releaseIP(HostId hostId) { |
238 | } | 238 | } |
239 | 239 | ||
240 | - public void releaseIP(MacAddress macID) { | 240 | + public Map<HostId, IpAssignment> listMapping() { |
241 | - } | 241 | + Map<HostId, IpAssignment> map = new HashMap<>(); |
242 | - | ||
243 | - public Map<MacAddress, IpAssignment> listMapping() { | ||
244 | - Map<MacAddress, IpAssignment> map = new HashMap<>(); | ||
245 | IpAssignment assignment = IpAssignment.builder() | 242 | IpAssignment assignment = IpAssignment.builder() |
246 | .ipAddress(Ip4Address.valueOf(EXPECTED_IP)) | 243 | .ipAddress(Ip4Address.valueOf(EXPECTED_IP)) |
247 | .assignmentStatus(IpAssignment.AssignmentStatus.Option_Assigned) | 244 | .assignmentStatus(IpAssignment.AssignmentStatus.Option_Assigned) |
248 | .leasePeriod(300) | 245 | .leasePeriod(300) |
249 | .timestamp(new Date()) | 246 | .timestamp(new Date()) |
250 | .build(); | 247 | .build(); |
251 | - map.put(CLIENT1_MAC, assignment); | 248 | + map.put(CLIENT1_HOST, assignment); |
252 | return map; | 249 | return map; |
253 | } | 250 | } |
254 | 251 | ... | ... |
... | @@ -11,9 +11,7 @@ | ... | @@ -11,9 +11,7 @@ |
11 | "ttl": "63", | 11 | "ttl": "63", |
12 | "lease": "300", | 12 | "lease": "300", |
13 | "renew": "150", | 13 | "renew": "150", |
14 | - "rebind": "200" | 14 | + "rebind": "200", |
15 | - }, | ||
16 | - "dhcpstore" : { | ||
17 | "delay": "3", | 15 | "delay": "3", |
18 | "timeout": "150", | 16 | "timeout": "150", |
19 | "startip": "10.0.0.110", | 17 | "startip": "10.0.0.110", | ... | ... |
-
Please register or login to post a comment