Committed by
Gerrit Code Review
add a delete vBNG feature
Change-Id: I21ce31d645be31320d06c36795e6b044f11924ab
Showing
5 changed files
with
110 additions
and
5 deletions
... | @@ -182,6 +182,27 @@ public class VbngConfigurationManager implements VbngConfigurationService { | ... | @@ -182,6 +182,27 @@ public class VbngConfigurationManager implements VbngConfigurationService { |
182 | return ipAddressMap.containsValue(ipAddress); | 182 | return ipAddressMap.containsValue(ipAddress); |
183 | } | 183 | } |
184 | 184 | ||
185 | + @Override | ||
186 | + public IpAddress recycleAssignedPublicIpAddress(IpAddress | ||
187 | + privateIpAddress) { | ||
188 | + IpAddress publicIpAddress = ipAddressMap.remove(privateIpAddress); | ||
189 | + if (publicIpAddress == null) { | ||
190 | + return null; | ||
191 | + } | ||
192 | + | ||
193 | + Iterator<Entry<IpPrefix, Boolean>> prefixes = | ||
194 | + localPublicIpPrefixes.entrySet().iterator(); | ||
195 | + while (prefixes.hasNext()) { | ||
196 | + Entry<IpPrefix, Boolean> prefixEntry = prefixes.next(); | ||
197 | + if (prefixEntry.getKey().contains(publicIpAddress) | ||
198 | + && !prefixEntry.getValue()) { | ||
199 | + updateIpPrefixStatus(prefixEntry.getKey(), true); | ||
200 | + } | ||
201 | + } | ||
202 | + | ||
203 | + return publicIpAddress; | ||
204 | + } | ||
205 | + | ||
185 | /** | 206 | /** |
186 | * Generates a new IP address base on a given IP address plus a number to | 207 | * Generates a new IP address base on a given IP address plus a number to |
187 | * increase. | 208 | * increase. | ... | ... |
... | @@ -61,4 +61,14 @@ public interface VbngConfigurationService { | ... | @@ -61,4 +61,14 @@ public interface VbngConfigurationService { |
61 | * @return the assigned public IP address if it exists, otherwise null | 61 | * @return the assigned public IP address if it exists, otherwise null |
62 | */ | 62 | */ |
63 | IpAddress getAssignedPublicIpAddress(IpAddress privateIpAddress); | 63 | IpAddress getAssignedPublicIpAddress(IpAddress privateIpAddress); |
64 | + | ||
65 | + /** | ||
66 | + * Recycles the public IP address assigned for a private IP address, and | ||
67 | + * at the same time deletes the mapping entry from this private IP address | ||
68 | + * to the public IP address. | ||
69 | + * | ||
70 | + * @param privateIpAddress a private IP address | ||
71 | + * @return the assigned public IP address if it exists, otherwise null | ||
72 | + */ | ||
73 | + IpAddress recycleAssignedPublicIpAddress(IpAddress privateIpAddress); | ||
64 | } | 74 | } | ... | ... |
... | @@ -91,7 +91,6 @@ public class VbngManager implements VbngService { | ... | @@ -91,7 +91,6 @@ public class VbngManager implements VbngService { |
91 | private HostListener hostListener; | 91 | private HostListener hostListener; |
92 | private IpAddress nextHopIpAddress; | 92 | private IpAddress nextHopIpAddress; |
93 | 93 | ||
94 | - | ||
95 | @Activate | 94 | @Activate |
96 | public void activate() { | 95 | public void activate() { |
97 | appId = coreService.registerApplication(APP_NAME); | 96 | appId = coreService.registerApplication(APP_NAME); |
... | @@ -133,6 +132,47 @@ public class VbngManager implements VbngService { | ... | @@ -133,6 +132,47 @@ public class VbngManager implements VbngService { |
133 | return publicIpAddress; | 132 | return publicIpAddress; |
134 | } | 133 | } |
135 | 134 | ||
135 | + @Override | ||
136 | + public IpAddress deleteVbng(IpAddress privateIpAddress) { | ||
137 | + // Recycle the public IP address assigned to this private IP address. | ||
138 | + // Recycling will also delete the mapping entry from the private IP | ||
139 | + // address to public IP address. | ||
140 | + IpAddress assignedPublicIpAddress = vbngConfigurationService | ||
141 | + .recycleAssignedPublicIpAddress(privateIpAddress); | ||
142 | + if (assignedPublicIpAddress == null) { | ||
143 | + return null; | ||
144 | + } | ||
145 | + | ||
146 | + // Remove the private IP address from privateIpAddressSet | ||
147 | + privateIpAddressSet.remove(privateIpAddress); | ||
148 | + | ||
149 | + // Remove intents | ||
150 | + removeForwardingPaths(privateIpAddress); | ||
151 | + | ||
152 | + return assignedPublicIpAddress; | ||
153 | + } | ||
154 | + | ||
155 | + /** | ||
156 | + * Removes the forwarding paths in both two directions between host | ||
157 | + * configured with private IP and next hop. | ||
158 | + * | ||
159 | + * @param privateIp the private IP address of a local host | ||
160 | + */ | ||
161 | + private void removeForwardingPaths(IpAddress privateIp) { | ||
162 | + PointToPointIntent toNextHopIntent = | ||
163 | + p2pIntentsFromHost.remove(privateIp); | ||
164 | + if (toNextHopIntent != null) { | ||
165 | + intentService.withdraw(toNextHopIntent); | ||
166 | + //intentService.purge(toNextHopIntent); | ||
167 | + } | ||
168 | + PointToPointIntent toLocalHostIntent = | ||
169 | + p2pIntentsToHost.remove(privateIp); | ||
170 | + if (toLocalHostIntent != null) { | ||
171 | + intentService.withdraw(toLocalHostIntent); | ||
172 | + //intentService.purge(toLocalHostIntent); | ||
173 | + } | ||
174 | + } | ||
175 | + | ||
136 | /** | 176 | /** |
137 | * Sets up forwarding paths in both two directions between host configured | 177 | * Sets up forwarding paths in both two directions between host configured |
138 | * with private IP and next hop. | 178 | * with private IP and next hop. |
... | @@ -207,7 +247,7 @@ public class VbngManager implements VbngService { | ... | @@ -207,7 +247,7 @@ public class VbngManager implements VbngService { |
207 | localHost.mac(), | 247 | localHost.mac(), |
208 | localHostConnectPoint, | 248 | localHostConnectPoint, |
209 | nextHopConnectPoint); | 249 | nextHopConnectPoint); |
210 | - p2pIntentsToHost.put(nextHopIpAddress, toLocalHostIntent); | 250 | + p2pIntentsToHost.put(privateIp, toLocalHostIntent); |
211 | intentService.submit(toLocalHostIntent); | 251 | intentService.submit(toLocalHostIntent); |
212 | } | 252 | } |
213 | 253 | ... | ... |
... | @@ -17,6 +17,7 @@ package org.onosproject.virtualbng; | ... | @@ -17,6 +17,7 @@ package org.onosproject.virtualbng; |
17 | 17 | ||
18 | import static org.slf4j.LoggerFactory.getLogger; | 18 | import static org.slf4j.LoggerFactory.getLogger; |
19 | 19 | ||
20 | +import javax.ws.rs.DELETE; | ||
20 | import javax.ws.rs.POST; | 21 | import javax.ws.rs.POST; |
21 | import javax.ws.rs.Path; | 22 | import javax.ws.rs.Path; |
22 | import javax.ws.rs.PathParam; | 23 | import javax.ws.rs.PathParam; |
... | @@ -35,13 +36,13 @@ public class VbngResource extends BaseResource { | ... | @@ -35,13 +36,13 @@ public class VbngResource extends BaseResource { |
35 | 36 | ||
36 | @POST | 37 | @POST |
37 | @Path("{privateip}") | 38 | @Path("{privateip}") |
38 | - public String privateIpNotification(@PathParam("privateip") | 39 | + public String privateIpAddNotification(@PathParam("privateip") |
39 | String privateIp) { | 40 | String privateIp) { |
40 | if (privateIp == null) { | 41 | if (privateIp == null) { |
41 | - log.info("Private IP address is null"); | 42 | + log.info("Private IP address to add is null"); |
42 | return "0"; | 43 | return "0"; |
43 | } | 44 | } |
44 | - log.info("Received a private IP address : {}", privateIp); | 45 | + log.info("Received a private IP address : {} to add", privateIp); |
45 | IpAddress privateIpAddress = IpAddress.valueOf(privateIp); | 46 | IpAddress privateIpAddress = IpAddress.valueOf(privateIp); |
46 | 47 | ||
47 | VbngService vbngService = get(VbngService.class); | 48 | VbngService vbngService = get(VbngService.class); |
... | @@ -56,4 +57,28 @@ public class VbngResource extends BaseResource { | ... | @@ -56,4 +57,28 @@ public class VbngResource extends BaseResource { |
56 | return "0"; | 57 | return "0"; |
57 | } | 58 | } |
58 | } | 59 | } |
60 | + | ||
61 | + @DELETE | ||
62 | + @Path("{privateip}") | ||
63 | + public String privateIpDeleteNotification(@PathParam("privateip") | ||
64 | + String privateIp) { | ||
65 | + if (privateIp == null) { | ||
66 | + log.info("Private IP address to delete is null"); | ||
67 | + return "0"; | ||
68 | + } | ||
69 | + log.info("Received a private IP address : {} to delete", privateIp); | ||
70 | + IpAddress privateIpAddress = IpAddress.valueOf(privateIp); | ||
71 | + | ||
72 | + VbngService vbngService = get(VbngService.class); | ||
73 | + | ||
74 | + IpAddress assignedPublicIpAddress = null; | ||
75 | + // Delete a virtual BNG | ||
76 | + assignedPublicIpAddress = vbngService.deleteVbng(privateIpAddress); | ||
77 | + | ||
78 | + if (assignedPublicIpAddress != null) { | ||
79 | + return assignedPublicIpAddress.toString(); | ||
80 | + } else { | ||
81 | + return "0"; | ||
82 | + } | ||
83 | + } | ||
59 | } | 84 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -36,4 +36,13 @@ public interface VbngService { | ... | @@ -36,4 +36,13 @@ public interface VbngService { |
36 | */ | 36 | */ |
37 | IpAddress createVbng(IpAddress privateIpAddress); | 37 | IpAddress createVbng(IpAddress privateIpAddress); |
38 | 38 | ||
39 | + /** | ||
40 | + * Deletes a virtual BNG. | ||
41 | + * | ||
42 | + * @param privateIpAddress a private IP address | ||
43 | + * @return the public address assigned for this private IP address if the | ||
44 | + * virtual BGN exists and is deleted, otherwise return null if | ||
45 | + * there is no vBNG for this private IP address | ||
46 | + */ | ||
47 | + IpAddress deleteVbng(IpAddress privateIpAddress); | ||
39 | } | 48 | } | ... | ... |
-
Please register or login to post a comment