model: Adding support for "fake" content object signatures
diff --git a/model/ndn-content-object.cc b/model/ndn-content-object.cc
index 544d48c..d9926ef 100644
--- a/model/ndn-content-object.cc
+++ b/model/ndn-content-object.cc
@@ -45,6 +45,7 @@
}
ContentObject::ContentObject ()
+ : m_signature (0)
{
}
@@ -98,11 +99,25 @@
return m_freshness;
}
+void
+ContentObject::SetSignature (uint32_t signature)
+{
+ m_signature = signature;
+}
+
+uint32_t
+ContentObject::GetSignature () const
+{
+ return m_signature;
+}
uint32_t
ContentObject::GetSerializedSize () const
{
uint32_t size = 2 + ((2 + 2) + (m_name->GetSerializedSize ()) + (2 + 2 + 4 + 2 + 2 + (2 + 0)));
+ if (m_signature != 0)
+ size += 4;
+
NS_LOG_INFO ("Serialize size = " << size);
return size;
}
@@ -113,8 +128,17 @@
start.WriteU8 (0x80); // version
start.WriteU8 (0x01); // packet type
- start.WriteU16 (2); // signature length
- start.WriteU16 (0); // empty signature
+ if (m_signature != 0)
+ {
+ start.WriteU16 (6); // signature length
+ start.WriteU16 (0xFF00); // "fake" simulator signature
+ start.WriteU32 (m_signature);
+ }
+ else
+ {
+ start.WriteU16 (2); // signature length
+ start.WriteU16 (0); // empty signature
+ }
// name
uint32_t offset = m_name->Serialize (start);
@@ -145,10 +169,20 @@
if (i.ReadU8 () != 0x01)
throw new ContentObjectException ();
- if (i.ReadU16 () != 2) // signature length
- throw new ContentObjectException ();
-
- if (i.ReadU16 () != 0) // signature type
+ uint32_t signatureLength = i.ReadU16 ();
+ if (signatureLength == 6)
+ {
+ if (i.ReadU16 () != 0xFF00) // signature type
+ throw new ContentObjectException ();
+ m_signature = i.ReadU32 ();
+ }
+ else if (signatureLength == 2)
+ {
+ if (i.ReadU16 () != 0) // signature type
+ throw new ContentObjectException ();
+ m_signature = 0;
+ }
+ else
throw new ContentObjectException ();
m_name = Create<Name> ();
diff --git a/model/ndn-content-object.h b/model/ndn-content-object.h
index 78b6e69..9803efe 100644
--- a/model/ndn-content-object.h
+++ b/model/ndn-content-object.h
@@ -137,6 +137,23 @@
Time
GetFreshness () const;
+ /**
+ * @brief Set "fake" signature on the content object
+ * @param signature uint32_t number, simulating content object signature
+ *
+ * Values for the signature totally depend on the application
+ */
+ void
+ SetSignature (uint32_t signature);
+
+ /**
+ * @brief Get "fake" signature of the content object
+ *
+ * Values for the signature totally depend on the application
+ */
+ uint32_t
+ GetSignature () const;
+
//////////////////////////////////////////////////////////////////
static TypeId GetTypeId (void); ///< @brief Get TypeId
@@ -150,6 +167,7 @@
Ptr<Name> m_name;
Time m_freshness;
Time m_timestamp;
+ uint32_t m_signature; // 0, means no signature, any other value application dependent (not a real signature)
};
typedef ContentObject ContentObjectHeader;
diff --git a/test/ndnSIM-serialization.cc b/test/ndnSIM-serialization.cc
index 2d42d93..1f1d2d6 100644
--- a/test/ndnSIM-serialization.cc
+++ b/test/ndnSIM-serialization.cc
@@ -82,6 +82,13 @@
source.SetTimestamp (Seconds (100));
NS_TEST_ASSERT_MSG_EQ (source.GetTimestamp (), Seconds (100), "set/get timestamp failed");
+ NS_TEST_ASSERT_MSG_EQ (source.GetSignature (), 0, "initialization of signature failed");
+ int size = source.GetSerializedSize ();
+ source.SetSignature (10);
+ NS_TEST_ASSERT_MSG_EQ (source.GetSignature (), 10, "set/get signature failed");
+
+ NS_TEST_ASSERT_MSG_EQ (source.GetSerializedSize (), size + 4, "Signature size should have increased by 4");
+
Packet packet (0);
//serialization
packet.AddHeader (source);
@@ -93,6 +100,7 @@
NS_TEST_ASSERT_MSG_EQ (source.GetName () , target.GetName () , "source/target name failed");
NS_TEST_ASSERT_MSG_EQ (source.GetFreshness (), target.GetFreshness (), "source/target freshness failed");
NS_TEST_ASSERT_MSG_EQ (source.GetTimestamp (), target.GetTimestamp (), "source/target timestamp failed");
+ NS_TEST_ASSERT_MSG_EQ (source.GetSignature (), target.GetSignature (), "source/target signature failed");
}
}