Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 3 | * Copyright (c) 2011 University of California, Los Angeles |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 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" |
Alexander Afanasyev | f9f4eb0 | 2011-12-16 01:51:14 -0800 | [diff] [blame] | 23 | #include "ccnx-l3-protocol.h" |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 24 | |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 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 | |
Alexander Afanasyev | 7f3e49e | 2012-04-30 00:17:07 -0700 | [diff] [blame] | 31 | #include "ns3/point-to-point-net-device.h" |
| 32 | #include "ns3/channel.h" |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame^] | 33 | #include "ns3/ccnx-name-components.h" |
Alexander Afanasyev | 7f3e49e | 2012-04-30 00:17:07 -0700 | [diff] [blame] | 34 | |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 35 | NS_LOG_COMPONENT_DEFINE ("CcnxNetDeviceFace"); |
| 36 | |
| 37 | namespace ns3 { |
| 38 | |
Alexander Afanasyev | cbe92ae | 2011-12-16 13:06:18 -0800 | [diff] [blame] | 39 | TypeId |
| 40 | CcnxNetDeviceFace::GetTypeId () |
| 41 | { |
| 42 | static TypeId tid = TypeId ("ns3::CcnxNetDeviceFace") |
| 43 | .SetParent<CcnxFace> () |
| 44 | .SetGroupName ("Ccnx") |
| 45 | ; |
| 46 | return tid; |
| 47 | } |
| 48 | |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 49 | /** |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 50 | * By default, Ccnx face are created in the "down" state. Before |
| 51 | * becoming useable, the user must invoke SetUp on the face |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 52 | */ |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 53 | CcnxNetDeviceFace::CcnxNetDeviceFace (Ptr<Node> node, const Ptr<NetDevice> &netDevice) |
| 54 | : CcnxFace (node) |
| 55 | , m_netDevice (netDevice) |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 56 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 57 | NS_LOG_FUNCTION (this << netDevice); |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 58 | |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 59 | SetMetric (1); // default metric |
| 60 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 61 | 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] | 62 | } |
| 63 | |
| 64 | CcnxNetDeviceFace::~CcnxNetDeviceFace () |
| 65 | { |
| 66 | NS_LOG_FUNCTION_NOARGS (); |
| 67 | } |
| 68 | |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 69 | CcnxNetDeviceFace& CcnxNetDeviceFace::operator= (const CcnxNetDeviceFace &) |
| 70 | { |
| 71 | return *this; |
| 72 | } |
| 73 | |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 74 | Ptr<NetDevice> |
| 75 | CcnxNetDeviceFace::GetNetDevice () const |
| 76 | { |
| 77 | return m_netDevice; |
| 78 | } |
| 79 | |
| 80 | void |
| 81 | CcnxNetDeviceFace::RegisterProtocolHandler (ProtocolHandler handler) |
| 82 | { |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 83 | NS_LOG_FUNCTION (this); |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 84 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 85 | CcnxFace::RegisterProtocolHandler (handler); |
| 86 | |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 87 | m_node->RegisterProtocolHandler (MakeCallback (&CcnxNetDeviceFace::ReceiveFromNetDevice, this), |
| 88 | CcnxL3Protocol::ETHERNET_FRAME_TYPE, m_netDevice, true/*promiscuous mode*/); |
| 89 | } |
| 90 | |
| 91 | void |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 92 | CcnxNetDeviceFace::SendImpl (Ptr<Packet> packet) |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 93 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 94 | NS_LOG_FUNCTION (this << packet); |
| 95 | |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 96 | NS_ASSERT_MSG (packet->GetSize () <= m_netDevice->GetMtu (), |
| 97 | "Packet size " << packet->GetSize () << " exceeds device MTU " |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 98 | << m_netDevice->GetMtu () |
| 99 | << " for Ccnx; fragmentation not supported"); |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 100 | |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 101 | m_netDevice->Send (packet, m_netDevice->GetBroadcast (), |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 102 | CcnxL3Protocol::ETHERNET_FRAME_TYPE); |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | // callback |
| 106 | void |
| 107 | CcnxNetDeviceFace::ReceiveFromNetDevice (Ptr<NetDevice> device, |
| 108 | Ptr<const Packet> p, |
| 109 | uint16_t protocol, |
| 110 | const Address &from, |
| 111 | const Address &to, |
| 112 | NetDevice::PacketType packetType) |
| 113 | { |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 114 | NS_LOG_FUNCTION (device << p << protocol << from << to << packetType); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 115 | Receive (p); |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 119 | std::ostream& |
| 120 | CcnxNetDeviceFace::Print (std::ostream& os) const |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 121 | { |
Alexander Afanasyev | 7f3e49e | 2012-04-30 00:17:07 -0700 | [diff] [blame] | 122 | os << "dev[" << GetNode ()->GetId () << "]=net(" << GetId () << ","; |
| 123 | os << DynamicCast<PointToPointNetDevice> (m_netDevice)->GetChannel ()->GetDevice (0)->GetNode ()->GetId (); |
| 124 | os << "-"; |
| 125 | os << DynamicCast<PointToPointNetDevice> (m_netDevice)->GetChannel ()->GetDevice (1)->GetNode ()->GetId (); |
| 126 | os << ")"; |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 127 | return os; |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | }; // namespace ns3 |
| 131 | |