Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 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" |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 29 | #include "ns3/udp-socket-factory.h" |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 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 | |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 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 | |
| 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 | */ |
| 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 | |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 74 | bool |
| 75 | UdpFace::ReceiveFromUdp (Ptr<const Packet> p) |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 76 | { |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 77 | return Face::Receive (p); |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | bool |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 81 | UdpFace::Send (Ptr<Packet> packet) |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 82 | { |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 83 | if (!Face::Send (packet)) |
| 84 | { |
| 85 | return false; |
| 86 | } |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 87 | |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 88 | NS_LOG_FUNCTION (this << packet); |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 89 | m_socket->Send (packet); |
| 90 | |
| 91 | return true; |
| 92 | } |
| 93 | |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 94 | Ipv4Address |
| 95 | UdpFace::GetAddress () const |
| 96 | { |
| 97 | return m_address; |
| 98 | } |
| 99 | |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 100 | std::ostream& |
| 101 | UdpFace::Print (std::ostream& os) const |
| 102 | { |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 103 | os << "dev=udp(" << GetId () << "," << GetAddress () << ")"; |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 104 | return os; |
| 105 | } |
| 106 | |
| 107 | } // namespace ndn |
| 108 | } // namespace ns3 |