OSGi property annotations for forwarding app

Change-Id: I3e4fa79e42edb232b141559823545494d117c4bf
diff --git a/apps/fwd/src/main/java/org/onosproject/fwd/OsgiPropertyConstants.java b/apps/fwd/src/main/java/org/onosproject/fwd/OsgiPropertyConstants.java
new file mode 100644
index 0000000..e4c795a
--- /dev/null
+++ b/apps/fwd/src/main/java/org/onosproject/fwd/OsgiPropertyConstants.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.fwd;
+
+public final class OsgiPropertyConstants {
+    private OsgiPropertyConstants() {
+    }
+
+    static final String PACKET_OUT_ONLY = "packetOutOnly";
+    static final boolean PACKET_OUT_ONLY_DEFAULT  = false;
+
+    static final String  PACKET_OUT_OFPP_TABLE  = "packetOutOfppTable";
+    static final boolean PACKET_OUT_OFPP_TABLE_DEFAULT = false;
+
+    static final String FLOW_TIMEOUT = "flowTimeout";
+    static final int FLOW_TIMEOUT_DEFAULT = 10;
+
+    static final String FLOW_PRIORITY = "flowPriority";
+    static final int FLOW_PRIORITY_DEFAULT = 10;
+
+    static final String IPV6_FORWARDING = "ipv6Forwarding";
+    static final boolean IPV6_FORWARDING_DEFAULT = false;
+
+    static final String MATCH_DST_MAC_ONLY = "matchDstMacOnly";
+    static final boolean MATCH_DST_MAC_ONLY_DEFAULT = false;
+
+    static final String MATCH_VLAN_ID = "matchVlanId";
+    static final boolean MATCH_VLAN_ID_DEFAULT = false;
+
+    static final String MATCH_IPV4_ADDRESS = "matchIpv4Address";
+    static final boolean MATCH_IPV4_ADDRESS_DEFAULT = false;
+
+    static final String MATCH_IPV4_DSCP = "matchIpv4Dscp";
+    static final boolean MATCH_IPV4_DSCP_DEFAULT = false;
+
+    static final String MATCH_IPV6_ADDRESS = "matchIpv6Address";
+    static final boolean MATCH_IPV6_ADDRESS_DEFAULT = false;
+
+    static final String MATCH_IPV6_FLOW_LABEL = "matchIpv6FlowLabel";
+    static final boolean MATCH_IPV6_FLOW_LABEL_DEFAULT = false;
+
+    static final String MATCH_TCP_UDP_PORTS = "matchTcpUdpPorts";
+    static final boolean MATCH_TCP_UDP_PORTS_DEFAULT = false;
+
+    static final String MATCH_ICMP_FIELDS = "matchIcmpFields";
+    static final boolean MATCH_ICMP_FIELDS_DEFAULT = false;
+
+    static final String IGNORE_IPV4_MCAST_PACKETS = "ignoreIPv4Multicast";
+    static final boolean IGNORE_IPV4_MCAST_PACKETS_DEFAULT = false;
+
+    static final String RECORD_METRICS = "recordMetrics";
+    static final boolean RECORD_METRICS_DEFAULT = false;
+}
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 77c304b..83dc3bc 100644
--- a/apps/fwd/src/main/java/org/onosproject/fwd/ReactiveForwarding.java
+++ b/apps/fwd/src/main/java/org/onosproject/fwd/ReactiveForwarding.java
@@ -89,17 +89,64 @@
 
 import static java.util.concurrent.Executors.newSingleThreadExecutor;
 import static org.onlab.util.Tools.groupedThreads;
