ONOS-506: IPv6 forwarding option for ReactiveForwarder.

org.onosproject.fwd.ReactiveForwarding.cfg
------------------------------------------
ipv6Forwarding = true

will enable IPv6 forwarding in ReactiveForwarder.

ONOS-506: Updates for the comment.

* ReactiveForwarding.java
Line 133: Make the comment to concrete Javadoc.
Line 134: Method is changed to static.
Line 141: Catch ClassCastException instead of generic Exception.

* org.onosproject.fwd.ReactiveForwarding.cfg
Line 3: Fix typo ;-).
Line 7: Add comment: the option affects both IPv4 and IPv6.

Change-Id: Ie7fdc7fc26c7d36b9633bfc828dffe27015214f7
diff --git a/apps/fwd/src/main/java/org/onosproject/fwd/ReactiveForwarding.java b/apps/fwd/src/main/java/org/onosproject/fwd/ReactiveForwarding.java
index 2178247..fcf8efb 100644
--- a/apps/fwd/src/main/java/org/onosproject/fwd/ReactiveForwarding.java
+++ b/apps/fwd/src/main/java/org/onosproject/fwd/ReactiveForwarding.java
@@ -84,10 +84,15 @@
             label = "Enable packet-out only forwarding; default is false")
     private boolean packetOutOnly = false;
 
+    @Property(name = "ipv6Forwarding", boolValue = false,
+            label = "Enable IPv6 forwarding; default is false")
+    private boolean ipv6Forwarding = false;
+
     @Activate
-    public void activate() {
+    public void activate(ComponentContext context) {
         appId = coreService.registerApplication("org.onosproject.fwd");
         packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 2);
+        readComponentConfiguration(context);
         log.info("Started with Application ID {}", appId.id());
     }
 
@@ -101,16 +106,49 @@
 
     @Modified
     public void modified(ComponentContext context) {
-        Dictionary properties = context.getProperties();
-        String flag = (String) properties.get("packetOutOnly");
-        if (flag != null) {
-            boolean enabled = flag.equals("true");
-            if (packetOutOnly != enabled) {
-                packetOutOnly = enabled;
-                log.info("Reconfigured. Packet-out only forwarding is {}",
-                         packetOutOnly ? "enabled" : "disabled");
-            }
+        readComponentConfiguration(context);
+    }
+
+    /**
+     * Extracts properties from the component configuration context.
+     *
+     * @param context the component context
+     */
+    private void readComponentConfiguration(ComponentContext context) {
+        Dictionary<?, ?> properties = context.getProperties();
+        boolean packetOutOnlyEnabled = isPropertyEnabled(properties, "packetOutOnly");
+        if (packetOutOnly != packetOutOnlyEnabled) {
+            packetOutOnly = packetOutOnlyEnabled;
+            log.info("Configured. Packet-out only forwarding is {}",
+                    packetOutOnly ? "enabled" : "disabled");
         }
+        boolean ipv6ForwardingEnabled = isPropertyEnabled(properties, "ipv6Forwarding");
+        if (ipv6Forwarding != ipv6ForwardingEnabled) {
+            ipv6Forwarding = ipv6ForwardingEnabled;
+            log.info("Configured. IPv6 forwarding is {}",
+                    ipv6Forwarding ? "enabled" : "disabled");
+        }
+    }
+
+    /**
+     * Check property name is defined and set to true.
+     *
+     * @param properties properties to be looked up
+     * @param propertyName the name of the property to look up
+     * @return true when the propertyName is defined and set to true
+     */
+    private static boolean isPropertyEnabled(Dictionary<?, ?> properties, String propertyName) {
+        boolean enabled = false;
+        try {
+            String flag = (String) properties.get(propertyName);
+            if (flag != null) {
+                enabled = flag.equals("true");
+            }
+        } catch (ClassCastException e) {
+            // No propertyName defined.
+            enabled = false;
+        }
+        return enabled;
     }
 
     /**
@@ -129,8 +167,13 @@
             InboundPacket pkt = context.inPacket();
             Ethernet ethPkt = pkt.parsed();
 
-            // Bail if this is deemed to be a control or IPv6 multicast packet.
-            if (isControlPacket(ethPkt) || isIpv6Multicast(ethPkt)) {
+            // Bail if this is deemed to be a control packet.
+            if (isControlPacket(ethPkt)) {
+                return;
+            }
+
+            // Skip IPv6 multicast packet when IPv6 forward is disabled.
+            if (!ipv6Forwarding && isIpv6Multicast(ethPkt)) {
                 return;
             }
 
diff --git a/tools/package/etc/org.onosproject.fwd.ReactiveForwarding.cfg b/tools/package/etc/org.onosproject.fwd.ReactiveForwarding.cfg
new file mode 100644
index 0000000..f3c8e8e
--- /dev/null
+++ b/tools/package/etc/org.onosproject.fwd.ReactiveForwarding.cfg
@@ -0,0 +1,15 @@
+#
+# Sample configuration for onos-app-fwd.
+# This configuration file would be placed at: $(KARAF_ROOT)/etc.
+#
+
+#
+# Enable packet-out only forwarding.
+# This flag affects to both IPv4 and IPv6.
+#
+# packetOutOnly = true
+
+#
+# Enable IPv6 forwarding.
+#
+# ipv6Forwarding = true