blob: 03d8ee4edc9f74f8026f061cf54a5ce5fba0c586 [file] [log] [blame]
Alexander Afanasyev016a5d82013-07-15 10:41:29 -07001/* -*- 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
Alexander Afanasyev0c395372014-12-20 15:54:02 -080022#include "ndn-udp-face.hpp"
23#include "ns3/ndn-l3-protocol.hpp"
Alexander Afanasyev016a5d82013-07-15 10:41:29 -070024
25#include "ns3/log.h"
26#include "ns3/packet.h"
27#include "ns3/node.h"
28#include "ns3/pointer.h"
Alexander Afanasyevd573af22013-07-27 12:57:08 -070029#include "ns3/udp-socket-factory.h"
Alexander Afanasyev016a5d82013-07-15 10:41:29 -070030
Alexander Afanasyev0c395372014-12-20 15:54:02 -080031#include "ns3/ndn-name.hpp"
Alexander Afanasyev016a5d82013-07-15 10:41:29 -070032
33using namespace std;
34
35NS_LOG_COMPONENT_DEFINE ("ndn.UdpFace");
36
37namespace ns3 {
38namespace ndn {
39
Alexander Afanasyev016a5d82013-07-15 10:41:29 -070040NS_OBJECT_ENSURE_REGISTERED (UdpFace);
41
42TypeId
43UdpFace::GetTypeId ()
44{
45 static TypeId tid = TypeId ("ns3::ndn::UdpFace")
46 .SetParent<Face> ()
47 .SetGroupName ("Ndn")
48 ;
49 return tid;
50}
51
52/**
53 * By default, Ndn face are created in the "down" state. Before
54 * becoming useable, the user must invoke SetUp on the face
55 */
56UdpFace::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
64UdpFace::~UdpFace ()
65{
66 NS_LOG_FUNCTION_NOARGS ();
67}
68
69UdpFace& UdpFace::operator= (const UdpFace &)
70{
71 return *this;
72}
73
Alexander Afanasyevd573af22013-07-27 12:57:08 -070074bool
75UdpFace::ReceiveFromUdp (Ptr<const Packet> p)
Alexander Afanasyev016a5d82013-07-15 10:41:29 -070076{
Alexander Afanasyevd573af22013-07-27 12:57:08 -070077 return Face::Receive (p);
Alexander Afanasyev016a5d82013-07-15 10:41:29 -070078}
79
80bool
Alexander Afanasyevd573af22013-07-27 12:57:08 -070081UdpFace::Send (Ptr<Packet> packet)
Alexander Afanasyev016a5d82013-07-15 10:41:29 -070082{
Alexander Afanasyevd573af22013-07-27 12:57:08 -070083 if (!Face::Send (packet))
84 {
85 return false;
86 }
Alexander Afanasyev016a5d82013-07-15 10:41:29 -070087
Alexander Afanasyevd573af22013-07-27 12:57:08 -070088 NS_LOG_FUNCTION (this << packet);
Alexander Afanasyev016a5d82013-07-15 10:41:29 -070089 m_socket->Send (packet);
90
91 return true;
92}
93
Alexander Afanasyev016a5d82013-07-15 10:41:29 -070094Ipv4Address
95UdpFace::GetAddress () const
96{
97 return m_address;
98}
99
Alexander Afanasyev016a5d82013-07-15 10:41:29 -0700100std::ostream&
101UdpFace::Print (std::ostream& os) const
102{
Alexander Afanasyevd573af22013-07-27 12:57:08 -0700103 os << "dev=udp(" << GetId () << "," << GetAddress () << ")";
Alexander Afanasyev016a5d82013-07-15 10:41:29 -0700104 return os;
105}
106
107} // namespace ndn
108} // namespace ns3