+import static org.onosproject.fwd.OsgiPropertyConstants.FLOW_PRIORITY;
+import static org.onosproject.fwd.OsgiPropertyConstants.FLOW_PRIORITY_DEFAULT;
+import static org.onosproject.fwd.OsgiPropertyConstants.FLOW_TIMEOUT;
+import static org.onosproject.fwd.OsgiPropertyConstants.FLOW_TIMEOUT_DEFAULT;
+import static org.onosproject.fwd.OsgiPropertyConstants.IGNORE_IPV4_MCAST_PACKETS;
+import static org.onosproject.fwd.OsgiPropertyConstants.IGNORE_IPV4_MCAST_PACKETS_DEFAULT;
+import static org.onosproject.fwd.OsgiPropertyConstants.IPV6_FORWARDING;
+import static org.onosproject.fwd.OsgiPropertyConstants.IPV6_FORWARDING_DEFAULT;
+import static org.onosproject.fwd.OsgiPropertyConstants.MATCH_DST_MAC_ONLY;
+import static org.onosproject.fwd.OsgiPropertyConstants.MATCH_DST_MAC_ONLY_DEFAULT;
+import static org.onosproject.fwd.OsgiPropertyConstants.MATCH_ICMP_FIELDS;
+import static org.onosproject.fwd.OsgiPropertyConstants.MATCH_ICMP_FIELDS_DEFAULT;
+import static org.onosproject.fwd.OsgiPropertyConstants.MATCH_IPV4_ADDRESS;
+import static org.onosproject.fwd.OsgiPropertyConstants.MATCH_IPV4_ADDRESS_DEFAULT;
+import static org.onosproject.fwd.OsgiPropertyConstants.MATCH_IPV4_DSCP;
+import static org.onosproject.fwd.OsgiPropertyConstants.MATCH_IPV4_DSCP_DEFAULT;
+import static org.onosproject.fwd.OsgiPropertyConstants.MATCH_IPV6_ADDRESS;
+import static org.onosproject.fwd.OsgiPropertyConstants.MATCH_IPV6_ADDRESS_DEFAULT;
+import static org.onosproject.fwd.OsgiPropertyConstants.MATCH_IPV6_FLOW_LABEL;
+import static org.onosproject.fwd.OsgiPropertyConstants.MATCH_IPV6_FLOW_LABEL_DEFAULT;
+import static org.onosproject.fwd.OsgiPropertyConstants.MATCH_TCP_UDP_PORTS;
+import static org.onosproject.fwd.OsgiPropertyConstants.MATCH_TCP_UDP_PORTS_DEFAULT;
+import static org.onosproject.fwd.OsgiPropertyConstants.MATCH_VLAN_ID;
+import static org.onosproject.fwd.OsgiPropertyConstants.MATCH_VLAN_ID_DEFAULT;
+import static org.onosproject.fwd.OsgiPropertyConstants.PACKET_OUT_OFPP_TABLE;
+import static org.onosproject.fwd.OsgiPropertyConstants.PACKET_OUT_OFPP_TABLE_DEFAULT;
+import static org.onosproject.fwd.OsgiPropertyConstants.PACKET_OUT_ONLY;
+import static org.onosproject.fwd.OsgiPropertyConstants.PACKET_OUT_ONLY_DEFAULT;
+import static org.onosproject.fwd.OsgiPropertyConstants.RECORD_METRICS;
+import static org.onosproject.fwd.OsgiPropertyConstants.RECORD_METRICS_DEFAULT;
 import static org.slf4j.LoggerFactory.getLogger;
 
 /**
  * Sample reactive forwarding application.
  */
