You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by ve...@apache.org on 2012/06/01 12:45:21 UTC

svn commit: r1345043 - in /incubator/etch/trunk/binding-cpp/runtime: include/transport/ src/main/ src/main/transport/ src/test/ src/test/transport/

Author: veithm
Date: Fri Jun  1 10:45:20 2012
New Revision: 1345043

URL: http://svn.apache.org/viewvc?rev=1345043&view=rev
Log:
ETCH-180 Packetizer Implementation

Change-Id: Ia166b490a37a732a687c201a100c015a915b1116

Added:
    incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchPacketizer.h
    incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchPacketizer.cpp
    incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchPacketizerTest.cpp
Modified:
    incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTransportPacket.h
    incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt
    incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt

Added: incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchPacketizer.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchPacketizer.h?rev=1345043&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchPacketizer.h (added)
+++ incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchPacketizer.h Fri Jun  1 10:45:20 2012
@@ -0,0 +1,157 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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.
+ */
+
+#ifndef __ETCHPACKETIZER_H__
+#define __ETCHPACKETIZER_H__
+#include "capu/util/SmartPointer.h"
+#include "transport/EtchSessionData.h"
+#include "transport/EtchTransportPacket.h"
+#include "transport/EtchSessionPacket.h"
+#include "transport/EtchFlexBuffer.h"
+#include "transport/EtchTransportData.h"
+#include "util/EtchURL.h"
+#include "util/EtchResources.h"
+#include "common/EtchString.h"
+
+/**
+ * Packetizes a stream data source. Reads a packet header:
+ * a 32-bit flag and a 32-bit length, both big-endian, verifies
+ * the flag, and then, using the length from the header,
+ * reads the packet data and passes it to the packet handler.
+ * As a packet source, accepts a packet and prepends a packet
+ * header to it before delivering it to a data source.
+ */
+
+class EtchPacketizer : public virtual EtchTransportPacket, public virtual EtchSessionData {
+public:
+
+  /**
+   * The default maximum packet size that will be accepted, 16376 bytes.
+   */
+  const static capu::int32_t DEFAULT_MAX_PKT_SIZE;
+
+  const static EtchString MAX_PKT_SIZE_TERM;
+
+  const static capu::int32_t SIG;
+
+  const static capu::uint32_t HEADER_SIZE;
+
+  /**
+   * Constructs the Packetizer with null packet handler and uri specified
+   * or defaulted maximum packet size.
+   * @param transport used to deliver data to the peer.
+   * @param uri
+   * @param resources
+   */
+  EtchPacketizer(EtchTransportData* transport, EtchString& uri);
+
+  /**
+   * Constructs the Packetizer with null packet handler and uri specified
+   * or defaulted maximum packet size.
+   * @param transport used to deliver data to the peer.
+   * @param uri
+   * @param resources
+   */
+  EtchPacketizer(EtchTransportData* transport, EtchURL* uri);
+
+  /**
+   * Destructor
+   */
+  ~EtchPacketizer();
+
+  /**
+   * @return the transport.
+   */
+  EtchTransportData* getTransport();
+
+  /**
+   * Returns header size
+   */
+  capu::int32_t getHeaderSize();
+
+  /**
+   * @see EtchSessionData
+   */
+  status_t sessionData(capu::SmartPointer<EtchWho> sender, capu::SmartPointer<EtchFlexBuffer> buf);
+
+  /**
+   * @see EtchTransport
+   */
+  status_t transportQuery(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> result);
+
+  /**
+   * @see EtchTransport
+   */
+  EtchSessionPacket* getSession();
+
+  /**
+   * @see EtchTransport
+   */
+  void setSession(EtchSessionPacket* session);
+
+  /**
+   * @see EtchTransport
+   */
+  status_t transportControl(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value);
+
+  /**
+   * @see EtchTransport
+   */
+  status_t transportNotify(capu::SmartPointer<EtchObject> event);
+
+  /**
+   * @see EtchTransportPacket
+   */
+  status_t transportPacket(capu::SmartPointer<EtchWho> recipient, capu::SmartPointer<EtchFlexBuffer> buf);
+
+  /**
+   * @see EtchSession
+   */
+  status_t sessionQuery(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> result);
+
+  /**
+   * @see EtchSession
+   */
+  status_t sessionControl(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value);
+
+  /**
+   * @see EtchSession
+   */
+  status_t sessionNotify(capu::SmartPointer<EtchObject> event);
+
+private:
+
+  EtchTransportData* mTransport;
+
+  EtchSessionPacket* mSession;
+
+  capu::uint32_t mMaxPktSize;
+
+  capu::uint32_t mBodyLen;
+
+  capu::bool_t mWantHeader;
+
+  capu::SmartPointer<EtchFlexBuffer> mSavedBuf;
+
+  status_t processHeader(EtchFlexBuffer* buf, capu::bool_t reset, capu::uint32_t &pktSize);
+
+};
+
+
+#endif /* ETCHPACKETIZER_H */
+

