blob: 2fe184080675075533b63855e2448d35e4ef1bac [file] [log] [blame]
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
Ilya Moiseenko956d0542012-01-02 15:26:40 -08003 * Copyright (c) 2011 University of California, Los Angeles
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -07004 *
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 Afanasyevf9f4eb02011-12-16 01:51:14 -080023#include "ccnx-l3-protocol.h"
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070024
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070025#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 Afanasyev7f3e49e2012-04-30 00:17:07 -070031#include "ns3/point-to-point-net-device.h"
32#include "ns3/channel.h"
33
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070034NS_LOG_COMPONENT_DEFINE ("CcnxNetDeviceFace");
35
36namespace ns3 {
37
Alexander Afanasyevcbe92ae2011-12-16 13:06:18 -080038TypeId
39CcnxNetDeviceFace::GetTypeId ()
40{
41 static TypeId tid = TypeId ("ns3::CcnxNetDeviceFace")
42 .SetParent<CcnxFace> ()
43 .SetGroupName ("Ccnx")
44 ;
45 return tid;
46}
47
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070048/**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070049 * By default, Ccnx face are created in the "down" state. Before
50 * becoming useable, the user must invoke SetUp on the face
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070051 */
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080052CcnxNetDeviceFace::CcnxNetDeviceFace (Ptr<Node> node, const Ptr<NetDevice> &netDevice)
53 : CcnxFace (node)
54 , m_netDevice (netDevice)
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070055{
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080056 NS_LOG_FUNCTION (this << netDevice);
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070057
Alexander Afanasyeva5abcd92012-04-17 13:34:43 -070058 SetMetric (1); // default metric
59
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080060 NS_ASSERT_MSG (m_netDevice != 0, "CcnxNetDeviceFace needs to be assigned a valid NetDevice");
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070061}
62
63CcnxNetDeviceFace::~CcnxNetDeviceFace ()
64{
65 NS_LOG_FUNCTION_NOARGS ();
66}
67
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070068CcnxNetDeviceFace& CcnxNetDeviceFace::operator= (const CcnxNetDeviceFace &)
69{
70 return *this;
71}
72
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070073Ptr<NetDevice>
74CcnxNetDeviceFace::GetNetDevice () const
75{
76 return m_netDevice;
77}
78
79void
80CcnxNetDeviceFace::RegisterProtocolHandler (ProtocolHandler handler)
81{
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080082 NS_LOG_FUNCTION (this);
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070083
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080084 CcnxFace::RegisterProtocolHandler (handler);
85
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070086 m_node->RegisterProtocolHandler (MakeCallback (&CcnxNetDeviceFace::ReceiveFromNetDevice, this),
87 CcnxL3Protocol::ETHERNET_FRAME_TYPE, m_netDevice, true/*promiscuous mode*/);
88}
89
90void
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080091CcnxNetDeviceFace::SendImpl (Ptr<Packet> packet)
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070092{
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080093 NS_LOG_FUNCTION (this << packet);
94
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070095 NS_ASSERT_MSG (packet->GetSize () <= m_netDevice->GetMtu (),
96 "Packet size " << packet->GetSize () << " exceeds device MTU "
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080097 << m_netDevice->GetMtu ()
98 << " for Ccnx; fragmentation not supported");
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070099
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700100 m_netDevice->Send (packet, m_netDevice->GetBroadcast (),
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800101 CcnxL3Protocol::ETHERNET_FRAME_TYPE);
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700102}
103
104// callback
105void
106CcnxNetDeviceFace::ReceiveFromNetDevice (Ptr<NetDevice> device,
107 Ptr<const Packet> p,
108 uint16_t protocol,
109 const Address &from,
110 const Address &to,
111 NetDevice::PacketType packetType)
112{
Alexander Afanasyev23d2b542011-12-07 18:54:46 -0800113 NS_LOG_FUNCTION (device << p << protocol << from << to << packetType);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800114 Receive (p);
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700115}
116
117
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700118std::ostream&
119CcnxNetDeviceFace::Print (std::ostream& os) const
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700120{
Alexander Afanasyev7f3e49e2012-04-30 00:17:07 -0700121 os << "dev[" << GetNode ()->GetId () << "]=net(" << GetId () << ",";
122 os << DynamicCast<PointToPointNetDevice> (m_netDevice)->GetChannel ()->GetDevice (0)->GetNode ()->GetId ();
123 os << "-";
124 os << DynamicCast<PointToPointNetDevice> (m_netDevice)->GetChannel ()->GetDevice (1)->GetNode ()->GetId ();
125 os << ")";
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700126 return os;
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700127}
128
129}; // namespace ns3
130