Slight update of packet format: adding overall packet length to the
common header
diff --git a/model/ndn-content-object.cc b/model/ndn-content-object.cc
index d9926ef..052cd4a 100644
--- a/model/ndn-content-object.cc
+++ b/model/ndn-content-object.cc
@@ -114,7 +114,8 @@
uint32_t
ContentObject::GetSerializedSize () const
{
- uint32_t size = 2 + ((2 + 2) + (m_name->GetSerializedSize ()) + (2 + 2 + 4 + 2 + 2 + (2 + 0)));
+ uint32_t size = 1 + 1 + 2 +
+ ((2 + 2) + (m_name->GetSerializedSize ()) + (2 + 2 + 4 + 2 + 2 + (2 + 0)));
if (m_signature != 0)
size += 4;
@@ -127,7 +128,8 @@
{
start.WriteU8 (0x80); // version
start.WriteU8 (0x01); // packet type
-
+ start.WriteU16 (GetSerializedSize () - 4); // length
+
if (m_signature != 0)
{
start.WriteU16 (6); // signature length
@@ -169,6 +171,8 @@
if (i.ReadU8 () != 0x01)
throw new ContentObjectException ();
+ i.ReadU16 (); // length
+
uint32_t signatureLength = i.ReadU16 ();
if (signatureLength == 6)
{
diff --git a/model/ndn-interest.cc b/model/ndn-interest.cc
index fc5b24f..f0a4f29 100644
--- a/model/ndn-interest.cc
+++ b/model/ndn-interest.cc
@@ -146,7 +146,12 @@
uint32_t
Interest::GetSerializedSize (void) const
{
- size_t size = 2 + (1 + 4 + 2 + 1 + (m_name->GetSerializedSize ()) + (2 + 0) + (2 + 0));
+ size_t size =
+ 1/*version*/ + 1 /*type*/ + 2/*length*/ +
+ (4/*nonce*/ + 1/*scope*/ + 1/*nack type*/ + 2/*timestamp*/ +
+ (m_name->GetSerializedSize ()) +
+ (2 + 0)/* selectors */ +
+ (2 + 0)/* options */);
NS_LOG_INFO ("Serialize size = " << size);
return size;
@@ -158,6 +163,8 @@
start.WriteU8 (0x80); // version
start.WriteU8 (0x00); // packet type
+ start.WriteU16 (GetSerializedSize () - 4);
+
start.WriteU32 (m_nonce);
start.WriteU8 (m_scope);
start.WriteU8 (m_nackType);
@@ -186,6 +193,8 @@
if (i.ReadU8 () != 0x00)
throw new InterestException ();
+ i.ReadU16 (); // length, don't need it right now
+
m_nonce = i.ReadU32 ();
m_scope = i.ReadU8 ();
m_nackType = i.ReadU8 ();