View | Details | Raw Unified | Return to bug 2413
Collapse All | Expand All

(-)a/src/internet/model/arp-header.cc (-1 / +1 lines)
 Lines 136-142    Link Here 
136
ArpHeader::GetSerializedSize (void) const
136
ArpHeader::GetSerializedSize (void) const
137
{
137
{
138
  NS_LOG_FUNCTION (this);
138
  NS_LOG_FUNCTION (this);
139
  NS_ASSERT((m_macSource.GetLength () == 6) || (m_macSource.GetLength () == 8));
139
  NS_ASSERT((m_macSource.GetLength () == 6) || (m_macSource.GetLength () == 8) || (m_macSource.GetLength () == 1));
140
  NS_ASSERT (m_macSource.GetLength () == m_macDest.GetLength ());
140
  NS_ASSERT (m_macSource.GetLength () == m_macDest.GetLength ());
141
141
142
  uint32_t length = 16;   // Length minus two hardware addresses
142
  uint32_t length = 16;   // Length minus two hardware addresses
(-)bdcf98f9b3df (+178 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 *
16
 * Author: Hossam Khader <hossamkhader@gmail.com>
17
 */
18
19
#include "ns3/core-module.h"
20
#include "ns3/node-container.h"
21
#include "ns3/mobility-helper.h"
22
#include "ns3/mobility-model.h"
23
#include "ns3/basic-energy-source-helper.h"
24
#include "ns3/energy-source-container.h"
25
#include "ns3/uan-helper.h"
26
#include "ns3/uan-channel.h"
27
#include "ns3/acoustic-modem-energy-model-helper.h"
28
#include "ns3/uan-application-helper.h"
29
#include "ns3/uan-application.h"
30
#include "ns3/ipv4-address-helper.h"
31
#include "ns3/internet-stack-helper.h"
32
#include "ns3/ipv4-interface.h"
33
#include "ns3/arp-cache.h"
34
35
using namespace ns3;
36
37
/**
38
 *
39
 * This example shows the usage of UanApplication to transfer data.
40
 * Two nodes are sending their remaining energy percentage (1 byte)
41
 * to a gateway node, that prints the received data.
42
 * The transmissions are scheduled at random times to avoid collisions
43
 * ARP parameters should be tuned, based on the network size
44
 *
45
 */
46
47
NS_LOG_COMPONENT_DEFINE ("UanApplicationExample");
48
49
void SetupPositions ();
50
void SetupEnergy ();
51
void SetupCommunications ();
52
void PrintReceivedPacket (Address src, Buffer data);
53
void SetupApplications ();
54
void SendPacket ();
55
void Run ();
56
57
NodeContainer nodeContainer;
58
59
void
60
SetupPositions ()
61
{
62
  MobilityHelper mobilityHelper;
63
  mobilityHelper.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
64
  mobilityHelper.Install (nodeContainer);
65
  nodeContainer.Get (0)->GetObject<MobilityModel> ()->SetPosition (Vector (0, 0, 0));
66
  nodeContainer.Get (1)->GetObject<MobilityModel> ()->SetPosition (Vector (100, 0, 0));
67
  nodeContainer.Get (2)->GetObject<MobilityModel> ()->SetPosition (Vector (-100, 0, 0));
68
}
69
70
void
71
SetupEnergy ()
72
{
73
  BasicEnergySourceHelper energySourceHelper;
74
  energySourceHelper.Set ("BasicEnergySourceInitialEnergyJ", DoubleValue (900000));
75
  energySourceHelper.Install (nodeContainer);
76
}
77
78
void
79
SetupCommunications ()
80
{
81
  Ptr<UanChannel> channel = CreateObject<UanChannel> ();
82
  UanHelper uanHelper;
83
  NetDeviceContainer netDeviceContainer = uanHelper.Install (nodeContainer, channel);
84
  EnergySourceContainer energySourceContainer;
85
  NodeContainer::Iterator node = nodeContainer.Begin ();
86
  while (node != nodeContainer.End ())
87
    {
88
      energySourceContainer.Add ((*node)->GetObject<EnergySourceContainer> ()->Get (0));
89
      node++;
90
    }
91
  AcousticModemEnergyModelHelper acousticModemEnergyModelHelper;
92
  acousticModemEnergyModelHelper.Install (netDeviceContainer, energySourceContainer);
93
94
  InternetStackHelper internet;
95
  internet.Install (nodeContainer);
96
  Ipv4AddressHelper ipv4;
97
  ipv4.SetBase ("10.0.0.0", "255.255.255.0");
98
  ipv4.Assign (netDeviceContainer);
99
100
  node = nodeContainer.Begin ();
101
  while (node != nodeContainer.End ())
102
    {
103
      (*node)->GetObject<Ipv4L3Protocol> ()->GetInterface (1)->GetArpCache ()->SetDeadTimeout (Hours (24));
104
      (*node)->GetObject<Ipv4L3Protocol> ()->GetInterface (1)->GetArpCache ()->SetAliveTimeout (Hours (12));
105
      (*node)->GetObject<Ipv4L3Protocol> ()->GetInterface (1)->GetArpCache ()->SetWaitReplyTimeout (Seconds (10));
106
      node++;
107
    }
108
}
109
110
void
111
PrintReceivedPacket (Address src, Buffer data)
112
{
113
  std::cout << "Time:" << Simulator::Now ().GetHours () << "|"
114
            << "Node:" << Ipv4Address::ConvertFrom (src)
115
            << "|Energy:" << (int)(data.Begin ().ReadU8 ()) << "%" << std::endl;
116
}
117
118
void
119
SetupApplications ()
120
{
121
  UanApplicationHelper uanApplicationHelper;
122
  ApplicationContainer applicationContainer;
123
  uanApplicationHelper.SetPort (9);
124
  applicationContainer = uanApplicationHelper.Install (nodeContainer);
125
  applicationContainer.Start (Seconds (0));
126
  NodeContainer::Iterator node = nodeContainer.Begin ();
127
  while (node != nodeContainer.End ())
128
    {
129
      Ptr<UanApplication> uanApplication = (*node)->GetApplication (0)->GetObject<UanApplication> ();
130
      uanApplication->SetPacketReceivedCallback (MakeCallback<void, Address, Buffer>(&PrintReceivedPacket));
131
      node++;
132
    }
133
}
134
135
void
136
SendPacket ()
137
{
138
  Ptr<UniformRandomVariable> uniformRandomVariable = CreateObject<UniformRandomVariable> ();
139
  NodeContainer::Iterator node = nodeContainer.Begin ();
140
  node++;
141
  while (node != nodeContainer.End ())
142
    {
143
      uint8_t energy = ((*node)->GetObject<EnergySourceContainer> ()->Get (0)->GetEnergyFraction ()) * 100;
144
      Ptr<UanApplication> uanApplication = (*node)->GetApplication (0)->GetObject<UanApplication> ();
145
      Buffer dataBuffer;
146
      dataBuffer.AddAtEnd (sizeof (uint8_t));
147
      Buffer::Iterator i = dataBuffer.Begin ();
148
      double time = uniformRandomVariable->GetValue (0, 15);
149
      i.WriteU8 (energy);
150
      Simulator::Schedule (Seconds (time), &UanApplication::Send, uanApplication, Ipv4Address ("10.0.0.1"), dataBuffer);
151
      node++;
152
    }
153
  Simulator::Schedule (Minutes (5), &SendPacket);
154
}
155
156
void
157
Run ()
158
{
159
  nodeContainer.Create (3);
160
  SetupPositions ();
161
  SetupEnergy ();
162
  SetupCommunications ();
163
  SetupApplications ();
164
  SendPacket ();
165
}
166
167
int
168
main (int argc, char *argv[])
169
{
170
  CommandLine cmd;
171
  cmd.Parse (argc, argv);
172
  Run ();
173
  Simulator::Stop (Days (20));
174
  Simulator::Run ();
175
  Simulator::Destroy ();
176
177
  return 0;
178
}
(-)a/src/uan/examples/wscript (+3 lines)
 Lines 6-8    Link Here 
6
6
7
    obj = bld.create_ns3_program('uan-rc-example', ['internet', 'mobility', 'stats', 'applications', 'uan'])
7
    obj = bld.create_ns3_program('uan-rc-example', ['internet', 'mobility', 'stats', 'applications', 'uan'])
8
    obj.source = 'uan-rc-example.cc'
8
    obj.source = 'uan-rc-example.cc'
9
10
    obj = bld.create_ns3_program('uan-application-example', ['internet', 'uan', 'mobility', 'energy'])
11
    obj.source = 'uan-application-example.cc'
(-)bdcf98f9b3df (+90 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Author: Hossam Khader <hossamkhader@gmail.com>
17
 */
18
19
#include "uan-application-helper.h"
20
#include "ns3/names.h"
21
#include "ns3/packet-socket-factory.h"
22
#include "ns3/packet-socket-helper.h"
23
#include "ns3/net-device.h"
24
#include "ns3/address.h"
25
#include "ns3/uan-application.h"
26
#include "ns3/internet-stack-helper.h"
27
28
29
namespace ns3 {
30
31
UanApplicationHelper::UanApplicationHelper ()
32
  : m_port (0)
33
{
34
  m_factory.SetTypeId ("ns3::UanApplication");
35
}
36
37
void 
38
UanApplicationHelper::SetAttribute (std::string name, const AttributeValue &value)
39
{
40
  m_factory.Set (name, value);
41
}
42
43
ApplicationContainer
44
UanApplicationHelper::Install (Ptr<Node> node) const
45
{
46
  return ApplicationContainer (DoInstall (node));
47
}
48
49
ApplicationContainer
50
UanApplicationHelper::Install (std::string nodeName) const
51
{
52
  Ptr<Node> node = Names::Find<Node> (nodeName);
53
  return ApplicationContainer (DoInstall (node));
54
}
55
56
ApplicationContainer
57
UanApplicationHelper::Install (NodeContainer c) const
58
{
59
  ApplicationContainer apps;
60
  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
61
    {
62
      apps.Add (DoInstall (*i));
63
    }
64
65
  return apps;
66
}
67
68
Ptr<Application>
69
UanApplicationHelper::DoInstall (Ptr<Node> node) const
70
{
71
  if(node->GetObject<Ipv4> () == NULL)
72
    {
73
      InternetStackHelper internet;
74
      internet.Install (node);
75
    }
76
77
  Ptr<Application> app = m_factory.Create<Application> ();
78
  node->AddApplication (app);
79
  app->GetObject<UanApplication> ()->SetPort (m_port);
80
81
  return app;
82
}
83
84
void
85
UanApplicationHelper::SetPort (uint16_t port)
86
{
87
  m_port = port;
88
}
89
90
} // namespace ns3
(-)bdcf98f9b3df (+100 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Author: Hossam Khader <hossamkhader@gmail.com>
17
 */
18
19
#ifndef UAN_APPLICATION_HELPER_H
20
#define UAN_APPLICATION_HELPER_H
21
22
23
#include "ns3/object-factory.h"
24
#include "ns3/attribute.h"
25
#include "ns3/node-container.h"
26
#include "ns3/application-container.h"
27
28
namespace ns3 {
29
30
/**
31
 * \ingroup uan
32
 * \brief A helper to make it easier to instantiate an ns3::UanApplication 
33
 * on a set of nodes.
34
 */
35
class UanApplicationHelper
36
{
37
public:
38
  /**
39
   * Create an UanApplicationHelper to make it easier to work with UanApplication
40
   */
41
  UanApplicationHelper ();
42
43
  /**
44
   * Helper function used to set the underlying application attributes.
45
   */
46
  void SetAttribute (std::string name, const AttributeValue &value);
47
48
  /**
49
   * Install an ns3::UanApplication on each node of the input container
50
   * configured with all the attributes set with SetAttribute.
51
   *
52
   * \param c NodeContainer of the set of nodes on which an UanApplication 
53
   * will be installed.
54
   * \returns Container of Ptr to the applications installed.
55
   */
56
  ApplicationContainer Install (NodeContainer c) const;
57
58
  /**
59
   * Install an ns3::UanApplication on the node configured with all the 
60
   * attributes set with SetAttribute.
61
   *
62
   * \param node The node on which an UanApplication will be installed.
63
   * \returns Container of Ptr to the applications installed.
64
   */
65
  ApplicationContainer Install (Ptr<Node> node) const;
66
67
  /**
68
   * Install an ns3::UanApplication on the node configured with all the 
69
   * attributes set with SetAttribute.
70
   *
71
   * \param nodeName The node on which an UanApplication will be installed.
72
   * \returns Container of Ptr to the applications installed.
73
   */
74
  ApplicationContainer Install (std::string nodeName) const;
75
76
  /**
77
   * Sets the UDP port number that the UanApplication will use
78
   *
79
   * \param port The UDP port number
80
   */
81
  void SetPort (uint16_t port);
82
83
private:
84
  /**
85
   * Install an ns3::UanApplication on the node configured with all the 
86
   * attributes set with SetAttribute.
87
   *
88
   * \param node The node on which an UanApplication will be installed.
89
   * \returns Ptr to the application installed.
90
   */
91
  Ptr<Application> DoInstall (Ptr<Node> node) const;
92
93
  ObjectFactory m_factory; //!< Object factory.
94
  uint16_t m_port;
95
};
96
97
} // namespace ns3
98
99
#endif /* UAN_APPLICATION_HELPER_H */
100
(-)bdcf98f9b3df (+172 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Author: Hossam Khader <hossamkhader@gmail.com>
17
 */
18
#include "uan-application.h"
19
#include "ns3/log.h"
20
#include "ns3/socket-factory.h"
21
#include "ns3/packet-socket-address.h"
22
#include "ns3/packet-socket.h"
23
24
namespace ns3 {
25
26
NS_LOG_COMPONENT_DEFINE ("UanApplication");
27
28
NS_OBJECT_ENSURE_REGISTERED (UanApplication);
29
30
TypeId 
31
UanApplication::GetTypeId (void)
32
{
33
  static TypeId tid = TypeId ("ns3::UanApplication")
34
    .SetParent<Application> ()
35
    .SetGroupName ("Applications")
36
    .AddConstructor<UanApplication> ()
37
  ;
38
  return tid;
39
}
40
41
UanApplication::UanApplication ()
42
{
43
  NS_LOG_FUNCTION (this);
44
  m_socket = NULL;
45
  m_packetReceivedCallback.Nullify ();
46
}
47
UanApplication::~UanApplication ()
48
{
49
  NS_LOG_FUNCTION (this);
50
}
51
52
void
53
UanApplication::DoDispose (void)
54
{
55
  NS_LOG_FUNCTION (this);
56
  m_socket = NULL;
57
  m_packetReceivedCallback.Nullify ();
58
  Application::DoDispose ();
59
}
60
61
uint32_t
62
UanApplication::GetApplicationId (void) const
63
{
64
  NS_LOG_FUNCTION (this);
65
  Ptr<Node> node = GetNode ();
66
  for (uint32_t i = 0; i < node->GetNApplications (); ++i)
67
    {
68
      if (node->GetApplication (i) == this)
69
        {
70
          return i;
71
        }
72
    }
73
  NS_ASSERT_MSG (false, "forgot to add application to node");
74
  return 0;
75
}
76
77
78
void 
79
UanApplication::Send (Address dst, const Buffer dataBuffer)
80
{
81
  NS_LOG_FUNCTION (this);
82
  const uint8_t * data = dataBuffer.PeekData ();
83
  Ptr<Socket> socket;
84
  socket = Socket::CreateSocket (GetNode (), TypeId::LookupByName ("ns3::UdpSocketFactory"));
85
  Ptr<Packet> packet = Create<Packet> (data, dataBuffer.GetSize ());
86
  NS_ASSERT (socket != NULL);
87
  if(Ipv4Address::IsMatchingType (dst))
88
    {
89
      InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), m_port);
90
      socket->Bind (local);
91
      socket->Connect (InetSocketAddress (Ipv4Address::ConvertFrom (dst), m_port));
92
      socket->Send (packet);
93
    }
94
95
  socket->Close ();
96
}
97
98
void
99
UanApplication::Receive (Ptr<Socket> socket)
100
{
101
  NS_LOG_FUNCTION (this << socket);
102
  NS_ASSERT (m_socket != NULL);
103
  Address srcAddress;
104
  while (m_socket->GetRxAvailable () > 0)
105
    {
106
      Ptr<Packet> packet = m_socket->RecvFrom (srcAddress);
107
      uint8_t *buffer = new uint8_t[packet->GetSize ()];
108
      packet->CopyData (buffer, packet->GetSize ());
109
      if(!m_packetReceivedCallback.IsNull ())
110
        {
111
          Buffer dataBuffer;
112
          dataBuffer.AddAtEnd ( packet->GetSize ());
113
          Buffer::Iterator iterator = dataBuffer.Begin ();
114
          iterator.Write (buffer, packet->GetSize ());
115
          m_packetReceivedCallback (InetSocketAddress::ConvertFrom (srcAddress).GetIpv4 (), dataBuffer);
116
        }
117
      delete[] buffer;
118
    }
119
120
} 
121
122
void 
123
UanApplication::StartApplication (void)
124
{
125
  NS_LOG_FUNCTION (this);
126
  if (!m_socket)
127
    {
128
      m_socket = Socket::CreateSocket (GetNode (), TypeId::LookupByName ("ns3::UdpSocketFactory"));
129
    }
130
  InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), m_port);
131
  m_socket->Bind (local);
132
  m_socket->SetRecvCallback (MakeCallback (&UanApplication::Receive, this));
133
}
134
 
135
void 
136
UanApplication::StopApplication (void)
137
{
138
  NS_LOG_FUNCTION (this);
139
  if(m_socket != NULL)
140
    {
141
      m_socket->Close ();
142
    }
143
  else
144
    {
145
      NS_LOG_WARN ("UanApplication found null socket to close in StopApplication");
146
    }
147
}
148
149
void
150
UanApplication::SetPacketReceivedCallback (PacketReceivedCallback callback)
151
{
152
  NS_LOG_FUNCTION (this);
153
  if (callback.IsNull ())
154
    {
155
      NS_LOG_DEBUG ("UanApplication:Setting NULL packet received callback!");
156
    }
157
  m_packetReceivedCallback = callback;
158
}
159
160
void
161
UanApplication::SetPort (uint16_t port)
162
{
163
  m_port = port;
164
}
165
166
uint16_t
167
UanApplication::GetPort () const
168
{
169
  return m_port;
170
}
171
172
} // namespace ns3
(-)bdcf98f9b3df (+114 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Author: Hossam Khader <hossamkhader@gmail.com>
17
 */
18
19
#ifndef UAN_APPLICATION_H
20
#define UAN_APPLICATION_H
21
22
23
#include "ns3/application.h"
24
#include "ns3/packet.h"
25
#include "ns3/uan-address.h"
26
#include "ns3/socket.h"
27
28
namespace ns3 {
29
30
/**
31
 * \ingroup uan
32
 * \brief a simple UDP application to be used in UAN networks
33
 * 
34
 * The Application uses the NS-3 IP stack, and UDP Sockets to send and received
35
 * data.
36
 * The user interacts with the application mainly through two functions:
37
 * Send () : Used to send the data in the buffer parameter to the
38
 * destination IPv4 address.
39
 * SetPacketReceivedCallback (): Used to set a receive callback where the raw 
40
 * packet payload, and the source IPv4 address will be passed as
41
 * parameters.
42
 */
43
44
class UanApplication : public Application
45
{
46
public:
47
48
  typedef Callback<void, Address, Buffer> PacketReceivedCallback;
49
50
  /**
51
   * \brief Get the type ID.
52
   * \return the object TypeId
53
   */
54
  static TypeId GetTypeId (void);
55
56
  /**
57
   * create a uan application
58
   */
59
  UanApplication ();
60
  virtual ~UanApplication ();
61
62
  /**
63
   * \brief Send a packet to the destination
64
   * \param dst the destination IPv4 address
65
   * \param dataBuffer the data to be sent
66
   */
67
  void Send (Address dst, const Buffer dataBuffer);
68
69
  /**
70
   * \brief Set a callback when a packet is received
71
   * \param callback the packet received callback
72
   */
73
  void SetPacketReceivedCallback (PacketReceivedCallback callback);
74
75
  /**
76
   * \brief Sets the UDP port number.
77
   * \param port The UDP port number
78
   */
79
  void SetPort (uint16_t port);
80
  
81
  /**
82
   * \brief Gets the UDP port number.
83
   * \return The UDP port number
84
   */
85
  uint16_t GetPort () const;
86
87
private:
88
89
  // inherited from Application base class.
90
  virtual void StartApplication (void);
91
  virtual void StopApplication (void);
92
  virtual void DoDispose (void);
93
  /**
94
   * \brief Return the application ID in the node.
95
   * \returns the application id
96
   */
97
  uint32_t GetApplicationId (void) const;
98
  /**
99
   * \brief Receive a packet
100
   * \param socket the receiving socket
101
   *
102
   * This function is called by lower layers through a callback.
103
   */
104
  void Receive (Ptr<Socket> socket);
105
106
  Ptr<Socket> m_socket; //!< Associated socket
107
  uint16_t m_port;      //!< Port number
108
  PacketReceivedCallback m_packetReceivedCallback;
109
110
};
111
112
} // namespace ns3
113
114
#endif /* UAN_APPLICATION_H */
(-)a/src/uan/model/uan-header-common.cc (-11 / +11 lines)
 Lines 29-39    Link Here 
29
{
29
{
30
}
30
}
31
31
32
UanHeaderCommon::UanHeaderCommon (const UanAddress src, const UanAddress dest, uint8_t type)
32
UanHeaderCommon::UanHeaderCommon (const UanAddress src, const UanAddress dest, uint16_t packetType)
33
  : Header (),
33
  : Header (),
34
    m_dest (dest),
34
    m_dest (dest),
35
    m_src (src),
35
    m_src (src),
36
    m_type (type)
36
    m_packetType (packetType)
37
{
37
{
38
38
39
}
39
}
 Lines 71-79    Link Here 
71
}
71
}
72
72
73
void
73
void
74
UanHeaderCommon::SetType (uint8_t type)
74
UanHeaderCommon::SetPacketType (uint16_t packetType)
75
{
75
{
76
  m_type = type;
76
  m_packetType = packetType;
77
}
77
}
78
78
79
UanAddress
79
UanAddress
 Lines 86-95    Link Here 
86
{
86
{
87
  return m_src;
87
  return m_src;
88
}
88
}
89
uint8_t
89
uint16_t
90
UanHeaderCommon::GetType (void) const
90
UanHeaderCommon::GetPacketType (void) const
91
{
91
{
92
  return m_type;
92
  return m_packetType;
93
}
93
}
94
94
95
// Inherrited methods
95
// Inherrited methods
 Lines 97-103    Link Here 
97
uint32_t
97
uint32_t
98
UanHeaderCommon::GetSerializedSize (void) const
98
UanHeaderCommon::GetSerializedSize (void) const
99
{
99
{
100
  return 1 + 1 + 1;
100
  return 1 + 1 + 2;
101
}
101
}
102
102
103
void
103
void
 Lines 105-111    Link Here 
105
{
105
{
106
  start.WriteU8 (m_src.GetAsInt ());
106
  start.WriteU8 (m_src.GetAsInt ());
107
  start.WriteU8 (m_dest.GetAsInt ());
107
  start.WriteU8 (m_dest.GetAsInt ());
108
  start.WriteU8 (m_type);
108
  start.WriteU16 (m_packetType);
109
}
109
}
110
110
111
uint32_t
111
uint32_t
 Lines 115-121    Link Here 
115
115
116
  m_src = UanAddress (rbuf.ReadU8 ());
116
  m_src = UanAddress (rbuf.ReadU8 ());
117
  m_dest = UanAddress (rbuf.ReadU8 ());
117
  m_dest = UanAddress (rbuf.ReadU8 ());
118
  m_type = rbuf.ReadU8 ();
118
  m_packetType = rbuf.ReadU16 ();
119
119
120
  return rbuf.GetDistanceFrom (start);
120
  return rbuf.GetDistanceFrom (start);
121
}
121
}
 Lines 123-129    Link Here 
