blob: 3250355b8f741966a0efed5a83295d113b8e0883 [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 *
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070018 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070019 *
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/log.h"
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070025#include "ns3/node.h"
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070026
Alexander Afanasyev98256102011-08-14 01:00:02 -070027NS_LOG_COMPONENT_DEFINE ("CcnxFace");
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070028
29namespace ns3 {
30
Alexander Afanasyev98256102011-08-14 01:00:02 -070031NS_OBJECT_ENSURE_REGISTERED (CcnxFace);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070032
33TypeId
Alexander Afanasyev98256102011-08-14 01:00:02 -070034CcnxFace::GetTypeId (void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070035{
Alexander Afanasyev98256102011-08-14 01:00:02 -070036 static TypeId tid = TypeId ("ns3::CcnxFace")
Alexander Afanasyev070aa482011-08-20 00:38:25 -070037 .SetGroupName ("Ccnx")
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070038 .SetParent<Object> ()
39 ;
40 return tid;
41}
42
43/**
Alexander Afanasyev98256102011-08-14 01:00:02 -070044 * By default, Ccnx face are created in the "down" state
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070045 * with no IP addresses. Before becoming useable, the user must
46 * invoke SetUp on them once an Ccnx address and mask have been set.
47 */
Alexander Afanasyev98256102011-08-14 01:00:02 -070048CcnxFace::CcnxFace ()
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070049 : m_metric (1)
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070050 , m_node (0)
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070051 , m_ifup (false)
52 , m_id ((uint32_t)-1)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070053{
54 NS_LOG_FUNCTION (this);
55}
56
Alexander Afanasyev98256102011-08-14 01:00:02 -070057CcnxFace::~CcnxFace ()
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070058{
59 NS_LOG_FUNCTION_NOARGS ();
60}
61
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070062CcnxFace::CcnxFace (const CcnxFace &)
63{
64}
65
66CcnxFace& CcnxFace::operator= (const CcnxFace &)
67{
68 return *this;
69}
70
71
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070072void
Alexander Afanasyev98256102011-08-14 01:00:02 -070073CcnxFace::DoDispose (void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070074{
75 NS_LOG_FUNCTION_NOARGS ();
76 m_node = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070077 Object::DoDispose ();
78}
79
80void
Alexander Afanasyev98256102011-08-14 01:00:02 -070081CcnxFace::SetNode (Ptr<Node> node)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070082{
83 m_node = node;
84}
85
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070086void
Alexander Afanasyev98256102011-08-14 01:00:02 -070087CcnxFace::SetMetric (uint16_t metric)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070088{
89 NS_LOG_FUNCTION (metric);
90 m_metric = metric;
91}
92
93uint16_t
Alexander Afanasyev98256102011-08-14 01:00:02 -070094CcnxFace::GetMetric (void) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070095{
96 NS_LOG_FUNCTION_NOARGS ();
97 return m_metric;
98}
99
100/**
Alexander Afanasyev98256102011-08-14 01:00:02 -0700101 * These are face states and may be distinct from
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700102 * NetDevice states, such as found in real implementations
Alexander Afanasyev98256102011-08-14 01:00:02 -0700103 * (where the device may be down but face state is still up).
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700104 */
105bool
Alexander Afanasyev98256102011-08-14 01:00:02 -0700106CcnxFace::IsUp (void) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700107{
108 NS_LOG_FUNCTION_NOARGS ();
109 return m_ifup;
110}
111
112bool
Alexander Afanasyev98256102011-08-14 01:00:02 -0700113CcnxFace::IsDown (void) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700114{
115 NS_LOG_FUNCTION_NOARGS ();
116 return !m_ifup;
117}
118
119void
Alexander Afanasyev98256102011-08-14 01:00:02 -0700120CcnxFace::SetUp (void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700121{
122 NS_LOG_FUNCTION_NOARGS ();
123 m_ifup = true;
124}
125
126void
Alexander Afanasyev98256102011-08-14 01:00:02 -0700127CcnxFace::SetDown (void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700128{
129 NS_LOG_FUNCTION_NOARGS ();
130 m_ifup = false;
131}
132
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700133bool
134CcnxFace::operator== (const CcnxFace &face) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700135{
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700136 return (m_node->GetId () == face.m_node->GetId ()) &&
137 (m_id == face.m_id);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700138}
139
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700140std::ostream& operator<< (std::ostream& os, const CcnxFace &face)
Alexander Afanasyev98256102011-08-14 01:00:02 -0700141{
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700142 os << "id=" << face.GetId ();
Alexander Afanasyev98256102011-08-14 01:00:02 -0700143 return os;
144}
145
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700146}; // namespace ns3
147