Fix bugs for dynamic interface configuration

- portNextObjStore is not updated when adding or removing portNextObjective
- Group keys for L2IG in flowObjectiveStore are deleted while modifying L2IG, which in turn causes an exception
- L3UG pointing to L2IG, which is already removed, is not removed
- Empty L2FG, with VLAN ID removed from the configuration, is not removed
- Bridging and unicast routing rules for hosts are not updated when changing port VLAN from untagged to tagged and vice versa

Change-Id: I9454fe553ae53e0fc8839a4ad629c0b5b9039a36
diff --git a/apps/segmentrouting/app/src/main/java/org/onosproject/segmentrouting/HostHandler.java b/apps/segmentrouting/app/src/main/java/org/onosproject/segmentrouting/HostHandler.java
index dcc77f8..a21e327 100644
--- a/apps/segmentrouting/app/src/main/java/org/onosproject/segmentrouting/HostHandler.java
+++ b/apps/segmentrouting/app/src/main/java/org/onosproject/segmentrouting/HostHandler.java
@@ -707,15 +707,29 @@
         MacAddress mac = host.mac();
         VlanId hostVlanId = host.vlan();
 
-        // Check whether the host vlan is valid for new interface configuration
-        if ((!popVlan && hostVlanId.equals(vlanId)) ||
-                (popVlan && hostVlanId.equals(VlanId.NONE))) {
-            srManager.defaultRoutingHandler.updateBridging(deviceId, portNum, mac, vlanId, popVlan, install);
-            // Update Forwarding objective and corresponding simple Next objective
-            // for each host and IP address connected to given port
-            host.ipAddresses().forEach(ipAddress -> srManager.defaultRoutingHandler.updateFwdObj(
-                    deviceId, portNum, ipAddress.toIpPrefix(), mac, vlanId, popVlan, install)
+        if (!install) {
+            // Do not check the host validity. Just remove all rules corresponding to the vlan id
+            // Revoke forwarding objective for bridging to the host
+            srManager.defaultRoutingHandler.updateBridging(deviceId, portNum, mac, vlanId, popVlan, false);
+
+            // Revoke forwarding objective and corresponding simple Next objective
+            // for each Host and IP address connected to given port
+            host.ipAddresses().forEach(ipAddress ->
+                srManager.routingRulePopulator.updateFwdObj(deviceId, portNum, ipAddress.toIpPrefix(),
+                                                            mac, vlanId, popVlan, false)
             );
+        } else {
+            // Check whether the host vlan is valid for new interface configuration
+            if ((!popVlan && hostVlanId.equals(vlanId)) ||
+                    (popVlan && hostVlanId.equals(VlanId.NONE))) {
+                srManager.defaultRoutingHandler.updateBridging(deviceId, portNum, mac, vlanId, popVlan, true);
+                // Update Forwarding objective and corresponding simple Next objective
+                // for each Host and IP address connected to given port
+                host.ipAddresses().forEach(ipAddress ->
+                    srManager.routingRulePopulator.updateFwdObj(deviceId, portNum, ipAddress.toIpPrefix(),
+                                                                mac, vlanId, popVlan, true)
+                );
+            }
         }
     }