123
void
123
void
124
UanHeaderCommon::Print (std::ostream &os) const
124
UanHeaderCommon::Print (std::ostream &os) const
125
{
125
{
126
  os << "UAN src=" << m_src << " dest=" << m_dest << " type=" << (uint32_t) m_type;
126
  os << "UAN src=" << m_src << " dest=" << m_dest << " type=" << (uint32_t) m_packetType;
127
}
127
}
128
128
129
129
(-)a/src/uan/model/uan-header-common.h (-11 / +12 lines)
 Lines 34-42    Link Here 
34
 * Common packet header fields.
34
 * Common packet header fields.
35
 *
35
 *
36
 * Includes 1 byte src address, 1 byte dest address,
36
 * Includes 1 byte src address, 1 byte dest address,
37
 * and a 1 byte type field.
37
 * and a 2 bytes packetType field.
38
 *
38
 *
39
 * The type field is protocol specific; see the relevant MAC protocol.
39
 * The packetType field is protocol specific; see the relevant MAC protocol.
40
 */
40
 */
41
class UanHeaderCommon : public Header
41
class UanHeaderCommon : public Header
42
{
42
{
 Lines 49-57    Link Here 
49
   *
49
   *
50
   * \param src Source address defined in header.
50
   * \param src Source address defined in header.
51
   * \param dest Destination address defined in header.
51
   * \param dest Destination address defined in header.
52
   * \param type Header type.
52
   * \param packetType The type of the packet.
53
   */
53
   */
54
  UanHeaderCommon (const UanAddress src, const UanAddress dest, uint8_t type);
54
  UanHeaderCommon (const UanAddress src, const UanAddress dest, uint16_t packetType);
55
  /** Destructor */
55
  /** Destructor */
56
  virtual ~UanHeaderCommon ();
56
  virtual ~UanHeaderCommon ();
57
57
 Lines 74-85    Link Here 
74
   */
74
   */
75
  void SetSrc (UanAddress src);
75
  void SetSrc (UanAddress src);
76
  /**
76
  /**
77
   * Set the header type.
77
   * Set the type of packet.
78
   *
78
   *
79
   * Use of this value is protocol specific.
79
   * Use of this value is protocol specific.
80
   * \param type The type value.
80
   * \param packetType The type of packet.
81
   */
81
   */
82
  void SetType (uint8_t type);
82
  void SetPacketType (uint16_t packetType);
83
83
84
  /**
84
  /**
85
   * Get the destination address.
85
   * Get the destination address.
 Lines 94-104    Link Here 
94
   */
94
   */
95
  UanAddress GetSrc (void) const;
95
  UanAddress GetSrc (void) const;
96
  /**
96
  /**
97
   * Get the header type value.
97
   * Get the type of packet.
98
   *
98
   *
99
   * \return value of type field.
99
   * Use of this value is protocol specific.
100
   * \return The type of packet.
100
   */
101
   */
101
  uint8_t GetType (void) const;
102
  uint16_t GetPacketType (void) const;
102
103
103
104
104
  // Inherited methods
105
  // Inherited methods
 Lines 110-116    Link Here 
110
private:
111
private:
111
  UanAddress m_dest;  //!< The destination address.
112
  UanAddress m_dest;  //!< The destination address.
112
  UanAddress m_src;   //!< The source address.
113
  UanAddress m_src;   //!< The source address.
113
  uint8_t m_type;     //!< The type field.
114
  uint16_t m_packetType;     //!< The type field.
114
115
115
};  // class UanHeaderCommon
116
};  // class UanHeaderCommon
116
117
(-)a/src/uan/model/uan-mac-aloha.cc (-7 / +19 lines)
 Lines 36-42    Link Here 
