[ONOS-2594] Channel handle to manage session handling with BGP peers

Change-Id: I6c58c674aa17e2a86b063e248af589d524ec5fe3
diff --git a/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPController.java b/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPController.java
index 49432aa..faa1de3 100755
--- a/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPController.java
+++ b/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPController.java
@@ -16,6 +16,9 @@
 
 package org.onosproject.bgp.controller;
 
+import java.util.Map;
+
+import org.onosproject.bgpio.exceptions.BGPParseException;
 import org.onosproject.bgpio.protocol.BGPMessage;
 
 /**
@@ -52,8 +55,9 @@
      *
      * @param bgpId id of the peer the message arrived on
      * @param msg the message to process.
+     * @throws BGPParseException on data processing error
      */
-    void processBGPPacket(BGPId bgpId, BGPMessage msg);
+    void processBGPPacket(BGPId bgpId, BGPMessage msg) throws BGPParseException;
 
     /**
      * Close all connected BGP peers.
@@ -73,5 +77,19 @@
      *
      * @return the integer number
      */
-    int getBGPConnNumber();
+    int connectedPeerCount();
+
+    /**
+     * Return BGP peer manager.
+     *
+     * @return BGPPeerManager peer manager instance
+     */
+    BgpPeerManager peerManager();
+
+    /**
+     * Return BGP connected peers.
+     *
+     * @return connectedPeers connected peers
+     */
+    Map<BGPId, BGPPeer> connectedPeers();
 }
\ No newline at end of file
diff --git a/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeer.java b/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeer.java
index 1b022c7..aafaf06 100755
--- a/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeer.java
+++ b/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeer.java
@@ -16,30 +16,16 @@
 package org.onosproject.bgp.controller;
 import java.util.List;
 import org.jboss.netty.channel.Channel;
+import org.onosproject.bgpio.protocol.BGPFactory;
 import org.onosproject.bgpio.protocol.BGPMessage;
-import org.onosproject.bgpio.protocol.BGPVersion;
 
 /**
- * Represents the peer side of an bgp peer.
+ * Represents the peer side of an BGP peer.
  *
  */
 public interface BGPPeer {
 
     /**
-     * Sets the BGP version for this bgp peer.
-     *
-     * @param bgpVersion the version to set.
-     */
-    void setBgpPeerVersion(BGPVersion bgpVersion);
-
-    /**
-     * Gets the BGP version for this bgp peer.
-     *
-     * @return bgp identifier.
-     */
-    int getBgpPeerIdentifier();
-
-    /**
      * Sets the associated Netty channel for this bgp peer.
      *
      * @param channel the Netty channel
@@ -54,27 +40,6 @@
     Channel getChannel();
 
     /**
-     * Sets the AS Number for this bgp peer.
-     *
-     * @param peerASNum the autonomous system number value to set.
-     */
-    void setBgpPeerASNum(short peerASNum);
-
-    /**
-     * Sets the hold time for this bgp peer.
-     *
-     * @param peerHoldTime the hold timer value to set.
-     */
-    void setBgpPeerHoldTime(short peerHoldTime);
-
-    /**
-     * Sets the peer identifier value.
-     *
-     * @param peerIdentifier the bgp peer identifier value.
-     */
-    void setBgpPeerIdentifier(int peerIdentifier);
-
-    /**
      * Sets whether the bgp peer is connected.
      *
      * @param connected whether the bgp peer is connected
@@ -82,15 +47,6 @@
     void setConnected(boolean connected);
 
     /**
-     * Initialises the behaviour.
-     *
-     * @param bgpId id of bgp peer
-     * @param bgpVersion BGP version
-     * @param pktStats packet statistics
-     */
-    void init(BGPId bgpId, BGPVersion bgpVersion, BGPPacketStats pktStats);
-
-    /**
      * Checks whether the handshake is complete.
      *
      * @return true is finished, false if not.
@@ -112,18 +68,11 @@
     void sendMessage(List<BGPMessage> msgs);
 
     /**
-     * Gets a string version of the ID for this bgp peer.
+     * Provides the factory for BGP version.
      *
-     * @return string version of the ID
+     * @return BGP version specific factory.
      */
-    String getStringId();
-
-    /**
-     * Gets the ipAddress of the peer.
-     *
-     * @return the peer bgpId in IPAddress format
-     */
-    BGPId getBGPId();
+    BGPFactory factory();
 
     /**
      * Checks if the bgp peer is still connected.
@@ -146,16 +95,9 @@
     String channelId();
 
     /**
-     * Gets the negotiated hold time.
+     * Return the BGP session info.
      *
-     * @return the negotiated hold time
+     * @return sessionInfo bgp session info
      */
-    int getNegotiatedHoldTime();
-
-    /**
-     * Sets negotiated hold time for the peer.
-     *
-     * @param negotiatedHoldTime negotiated hold time
-     */
-    void setNegotiatedHoldTime(short negotiatedHoldTime);
+    BgpSessionInfo sessionInfo();
 }
diff --git a/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpSessionInfo.java b/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpSessionInfo.java
new file mode 100755
index 0000000..17753ff
--- /dev/null
+++ b/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpSessionInfo.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * 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.bgp.controller;
+
+import org.onosproject.bgpio.protocol.BGPVersion;
+
+/**
+ * Abstraction of an BGP session info. Maintian session parameters obtained during session creation.
+ */
+public interface BgpSessionInfo {
+    /**
+     * Gets the bgp session type iBGP/eBGP.
+     *
+     * @return isiBGPSession, true if session is of type internal, otherwise false.
+     */
+    boolean isIbgpSession();
+
+    /**
+     * Gets the negotiated hold time for the session.
+     *
+     * @return negotiated hold time.
+     */
+    short negotiatedholdTime();
+
+    /**
+     * Gets the BGP ID of BGP peer.
+     *
+     * @return bgp ID.
+     */
+    BGPId remoteBgpId();
+
+    /**
+     * Gets the BGP version of peer.
+     *
+     * @return bgp version.
+     */
+    BGPVersion remoteBgpVersion();
+
+    /**
+     * Gets the BGP remote bgp AS number.
+     *
+     * @return remoteBgpASNum peer AS number.
+     */
+    long remoteBgpASNum();
+
+    /**
+     * Gets the BGP peer hold time.
+     *
+     * @return bgp hold time.
+     */
+    short remoteBgpHoldTime();
+
+    /**
+     * Gets the BGP version for this bgp peer.
+     *
+     * @return bgp identifier.
+     */
+    int remoteBgpIdentifier();
+}