NS-3 based Named Data Networking (NDN) simulator
ndnSIM: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
ndn-udp-face.cc
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2 /*
3  * Copyright (c) 2013 University of California, Los Angeles
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19  *
20  */
21 
22 #include "ndn-udp-face.h"
23 #include "ns3/ndn-l3-protocol.h"
24 
25 #include "ns3/log.h"
26 #include "ns3/packet.h"
27 #include "ns3/node.h"
28 #include "ns3/pointer.h"
29 #include "ns3/udp-socket-factory.h"
30 
31 #include "ns3/ndn-name.h"
32 
33 using namespace std;
34 
35 NS_LOG_COMPONENT_DEFINE ("ndn.UdpFace");
36 
37 namespace ns3 {
38 namespace ndn {
39 
40 NS_OBJECT_ENSURE_REGISTERED (UdpFace);
41 
42 TypeId
43 UdpFace::GetTypeId ()
44 {
45  static TypeId tid = TypeId ("ns3::ndn::UdpFace")
46  .SetParent<Face> ()
47  .SetGroupName ("Ndn")
48  ;
49  return tid;
50 }
51 
56 UdpFace::UdpFace (Ptr<Node> node, Ptr<Socket> socket, Ipv4Address address)
57  : Face (node)
58  , m_socket (socket)
59  , m_address (address)
60 {
61  SetMetric (1); // default metric
62 }
63 
64 UdpFace::~UdpFace ()
65 {
66  NS_LOG_FUNCTION_NOARGS ();
67 }
68 
69 UdpFace& UdpFace::operator= (const UdpFace &)
70 {
71  return *this;
72 }
73 
74 bool
75 UdpFace::ReceiveFromUdp (Ptr<const Packet> p)
76 {
77  return Face::Receive (p);
78 }
79 
80 bool
81 UdpFace::Send (Ptr<Packet> packet)
82 {
83  if (!Face::Send (packet))
84  {
85  return false;
86  }
87 
88  NS_LOG_FUNCTION (this << packet);
89  m_socket->Send (packet);
90 
91  return true;
92 }
93 
94 Ipv4Address
95 UdpFace::GetAddress () const
96 {
97  return m_address;
98 }
99 
100 std::ostream&
101 UdpFace::Print (std::ostream& os) const
102 {
103  os << "dev=udp(" << GetId () << "," << GetAddress () << ")";
104  return os;
105 }
106 
107 } // namespace ndn
108 } // namespace ns3
uint32_t GetId() const
Get face Id.
Definition: ndn-face.h:314
Virtual class defining NDN face.
Definition: ndn-face.h:58
virtual void SetMetric(uint16_t metric)
Assign routing/forwarding metric with face.
Definition: ndn-face.cc:230
virtual bool Receive(Ptr< const Packet > p)
Send packet up to the stack (towards forwarding strategy)
Definition: ndn-face.cc:163
virtual bool Send(Ptr< Packet > packet)
Send packet down to the stack (towards app or network)
Definition: ndn-face.cc:149
virtual std::ostream & Print(std::ostream &os) const
Print information about the face into the stream.
virtual bool Send(Ptr< Packet > p)
Send packet down to the stack (towards app or network)
Definition: ndn-udp-face.cc:81