36
36
37
UanMacAloha::UanMacAloha ()
37
UanMacAloha::UanMacAloha ()
38
  : UanMac (),
38
  : UanMac (),
39
    m_cleared (false)
39
    m_cleared (false),
40
    m_txMode (UanTxMode::PSK)
40
{
41
{
41
}
42
}
42
43
 Lines 89-95    Link Here 
89
  m_address=addr;
90
  m_address=addr;
90
}
91
}
91
bool
92
bool
92
UanMacAloha::Enqueue (Ptr<Packet> packet, const Address &dest, uint16_t protocolNumber)
93
UanMacAloha::Enqueue (Ptr<Packet> packet, uint16_t packetType, const Address &dest)
93
{
94
{
94
  NS_LOG_DEBUG ("" << Simulator::Now ().GetSeconds () << " MAC " << UanAddress::ConvertFrom (GetAddress ()) << " Queueing packet for " << UanAddress::ConvertFrom (dest));
95
  NS_LOG_DEBUG ("" << Simulator::Now ().GetSeconds () << " MAC " << UanAddress::ConvertFrom (GetAddress ()) << " Queueing packet for " << UanAddress::ConvertFrom (dest));
95
96
 Lines 101-110    Link Here 
101
      UanHeaderCommon header;
102
      UanHeaderCommon header;
102
      header.SetSrc (src);
103
      header.SetSrc (src);
103
      header.SetDest (udest);
104
      header.SetDest (udest);
104
      header.SetType (0);
105
      header.SetPacketType (packetType);
105
106
      packet->AddHeader (header);
106
      packet->AddHeader (header);
107
      m_phy->SendPacket (packet, protocolNumber);
107
      m_phy->SendPacket (packet, GetTxMode ());
108
      return true;
108
      return true;
109
    }
109
    }
