blob: 7821055a7010cf2d35683e266ebb08bec919727b [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 Afanasyev7fd74f92011-08-25 19:40:17 -070026#include "ns3/assert.h"
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070027
Alexander Afanasyev98256102011-08-14 01:00:02 -070028NS_LOG_COMPONENT_DEFINE ("CcnxFace");
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070029
30namespace ns3 {
31
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070032// NS_OBJECT_ENSURE_REGISTERED (CcnxFace);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070033
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070034// TypeId
35// CcnxFace::GetTypeId (void)
36// {
37// static TypeId tid = TypeId ("ns3::CcnxFace")
38// .SetGroupName ("Ccnx")
39// .SetParent<Object> ()
40// ;
41// return tid;
42// }
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070043
44/**
Alexander Afanasyev98256102011-08-14 01:00:02 -070045 * By default, Ccnx face are created in the "down" state
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070046 * with no IP addresses. Before becoming useable, the user must
47 * invoke SetUp on them once an Ccnx address and mask have been set.
48 */
Alexander Afanasyev98256102011-08-14 01:00:02 -070049CcnxFace::CcnxFace ()
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070050 // : m_metric (1)
51 : m_node (0)
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070052 , m_ifup (false)
53 , m_id ((uint32_t)-1)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070054{
55 NS_LOG_FUNCTION (this);
56}
57
Alexander Afanasyev98256102011-08-14 01:00:02 -070058CcnxFace::~CcnxFace ()
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070059{
60 NS_LOG_FUNCTION_NOARGS ();
61}
62
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070063CcnxFace::CcnxFace (const CcnxFace &)
64{
65}
66
67CcnxFace& CcnxFace::operator= (const CcnxFace &)
68{
69 return *this;
70}
71
72
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070073// void
74// CcnxFace::DoDispose (void)
75// {
76// NS_LOG_FUNCTION_NOARGS ();
77// m_node = 0;
78// Object::DoDispose ();
79// }
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070080
81void
Alexander Afanasyev98256102011-08-14 01:00:02 -070082CcnxFace::SetNode (Ptr<Node> node)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070083{
84 m_node = node;
85}
86
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070087// void
88// CcnxFace::SetMetric (uint16_t metric)
89// {
90// NS_LOG_FUNCTION (metric);
91// m_metric = metric;
92// }
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070093
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070094// uint16_t
95// CcnxFace::GetMetric (void) const
96// {
97// NS_LOG_FUNCTION_NOARGS ();
98// return m_metric;
99// }
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700100
101/**
Alexander Afanasyev98256102011-08-14 01:00:02 -0700102 * These are face states and may be distinct from
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700103 * NetDevice states, such as found in real implementations
Alexander Afanasyev98256102011-08-14 01:00:02 -0700104 * (where the device may be down but face state is still up).
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700105 */
106bool
Alexander Afanasyev98256102011-08-14 01:00:02 -0700107CcnxFace::IsUp (void) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700108{
109 NS_LOG_FUNCTION_NOARGS ();
110 return m_ifup;
111}
112
113bool
Alexander Afanasyev98256102011-08-14 01:00:02 -0700114CcnxFace::IsDown (void) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700115{
116 NS_LOG_FUNCTION_NOARGS ();
117 return !m_ifup;
118}
119
120void
Alexander Afanasyev98256102011-08-14 01:00:02 -0700121CcnxFace::SetUp (void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700122{
123 NS_LOG_FUNCTION_NOARGS ();
124 m_ifup = true;
125}
126
127void
Alexander Afanasyev98256102011-08-14 01:00:02 -0700128CcnxFace::SetDown (void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700129{
130 NS_LOG_FUNCTION_NOARGS ();
131 m_ifup = false;
132}
133
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700134bool
Ilya Moiseenkoacac1ea2011-10-28 13:16:53 -0700135CcnxFace::IsLocal() const
136{
137 return m_isLocal;
138}
139
140bool
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700141CcnxFace::operator== (const CcnxFace &face) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700142{
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700143 NS_ASSERT_MSG (m_node->GetId () == face.m_node->GetId (), "Faces of different nodes should not be compared to each other");
144
145 return (m_id == face.m_id);
146}
147
148bool
149CcnxFace::operator< (const CcnxFace &face) const
150{
151 NS_ASSERT_MSG (m_node->GetId () == face.m_node->GetId (), "Faces of different nodes should not be compared to each other");
152
153 return (m_id < face.m_id);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700154}
155
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700156std::ostream&
157CcnxFace::Print (std::ostream &os) const
158{
159 os << "id=" << GetId ();
160 return os;
161}
162
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700163std::ostream& operator<< (std::ostream& os, const CcnxFace &face)
Alexander Afanasyev98256102011-08-14 01:00:02 -0700164{
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700165 face.Print (os);
Alexander Afanasyev98256102011-08-14 01:00:02 -0700166 return os;
167}
168
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700169}; // namespace ns3
170