blob: 19eb21d710617ff0081a4ed56ba6fcd27893a1d0 [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 Afanasyev08d984e2011-08-13 19:20:22 -070032/**
Alexander Afanasyev98256102011-08-14 01:00:02 -070033 * By default, Ccnx face are created in the "down" state
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070034 * with no IP addresses. Before becoming useable, the user must
35 * invoke SetUp on them once an Ccnx address and mask have been set.
36 */
Alexander Afanasyev98256102011-08-14 01:00:02 -070037CcnxFace::CcnxFace ()
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070038 // : m_metric (1)
39 : m_node (0)
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070040 , m_ifup (false)
41 , m_id ((uint32_t)-1)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070042{
43 NS_LOG_FUNCTION (this);
44}
45
Alexander Afanasyev98256102011-08-14 01:00:02 -070046CcnxFace::~CcnxFace ()
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070047{
48 NS_LOG_FUNCTION_NOARGS ();
49}
50
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070051CcnxFace::CcnxFace (const CcnxFace &)
52{
53}
54
55CcnxFace& CcnxFace::operator= (const CcnxFace &)
56{
57 return *this;
58}
59
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070060void
Alexander Afanasyev98256102011-08-14 01:00:02 -070061CcnxFace::SetNode (Ptr<Node> node)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070062{
63 m_node = node;
64}
65
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070066// void
67// CcnxFace::SetMetric (uint16_t metric)
68// {
69// NS_LOG_FUNCTION (metric);
70// m_metric = metric;
71// }
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070072
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070073// uint16_t
74// CcnxFace::GetMetric (void) const
75// {
76// NS_LOG_FUNCTION_NOARGS ();
77// return m_metric;
78// }
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070079
80/**
Alexander Afanasyev98256102011-08-14 01:00:02 -070081 * These are face states and may be distinct from
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070082 * NetDevice states, such as found in real implementations
Alexander Afanasyev98256102011-08-14 01:00:02 -070083 * (where the device may be down but face state is still up).
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070084 */
85bool
Alexander Afanasyev98256102011-08-14 01:00:02 -070086CcnxFace::IsUp (void) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070087{
88 NS_LOG_FUNCTION_NOARGS ();
89 return m_ifup;
90}
91
92bool
Alexander Afanasyev98256102011-08-14 01:00:02 -070093CcnxFace::IsDown (void) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070094{
95 NS_LOG_FUNCTION_NOARGS ();
96 return !m_ifup;
97}
98
99void
Alexander Afanasyev98256102011-08-14 01:00:02 -0700100CcnxFace::SetUp (void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700101{
102 NS_LOG_FUNCTION_NOARGS ();
103 m_ifup = true;
104}
105
106void
Alexander Afanasyev98256102011-08-14 01:00:02 -0700107CcnxFace::SetDown (void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700108{
109 NS_LOG_FUNCTION_NOARGS ();
110 m_ifup = false;
111}
112
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700113bool
114CcnxFace::operator== (const CcnxFace &face) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700115{
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800116 NS_ASSERT_MSG (m_node->GetId () == face.m_node->GetId (),
117 "Faces of different nodes should not be compared to each other");
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700118
119 return (m_id == face.m_id);
120}
121
122bool
123CcnxFace::operator< (const CcnxFace &face) const
124{
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800125 NS_ASSERT_MSG (m_node->GetId () == face.m_node->GetId (),
126 "Faces of different nodes should not be compared to each other");
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700127
128 return (m_id < face.m_id);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700129}
130
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700131std::ostream&
132CcnxFace::Print (std::ostream &os) const
133{
134 os << "id=" << GetId ();
135 return os;
136}
137
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700138std::ostream& operator<< (std::ostream& os, const CcnxFace &face)
Alexander Afanasyev98256102011-08-14 01:00:02 -0700139{
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700140 face.Print (os);
Alexander Afanasyev98256102011-08-14 01:00:02 -0700141 return os;
142}
143
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700144}; // namespace ns3
145