blob: b4b29e1a7bfc61dc5629cf97693c7ed0f44c423b [file] [log] [blame]
Ilya Moiseenko1a8be032012-01-18 12:51:09 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011 University of California, Los Angeles
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 *
18 * Author: Ilya Moiseenko <iliamo@cs.ucla.edu>
19 */
20
21#include "ccnx-path-stretch-tag.h"
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080022#include "ns3/node.h"
23#include "ns3/names.h"
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080024
25namespace ns3 {
26
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080027WeightsPathStretchTag::WeightsPathStretchTag ()
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080028{
29}
30
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080031void
32WeightsPathStretchTag::AddPathInfo (Ptr<Node> node, uint32_t weight)
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080033{
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080034 m_infos.push_back (NodeWeightPair (node, weight));
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080035}
36
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080037
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080038TypeId WeightsPathStretchTag::GetTypeId ()
39{
40 static TypeId tid = TypeId("ns3::WeightsPathStretchTag")
41 .SetParent<Tag>()
42 .AddConstructor<WeightsPathStretchTag>()
43 ;
44 return tid;
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080045}
46
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080047// TypeId
48// WeightsPathStretchTag::GetInstanceTypeId () const
49// {
50// return GetTypeId ();
51// }
52
53uint32_t
54WeightsPathStretchTag::GetTotalWeight () const
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080055{
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080056 uint32_t total = 0;
57 for (std::list<NodeWeightPair>::const_iterator info = m_infos.begin (); info != m_infos.end (); info++)
58 {
59 total += info->weight;
60 }
61 return total;
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080062}
63
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080064Ptr<Node>
65WeightsPathStretchTag::GetSourceNode () const
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080066{
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080067 NS_ASSERT (m_infos.size () > 0);
68 return m_infos.front ().node;
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080069}
70
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080071uint32_t WeightsPathStretchTag::GetSerializedSize (void) const
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080072{
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080073 return 0;
74 // return sizeof (GetPointer (m_value.node)) + sizeof (m_value.weight);
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080075}
76
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080077void WeightsPathStretchTag::Serialize (TagBuffer i) const
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080078{
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080079 NS_FATAL_ERROR ("Serialization is not supported for this tag");
80 // m_value.node->Ref ();
81 // i.WriteU64 (reinterpret_cast<uint64_t> (GetPointer (m_value.node)));
82 // i.WriteU32 (m_value.weight);
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080083}
84
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080085void WeightsPathStretchTag::Deserialize (TagBuffer i)
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080086{
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080087 NS_FATAL_ERROR ("Deserialization is not supported for this tag");
88 // m_value.node = Ptr<Node> (reinterpret_cast<Node*> (i.ReadU64 ()), false);
89 // m_value.weight = i.ReadU32 ();
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080090}
91
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080092void WeightsPathStretchTag::Print (std::ostream &os) const
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080093{
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080094 for (std::list<NodeWeightPair>::const_iterator info = m_infos.begin ();
95 info != m_infos.end ();
96 info ++)
97 {
98 if (info != m_infos.begin ()) os << ",";
99 NS_ASSERT (info->node != 0);
100
101 std::string name = Names::FindName (info->node);
102 if (!name.empty ())
103 os << name;
104 else
105 os << info->node->GetId ();
106 os << ":" << info->weight;
107 }
Ilya Moiseenko1a8be032012-01-18 12:51:09 -0800108}
109
Ilya Moiseenko1a8be032012-01-18 12:51:09 -0800110} // namespace ns3
111