Initial routines for ContentObjectHeader. Another round of moving files around
diff --git a/model/content-object-header.cc b/model/content-object-header.cc
new file mode 100644
index 0000000..79b5ed0
--- /dev/null
+++ b/model/content-object-header.cc
@@ -0,0 +1,85 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Ilya Moiseenko <iliamo@cs.ucla.edu>
+ */
+
+
+#include "content-object-header.h"
+
+namespace ns3
+{
+namespace NDNabstraction
+{
+
+ ContentObjectHeader::ContentObjectHeader ()
+ {
+ }
+
+ void
+ ContentObjectHeader::SetName (const Ptr<Name::Components> &name)
+ {
+ m_name = name;
+ }
+
+ const Name::Components&
+ ContentObjectHeader::GetName () const
+ {
+ return *m_name;
+ }
+
+ uint32_t
+ ContentObjectHeader::GetSerializedSize (void) const
+ {
+ return 0;
+ }
+
+ void
+ ContentObjectHeader::Serialize (Buffer::Iterator start) const
+ {
+ return;
+ }
+
+ uint32_t
+ ContentObjectHeader::Deserialize (Buffer::Iterator start)
+ {
+ return 0;
+ }
+
+ TypeId
+ ContentObjectHeader::GetTypeId (void)
+ {
+ static TypeId tid = TypeId ("ns3::NDNabstraction::ContentObjectHeader")
+ .SetParent<Header> ()
+ .AddConstructor<ContentObjectHeader> ()
+ ;
+ return tid;
+ }
+
+ TypeId
+ ContentObjectHeader::GetInstanceTypeId (void) const
+ {
+ return GetTypeId ();
+ }
+
+ void
+ ContentObjectHeader::Print (std::ostream &os) const
+ {
+ os << "ContentObject: " << *m_name;
+ }
+}
+}
diff --git a/model/content-object-header.h b/model/content-object-header.h
new file mode 100644
index 0000000..454f8e2
--- /dev/null
+++ b/model/content-object-header.h
@@ -0,0 +1,108 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Ilya Moiseenko <iliamo@cs.ucla.edu>
+ * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef _CONTENT_OBJECT_HEADER_H_
+#define _CONTENT_OBJECT_HEADER_H_
+
+#include <ns3/integer.h>
+#include <ns3/header.h>
+
+#include <string>
+#include <vector>
+#include <list>
+
+#include "name-components.h"
+
+namespace ns3
+{
+namespace NDNabstraction
+{
+
+/**
+ * CCNx XML definition of ContentObject
+ *
+ * Only few important fields are actually implemented in the simulation
+ *
+ *
+ * NDN ContentObjectHeader and routines to serialize/deserialize
+ *
+ * Simplifications:
+ */
+
+class ContentObjectHeader : public Header
+{
+public:
+ /**
+ * Constructor
+ *
+ * Creates a null header
+ **/
+ ContentObjectHeader ();
+
+ /**
+ * \brief Set interest name
+ *
+ * Sets name of the interest. For example, SetName( Name::Components("prefix")("postfix") );
+ **/
+ void
+ SetName (const Ptr<Name::Components> &name);
+
+ const Name::Components&
+ GetName () const;
+
+ // void
+ // SetSignature ();
+
+ // ?
+ // GetSignature () const;
+
+ // void
+ // SetSignedInfo ();
+
+ // ?
+ // GetSignedInfo () const;
+
+ // void
+ // SetContent ();
+
+ // ?
+ // GetContent ();
+
+ //////////////////////////////////////////////////////////////////
+
+ static TypeId GetTypeId (void);
+ virtual TypeId GetInstanceTypeId (void) const;
+ virtual void Print (std::ostream &os) const;
+ virtual uint32_t GetSerializedSize (void) const;
+ virtual void Serialize (Buffer::Iterator start) const;
+ virtual uint32_t Deserialize (Buffer::Iterator start);
+
+private:
+ Ptr<Name::Components> m_name;
+ // m_signature;
+ // m_signedInfo;
+ // ? content
+};
+
+} // namespace NDNabstraction
+} // namespace ns3
+
+#endif // _CONTENT_OBJECT_HEADER_H_
diff --git a/model/interest-packet.cc b/model/interest-header.cc
similarity index 98%
rename from model/interest-packet.cc
rename to model/interest-header.cc
index eecb753..ef974a9 100644
--- a/model/interest-packet.cc
+++ b/model/interest-header.cc
@@ -23,7 +23,7 @@
///< #CCN_PR_SCOPE2 (0x80) immediate neighborhood
-#include "interest-packet.h"
+#include "interest-header.h"
namespace ns3
{
diff --git a/model/interest-header.h b/model/interest-header.h
new file mode 100644
index 0000000..4f2b948
--- /dev/null
+++ b/model/interest-header.h
@@ -0,0 +1,227 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Ilya Moiseenko <iliamo@cs.ucla.edu>
+ * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef _INTEREST_HEADER_H_
+#define _INTEREST_HEADER_H_
+
+#include <ns3/integer.h>
+#include <ns3/header.h>
+
+#include <string>
+#include <vector>
+#include <list>
+
+#include "name-components.h"
+
+namespace ns3
+{
+namespace NDNabstraction
+{
+
+/**
+ * CCNx XML definition of Interest
+ *
+ * Only few important fields are actually implemented in the simulation
+ *
+ * <xs:element name="Interest" type="InterestType"/>
+ * <xs:complexType name="InterestType">
+ * <xs:sequence>
+ * <xs:element name="Name" type="NameType"/>
+ * <xs:element name="MinSuffixComponents" type="xs:nonNegativeInteger"
+ * minOccurs="0" maxOccurs="1"/>
+ * <xs:element name="MaxSuffixComponents" type="xs:nonNegativeInteger"
+ * minOccurs="0" maxOccurs="1"/>
+ * <xs:choice minOccurs="0" maxOccurs="1">
+ * <xs:element name="PublisherPublicKeyDigest" type="DigestType"/>
+ * <xs:element name="PublisherCertificateDigest" type="DigestType"/>
+ * <xs:element name="PublisherIssuerKeyDigest" type="DigestType"/>
+ * <xs:element name="PublisherIssuerCertificateDigest" type="DigestType"/>
+ * </xs:choice>
+ * <xs:element name="Exclude" type="ExcludeType"
+ * minOccurs="0" maxOccurs="1"/>
+ * <xs:element name="ChildSelector" type="xs:nonNegativeInteger"
+ * minOccurs="0" maxOccurs="1"/>
+ * <xs:element name="AnswerOriginKind" type="xs:nonNegativeInteger"
+ * minOccurs="0" maxOccurs="1"/>
+ * <xs:element name="Scope" type="xs:nonNegativeInteger"
+ * minOccurs="0" maxOccurs="1"/>
+ * <xs:element name="InterestLifetime" type="FinegrainLifetimeType"
+ * minOccurs="0" maxOccurs="1"/>
+ * <xs:element name="Nonce" type="Base64BinaryType"
+ * minOccurs="0" maxOccurs="1"/>
+ * </xs:sequence>
+ * </xs:complexType>
+ *
+ * <xs:complexType name="NameType">
+ * <xs:sequence>
+ * <xs:element name="Component" type="Base64BinaryType"
+ * minOccurs="0" maxOccurs="unbounded"/>
+ * </xs:sequence>
+ * </xs:complexType>
+ *
+ * <xs:complexType name="ExcludeType">
+ * <xs:sequence>
+ * <xs:choice minOccurs="0" maxOccurs="1">
+ * <xs:element name="Any" type="EmptyType"/>
+ * <xs:element name="Bloom" type="Base64BinaryType"/> <!-- Bloom is deprecated --!>
+ * </xs:choice>
+ * <xs:sequence minOccurs="0" maxOccurs="unbounded">
+ * <xs:element name="Component" type="Base64BinaryType"/>
+ * <xs:choice minOccurs="0" maxOccurs="1">
+ * <xs:element name="Any" type="EmptyType"/>
+ * <xs:element name="Bloom" type="Base64BinaryType"/> <!-- Bloom is deprecated --!>
+ * </xs:choice>
+ * </xs:sequence>
+ * </xs:sequence>
+ * </xs:complexType>
+ *
+ * <!-- Binary representation of time, Unix time epoch, units 2**-12 sec (0.000244140625 sec) -->
+ * <!-- The length limit limit of 6 bytes is not actually to be enforced, but
+ * it will be a loooooooong time before anyone cares. -->
+ *
+ * <!-- Binary representation of relative time, relative to "now" -->
+ * <xs:complexType name="FinegrainLifetimeType">
+ * <xs:simpleContent>
+ * <xs:extension base="BinaryTime12">
+ * <xs:attribute name="ccnbencoding" type="xs:string" fixed="base64Binary"/>
+ * </xs:extension>
+ * </xs:simpleContent>
+ * </xs:complexType>
+ *
+ * <xs:simpleType name="BinaryTime12">
+ * <xs:restriction base="xs:base64Binary">
+ * <xs:length value="6" fixed="true"/>
+ * </xs:restriction>
+ * </xs:simpleType>
+ *
+ **/
+
+/**
+ NDN InterestHeader and routines to serialize/deserialize
+
+ Simplifications:
+ - Name: binary name components are not supported
+ - MinSuffixComponents and MasSuffixComponents: if value is negative (default), will not be serialized
+ - ChildSelector, AnswerOriginKind: 0 - false, 1 - true, -1 not set
+ - Publisher* elements are not supported
+ - Exclude: only simple name matching is supported (Bloom support has been deprecated in CCNx)
+ - InterestLifetime: not used if negative
+ - Nonce: 32 bit random integer. If value is 0, will not be serialized
+ */
+class InterestHeader : public Header
+{
+public:
+ /**
+ * Constructor
+ *
+ * Creates a null header
+ **/
+ InterestHeader ();
+
+ /**
+ * \brief Set interest name
+ *
+ * Sets name of the interest. For example, SetName( Name::Components("prefix")("postfix") );
+ **/
+ void
+ SetName (const Ptr<Name::Components> &name);
+
+ const Name::Components&
+ GetName () const;
+
+ void
+ SetMinSuffixComponents (int32_t value);
+
+ int32_t
+ GetMinSuffixComponents () const;
+
+ void
+ SetMaxSuffixComponents (int32_t value);
+
+ int32_t
+ GetMaxSuffixComponents () const;
+
+ /**
+ * \brief Set exclude filer
+ *
+ * For example, SetExclude (Name::Components("exclude1")("exclude2")("exclude3"))
+ **/
+ void
+ SetExclude (const Ptr<Name::Components> &exclude);
+
+ const Name::Components&
+ GetExclude () const;
+
+ void
+ EnableChildSelector ();
+
+ bool
+ IsEnabledChildSelector () const;
+
+ void
+ EnableAnswerOriginKind ();
+
+ bool
+ IsEnabledAnswerOriginKind () const;
+
+ void
+ SetScope (int8_t scope);
+
+ int8_t
+ GetScope () const;
+
+ void
+ SetInterestLifetime (intmax_t lifetime);
+
+ intmax_t
+ GetInterestLifetime () const;
+
+ void
+ SetNonce (uint32_t nonce);
+
+ uint32_t
+ GetNonce () const;
+
+ //////////////////////////////////////////////////////////////////
+
+ static TypeId GetTypeId (void);
+ virtual TypeId GetInstanceTypeId (void) const;
+ virtual void Print (std::ostream &os) const;
+ virtual uint32_t GetSerializedSize (void) const;
+ virtual void Serialize (Buffer::Iterator start) const;
+ virtual uint32_t Deserialize (Buffer::Iterator start);
+
+private:
+ Ptr<Name::Components> m_name;
+ int32_t m_minSuffixComponents; ///< minimum suffix components. not used if negative
+ int32_t m_maxSuffixComponents; ///< maximum suffix components. not used if negative
+ Ptr<Name::Components> m_exclude; ///< exclude filter
+ bool m_childSelector;
+ bool m_answerOriginKind;
+ int8_t m_scope; ///< -1 not set, 0 local scope, 1 this host, 2 immediate neighborhood
+ intmax_t m_interestLifetime; ///< InterestLifetime in 2^{-12} (0.000244140625 sec). not used if negative
+ uint32_t m_nonce; ///< Nonce. not used if zero
+};
+
+} // namespace NDNabstraction
+} // namespace ns3
+
+#endif // _INTEREST_HEADER_H_
diff --git a/model/interest-packet.h b/model/interest-packet.h
deleted file mode 100644
index d4b2f9f..0000000
--- a/model/interest-packet.h
+++ /dev/null
@@ -1,254 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2011 University of California, Los Angeles
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: Ilya Moiseenko <iliamo@cs.ucla.edu>
- */
-
-#ifndef _INTEREST_PACKET_H_
-#define _INTEREST_PACKET_H_
-
-//#define CCN_INTEREST_LIFETIME_SEC 4
-//#define CCN_INTEREST_LIFETIME_MICROSEC (CCN_INTEREST_LIFETIME_SEC * 1000000)
-
-#include <ns3/integer.h>
-#include <ns3/header.h>
-#include <ns3/packet.h>
-
-#include <string>
-#include <vector>
-#include <list>
-
-#include "name-components.h"
-
-namespace ns3
-{
-namespace NDNabstraction
-{
-
-/**
- * CCNx XML definition of Interest
- *
- * Only few important fields are actually implemented in the simulation
- *
- * <xs:element name="Interest" type="InterestType"/>
- * <xs:complexType name="InterestType">
- * <xs:sequence>
- * <xs:element name="Name" type="NameType"/>
- * <xs:element name="MinSuffixComponents" type="xs:nonNegativeInteger"
- * minOccurs="0" maxOccurs="1"/>
- * <xs:element name="MaxSuffixComponents" type="xs:nonNegativeInteger"
- * minOccurs="0" maxOccurs="1"/>
- * <xs:choice minOccurs="0" maxOccurs="1">
- * <xs:element name="PublisherPublicKeyDigest" type="DigestType"/>
- * <xs:element name="PublisherCertificateDigest" type="DigestType"/>
- * <xs:element name="PublisherIssuerKeyDigest" type="DigestType"/>
- * <xs:element name="PublisherIssuerCertificateDigest" type="DigestType"/>
- * </xs:choice>
- * <xs:element name="Exclude" type="ExcludeType"
- * minOccurs="0" maxOccurs="1"/>
- * <xs:element name="ChildSelector" type="xs:nonNegativeInteger"
- * minOccurs="0" maxOccurs="1"/>
- * <xs:element name="AnswerOriginKind" type="xs:nonNegativeInteger"
- * minOccurs="0" maxOccurs="1"/>
- * <xs:element name="Scope" type="xs:nonNegativeInteger"
- * minOccurs="0" maxOccurs="1"/>
- * <xs:element name="InterestLifetime" type="FinegrainLifetimeType"
- * minOccurs="0" maxOccurs="1"/>
- * <xs:element name="Nonce" type="Base64BinaryType"
- * minOccurs="0" maxOccurs="1"/>
- * </xs:sequence>
- * </xs:complexType>
- *
- * <xs:complexType name="NameType">
- * <xs:sequence>
- * <xs:element name="Component" type="Base64BinaryType"
- * minOccurs="0" maxOccurs="unbounded"/>
- * </xs:sequence>
- * </xs:complexType>
- *
- * <xs:complexType name="ExcludeType">
- * <xs:sequence>
- * <xs:choice minOccurs="0" maxOccurs="1">
- * <xs:element name="Any" type="EmptyType"/>
- * <xs:element name="Bloom" type="Base64BinaryType"/> <!-- Bloom is deprecated --!>
- * </xs:choice>
- * <xs:sequence minOccurs="0" maxOccurs="unbounded">
- * <xs:element name="Component" type="Base64BinaryType"/>
- * <xs:choice minOccurs="0" maxOccurs="1">
- * <xs:element name="Any" type="EmptyType"/>
- * <xs:element name="Bloom" type="Base64BinaryType"/> <!-- Bloom is deprecated --!>
- * </xs:choice>
- * </xs:sequence>
- * </xs:sequence>
- * </xs:complexType>
- *
- * <!-- Binary representation of time, Unix time epoch, units 2**-12 sec (0.000244140625 sec) -->
- * <!-- The length limit limit of 6 bytes is not actually to be enforced, but
- * it will be a loooooooong time before anyone cares. -->
- *
- * <!-- Binary representation of relative time, relative to "now" -->
- * <xs:complexType name="FinegrainLifetimeType">
- * <xs:simpleContent>
- * <xs:extension base="BinaryTime12">
- * <xs:attribute name="ccnbencoding" type="xs:string" fixed="base64Binary"/>
- * </xs:extension>
- * </xs:simpleContent>
- * </xs:complexType>
- *
- * <xs:simpleType name="BinaryTime12">
- * <xs:restriction base="xs:base64Binary">
- * <xs:length value="6" fixed="true"/>
- * </xs:restriction>
- * </xs:simpleType>
- *
- **/
-
- /**
- NDN InterestPacket and routes to serialize/deserialize
-
- Simplifications:
- - Name: binary name components are not supported
- - MinSuffixComponents and MasSuffixComponents: if value is negative (default), will not be serialized
- - ChildSelector, AnswerOriginKind: 0 - false, 1 - true, -1 not set
- - Publisher* elements are not supported
- - Exclude: only simple name matching is supported (Bloom support has been deprecated in CCNx)
- - InterestLifetime: not used if negative
- - Nonce: 32 bit random integer. If value is 0, will not be serialized
- */
- class InterestHeader : public Header
- {
- public:
- /**
- * Constructor
- *
- * Creates a null header
- **/
- InterestHeader ();
-
- /**
- * \brief Set interest name
- *
- * Sets name of the interest. For example, SetName( Name::Components("prefix")("postfix") );
- **/
- void
- SetName (const Ptr<Name::Components> &name);
-
- const Name::Components&
- GetName () const;
-
- void
- SetMinSuffixComponents (int32_t value);
-
- int32_t
- GetMinSuffixComponents () const;
-
- void
- SetMaxSuffixComponents (int32_t value);
-
- int32_t
- GetMaxSuffixComponents () const;
-
- /**
- * \brief Set exclude filer
- *
- * For example, SetExclude (Name::Components("exclude1")("exclude2")("exclude3"))
- **/
- void
- SetExclude (const Ptr<Name::Components> &exclude);
-
- const Name::Components&
- GetExclude () const;
-
- void
- EnableChildSelector ();
-
- bool
- IsEnabledChildSelector () const;
-
- void
- EnableAnswerOriginKind ();
-
- bool
- IsEnabledAnswerOriginKind () const;
-
- void
- SetScope (int8_t scope);
-
- int8_t
- GetScope () const;
-
- void
- SetInterestLifetime (intmax_t lifetime);
-
- intmax_t
- GetInterestLifetime () const;
-
- void
- SetNonce (uint32_t nonce);
-
- uint32_t
- GetNonce () const;
-
- //////////////////////////////////////////////////////////////////
-
- static TypeId GetTypeId (void);
- virtual TypeId GetInstanceTypeId (void) const;
- virtual void Print (std::ostream &os) const;
- virtual uint32_t GetSerializedSize (void) const;
- virtual void Serialize (Buffer::Iterator start) const;
- virtual uint32_t Deserialize (Buffer::Iterator start);
-
- private:
- Ptr<Name::Components> m_name;
- int32_t m_minSuffixComponents; ///< minimum suffix components. not used if negative
- int32_t m_maxSuffixComponents; ///< maximum suffix components. not used if negative
- Ptr<Name::Components> m_exclude; ///< exclude filter
- bool m_childSelector;
- bool m_answerOriginKind;
- int8_t m_scope; ///< -1 not set, 0 local scope, 1 this host, 2 immediate neighborhood
- intmax_t m_interestLifetime; ///< InterestLifetime in 2^{-12} (0.000244140625 sec). not used if negative
- uint32_t m_nonce; ///< Nonce. not used if zero
- };
-
-
- // Not sure that we need a separate NndPacket class. Everything useful will be inside (Interest|ContentObject)Header
-// class NdnPacket : public Packet
-// {
-// public:
-// NdnPacket( )
- // ;
- // InterestPacket (const unsigned char *name, uint32_t size);
-
-
- // uint32_t GetName (unsigned char *name);
-
- // void AddTimeout (uint32_t milliseconds);
- // uint32_t GetTimeout (void);
- // void RemoveTimeout (void);
-
- // void AddNonce (uint32_t nonce);
- // uint32_t GetNonce (void);
- // void RemoveNonce (void);
-
- // uint32_t maxNameLength;
-
-// };
-
-}
-}
-
-#endif // _NDN_PACKET_H_
diff --git a/model/stupid-interest-generator.cc b/model/stupid-interest-generator.cc
new file mode 100644
index 0000000..bd2cb6d
--- /dev/null
+++ b/model/stupid-interest-generator.cc
@@ -0,0 +1,181 @@
+//
+// ndn_stupidinterestgenerator.cpp
+// Abstraction
+//
+// Created by Ilya Moiseenko on 05.08.11.
+// Copyright 2011 UCLA. All rights reserved.
+//
+
+#include "stupid-interest-generator.h"
+
+#include "ns3/socket.h"
+#include "ns3/socket-factory.h"
+#include "ns3/simulator.h"
+
+#include "interest-header.h"
+#include "content-object-header.h"
+
+NS_LOG_COMPONENT_DEFINE ("StupidInterestGenerator");
+
+namespace ns3
+{
+//namespace NDNabstraction
+//{
+ using namespace NDNabstraction;
+
+ NS_OBJECT_ENSURE_REGISTERED (StupidInterestGenerator);
+
+ TypeId
+ StupidInterestGenerator::GetTypeId (void)
+ {
+ static TypeId tid = TypeId ("ns3::StupidInterestGenerator")
+ .SetParent<Application> ()
+ .AddConstructor<StupidInterestGenerator> ()
+ .AddAttribute ("Remote", "The address of the destination",
+ AddressValue (),
+ MakeAddressAccessor (&StupidInterestGenerator::m_peer),
+ MakeAddressChecker ())
+ .AddAttribute ("OffTime", "Time interval between packets",
+ TimeValue (Seconds (0.1)),
+ MakeTimeAccessor (&StupidInterestGenerator::m_offTime),
+ MakeTimeChecker ())
+ .AddAttribute ("Protocol", "The type of protocol to use.",
+ TypeIdValue (UdpSocketFactory::GetTypeId ()),
+ MakeTypeIdAccessor (&StupidInterestGenerator::m_tid),
+ MakeTypeIdChecker ())
+ ;
+ return tid;
+ }
+
+ StupidInterestGenerator::StupidInterestGenerator ()
+ {
+ NS_LOG_FUNCTION_NOARGS ();
+ m_socket = 0;
+ //m_connected = false;
+ //m_residualBits = 0;
+ //m_lastStartTime = Seconds (0);
+ //m_totBytes = 0;
+ }
+
+ StupidInterestGenerator::~StupidInterestGenerator()
+ {
+ NS_LOG_FUNCTION_NOARGS ();
+ }
+
+ void
+ StupidInterestGenerator::DoDispose (void)
+ {
+ NS_LOG_FUNCTION_NOARGS ();
+
+ m_socket = 0;
+ // chain up
+ Application::DoDispose ();
+ }
+
+ // Application Methods
+ void StupidInterestGenerator::StartApplication () // Called at time specified by Start
+ {
+ NS_LOG_FUNCTION_NOARGS ();
+
+ // Create the socket if not already
+ if (!m_socket)
+ {
+ m_socket = Socket::CreateSocket (GetNode (), m_tid);
+ m_socket->Bind ();
+ m_socket->Connect (m_peer);
+ m_socket->SetAllowBroadcast (true);
+ m_socket->ShutdownRecv ();
+ }
+ // Insure no pending event
+ CancelEvents ();
+ // If we are not yet connected, there is nothing to do here
+ // The ConnectionComplete upcall will start timers at that time
+ //if (!m_connected) return;
+ ScheduleStartEvent ();
+ }
+
+ void StupidInterestGenerator::StopApplication () // Called at time specified by Stop
+ {
+ NS_LOG_FUNCTION_NOARGS ();
+
+ CancelEvents ();
+ if(m_socket != 0)
+ {
+ m_socket->Close ();
+ }
+ else
+ {
+ NS_LOG_WARN ("OnOffApplication found null socket to close in StopApplication");
+ }
+ }
+
+ void StupidInterestGenerator::CancelEvents ()
+ {
+ NS_LOG_FUNCTION_NOARGS ();
+
+ Simulator::Cancel (m_sendEvent);
+ Simulator::Cancel (m_startStopEvent);
+ }
+
+ void StupidInterestGenerator::ScheduleStartEvent ()
+ { // Schedules the event to start sending data (switch to the "On" state)
+ NS_LOG_FUNCTION_NOARGS ();
+
+ Time offInterval = Seconds (m_offTime);
+ NS_LOG_LOGIC ("start at " << offInterval);
+ m_startStopEvent = Simulator::Schedule (offInterval, &StupidInterestGenerator::StartSending, this);
+ }
+
+ // Event handlers
+ void StupidInterestGenerator::StartSending ()
+ {
+ NS_LOG_FUNCTION_NOARGS ();
+ //m_lastStartTime = Simulator::Now ();
+ ScheduleNextTx (); // Schedule the send packet event
+ //ScheduleStopEvent ();
+ }
+
+ void StupidInterestGenerator::StopSending ()
+ {
+ NS_LOG_FUNCTION_NOARGS ();
+ CancelEvents ();
+
+ ScheduleStartEvent ();
+ }
+
+ // Private helpers
+ void StupidInterestGenerator::ScheduleNextTx ()
+ {
+ NS_LOG_FUNCTION_NOARGS ();
+
+
+ Time nextTime = Seconds(0.); //send now
+ m_sendEvent = Simulator::Schedule (nextTime,
+ &StupidInterestGenerator::SendPacket, this);
+ }
+
+
+ void StupidInterestGenerator::SendPacket ()
+ {
+ // NS_LOG_FUNCTION_NOARGS ();
+ // NS_LOG_LOGIC ("sending packet at " << Simulator::Now ());
+ // NS_ASSERT (m_sendEvent.IsExpired ());
+
+ // NameBuilder name;
+ // name("prefix1")("prefix2")("filename");
+ InterestHeader ();
+
+ ContentObjectHeader ();
+
+ // const ccn_charbuf *output = name.GetName();
+ // Ptr<InterestPacket> packet = Create<InterestPacket>(name,(uint32_t)output->length);
+ // packet->AddTimeout(4000);
+ // UniformVariable var;
+ // packet->AddNonce(var.GetInteger(1,10000));
+ // m_socket->Send(packet);
+
+ // ScheduleStartEvent();
+ }
+
+//}
+}
diff --git a/model/stupid-interest-generator.h b/model/stupid-interest-generator.h
new file mode 100644
index 0000000..8d927cd
--- /dev/null
+++ b/model/stupid-interest-generator.h
@@ -0,0 +1,79 @@
+//
+// ndn_stupidinterestgenerator.h
+// Abstraction
+//
+// Created by Ilya Moiseenko on 05.08.11.
+// Copyright 2011 UCLA. All rights reserved.
+//
+
+#include <ns3/application.h>
+#include <ns3/log.h>
+#include <ns3/address.h>
+#include <ns3/random-variable.h>
+#include <ns3/nstime.h>
+#include <ns3/event-id.h>
+#include <ns3/ptr.h>
+#include <ns3/udp-socket-factory.h>
+
+#include "ccn/ccn.h"
+
+namespace ns3
+{
+
+
+//namespace NDNabstraction
+//{
+ class Socket; //dynamic linking works in a somehow strange way
+
+ class StupidInterestGenerator: public Application
+ {
+ public:
+ static TypeId GetTypeId (void);
+
+ StupidInterestGenerator ();
+
+ virtual ~StupidInterestGenerator();
+
+
+ protected:
+ virtual void DoDispose (void);
+ private:
+ // inherited from Application base class.
+ virtual void StartApplication (void); // Called at time specified by Start
+ virtual void StopApplication (void); // Called at time specified by Stop
+
+ //Time m_onTime;
+ Time m_offTime;
+
+ Address m_peer; // Peer address
+ Ptr<Socket> m_socket;
+ EventId m_startStopEvent; // Event id for next start or stop event
+ EventId m_sendEvent; // Eventid of pending "send packet" event
+ TypeId m_tid;
+
+ //helpers
+ void CancelEvents ();
+
+ void Construct (Ptr<Node> n,
+ const Address &remote,
+ std::string tid,
+ const RandomVariable& ontime,
+ const RandomVariable& offtime,
+ uint32_t size);
+
+ // Event handlers
+ void StartSending ();
+ void StopSending ();
+ void SendPacket ();
+
+ private:
+ void ScheduleNextTx ();
+ void ScheduleStartEvent ();
+ void ScheduleStopEvent ();
+ void ConnectionSucceeded (Ptr<Socket>);
+ void ConnectionFailed (Ptr<Socket>);
+ void Ignore (Ptr<Socket>);
+
+ };
+//}
+}
diff --git a/model/stupid-interest-sink.cc b/model/stupid-interest-sink.cc
new file mode 100644
index 0000000..757d154
--- /dev/null
+++ b/model/stupid-interest-sink.cc
@@ -0,0 +1,187 @@
+//
+// stupid-interest-sink.cpp
+// Abstraction
+//
+// Created by Ilya Moiseenko on 10.08.11.
+// Copyright 2011 UCLA. All rights reserved.
+//
+
+#include "stupid-interest-sink.h"
+#include "ns3/address.h"
+#include "ns3/address-utils.h"
+#include "ns3/log.h"
+#include "ns3/inet-socket-address.h"
+#include "ns3/node.h"
+#include "ns3/socket.h"
+#include "ns3/udp-socket.h"
+#include "ns3/simulator.h"
+#include "ns3/socket-factory.h"
+#include "ns3/packet.h"
+#include "ns3/trace-source-accessor.h"
+#include "ns3/udp-socket-factory.h"
+
+using namespace std;
+
+namespace ns3 {
+
+ NS_LOG_COMPONENT_DEFINE ("StupidInterestSink");
+ NS_OBJECT_ENSURE_REGISTERED (StupidInterestSink);
+
+ TypeId
+ StupidInterestSink::GetTypeId (void)
+ {
+ static TypeId tid = TypeId ("ns3::StupidInterestSink")
+ .SetParent<Application> ()
+ .AddConstructor<StupidInterestSink> ()
+ .AddAttribute ("Local", "The Address on which to Bind the rx socket.",
+ AddressValue (),
+ MakeAddressAccessor (&StupidInterestSink::m_local),
+ MakeAddressChecker ())
+ .AddAttribute ("Protocol", "The type id of the protocol to use for the rx socket.",
+ TypeIdValue (UdpSocketFactory::GetTypeId ()),
+ MakeTypeIdAccessor (&StupidInterestSink::m_tid),
+ MakeTypeIdChecker ())
+ .AddTraceSource ("Rx", "A packet has been received",
+ MakeTraceSourceAccessor (&StupidInterestSink::m_rxTrace))
+ ;
+ return tid;
+ }
+
+ StupidInterestSink::StupidInterestSink ()
+ {
+ NS_LOG_FUNCTION (this);
+ m_socket = 0;
+ m_totalRx = 0;
+ }
+
+ StupidInterestSink::~StupidInterestSink()
+ {
+ NS_LOG_FUNCTION (this);
+ }
+
+ uint32_t StupidInterestSink::GetTotalRx () const
+ {
+ return m_totalRx;
+ }
+
+ Ptr<Socket>
+ StupidInterestSink::GetListeningSocket (void) const
+ {
+ NS_LOG_FUNCTION (this);
+ return m_socket;
+ }
+
+ std::list<Ptr<Socket> >
+ StupidInterestSink::GetAcceptedSockets (void) const
+ {
+ NS_LOG_FUNCTION (this);
+ return m_socketList;
+ }
+
+ void StupidInterestSink::DoDispose (void)
+ {
+ NS_LOG_FUNCTION (this);
+ m_socket = 0;
+ m_socketList.clear ();
+
+ // chain up
+ Application::DoDispose ();
+ }
+
+
+ // Application Methods
+ void StupidInterestSink::StartApplication () // Called at time specified by Start
+ {
+ NS_LOG_FUNCTION (this);
+ // Create the socket if not already
+ if (!m_socket)
+ {
+ m_socket = Socket::CreateSocket (GetNode (), m_tid);
+ m_socket->Bind (m_local);
+ m_socket->Listen ();
+ m_socket->ShutdownSend ();
+ if (addressUtils::IsMulticast (m_local))
+ {
+ Ptr<UdpSocket> udpSocket = DynamicCast<UdpSocket> (m_socket);
+ if (udpSocket)
+ {
+ // equivalent to setsockopt (MCAST_JOIN_GROUP)
+ udpSocket->MulticastJoinGroup (0, m_local);
+ }
+ else
+ {
+ NS_FATAL_ERROR ("Error: joining multicast on a non-UDP socket");
+ }
+ }
+ }
+
+ m_socket->SetRecvCallback (MakeCallback (&StupidInterestSink::HandleRead, this));
+ m_socket->SetAcceptCallback (
+ MakeNullCallback<bool, Ptr<Socket>, const Address &> (),
+ MakeCallback (&StupidInterestSink::HandleAccept, this));
+ m_socket->SetCloseCallbacks (
+ MakeCallback (&StupidInterestSink::HandlePeerClose, this),
+ MakeCallback (&StupidInterestSink::HandlePeerError, this));
+ }
+
+ void StupidInterestSink::StopApplication () // Called at time specified by Stop
+ {
+ NS_LOG_FUNCTION (this);
+ while(!m_socketList.empty ()) //these are accepted sockets, close them
+ {
+ Ptr<Socket> acceptedSocket = m_socketList.front ();
+ m_socketList.pop_front ();
+ acceptedSocket->Close ();
+ }
+ if (m_socket)
+ {
+ m_socket->Close ();
+ m_socket->SetRecvCallback (MakeNullCallback<void, Ptr<Socket> > ());
+ }
+ }
+
+ void StupidInterestSink::HandleRead (Ptr<Socket> socket)
+ {
+ NS_LOG_FUNCTION (this << socket);
+ Ptr<Packet> packet;
+ Address from;
+ while (packet = socket->RecvFrom (from))
+ {
+ if (packet->GetSize () == 0)
+ { //EOF
+ break;
+ }
+ if (InetSocketAddress::IsMatchingType (from))
+ {
+ m_totalRx += packet->GetSize ();
+ InetSocketAddress address = InetSocketAddress::ConvertFrom (from);
+ NS_LOG_INFO ("Received " << packet->GetSize () << " bytes from " <<
+ address.GetIpv4 () << " [" << address << "]"
+ << " total Rx " << m_totalRx);
+ //cast address to void , to suppress 'address' set but not used
+ //compiler warning in optimized builds
+ (void) address;
+ }
+ m_rxTrace (packet, from);
+ }
+ }
+
+ void StupidInterestSink::HandlePeerClose (Ptr<Socket> socket)
+ {
+ NS_LOG_INFO ("PktSink, peerClose");
+ }
+
+ void StupidInterestSink::HandlePeerError (Ptr<Socket> socket)
+ {
+ NS_LOG_INFO ("PktSink, peerError");
+ }
+
+
+ void StupidInterestSink::HandleAccept (Ptr<Socket> s, const Address& from)
+ {
+ NS_LOG_FUNCTION (this << s << from);
+ s->SetRecvCallback (MakeCallback (&StupidInterestSink::HandleRead, this));
+ m_socketList.push_back (s);
+ }
+
+} // Namespace ns3
diff --git a/model/stupid-interest-sink.h b/model/stupid-interest-sink.h
new file mode 100644
index 0000000..66cedd9
--- /dev/null
+++ b/model/stupid-interest-sink.h
@@ -0,0 +1,67 @@
+//
+// stupid-interest-sink.h
+// Abstraction
+//
+// Created by Ilya Moiseenko on 10.08.11.
+// Copyright 2011 UCLA. All rights reserved.
+//
+
+#include "ns3/application.h"
+#include "ns3/event-id.h"
+#include "ns3/ptr.h"
+#include "ns3/traced-callback.h"
+#include "ns3/address.h"
+
+namespace ns3
+{
+
+ class Address;
+ class Socket;
+ class Packet;
+
+ class StupidInterestSink : public Application
+ {
+ public:
+ static TypeId GetTypeId (void);
+ StupidInterestSink ();
+
+ virtual ~StupidInterestSink ();
+
+ /**
+ * \return the total bytes received in this sink app
+ */
+ uint32_t GetTotalRx () const;
+
+ /**
+ * \return pointer to listening socket
+ */
+ Ptr<Socket> GetListeningSocket (void) const;
+
+ /**
+ * \return list of pointers to accepted sockets
+ */
+ std::list<Ptr<Socket> > GetAcceptedSockets (void) const;
+
+ protected:
+ virtual void DoDispose (void);
+ private:
+ // inherited from Application base class.
+ virtual void StartApplication (void); // Called at time specified by Start
+ virtual void StopApplication (void); // Called at time specified by Stop
+
+ void HandleRead (Ptr<Socket>);
+ void HandleAccept (Ptr<Socket>, const Address& from);
+ void HandlePeerClose (Ptr<Socket>);
+ void HandlePeerError (Ptr<Socket>);
+
+ // In the case of TCP, each socket accept returns a new socket, so the
+ // listening socket is stored seperately from the accepted sockets
+ Ptr<Socket> m_socket; // Listening socket
+ std::list<Ptr<Socket> > m_socketList; //the accepted sockets
+
+ Address m_local; // Local address to bind to
+ uint32_t m_totalRx; // Total bytes received
+ TypeId m_tid; // Protocol TypeId
+ TracedCallback<Ptr<const Packet>, const Address &> m_rxTrace;
+ };
+}
\ No newline at end of file