Add group table, flow rules by listening to openstack node events

Change-Id: Ifbb1ae9c812e9bc24260e960c17b5430dcf59a11
diff --git a/apps/openstackvtap/app/src/main/java/org/onosproject/openstackvtap/util/OpenstackVtapUtil.java b/apps/openstackvtap/app/src/main/java/org/onosproject/openstackvtap/util/OpenstackVtapUtil.java
new file mode 100644
index 0000000..1e67693
--- /dev/null
+++ b/apps/openstackvtap/app/src/main/java/org/onosproject/openstackvtap/util/OpenstackVtapUtil.java
@@ -0,0 +1,79 @@
+/*
+ * 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.openstackvtap.util;
+
+import org.onlab.packet.IPv4;
+import org.onosproject.net.group.DefaultGroupKey;
+import org.onosproject.net.group.GroupKey;
+import org.onosproject.openstackvtap.api.OpenstackVtap;
+
+/**
+ * An utility that used in openstack vTap app.
+ */
+public final class OpenstackVtapUtil {
+
+    private static final String VTAP_GROUP_KEY = "VTAP_GROUP_KEY";
+
+    /**
+     * Prevents object instantiation from external.
+     */
+    private OpenstackVtapUtil() {
+    }
+
+    /**
+     * Obtains vTap type from the given string.
+     *
+     * @param str string
+     * @return vTap type
+     */
+    public static OpenstackVtap.Type getVtapTypeFromString(String str) {
+        switch (str) {
+            case "all":
+                return OpenstackVtap.Type.VTAP_ALL;
+            case "tx":
+                return OpenstackVtap.Type.VTAP_TX;
+            case "rx":
+                return OpenstackVtap.Type.VTAP_RX;
+            case "none":
+                return OpenstackVtap.Type.VTAP_NONE;
+            default:
+                throw new IllegalArgumentException("Invalid vTap type string");
+        }
+    }
+
+    /**
+     * Obtains IP protocol type from the given string.
+     *
+     * @param str string
+     * @return vTap type
+     */
+    public static byte getProtocolTypeFromString(String str) {
+        switch (str) {
+            case "tcp":
+                return IPv4.PROTOCOL_TCP;
+            case "udp":
+                return IPv4.PROTOCOL_UDP;
+            case "icmp":
+                return IPv4.PROTOCOL_ICMP;
+            default:
+                return 0;
+        }
+    }
+
+    public static GroupKey getGroupKey(int groupId) {
+        return new DefaultGroupKey((VTAP_GROUP_KEY + Integer.toString(groupId)).getBytes());
+    }
+}
diff --git a/apps/openstackvtap/app/src/main/java/org/onosproject/openstackvtap/util/package-info.java b/apps/openstackvtap/app/src/main/java/org/onosproject/openstackvtap/util/package-info.java
new file mode 100644
index 0000000..905d1c4
--- /dev/null
+++ b/apps/openstackvtap/app/src/main/java/org/onosproject/openstackvtap/util/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Openstack vTap utility package.
+ */
+package org.onosproject.openstackvtap.util;
\ No newline at end of file