diff --git a/src/vnm_mad/remotes/802.1Q/clean b/src/vnm_mad/remotes/802.1Q/clean
deleted file mode 120000
index 940540d063..0000000000
--- a/src/vnm_mad/remotes/802.1Q/clean
+++ /dev/null
@@ -1 +0,0 @@
-../fw/clean
\ No newline at end of file
diff --git a/src/vnm_mad/remotes/802.1Q/clean b/src/vnm_mad/remotes/802.1Q/clean
new file mode 100755
index 0000000000..667e452885
--- /dev/null
+++ b/src/vnm_mad/remotes/802.1Q/clean
@@ -0,0 +1,36 @@
+#!/usr/bin/env ruby
+
+# -------------------------------------------------------------------------- #
+# Copyright 2002-2015, OpenNebula Project (OpenNebula.org), C12G Labs        #
+#                                                                            #
+# 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.                                             #
+#--------------------------------------------------------------------------- #
+
+$: << File.dirname(__FILE__)
+$: << File.join(File.dirname(__FILE__), "..")
+
+require 'vnmmad'
+require 'vlan_tag_driver'
+
+template64 = ARGV[0]
+
+begin
+    hm = VLANTagDriver.from_base64(template64)
+    hm.deactivate
+    filter_driver = VNMMAD::VNMDriver.filter_driver(template64)
+    filter_driver.deactivate
+rescue Exception => e
+    OpenNebula.log_error(e.message)
+    OpenNebula.log_error(e.backtrace)
+    exit 1
+end
diff --git a/src/vnm_mad/remotes/802.1Q/vlan_tag_driver.rb b/src/vnm_mad/remotes/802.1Q/vlan_tag_driver.rb
index edc8365f2e..b5c74c2d57 100644
--- a/src/vnm_mad/remotes/802.1Q/vlan_tag_driver.rb
+++ b/src/vnm_mad/remotes/802.1Q/vlan_tag_driver.rb
@@ -30,10 +30,10 @@ class VLANTagDriver < VNMMAD::VLANDriver
     XPATH_FILTER = "TEMPLATE/NIC[VLAN='YES']"
 
     ############################################################################
-    # Creatges the driver device operations are not locked
+    # Create driver device operations are locked
     ############################################################################
     def initialize(vm, deploy_id = nil, hypervisor = nil)
-        @locking = false
+        @locking = true
 
         super(vm, XPATH_FILTER, deploy_id, hypervisor)
     end
@@ -41,13 +41,13 @@ class VLANTagDriver < VNMMAD::VLANDriver
     ############################################################################
     # This function creates and activate a VLAN device
     ############################################################################
-    def create_vlan_dev(options)
-        mtu = options[:mtu] ? "mtu #{options[:mtu]}" : ""
+    def create_vlan_dev
+        mtu = @nic[:mtu] ? "mtu #{@nic[:mtu]}" : ""
 
         OpenNebula.exec_and_log("#{command(:ip)} link add link"\
-            " #{options[:phydev]} name #{options[:vlan_dev]} #{mtu} type vlan id"\
-            " #{options[:vlan_id]}")
+            " #{@nic[:phydev]} name #{@nic[:vlan_dev]} #{mtu} type vlan id"\
+            " #{@nic[:vlan_id]}")
 
-        OpenNebula.exec_and_log("#{command(:ip)} link set #{options[:vlan_dev]} up")
+        OpenNebula.exec_and_log("#{command(:ip)} link set #{@nic[:vlan_dev]} up")
     end
 end
diff --git a/src/vnm_mad/remotes/lib/vlan.rb b/src/vnm_mad/remotes/lib/vlan.rb
index 469aa207e8..04b7231fde 100644
--- a/src/vnm_mad/remotes/lib/vlan.rb
+++ b/src/vnm_mad/remotes/lib/vlan.rb
@@ -24,6 +24,8 @@ module VNMMAD
     class VLANDriver < VNMMAD::VNMDriver
 
         def initialize(vm_tpl, xpath_filter, deploy_id = nil, hypervisor = nil)
+            @locking = true
+
             super(vm_tpl, xpath_filter, deploy_id, hypervisor)
 
             lock
@@ -35,21 +37,28 @@ module VNMMAD
         def activate
             lock
 
-            options = Hash.new
-
             process do |nic|
+                @nic = nic
 
-                options.clear
+                next if @nic[:phydev].nil?
 