110
  else
110
  else
 Lines 112-118    Link Here 
112
}
112
}
113
113
114
void
114
void
115
UanMacAloha::SetForwardUpCb (Callback<void, Ptr<Packet>, const UanAddress& > cb)
115
UanMacAloha::SetForwardUpCb (Callback<void, Ptr<Packet>, uint16_t, const UanAddress&> cb)
116
{
116
{
117
  m_forUpCb = cb;
117
  m_forUpCb = cb;
118
}
118
}
 Lines 133-139    Link Here 
133
133
134
  if (header.GetDest () == GetAddress () || header.GetDest () == UanAddress::GetBroadcast ())
134
  if (header.GetDest () == GetAddress () || header.GetDest () == UanAddress::GetBroadcast ())
135
    {
135
    {
136
      m_forUpCb (pkt, header.GetSrc ());
136
      m_forUpCb (pkt, header.GetPacketType (), header.GetSrc ());
137
    }
137
    }
138
138
139
}
139
}
 Lines 158-161    Link Here 
158
  return 0;
158
  return 0;
159
}
159
}
160
160
161
void
162
UanMacAloha::SetTxMode (UanTxMode::ModulationType txMode)
163
{
164
  m_txMode = txMode;
161
}
165
}
166
167
UanTxMode::ModulationType
168
UanMacAloha::GetTxMode ()
169
{
170
  return m_txMode;
171
}
172
173
}
(-)a/src/uan/model/uan-mac-aloha.h (-3 / +9 lines)
 Lines 23-28    Link Here 