-@Component(immediate = true, service = ReactiveForwarding.class)
+@Component(
+    immediate = true,
+    service = ReactiveForwarding.class,
+    property = {
+        PACKET_OUT_ONLY + ":Boolean=" + PACKET_OUT_ONLY_DEFAULT,
+        PACKET_OUT_OFPP_TABLE + ":Boolean=" + PACKET_OUT_OFPP_TABLE_DEFAULT,
+        FLOW_TIMEOUT + ":Integer=" + FLOW_TIMEOUT_DEFAULT,
+        FLOW_PRIORITY  + ":Integer=" + FLOW_PRIORITY_DEFAULT,
+        IPV6_FORWARDING + ":Boolean=" + IPV6_FORWARDING_DEFAULT,
+        MATCH_DST_MAC_ONLY + ":Boolean=" + MATCH_DST_MAC_ONLY_DEFAULT,
+        MATCH_VLAN_ID + ":Boolean=" + MATCH_VLAN_ID_DEFAULT,
+        MATCH_IPV4_ADDRESS + ":Boolean=" + MATCH_IPV4_ADDRESS_DEFAULT,
+        MATCH_IPV4_DSCP + ":Boolean=" + MATCH_IPV4_DSCP_DEFAULT,
+        MATCH_IPV6_ADDRESS + ":Boolean=" + MATCH_IPV6_ADDRESS_DEFAULT,
+        MATCH_IPV6_FLOW_LABEL + ":Boolean=" + MATCH_IPV6_FLOW_LABEL_DEFAULT,
+        MATCH_TCP_UDP_PORTS + ":Boolean=" + MATCH_TCP_UDP_PORTS_DEFAULT,
+        MATCH_ICMP_FIELDS + ":Boolean=" + MATCH_ICMP_FIELDS_DEFAULT,
+        IGNORE_IPV4_MCAST_PACKETS + ":Boolean=" + IGNORE_IPV4_MCAST_PACKETS_DEFAULT,
+        RECORD_METRICS + ":Boolean=" + RECORD_METRICS_DEFAULT
+    }
+)
 public class ReactiveForwarding {
 
-    private static final int DEFAULT_TIMEOUT = 10;
-    private static final int DEFAULT_PRIORITY = 10;
-
     private final Logger log = getLogger(getClass());
 
     @Reference(cardinality = ReferenceCardinality.MANDATORY)
@@ -132,70 +179,50 @@
 
     private ApplicationId appId;
 
-    //@Property(name = "packetOutOnly", boolValue = false,
-    //        label = "Enable packet-out only forwarding; default is false")
-    private boolean packetOutOnly = false;
+    /** Enable packet-out only forwarding; default is false. */
+    private boolean packetOutOnly = PACKET_OUT_ONLY_DEFAULT;
 
-    //@Property(name = "packetOutOfppTable", boolValue = false,
-    //        label = "Enable first packet forwarding using OFPP_TABLE port " +
-    //                "instead of PacketOut with actual port; default is false")
-    private boolean packetOutOfppTable = false;
+    /** Enable first packet forwarding using OFPP_TABLE port instead of PacketOut with actual port; default is false. */
+    private boolean packetOutOfppTable = PACKET_OUT_OFPP_TABLE_DEFAULT;
 
-    //@Property(name = "flowTimeout", intValue = DEFAULT_TIMEOUT,
-    //        label = "Configure Flow Timeout for installed flow rules; " +
-    //                "default is 10 sec")
-    private int flowTimeout = DEFAULT_TIMEOUT;
+    /** Configure Flow Timeout for installed flow rules; default is 10 sec. */
+    private int flowTimeout = FLOW_TIMEOUT_DEFAULT;
 
-    //@Property(name = "flowPriority", intValue = DEFAULT_PRIORITY,
-    //        label = "Configure Flow Priority for installed flow rules; " +
-    //                "default is 10")
-    private int flowPriority = DEFAULT_PRIORITY;
+    /** Configure Flow Priority for installed flow rules; default is 10. */
+    private int flowPriority = FLOW_PRIORITY_DEFAULT;
 
-    //@Property(name = "ipv6Forwarding", boolValue = false,
-    //        label = "Enable IPv6 forwarding; default is false")
-    private boolean ipv6Forwarding = false;
+    /** Enable IPv6 forwarding; default is false. */
+    private boolean ipv6Forwarding = IPV6_FORWARDING_DEFAULT;
 
-    //@Property(name = "matchDstMacOnly", boolValue = false,
-    //        label = "Enable matching Dst Mac Only; default is false")
-    private boolean matchDstMacOnly = false;
+    /** Enable matching Dst Mac Only; default is false. */
+    private boolean matchDstMacOnly = MATCH_DST_MAC_ONLY_DEFAULT;
 
-    //@Property(name = "matchVlanId", boolValue = false,
-    //        label = "Enable matching Vlan ID; default is false")
-    private boolean matchVlanId = false;
+    /** Enable matching Vlan ID; default is false. */
+    private boolean matchVlanId = MATCH_VLAN_ID_DEFAULT;
 
-    //@Property(name = "matchIpv4Address", boolValue = false,
-    //        label = "Enable matching IPv4 Addresses; default is false")
-    private boolean matchIpv4Address = false;
+    /** Enable matching IPv4 Addresses; default is false. */
+    private boolean matchIpv4Address = MATCH_IPV4_ADDRESS_DEFAULT;
 
-    //@Property(name = "matchIpv4Dscp", boolValue = false,
-    //        label = "Enable matching IPv4 DSCP and ECN; default is false")
-    private boolean matchIpv4Dscp = false;
+    /** Enable matching IPv4 DSCP and ECN; default is false. */
+    private boolean matchIpv4Dscp = MATCH_IPV4_DSCP_DEFAULT;
 
-    //@Property(name = "matchIpv6Address", boolValue = false,
-    //        label = "Enable matching IPv6 Addresses; default is false")
-    private boolean matchIpv6Address = false;
+    /** Enable matching IPv6 Addresses; default is false. */
+    private boolean matchIpv6Address = MATCH_IPV6_ADDRESS_DEFAULT;
 
-    //@Property(name = "matchIpv6FlowLabel", boolValue = false,
-    //        label = "Enable matching IPv6 FlowLabel; default is false")
-    private boolean matchIpv6FlowLabel = false;
+    /** Enable matching IPv6 FlowLabel; default is false. */
+    private boolean matchIpv6FlowLabel = MATCH_IPV6_FLOW_LABEL_DEFAULT;
 
-    //@Property(name = "matchTcpUdpPorts", boolValue = false,
-    //        label = "Enable matching TCP/UDP ports; default is false")
-    private boolean matchTcpUdpPorts = false;
+    /** Enable matching TCP/UDP ports; default is false. */
+    private boolean matchTcpUdpPorts = MATCH_TCP_UDP_PORTS_DEFAULT;
 
-    //@Property(name = "matchIcmpFields", boolValue = false,
-    //        label = "Enable matching ICMPv4 and ICMPv6 fields; " +
-    //                "default is false")
-    private boolean matchIcmpFields = false;
+    /** Enable matching ICMPv4 and ICMPv6 fields; default is false. */
+    private boolean matchIcmpFields = MATCH_ICMP_FIELDS_DEFAULT;
 
+    /** Ignore (do not forward) IPv4 multicast packets; default is false. */
+    private boolean ignoreIpv4McastPackets = IGNORE_IPV4_MCAST_PACKETS_DEFAULT;
 
-    //@Property(name = "ignoreIPv4Multicast", boolValue = false,
-    //        label = "Ignore (do not forward) IPv4 multicast packets; default is false")
-    private boolean ignoreIpv4McastPackets = false;
-
-    //@Property(name = "recordMetrics", boolValue = false,
-    //        label = "Enable record metrics for reactive forwarding")
-    private boolean recordMetrics = false;
+    /** Enable record metrics for reactive forwarding. */
+    private boolean recordMetrics = RECORD_METRICS_DEFAULT;
 
     private final TopologyListener topologyListener = new InternalTopologyListener();
 
@@ -285,7 +312,7 @@
         Dictionary<?, ?> properties = context.getProperties();
 
         Boolean packetOutOnlyEnabled =
-                Tools.isPropertyEnabled(properties, "packetOutOnly");
+                Tools.isPropertyEnabled(properties, PACKET_OUT_ONLY);
         if (packetOutOnlyEnabled == null) {
             log.info("Packet-out is not configured, " +
                      "using current value of {}", packetOutOnly);
@@ -296,7 +323,7 @@
         }
 
         Boolean packetOutOfppTableEnabled =
-                Tools.isPropertyEnabled(properties, "packetOutOfppTable");
+                Tools.isPropertyEnabled(properties, PACKET_OUT_OFPP_TABLE);
         if (packetOutOfppTableEnabled == null) {
             log.info("OFPP_TABLE port is not configured, " +
                      "using current value of {}", packetOutOfppTable);
@@ -307,7 +334,7 @@
         }
 
         Boolean ipv6ForwardingEnabled =
-                Tools.isPropertyEnabled(properties, "ipv6Forwarding");
+                Tools.isPropertyEnabled(properties, IPV6_FORWARDING);
         if (ipv6ForwardingEnabled == null) {
             log.info("IPv6 forwarding is not configured, " +
                      "using current value of {}", ipv6Forwarding);
@@ -318,7 +345,7 @@
         }
 
         Boolean matchDstMacOnlyEnabled =
-                Tools.isPropertyEnabled(properties, "matchDstMacOnly");
+                Tools.isPropertyEnabled(properties, MATCH_DST_MAC_ONLY);
         if (matchDstMacOnlyEnabled == null) {
             log.info("Match Dst MAC is not configured, " +
                      "using current value of {}", matchDstMacOnly);
@@ -329,7 +356,7 @@
         }
 
         Boolean matchVlanIdEnabled =
-                Tools.isPropertyEnabled(properties, "matchVlanId");
+                Tools.isPropertyEnabled(properties, MATCH_VLAN_ID);
         if (matchVlanIdEnabled == null) {
             log.info("Matching Vlan ID is not configured, " +
                      "using current value of {}", matchVlanId);
@@ -340,7 +367,7 @@
         }
 
         Boolean matchIpv4AddressEnabled =
-                Tools.isPropertyEnabled(properties, "matchIpv4Address");
+                Tools.isPropertyEnabled(properties, MATCH_IPV4_ADDRESS);
         if (matchIpv4AddressEnabled == null) {
             log.info("Matching IPv4 Address is not configured, " +
                      "using current value of {}", matchIpv4Address);
@@ -351,7 +378,7 @@
         }
 
         Boolean matchIpv4DscpEnabled =
-                Tools.isPropertyEnabled(properties, "matchIpv4Dscp");
+                Tools.isPropertyEnabled(properties, MATCH_IPV4_DSCP);
         if (matchIpv4DscpEnabled == null) {
             log.info("Matching IPv4 DSCP and ECN is not configured, " +
                      "using current value of {}", matchIpv4Dscp);
@@ -362,7 +389,7 @@
         }
 
         Boolean matchIpv6AddressEnabled =
-                Tools.isPropertyEnabled(properties, "matchIpv6Address");
+                Tools.isPropertyEnabled(properties, MATCH_IPV6_ADDRESS);
         if (matchIpv6AddressEnabled == null) {
             log.info("Matching IPv6 Address is not configured, " +
                      "using current value of {}", matchIpv6Address);
@@ -373,7 +400,7 @@
         }
 
         Boolean matchIpv6FlowLabelEnabled =
-                Tools.isPropertyEnabled(properties, "matchIpv6FlowLabel");
+                Tools.isPropertyEnabled(properties, MATCH_IPV6_FLOW_LABEL);
         if (matchIpv6FlowLabelEnabled == null) {
             log.info("Matching IPv6 FlowLabel is not configured, " +
                      "using current value of {}", matchIpv6FlowLabel);
@@ -384,7 +411,7 @@
         }
 
         Boolean matchTcpUdpPortsEnabled =
-                Tools.isPropertyEnabled(properties, "matchTcpUdpPorts");
+                Tools.isPropertyEnabled(properties, MATCH_TCP_UDP_PORTS);
         if (matchTcpUdpPortsEnabled == null) {
             log.info("Matching TCP/UDP fields is not configured, " +
                      "using current value of {}", matchTcpUdpPorts);
@@ -395,7 +422,7 @@
         }
 
         Boolean matchIcmpFieldsEnabled =
-                Tools.isPropertyEnabled(properties, "matchIcmpFields");
+                Tools.isPropertyEnabled(properties, MATCH_ICMP_FIELDS);
         if (matchIcmpFieldsEnabled == null) {
             log.info("Matching ICMP (v4 and v6) fields is not configured, " +
                      "using current value of {}", matchIcmpFields);
@@ -406,7 +433,7 @@
         }
 
         Boolean ignoreIpv4McastPacketsEnabled =
-                Tools.isPropertyEnabled(properties, "ignoreIpv4McastPackets");
+                Tools.isPropertyEnabled(properties, IGNORE_IPV4_MCAST_PACKETS);
         if (ignoreIpv4McastPacketsEnabled == null) {
             log.info("Ignore IPv4 multi-cast packet is not configured, " +
                      "using current value of {}", ignoreIpv4McastPackets);
@@ -416,7 +443,7 @@
                     ignoreIpv4McastPackets ? "enabled" : "disabled");
         }
         Boolean recordMetricsEnabled =
-                Tools.isPropertyEnabled(properties, "recordMetrics");
+                Tools.isPropertyEnabled(properties, RECORD_METRICS);
         if (recordMetricsEnabled == null) {
             log.info("IConfigured. Ignore record metrics  is {} ," +
                     "using current value of {}", recordMetrics);
@@ -426,10 +453,10 @@
                     recordMetrics ? "enabled" : "disabled");
         }
 
-        flowTimeout = Tools.getIntegerProperty(properties, "flowTimeout", DEFAULT_TIMEOUT);
+        flowTimeout = Tools.getIntegerProperty(properties, FLOW_TIMEOUT, FLOW_TIMEOUT_DEFAULT);
         log.info("Configured. Flow Timeout is configured to {} seconds", flowTimeout);
 
-        flowPriority = Tools.getIntegerProperty(properties, "flowPriority", DEFAULT_PRIORITY);
+        flowPriority = Tools.getIntegerProperty(properties, FLOW_PRIORITY, FLOW_PRIORITY_DEFAULT);
         log.info("Configured. Flow Priority is configured to {}", flowPriority);
     }