blob: d672f072f9b7f3888776559499fb4bbd1f74ab0e [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 Afanasyev98256102011-08-14 01:00:02 -070032NS_OBJECT_ENSURE_REGISTERED (CcnxFace);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070033
34TypeId
Alexander Afanasyev98256102011-08-14 01:00:02 -070035CcnxFace::GetTypeId (void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070036{
Alexander Afanasyev98256102011-08-14 01:00:02 -070037 static TypeId tid = TypeId ("ns3::CcnxFace")
Alexander Afanasyev070aa482011-08-20 00:38:25 -070038 .SetGroupName ("Ccnx")
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070039 .SetParent<Object> ()
40 ;
41 return tid;
42}
43
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 Afanasyev56f79ea2011-08-17 23:54:27 -070050 : m_metric (1)
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070051 , 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 Afanasyev08d984e2011-08-13 19:20:22 -070073void
Alexander Afanasyev98256102011-08-14 01:00:02 -070074CcnxFace::DoDispose (void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070075{
76 NS_LOG_FUNCTION_NOARGS ();
77 m_node = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070078 Object::DoDispose ();
79}
80
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 Afanasyev08d984e2011-08-13 19:20:22 -070087void
Alexander Afanasyev98256102011-08-14 01:00:02 -070088CcnxFace::SetMetric (uint16_t metric)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070089{
90 NS_LOG_FUNCTION (metric);
91 m_metric = metric;
92}
93
94uint16_t
Alexander Afanasyev98256102011-08-14 01:00:02 -070095CcnxFace::GetMetric (void) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070096{
97 NS_LOG_FUNCTION_NOARGS ();
98 return m_metric;
99}
100
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
135CcnxFace::operator== (const CcnxFace &face) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700136{
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700137 NS_ASSERT_MSG (m_node->GetId () == face.m_node->GetId (), "Faces of different nodes should not be compared to each other");
138
139 return (m_id == face.m_id);
140}
141
142bool
143CcnxFace::operator< (const CcnxFace &face) const
144{
145 NS_ASSERT_MSG (m_node->GetId () == face.m_node->GetId (), "Faces of different nodes should not be compared to each other");
146
147 return (m_id < face.m_id);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700148}
149
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700150std::ostream& operator<< (std::ostream& os, const CcnxFace &face)
Alexander Afanasyev98256102011-08-14 01:00:02 -0700151{
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700152 os << "id=" << face.GetId ();
Alexander Afanasyev98256102011-08-14 01:00:02 -0700153 return os;
154}
155
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700156}; // namespace ns3
157