Adding openflow protocol set support in onos for device

Change-Id: Id796e54b536eda19d511a1978657abd6e149f117
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/BridgeDescription.java b/core/api/src/main/java/org/onosproject/net/behaviour/BridgeDescription.java
index 945fd5b..a3b02a8 100644
--- a/core/api/src/main/java/org/onosproject/net/behaviour/BridgeDescription.java
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/BridgeDescription.java
@@ -104,6 +104,14 @@
     Optional<Boolean> disableInBand();
 
     /**
+     * Returns list of Control Protocol Versions supported on device.
+     * @return List of Control Protocol Versions enabled on bridge
+     */
+    Optional<List<ControlProtocolVersion>> controlProtocols();
+
+    /**
+
+    /**
      * Builder of bridge description entities.
      */
     interface Builder {
@@ -156,6 +164,13 @@
         Builder datapathType(String datapathType);
 
         /**
+         * Returns bridge description builder with given control protocol versions.
+         * @param controlProtocols List of control protocol
+         * @return bridge description builder
+         */
+        Builder controlProtocols(List<ControlProtocolVersion> controlProtocols);
+
+        /**
          * Returns bridge description builder with in-band control disabled.
          *
          * @return bridge description builder
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/ControlProtocolVersion.java b/core/api/src/main/java/org/onosproject/net/behaviour/ControlProtocolVersion.java
new file mode 100644
index 0000000..2b5ee7c
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/ControlProtocolVersion.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2017-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.net.behaviour;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public enum ControlProtocolVersion {
+    OF_1_0("OpenFlow10"),
+    OF_1_1("OpenFlow11"),
+    OF_1_2("OpenFlow12"),
+    OF_1_3("OpenFlow13"),
+    OF_1_4("OpenFlow14"),
+    OF_1_5("OpenFlow15");
+
+    private final String versionString;
+
+    /**
+     * Creates the enum from a string representing the control protoocol version.
+     *
+     * @param versionString the text representing the control protocol version.
+     */
+    ControlProtocolVersion(final String versionString) {
+        this.versionString = versionString;
+    }
+
+    @Override
+    public String toString() {
+        return versionString;
+    }
+
+    /**
+     * Returns a list of control protocol version string values.
+     *
+     * @return the list of string values corresponding to the enums
+     */
+    public static List<String> toStringList() {
+        return Arrays.stream(values())
+                .map(ControlProtocolVersion::toString)
+                .collect(Collectors.toCollection(ArrayList::new));
+    }
+
+    /**
+     * Alternative method to valueOf. It returns the ControlProtocolVersion type
+     * corresponding to the given string. If the parameter does not match a
+     * constant name, or is null, null is returned.
+     *
+     * @param versionString the string representing the encapsulation type
+     * @return the EncapsulationType constant corresponding to the string given
+     */
+    public static ControlProtocolVersion enumFromString(String versionString) {
+        if (versionString != null && !versionString.isEmpty()) {
+            for (ControlProtocolVersion c : values()) {
+                if (versionString.equalsIgnoreCase(c.toString())) {
+                    return c;
+                }
+            }
+        }
+        return null;
+    }
+
+}
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/DefaultBridgeDescription.java b/core/api/src/main/java/org/onosproject/net/behaviour/DefaultBridgeDescription.java
index 1d5f550..cc0b837 100644
--- a/core/api/src/main/java/org/onosproject/net/behaviour/DefaultBridgeDescription.java
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/DefaultBridgeDescription.java
@@ -39,6 +39,7 @@
     private final Optional<FailMode> failMode;
     private final Optional<String> datapathId;
     private final Optional<String> datapathType;
+    private final Optional<List<ControlProtocolVersion>> controlProtocols;
     private final Optional<Boolean> disableInBand;
 
     /* Adds more configurations */
@@ -49,7 +50,8 @@
                                      Optional<FailMode> failMode,
                                      Optional<String> datapathId,
                                      Optional<String> datapathType,
-                                     Optional<Boolean> disableInBand) {
+                                     Optional<Boolean> disableInBand,
+                                     Optional<List<ControlProtocolVersion>> controlProtocols) {
         this.name = checkNotNull(name);
         this.controllers = controllers;
         this.enableLocalController = enableLocalController;
@@ -57,6 +59,7 @@
         this.datapathId = datapathId;
         this.datapathType = datapathType;
         this.disableInBand = disableInBand;
+        this.controlProtocols = controlProtocols;
     }
 
     @Override
@@ -95,6 +98,11 @@
     }
 
     @Override
+    public Optional<List<ControlProtocolVersion>> controlProtocols() {
+        return controlProtocols;
+    }
+
+    @Override
     public Optional<DeviceId> deviceId() {
         if (datapathId.isPresent()) {
             return Optional.of(DeviceId.deviceId("of:" + datapathId.get()));
@@ -125,6 +133,7 @@
         private Optional<FailMode> failMode = Optional.empty();
         private Optional<String> datapathId = Optional.empty();
         private Optional<String> datapathType = Optional.empty();
+        private Optional<List<ControlProtocolVersion>> controlProtocols = Optional.empty();
         private Optional<Boolean> disableInBand = Optional.empty();
 
         private Builder() {
@@ -137,7 +146,8 @@
                                                 failMode,
                                                 datapathId,
                                                 datapathType,
-                                                disableInBand);
+                                                disableInBand,
+                                                controlProtocols);
         }
 
         @Override
@@ -180,6 +190,12 @@
         }
 
         @Override