23
23
24
#include "uan-mac.h"
24
#include "uan-mac.h"
25
#include "uan-address.h"
25
#include "uan-address.h"
26
#include "uan-tx-mode.h"
26
27
27
namespace ns3
28
namespace ns3
28
{
29
{
 Lines 57-68    Link Here 
57
  // Inherited methods
58
  // Inherited methods
58
  Address GetAddress (void);
59
  Address GetAddress (void);
59
  virtual void SetAddress (UanAddress addr);
60
  virtual void SetAddress (UanAddress addr);
60
  virtual bool Enqueue (Ptr<Packet> pkt, const Address &dest, uint16_t protocolNumber);
61
  virtual bool Enqueue (Ptr<Packet> pkt, uint16_t packetType, const Address &dest);
61
  virtual void SetForwardUpCb (Callback<void, Ptr<Packet>, const UanAddress& > cb);
62
  virtual void SetForwardUpCb (Callback<void, Ptr<Packet>, uint16_t, const UanAddress&> cb);
62
  virtual void AttachPhy (Ptr<UanPhy> phy);
63
  virtual void AttachPhy (Ptr<UanPhy> phy);
63
  virtual Address GetBroadcast (void) const;
64
  virtual Address GetBroadcast (void) const;
64
  virtual void Clear (void);
65
  virtual void Clear (void);
65
  int64_t AssignStreams (int64_t stream);
66
  int64_t AssignStreams (int64_t stream);
67
  UanTxMode::ModulationType GetTxMode ();
68
  void SetTxMode (UanTxMode::ModulationType txMode);
66
69
67
private:
70
private:
68
  /** The MAC address. */
71
  /** The MAC address. */
 Lines 70-76    Link Here 
70
  /** PHY layer attached to this MAC. */
73
  /** PHY layer attached to this MAC. */
71
  Ptr<UanPhy> m_phy;
74
  Ptr<UanPhy> m_phy;
72
  /** Forwarding up callback. */
75
  /** Forwarding up callback. */
73
  Callback<void, Ptr<Packet>, const UanAddress& > m_forUpCb;
76
  Callback<void, Ptr<Packet>, uint16_t, const UanAddress& > m_forUpCb;
74
  /** Flag when we've been cleared. */
77
  /** Flag when we've been cleared. */
75
  bool m_cleared;
78
  bool m_cleared;
76
79
 Lines 92-97    Link Here 
92
  void RxPacketError (Ptr<Packet> pkt, double sinr);
95
  void RxPacketError (Ptr<Packet> pkt, double sinr);
93
protected:
96
protected:
94
  virtual void DoDispose ();
97
  virtual void DoDispose ();
98
  
99
private:
100
  UanTxMode::ModulationType m_txMode;
95
101
96
};  // class UanMacAloha
102
};  // class UanMacAloha
97
103
(-)a/src/uan/model/uan-mac-cw.cc (-8 / +21 lines)
 Lines 38-44    Link Here 
38
    m_phy (0),
38
    m_phy (0),
39
    m_pktTx (0),
39
    m_pktTx (0),
40
    m_state (IDLE),
40
    m_state (IDLE),
41
    m_cleared (false)
41
    m_cleared (false),
42
    m_txMode (UanTxMode::PSK)
42
43
43
{
44
{
44
  m_rv = CreateObject<UniformRandomVariable> ();
45
  m_rv = CreateObject<UniformRandomVariable> ();
 Lines 120-126    Link Here 
120
}
121
}
121
122
122
bool
123
bool
123
UanMacCw::Enqueue (Ptr<Packet> packet, const Address &dest, uint16_t protocolNumber)
124
UanMacCw::Enqueue (Ptr<Packet> packet, uint16_t packetType, const Address &dest)
124
{
125
{
125
126
126
  switch (m_state)
127
  switch (m_state)
 Lines 150-164    Link Here 
150
        UanHeaderCommon header;
151
        UanHeaderCommon header;
151
        header.SetDest (UanAddress::ConvertFrom (dest));
152
        header.SetDest (UanAddress::ConvertFrom (dest));
152
        header.SetSrc (m_address);
153
        header.SetSrc (m_address);
153
        header.SetType (0);
154
        header.SetPacketType (packetType);
154
        packet->AddHeader (header);
155
        packet->AddHeader (header);
155
156
156
        m_enqueueLogger (packet, protocolNumber);
157
        m_enqueueLogger (packet, GetTxMode ());
157
158
158
        if (m_phy->IsStateBusy ())
159
        if (m_phy->IsStateBusy ())
159
          {
160
          {
160
            m_pktTx = packet;
161
            m_pktTx = packet;
161
            m_pktTxProt = protocolNumber;
162
            m_pktTxProt = GetTxMode ();
162
            m_state = CCABUSY;
163
            m_state = CCABUSY;
163
            uint32_t cw = (uint32_t) m_rv->GetValue (0,m_cw);
164
            uint32_t cw = (uint32_t) m_rv->GetValue (0,m_cw);
164
            m_savedDelayS = Seconds ((double)(cw) * m_slotTime.GetSeconds ());
165
            m_savedDelayS = Seconds ((double)(cw) * m_slotTime.GetSeconds ());
 Lines 172-178    Link Here 
172
            NS_LOG_DEBUG ("Time " << Simulator::Now ().GetSeconds () << ": Addr " << GetAddress () << ": Enqueuing new packet while idle (sending)");
173
            NS_LOG_DEBUG ("Time " << Simulator::Now ().GetSeconds () << ": Addr " << GetAddress () << ": Enqueuing new packet while idle (sending)");
173
            NS_ASSERT (m_phy->GetTransducer ()->GetArrivalList ().size () == 0 && !m_phy->IsStateTx ());
174
            NS_ASSERT (m_phy->GetTransducer ()->GetArrivalList ().size () == 0 && !m_phy->IsStateTx ());
174
            m_state = TX;
175
            m_state = TX;
175
            m_phy->SendPacket (packet,protocolNumber);
176
            m_phy->SendPacket (packet,GetTxMode ());
176
177
177
          }
178
          }
178
        break;
179
        break;
 Lines 188-194    Link Here 
188
}
189
}
189
190
190
void
191
void
191
UanMacCw::SetForwardUpCb (Callback<void, Ptr<Packet>, const UanAddress&> cb)
192
UanMacCw::SetForwardUpCb (Callback<void, Ptr<Packet>, uint16_t, const UanAddress&> cb)
192
{
193
{
193
  m_forwardUpCb = cb;
194
  m_forwardUpCb = cb;
194
}
195
}
 Lines 348-354    Link Here 
348
349
349
  if (header.GetDest () == m_address || header.GetDest () == UanAddress::GetBroadcast ())
350
  if (header.GetDest () == m_address || header.GetDest () == UanAddress::GetBroadcast ())
350
    {
351
    {
351
      m_forwardUpCb (packet, header.GetSrc ());
352
      m_forwardUpCb (packet, header.GetPacketType (), header.GetSrc ());
352
    }
353
    }
353
}
354
}
354
void
355
void
 Lines 395-398    Link Here 
