samanwita pal
Committed by Gerrit Code Review

DHCP Config changes + null pointer checks + ONOS-2881

Change-Id: Ice391f539ae816329fde7970d762380a36fd7661
...@@ -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 }
......
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,6 +146,7 @@ public class DistributedDhcpStore implements DhcpStore { ...@@ -156,6 +146,7 @@ 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();
149 + if (nextIPAddr != null) {
159 assignmentInfo = IpAssignment.builder() 150 assignmentInfo = IpAssignment.builder()
160 .ipAddress(nextIPAddr) 151 .ipAddress(nextIPAddr)
161 .timestamp(new Date()) 152 .timestamp(new Date())
...@@ -163,17 +154,18 @@ public class DistributedDhcpStore implements DhcpStore { ...@@ -163,17 +154,18 @@ public class DistributedDhcpStore implements DhcpStore {
163 .assignmentStatus(IpAssignment.AssignmentStatus.Option_Requested) 154 .assignmentStatus(IpAssignment.AssignmentStatus.Option_Requested)
164 .build(); 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,16 +194,18 @@ public class DistributedDhcpStore implements DhcpStore { ...@@ -202,16 +194,18 @@ 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);
204 + if ((freeIP.toInt() > startIPRange.toInt()) && (freeIP.toInt() < endIPRange.toInt())) {
212 freeIPPool.add(freeIP); 205 freeIPPool.add(freeIP);
213 } 206 }
214 } 207 }
208 + }
215 209
216 @Override 210 @Override
217 public void setDefaultTimeoutForPurge(int timeInSeconds) { 211 public void setDefaultTimeoutForPurge(int timeInSeconds) {
...@@ -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);
243 + if ((freeIP.toInt() > startIPRange.toInt()) && (freeIP.toInt() < endIPRange.toInt())) {
252 freeIPPool.add(freeIP); 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",
......