Pingping Lin | ffa27d3 | 2015-04-30 14:41:03 -0700 | [diff] [blame] | 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 | package org.onosproject.virtualbng; |
| 17 | |
| 18 | import static org.slf4j.LoggerFactory.getLogger; |
| 19 | |
| 20 | import javax.ws.rs.POST; |
| 21 | import javax.ws.rs.Path; |
| 22 | import javax.ws.rs.PathParam; |
| 23 | |
| 24 | import org.onlab.packet.IpAddress; |
| 25 | import org.onlab.rest.BaseResource; |
| 26 | import org.slf4j.Logger; |
| 27 | |
| 28 | /** |
| 29 | * This class provides REST services to virtual BNG. |
| 30 | */ |
| 31 | @Path("privateip") |
| 32 | public class VbngResource extends BaseResource { |
| 33 | |
| 34 | private final Logger log = getLogger(getClass()); |
| 35 | |
| 36 | @POST |
| 37 | @Path("{privateip}") |
| 38 | public String privateIpNotification(@PathParam("privateip") |
| 39 | String privateIp) { |
| 40 | if (privateIp == null) { |
| 41 | log.info("Private IP address is null"); |
| 42 | return "0"; |
| 43 | } |
| 44 | log.info("Received a private IP address : {}", privateIp); |
| 45 | IpAddress privateIpAddress = IpAddress.valueOf(privateIp); |
| 46 | |
| 47 | VbngService vbngService = get(VbngService.class); |
| 48 | |
| 49 | IpAddress publicIpAddress = null; |
Pingping Lin | 99d0b20 | 2015-05-05 14:08:48 -0700 | [diff] [blame] | 50 | // Create a virtual BNG |
| 51 | publicIpAddress = vbngService.createVbng(privateIpAddress); |
Pingping Lin | ffa27d3 | 2015-04-30 14:41:03 -0700 | [diff] [blame] | 52 | |
| 53 | if (publicIpAddress != null) { |
| 54 | return publicIpAddress.toString(); |
| 55 | } else { |
| 56 | return "0"; |
| 57 | } |
| 58 | } |
| 59 | } |