395
  m_savedDelayS = Seconds (0);
396
  m_savedDelayS = Seconds (0);
396
}
397
}
397
398
399
void
400
UanMacCw::SetTxMode (UanTxMode::ModulationType txMode)
401
{
402
  m_txMode = txMode;
403
}
404
405
UanTxMode::ModulationType
406
UanMacCw::GetTxMode ()
407
{
408
  return m_txMode;
409
}
410
398
} // namespace ns3
411
} // namespace ns3
(-)a/src/uan/model/uan-mac-cw.h (-3 / +9 lines)
 Lines 85-92    Link Here 
85
  // Inherited methods from UanMac
85
  // Inherited methods from UanMac
86
  virtual Address GetAddress ();
86
  virtual Address GetAddress ();
87
  virtual void SetAddress (UanAddress addr);
87
  virtual void SetAddress (UanAddress addr);
88
  virtual bool Enqueue (Ptr<Packet> pkt, const Address &dest, uint16_t protocolNumber);
88
  virtual bool Enqueue (Ptr<Packet> pkt, uint16_t packetType, const Address &dest);
89
  virtual void SetForwardUpCb (Callback<void, Ptr<Packet>, const UanAddress&> cb);
89
  virtual void SetForwardUpCb (Callback<void, Ptr<Packet>, uint16_t, const UanAddress&> cb);
90
  virtual void AttachPhy (Ptr<UanPhy> phy);
90
  virtual void AttachPhy (Ptr<UanPhy> phy);
91
  virtual Address GetBroadcast (void) const;
91
  virtual Address GetBroadcast (void) const;
92
  virtual void Clear (void);
92
  virtual void Clear (void);
 Lines 99-104    Link Here 
99
  virtual void NotifyCcaStart (void);
99
  virtual void NotifyCcaStart (void);
100
  virtual void NotifyCcaEnd (void);
100
  virtual void NotifyCcaEnd (void);
101
  virtual void NotifyTxStart (Time duration);
101
  virtual void NotifyTxStart (Time duration);
102
  
103
  UanTxMode::ModulationType GetTxMode ();
104
  void SetTxMode (UanTxMode::ModulationType txMode);
102
105
103
  /**
106
  /**
104
   *  TracedCallback signature for enqueue/dequeue of a packet.
107
   *  TracedCallback signature for enqueue/dequeue of a packet.
 Lines 119-125    Link Here 
119
  } State;
122
  } State;
120
123
121
  /** Forwarding up callback. */
124
  /** Forwarding up callback. */
122
  Callback <void, Ptr<Packet>, const UanAddress& > m_forwardUpCb;
125
  Callback <void, Ptr<Packet>, uint16_t, const UanAddress&> m_forwardUpCb;
123
  /** The MAC address. */
126
  /** The MAC address. */
124
  UanAddress m_address;
127
  UanAddress m_address;
125
  /** PHY layer attached to this MAC. */
128
  /** PHY layer attached to this MAC. */
 Lines 183-188    Link Here 
183
186
184
protected:
187
protected:
185
  virtual void DoDispose ();
188
  virtual void DoDispose ();
189
  
190
private:
191
  UanTxMode::ModulationType m_txMode;
186
192
187
};  // class UanMacCw
193
};  // class UanMacCw
188
194
(-)a/src/uan/model/uan-mac-rc-gw.cc (-7 / +7 lines)
 Lines 183-196    Link Here 
183
}
183
}
184
184
185
bool
185
bool
186
UanMacRcGw::Enqueue (Ptr<Packet> packet, const Address &dest, uint16_t protocolNumber)
186
UanMacRcGw::Enqueue (Ptr<Packet> packet, uint16_t packetType, const Address &dest)
187
{
187
{
188
  NS_LOG_WARN ("RCMAC Gateway transmission to acoustic nodes is not yet implemented");
188
  NS_LOG_WARN ("RCMAC Gateway transmission to acoustic nodes is not yet implemented");
189
  return false;
189
  return false;
190
}
190
}
191
191
192
void
192
void
193
UanMacRcGw::SetForwardUpCb (Callback<void, Ptr<Packet>, const UanAddress&> cb)
193
UanMacRcGw::SetForwardUpCb (Callback<void, Ptr<Packet>, uint16_t, const UanAddress&> cb)
194
{
194
{
195
  m_forwardUpCb = cb;
195
  m_forwardUpCb = cb;
196
}
196
}
 Lines 231-237    Link Here 
231
231
232
  pkt->RemoveHeader (ch);
232
  pkt->RemoveHeader (ch);
233
233
234
  switch (ch.GetType ())
234
  switch (ch.GetPacketType ())
235
    {
235
    {
236
    case UanMacRc::TYPE_DATA:
236
    case UanMacRc::TYPE_DATA:
237
      {
237
      {
 Lines 247-253    Link Here 
247
            NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " GW Received data packet from " << ch.GetSrc () << " length = " << pkt->GetSize ());
247
            NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " GW Received data packet from " << ch.GetSrc () << " length = " << pkt->GetSize ());
248
            m_ackData[ch.GetSrc ()].rxFrames.insert (dh.GetFrameNo ());
248
            m_ackData[ch.GetSrc ()].rxFrames.insert (dh.GetFrameNo ());
249
          }
249
          }
250
        m_forwardUpCb (pkt, ch.GetSrc ());
250
        m_forwardUpCb (pkt, ch.GetPacketType (), ch.GetSrc ());
251
      }
251
      }
252
      break;
252
      break;
253
    case UanMacRc::TYPE_GWPING:
253
    case UanMacRc::TYPE_GWPING:
 Lines 447-453    Link Here 
447
  UanHeaderCommon ch;
447
  UanHeaderCommon ch;
448
  ch.SetDest (UanAddress::GetBroadcast ());
448
  ch.SetDest (UanAddress::GetBroadcast ());
449
  ch.SetSrc (m_address);
449
  ch.SetSrc (m_address);
450
  ch.SetType (UanMacRc::TYPE_CTS);
450
  ch.SetPacketType (UanMacRc::TYPE_CTS);
451
  cts->AddHeader (ctsg);
451
  cts->AddHeader (ctsg);
452
  cts->AddHeader (ch);
452
  cts->AddHeader (ch);
453
  SendPacket (cts, m_currentRateNum);
453
  SendPacket (cts, m_currentRateNum);
 Lines 492-498    Link Here 
492
      UanHeaderCommon ch;
492
      UanHeaderCommon ch;
493
      ch.SetDest (dest);
493
      ch.SetDest (dest);
494
      ch.SetSrc (m_address);
494
      ch.SetSrc (m_address);
495
      ch.SetType (UanMacRc::TYPE_ACK);
495
      ch.SetPacketType (UanMacRc::TYPE_ACK);
496
      UanHeaderRcAck ah;
496
      UanHeaderRcAck ah;
497
      ah.SetFrameNo (data.frameNo);
497
      ah.SetFrameNo (data.frameNo);
498
      std::list<uint32_t>::iterator nit = toNack.begin ();
498
      std::list<uint32_t>::iterator nit = toNack.begin ();
 Lines 517-523    Link Here 
517
  UanHeaderCommon ch;
517
  UanHeaderCommon ch;
518
  pkt->PeekHeader (ch);
518
  pkt->PeekHeader (ch);
519
  std::string type;
519
  std::string type;
520
  switch (ch.GetType ())
520
  switch (ch.GetPacketType ())
