REST interface for VPLS application

Change-Id: I2cab5bd6ff0ce026d0ef844bba6199fdd7f3e50d
This repository contains the files that provide a REST interface for VPLS
application.I create a new package in org.onosproject.vpls
called rest that contains the java classes VplsWebApplication and
VplsWebResource. The VplsWebResource provides create/update/read/delete
(CURD) functionality, leveraging the methods defined in the Vpls java
interface. I create a new folder called resources that contains
the json definitions and the files for the "web page".
diff --git a/apps/vpls/BUILD b/apps/vpls/BUILD
index e2a2c69..20fac7a 100644
--- a/apps/vpls/BUILD
+++ b/apps/vpls/BUILD
@@ -4,12 +4,17 @@
 ]
 
 osgi_jar_with_tests(
+    api_description = "REST API for Vpls ",
+    api_package = "org.onosproject.vpls.rest",
+    api_title = "VPLS REST",
+    api_version = "1.0",
     exclude_tests = ["org.onosproject.vpls.VplsTest"],
     karaf_command_packages = [
         "org.onosproject.vpls.cli",
         "org.onosproject.vpls.cli.completer",
     ],
     test_deps = TEST_ADAPTERS,
+    web_context = "/onos/vpls",
     deps = COMPILE_DEPS,
 )
 
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/VplsManager.java b/apps/vpls/src/main/java/org/onosproject/vpls/VplsManager.java
index 425f77d..293f92b 100644
--- a/apps/vpls/src/main/java/org/onosproject/vpls/VplsManager.java
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/VplsManager.java
@@ -16,6 +16,7 @@
 package org.onosproject.vpls;
 
 import com.google.common.collect.ImmutableSet;
+import org.onosproject.codec.CodecService;
 import org.onosproject.net.EncapsulationType;
 import org.onosproject.net.Host;
 import org.onosproject.net.host.HostEvent;
@@ -29,6 +30,7 @@
 import org.onosproject.vpls.api.VplsOperation;
 import org.onosproject.vpls.api.VplsOperationService;
 import org.onosproject.vpls.api.VplsStore;
+import org.onosproject.vpls.rest.VplsCodec;
 import org.onosproject.vpls.store.VplsStoreEvent;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
@@ -65,9 +67,13 @@
     @Reference(cardinality = ReferenceCardinality.MANDATORY)
     protected VplsOperationService operationService;
 
+    @Reference(cardinality = ReferenceCardinality.MANDATORY)
+    protected CodecService codecService;
+
     private StoreDelegate<VplsStoreEvent> vplsStoreDelegate;
     private HostListener vplsHostListener;
 
