blob: d14e136cb88634c00bb1d6f1d9288ef799d3cc8f [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
31NS_LOG_COMPONENT_DEFINE ("CcnxNetDeviceFace");
32
33namespace ns3 {
34
Alexander Afanasyevcbe92ae2011-12-16 13:06:18 -080035TypeId
36CcnxNetDeviceFace::GetTypeId ()
37{
38 static TypeId tid = TypeId ("ns3::CcnxNetDeviceFace")
39 .SetParent<CcnxFace> ()
40 .SetGroupName ("Ccnx")
41 ;
42 return tid;
43}
44
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070045/**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070046 * By default, Ccnx face are created in the "down" state. Before
47 * becoming useable, the user must invoke SetUp on the face
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070048 */
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080049CcnxNetDeviceFace::CcnxNetDeviceFace (Ptr<Node> node, const Ptr<NetDevice> &netDevice)
50 : CcnxFace (node)
51 , m_netDevice (netDevice)
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070052{
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080053 NS_LOG_FUNCTION (this << netDevice);
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070054
Alexander Afanasyeva5abcd92012-04-17 13:34:43 -070055 SetMetric (1); // default metric
56
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080057 NS_ASSERT_MSG (m_netDevice != 0, "CcnxNetDeviceFace needs to be assigned a valid NetDevice");
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070058}
59
60CcnxNetDeviceFace::~CcnxNetDeviceFace ()
61{
62 NS_LOG_FUNCTION_NOARGS ();
63}
64
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070065CcnxNetDeviceFace& CcnxNetDeviceFace::operator= (const CcnxNetDeviceFace &)
66{
67 return *this;
68}
69
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070070Ptr<NetDevice>
71CcnxNetDeviceFace::GetNetDevice () const
72{
73 return m_netDevice;
74}
75
76void
77CcnxNetDeviceFace::RegisterProtocolHandler (ProtocolHandler handler)
78{
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080079 NS_LOG_FUNCTION (this);
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070080
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080081 CcnxFace::RegisterProtocolHandler (handler);
82
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070083 m_node->RegisterProtocolHandler (MakeCallback (&CcnxNetDeviceFace::ReceiveFromNetDevice, this),
84 CcnxL3Protocol::ETHERNET_FRAME_TYPE, m_netDevice, true/*promiscuous mode*/);
85}
86
87void
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080088CcnxNetDeviceFace::SendImpl (Ptr<Packet> packet)
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070089{
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080090 NS_LOG_FUNCTION (this << packet);
91
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070092 NS_ASSERT_MSG (packet->GetSize () <= m_netDevice->GetMtu (),
93 "Packet size " << packet->GetSize () << " exceeds device MTU "
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080094 << m_netDevice->GetMtu ()
95 << " for Ccnx; fragmentation not supported");
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070096
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070097 m_netDevice->Send (packet, m_netDevice->GetBroadcast (),
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080098 CcnxL3Protocol::ETHERNET_FRAME_TYPE);
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070099}
100
101// callback
102void
103CcnxNetDeviceFace::ReceiveFromNetDevice (Ptr<NetDevice> device,
104 Ptr<const Packet> p,
105 uint16_t protocol,
106 const Address &from,
107 const Address &to,
108 NetDevice::PacketType packetType)
109{
Alexander Afanasyev23d2b542011-12-07 18:54:46 -0800110 NS_LOG_FUNCTION (device << p << protocol << from << to << packetType);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800111 Receive (p);
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700112}
113
114
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700115std::ostream&
116CcnxNetDeviceFace::Print (std::ostream& os) const
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700117{
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700118 os << "dev[" << GetNode ()->GetId () << "]=net(" << GetId () << ")";
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700119 return os;
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700120}
121
122}; // namespace ns3
123