model: Major API changes
Interest and ContentObject are no longer derived from Header class.
Instead, they are encapsulating payload and, optionally, wire-formatted
Packet object.
Refs #1005 (http://redmine.named-data.net/)
diff --git a/model/ndn-interest.cc b/model/ndn-interest.cc
index f0a4f29..195c4f9 100644
--- a/model/ndn-interest.cc
+++ b/model/ndn-interest.cc
@@ -31,24 +31,14 @@
NS_OBJECT_ENSURE_REGISTERED (Interest);
-TypeId
-Interest::GetTypeId (void)
-{
- static TypeId tid = TypeId ("ns3::ndn::Interest")
- .SetGroupName ("Ndn")
- .SetParent<Header> ()
- .AddConstructor<Interest> ()
- ;
- return tid;
-}
-
-
Interest::Interest ()
: m_name ()
, m_scope (0xFF)
, m_interestLifetime (Seconds (0))
, m_nonce (0)
, m_nackType (NORMAL_INTEREST)
+ , m_payload (0)
+ , m_wire (0)
{
}
@@ -58,28 +48,23 @@
, m_interestLifetime (interest.m_interestLifetime)
, m_nonce (interest.m_nonce)
, m_nackType (interest.m_nackType)
+ , m_payload (interest.GetPayload ()->Copy ())
+ , m_wire (0)
{
}
-Ptr<Interest>
-Interest::GetInterest (Ptr<Packet> packet)
-{
- Ptr<Interest> interest = Create<Interest> ();
- packet->RemoveHeader (*interest);
-
- return interest;
-}
-
void
Interest::SetName (Ptr<Name> name)
{
m_name = name;
+ m_wire = 0;
}
void
Interest::SetName (const Name &name)
{
m_name = Create<Name> (name);
+ m_wire = 0;
}
const Name&
@@ -99,6 +84,7 @@
Interest::SetScope (int8_t scope)
{
m_scope = scope;
+ m_wire = 0;
}
int8_t
@@ -111,6 +97,7 @@
Interest::SetInterestLifetime (Time lifetime)
{
m_interestLifetime = lifetime;
+ m_wire = 0;
}
Time
@@ -123,6 +110,7 @@
Interest::SetNonce (uint32_t nonce)
{
m_nonce = nonce;
+ m_wire = 0;
}
uint32_t
@@ -135,6 +123,7 @@
Interest::SetNack (uint8_t nackType)
{
m_nackType = nackType;
+ m_wire = 0;
}
uint8_t
@@ -143,82 +132,18 @@
return m_nackType;
}
-uint32_t
-Interest::GetSerializedSize (void) const
-{
- 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;
-}
-
void
-Interest::Serialize (Buffer::Iterator start) const
+Interest::SetPayload (Ptr<Packet> payload)
{
- 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);
-
- NS_ASSERT_MSG (0 <= m_interestLifetime.ToInteger (Time::S) && m_interestLifetime.ToInteger (Time::S) < 65535,
- "Incorrect InterestLifetime (should not be smaller than 0 and larger than 65535");
-
- // rounding timestamp value to seconds
- start.WriteU16 (static_cast<uint16_t> (m_interestLifetime.ToInteger (Time::S)));
-
- uint32_t offset = m_name->Serialize (start);
- start.Next (offset);
-
- start.WriteU16 (0); // no selectors
- start.WriteU16 (0); // no options
+ m_payload = payload;
}
-uint32_t
-Interest::Deserialize (Buffer::Iterator start)
+Ptr<const Payload>
+Interest::GetPayload () const
{
- Buffer::Iterator i = start;
-
- if (i.ReadU8 () != 0x80)
- throw new InterestException ();
-
- 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 ();
-
- m_interestLifetime = Seconds (i.ReadU16 ());
-
- m_name = Create<Name> ();
- uint32_t offset = m_name->Deserialize (i);
- i.Next (offset);
-
- i.ReadU16 ();
- i.ReadU16 ();
-
- NS_ASSERT (GetSerializedSize () == (i.GetDistanceFrom (start)));
-
- return i.GetDistanceFrom (start);
+ return m_payload;
}
-TypeId
-Interest::GetInstanceTypeId (void) const
-{
- return GetTypeId ();
-}
-
void
Interest::Print (std::ostream &os) const
{