Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2005,2006,2007 INRIA |
| 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 "ccnx-net-device-face.h" |
| 23 | |
| 24 | #include "ns3/ccnx-l3-protocol.h" |
| 25 | #include "ns3/net-device.h" |
| 26 | #include "ns3/log.h" |
| 27 | #include "ns3/packet.h" |
| 28 | #include "ns3/node.h" |
| 29 | #include "ns3/pointer.h" |
| 30 | |
| 31 | NS_LOG_COMPONENT_DEFINE ("CcnxNetDeviceFace"); |
| 32 | |
| 33 | namespace ns3 { |
| 34 | |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 35 | /** |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 36 | * By default, Ccnx face are created in the "down" state. Before |
| 37 | * becoming useable, the user must invoke SetUp on the face |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 38 | */ |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame^] | 39 | CcnxNetDeviceFace::CcnxNetDeviceFace (Ptr<Node> node, const Ptr<NetDevice> &netDevice) |
| 40 | : CcnxFace (node) |
| 41 | , m_netDevice (netDevice) |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 42 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame^] | 43 | NS_LOG_FUNCTION (this << netDevice); |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 44 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame^] | 45 | NS_ASSERT_MSG (m_netDevice != 0, "CcnxNetDeviceFace needs to be assigned a valid NetDevice"); |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | CcnxNetDeviceFace::~CcnxNetDeviceFace () |
| 49 | { |
| 50 | NS_LOG_FUNCTION_NOARGS (); |
| 51 | } |
| 52 | |
| 53 | CcnxNetDeviceFace::CcnxNetDeviceFace (const CcnxNetDeviceFace &) |
| 54 | { |
| 55 | } |
| 56 | |
| 57 | CcnxNetDeviceFace& CcnxNetDeviceFace::operator= (const CcnxNetDeviceFace &) |
| 58 | { |
| 59 | return *this; |
| 60 | } |
| 61 | |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 62 | Ptr<NetDevice> |
| 63 | CcnxNetDeviceFace::GetNetDevice () const |
| 64 | { |
| 65 | return m_netDevice; |
| 66 | } |
| 67 | |
| 68 | void |
| 69 | CcnxNetDeviceFace::RegisterProtocolHandler (ProtocolHandler handler) |
| 70 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame^] | 71 | NS_LOG_FUNCTION (this << handler); |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 72 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame^] | 73 | CcnxFace::RegisterProtocolHandler (handler); |
| 74 | |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 75 | m_node->RegisterProtocolHandler (MakeCallback (&CcnxNetDeviceFace::ReceiveFromNetDevice, this), |
| 76 | CcnxL3Protocol::ETHERNET_FRAME_TYPE, m_netDevice, true/*promiscuous mode*/); |
| 77 | } |
| 78 | |
| 79 | void |
| 80 | CcnxNetDeviceFace::Send (Ptr<Packet> packet) |
| 81 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame^] | 82 | NS_LOG_FUNCTION (this << packet); |
| 83 | |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 84 | NS_ASSERT_MSG (packet->GetSize () <= m_netDevice->GetMtu (), |
| 85 | "Packet size " << packet->GetSize () << " exceeds device MTU " |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 86 | << m_netDevice->GetMtu () |
| 87 | << " for Ccnx; fragmentation not supported"); |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 88 | |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 89 | m_netDevice->Send (packet, m_netDevice->GetBroadcast (), |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 90 | CcnxL3Protocol::ETHERNET_FRAME_TYPE); |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | // callback |
| 94 | void |
| 95 | CcnxNetDeviceFace::ReceiveFromNetDevice (Ptr<NetDevice> device, |
| 96 | Ptr<const Packet> p, |
| 97 | uint16_t protocol, |
| 98 | const Address &from, |
| 99 | const Address &to, |
| 100 | NetDevice::PacketType packetType) |
| 101 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame^] | 102 | Receive (p); |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 106 | std::ostream& |
| 107 | CcnxNetDeviceFace::Print (std::ostream& os) const |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 108 | { |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 109 | os << "dev=net(" << GetId () << ")"; |
| 110 | return os; |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | }; // namespace ns3 |
| 114 | |