+
     @Activate
     public void activate() {
         vplsStoreDelegate = new VplsStoreDelegate();
@@ -75,12 +81,14 @@
 
         vplsStore.setDelegate(vplsStoreDelegate);
         hostService.addListener(vplsHostListener);
+        codecService.registerCodec(VplsData.class, new VplsCodec());
     }
 
     @Deactivate
     public void deactivate() {
         vplsStore.unsetDelegate(vplsStoreDelegate);
         hostService.removeListener(vplsHostListener);
+        codecService.unregisterCodec(VplsData.class);
     }
 
     @Override
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/rest/VplsCodec.java b/apps/vpls/src/main/java/org/onosproject/vpls/rest/VplsCodec.java
new file mode 100644
index 0000000..8f8bf3f
--- /dev/null
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/rest/VplsCodec.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2020-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.vpls.rest;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.codec.CodecContext;
+import org.onosproject.codec.JsonCodec;
+import org.onosproject.net.EncapsulationType;
+import org.onosproject.net.intf.Interface;
+import org.onosproject.vpls.api.VplsData;
+import org.slf4j.Logger;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.stream.IntStream;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.slf4j.LoggerFactory.getLogger;
+/**
+ * Vpls JSON codec.
+ */
+public final class VplsCodec extends JsonCodec<VplsData> {
+
+    // JSON field names
+    private static final String NAME = "name";
+    private static final String ENCAPSULATION_TYPE = "encapsulation";
+    private static final String INTERFACES = "interfaces";
+
+    private final Logger log = getLogger(getClass());
+
+    @Override
+    public ObjectNode encode(VplsData vplsData, CodecContext context) {
+        checkNotNull(vplsData, "Vpls cannot be null");
+        ObjectNode result = context.mapper().createObjectNode()
+                .put(NAME, vplsData.name())
+                .put(ENCAPSULATION_TYPE, vplsData.encapsulationType().toString());
+        ArrayNode interfaces = context.mapper().createArrayNode();
+        vplsData.interfaces().forEach(interf -> {
+            ObjectNode bandJson = context.codec(Interface.class).encode(interf, context);
+            interfaces.add(bandJson);
+        });
+        result.set(INTERFACES, interfaces);
+        return result;
+    }
+    @Override
+    public VplsData decode(ObjectNode json, CodecContext context) {
+        if (json == null || !json.isObject()) {
+            return null;
+        }
+
+        String vplsName = json.findValue(NAME).asText();
+        EncapsulationType encap = EncapsulationType.enumFromString(json.findValue(ENCAPSULATION_TYPE).asText());
+        VplsData vplsData = VplsData.of(vplsName, encap);
+
+        Collection<Interface> interfaceList = new ArrayList<>();
+        JsonNode interfacesJeson = json.findValue(INTERFACES);
+        JsonCodec<Interface> interfaceCodec = context.codec(Interface.class);
+        if (interfacesJeson != null) {
+            IntStream.range(0, interfacesJeson.size())
+                    .forEach(i -> interfaceList.add(
+                            interfaceCodec.decode(get(interfacesJeson, i),
+                                    context)));
+            vplsData.addInterfaces(interfaceList);
+        }
+        return vplsData;
+    }
+
+}
+
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/rest/VplsWebApplication.java b/apps/vpls/src/main/java/org/onosproject/vpls/rest/VplsWebApplication.java
new file mode 100644
index 0000000..0581130
--- /dev/null
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/rest/VplsWebApplication.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2020-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.vpls.rest;
+
+import org.onlab.rest.AbstractWebApplication;
+
+import java.util.Set;
+
+/**
+ * VPLS web application.
+ */
+public class VplsWebApplication extends AbstractWebApplication {
+    @Override
+    public Set<Class<?>> getClasses() {
+        return getClasses(VplsWebResource.class);
+    }
+}
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/rest/VplsWebResource.java b/apps/vpls/src/main/java/org/onosproject/vpls/rest/VplsWebResource.java
new file mode 100644
index 0000000..ae227ed
--- /dev/null
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/rest/VplsWebResource.java
@@ -0,0 +1,222 @@
+/*
+ * Copyright 2020-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.vpls.rest;
+
+
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.net.intf.Interface;
+import org.onosproject.net.intf.InterfaceAdminService;
+import org.onosproject.rest.AbstractWebResource;
+import org.onosproject.vpls.api.Vpls;
+import org.onosproject.vpls.api.VplsData;
+
+import org.slf4j.Logger;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.core.MediaType;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.ArrayList;
+
+
+import static org.onlab.util.Tools.readTreeFromStream;
+import static org.onlab.util.Tools.nullIsNotFound;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Query and program Vplss.
+ */
+@Path("vpls")
+public class VplsWebResource extends AbstractWebResource {
+    @Context
+    private UriInfo uriInfo;
+
+    private static final String VPLS_NOT_FOUND = "Vpls is not found for ";
+    private static final String VPLSS = "vplss";
+    private static final String VPLS = "vpls";
+    private static final String INTERFACES = "interfaces";
+
+    private final ObjectNode root = mapper().createObjectNode();
+    private final Logger log = getLogger(getClass());
+    /**
+     * Gets all Vplss. Returns array of all Vplss in the system.
+     *
+     * @return 200 OK with a collection of Vplss
+     * @onos.rsModel Vplss
+     */
+    @GET
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response getVplss() {
+        ArrayNode vplssNode = root.putArray(VPLSS);
+        Vpls service = get(Vpls.class);
+        Collection<VplsData> vplsDatas = service.getAllVpls();
+        if (!vplsDatas.isEmpty()) {
+            for (VplsData entry : vplsDatas) {
+                vplssNode.add(codec(VplsData.class).encode(entry, this));
+            }
+        }
+
+        return ok(root).build();
+    }
+
+    /**
+     * Gets Vpls. Returns a Vpls by vplsName.
+     * @param  vplsName  vpls name
+     * @return 200 OK with a vpls, return 404 if no entry has been found
+     * @onos.rsModel Vpls
+     */
+    @GET
+    @Produces(MediaType.APPLICATION_JSON)
+    @Path("{vplsName}")
+    public Response getVpls(@PathParam("vplsName") String vplsName) {
+        ArrayNode vplsNode = root.putArray(VPLS);
+        Vpls service = get(Vpls.class);
+        final VplsData vplsData = nullIsNotFound(service.getVpls(vplsName),
+                VPLS_NOT_FOUND + vplsName);
+        vplsNode.add(codec(VplsData.class).encode(vplsData, this));
+
+        return ok(root).build();
+    }
+    /**
+     * Creates new vpls. Creates and installs a new Vplps.<br>
+     *
+     * @param stream Vpls JSON
+     * @return status of the request - CREATED if the JSON is correct,
+     * BAD_REQUEST if the JSON is invalid
+     * @onos.rsModel VplsPost
+     */
+    @POST
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response createVpls(InputStream stream) {
+        Vpls service = get(Vpls.class);
+        InterfaceAdminService interfaceService = get(InterfaceAdminService.class);
+        try {
+            ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
+
+            VplsData vplsData = codec(VplsData.class).decode(jsonTree, this);
+            vplsData.interfaces().forEach(interf -> {
+                    interfaceService.add(interf);
+            });
+            service.addInterfaces(vplsData, vplsData.interfaces());
+
+            UriBuilder locationBuilder = uriInfo.getBaseUriBuilder()
+                    .path(VPLS);
+            return Response
+                    .created(locationBuilder.build())
+                    .build();
+
+            } catch (IOException e) {
+            throw new IllegalArgumentException(e.getMessage());
+        }
+
+    }
+
+    /**
+     * Add new interfaces. Add new interfaces to a Vpls.<br>
+     *
+     * @param stream interfaces JSON
+     * @param vplsName Vpls name
+     * @return status of the request - CREATED if the JSON is correct,
+     * BAD_REQUEST if the JSON is invalid
+     * @onos.rsModel InterfacesPost
+     */
+    @POST
+    @Path("interfaces/{vplsName}")
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response addInterfaces(@PathParam("vplsName") String vplsName, InputStream stream) {
+        Vpls service = get(Vpls.class);
+        InterfaceAdminService interfaceService = get(InterfaceAdminService.class);
+        final VplsData vplsData = nullIsNotFound(service.getVpls(vplsName),
+                VPLS_NOT_FOUND + vplsName);
+        try {
+            ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
+            Collection<Interface> interfaceList = new ArrayList<>();
+            jsonTree.forEach(interf -> {
+                Interface inter = codec(Interface.class).decode(jsonTree, this);
+                interfaceList.add(inter);
+                interfaceService.add(inter);
+            });
+            service.addInterfaces(vplsData, interfaceList);
+            UriBuilder locationBuilder = uriInfo.getBaseUriBuilder()
+                    .path(INTERFACES)
+                    .path(vplsName);
+            return Response
+                    .created(locationBuilder.build())
+                    .build();
+
+        } catch (IOException e) {
+            throw new IllegalArgumentException(e.getMessage());
+        }
+
+    }
+
+    /**
+     * Removes the specified vpls.
+     *
+     * @param vplsName Vpls name
+     * @return 204 NO CONTENT
+     */
+    @DELETE
+    @Path("{vplsName}")
+    public Response deleteVpls(@PathParam("vplsName") String vplsName) {
+        Vpls service = get(Vpls.class);
+        final VplsData vplsData = nullIsNotFound(service.getVpls(vplsName),
+                VPLS_NOT_FOUND + vplsName);
+        service.removeVpls(vplsData);
+        return Response.noContent().build();
+    }
+
+    /**
+     * Removes a specified interface.
+     *
+     * @param vplsName Vpls name
+     * @param interfaceName interface name
+     * @return 204 NO CONTENT
+     *
+     */
+    @DELETE
+    @Path("interface/{vplsName}/{interfaceName}")
+    public Response deleteInterface(@PathParam("vplsName") String vplsName,
+                                    @PathParam("interfaceName") String interfaceName) {
+        Vpls service = get(Vpls.class);
+        InterfaceAdminService interfaceService = get(InterfaceAdminService.class);
+        final VplsData vplsData = nullIsNotFound(service.getVpls(vplsName),
+                VPLS_NOT_FOUND + vplsName);
+        vplsData.interfaces().forEach(anInterface -> {
+            if (anInterface.name().equals(interfaceName)) {
+                interfaceService.remove(anInterface.connectPoint(), anInterface.name());
+                service.removeInterface(vplsData, anInterface);
+            }
+        });
+
+        return Response.noContent().build();
+    }
+
+}
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/rest/package-info.java b/apps/vpls/src/main/java/org/onosproject/vpls/rest/package-info.java
new file mode 100644
index 0000000..f8adcdf
--- /dev/null
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/rest/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Implementation REST for VPLS services.
+ */
+package org.onosproject.vpls.rest;
\ No newline at end of file
diff --git a/apps/vpls/src/main/resources/definitions/InterfacesPost.json b/apps/vpls/src/main/resources/definitions/InterfacesPost.json
new file mode 100644
index 0000000..c605c92
--- /dev/null
+++ b/apps/vpls/src/main/resources/definitions/InterfacesPost.json
@@ -0,0 +1,50 @@
+{
+  "type": "object",
+  "title": "interfaces",
+  "required": [
+    "interfaces"
+  ],
+  "properties": {
+    "interfaces": {
+      "type": "array",
+      "xml": {
+        "name": "interfaces",
+        "wrapped": true
+      },
+      "items": {
+        "type": "object",
+        "title": "interfaces",
+        "required": [
+          "name",
+          "connect point",
+          "ips",
+          "mac",
+          "vlan"
+        ],
+        "properties": {
+          "name": {
+            "type": "string",
+            "example": "h1"
+          },
+          "connect point": {
+            "type": "string",
+            "example": "of:0000000000000001/1"
+          },
+          "ips": {
+            "type": "array",
+            "example": ["10.0.1.1/24"]
+          },
+          "mac": {
+            "type": "string",
+            "example": "00:04:00:00:00:02"
+          },
+          "vlan": {
+            "type": "string",
+            "example": "100"
+          }
+        }
+      }
+    }
+  }
+}
+
diff --git a/apps/vpls/src/main/resources/definitions/Vpls.json b/apps/vpls/src/main/resources/definitions/Vpls.json
new file mode 100644
index 0000000..611ea6d
--- /dev/null
+++ b/apps/vpls/src/main/resources/definitions/Vpls.json
@@ -0,0 +1,65 @@
+{
+  "type": "object",
+  "title": "vpls",
+
+  "required": [
+    "name"
+  ],
+  "properties": {
+    "name": {
+      "type": "String",
+      "example": "VPLS1"
+    },
+    "Interfaces": {
+      "type": "array",
+      "xml": {
+        "name": "interfaces",
+        "wrapped": true
+      },
+      "items": {
+        "type": "object",
+        "title": "interfaces",
+        "required": [
+          "name",
+          "connectPoint",
+          "ips",
+          "mac",
+          "vlan"
+        ],
+        "properties": {
+          "name": {
+            "type": "string",
+            "example": "h1"
+          },
+          "properties": {
+            "connectPoint": {
+              "type": "string",
+              "example": "of:0000000000000001/1"
+            },
+            "ips": {
+              "type": "array",
+              "example": ["10.0.1.1/24"]
+            },
+            "mac": {
+              "type": "string",
+              "example": "00:04:00:00:00:02"
+            },
+            "vlan": {
+              "type": "string",
+              "example": "100"
+            }
+          }
+        }
+      },
+    "encap": {
+      "type": "String",
+      "example": "vlan"
+      },
+      "state": {
+        "type": "String",
+        "example": "ADDED"
+      }
+    }
+  }
+}
+
diff --git a/apps/vpls/src/main/resources/definitions/VplsPost.json b/apps/vpls/src/main/resources/definitions/VplsPost.json
new file mode 100644
index 0000000..88da89a
--- /dev/null
+++ b/apps/vpls/src/main/resources/definitions/VplsPost.json
@@ -0,0 +1,75 @@
+{
+  "type": "object",
+  "title": "vpls",
+  "required": [
+    "vpls"
+  ],
+  "properties": {
+    "vpls": {
+      "type": "array",
+      "xml": {
+        "name": "vpls",
+        "wrapped": true
+      },
+      "items": {
+        "type": "object",
+        "title": "vpls",
+        "required": [
+          "name",
+          "encapsulation"
+        ],
+        "properties": {
+          "name": {
+            "type": "string",
+            "example": "VPLS1"
+          },
+          "encapsulation": {
+            "type": "string",
+            "example": "VLAN"
+          },
+          "interfaces": {
+            "type": "array",
+            "xml": {
+              "name": "interfaces",
+              "wrapped": true
+            },
+            "items": {
+              "type": "object",
+              "title": "interfaces",
+              "required": [
+                "name",
+                "connect point",
+                "ips",
+                "mac",
+                "vlan"
+              ],
+              "properties": {
+                "name": {
+                  "type": "string",
+                  "example": "h1"
+                },
+                "connect point": {
+                  "type": "string",
+                  "example": "of:0000000000000001/1"
+                },
+                "ips": {
+                  "type": "array",
+                  "example": ["10.0.1.1/24"]
+                },
+                "mac": {
+                  "type": "string",
+                  "example": "00:04:00:00:00:02"
+                },
+                "vlan": {
+                  "type": "string",
+                  "example": "100"
+                }
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+}
+
diff --git a/apps/vpls/src/main/resources/definitions/Vplss.json b/apps/vpls/src/main/resources/definitions/Vplss.json
new file mode 100644
index 0000000..f1adbcc
--- /dev/null
+++ b/apps/vpls/src/main/resources/definitions/Vplss.json
@@ -0,0 +1,66 @@
+{
+  "type": "object",
+  "title": "vplss",
+
+  "required": [
+    "name"
+  ],
+  "properties": {
+    "name": {
+      "type": "String",
+      "example": "VPLS1"
+    },
+    "Interfaces": {
+      "type": "array",
+      "xml": {
+        "name": "interfaces",
+        "wrapped": true
+      },
+      "items": {
+        "type": "object",
+        "title": "interfaces",
+        "required": [
+          "name",
+          "connectPoint",
+          "ips",
+          "mac",
+          "vlan"
+        ],
+        "properties": {
+          "name": {
+            "type": "string",
+            "example": "h1"
+          },
+          "properties": {
+            "connectPoint": {
+              "type": "string",
+              "example": "of:0000000000000001/1"
+            },
+            "ips": {
+              "type": "array",
+              "example": ["10.0.1.1/24"]
+            },
+            "mac": {
+              "type": "string",
+              "example": "00:04:00:00:00:02"
+            },
+            "vlan": {
+              "type": "string",
+              "example": "100"
+            }
+          }
+        }
+      },
+      "encapsulation": {
+        "type": "String",
+        "example": "vlan"
+      },
+      "state": {
+        "type": "String",
+        "example": "ADDED"
+      }
+    }
+  }
+}
+
+
diff --git a/apps/vpls/src/main/webapp/WEB-INF/web.xml b/apps/vpls/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..9aa0e3f
--- /dev/null
+++ b/apps/vpls/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2020-present Open Networking Foundation
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xmlns="http://java.sun.com/xml/ns/javaee"
+         xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+         id="ONOS" version="2.5">
+    <display-name> Vpls REST API v1.0</display-name>
+
+    <security-constraint>
+        <web-resource-collection>
+            <web-resource-name>Secured</web-resource-name>
+            <url-pattern>/*</url-pattern>
+        </web-resource-collection>
+        <auth-constraint>
+            <role-name>admin</role-name>
+            <role-name>viewer</role-name>
+        </auth-constraint>
+    </security-constraint>
+
+    <security-role>
+        <role-name>admin</role-name>
+        <role-name>viewer</role-name>
+    </security-role>
+
+    <login-config>
+        <auth-method>BASIC</auth-method>
+        <realm-name>karaf</realm-name>
+    </login-config>
+
+    <servlet>
+        <servlet-name>JAX-RS Service</servlet-name>
+        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+        <init-param>
+            <param-name>javax.ws.rs.Application</param-name>
+            <param-value>org.onosproject.vpls.rest.VplsWebApplication</param-value>
+        </init-param>
+        <load-on-startup>1</load-on-startup>
+    </servlet>
+
+    <servlet-mapping>
+        <servlet-name>JAX-RS Service</servlet-name>
+        <url-pattern>/*</url-pattern>
+    </servlet-mapping>
+</web-app>
diff --git a/apps/vpls/src/test/java/org/onosproject/vpls/VplsManagerTest.java b/apps/vpls/src/test/java/org/onosproject/vpls/VplsManagerTest.java
index d9bba87..472860f 100644
--- a/apps/vpls/src/test/java/org/onosproject/vpls/VplsManagerTest.java
+++ b/apps/vpls/src/test/java/org/onosproject/vpls/VplsManagerTest.java
@@ -19,6 +19,8 @@
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.onosproject.codec.CodecService;
+import org.onosproject.codec.JsonCodec;
 import org.onosproject.net.EncapsulationType;
 import org.onosproject.net.host.HostEvent;
 import org.onosproject.vpls.api.VplsData;
@@ -27,6 +29,7 @@
 import org.onosproject.vpls.store.VplsStoreEvent;
 
 import java.util.Collection;
+import java.util.Set;
 
 import static org.junit.Assert.*;
 import static org.onosproject.net.EncapsulationType.*;
@@ -37,6 +40,7 @@
  */
 public class VplsManagerTest extends VplsTest {
     private VplsManager vplsManager;
+    private CodecService codecService = new TestCodecService();
     private TestVplsStore vplsStore = new TestVplsStore();
     private TestHostService hostService = new TestHostService();
     private TestInterfaceService interfaceService = new TestInterfaceService();
@@ -45,6 +49,7 @@
     @Before
     public void setup() {
         vplsManager = new VplsManager();
+        vplsManager.codecService = codecService;
         vplsManager.hostService = hostService;
         vplsManager.vplsStore = vplsStore;
         vplsManager.operationService = vplsOperationService;
@@ -336,4 +341,31 @@
         }
     }
 
+    /**
+     * Test Codec service.
+     */
+    class TestCodecService implements CodecService {
+
+
+        @Override
+        public Set<Class<?>> getCodecs() {
+            return null;
+        }
+
+        @Override
+        public <T> JsonCodec<T> getCodec(Class<T> entityClass) {
+            return null;
+        }
+
+        @Override
+        public <T> void registerCodec(Class<T> entityClass, JsonCodec<T> codec) {
+
+        }
+
+        @Override
+        public void unregisterCodec(Class<?> entityClass) {
+
+        }
+    }
+
 }
diff --git a/apps/vpls/src/test/java/org/onosproject/vpls/VplsTest.java b/apps/vpls/src/test/java/org/onosproject/vpls/VplsTest.java
index 6051f92..9920a22 100644
--- a/apps/vpls/src/test/java/org/onosproject/vpls/VplsTest.java
+++ b/apps/vpls/src/test/java/org/onosproject/vpls/VplsTest.java
@@ -629,6 +629,7 @@
         NetworkConfigListener listener;
         VplsAppConfig vplsAppConfig;
 
+
         @Override
         public void addListener(NetworkConfigListener listener) {
             this.listener = listener;
diff --git a/apps/vpls/src/test/java/resources/vpls-cfg.json b/apps/vpls/src/test/java/resources/vpls-cfg.json
new file mode 100644
index 0000000..5236124
--- /dev/null
+++ b/apps/vpls/src/test/java/resources/vpls-cfg.json
@@ -0,0 +1,67 @@
+{
+  "ports": {
+    "of:0000000000000001/1": {
+      "interfaces": [
+        {
+          "name": "h1",
+          "vlan": "100"
+        }
+      ]
+    },
+    "of:0000000000000002/1": {
+      "interfaces": [
+        {
+          "name": "h2",
+          "vlan": "200"
+        }
+      ]
+    },
+    "of:0000000000000003/1": {
+      "interfaces": [
+        {
+          "name": "h3",
+          "vlan": "300"
+        }
+      ]
+    },
+    "of:0000000000000004/1": {
+      "interfaces": [
+        {
+          "name": "h4",
+          "vlan": "400"
+        }
+      ]
+    },
+    "of:0000000000000005/1": {
+      "interfaces": [
+        {
+          "name": "h5"
+        }
+      ]
+    },
+    "of:0000000000000006/1": {
+      "interfaces": [
+        {
+          "name": "h6"
+        }
+      ]
+    }
+  },
+  "apps" : {
+    "org.onosproject.vpls" : {
+      "vpls" : {
+        "vplsList" : [
+          {
+            "name" : "VPLS1",
+            "interfaces" : ["h1", "h2", "h5", "h6"]
+          },
+          {
+            "name" : "VPLS2",
+            "interfaces" : ["h3", "h4"],
+            "encapsulation" : "vlan"
+          }
+        ]
+      }
+    }
+  }
+}
\ No newline at end of file