blob: 943698148654d6ea1565b910b0fd45d79f3b2d1a [file] [log] [blame]
Pingping Linffa27d32015-04-30 14:41:03 -07001/*
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 */
16package org.onosproject.virtualbng;
17
18import static org.slf4j.LoggerFactory.getLogger;
19
20import javax.ws.rs.POST;
21import javax.ws.rs.Path;
22import javax.ws.rs.PathParam;
23
24import org.onlab.packet.IpAddress;
25import org.onlab.rest.BaseResource;
26import org.slf4j.Logger;
27
28/**
29 * This class provides REST services to virtual BNG.
30 */
31@Path("privateip")
32public 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 Lin99d0b202015-05-05 14:08:48 -070050 // Create a virtual BNG
51 publicIpAddress = vbngService.createVbng(privateIpAddress);
Pingping Linffa27d32015-04-30 14:41:03 -070052
53 if (publicIpAddress != null) {
54 return publicIpAddress.toString();
55 } else {
56 return "0";
57 }
58 }
59}