-                options[:bridge]     = nic[:bridge]
-                options[:phydev]     = nic[:phydev]
-                options[:vlan_id]    = nic[:vlan_id]
-                options[:network_id] = nic[:network_id]
-                options[:mtu]        = nic[:mtu]
+                # Get the name of the vlan device.
+                get_vlan_dev_name
 
-                return if options[:phydev].nil?
+                # Create the bridge.
+                create_bridge
 
-                set_up_vlan(options)
+                # Return if vlan device is already in the bridge.
+                next if @bridges[@nic[:bridge]].include? @nic[:vlan_dev]
+
+                # Create vlan device.
+                create_vlan_dev
+
+                # Add vlan device to the bridge.
+                OpenNebula.exec_and_log("#{command(:brctl)} addif"\
+                    " #{@nic[:bridge]} #{@nic[:vlan_dev]}")
+
+                @bridges[@nic[:bridge]] << @nic[:vlan_dev]
             end
 
             unlock
@@ -57,56 +66,67 @@ module VNMMAD
             return 0
         end
 
-        # Set ups the VLAN for the VMs.
-        #   @param options [Hash] including
-        #   - :phydev Physical Device to bind the VLAN traffic to
-        #   - :bridge Name of the bridge to attach the VMs and VLAN dev to
-        #   - :network_id
-        def set_up_vlan(options)
-
-            if options[:vlan_id].nil?
-                options[:vlan_id] = CONF[:start_vlan] + options[:network_id].to_i
-            end
-
-            options[:vlan_dev] = "#{options[:phydev]}.#{options[:vlan_id]}"
-
-            create_bridge(options[:bridge])
-
-            return if @bridges[options[:bridge]].include? options[:vlan_dev]
-
-            create_vlan_dev(options)
-
-            OpenNebula.exec_and_log("#{command(:brctl)} addif"\
-                " #{options[:bridge]} #{options[:vlan_dev]}")
-
-            @bridges[options[:bridge]] << options[:vlan_dev]
-        end
-
         # This function needs to be implemented by any VLAN driver to
         # create the VLAN device. The device MUST be set up by this function
-        # Options is a driver specific hash. It includes
-        #   :vlan_dev the name for the VLAN device
-        #   :phydev Physical Device to bind the VLAN traffic to
-        #   :vlan_id the VLAN ID
-        #   : additional driver specific parameters
-        def create_vlan_dev(options)
+        def create_vlan_dev
             OpenNebula.log_error("create_vlan_dev function not implemented.")
 
             exit -1
         end
 
+        # Deactivate the driver and delete bridges and tags devices as needed.
+        def deactivate
+            lock
+
+            attach_nic_id = @vm['TEMPLATE/NIC[ATTACH="YES"]/NIC_ID']
+
+            process do |nic|
+                next if attach_nic_id && attach_nic_id != nic[:nic_id]
+
+                @nic = nic
+
+                next if @nic[:phydev].nil?
+
+                # Get the name of the vlan device.
+                get_vlan_dev_name
+
+                # Return if the vlan device is not the only left device in the bridge.
+                next if @bridges[@nic[:bridge]].length > 1 or !@bridges[@nic[:bridge]].include? @nic[:vlan_dev]
+
+                # Delete the vlan device.
+                OpenNebula.exec_and_log("#{command(:ip)} link delete"\
+                    " #{@nic[:vlan_dev]}")
+                @bridges[@nic[:bridge]].delete(@nic[:vlan_dev])
+
+                # Delete the bridge.
+                OpenNebula.exec_and_log("#{command(:ip)} link delete"\
+                    " #{@nic[:bridge]}")
+                @bridges.delete(@nic[:bridge])
+            end
+
+            unlock
+        end
+
     private
+        # Generate the name of the vlan device which will be added to the bridge.
+        def get_vlan_dev_name
+            if @nic[:vlan_id].nil?
+                @nic[:vlan_id] = CONF[:start_vlan] + @nic[:network_id].to_i
+            end
+
+            @nic[:vlan_dev] = "#{@nic[:phydev]}.#{@nic[:vlan_id]}"
+        end
+
         # Creates a bridge if it does not exists, and brings it up.
         # This function IS FINAL, exits if action cannot be completed
-        #   @param bridge [String] the bridge name
-        def create_bridge(bridge)
-            return if @bridges.keys.include? bridge
+        def create_bridge
+            return if @bridges.keys.include? @nic[:bridge]
 
