[ONOS-6224] L3VPN service delete

Change-Id: I2eabb231def39dba6613dc5b95f2b16594133ad4
diff --git a/apps/l3vpn/netl3vpn/src/main/java/org/onosproject/l3vpn/netl3vpn/BgpModelIdLevel.java b/apps/l3vpn/netl3vpn/src/main/java/org/onosproject/l3vpn/netl3vpn/BgpModelIdLevel.java
index 334f2fe..05ee2bb 100644
--- a/apps/l3vpn/netl3vpn/src/main/java/org/onosproject/l3vpn/netl3vpn/BgpModelIdLevel.java
+++ b/apps/l3vpn/netl3vpn/src/main/java/org/onosproject/l3vpn/netl3vpn/BgpModelIdLevel.java
@@ -35,5 +35,10 @@
     /**
      * Requested model id level is device list.
      */
-    DEVICE
+    DEVICE,
+
+    /**
+     * Requested model id level is VPN list.
+     */
+    VPN
 }
diff --git a/apps/l3vpn/netl3vpn/src/main/java/org/onosproject/l3vpn/netl3vpn/DeviceInfo.java b/apps/l3vpn/netl3vpn/src/main/java/org/onosproject/l3vpn/netl3vpn/DeviceInfo.java
index 648d556..a45cc68 100644
--- a/apps/l3vpn/netl3vpn/src/main/java/org/onosproject/l3vpn/netl3vpn/DeviceInfo.java
+++ b/apps/l3vpn/netl3vpn/src/main/java/org/onosproject/l3vpn/netl3vpn/DeviceInfo.java
@@ -17,7 +17,7 @@
 package org.onosproject.l3vpn.netl3vpn;
 
 import org.onosproject.net.DeviceId;
-import org.onosproject.net.behaviour.L3vpnConfig;
+import org.onosproject.net.behaviour.L3VpnConfig;
 import org.onosproject.net.driver.DriverHandler;
 import org.onosproject.net.driver.DriverService;
 import org.onosproject.yang.model.ModelObjectData;
@@ -158,7 +158,7 @@
      */
     public ModelObjectData processCreateInstance(DriverService driverSvc,
                                                  ModelObjectData modelData) {
-        L3vpnConfig config = getL3VpnConfig(driverSvc);
+        L3VpnConfig config = getL3VpnConfig(driverSvc);
         return (ModelObjectData) config.createInstance(modelData);
     }
 
@@ -173,7 +173,7 @@
      */
     public ModelObjectData processCreateInterface(DriverService driverSvc,
                                                   ModelObjectData modData) {
-        L3vpnConfig config = getL3VpnConfig(driverSvc);
+        L3VpnConfig config = getL3VpnConfig(driverSvc);
         return (ModelObjectData) config.bindInterface(modData);
     }
 
@@ -190,7 +190,7 @@
     public ModelObjectData processCreateBgpInfo(DriverService driverSvc,
                                                 BgpInfo bgpInfo,
                                                 BgpDriverInfo driverInfo) {
-        L3vpnConfig config = getL3VpnConfig(driverSvc);
+        L3VpnConfig config = getL3VpnConfig(driverSvc);
         return (ModelObjectData) config.createBgpInfo(bgpInfo, driverInfo);
     }
 
@@ -205,7 +205,7 @@
      */
     public ModelObjectData processDeleteInstance(DriverService driverSvc,
                                                  ModelObjectData modData) {
-        L3vpnConfig config = getL3VpnConfig(driverSvc);
+        L3VpnConfig config = getL3VpnConfig(driverSvc);
         return (ModelObjectData) config.deleteInstance(modData);
     }
 
@@ -237,8 +237,8 @@
     public ModelObjectData processDeleteBgpInfo(DriverService driverSvc,
                                                 BgpInfo bgpInfo,
                                                 BgpDriverInfo driverInfo) {
-        // TODO: Need to call the behaviour.
-        return null;
+        L3VpnConfig config = getL3VpnConfig(driverSvc);
+        return (ModelObjectData) config.deleteBgpInfo(bgpInfo, driverInfo);
     }
 
     /**
@@ -247,8 +247,8 @@
      * @param driverSvc driver service
      * @return L3VPN config
      */
-    private L3vpnConfig getL3VpnConfig(DriverService driverSvc) {
+    private L3VpnConfig getL3VpnConfig(DriverService driverSvc) {
         DriverHandler handler = driverSvc.createHandler(deviceId);
-        return handler.behaviour(L3vpnConfig.class);
+        return handler.behaviour(L3VpnConfig.class);
     }
 }
diff --git a/apps/l3vpn/netl3vpn/src/main/java/org/onosproject/l3vpn/netl3vpn/impl/DistributedNetL3VpnStore.java b/apps/l3vpn/netl3vpn/src/main/java/org/onosproject/l3vpn/netl3vpn/impl/DistributedNetL3VpnStore.java
index 6debaf4..09c2f6a 100644
--- a/apps/l3vpn/netl3vpn/src/main/java/org/onosproject/l3vpn/netl3vpn/impl/DistributedNetL3VpnStore.java
+++ b/apps/l3vpn/netl3vpn/src/main/java/org/onosproject/l3vpn/netl3vpn/impl/DistributedNetL3VpnStore.java
@@ -198,7 +198,7 @@
     public void addInterfaceInfo(AccessInfo accessInfo, InterfaceInfo intInfo) {
         checkNotNull(accessInfo, ACCESS_INFO_NULL);
         checkNotNull(intInfo, INT_INFO_NULL);
-        intInfoMap.putIfAbsent(accessInfo, intInfo);
+        intInfoMap.put(accessInfo, intInfo);
     }
 
     @Override
