blob: 6ce6b92cf3bc5fca7182da691209a07a19e35162 [file] [log] [blame]
Alexander Afanasyevc74a6022011-08-15 20:01:35 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -07002/*
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:
19 *
20 */
21
Alexander Afanasyev98256102011-08-14 01:00:02 -070022#include "ccnx-face.h"
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070023
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070024#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
Alexander Afanasyev98256102011-08-14 01:00:02 -070031NS_LOG_COMPONENT_DEFINE ("CcnxFace");
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070032
33namespace ns3 {
34
Alexander Afanasyev98256102011-08-14 01:00:02 -070035NS_OBJECT_ENSURE_REGISTERED (CcnxFace);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070036
37TypeId
Alexander Afanasyev98256102011-08-14 01:00:02 -070038CcnxFace::GetTypeId (void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070039{
Alexander Afanasyev98256102011-08-14 01:00:02 -070040 static TypeId tid = TypeId ("ns3::CcnxFace")
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070041 .SetParent<Object> ()
42 ;
43 return tid;
44}
45
46/**
Alexander Afanasyev98256102011-08-14 01:00:02 -070047 * By default, Ccnx face are created in the "down" state
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070048 * with no IP addresses. Before becoming useable, the user must
49 * invoke SetUp on them once an Ccnx address and mask have been set.
50 */
Alexander Afanasyev98256102011-08-14 01:00:02 -070051CcnxFace::CcnxFace ()
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070052 : m_ifup (false)
53 , m_metric (1)
54 , m_node (0)
55 , m_device (0)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070056{
57 NS_LOG_FUNCTION (this);
58}
59
Alexander Afanasyev98256102011-08-14 01:00:02 -070060CcnxFace::~CcnxFace ()
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070061{
62 NS_LOG_FUNCTION_NOARGS ();
63}
64
65void
Alexander Afanasyev98256102011-08-14 01:00:02 -070066CcnxFace::DoDispose (void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070067{
68 NS_LOG_FUNCTION_NOARGS ();
69 m_node = 0;
70 m_device = 0;
71 Object::DoDispose ();
72}
73
74void
Alexander Afanasyev98256102011-08-14 01:00:02 -070075CcnxFace::SetNode (Ptr<Node> node)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070076{
77 m_node = node;
78}
79
80void
Alexander Afanasyev98256102011-08-14 01:00:02 -070081CcnxFace::SetDevice (Ptr<NetDevice> device)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070082{
83 m_device = device;
84}
85
86Ptr<NetDevice>
Alexander Afanasyev98256102011-08-14 01:00:02 -070087CcnxFace::GetDevice (void) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070088{
89 return m_device;
90}
91
92void
Alexander Afanasyev98256102011-08-14 01:00:02 -070093CcnxFace::SetMetric (uint16_t metric)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070094{
95 NS_LOG_FUNCTION (metric);
96 m_metric = metric;
97}
98
99uint16_t
Alexander Afanasyev98256102011-08-14 01:00:02 -0700100CcnxFace::GetMetric (void) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700101{
102 NS_LOG_FUNCTION_NOARGS ();
103 return m_metric;
104}
105
106/**
Alexander Afanasyev98256102011-08-14 01:00:02 -0700107 * These are face states and may be distinct from
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700108 * NetDevice states, such as found in real implementations
Alexander Afanasyev98256102011-08-14 01:00:02 -0700109 * (where the device may be down but face state is still up).
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700110 */
111bool
Alexander Afanasyev98256102011-08-14 01:00:02 -0700112CcnxFace::IsUp (void) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700113{
114 NS_LOG_FUNCTION_NOARGS ();
115 return m_ifup;
116}
117
118bool
Alexander Afanasyev98256102011-08-14 01:00:02 -0700119CcnxFace::IsDown (void) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700120{
121 NS_LOG_FUNCTION_NOARGS ();
122 return !m_ifup;
123}
124
125void
Alexander Afanasyev98256102011-08-14 01:00:02 -0700126CcnxFace::SetUp (void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700127{
128 NS_LOG_FUNCTION_NOARGS ();
129 m_ifup = true;
130}
131
132void
Alexander Afanasyev98256102011-08-14 01:00:02 -0700133CcnxFace::SetDown (void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700134{
135 NS_LOG_FUNCTION_NOARGS ();
136 m_ifup = false;
137}
138
139void
Alexander Afanasyev98256102011-08-14 01:00:02 -0700140CcnxFace::Send (Ptr<Packet> packet)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700141{
Alexander Afanasyev98256102011-08-14 01:00:02 -0700142 NS_ASSERT_MSG (packet->GetSize () <= GetDevice ()->GetMtu (),
143 "Packet size " << packet->GetSize () << " exceeds device MTU "
144 << GetDevice ()->GetMtu ()
145 << " for Ccnx; fragmentation not supported");
146
147 NS_LOG_FUNCTION (*packet);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700148 if (!IsUp ())
149 {
150 return;
151 }
152
Alexander Afanasyev98256102011-08-14 01:00:02 -0700153 m_device->Send (packet, m_device->GetBroadcast (),
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700154 CcnxL3Protocol::ETHERNET_FRAME_TYPE);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700155}
156
Alexander Afanasyev98256102011-08-14 01:00:02 -0700157std::ostream& operator<< (std::ostream& os, CcnxFace const& face)
158{
159 os << "dev=" << face.GetDevice ()->GetIfIndex ();
160 return os;
161}
162
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700163}; // namespace ns3
164