+        public Builder controlProtocols(List<ControlProtocolVersion> controlProtocols) {
+            this.controlProtocols = Optional.ofNullable(controlProtocols);
+            return this;
+        }
+
+        @Override
         public Builder disableInBand() {
             this.disableInBand = Optional.of(Boolean.TRUE);
             return this;
diff --git a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbBridge.java b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbBridge.java
index 34c2d43..6bddef3 100644
--- a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbBridge.java
+++ b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbBridge.java
@@ -20,16 +20,16 @@
 import org.onosproject.net.behaviour.BridgeDescription;
 import org.onosproject.net.behaviour.BridgeDescription.FailMode;
 import org.onosproject.net.behaviour.ControllerInfo;
-
+import org.onosproject.net.behaviour.ControlProtocolVersion;
 import static com.google.common.base.MoreObjects.toStringHelper;
 import static org.onosproject.ovsdb.controller.OvsdbConstant.DATAPATH_ID;
 import static org.onosproject.ovsdb.controller.OvsdbConstant.DISABLE_INBAND;
-
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Optional;
 
+
 import static com.google.common.base.Preconditions.checkNotNull;
 
 /**
@@ -47,6 +47,9 @@
     /* Adds more properties */
     private final Optional<String> datapathType;
 
+    /* Add control protocol version property */
+    private final Optional<List<ControlProtocolVersion>> controlProtocols;
+
     /* other optional configs */
     private final Map<String, String> otherConfigs;
 
@@ -57,16 +60,19 @@
      * @param failMode openflow controller fail mode policy
      * @param controllers list of openflow controllers
      * @param datapathType ovs datapath_type
+     * @param controlProtocols list of control protocols
      * @param otherConfigs other configs
      */
     private OvsdbBridge(String name, Optional<FailMode> failMode,
                        List<ControllerInfo> controllers,
                        Optional<String> datapathType,
+                       Optional<List<ControlProtocolVersion>> controlProtocols,
                        Map<String, String> otherConfigs) {
         this.name = checkNotNull(name);
         this.failMode = failMode;
         this.controllers = controllers;
         this.datapathType = datapathType;
+        this.controlProtocols = controlProtocols;
         this.otherConfigs = otherConfigs;
     }
 
@@ -107,6 +113,14 @@
     }
 
     /**
+     *  Returns Control protocol versions of the bridge.
+     * @return List of Control protocols
+     */
+    public Optional<List<ControlProtocolVersion>> controlProtocols() {
+        return controlProtocols;
+    }
+
+    /**
      * Returns other configurations of the bridge.
      *
      * @return map of configurations
@@ -148,6 +162,7 @@
                 .add("failMode", failMode)
                 .add("controllers", controllers)
                 .add("datapathType", datapathType)
+                .add("controlProtocols", controlProtocols)
                 .add("otherConfigs", otherConfigs)
                 .toString();
     }
@@ -180,6 +195,7 @@
         private List<ControllerInfo> controllers = Lists.newArrayList();
         private Optional<String> datapathType = Optional.empty();
         private Map<String, String> otherConfigs = Maps.newHashMap();
+        private Optional<List<ControlProtocolVersion>> controlProtocols = Optional.empty();
 
         private Builder() {
         }
@@ -200,6 +216,9 @@
             if (bridgeDesc.datapathType().isPresent()) {
                 this.datapathType = bridgeDesc.datapathType();
             }
+            if (bridgeDesc.controlProtocols().isPresent()) {
+                this.controlProtocols = bridgeDesc.controlProtocols();
+            }
             this.name = bridgeDesc.name();
             this.failMode = bridgeDesc.failMode();
             this.controllers = Lists.newArrayList(bridgeDesc.controllers());
@@ -211,7 +230,7 @@
          * @return ovsdb bridge
          */
         public OvsdbBridge build() {
-            return new OvsdbBridge(name, failMode, controllers, datapathType, otherConfigs);
+            return new OvsdbBridge(name, failMode, controllers, datapathType, controlProtocols, otherConfigs);
         }
 
         /**
@@ -292,6 +311,16 @@
         }
 
         /**
+         * Returns OVSDB bridge builder with  given control protocol Versions.
+         * @param controlProtocols list of control protocols
+         * @return ovsdb bridge builder
+         */
+        public Builder controlProtocols(List<ControlProtocolVersion> controlProtocols) {
+            this.controlProtocols = Optional.ofNullable(controlProtocols);
+            return this;
+        }
+
+        /**
          * Returns OVSDB bridge builder with a given disable in-band config.
          *
          * @return ovsdb bridge builder
diff --git a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbConstant.java b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbConstant.java
index 54c5fcb..f74186e 100644
--- a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbConstant.java
+++ b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbConstant.java
@@ -45,6 +45,7 @@
     // other configs
     public static final String DATAPATH_ID = "datapath-id";
     public static final String DISABLE_INBAND = "disable-in-band";
+    public static final String PROTOCOLS = "protocols";
 
     /** Port table. */
     public static final String PORT = "Port";
diff --git a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java
index b36032b..6056be2 100644
--- a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java
+++ b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java
@@ -29,6 +29,7 @@
 import org.onlab.packet.IpAddress;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.PortNumber;
+import org.onosproject.net.behaviour.ControlProtocolVersion;
 import org.onosproject.net.behaviour.ControllerInfo;
 import org.onosproject.net.behaviour.MirroringName;
 import org.onosproject.net.behaviour.MirroringStatistics;
@@ -485,6 +486,12 @@
             bridge.setDatapathType(datapathType);
         }
 
+        if (ovsdbBridge.controlProtocols().isPresent()) {
+            bridge.setProtocols(ovsdbBridge.controlProtocols().get().stream()
+                    .map(ControlProtocolVersion::toString)
+                    .collect(Collectors.toCollection(HashSet::new)));
+        }
+
         String bridgeUuid = getBridgeUuid(ovsdbBridge.name());
         if (bridgeUuid == null) {
             bridge.setName(ovsdbBridge.name());