blob: fe3e41c3482b50203bf5da50e3b7fc8fad1ec2c0 [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>
Alexander Afanasyev161a5c42012-04-17 15:14:04 -070019 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080020 */
21
Alexander Afanasyev161a5c42012-04-17 15:14:04 -070022#include "weights-path-stretch-tag.h"
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080023#include "ns3/node.h"
24#include "ns3/names.h"
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080025
26namespace ns3 {
27
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080028WeightsPathStretchTag::WeightsPathStretchTag ()
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080029{
30}
31
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080032void
33WeightsPathStretchTag::AddPathInfo (Ptr<Node> node, uint32_t weight)
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080034{
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080035 m_infos.push_back (NodeWeightPair (node, weight));
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080036}
37
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080038
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080039TypeId WeightsPathStretchTag::GetTypeId ()
40{
41 static TypeId tid = TypeId("ns3::WeightsPathStretchTag")
42 .SetParent<Tag>()
43 .AddConstructor<WeightsPathStretchTag>()
44 ;
45 return tid;
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080046}
47
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080048// TypeId
49// WeightsPathStretchTag::GetInstanceTypeId () const
50// {
51// return GetTypeId ();
52// }
53
Alexander Afanasyev6bff0df2012-01-19 17:51:52 -080054uint64_t
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080055WeightsPathStretchTag::GetTotalWeight () const
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080056{
Alexander Afanasyev6bff0df2012-01-19 17:51:52 -080057 uint64_t total = 0;
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080058 for (std::list<NodeWeightPair>::const_iterator info = m_infos.begin (); info != m_infos.end (); info++)
59 {
60 total += info->weight;
61 }
62 return total;
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080063}
64
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080065Ptr<Node>
66WeightsPathStretchTag::GetSourceNode () const
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080067{
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080068 NS_ASSERT (m_infos.size () > 0);
69 return m_infos.front ().node;
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080070}
71
Alexander Afanasyev6bff0df2012-01-19 17:51:52 -080072Ptr<Node>
73WeightsPathStretchTag::GetDestinationNode () const
74{
75 NS_ASSERT (m_infos.size () > 0);
76 return m_infos.back ().node;
77}
78
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080079uint32_t WeightsPathStretchTag::GetSerializedSize (void) const
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080080{
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080081 return 0;
82 // return sizeof (GetPointer (m_value.node)) + sizeof (m_value.weight);
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080083}
84
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080085void WeightsPathStretchTag::Serialize (TagBuffer i) const
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080086{
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080087 NS_FATAL_ERROR ("Serialization is not supported for this tag");
88 // m_value.node->Ref ();
89 // i.WriteU64 (reinterpret_cast<uint64_t> (GetPointer (m_value.node)));
90 // i.WriteU32 (m_value.weight);
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080091}
92
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080093void WeightsPathStretchTag::Deserialize (TagBuffer i)
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080094{
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080095 NS_FATAL_ERROR ("Deserialization is not supported for this tag");
96 // m_value.node = Ptr<Node> (reinterpret_cast<Node*> (i.ReadU64 ()), false);
97 // m_value.weight = i.ReadU32 ();
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080098}
99
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800100void WeightsPathStretchTag::Print (std::ostream &os) const
Ilya Moiseenko1a8be032012-01-18 12:51:09 -0800101{
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800102 for (std::list<NodeWeightPair>::const_iterator info = m_infos.begin ();
103 info != m_infos.end ();
104 info ++)
105 {
106 if (info != m_infos.begin ()) os << ",";
107 NS_ASSERT (info->node != 0);
108
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800109 os << info->node->GetId () << "(" << Names::FindName (info->node) << ")";
110 // std::string name = Names::FindName (info->node);
111 // if (!name.empty ())
112 // os << name;
113 // else
114 // os << info->node->GetId ();
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800115 os << ":" << info->weight;
116 }
Ilya Moiseenko1a8be032012-01-18 12:51:09 -0800117}
118
Ilya Moiseenko1a8be032012-01-18 12:51:09 -0800119} // namespace ns3
120