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 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 22 | #include "ndn-udp-face.hpp" |
| 23 | #include "ns3/ndn-l3-protocol.hpp" |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 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 | |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 31 | using namespace std; |
| 32 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 33 | NS_LOG_COMPONENT_DEFINE("ndn.UdpFace"); |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 34 | |
| 35 | namespace ns3 { |
| 36 | namespace ndn { |
| 37 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 38 | NS_OBJECT_ENSURE_REGISTERED(UdpFace); |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 39 | |
| 40 | TypeId |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 41 | UdpFace::GetTypeId() |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 42 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 43 | static TypeId tid = TypeId("ns3::ndn::UdpFace").SetParent<Face>().SetGroupName("Ndn"); |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 44 | return tid; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * By default, Ndn face are created in the "down" state. Before |
| 49 | * becoming useable, the user must invoke SetUp on the face |
| 50 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 51 | UdpFace::UdpFace(Ptr<Node> node, Ptr<Socket> socket, Ipv4Address address) |
| 52 | : Face(node) |
| 53 | , m_socket(socket) |
| 54 | , m_address(address) |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 55 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 56 | SetMetric(1); // default metric |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 59 | UdpFace::~UdpFace() |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 60 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 61 | NS_LOG_FUNCTION_NOARGS(); |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | UdpFace& UdpFace::operator= (const UdpFace &) |
| 65 | { |
| 66 | return *this; |
| 67 | } |
| 68 | |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 69 | bool |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 70 | UdpFace::ReceiveFromUdp(Ptr<const Packet> p) |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 71 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 72 | return Face::Receive(p); |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | bool |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 76 | UdpFace::Send(Ptr<Packet> packet) |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 77 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 78 | if (!Face::Send(packet)) { |
| 79 | return false; |
| 80 | } |
| 81 | |
| 82 | NS_LOG_FUNCTION(this << packet); |
| 83 | m_socket->Send(packet); |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 84 | |
| 85 | return true; |
| 86 | } |
| 87 | |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 88 | Ipv4Address |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 89 | UdpFace::GetAddress() const |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 90 | { |
| 91 | return m_address; |
| 92 | } |
| 93 | |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 94 | std::ostream& |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 95 | UdpFace::Print(std::ostream& os) const |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 96 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 97 | os << "dev=udp(" << GetId() << "," << GetAddress() << ")"; |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 98 | return os; |
| 99 | } |
| 100 | |
| 101 | } // namespace ndn |
| 102 | } // namespace ns3 |