blob: 31adca188a61be6114f510b7e42a1f16ef230852 [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
Alexander Afanasyev6bff0df2012-01-19 17:51:52 -080053uint64_t
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080054WeightsPathStretchTag::GetTotalWeight () const
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080055{
Alexander Afanasyev6bff0df2012-01-19 17:51:52 -080056 uint64_t total = 0;
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080057 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 Afanasyev6bff0df2012-01-19 17:51:52 -080071Ptr<Node>
72WeightsPathStretchTag::GetDestinationNode () const
73{
74 NS_ASSERT (m_infos.size () > 0);
75 return m_infos.back ().node;
76}
77
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080078uint32_t WeightsPathStretchTag::GetSerializedSize (void) const
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080079{
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080080 return 0;
81 // return sizeof (GetPointer (m_value.node)) + sizeof (m_value.weight);
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080082}
83
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080084void WeightsPathStretchTag::Serialize (TagBuffer i) const
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080085{
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080086 NS_FATAL_ERROR ("Serialization is not supported for this tag");
87 // m_value.node->Ref ();
88 // i.WriteU64 (reinterpret_cast<uint64_t> (GetPointer (m_value.node)));
89 // i.WriteU32 (m_value.weight);
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080090}
91
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080092void WeightsPathStretchTag::Deserialize (TagBuffer i)
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080093{
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080094 NS_FATAL_ERROR ("Deserialization is not supported for this tag");
95 // m_value.node = Ptr<Node> (reinterpret_cast<Node*> (i.ReadU64 ()), false);
96 // m_value.weight = i.ReadU32 ();
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080097}
98
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080099void WeightsPathStretchTag::Print (std::ostream &os) const
Ilya Moiseenko1a8be032012-01-18 12:51:09 -0800100{
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800101 for (std::list<NodeWeightPair>::const_iterator info = m_infos.begin ();
102 info != m_infos.end ();
103 info ++)
104 {
105 if (info != m_infos.begin ()) os << ",";
106 NS_ASSERT (info->node != 0);
107
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800108 os << info->node->GetId () << "(" << Names::FindName (info->node) << ")";
109 // std::string name = Names::FindName (info->node);
110 // if (!name.empty ())
111 // os << name;
112 // else
113 // os << info->node->GetId ();
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800114 os << ":" << info->weight;
115 }
Ilya Moiseenko1a8be032012-01-18 12:51:09 -0800116}
117
Ilya Moiseenko1a8be032012-01-18 12:51:09 -0800118} // namespace ns3
119