Committed by
Gerrit Code Review
add a rest to get the IP address map to vBNG
Change-Id: I9f7c8cd082a5b6779fcb7d3636f873544f74d290
Showing
3 changed files
with
74 additions
and
2 deletions
| ... | @@ -73,10 +73,12 @@ | ... | @@ -73,10 +73,12 @@ |
| 73 | <Import-Package> | 73 | <Import-Package> |
| 74 | org.slf4j, | 74 | org.slf4j, |
| 75 | javax.ws.rs, | 75 | javax.ws.rs, |
| 76 | + javax.ws.rs.core, | ||
| 76 | com.sun.jersey.api.core, | 77 | com.sun.jersey.api.core, |
| 77 | com.sun.jersey.spi.container.servlet, | 78 | com.sun.jersey.spi.container.servlet, |
| 78 | com.sun.jersey.server.impl.container.servlet, | 79 | com.sun.jersey.server.impl.container.servlet, |
| 79 | com.fasterxml.jackson.databind, | 80 | com.fasterxml.jackson.databind, |
| 81 | + com.fasterxml.jackson.databind.node, | ||
| 80 | org.apache.karaf.shell.commands, | 82 | org.apache.karaf.shell.commands, |
| 81 | com.google.common.*, | 83 | com.google.common.*, |
| 82 | org.onlab.packet.*, | 84 | org.onlab.packet.*, | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2015 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 | + | ||
| 17 | +package org.onosproject.virtualbng; | ||
| 18 | + | ||
| 19 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 20 | + | ||
| 21 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
| 22 | + | ||
| 23 | +import java.util.Map.Entry; | ||
| 24 | + | ||
| 25 | +import org.onlab.packet.IpAddress; | ||
| 26 | +import org.onosproject.codec.CodecContext; | ||
| 27 | +import org.onosproject.codec.JsonCodec; | ||
| 28 | + | ||
| 29 | +/** | ||
| 30 | + * Codec for encoding a IP address mapping entry to JSON. | ||
| 31 | + */ | ||
| 32 | +public final class IpAddressMapEntryCodec extends JsonCodec<Entry<IpAddress, IpAddress>> { | ||
| 33 | + | ||
| 34 | + @Override | ||
| 35 | + public ObjectNode encode(Entry<IpAddress, IpAddress> entry, CodecContext context) { | ||
| 36 | + checkNotNull(entry, "IP address map entry cannot be null"); | ||
| 37 | + final ObjectNode result = context.mapper().createObjectNode() | ||
| 38 | + .put(entry.getKey().toString(), entry.getValue().toString()); | ||
| 39 | + | ||
| 40 | + return result; | ||
| 41 | + } | ||
| 42 | +} |
| ... | @@ -17,20 +17,29 @@ package org.onosproject.virtualbng; | ... | @@ -17,20 +17,29 @@ package org.onosproject.virtualbng; |
| 17 | 17 | ||
| 18 | import static org.slf4j.LoggerFactory.getLogger; | 18 | import static org.slf4j.LoggerFactory.getLogger; |
| 19 | 19 | ||
| 20 | +import com.fasterxml.jackson.databind.ObjectMapper; | ||
| 21 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
| 22 | + | ||
| 23 | +import java.util.Map; | ||
| 24 | + | ||
| 20 | import javax.ws.rs.DELETE; | 25 | import javax.ws.rs.DELETE; |
| 26 | +import javax.ws.rs.GET; | ||
| 21 | import javax.ws.rs.POST; | 27 | import javax.ws.rs.POST; |
| 22 | import javax.ws.rs.Path; | 28 | import javax.ws.rs.Path; |
| 23 | import javax.ws.rs.PathParam; | 29 | import javax.ws.rs.PathParam; |
| 30 | +import javax.ws.rs.Produces; | ||
| 31 | +import javax.ws.rs.core.MediaType; | ||
| 32 | +import javax.ws.rs.core.Response; | ||
| 24 | 33 | ||
| 25 | import org.onlab.packet.IpAddress; | 34 | import org.onlab.packet.IpAddress; |
| 26 | -import org.onlab.rest.BaseResource; | 35 | +import org.onosproject.rest.AbstractWebResource; |
| 27 | import org.slf4j.Logger; | 36 | import org.slf4j.Logger; |
| 28 | 37 | ||
| 29 | /** | 38 | /** |
| 30 | * This class provides REST services to virtual BNG. | 39 | * This class provides REST services to virtual BNG. |
| 31 | */ | 40 | */ |
| 32 | @Path("privateip") | 41 | @Path("privateip") |
| 33 | -public class VbngResource extends BaseResource { | 42 | +public class VbngResource extends AbstractWebResource { |
| 34 | 43 | ||
| 35 | private final Logger log = getLogger(getClass()); | 44 | private final Logger log = getLogger(getClass()); |
| 36 | 45 | ||
| ... | @@ -81,4 +90,23 @@ public class VbngResource extends BaseResource { | ... | @@ -81,4 +90,23 @@ public class VbngResource extends BaseResource { |
| 81 | return "0"; | 90 | return "0"; |
| 82 | } | 91 | } |
| 83 | } | 92 | } |
| 93 | + | ||
| 94 | + @GET | ||
| 95 | + @Path("map") | ||
| 96 | + @Produces(MediaType.APPLICATION_JSON) | ||
| 97 | + public Response privateIpDeleteNotification() { | ||
| 98 | + | ||
| 99 | + log.info("Received vBNG IP address map request"); | ||
| 100 | + | ||
| 101 | + VbngConfigurationService vbngConfigurationService = | ||
| 102 | + get(VbngConfigurationService.class); | ||
| 103 | + | ||
| 104 | + Map<IpAddress, IpAddress> map = | ||
| 105 | + vbngConfigurationService.getIpAddressMappings(); | ||
| 106 | + ObjectNode result = new ObjectMapper().createObjectNode(); | ||
| 107 | + | ||
| 108 | + result.set("map", new IpAddressMapEntryCodec().encode(map.entrySet(), this)); | ||
| 109 | + | ||
| 110 | + return ok(result.toString()).build(); | ||
| 111 | + } | ||
| 84 | } | 112 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment