Adding EVC rest enpoint for CarrierEthernet app

Change-Id: Ie6a1c0e5ab1fe1cd17d0fefb892f51cf540ead3e
diff --git a/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/app/CarrierEthernetEvcUtils.java b/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/app/CarrierEthernetEvcUtils.java
new file mode 100644
index 0000000..fab928b
--- /dev/null
+++ b/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/app/CarrierEthernetEvcUtils.java
@@ -0,0 +1,159 @@
+package org.onosproject.ecord.carrierethernet.app;
+
+import org.onlab.packet.VlanId;
+import org.onlab.util.Bandwidth;
+import org.onosproject.net.ConnectPoint;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import static org.onosproject.ecord.carrierethernet.app.CarrierEthernetVirtualConnection.MAX_NUM_UNI;
+
+/**
+ * Utilities to build EthernetVirtualConnections.
+ */
+public final class CarrierEthernetEvcUtils {
+
+    // no instantiation
+    private CarrierEthernetEvcUtils() {
+    }
+
+    /**
+     * Return the CE-VLAN ID for the CE evc based on the CLI-supplied argument.
+     *
+     * @param argCeVlanId vlanID
+     * @return CE-VLAN ID for the CE evc
+     */
+    public static VlanId generateCeVlanId(short argCeVlanId) {
+        return ((argCeVlanId == -1) ? null : VlanId.vlanId(argCeVlanId));
+    }
+
+    /**
+     * Return the CE evc type based on the CLI-supplied arguments.
+     *
+     * @param evcTypeString EVC type
+     * @param uniList       UNIs list
+     * @return the CE evc type
+     */
+    public static CarrierEthernetConnection.Type generateEvcType(String evcTypeString, List<String> uniList) {
+        if (evcTypeString == null) {
+            return ((uniList.size() > 2) ?
+                    CarrierEthernetConnection.Type.MULTIPOINT_TO_MULTIPOINT :
+                    CarrierEthernetConnection.Type.POINT_TO_POINT);
+        } else {
+            // TODO: Catch exception
+            return CarrierEthernetConnection.Type.valueOf(evcTypeString);
+        }
+    }
+
+    /**
+     * Return the EVC maxNumUni parameter based on the CLI-supplied arguments.
+     *
+     * @param maxNumUni     maximum numbers of UNIs
+     * @param evcTypeString EVC Type
+     * @param uniList       UNIs list
+     * @return the maxNumUni parameter
+     */
+    public static Integer generateMaxNumUni(int maxNumUni, String evcTypeString, List<String> uniList) {
+        if (maxNumUni == -1) {
+            if (evcTypeString == null) {
+                return ((uniList.size() > 2) ?
+                        MAX_NUM_UNI : 2);
+            } else {
+                // TODO: Catch exception
+                CarrierEthernetConnection.Type evcType =
+                        CarrierEthernetConnection.Type.valueOf(evcTypeString);
+                return (evcType.equals(CarrierEthernetConnection.Type.POINT_TO_POINT) ? 2 :
+                        MAX_NUM_UNI);
+            }
+        } else {
+            return maxNumUni;
+        }
+    }
+
+    /**
+     * Return the BW profile type based on the CLI-supplied arguments.
+     *
+     * @param ceVlanId vlanID
+     * @return the BWP profile type
+     */
+    public static CarrierEthernetBandwidthProfile.Type generateBandwidthProfileType(short ceVlanId) {
+        // TODO: Add the CoS BW profile case
+        return ((ceVlanId == -1) ?
+                CarrierEthernetBandwidthProfile.Type.INTERFACE : CarrierEthernetBandwidthProfile.Type.EVC);
+    }
+
+    /**
+     * Return the BW profile id based on the CLI-supplied arguments.
+     *
+     * @param uniId    UNI id
+     * @param evcCfgId EVC configuration Id
+     * @param ceVlanId vlanID
+     * @return the BW profile id
+     */
+    public static String generateBandwidthProfileId(String uniId, String evcCfgId, int ceVlanId) {
+        // TODO: Add the CoS BW profile case
+        return ((ceVlanId == -1) ? uniId : evcCfgId);
+    }
+
+    /**
+     * Return the set of UNIs for the CE EVC based on the CLI-supplied arguments.
+     *
+     * @param evcTypeString Type of the UNI
+     * @param uniList       list of remaning UNIs
+     * @param ceVlanId      vlanID
+     * @param firstUni      first UNI id
+     * @param evcCfgId      EVC configuration Id
+     * @param cir           The CIR in Mbps
+     * @param eir           The EIR in Mbps
+     * @param cbs           The CBS in Byte
+     * @param ebs           The EBS in Byte
+     * @return the set of UNIs for the CE EVC
+     */
+    public static Set<CarrierEthernetUni> generateUniSet(String evcTypeString, List<String> uniList,
+                                                         short ceVlanId, String firstUni, String evcCfgId,
+                                                         Double cir, Double eir, Long cbs, Long ebs) {
+
+        Set<CarrierEthernetUni> uniSet = new HashSet<>();
+
+        CarrierEthernetConnection.Type evcType = generateEvcType(evcTypeString, uniList);
+
+        // We assume that first UNI supplied is always root
+        uniSet.add(CarrierEthernetUni.builder()
+                           .cp(ConnectPoint.deviceConnectPoint(firstUni))
+                           .role(CarrierEthernetUni.Role.ROOT)
+                           .ceVlanId(generateCeVlanId(ceVlanId))
+                           .bwp(CarrierEthernetBandwidthProfile.builder()
+                                        .id(generateBandwidthProfileId(firstUni, evcCfgId, ceVlanId))
+                                        .type(generateBandwidthProfileType(ceVlanId))
+                                        .cir(Bandwidth.mbps(cir))
+                                        .eir(Bandwidth.mbps(eir))
+                                        .cbs(cbs)
+                                        .ebs(ebs)
+                                        .build())
+                           .build());
+
+        final CarrierEthernetUni.Role role;
+        // For E-Line and E-LAN all UNIs are roots. For E-Tree all UNIs are leafs except from one
+        role = ((evcType == CarrierEthernetConnection.Type.ROOT_MULTIPOINT) ?
+                CarrierEthernetUni.Role.LEAF : CarrierEthernetUni.Role.ROOT);
+
+       uniList.forEach(argUni -> uniSet.add(
+                CarrierEthernetUni.builder()
+                        .cp(ConnectPoint.deviceConnectPoint(argUni))
+                        .role(role)
+                        .ceVlanId(generateCeVlanId(ceVlanId))
+                        .bwp(CarrierEthernetBandwidthProfile.builder()
+                                     .id(generateBandwidthProfileId(argUni, evcCfgId, ceVlanId))
+                                     .type(generateBandwidthProfileType(ceVlanId))
+                                     .cir(Bandwidth.mbps(cir))
+                                     .eir(Bandwidth.mbps(eir))
+                                     .cbs(cbs)
+                                     .ebs(ebs)
+                                     .build())
+                        .build()));
+
+        return uniSet;
+    }
+}
diff --git a/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/cli/commands/CarrierEthernetCreateEvcCommand.java b/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/cli/commands/CarrierEthernetCreateEvcCommand.java
index b3c4225..c5ce82e 100644
--- a/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/cli/commands/CarrierEthernetCreateEvcCommand.java
+++ b/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/cli/commands/CarrierEthernetCreateEvcCommand.java
@@ -19,24 +19,19 @@
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.commands.Option;
-import org.onlab.packet.VlanId;
-import org.onlab.util.Bandwidth;
 import org.onosproject.cli.AbstractShellCommand;
 import org.onosproject.ecord.carrierethernet.api.CarrierEthernetService;