diff --git a/apps/l3vpn/netl3vpn/src/main/java/org/onosproject/l3vpn/netl3vpn/impl/NetL3vpnManager.java b/apps/l3vpn/netl3vpn/src/main/java/org/onosproject/l3vpn/netl3vpn/impl/NetL3VpnManager.java
similarity index 94%
rename from apps/l3vpn/netl3vpn/src/main/java/org/onosproject/l3vpn/netl3vpn/impl/NetL3vpnManager.java
rename to apps/l3vpn/netl3vpn/src/main/java/org/onosproject/l3vpn/netl3vpn/impl/NetL3VpnManager.java
index 4dc9165..67c6237 100644
--- a/apps/l3vpn/netl3vpn/src/main/java/org/onosproject/l3vpn/netl3vpn/impl/NetL3vpnManager.java
+++ b/apps/l3vpn/netl3vpn/src/main/java/org/onosproject/l3vpn/netl3vpn/impl/NetL3VpnManager.java
@@ -142,14 +142,16 @@
 import static org.onosproject.l3vpn.netl3vpn.impl.NetL3VpnUtil.getModIdForSites;
 import static org.onosproject.l3vpn.netl3vpn.impl.NetL3VpnUtil.getResourceData;
 import static org.onosproject.l3vpn.netl3vpn.impl.NetL3VpnUtil.getRole;
+import static org.onosproject.l3vpn.netl3vpn.impl.NetL3VpnUtil.getVpnBgpDelModObj;
 import static org.onosproject.l3vpn.netl3vpn.impl.NetL3VpnUtil.getVpnCreateModObj;
+import static org.onosproject.l3vpn.netl3vpn.impl.NetL3VpnUtil.getVpnDelModObj;
 import static org.onosproject.yang.runtime.helperutils.YangApacheUtils.getYangModel;
 
 /**
  * The IETF net l3vpn manager implementation.
  */
 @Component(immediate = true)
