blob: e19dc57ba8abaab02aaed66c451192e568af754d [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 Afanasyev08d984e2011-08-13 19:20:22 -070037 .SetParent<Object> ()
38 ;
39 return tid;
40}
41
42/**
Alexander Afanasyev98256102011-08-14 01:00:02 -070043 * By default, Ccnx face are created in the "down" state
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070044 * with no IP addresses. Before becoming useable, the user must
45 * invoke SetUp on them once an Ccnx address and mask have been set.
46 */
Alexander Afanasyev98256102011-08-14 01:00:02 -070047CcnxFace::CcnxFace ()
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070048 : m_metric (1)
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070049 , m_node (0)
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070050 , m_ifup (false)
51 , m_id ((uint32_t)-1)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070052{
53 NS_LOG_FUNCTION (this);
54}
55
Alexander Afanasyev98256102011-08-14 01:00:02 -070056CcnxFace::~CcnxFace ()
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070057{
58 NS_LOG_FUNCTION_NOARGS ();
59}
60
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070061CcnxFace::CcnxFace (const CcnxFace &)
62{
63}
64
65CcnxFace& CcnxFace::operator= (const CcnxFace &)
66{
67 return *this;
68}
69
70
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070071void
Alexander Afanasyev98256102011-08-14 01:00:02 -070072CcnxFace::DoDispose (void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070073{
74 NS_LOG_FUNCTION_NOARGS ();
75 m_node = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070076 Object::DoDispose ();
77}
78
79void
Alexander Afanasyev98256102011-08-14 01:00:02 -070080CcnxFace::SetNode (Ptr<Node> node)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070081{
82 m_node = node;
83}
84
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070085void
Alexander Afanasyev98256102011-08-14 01:00:02 -070086CcnxFace::SetMetric (uint16_t metric)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070087{
88 NS_LOG_FUNCTION (metric);
89 m_metric = metric;
90}
91
92uint16_t
Alexander Afanasyev98256102011-08-14 01:00:02 -070093CcnxFace::GetMetric (void) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070094{
95 NS_LOG_FUNCTION_NOARGS ();
96 return m_metric;
97}
98
99/**
Alexander Afanasyev98256102011-08-14 01:00:02 -0700100 * These are face states and may be distinct from
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700101 * NetDevice states, such as found in real implementations
Alexander Afanasyev98256102011-08-14 01:00:02 -0700102 * (where the device may be down but face state is still up).
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700103 */
104bool
Alexander Afanasyev98256102011-08-14 01:00:02 -0700105CcnxFace::IsUp (void) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700106{
107 NS_LOG_FUNCTION_NOARGS ();
108 return m_ifup;
109}
110
111bool
Alexander Afanasyev98256102011-08-14 01:00:02 -0700112CcnxFace::IsDown (void) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700113{
114 NS_LOG_FUNCTION_NOARGS ();
115 return !m_ifup;
116}
117
118void
Alexander Afanasyev98256102011-08-14 01:00:02 -0700119CcnxFace::SetUp (void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700120{
121 NS_LOG_FUNCTION_NOARGS ();
122 m_ifup = true;
123}
124
125void
Alexander Afanasyev98256102011-08-14 01:00:02 -0700126CcnxFace::SetDown (void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700127{
128 NS_LOG_FUNCTION_NOARGS ();
129 m_ifup = false;
130}
131
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700132bool
133CcnxFace::operator== (const CcnxFace &face) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700134{
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700135 return (m_node->GetId () == face.m_node->GetId ()) &&
136 (m_id == face.m_id);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700137}
138
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700139std::ostream& operator<< (std::ostream& os, const CcnxFace &face)
Alexander Afanasyev98256102011-08-14 01:00:02 -0700140{
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700141 os << "id=" << face.GetId ();
Alexander Afanasyev98256102011-08-14 01:00:02 -0700142 return os;
143}
144
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700145}; // namespace ns3
146