-            OpenNebula.exec_and_log("#{command(:brctl)} addbr #{bridge}")
+            OpenNebula.exec_and_log("#{command(:brctl)} addbr #{@nic[:bridge]}")
 
-            @bridges[bridge] = Array.new
+            @bridges[@nic[:bridge]] = Array.new
 
-            OpenNebula.exec_and_log("#{command(:ip)} link set #{bridge} up")
+            OpenNebula.exec_and_log("#{command(:ip)} link set #{@nic[:bridge]} up")
         end
 
         # Get hypervisor bridges
diff --git a/src/vnm_mad/remotes/vxlan/clean b/src/vnm_mad/remotes/vxlan/clean
deleted file mode 120000
index 940540d063..0000000000
--- a/src/vnm_mad/remotes/vxlan/clean
+++ /dev/null
@@ -1 +0,0 @@
-../fw/clean
\ No newline at end of file
diff --git a/src/vnm_mad/remotes/vxlan/clean b/src/vnm_mad/remotes/vxlan/clean
new file mode 100755
index 0000000000..7b9bc76bb1
--- /dev/null
+++ b/src/vnm_mad/remotes/vxlan/clean
@@ -0,0 +1,36 @@
+#!/usr/bin/env ruby
+
+# -------------------------------------------------------------------------- #
+# Copyright 2002-2015, OpenNebula Project (OpenNebula.org), C12G Labs        #
+#                                                                            #
+# 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.                                             #
+#--------------------------------------------------------------------------- #
+
+$: << File.dirname(__FILE__)
+$: << File.join(File.dirname(__FILE__), "..")
+
+require 'vnmmad'
+require 'vxlan_driver'
+
+template64 = ARGV[0]
+
+begin
+    hm = VXLANDriver.from_base64(template64)
+    hm.deactivate
+    filter_driver = VNMMAD::VNMDriver.filter_driver(template64)
+    filter_driver.deactivate
+rescue Exception => e
+    OpenNebula.log_error(e.message)
+    OpenNebula.log_error(e.backtrace)
+    exit 1
+end
diff --git a/src/vnm_mad/remotes/vxlan/vxlan_driver.rb b/src/vnm_mad/remotes/vxlan/vxlan_driver.rb
index b5d26f63fe..35e06af011 100644
--- a/src/vnm_mad/remotes/vxlan/vxlan_driver.rb
+++ b/src/vnm_mad/remotes/vxlan/vxlan_driver.rb
@@ -30,10 +30,10 @@ class VXLANDriver < VNMMAD::VLANDriver
     XPATH_FILTER = "TEMPLATE/NIC[VLAN='YES']"
 
     ############################################################################
-    # Creatges the driver device operations are not locked
+    # Create driver device operations are locked
     ############################################################################
     def initialize(vm, deploy_id = nil, hypervisor = nil)
-        @locking = false
+        @locking = true
 
         super(vm, XPATH_FILTER, deploy_id, hypervisor)
     end
@@ -41,15 +41,15 @@ class VXLANDriver < VNMMAD::VLANDriver
     ############################################################################
     # This function creates and activate a VLAN device
     ############################################################################
-    def create_vlan_dev(options)
-        mc  = VNMMAD::VNMNetwork::IPv4.to_i(CONF[:vxlan_mc]) + options[:vlan_id].to_i
+    def create_vlan_dev
+        mc  = VNMMAD::VNMNetwork::IPv4.to_i(CONF[:vxlan_mc]) + @nic[:vlan_id].to_i
         mcs = VNMMAD::VNMNetwork::IPv4.to_s(mc)
-        mtu = options[:mtu] ? "mtu #{options[:mtu]}" : ""
+        mtu = @nic[:mtu] ? "mtu #{@nic[:mtu]}" : ""
 
-        OpenNebula.exec_and_log("#{command(:ip)} link add #{options[:vlan_dev]}"\
-            " #{mtu} type vxlan id #{options[:vlan_id]} group #{mcs}"\
-            " dev #{options[:phydev]}")
+        OpenNebula.exec_and_log("#{command(:ip)} link add #{@nic[:vlan_dev]}"\
+            " #{mtu} type vxlan id #{@nic[:vlan_id]} group #{mcs}"\
+            " dev #{@nic[:phydev]}")
 
-        OpenNebula.exec_and_log("#{command(:ip)} link set #{options[:vlan_dev]} up")
+        OpenNebula.exec_and_log("#{command(:ip)} link set #{@nic[:vlan_dev]} up")
     end
 end