-public class NetL3vpnManager {
+public class NetL3VpnManager {
 
     private static final String APP_ID = "org.onosproject.app.l3vpn";
     private static final String L3_VPN_ID_TOPIC = "l3vpn-id";
@@ -569,6 +571,7 @@
         InterfaceInfo interInfo = new InterfaceInfo(info, portName,
                                                     instance.vpnName());
         l3VpnStore.addInterfaceInfo(accInfo, interInfo);
+        l3VpnStore.addVpnIns(instance.vpnName(), instance);
     }
 
     /**
@@ -645,7 +648,6 @@
         Map<AccessInfo, InterfaceInfo> intMap = l3VpnStore.getInterfaceInfo();
         generateRdRt(inst, role);
         DeviceInfo info = new DeviceInfo(id);
-        inst.addDevInfo(id, info);
 
         NetworkInstances instances = createInstance(inst, role, ip);
         ModelObjectData devMod = getVpnCreateModObj(intMap, instances,
@@ -655,6 +657,7 @@
         ResourceData resData = modelConverter.createDataNode(driMod);
         addToStore(resData);
         l3VpnStore.addVpnIns(inst.vpnName(), inst);
+        inst.addDevInfo(id, info);
         return info;
     }
 
@@ -871,7 +874,7 @@
         Interfaces interfaces = createInterface(pName, ins.vpnName(),
                                                 connect);
         ModelObjectData devMod = getIntCreateModObj(
-                intMap, interfaces, info.deviceId().toString());
+                info.ifNames(), interfaces, info.deviceId().toString());
         ModelObjectData driMod = info.processCreateInterface(driverService,
                                                              devMod);
         ResourceData resData = modelConverter.createDataNode(driMod);
@@ -896,7 +899,7 @@
         if (intBgp != null) {
             intBgp.vpnName(name);
             BgpDriverInfo config = getBgpCreateConfigObj(
-                    bgpMap, info.deviceId().toString());
+                    bgpMap, info.deviceId().toString(), info.bgpInfo(), intBgp);
             ModelObjectData driData = info.processCreateBgpInfo(
                     driverService, intBgp, config);
             l3VpnStore.addBgpInfo(info.bgpInfo(), info.deviceId());
@@ -965,24 +968,47 @@
      */
     private void deleteVpnInstance(VpnInstance instance, boolean isIntDeleted) {
         Map<DeviceId, DeviceInfo> devices = instance.devInfo();
-        for (Map.Entry<DeviceId, DeviceInfo> device : devices.entrySet()) {
-            Map<AccessInfo, InterfaceInfo> intMap =
-                    l3VpnStore.getInterfaceInfo();
-            NetworkInstances ins = deleteInstance(instance.vpnName());
-            DeviceInfo dev = device.getValue();
-
-            ModelObjectData devMod = getVpnCreateModObj(
-                    intMap, ins, dev.deviceId().toString());
-            ModelObjectData driMod = dev.processDeleteInstance(driverService,
-                                                               devMod);
-            ResourceData resData = modelConverter.createDataNode(driMod);
-            deleteFromStore(resData);
-            if (!isIntDeleted) {
-                //TODO: Remove from store.
-                remInterfaceFromMap(dev);
+        if (devices != null) {
+            for (Map.Entry<DeviceId, DeviceInfo> device : devices.entrySet()) {
+                NetworkInstances ins = deleteInstance(instance.vpnName());
+                DeviceInfo dev = device.getValue();
+                if (!isIntDeleted) {
+                    remVpnBgp(dev);
+                    remInterfaceFromMap(dev);
+                }
+                Map<AccessInfo, InterfaceInfo> intMap =
+                        l3VpnStore.getInterfaceInfo();
+                String id = dev.deviceId().toString();
+                ModelObjectData devMod = getVpnDelModObj(intMap, ins, id);
+                ModelObjectData driMod = dev.processDeleteInstance(
+                        driverService, devMod);
+                ResourceData resData = modelConverter.createDataNode(driMod);
+                deleteFromStore(resData);
             }
+            l3VpnStore.removeVpnInstance(instance.vpnName());
         }
-        l3VpnStore.removeVpnInstance(instance.vpnName());
+    }
+
+    /**
+     * Removes the BGP information for that complete VPN instance.
+     *
+     * @param dev device info
+     */
+    private void remVpnBgp(DeviceInfo dev) {
+        BgpInfo devBgp = dev.bgpInfo();
+        if (devBgp != null) {
+            l3VpnStore.removeBgpInfo(devBgp);
+            BgpInfo delInfo = new BgpInfo();
+            delInfo.vpnName(devBgp.vpnName());
+            String id = dev.deviceId().toString();
+            Map<BgpInfo, DeviceId> bgpMap = l3VpnStore.getBgpInfo();
+            BgpDriverInfo driConfig = getVpnBgpDelModObj(bgpMap, id);
+            ModelObjectData driData = dev.processDeleteBgpInfo(
+                    driverService, delInfo, driConfig);
+            ResourceData resData = modelConverter.createDataNode(driData);
+            deleteFromStore(resData);
+            l3VpnStore.removeBgpInfo(devBgp);
+        }
     }
 
     /**
@@ -993,7 +1019,7 @@
      */
     private void deleteFromStore(ResourceData resData) {
         if (resData != null) {
-            configService.deleteNode(resData.resourceId());
+            configService.deleteNodeRecursive(resData.resourceId());
         }
     }
 
@@ -1005,8 +1031,10 @@
      */
     private void remInterfaceFromMap(DeviceInfo deviceInfo) {
         List<AccessInfo> accesses = deviceInfo.accesses();
-        for (AccessInfo access : accesses) {
-            l3VpnStore.removeInterfaceInfo(access);
+        if (accesses != null) {
+            for (AccessInfo access : accesses) {
+                l3VpnStore.removeInterfaceInfo(access);
+            }
         }
         deviceInfo.ifNames(null);
         deviceInfo.accesses(null);
diff --git a/apps/l3vpn/netl3vpn/src/main/java/org/onosproject/l3vpn/netl3vpn/impl/NetL3VpnUtil.java b/apps/l3vpn/netl3vpn/src/main/java/org/onosproject/l3vpn/netl3vpn/impl/NetL3VpnUtil.java
index a713fc3..5875fe7 100644
--- a/apps/l3vpn/netl3vpn/src/main/java/org/onosproject/l3vpn/netl3vpn/impl/NetL3VpnUtil.java
+++ b/apps/l3vpn/netl3vpn/src/main/java/org/onosproject/l3vpn/netl3vpn/impl/NetL3VpnUtil.java
@@ -49,6 +49,7 @@
 import static org.onosproject.l3vpn.netl3vpn.BgpModelIdLevel.DEVICE;
 import static org.onosproject.l3vpn.netl3vpn.BgpModelIdLevel.DEVICES;
 import static org.onosproject.l3vpn.netl3vpn.BgpModelIdLevel.ROOT;
+import static org.onosproject.l3vpn.netl3vpn.BgpModelIdLevel.VPN;
 import static org.onosproject.l3vpn.netl3vpn.VpnType.ANY_TO_ANY;
 import static org.onosproject.l3vpn.netl3vpn.VpnType.HUB;
 import static org.onosproject.l3vpn.netl3vpn.VpnType.SPOKE;
@@ -385,16 +386,15 @@
     /**
      * Returns the interface create model object data.
      *
-     * @param intMap interface map
-     * @param ifs    interface instance
-     * @param id     device id
+     * @param ifNames interfaces
+     * @param ifs     interface instance
+     * @param id      device id
      * @return interface model object data
      */
-    static ModelObjectData getIntCreateModObj(Map<AccessInfo, InterfaceInfo> intMap,
+    static ModelObjectData getIntCreateModObj(List<String> ifNames,
                                               Interfaces ifs, String id) {
         ModelObjectData modData;
-        boolean intAdded = isDevIdPresent(intMap, id);
-        if (intAdded) {
+        if (ifNames.size() > 1) {
             modData = buildIntModDataDevice(id, ifs);
         } else {
             modData = buildIntModDataRoot(id, ifs);
@@ -439,15 +439,20 @@
      *
      * @param bgpMap BGP map
      * @param id     device id
-     * @return driver config info
+     * @param devBgp device BGP info
+     * @param intBgp interface BGP info
+     * @return BGP driver config
      */
     static BgpDriverInfo getBgpCreateConfigObj(Map<BgpInfo, DeviceId> bgpMap,
-                                               String id) {
+                                               String id, BgpInfo devBgp,
+                                               BgpInfo intBgp) {
         boolean isDevIdPresent = isDevIdBgpPresent(bgpMap, id);
         BgpDriverInfo info;
-        if (isDevIdPresent) {
+        if (devBgp != intBgp) {
+            //TODO: With ipv6 BGP it has to be changed
+            info = new BgpDriverInfo(VPN, id);
+        } else if (isDevIdPresent) {
             info = new BgpDriverInfo(DEVICE, id);
-
         } else if (bgpMap.size() != 0) {
             info = new BgpDriverInfo(DEVICES, id);
         } else {
@@ -473,4 +478,48 @@
         }
         return false;
     }
+
+    /**
+     * Returns the model object data for VPN instance deletion.
+     *
+     * @param intMap interface map
+     * @param ins    VPN instance
+     * @param id     device id
+     * @return model object data
+     */
+    static ModelObjectData getVpnDelModObj(Map<AccessInfo, InterfaceInfo> intMap,
+                                           NetworkInstances ins,
+                                           String id) {
+        boolean isDevIdPresent = isDevIdPresent(intMap, id);
+        ModelObjectData modData;
+        if (intMap.size() == 0) {
+            modData = buildInsModDataRoot(id, ins);
+        } else if (isDevIdPresent) {
+            modData = buildInsModDataDevice(id, ins);
+        } else {
+            modData = buildInsModDataDevices(id, ins);
+        }
+        return modData;
+    }
+
+    /**
+     * Returns the BGP driver info for VPN BGP instance deletion.
+     *
+     * @param bgpMap BGP map
+     * @param id     device id
+     * @return BGP driver info
+     */
+    static BgpDriverInfo getVpnBgpDelModObj(Map<BgpInfo, DeviceId> bgpMap,
+                                            String id) {
+        boolean isDevIdPresent = isDevIdBgpPresent(bgpMap, id);
+        BgpDriverInfo driInfo;
+        if (bgpMap.size() == 0) {
+            driInfo = new BgpDriverInfo(ROOT, id);
+        } else if (isDevIdPresent) {
+            driInfo = new BgpDriverInfo(DEVICE, id);
+        } else {
+            driInfo = new BgpDriverInfo(DEVICES, id);
+        }
+        return driInfo;
+    }
 }
diff --git a/apps/l3vpn/yangmodel/pom.xml b/apps/l3vpn/yangmodel/pom.xml
index ae2a75c..841a3cf 100644
--- a/apps/l3vpn/yangmodel/pom.xml
+++ b/apps/l3vpn/yangmodel/pom.xml
@@ -18,13 +18,6 @@
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
-    <dependencies>
-        <dependency>
-            <groupId>org.onosproject</groupId>
-            <artifactId>onos-yang-model</artifactId>
-            <version>1.12.0-b7</version>
-        </dependency>
-    </dependencies>
 
     <parent>
         <groupId>org.onosproject</groupId>
@@ -37,21 +30,4 @@
     <packaging>bundle</packaging>
 
     <description>IETF L3VPN YANG models</description>
-
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.onosproject</groupId>
-                <artifactId>onos-yang-compiler-maven-plugin</artifactId>
-                <version>1.12.0-b7</version>
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>yang2java</goal>
-                        </goals>
-                    </execution>
-                </executions>
-            </plugin>
-        </plugins>
-    </build>
 </project>
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/L3vpnConfig.java b/core/api/src/main/java/org/onosproject/net/behaviour/L3VpnConfig.java
similarity index 97%
rename from core/api/src/main/java/org/onosproject/net/behaviour/L3vpnConfig.java
rename to core/api/src/main/java/org/onosproject/net/behaviour/L3VpnConfig.java
index 751316d..b710006 100644
--- a/core/api/src/main/java/org/onosproject/net/behaviour/L3vpnConfig.java
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/L3VpnConfig.java
@@ -21,7 +21,7 @@
 /**
  * Behaviour for handling various drivers for l3vpn configurations.
  */
-public interface L3vpnConfig extends HandlerBehaviour {
+public interface L3VpnConfig extends HandlerBehaviour {
 
     /**
      * Create virtual routing forwarding instance on requested device with
diff --git a/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/BgpConstructionUtil.java b/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/BgpConstructionUtil.java
index 8472ed4..85e4da6 100644
--- a/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/BgpConstructionUtil.java
+++ b/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/BgpConstructionUtil.java
@@ -33,10 +33,12 @@
 import org.onosproject.yang.gen.v1.ne.bgpcomm.rev20141225.nebgpcomm.devices.device.bgp.bgpcomm.BgpVrfs;
 import org.onosproject.yang.gen.v1.ne.bgpcomm.rev20141225.nebgpcomm.devices.device.bgp.bgpcomm.DefaultBgpVrfs;
 import org.onosproject.yang.gen.v1.ne.bgpcomm.rev20141225.nebgpcomm.devices.device.bgp.bgpcomm.bgpvrfs.BgpVrf;
+import org.onosproject.yang.gen.v1.ne.bgpcomm.rev20141225.nebgpcomm.devices.device.bgp.bgpcomm.bgpvrfs.BgpVrfKeys;
 import org.onosproject.yang.gen.v1.ne.bgpcomm.rev20141225.nebgpcomm.devices.device.bgp.bgpcomm.bgpvrfs.DefaultBgpVrf;
 import org.onosproject.yang.gen.v1.ne.bgpcomm.rev20141225.nebgpcomm.devices.device.bgp.bgpcomm.bgpvrfs.bgpvrf.BgpVrfAfs;
 import org.onosproject.yang.gen.v1.ne.bgpcomm.rev20141225.nebgpcomm.devices.device.bgp.bgpcomm.bgpvrfs.bgpvrf.DefaultBgpVrfAfs;
 import org.onosproject.yang.gen.v1.ne.bgpcomm.rev20141225.nebgpcomm.devices.device.bgp.bgpcomm.bgpvrfs.bgpvrf.bgpvrfafs.BgpVrfAf;
+import org.onosproject.yang.gen.v1.ne.bgpcomm.rev20141225.nebgpcomm.devices.device.bgp.bgpcomm.bgpvrfs.bgpvrf.bgpvrfafs.BgpVrfAfKeys;
 import org.onosproject.yang.gen.v1.ne.bgpcomm.rev20141225.nebgpcomm.devices.device.bgp.bgpcomm.bgpvrfs.bgpvrf.bgpvrfafs.DefaultBgpVrfAf;
 import org.onosproject.yang.gen.v1.ne.bgpcomm.rev20141225.nebgpcomm.devices.device.bgp.bgpcomm.bgpvrfs.bgpvrf.bgpvrfafs.bgpvrfaf.DefaultImportRoutes;
 import org.onosproject.yang.gen.v1.ne.bgpcomm.rev20141225.nebgpcomm.devices.device.bgp.bgpcomm.bgpvrfs.bgpvrf.bgpvrfafs.bgpvrfaf.ImportRoutes;
@@ -100,29 +102,33 @@
 
         bgpVrf.vrfName(bgpInfo.vpnName());
         Map<RouteProtocol, ProtocolInfo> proMap = bgpInfo.protocolInfo();
-        addRouteProtocol(proMap, bgpVrfAfs);
+        ImportRoute route = addRouteProtocol(proMap, bgpVrfAfs);
 
         bgpVrf.bgpVrfAfs(bgpVrfAfs);
         bgpVrfList.add(bgpVrf);
         bgpVrfs.bgpVrf(bgpVrfList);
         bgpBuilder.bgpVrfs(bgpVrfs);
         bgp.bgpcomm(bgpBuilder);
-        return getModObjData(modIdLevel, bgp, devId, bgpVrf);
+        return getModObjData(modIdLevel, bgp, devId, bgpVrf, route);
     }
 
     /**
      * Adds route protocol from the standard device model to the BGP address
      * family respectively.
+     * //TODO: IPV6 has to be handled.
      *
      * @param proMap    protocol map
      * @param bgpVrfAfs BGP address family
+     * @return import route
      */
-    private static void addRouteProtocol(Map<RouteProtocol, ProtocolInfo> proMap,
-                                         BgpVrfAfs bgpVrfAfs) {
+    private static ImportRoute addRouteProtocol(Map<RouteProtocol, ProtocolInfo> proMap,
+                                                BgpVrfAfs bgpVrfAfs) {
         BgpVrfAf ipv4 = new DefaultBgpVrfAf();
         ImportRoutes ipv4Routes = new DefaultImportRoutes();
         ipv4.afType(of(IPV4UNI));
 
+        ImportRoute route = null;
+
         BgpVrfAf ipv6 = new DefaultBgpVrfAf();
         ImportRoutes ipv6Routes = new DefaultImportRoutes();
         ipv6.afType(of(IPV6UNI));
@@ -130,7 +136,7 @@
             RouteProtocol protocol = info.getKey();
             ProtocolInfo proInfo = info.getValue();
             if (proInfo.isIpv4Af()) {
-                addImportRoute(ipv4Routes, proInfo, protocol);
+                route = addImportRoute(ipv4Routes, proInfo, protocol);
             }
             if (proInfo.isIpv6Af()) {
                 addImportRoute(ipv6Routes, proInfo, protocol);
@@ -144,6 +150,7 @@
                 !ipv6Routes.importRoute().isEmpty()) {
             addToBgpVrf(ipv6Routes, ipv6, bgpVrfAfs);
         }
+        return route;
     }
 
     /**
@@ -168,13 +175,16 @@
      * @param routes   routes object
      * @param proInfo  protocol info
      * @param protocol route protocol
+     * @return import route object
      */
-    private static void addImportRoute(ImportRoutes routes, ProtocolInfo proInfo,
-                                       RouteProtocol protocol) {
+    private static ImportRoute addImportRoute(ImportRoutes routes,
+                                              ProtocolInfo proInfo,
+                                              RouteProtocol protocol) {
         List<ImportRoute> routeList = new LinkedList<>();
         ImportRoute route = buildAfBgp(proInfo, protocol);
         routeList.add(route);
         routes.importRoute(routeList);
+        return route;
     }
 
     /**
@@ -233,12 +243,17 @@
      * @param bgp        driver BGP object
      * @param devId      device id
      * @param bgpVrf     driver BGP VRF object
+     * @param route      import route object
      * @return model object data
      */
     public static ModelObjectData getModObjData(BgpModelIdLevel modIdLevel,
                                                 Bgp bgp, String devId,
-                                                BgpVrf bgpVrf) {
+                                                BgpVrf bgpVrf, ImportRoute route) {
         switch (modIdLevel) {
+
+            case VPN:
+                return getRouteProModObj(bgpVrf.vrfName(), route, devId);
+
             case ROOT:
                 return getRootModObj(bgp, devId);
 
@@ -254,6 +269,36 @@
     }
 
     /**
+     * Returns the model object data of route protocol.
+     *
+     * @param vpnName VPN name
+     * @param route   import route
+     * @param devId   device id
+     * @return model object data
+     */
+    private static ModelObjectData getRouteProModObj(String vpnName,
+                                                     ImportRoute route,
+                                                     String devId) {
+        DeviceKeys key = new DeviceKeys();
+        key.deviceid(devId);
+        BgpVrfKeys vpnKey = new BgpVrfKeys();
+        vpnKey.vrfName(vpnName);
+        BgpVrfAfKeys afKey = new BgpVrfAfKeys();
+        afKey.afType(of(IPV4UNI));
+        ModelObjectId id = ModelObjectId.builder()
+                .addChild(DefaultDevices.class)
+                .addChild(DefaultDevice.class, key)
+                .addChild(DefaultBgp.class)
+                .addChild(DefaultBgpcomm.class)
+                .addChild(DefaultBgpVrfs.class)
+                .addChild(DefaultBgpVrf.class, vpnKey)
+                .addChild(DefaultBgpVrfAfs.class)
+                .addChild(DefaultBgpVrfAf.class, afKey)
+                .addChild(DefaultImportRoutes.class).build();
+        return getData(id, (InnerModelObject) route);
+    }
+
+    /**
      * Returns the driver model object data with device in model object id,
      * till BGP VRF.
      *
@@ -316,4 +361,81 @@
         device.bgp(bgp);
         return device;
     }
+
+    /**
+     * Returns the BGP model object data for deletion.
+     *
+     * @param bgpInfo   BGP info
+     * @param bgpConfig BGP driver config
+     * @return model object data
+     */
+    static ModelObjectData getDeleteBgp(BgpInfo bgpInfo,
+                                        BgpDriverInfo bgpConfig) {
+        BgpModelIdLevel modIdLvl = bgpConfig.modIdLevel();
+        switch (modIdLvl) {
+            case ROOT:
+                return getDelRootModObj();
+
+            case DEVICES:
+                return getDelDevicesModObj(bgpConfig.devId());
+
+            case DEVICE:
+                return getDelDeviceModObj(bgpConfig.devId(), bgpInfo.vpnName());
+
+            default:
+                throw new IllegalArgumentException(UNSUPPORTED_MODEL_LVL);
+        }
+    }
+
+    /**
+     * Returns the model object data with respect to device level.
+     *
+     * @param devId   device id
+     * @param vpnName VPN name
+     * @return model object data
+     */
+    private static ModelObjectData getDelDeviceModObj(String devId,
+                                                      String vpnName) {
+        DeviceKeys devKeys = new DeviceKeys();
+        devKeys.deviceid(devId);
+        BgpVrfKeys vpnKey = new BgpVrfKeys();
+        vpnKey.vrfName(vpnName);
+        ModelObjectId modelId = ModelObjectId.builder()
+                .addChild(DefaultDevices.class)
+                .addChild(DefaultDevice.class, devKeys)
+                .addChild(DefaultBgp.class)
+                .addChild(DefaultBgpcomm.class)
+                .addChild(DefaultBgpVrfs.class)
+                .addChild(DefaultBgpVrf.class, vpnKey).build();
+        DefaultBgpVrfAfs afs = new DefaultBgpVrfAfs();
+        return getData(modelId, afs);
+    }
+
+    /**
+     * Returns the model object data with respect to root level.
+     *
+     * @return model object data
+     */
+    private static ModelObjectData getDelRootModObj() {
+        DefaultDevice device = new DefaultDevice();
+        ModelObjectId modelId = ModelObjectId.builder().addChild(
+                DefaultDevices.class).build();
+        return getData(modelId, device);
+    }
+
+    /**
+     * Returns the model object data for devices level.
+     *
+     * @param id device id
+     * @return model object data
+     */
+    private static ModelObjectData getDelDevicesModObj(String id) {
+        DeviceKeys devKeys = new DeviceKeys();
+        devKeys.deviceid(id);
+        ModelObjectId modelId = ModelObjectId.builder()
+                .addChild(DefaultDevices.class)
+                .addChild(DefaultDevice.class, devKeys).build();
+        DefaultBgp bgp = new DefaultBgp();
+        return getData(modelId, bgp);
+    }
 }
diff --git a/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/DriverUtil.java b/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/DriverUtil.java
index edeffef..af997c4 100644
--- a/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/DriverUtil.java
+++ b/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/DriverUtil.java
@@ -17,9 +17,11 @@
 package org.onosproject.drivers.huawei;
 
 import org.onosproject.yang.gen.v1.ne.l3vpn.api.rev20141225.nel3vpnapi.DefaultDevices;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev20140508.ietfinterfaces.devices.DeviceKeys;
 import org.onosproject.yang.model.AtomicPath;
 import org.onosproject.yang.model.DefaultModelObjectData;
 import org.onosproject.yang.model.InnerModelObject;
+import org.onosproject.yang.model.KeyInfo;
 import org.onosproject.yang.model.ModelObject;
 import org.onosproject.yang.model.ModelObjectData;
 import org.onosproject.yang.model.ModelObjectId;
@@ -28,6 +30,8 @@
 import java.util.Iterator;
 import java.util.List;
 
+import static org.onosproject.drivers.huawei.L3VpnUtil.getDevIdFromIns;
+
 /**
  * Representation of utility for huawei driver.
  */
@@ -164,26 +168,46 @@
      * not present then null is returned. If only one path is available in
      * the list then devices value is returned.
      *
-     * @param id model object data
+     * @param id    model object id
+     * @param isIns if for VPN instance
      * @return device id
      */
-    static String getIdFromModId(ModelObjectId id) {
+    static String getIdFromModId(ModelObjectId id, boolean isIns) {
         if (id == null) {
             return null;
         }
-
         List<AtomicPath> paths = id.atomicPaths();
         int size = paths.size();
-        if (size == 1) {
-            return CONS_DEVICES;
-        } else if (size == 2) {
-            return ((MultiInstanceNode) paths.get(1)).key().toString();
-        } else {
-            throw new IllegalArgumentException(MODEL_OBJ_ID_LIMIT);
+
+        switch (size) {
+            case 1:
+                return CONS_DEVICES;
+
+            case 2:
+                return getDevId(paths, isIns);
+
+            default:
+                throw new IllegalArgumentException(MODEL_OBJ_ID_LIMIT);
         }
     }
 
     /**
+     * Returns the device id from the model object id's key info.
+     *
+     * @param paths atomic path list
+     * @param isIns if VPN instance
+     * @return device id
+     */
+    private static String getDevId(List<AtomicPath> paths, boolean isIns) {
+        MultiInstanceNode info = (MultiInstanceNode) paths.get(1);
+        KeyInfo key = info.key();
+        if (!isIns) {
+            return ((DeviceKeys) key).deviceid();
+        }
+        return getDevIdFromIns(key);
+    }
+
+    /**
      * Returns the first object from the model object data. If no objects are
      * present then it returns null.
      *
diff --git a/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/HuaweiL3vpnConfig.java b/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/HuaweiL3VpnConfig.java
similarity index 92%
rename from drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/HuaweiL3vpnConfig.java
rename to drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/HuaweiL3VpnConfig.java
index 5a663e4..300e480 100644
--- a/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/HuaweiL3vpnConfig.java
+++ b/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/HuaweiL3VpnConfig.java
@@ -21,7 +21,7 @@
 import org.onosproject.config.FailedException;
 import org.onosproject.l3vpn.netl3vpn.BgpDriverInfo;
 import org.onosproject.l3vpn.netl3vpn.BgpInfo;
-import org.onosproject.net.behaviour.L3vpnConfig;
+import org.onosproject.net.behaviour.L3VpnConfig;
 import org.onosproject.net.driver.AbstractHandlerBehaviour;
 import org.onosproject.yang.gen.v1.l3vpn.comm.type.rev20141225.NeL3VpncommType;
 import org.onosproject.yang.gen.v1.ne.bgpcomm.rev20141225.NeBgpcomm;
@@ -40,11 +40,13 @@
 import java.util.Iterator;
 
 import static org.onosproject.drivers.huawei.BgpConstructionUtil.getCreateBgp;
+import static org.onosproject.drivers.huawei.BgpConstructionUtil.getDeleteBgp;
 import static org.onosproject.drivers.huawei.DriverUtil.DEVICES;
 import static org.onosproject.drivers.huawei.DriverUtil.NAMESPACE;
 import static org.onosproject.drivers.huawei.DriverUtil.SERVICE_NOT_FOUND;
 import static org.onosproject.drivers.huawei.DriverUtil.SLASH;
 import static org.onosproject.drivers.huawei.InsConstructionUtil.getCreateVpnIns;
+import static org.onosproject.drivers.huawei.InsConstructionUtil.getDeleteVpnIns;
 import static org.onosproject.drivers.huawei.IntConstructionUtil.getCreateInt;
 import static org.onosproject.yang.runtime.DefaultModelRegistrationParam.builder;
 import static org.onosproject.yang.runtime.helperutils.YangApacheUtils.getYangModel;
@@ -52,8 +54,8 @@
 /**
  * Configures l3vpn on Huawei devices.
  */
-public class HuaweiL3vpnConfig extends AbstractHandlerBehaviour
-        implements L3vpnConfig {
+public class HuaweiL3VpnConfig extends AbstractHandlerBehaviour
+        implements L3VpnConfig {
 
     /**
      * YANG model registry.
@@ -68,7 +70,7 @@
     /**
      * Constructs huawei L3VPN config.
      */
-    public HuaweiL3vpnConfig() {
+    public HuaweiL3VpnConfig() {
     }
 
     /**
@@ -148,7 +150,7 @@
 
     @Override
     public Object deleteInstance(Object objectData) {
-        return InsConstructionUtil.getDeleteVpnIns((ModelObjectData) objectData);
+        return getDeleteVpnIns((ModelObjectData) objectData);
     }
 
     @Override
@@ -159,8 +161,7 @@
 
     @Override
     public Object deleteBgpInfo(Object bgpInfo, Object bgpConfig) {
-        //TODO:To be committed.
-        return null;
+        return getDeleteBgp((BgpInfo) bgpInfo, (BgpDriverInfo) bgpConfig);
     }
 
     /**
diff --git a/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/InsConstructionUtil.java b/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/InsConstructionUtil.java
index 918c5fd..6e13c34 100644
--- a/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/InsConstructionUtil.java
+++ b/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/InsConstructionUtil.java
@@ -35,6 +35,7 @@
 import org.onosproject.yang.gen.v1.ne.l3vpn.api.rev20141225.nel3vpnapi.devices.device.l3vpn.l3vpncomm.l3vpninstances.l3vpninstance.vpninstafs.vpninstaf.VpnTargets;
 import org.onosproject.yang.gen.v1.ne.l3vpn.api.rev20141225.nel3vpnapi.devices.device.l3vpn.l3vpncomm.l3vpninstances.l3vpninstance.vpninstafs.vpninstaf.vpntargets.DefaultVpnTarget;
 import org.onosproject.yang.gen.v1.ne.l3vpn.api.rev20141225.nel3vpnapi.devices.device.l3vpn.l3vpncomm.l3vpninstances.l3vpninstance.vpninstafs.vpninstaf.vpntargets.VpnTarget;
+import org.onosproject.yang.gen.v1.ne.l3vpn.comm.rev20141225.nel3vpncomm.l3vpnifs.DefaultL3VpnIfs;
 import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.bgp.l3vpn.rev20160909.ietfbgpl3vpn.devices.device.networkinstances.networkinstance.DefaultAugmentedNiNetworkInstance;
 import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.bgp.l3vpn.rev20160909.ietfbgpl3vpn.l3vpnvrfparams.ipv4.Unicast;
 import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.bgp.l3vpn.rev20160909.ietfbgpl3vpn.routetargetset.Rts;
@@ -105,7 +106,7 @@
     static ModelObjectData getCreateVpnIns(ModelObjectData modObj,
                                            boolean isDevAvail) {
         ModelIdLevel modIdLvl = DEVICE;
-        String id = getIdFromModId(modObj.identifier());
+        String id = getIdFromModId(modObj.identifier(), true);
         Object obj = getObjFromModData(modObj);
 
         if (obj == null) {
@@ -392,7 +393,7 @@
      */
     static Object getDeleteVpnIns(ModelObjectData modObj) {
         ModelIdLevel modIdLvl = DEVICE;
-        String id = getIdFromModId(modObj.identifier());
+        String id = getIdFromModId(modObj.identifier(), true);
         Object obj = getObjFromModData(modObj);
 
         if (obj == null) {
@@ -434,20 +435,22 @@
         switch (modIdLvl) {
             case ROOT:
                 modId = getModObjIdDriDevices();
-                break;
+                DefaultDevice device = new DefaultDevice();
+                return getData(modId, device);
 
             case DEVICES:
+                DefaultL3Vpn l3Vpn = new DefaultL3Vpn();
                 modId = getModObjIdDriDevice(id).build();
-                break;
+                return getData(modId, l3Vpn);
 
             case DEVICE:
+                DefaultL3VpnIfs l3VpnIfs = new DefaultL3VpnIfs();
                 modId = getModObjIdDriVpn(id, name);
-                break;
+                return getData(modId, l3VpnIfs);
 
             default:
                 throw new IllegalArgumentException(UNSUPPORTED_MODEL_LVL);
         }
-        return getData(modId, null);
     }
 
     /**
diff --git a/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/IntConstructionUtil.java b/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/IntConstructionUtil.java
index da4a85c..bfd182a 100644
--- a/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/IntConstructionUtil.java
+++ b/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/IntConstructionUtil.java
@@ -77,7 +77,7 @@
      */
     static ModelObjectData getCreateInt(ModelObjectData modObj) {
         boolean isModIdAvail = true;
-        String id = getIdFromModId(modObj.identifier());
+        String id = getIdFromModId(modObj.identifier(), false);
         Object obj = getObjFromModData(modObj);
         if (id == null) {
             isModIdAvail = false;
diff --git a/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/L3VpnUtil.java b/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/L3VpnUtil.java
new file mode 100644
index 0000000..a0f04ce
--- /dev/null
+++ b/drivers/huawei/driver/src/main/java/org/onosproject/drivers/huawei/L3VpnUtil.java
@@ -0,0 +1,40 @@
+/*
+ * 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.drivers.huawei;
+
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.instance.rev20160623.ietfnetworkinstance.devices.DeviceKeys;
+import org.onosproject.yang.model.KeyInfo;
+
+/**
+ * Representation of utility for huawei driver's L3VPN.
+ */
+public final class L3VpnUtil {
+
+    // No instantiation.
+    private L3VpnUtil() {
+    }
+
+    /**
+     * Returns the device id from the instance key.
+     *
+     * @param key instance key
+     * @return device id
+     */
+    static String getDevIdFromIns(KeyInfo key) {
+        return ((DeviceKeys) key).deviceid();
+    }
+}
diff --git a/drivers/huawei/driver/src/main/resources/huawei-drivers.xml b/drivers/huawei/driver/src/main/resources/huawei-drivers.xml
index 35a1302..6918877 100644
--- a/drivers/huawei/driver/src/main/resources/huawei-drivers.xml
+++ b/drivers/huawei/driver/src/main/resources/huawei-drivers.xml
@@ -17,8 +17,8 @@
 <drivers>
     <driver name="huawei" extends="" manufacturer="Huawei"
             hwVersion="" swVersion="">
-        <behaviour api="org.onosproject.net.behaviour.L3vpnConfig"
-                   impl="org.onosproject.drivers.huawei.HuaweiL3vpnConfig"/>
+        <behaviour api="org.onosproject.net.behaviour.L3VpnConfig"
+                   impl="org.onosproject.drivers.huawei.HuaweiL3VpnConfig"/>
         <behaviour api="org.onosproject.net.device.DeviceDescriptionDiscovery"
                    impl="org.onosproject.drivers.huawei.HuaweiDeviceDescription"/>
         <behaviour api="org.onosproject.net.device.PortStatisticsDiscovery"
diff --git a/drivers/pom.xml b/drivers/pom.xml
index f68076b..5e73f4c 100644
--- a/drivers/pom.xml
+++ b/drivers/pom.xml
@@ -48,7 +48,6 @@
         <module>juniper</module>
         <module>lisp</module>
         <module>flowspec</module>
-        <module>huawei</module>
     </modules>
 
     <!--<properties>