[Emu][ONOS-2593, ONOS-2594] BGP SBI controller and session handler

Change-Id: Ia95717ff173b2e3e1198bdd0fafef7cb0aa8f734
diff --git a/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPMessage.java b/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPMessage.java
new file mode 100644
index 0000000..a5d8154
--- /dev/null
+++ b/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPMessage.java
@@ -0,0 +1,92 @@
+/*
+ * 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.bgpio.protocol;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.types.BGPHeader;
+
+/**
+ * Abstraction of an entity providing BGP Messages.
+ */
+public interface BGPMessage extends Writeable {
+    /**
+     * Returns BGP Header of BGP Message.
+     *
+     * @return BGP Header of BGP Message
+     */
+    BGPHeader getHeader();
+
+    /**
+     * Returns version of BGP Message.
+     *
+     * @return version of BGP Message
+     */
+    BGPVersion getVersion();
+
+    /**
+     * Returns BGP Type of BGP Message.
+     *
+     * @return BGP Type of BGP Message
+     */
+    BGPType getType();
+
+    @Override
+    void writeTo(ChannelBuffer cb) throws BGPParseException;
+
+    /**
+     * Builder interface with get and set functions to build BGP Message.
+     */
+    interface Builder {
+        /**
+         * Builds BGP Message.
+         *
+         * @return BGP Message
+         * @throws BGPParseException while building bgp message
+         */
+        BGPMessage build() throws BGPParseException;
+
+        /**
+         * Returns BGP Version of BGP Message.
+         *
+         * @return BGP Version of BGP Message
+         */
+        BGPVersion getVersion();
+
+        /**
+         * Returns BGP Type of BGP Message.
+         *
+         * @return BGP Type of BGP Message
+         */
+        BGPType getType();
+
+        /**
+         * Returns BGP Header of BGP Message.
+         *
+         * @return BGP Header of BGP Message
+         */
+        BGPHeader getHeader();
+
+        /**
+         * Sets BgpHeader and return its builder.
+         *
+         * @param bgpMsgHeader BGP Message Header
+         * @return builder by setting BGP message header
+         */
+        Builder setHeader(BGPHeader bgpMsgHeader);
+    }
+}
\ No newline at end of file
diff --git a/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPMessageReader.java b/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPMessageReader.java
new file mode 100755
index 0000000..18b8f58
--- /dev/null
+++ b/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPMessageReader.java
@@ -0,0 +1,36 @@
+/*
+ * 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.bgpio.protocol;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.types.BGPHeader;
+
+/**
+ * Abstraction of an entity providing BGP Message Reader.
+ */
+public interface BGPMessageReader<T> {
+
+    /**
+     * Reads the Objects in the BGP Message and Returns BGP Message.
+     *
+     * @param cb Channel Buffer
+     * @param bgpHeader BGP message header
+     * @return BGP Message
+     * @throws BGPParseException while parsing BGP message.
+     */
+    T readFrom(ChannelBuffer cb, BGPHeader bgpHeader) throws BGPParseException;
+}
\ No newline at end of file
diff --git a/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPType.java b/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPType.java
new file mode 100755
index 0000000..d334915
--- /dev/null
+++ b/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPType.java
@@ -0,0 +1,45 @@
+/*
+ * 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.bgpio.protocol;
+
+/**
+ * Enum to Provide the Different types of BGP messages.
+ */
+public enum BGPType {
+
+    NONE(0), OPEN(1), UPDATE(2), NOTIFICATION(3), KEEP_ALIVE(4);
+
+    int value;
+
+    /**
+     * Assign value with the value val as the types of BGP message.
+     *
+     * @param val type of BGP message
+     */
+    BGPType(int val) {
+        value = val;
+    }
+
+    /**
+     * Returns value as type of BGP message.
+     *
+     * @return value type of BGP message
+     */
+    public byte getType() {
+        return (byte) value;
+    }
+}
\ No newline at end of file
diff --git a/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPVersion.java b/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPVersion.java
new file mode 100755
index 0000000..97bc7dc
--- /dev/null
+++ b/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPVersion.java
@@ -0,0 +1,45 @@
+/*
+ * 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.bgpio.protocol;
+
+/**
+ * Enum to provide BGP Message Version.
+ */
+public enum BGPVersion {
+
+    BGP_4(4);
+
+    public final int packetVersion;
+
+    /**
+     * Assign BGP PacketVersion with specified packetVersion.
+     *
+     * @param packetVersion version of BGP
+     */
+    BGPVersion(final int packetVersion) {
+        this.packetVersion = packetVersion;
+    }
+
+    /**
+     * Returns Packet version of BGP Message.
+     *
+     * @return packetVersion
+     */
+    public int getPacketVersion() {
+        return packetVersion;
+    }
+}
\ No newline at end of file
diff --git a/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/Writeable.java b/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/Writeable.java
new file mode 100755
index 0000000..72df7f3
--- /dev/null
+++ b/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/Writeable.java
@@ -0,0 +1,35 @@
+/*
+ * 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.bgpio.protocol;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BGPParseException;
+
+/**
+ * Abstraction of an entity providing functionality to write byte streams of
+ * Messages to channel buffer.
+ */
+public interface Writeable {
+
+    /**
+     * Writes byte streams of messages to channel buffer.
+     *
+     * @param cb channelBuffer
+     * @throws BGPParseException when error occurs while writing BGP message to channel buffer
+     */
+    void writeTo(ChannelBuffer cb) throws BGPParseException;
+}
\ No newline at end of file