-import org.onosproject.ecord.carrierethernet.app.CarrierEthernetBandwidthProfile;
-import org.onosproject.ecord.carrierethernet.app.CarrierEthernetUni;
 import org.onosproject.ecord.carrierethernet.app.CarrierEthernetVirtualConnection;
-import org.onosproject.net.ConnectPoint;
 
-import java.util.HashSet;
 import java.util.List;
-import java.util.Set;
+
+import static org.onosproject.ecord.carrierethernet.app.CarrierEthernetEvcUtils.*;
 
 /**
  * CLI command for installing an Ethernet Virtual Connection.
  */
 @Command(scope = "onos", name = "ce-evc-create",
-         description = "Carrier Ethernet EVC creation command.")
+        description = "Carrier Ethernet EVC creation command.")
 public class CarrierEthernetCreateEvcCommand extends AbstractShellCommand {
 
     @Argument(index = 0, name = "argEvcCfgId",
@@ -46,160 +41,40 @@
             "EVC type (defaults to POINT_TO_POINT or MULTIPOINT_TO_MULTIPOINT, depending on number of UNIs)",
             required = false, multiValued = false)
     String argEvcType = null;
-    @Argument(index = 2, name = "argFirstUni", description =
-            "First UNI in list (if point to multipoint, this is the root)", required = true, multiValued = false)
-    String argFirstUni = null;
     @Argument(index = 3, name = "argUniList",
-            description = "List of remaining UNIs (if point to multipoint, these are the leaves)",
+            description = "List of UNIs (if point to multipoint, first is root, other are leaves)",
             required = true, multiValued = true)
     List<String> argUniList = Lists.newArrayList();
     @Option(name = "-v", aliases = "--cevlan", description = "CE-VLAN ID (applied to all UNIs)",
             required = false, multiValued = false)
-    String argCeVlanId = null;
+    short argCeVlanId = -1;
     @Option(name = "-id", aliases = "--evc-id", description = "The ID of a evc to be updated" +
             " (if evc does not exist, a new evc will be installed)", required = false, multiValued = false)
     String argEvcId = null;
     @Option(name = "-u", aliases = "--maxNumUni", description = "The maximum number of UNIs in the EVC",
             required = false, multiValued = false)
-    String argMaxNumUni = null;
+    int argMaxNumUni = -1;
     @Option(name = "-c", aliases = "--cir", description = "The CIR in Mbps", required = false, multiValued = false)
-    String argCir = "0";
+    double argCir = 0;
     @Option(name = "-e", aliases = "--eir", description = "The EIR in Mbps", required = false, multiValued = false)
-    String argEir = "0";
+    double argEir = 0;
     @Option(name = "-cbs", aliases = "--cbs", description = "The CBS in Bytes", required = false, multiValued = false)
-    String argCbs = "0";
+    long argCbs = 0;
     @Option(name = "-ebs", aliases = "--ebs", description = "The EBS in Bytes", required = false, multiValued = false)
-    String argEbs = "0";
+    long argEbs = 0;
 
     // TODO: Add further arguments for VLAN tag preservation, CoS preservation etc.
 
     @Override
     protected void execute() {
         CarrierEthernetService ceManager = get(CarrierEthernetService.class);
-        ceManager.installEvc(CarrierEthernetVirtualConnection.builder()
-                                     .id(argEvcId)
-                                     .cfgId(argEvcCfgId)
-                                     .type(generateEvcType())
-                                     .maxNumUni(generateMaxNumUni())
-                                     .uniSet(generateUniSet())
+        ceManager.installEvc(CarrierEthernetVirtualConnection.builder().id(argEvcId).cfgId(argEvcCfgId)
+                                     .type(generateEvcType(argEvcType, argUniList))
+                                     .maxNumUni(generateMaxNumUni(argMaxNumUni, argEvcType, argUniList))
+                                     .uniSet(generateUniSet(argEvcType,  argUniList.subList(1, argUniList.size()),
+                                                            argCeVlanId, argUniList.get(0), argEvcCfgId, argCir,
+                                                            argEir, argCbs, argEbs))
                                      .build());
     }
 
-    /**
-     * Return the CE-VLAN ID for the CE evc based on the CLI-supplied argument.
-     *
-     * @return CE-VLAN ID for the CE evc
-     */
-    VlanId generateCeVlanId() {
-        return ((argCeVlanId == null) ? null : VlanId.vlanId(Short.parseShort(argCeVlanId)));
-    }
-
-    /**
-     * Return the CE evc type based on the CLI-supplied arguments.
-     *
-     * @return the CE evc type
-     */
-    CarrierEthernetVirtualConnection.Type generateEvcType() {
-        if (argEvcType == null) {
-            return ((argUniList.size() > 2) ?
-                    CarrierEthernetVirtualConnection.Type.MULTIPOINT_TO_MULTIPOINT :
-                    CarrierEthernetVirtualConnection.Type.POINT_TO_POINT);
-        } else {
-            // TODO: Catch exception
-            return CarrierEthernetVirtualConnection.Type.valueOf(argEvcType);
-        }
-    }
-
-    /**
-     * Return the EVC maxNumUni parameter based on the CLI-supplied arguments.
-     *
-     * @return the maxNumUni parameter
-     */
-    Integer generateMaxNumUni() {
-        if (argMaxNumUni == null) {
-            if (argEvcType == null) {
-                return ((argUniList.size() > 2) ?
-                        CarrierEthernetVirtualConnection.MAX_NUM_UNI : 2);
-            } else {
-                // TODO: Catch exception
-                CarrierEthernetVirtualConnection.Type evcType =
-                        CarrierEthernetVirtualConnection.Type.valueOf(argEvcType);
-                return (evcType.equals(CarrierEthernetVirtualConnection.Type.POINT_TO_POINT) ? 2 :
-                        CarrierEthernetVirtualConnection.MAX_NUM_UNI);
-            }
-        } else {
-            return Integer.valueOf(argMaxNumUni);
-        }
-    }
-
-    /**
-     * Return the BW profile type based on the CLI-supplied arguments.
-     *
-     * @return the BWP profile type
-     */
-    CarrierEthernetBandwidthProfile.Type generateBandwidthProfileType() {
-        // TODO: Add the CoS BW profile case
-        return ((argCeVlanId == null) ?
-                CarrierEthernetBandwidthProfile.Type.INTERFACE : CarrierEthernetBandwidthProfile.Type.EVC);
-    }
-
-    /**
-     * Return the BW profile id based on the CLI-supplied arguments.
-     *
-     * @param uniId the UNI id
-     * @return the BW profile id
-     */
-    String generateBandwidthProfileId(String uniId) {
-        // TODO: Add the CoS BW profile case
-        return ((argCeVlanId == null) ? uniId : argEvcCfgId);
-    }
-
-    /**
-     * Return the set of UNIs for the CE EVC based on the CLI-supplied arguments.
-     *
-     * @return the set of UNIs for the CE EVC
-     */
-    Set<CarrierEthernetUni> generateUniSet() {
-
-        Set<CarrierEthernetUni> uniSet = new HashSet<>();
-
-        CarrierEthernetVirtualConnection.Type evcType = generateEvcType();
-
-        // We assume that first UNI supplied is always root
-        uniSet.add(CarrierEthernetUni.builder()
-                           .cp(ConnectPoint.deviceConnectPoint(argFirstUni))
-                           .role(CarrierEthernetUni.Role.ROOT)
-                           .ceVlanId(generateCeVlanId())
-                           .bwp(CarrierEthernetBandwidthProfile.builder()
-                                        .id(generateBandwidthProfileId(argFirstUni))
-                                        .type(generateBandwidthProfileType())
-                                        .cir(Bandwidth.mbps(Double.parseDouble(argCir)))
-                                        .eir(Bandwidth.mbps(Double.parseDouble(argEir)))
-                                        .cbs(Long.parseLong(argCbs))
-                                        .ebs(Long.parseLong(argEbs))
-                                        .build())
-                           .build());
-
-        final CarrierEthernetUni.Role role;
-        // For E-Line and E-LAN all UNIs are roots. For E-Tree all UNIs are leafs except from one
-        role = ((evcType == CarrierEthernetVirtualConnection.Type.ROOT_MULTIPOINT) ?
-                CarrierEthernetUni.Role.LEAF : CarrierEthernetUni.Role.ROOT);
-
-        argUniList.forEach(argUni -> uniSet.add(
-                CarrierEthernetUni.builder()
-                        .cp(ConnectPoint.deviceConnectPoint(argUni))
-                        .role(role)
-                        .ceVlanId(generateCeVlanId())
-                        .bwp(CarrierEthernetBandwidthProfile.builder()
-                                     .id(generateBandwidthProfileId(argUni))
-                                     .type(generateBandwidthProfileType())
-                                     .cir(Bandwidth.mbps(Double.parseDouble(argCir)))
-                                     .eir(Bandwidth.mbps(Double.parseDouble(argEir)))
-                                     .cbs(Long.parseLong(argCbs))
-                                     .ebs(Long.parseLong(argEbs))
-                                     .build())
-                        .build()));
-
-        return uniSet;
-    }
-}
+}
\ No newline at end of file
diff --git a/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/rest/CarrierEthernetWebApplication.java b/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/rest/CarrierEthernetWebApplication.java
new file mode 100644
index 0000000..a56dba1
--- /dev/null
+++ b/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/rest/CarrierEthernetWebApplication.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * 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.ecord.carrierethernet.rest;
+
+import org.onlab.rest.AbstractWebApplication;
+
+import java.util.Set;
+
+/**
+ * CarrierEthernet REST API web application.
+ */
+public class CarrierEthernetWebApplication extends AbstractWebApplication {
+    @Override
+    public Set<Class<?>> getClasses() {
+        return getClasses(CarrierEthernetWebResource.class);
+    }
+}
diff --git a/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/rest/CarrierEthernetWebResource.java b/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/rest/CarrierEthernetWebResource.java
new file mode 100644
index 0000000..f606026
--- /dev/null
+++ b/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/rest/CarrierEthernetWebResource.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * 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.ecord.carrierethernet.rest;
+
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.ecord.carrierethernet.api.CarrierEthernetService;
+import org.onosproject.ecord.carrierethernet.app.CarrierEthernetVirtualConnection;
+import org.onosproject.rest.AbstractWebResource;
+
+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.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Carrier Ethernet web resource.
+ */
+@Path("carrierethernet")
+public class CarrierEthernetWebResource extends AbstractWebResource {
+
+    private static final String EVCS = "evcs";
+    private final ObjectNode root = mapper().createObjectNode();
+    private final ArrayNode evcsNode = root.putArray(EVCS);
+
+    CarrierEthernetService ceManager = get(CarrierEthernetService.class);
+
+    /**
+     * Gets all EVC entries. Returns array of all EVCs in the system.
+     *
+     * @return 200 OK with a collection of Evcs
+     */
+    @GET
+    @Produces(MediaType.APPLICATION_JSON)
+    @Path("evc")
+    public Response getEvcs() {
+        ceManager.evcMap().values().stream()
+                .forEach(evc -> evcsNode.add(
+                        codec(CarrierEthernetVirtualConnection.class)
+                                .encode(evc, this)));
+
+
+        return ok(root).build();
+    }
+
+    /**
+     * Gets an EVC entry by deviceId.
+     *
+     * @return 200 OK with the requested Evc.
+     */
+    @GET
+    @Produces(MediaType.APPLICATION_JSON)
+    @Path("evc/{evcId}")
+    public Response getEvc(@PathParam("evcId") String evcId) {
+        ObjectNode evc = codec(CarrierEthernetVirtualConnection.class)
+                .encode(ceManager.getEvc(evcId), this);
+        return ok(evc).build();
+    }
+
+    /**
+     * Install an EVC with given parameters.
+     *
+     * @return 200 OK if the EVC was installed
+     */
+    @POST
+    @Path("evc")
+    @Consumes(MediaType.APPLICATION_JSON)
+    public Response setEvc(InputStream stream) {
+        ObjectNode root = mapper().createObjectNode();
+        try {
+            ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+            CarrierEthernetVirtualConnection evc =
+                    codec(CarrierEthernetVirtualConnection.class).decode(jsonTree, this);
+            ceManager.installEvc(evc);
+            root.put("evcId", evc.id());
+        } catch (IOException e) {
+            throw new IllegalArgumentException(e.getMessage());
+        }
+        return ok(root).build();
+    }
+
+    /**
+     * Removes all EVCs installed in the CE app.
+     *
+     * @return 204 NO CONTENT
+     */
+    @DELETE
+    @Produces(MediaType.APPLICATION_JSON)
+    @Path("evc")
+    public Response removeAllEvc() {
+        ceManager.removeAllEvcs();
+        return Response.noContent().build();
+    }
+
+    /**
+     * Removes one EVCs by evcId.
+     *
+     * @param evcId the EVC to remove.
+     * @return 204 NO CONTENT
+     */
+    @DELETE
+    @Produces(MediaType.APPLICATION_JSON)
+    @Path("evc/{evcId}")
+    public Response removeEvcWithId(@PathParam("evcId") String evcId) {
+        ceManager.removeEvc(evcId);
+        return Response.noContent().build();
+    }
+
+}
diff --git a/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/rest/EvcCodec.java b/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/rest/EvcCodec.java
new file mode 100644
index 0000000..cfc378f
--- /dev/null
+++ b/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/rest/EvcCodec.java
@@ -0,0 +1,95 @@
+package org.onosproject.ecord.carrierethernet.rest;
+
+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.ecord.carrierethernet.app.CarrierEthernetBandwidthProfile;
+import org.onosproject.ecord.carrierethernet.app.CarrierEthernetNetworkInterface;
+import org.onosproject.ecord.carrierethernet.app.CarrierEthernetUni;
+import org.onosproject.ecord.carrierethernet.app.CarrierEthernetVirtualConnection;
+import org.slf4j.Logger;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.onlab.util.Tools.nullIsIllegal;
+import static org.onosproject.ecord.carrierethernet.app.CarrierEthernetEvcUtils.*;
+import static org.onosproject.ecord.carrierethernet.app.CarrierEthernetVirtualConnection.builder;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Implementation of encoder for Alarm codec.
+ */
+public class EvcCodec extends JsonCodec<CarrierEthernetVirtualConnection> {
+
+    private static final String EVC_ID_REQUIRED = "EVC Id Must be specified";
+    private static final String EVC_TYPE_REQUIRED = "EVC Type Must be specified";
+    private static final String ARRAY_REQUIRED = "UNI array was not specified";
+
+    private final Logger log = getLogger(getClass());
+
+    @Override
+    public ObjectNode encode(CarrierEthernetVirtualConnection evc, CodecContext context) {
+        ObjectNode evcRoot = context.mapper().createObjectNode();
+        evcRoot.put("evcCfgId", evc.cfgId());
+        evcRoot.put("evcId", evc.id());
+        ArrayNode uniList = context.mapper()
+                .valueToTree(evc.uniSet().stream()
+                                     .map(CarrierEthernetNetworkInterface::id)
+                                     .collect(Collectors.toList()));
+        evcRoot.putArray("uniList").addAll(uniList);
+        evcRoot.put("maxNumUni", evc.maxNumUni());
+        CarrierEthernetUni uni = evc.uniSet().iterator().next();
+        evcRoot.put("vlanId", uni.ceVlanId().toString());
+        CarrierEthernetBandwidthProfile bwp = uni.bwp();
+        if (bwp != null) {
+            evcRoot.put("cir", bwp.cir().bps());
+            evcRoot.put("eir", bwp.eir().bps());
+            evcRoot.put("cbs", bwp.cbs());
+            evcRoot.put("ebs", bwp.ebs());
+        }
+        return evcRoot;
+    }
+
+    @Override
+    public CarrierEthernetVirtualConnection decode(ObjectNode json, CodecContext context) {
+        String argEvcCfgId = json.get("evcCfgId").asText(null);
+        String argEvcId = null;
+        if (json.has("evcId")) {
+            argEvcId = json.get("evcId").asText();
+        }
+        ArrayNode uniArray = nullIsIllegal((ArrayNode) json.get("uniList"),
+                                           ARRAY_REQUIRED);
+        List<String> uniList = new ArrayList<>();
+        uniArray.forEach(jsonNode -> uniList.add(jsonNode.asText()));
+        String evcTypeString = nullIsIllegal(json.get("evcType").asText(),
+                                             EVC_TYPE_REQUIRED);
+        int maxNumUni = -1;
+        if (json.has("maxNumUni")) {
+            maxNumUni = json.get("maxNumUni").asInt(-1);
+        }
+
+        short vlanId = -1;
+        if (json.has("vlanId")) {
+            vlanId = json.get("vlanId").shortValue();
+        }
+        double cir = json.get("cir").asDouble(0.0);
+        double eir = json.get("eir").asDouble(0.0);
+        long cbs = json.get("cbs").asLong(0L);
+        long ebs = json.get("ebs").asLong(0L);
+        log.info("Received REST call with parameters: " + "evcCfgId={}, evcId={}," +
+                         " uniList={}, evcType={}, maxNumUni={}, vlanId={}, cir={}, " +
+                         "eir={}, cbs={}, ebs={}", argEvcCfgId, argEvcId, uniList,
+                 evcTypeString, maxNumUni, vlanId, cir, eir, cbs, ebs);
+        return builder().id(argEvcId).cfgId(argEvcCfgId)
+                .type(generateEvcType(evcTypeString, uniList))
+                .maxNumUni(generateMaxNumUni(maxNumUni, evcTypeString, uniList))
+                .uniSet(generateUniSet(evcTypeString, uniList.subList(1, uniList.size()),
+                                       vlanId, uniList.get(0), argEvcCfgId, cir, eir,
+                                       cbs, ebs))
+                .build();
+    }
+
+}
diff --git a/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/rest/EvcCodecRegistrator.java b/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/rest/EvcCodecRegistrator.java
new file mode 100644
index 0000000..9405b7c
--- /dev/null
+++ b/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/rest/EvcCodecRegistrator.java
@@ -0,0 +1,34 @@
+package org.onosproject.ecord.carrierethernet.rest;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onosproject.codec.CodecService;
+import org.onosproject.ecord.carrierethernet.app.CarrierEthernetVirtualConnection;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Implementation of the JSON codec brokering service for Carrier Ethernet app.
+ */
+@Component(immediate = true)
+public class EvcCodecRegistrator {
+
+    private static final Logger log = LoggerFactory.getLogger(EvcCodecRegistrator.class);
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected CodecService codecService;
+
+    @Activate
+    public void activate() {
+        codecService.registerCodec(CarrierEthernetVirtualConnection.class, new EvcCodec());
+        log.info("Started");
+    }
+
+    @Deactivate
+    public void deactivate() {
+        log.info("Stopped");
+    }
+}
diff --git a/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/rest/package-info.java b/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/rest/package-info.java
new file mode 100644
index 0000000..400df6e
--- /dev/null
+++ b/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/rest/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.
+ */
+
+/**
+ * CLI implementation for the Carrier Ethernet Application.
+ */
+package org.onosproject.ecord.carrierethernet.rest;
\ No newline at end of file
diff --git a/carrierethernet/src/main/resources/sampleEVC.json b/carrierethernet/src/main/resources/sampleEVC.json
new file mode 100644
index 0000000..2eaf759
--- /dev/null
+++ b/carrierethernet/src/main/resources/sampleEVC.json
@@ -0,0 +1,14 @@
+{
+  "evcId": "evc1",
+  "evcCfgId": "evpl1",
+  "uniList": [
+    "netconf:192.168.56.10:830/0",
+    "netconf:192.168.56.20:830/0"
+  ],
+  "evcType": "POINT_TO_POINT",
+  "vlanId": 100,
+  "cir": "400",
+  "eir": "200",
+  "cbs": "3000",
+  "ebs": "2000"
+}
\ No newline at end of file
diff --git a/carrierethernet/src/main/webapp/WEB-INF/web.xml b/carrierethernet/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..5774d22
--- /dev/null
+++ b/carrierethernet/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2017-present Open Networking Laboratory
+  ~
+  ~ 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"
+         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>CarrierEthernet REST APIs</display-name>
+
+    <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.ecord.carrierethernet.rest.CarrierEthernetWebApplication</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>