Modified: incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTransportPacket.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTransportPacket.h?rev=1345043&r1=1345042&r2=1345043&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTransportPacket.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTransportPacket.h Fri Jun  1 10:45:20 2012
@@ -32,7 +32,7 @@ public:
    * Returns the size of the packet header for the transport.
    * @return the size of the packet header for the transport.
    */
-  virtual capu::int32_t headerSize() = 0;
+  virtual capu::int32_t getHeaderSize() = 0;
 
   /**
    * Delivers the packet to the transport after adding the packet header.

Modified: incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt?rev=1345043&r1=1345042&r2=1345043&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt Fri Jun  1 10:45:20 2012
@@ -60,6 +60,7 @@ SET(MAIN_INCLUDES
     ${PROJECT_SOURCE_DIR}/include/transport/EtchTcpConnection.h
     ${PROJECT_SOURCE_DIR}/include/transport/EtchTcpListener.h
     ${PROJECT_SOURCE_DIR}/include/transport/EtchTcpOption.h
+    ${PROJECT_SOURCE_DIR}/include/transport/EtchPacketizer.h
     ${PROJECT_SOURCE_DIR}/include/util/EtchUtil.h
     )
 
@@ -84,6 +85,7 @@ SET(MAIN_SOURCES
     transport/EtchTcpConnection.cpp
     transport/EtchTcpListener.cpp
     transport/EtchTcpOption.cpp
+    transport/EtchPacketizer.cpp
     util/EtchUtil.cpp
     )
 

Added: incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchPacketizer.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchPacketizer.cpp?rev=1345043&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchPacketizer.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchPacketizer.cpp Fri Jun  1 10:45:20 2012
@@ -0,0 +1,237 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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.
+ */
+
+#include "transport/EtchPacketizer.h"
+
+const capu::uint32_t EtchPacketizer::HEADER_SIZE = 8;
+
+const capu::int32_t EtchPacketizer::SIG = 0xdeadbeef;
+
+const capu::int32_t EtchPacketizer::DEFAULT_MAX_PKT_SIZE = 16384 - EtchPacketizer::HEADER_SIZE;
+
+const EtchString EtchPacketizer::MAX_PKT_SIZE_TERM("Packetizer.maxPktSize");
+
+EtchPacketizer::EtchPacketizer(EtchTransportData* transport, EtchString& uri)
+: mTransport(transport), mBodyLen(0), mWantHeader(true) {
+
+  if (mTransport != NULL)
+    mTransport->setSession(this);
+  
+  EtchURL url(uri.c_str());
+  EtchString value;
+  url.getTerms().get((EtchString&) EtchPacketizer::MAX_PKT_SIZE_TERM, &value);
+  if (value.length() == 0)
+    mMaxPktSize = EtchPacketizer::DEFAULT_MAX_PKT_SIZE;
+  else {
+    mMaxPktSize = atoi(value.c_str());
+
+    if (mMaxPktSize <= 0)
+      mMaxPktSize = DEFAULT_MAX_PKT_SIZE;
+  }
+  mSavedBuf = new EtchFlexBuffer();
+}
+
+EtchPacketizer::EtchPacketizer(EtchTransportData* transport, EtchURL* uri)
+: mTransport(transport), mBodyLen(0), mWantHeader(true) {
+  EtchString value("");
+  if (mTransport != NULL)
+    transport->setSession(this);
+
+  uri->getTerms().get((EtchString&) EtchPacketizer::MAX_PKT_SIZE_TERM, &value);
+  if (value.length() == 0)
+    mMaxPktSize = EtchPacketizer::DEFAULT_MAX_PKT_SIZE;
+  else {
+    mMaxPktSize = atoi(value.c_str());
+
+    if (mMaxPktSize <= 0)
+      mMaxPktSize = DEFAULT_MAX_PKT_SIZE;
+  }
+  mSavedBuf = new EtchFlexBuffer();
+}
+
+EtchPacketizer::~EtchPacketizer() {
+  mTransport->setSession(NULL);
+}
+
+capu::int32_t EtchPacketizer::getHeaderSize() {
+  return EtchPacketizer::HEADER_SIZE;
+}
+
+status_t EtchPacketizer::transportControl(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value) {
+  return mTransport->transportControl(control, value);
+}
+
+status_t EtchPacketizer::transportNotify(capu::SmartPointer<EtchObject> event) {
+  return mTransport->transportNotify(event);
+}
+
+status_t EtchPacketizer::transportQuery(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> result) {
+  return mTransport->transportQuery(query, result);
+}
+
+EtchSessionPacket* EtchPacketizer::getSession() {
+  return mSession;
+}
+
+void EtchPacketizer::setSession(EtchSessionPacket* session) {
+  mSession = session;
+}
+
+status_t EtchPacketizer::sessionControl(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value) {
+  return mSession->sessionControl(control, value);
+}
+
+status_t EtchPacketizer::sessionNotify(capu::SmartPointer<EtchObject> event) {
+  return mSession->sessionNotify(event);
+}
+
+status_t EtchPacketizer::sessionQuery(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> result) {
+  return mSession->sessionQuery(query, result);
+}
+
+status_t EtchPacketizer::transportPacket(capu::SmartPointer<EtchWho> recipient, capu::SmartPointer<EtchFlexBuffer> buf) {
+  // assert index is at the start of the header.
+  capu::uint32_t dataSize = buf->getAvailableBytes();
+  if (dataSize < EtchPacketizer::HEADER_SIZE)
+    return ETCH_ERANGE;
+  capu::uint32_t pktSize = dataSize - EtchPacketizer::HEADER_SIZE;
+  if (pktSize > mMaxPktSize)
+    return ETCH_ERANGE;
+
+  capu::uint32_t index = buf->getIndex();
+  buf->put((capu::int8_t*) & EtchPacketizer::SIG, sizeof (EtchPacketizer::SIG));
+  buf->put((capu::int8_t*) & pktSize, sizeof (pktSize));
+  buf->setIndex(index);
+  return mTransport->transportData(recipient, buf);
+}
+
+status_t EtchPacketizer::sessionData(capu::SmartPointer<EtchWho> sender, capu::SmartPointer<EtchFlexBuffer> buf) {
+
+  // there are two options here. one is that we have no buffered data
+  // and the entire packet is contained within the buf. in that case
+  // we could optimize the daylights out of the process and directly
+  // drop the packet on the handler.
+
+  status_t result;
+  while (buf->getAvailableBytes() > 0) {
+    if (mWantHeader) {
+      // do we have enough to make a header?
+
+      if (mSavedBuf->getLength() + buf->getAvailableBytes() >= HEADER_SIZE) {
+        capu::uint32_t pktSize;
+
+        if (mSavedBuf->getLength() == 0) {
+          // savedBuf is empty, entire header in buf.
+
+          result = processHeader(buf.get(), false, pktSize);
+          if (result != ETCH_OK)
+            return result;
+        } else // header split across savedBuf and buf
+        {
+          // move just enough data from buf to savedBuf to have a header.
+
+          capu::uint32_t needFromBuf = HEADER_SIZE - mSavedBuf->getLength();
+          mSavedBuf->put(*buf, needFromBuf);
+          mSavedBuf->setIndex(0);
+
+          result = processHeader(mSavedBuf.get(), true, pktSize);
+          if (result != ETCH_OK)
+            return result;
+        }
+
+        if (pktSize == 0)
+          continue;
+
+        mBodyLen = pktSize;
+        mWantHeader = false;
+      } else // want header, but there's not enough to make it.
+      {
+        // save buf in savedBuf.
+
+        mSavedBuf->setIndex(mSavedBuf->getLength());
+        mSavedBuf->put(*buf);
+      }
+    } else if (mSavedBuf->getLength() + buf->getAvailableBytes() >= mBodyLen) {
+      // want body, and there's enough to make it.
+
+      // three possible cases: the body is entirely in savedBuf,
+      // the body is split, or the body is entirely in buf. assert
+      // that the body cannot entirely be in savedBuf, or else
+      // we'd have processed it last time.
+
+      if (mSavedBuf->getLength() == 0) {
+        // savedBuf is empty, entire body in buf.
+
+        capu::uint32_t length = buf->getLength();
+        capu::uint32_t index = buf->getIndex();
+        buf->setLength(index + mBodyLen);
+
+        mSession->sessionPacket(sender, buf);
+
+        buf->setLength(length);
+        buf->setIndex(index + mBodyLen);
+
+        mWantHeader = true;
+      } else // body split across savedBuf and buf
+      {
+        // move just enough data from buf to savedBuf to have a body.
+
+        capu::uint32_t needFromBuf = mBodyLen - mSavedBuf->getLength();
+        mSavedBuf->put(*buf, needFromBuf);
+        mSavedBuf->setIndex(0);
+
+        mSession->sessionPacket(sender, mSavedBuf);
+
+        mSavedBuf->reset();
+        mWantHeader = true;
+      }
+    } else // want body, but there's not enough to make it.
+    {
+      // save buf in savedBuf.
+      mSavedBuf->put(*buf);
+    }
+  }
+  // buf is now empty, and there's nothing else to do.
+  if (buf->getAvailableBytes() != 0)
+    return ETCH_ERROR;
+  return ETCH_OK;
+}
+
+status_t EtchPacketizer::processHeader(EtchFlexBuffer* buf, capu::bool_t reset, capu::uint32_t &pktSize) {
+  capu::int32_t sig = 0;
+  buf->getInteger(sig);
+
+  if (sig != SIG) {
+    return ETCH_ERROR;
+  }
+
+  buf->getInteger((capu::int32_t&)pktSize);
+
+  if (reset)
+    buf->reset();
+
+  if (pktSize > mMaxPktSize) {
+    return ETCH_ERROR;
+  }
+  
+  return ETCH_OK;
+}
+
+EtchTransportData* EtchPacketizer::getTransport() {
+  return mTransport;
+}
\ No newline at end of file

