BGP Controller test

Change-Id: I4bdafeec877d5fbfa79306717cf3033936e0fe59
diff --git a/bgp/ctl/src/test/java/org/onosproject/bgp/BgpPeerChannelHandlerTest.java b/bgp/ctl/src/test/java/org/onosproject/bgp/BgpPeerChannelHandlerTest.java
new file mode 100755
index 0000000..6f1828f
--- /dev/null
+++ b/bgp/ctl/src/test/java/org/onosproject/bgp/BgpPeerChannelHandlerTest.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2014-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;
+
+import java.util.LinkedList;
+import java.util.concurrent.TimeUnit;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBuffers;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.channel.ChannelStateEvent;
+import org.jboss.netty.channel.SimpleChannelHandler;
+import org.onosproject.bgpio.protocol.ver4.BGPKeepaliveMsgVer4;
+import org.onosproject.bgpio.protocol.ver4.BGPOpenMsgVer4;
+import org.onosproject.bgpio.types.BGPHeader;
+import org.onosproject.bgpio.types.BGPValueType;
+
+public class BgpPeerChannelHandlerTest extends SimpleChannelHandler {
+    public static final int OPEN_MSG_MINIMUM_LENGTH = 29;
+    public static final byte[] MARKER = new byte[] {(byte) 0xff, (byte) 0xff,
+        (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+        (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+        (byte) 0xff, (byte) 0xff};
+    public static final BGPHeader DEFAULT_OPEN_HEADER = new BGPHeader(MARKER,
+            (short) OPEN_MSG_MINIMUM_LENGTH, (byte) 0X01);
+    LinkedList<BGPValueType> capabilityTlv = new LinkedList<>();
+    public byte version;
+    public short asNumber;
+    public short holdTime;
+    public int bgpId;
+    public boolean isLargeAsCapabilitySet;
+
+    final BGPOpenMsgVer4 openMessage = new BGPOpenMsgVer4();
+    ChannelHandlerContext savedCtx;
+
+    /**
+     * Constructor to initialize all variables of BGP Open message.
+     *
+     * @param version BGP version in open message
+     * @param asNumber AS number in open message
+     * @param holdTime hold time in open message
+     * @param bgpId BGP identifier in open message
+     * @param capabilityTlv capabilities in open message
+     */
+    public BgpPeerChannelHandlerTest(byte version,
+            short asNumber,
+            short holdTime,
+            int bgpId,
+            boolean isLargeAsCapabilitySet,
+            LinkedList<BGPValueType> capabilityTlv) {
+        this.version = version;
+        this.asNumber = asNumber;
+        this.holdTime = holdTime;
+        this.bgpId = bgpId;
+        this.isLargeAsCapabilitySet = isLargeAsCapabilitySet;
+        this.capabilityTlv = capabilityTlv;
+    }
+
+    /**
+     * closes the channel.
+     */
+    void closeChannel() {
+        savedCtx.getChannel().close();
+    }
+
+    @Override
+    public void channelConnected(ChannelHandlerContext ctx,
+                                 ChannelStateEvent channelEvent) throws InterruptedException {
+        this.savedCtx = ctx;
+
+        BGPOpenMsgVer4 openMsg = new BGPOpenMsgVer4(DEFAULT_OPEN_HEADER,
+                this.version,
+                this.asNumber,
+                this.holdTime,
+                this.bgpId,
+                this.capabilityTlv);
+        ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
+        openMsg.writeTo(buffer);
+        ctx.getChannel().write(buffer);
+
+        TimeUnit.MILLISECONDS.sleep(100);
+
+        BGPKeepaliveMsgVer4 keepaliveMsg = new BGPKeepaliveMsgVer4();
+        ChannelBuffer buffer1 = ChannelBuffers.dynamicBuffer();
+        keepaliveMsg.writeTo(buffer1);
+        ctx.getChannel().write(buffer1);
+    }
+
+    @Override
+    public void channelDisconnected(ChannelHandlerContext ctx,
+                                    ChannelStateEvent channelEvent) {
+        //Do Nothing
+    }
+}