521
    {
521
    {
522
    case UanMacRc::TYPE_DATA:
522
    case UanMacRc::TYPE_DATA:
523
      type = "DATA";
523
      type = "DATA";
(-)a/src/uan/model/uan-mac-rc-gw.h (-3 / +3 lines)
 Lines 69-76    Link Here 
69
  // Inherited methods
69
  // Inherited methods
70
  virtual Address GetAddress (void);
70
  virtual Address GetAddress (void);
71
  virtual void SetAddress (UanAddress addr);
71
  virtual void SetAddress (UanAddress addr);
72
  virtual bool Enqueue (Ptr<Packet> pkt, const Address &dest, uint16_t protocolNumber);
72
  virtual bool Enqueue (Ptr<Packet> pkt, uint16_t packetType, const Address &dest);
73
  virtual void SetForwardUpCb (Callback<void, Ptr<Packet>, const UanAddress&> cb);
73
  virtual void SetForwardUpCb (Callback<void, Ptr<Packet>, uint16_t, const UanAddress&> cb);
74
  virtual void AttachPhy (Ptr<UanPhy> phy);
74
  virtual void AttachPhy (Ptr<UanPhy> phy);
75
  virtual Address GetBroadcast (void) const;
75
  virtual Address GetBroadcast (void) const;
76
  virtual void Clear (void);
76
  virtual void Clear (void);
 Lines 126-132    Link Here 
126
    uint8_t expFrames;  //!< Expected number of frames.
126
    uint8_t expFrames;  //!< Expected number of frames.
127
  };
127
  };
128
  /** Forwarding up callback. */
128
  /** Forwarding up callback. */
129
  Callback<void, Ptr<Packet>, const UanAddress& > m_forwardUpCb;
129
  Callback<void, Ptr<Packet>, uint16_t, const UanAddress&> m_forwardUpCb;
130
  
130
  
131
  Ptr<UanPhy> m_phy;            //!< PHY layer attached to this MAC.
131
  Ptr<UanPhy> m_phy;            //!< PHY layer attached to this MAC.
132
  UanAddress m_address;         //!< The MAC address.
132
  UanAddress m_address;         //!< The MAC address.
(-)a/src/uan/model/uan-mac-rc.cc (-10 / +10 lines)
 Lines 288-298    Link Here 
288
}
288
}
289
289
290
bool
290
bool
291
UanMacRc::Enqueue (Ptr<Packet> packet, const Address &dest, uint16_t protocolNumber)
291
UanMacRc::Enqueue (Ptr<Packet> packet, uint16_t packetType, const Address &dest)
292
{
292
{
293
  if (protocolNumber > 0)
293
  if (packetType > 0)
294
    {
294
    {
295
      NS_LOG_WARN ("Warning: UanMacRc does not support multiple protocols.  protocolNumber argument to Enqueue is being ignored");
295
      NS_LOG_WARN ("Warning: UanMacRc does not support multiple protocols.  packetType argument to Enqueue is being ignored");
296
    }
296
    }
297
297
298
298
 Lines 324-330    Link Here 
324
}
324
}
325
325
326
void
326
void
327
UanMacRc::SetForwardUpCb (Callback<void, Ptr<Packet>, const UanAddress&> cb)
327
UanMacRc::SetForwardUpCb (Callback<void, Ptr<Packet>, uint16_t, const UanAddress&> cb)
328
{
328
{
329
  m_forwardUpCb = cb;
329
  m_forwardUpCb = cb;
330
}
330
}
 Lines 353-359    Link Here 
353
      m_rxLogger (pkt, mode);
353
      m_rxLogger (pkt, mode);
354
    }
354
    }
355
355
356
  switch (ch.GetType ())
356
  switch (ch.GetPacketType ())
357
    {
357
    {
358
    case TYPE_DATA:
358
    case TYPE_DATA:
359
359
 Lines 362-368    Link Here 
362
          NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Node " << m_address << " UanMacRc Receiving DATA packet from PHY");
362
          NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Node " << m_address << " UanMacRc Receiving DATA packet from PHY");
363
          UanHeaderRcData dh;
363
          UanHeaderRcData dh;
364
          pkt->RemoveHeader (dh);
364
          pkt->RemoveHeader (dh);
365
          m_forwardUpCb (pkt, ch.GetSrc ());
365
          m_forwardUpCb (pkt, ch.GetPacketType (), ch.GetSrc ());
366
        }
366
        }
367
      break;
367
      break;
368
    case TYPE_RTS:
368
    case TYPE_RTS:
 Lines 428-434    Link Here 
428
      ProcessAck (pkt);
428
      ProcessAck (pkt);
429
      break;
429
      break;
430
    default:
430
    default:
431
      NS_FATAL_ERROR ("Unknown packet type " << ch.GetType () << " received at node " << GetAddress ());
431
      NS_FATAL_ERROR ("Unknown packet type " << ch.GetPacketType () << " received at node " << GetAddress ());
432
    }
432
    }
433
433
434
}
434
}
 Lines 484-490    Link Here 
484
      pkt->AddHeader (dh);
484
      pkt->AddHeader (dh);
485
485
486
      UanHeaderCommon ch;
486
      UanHeaderCommon ch;
487
      ch.SetType (TYPE_DATA);
487
      ch.SetPacketType (TYPE_DATA);
488
      ch.SetDest (m_assocAddr);
488
      ch.SetDest (m_assocAddr);
489
      ch.SetSrc (m_address);
489
      ch.SetSrc (m_address);
490
490
 Lines 528-534    Link Here 
528
  UanHeaderCommon ch;
528
  UanHeaderCommon ch;
529
  pkt->PeekHeader (ch);
529
  pkt->PeekHeader (ch);
530
  std::string type;
530
  std::string type;
531
  switch (ch.GetType ())
531
  switch (ch.GetPacketType ())