Modified: incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt?rev=1345043&r1=1345042&r2=1345043&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt Fri Jun  1 10:45:20 2012
@@ -47,6 +47,7 @@ add_executable (etch-cpp-test
     transport/EtchFlexBufferTest.cpp
     transport/EtchTcpConnectionTest.cpp
     transport/EtchTcpListenerTest.cpp
+    transport/EtchPacketizerTest.cpp
     util/EtchUtilTest.cpp
     ${GTEST}/src/gtest-all.cc
     ${GMOCK}/src/gmock-all.cc

Added: incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchPacketizerTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchPacketizerTest.cpp?rev=1345043&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchPacketizerTest.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchPacketizerTest.cpp Fri Jun  1 10:45:20 2012
@@ -0,0 +1,135 @@
+/* $Id$
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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.
+ */
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+#include "transport/EtchPacketizer.h"
+#include "common/EtchString.h"
+#include "common/EtchError.h"
+#include "util/EtchURL.h"
+#include "transport/EtchTcpConnection.h"
+#include "capu/util/SmartPointer.h"
+#include "common/EtchSocket.h"
+#include "transport/EtchSessionListener.h"
+#include "transport/EtchTcpListener.h"
+#include "transport/EtchSessionPacket.h"
+#include "transport/EtchFlexBuffer.h"
+
+class MockListener3 : public virtual EtchSessionListener<EtchSocket> {
+public:
+
+  //This method is called
+
+  status_t sessionAccepted(EtchSocket* connection) {
+    delete connection;
+    return ETCH_OK;
+  }
+
+  MOCK_METHOD2(sessionQuery, status_t(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> result));
+
+  MOCK_METHOD2(sessionControl, status_t(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value));
+
+  MOCK_METHOD1(sessionNotify, status_t(capu::SmartPointer<EtchObject> event));
+};
+
+class MockMessagizer : public EtchSessionPacket {
+public:
+
+  MOCK_METHOD2(sessionPacket, status_t(capu::SmartPointer<EtchWho> receipent, capu::SmartPointer<EtchFlexBuffer> buf));
+
+  MOCK_METHOD2(sessionQuery, status_t(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> result));
+
+  MOCK_METHOD2(sessionControl, status_t(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value));
+
+  MOCK_METHOD1(sessionNotify, status_t(capu::SmartPointer<EtchObject> event));
+};
+
+TEST(EtchPacketizer, constructorTest) {
+  EtchURL u("tcp://127.0.0.1:4001");
+  EtchTransportData* conn = new EtchTcpConnection(NULL, &u);
+  EtchSessionData* packetizer = new EtchPacketizer(conn, &u);
+  delete packetizer;
+  delete conn;
+}
+
+TEST(EtchPacketizer, TransportControlTest) {
+  EtchURL u("tcp://127.0.0.1:4001");
+  EtchTransportData* conn = new EtchTcpConnection(NULL, &u);
+  EtchPacketizer* res = new EtchPacketizer(conn, &u);
+
+  EtchSessionListener<EtchSocket>* mSessionListener = new MockListener3();
+  EtchTcpListener* listener = new EtchTcpListener(&u);
+  //Start the mock listener
+  listener->setSession(mSessionListener);
+  listener->transportControl(new EtchString(EtchTcpListener::START_AND_WAIT_UP), new EtchInt32(1000));
+  res->transportControl(new EtchString(EtchPacketizer::START_AND_WAIT_UP), new EtchInt32(1000));
+
+  res->transportControl(new EtchString(EtchPacketizer::STOP_AND_WAIT_DOWN), new EtchInt32(1000));
+  listener->transportControl(new EtchString(EtchTcpListener::STOP_AND_WAIT_DOWN),new EtchInt32(1000));
+
+  conn->setSession(NULL);
+  res->setSession(NULL);
+  listener->setSession(NULL);
+
+  delete mSessionListener;
+  delete res;
+  delete conn;
+  delete listener;
+}
+
+TEST(EtchPacketizer, TransportPacketTest) {
+  EtchURL u("tcp://127.0.0.1:4001");
+  EtchTransportData* conn = new EtchTcpConnection(NULL, &u);
+  EtchPacketizer* packetizer = new EtchPacketizer(conn, &u);
+  capu::SmartPointer<EtchFlexBuffer> buffer = new EtchFlexBuffer();
+
+  //A packet is try to transmit data through not started transport
+  buffer->put((capu::int8_t *)"_header_", packetizer->getHeaderSize());
+  buffer->put((capu::int8_t *)"test", 4);
+  buffer->setIndex(0);
+
+  EXPECT_TRUE(packetizer->transportPacket(NULL, buffer) == ETCH_ERROR);
+
+  delete packetizer;
+  delete conn;
+}
+
+TEST(EtchPacketizer, SessionDataTest) {
+  EtchURL u("tcp://127.0.0.1:4001");
+  EtchTransportData* conn = new EtchTcpConnection(NULL, &u);
+  EtchPacketizer* packetizer = new EtchPacketizer(conn, &u);
+  capu::SmartPointer<EtchFlexBuffer> buffer = new EtchFlexBuffer();
+
+  //A packet is created
+  capu::int32_t pktsize = 4;
+  buffer->put((capu::int8_t *) & packetizer->SIG, sizeof (capu::int32_t));
+  buffer->put((capu::int8_t *) & pktsize, sizeof (capu::int32_t));
+  buffer->put((capu::int8_t *)"test", pktsize);
+  buffer->setIndex(0);
+  EXPECT_TRUE(buffer->getLength() == 12);
+
+  EtchSessionPacket* mSessionPacker = new MockMessagizer();
+  packetizer->setSession(mSessionPacker);
+
+  MockMessagizer * mock = (MockMessagizer*) mSessionPacker;
+  EXPECT_CALL(*mock, sessionPacket(capu::SmartPointer<EtchWho > (NULL), buffer));
+  EXPECT_TRUE(packetizer->sessionData(NULL, buffer) == ETCH_OK);
+
+  packetizer->setSession(NULL);
+  delete mSessionPacker;
+  delete packetizer;
+  delete conn;
+}
\ No newline at end of file