532
    {
532
    {
533
    case TYPE_DATA:
533
    case TYPE_DATA:
534
      type = "DATA";
534
      type = "DATA";
 Lines 721-727    Link Here 
721
      Ptr<Packet> pkt = phyDual->GetPhy1PacketRx ();
721
      Ptr<Packet> pkt = phyDual->GetPhy1PacketRx ();
722
      UanHeaderCommon ch;
722
      UanHeaderCommon ch;
723
      pkt->PeekHeader (ch);
723
      pkt->PeekHeader (ch);
724
      if (ch.GetType () == TYPE_CTS || ch.GetType () == TYPE_ACK)
724
      if (ch.GetPacketType () == TYPE_CTS || ch.GetPacketType () == TYPE_ACK)
725
        {
725
        {
726
          phy1ok = false;
726
          phy1ok = false;
727
        }
727
        }
(-)a/src/uan/model/uan-mac-rc.h (-3 / +3 lines)
 Lines 185-192    Link Here 
185
  // Inherited methods
185
  // Inherited methods
186
  virtual Address GetAddress (void);
186
  virtual Address GetAddress (void);
187
  virtual void SetAddress (UanAddress addr);
187
  virtual void SetAddress (UanAddress addr);
188
  virtual bool Enqueue (Ptr<Packet> pkt, const Address &dest, uint16_t protocolNumber);
188
  virtual bool Enqueue (Ptr<Packet> pkt, uint16_t packetType, const Address &dest);
189
  virtual void SetForwardUpCb (Callback<void, Ptr<Packet>, const UanAddress&> cb);
189
  virtual void SetForwardUpCb (Callback<void, Ptr<Packet>, uint16_t, const UanAddress&> cb);
190
  virtual void AttachPhy (Ptr<UanPhy> phy);
190
  virtual void AttachPhy (Ptr<UanPhy> phy);
191
  virtual Address GetBroadcast (void) const;
191
  virtual Address GetBroadcast (void) const;
192
  virtual void Clear (void);
192
  virtual void Clear (void);
 Lines 241-247    Link Here 
241
  std::list<Reservation> m_resList;
241
  std::list<Reservation> m_resList;
242
242
243
  /** The callback to forward a packet up to higher layer. */
243
  /** The callback to forward a packet up to higher layer. */
244
  Callback<void, Ptr<Packet>, const UanAddress& > m_forwardUpCb;
244
  Callback<void, Ptr<Packet>, uint16_t, const UanAddress&> m_forwardUpCb;
245
245
246
  /** A packet was destined for and received at this MAC layer. */
246
  /** A packet was destined for and received at this MAC layer. */
247
  TracedCallback<Ptr<const Packet>, UanTxMode > m_rxLogger;
247
  TracedCallback<Ptr<const Packet>, UanTxMode > m_rxLogger;
(-)a/src/uan/model/uan-mac.h (-4 / +4 lines)
 Lines 72-82    Link Here 
72
   * Enqueue packet to be transmitted.
72
   * Enqueue packet to be transmitted.
73
   *
73
   *
74
   * \param pkt Packet to be transmitted.
74
   * \param pkt Packet to be transmitted.
75
   * \param packetType The type of the packet. Usage varies by MAC.
75
   * \param dest Destination address.
76
   * \param dest Destination address.
76
   * \param protocolNumber Protocol number.  Usage varies by MAC.
77
   * \return True if packet was successfully enqueued.
77
   * \return True if packet was successfully enqueued.
78
   */
78
   */
79
  virtual bool Enqueue (Ptr<Packet> pkt, const Address &dest, uint16_t protocolNumber) = 0;
79
  virtual bool Enqueue (Ptr<Packet> pkt, uint16_t packetType, const Address &dest) = 0;
80
  /**
80
  /**
81
   * Set the callback to forward packets up to higher layers.
81
   * Set the callback to forward packets up to higher layers.
82
   * 
82
   * 
 Lines 84-90    Link Here 
84
   * \pname{packet} The packet.
84
   * \pname{packet} The packet.
85
   * \pname{address} The source address.
85
   * \pname{address} The source address.
86
   */
86
   */
87
  virtual void SetForwardUpCb (Callback<void, Ptr<Packet>, const UanAddress&> cb) = 0;
87
  virtual void SetForwardUpCb (Callback<void, Ptr<Packet>, uint16_t, const UanAddress&> cb) = 0;
88
88
89
  /**
89
  /**
90
   * Attach PHY layer to this MAC.
90
   * Attach PHY layer to this MAC.
 Lines 124-130    Link Here 
124
   */
124
   */
125
  typedef void (* PacketModeTracedCallback)
125
  typedef void (* PacketModeTracedCallback)
126
    (Ptr<const Packet> packet, UanTxMode mode);
126
    (Ptr<const Packet> packet, UanTxMode mode);
127
127
  
128
};  // class UanMac
128
};  // class UanMac
129
129
130
} // namespace ns3
130
} // namespace ns3
(-)a/src/uan/model/uan-net-device.cc (-4 / +4 lines)
 Lines 291-297    Link Here 
291
bool
291
bool
292
UanNetDevice::Send (Ptr<Packet> packet, const Address &dest, uint16_t protocolNumber)
292
UanNetDevice::Send (Ptr<Packet> packet, const Address &dest, uint16_t protocolNumber)
293
{
293
{
294
  return m_mac->Enqueue (packet, dest, protocolNumber);
294
  return m_mac->Enqueue (packet, protocolNumber, dest);
295
}
295
}
296
296
297
bool
297
bool
 Lines 316-322    Link Here 
316
bool
316
bool
317
UanNetDevice::NeedsArp () const
317
UanNetDevice::NeedsArp () const
318
{
318
{
319
  return false;
319
  return true;
320
}
320
}
321
321
322
void
322
void
 Lines 326-336    Link Here 
326
}
326
}
327
327
328
void
328
void
329
UanNetDevice::ForwardUp (Ptr<Packet> pkt, const UanAddress &src)
329
UanNetDevice::ForwardUp (Ptr<Packet> pkt, uint16_t protocolNumber, const UanAddress &src)
330
{
330
{
331
  NS_LOG_DEBUG ("Forwarding packet up to application");
331
  NS_LOG_DEBUG ("Forwarding packet up to application");
332
  m_rxLogger (pkt, src);
332
  m_rxLogger (pkt, src);
333
  m_forwardUp (this, pkt, 0, src);
333
  m_forwardUp (this, pkt, protocolNumber, src);
334
334
335
}
335
}
336
336
(-)a/src/uan/model/uan-net-device.h (-1 / +2 lines)
 Lines 162-169    Link Here 
162
   *
162
   *
163
   * \param pkt The packet.
163
   * \param pkt The packet.
164
   * \param src The source address.
164
   * \param src The source address.
165
   * \param packetType The Type of the packet.
165
   */
166
   */
166
  virtual void ForwardUp (Ptr<Packet> pkt, const UanAddress &src);
167
  virtual void ForwardUp (Ptr<Packet> pkt, uint16_t packetType, const UanAddress &src);
167
  
168
  
168
  /** \return The channel attached to this device. */
169
  /** \return The channel attached to this device. */
169
  Ptr<UanChannel> DoGetChannel (void) const;
170
  Ptr<UanChannel> DoGetChannel (void) const;
(-)a/src/uan/model/uan-phy-dual.cc (-1 / +1 lines)
 Lines 97-103    Link Here 
97
97
98
          if (pkt)
98
          if (pkt)
99
            {
99
            {
100
              if (ch.GetType () == UanMacRc::TYPE_DATA)
100
              if (ch.GetPacketType () == UanMacRc::TYPE_DATA)
101
                {
101
                {
102
                  NS_LOG_DEBUG ("Adding interferer from " << ch2.GetSrc () << " against " << ch.GetSrc () << ": PktRxMode: "
102
                  NS_LOG_DEBUG ("Adding interferer from " << ch2.GetSrc () << " against " << ch.GetSrc () << ": PktRxMode: "
103
                                                          << mode.GetName () << " Int mode: " << it->GetTxMode ().GetName () << " Separation: "
103
                                                          << mode.GetName () << " Int mode: " << it->GetTxMode ().GetName () << " Separation: "
(-)a/src/uan/wscript (-1 / +5 lines)
 Lines 25-32    Link Here 
25
        'model/uan-phy.cc',
25
        'model/uan-phy.cc',
26
        'model/uan-noise-model.cc',
26
        'model/uan-noise-model.cc',
27
        'model/acoustic-modem-energy-model.cc',
27
        'model/acoustic-modem-energy-model.cc',
28
        'model/uan-application.cc',
28
        'helper/uan-helper.cc',
29
        'helper/uan-helper.cc',
29
        'helper/acoustic-modem-energy-model-helper.cc',
30
        'helper/acoustic-modem-energy-model-helper.cc',
31
        'helper/uan-application-helper.cc',
30
        ]
32
        ]
31
33
32
    module_test = bld.create_ns3_module_test_library('uan')
34
    module_test = bld.create_ns3_module_test_library('uan')
 Lines 58-66    Link Here 
58
        'model/uan-header-rc.h',
60
        'model/uan-header-rc.h',
59
        'model/uan-mac-rc.h',
61
        'model/uan-mac-rc.h',
60
        'model/acoustic-modem-energy-model.h',
62
        'model/acoustic-modem-energy-model.h',
63
        'model/uan-mac-rc-gw.h',
64
        'model/uan-application.h',
61
        'helper/uan-helper.h',
65
        'helper/uan-helper.h',
62
        'helper/acoustic-modem-energy-model-helper.h',
66
        'helper/acoustic-modem-energy-model-helper.h',
63
        'model/uan-mac-rc-gw.h',
67
        'helper/uan-application-helper.h',
64
        ]
68
        ]
65
69
66
    if (bld.env['ENABLE_EXAMPLES']):
70
    if (bld.env['ENABLE_EXAMPLES']):

Return to bug 2413