Merge with fdc9923859776bf7164504c2a3609f7231e588a3
authorJaume Nin
Tue, 02 Aug 2011 18:22:23 +0200
changeset 8358 25a3421e9d6e
parent 8357 7bb52f00c205 (diff)
parent 8356 fdc992385977 (current diff)
child 8359 38ad52341819
Merge with fdc9923859776bf7164504c2a3609f7231e588a3
src/lte/wscript
--- a/src/lte/examples/epc-gtpu-tunnel-example.cc	Fri Jul 29 18:26:35 2011 +0200
+++ b/src/lte/examples/epc-gtpu-tunnel-example.cc	Tue Aug 02 18:22:23 2011 +0200
@@ -18,25 +18,18 @@
  * Author: Jaume Nin <jaume.nin@cttc.cat>
  */
 
-#include <iostream>
-#include <fstream>
-#include <string>
-#include <cassert>
 
 #include "ns3/core-module.h"
 #include "ns3/network-module.h"
 #include "ns3/lte-module.h"
 #include "ns3/config-store.h"
-#include "ns3/core-module.h"
-#include "ns3/network-module.h"
 #include "ns3/internet-module.h"
 #include "ns3/csma-module.h"
 #include "ns3/csma-helper.h"
 #include "ns3/applications-module.h"
-#include "ns3/virtual-net-device.h"
 #include "ns3/ipv4-global-routing-helper.h"
-#include "ns3/epc-gtpu-tunnel.h"
-#include "ns3/inet-socket-address.h"
+#include "ns3/epc-helper.h"
+//#include "ns3/gtk-config-store.h"
 
 using namespace ns3;
 
@@ -48,70 +41,70 @@
 
   // Command line arguments
   CommandLine cmd;
-  cmd.Parse(argc, argv);
+  cmd.Parse (argc, argv);
 
   ConfigStore inputConfig;
-  inputConfig.ConfigureDefaults();
+  inputConfig.ConfigureDefaults ();
 
   // parse again so you can override default values from the command line
-  cmd.Parse(argc, argv);
+  cmd.Parse (argc, argv);
 
-  NS_LOG_INFO("Create nodes.");
+  NS_LOG_INFO ("Create nodes.");
   NodeContainer c;
-  c.Create(2);
+  c.Create (2);
 
   InternetStackHelper internet;
-  internet.Install(c);
+  internet.Install (c);
 
   // Create the channels first
-  NS_LOG_INFO("Create channels.");
+  NS_LOG_INFO ("Create channels.");
 
   CsmaHelper csma;
   csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
   csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560)));
-  NetDeviceContainer nc = csma.Install(c);
+  NetDeviceContainer nc = csma.Install (c);
+
+  NS_LOG_INFO ("Assign IP Addresses.");
+  Ipv4AddressHelper ipv4;
+  ipv4.SetBase ("10.0.1.0", "255.255.255.0");
+  Ipv4InterfaceContainer ic = ipv4.Assign (nc);
+  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
   AsciiTraceHelper ascii;
   csma.EnableAsciiAll (ascii.CreateFileStream ("epc-gtp.tr"));
   csma.EnablePcapAll ("epc-gtp");
 
-  NS_LOG_INFO("Assign IP Addresses.");
-  Ipv4AddressHelper ipv4;
-  ipv4.SetBase("10.0.1.0", "255.255.255.0");
-  Ipv4InterfaceContainer i = ipv4.Assign(nc);
-  Ipv4GlobalRoutingHelper::PopulateRoutingTables();
+  EpcHelper epcHelper;
 
-  GtpuTunnel t(c.Get(0), c.Get(1), i.GetAddress(0),i.GetAddress(1), Ipv4Address ("11.0.0.1"),Ipv4Address ("11.0.0.2"),
-      Ipv4Mask("255.255.255.0"), 15);
+  epcHelper.InstallGtpu (c.Get (0));
+  epcHelper.InstallGtpu (c.Get (1));
 
-  NS_LOG_INFO("Create Applications.");
+  epcHelper.CreateGtpuTunnel (c.Get (0), ic.GetAddress (0),  c.Get (1), ic.GetAddress (1));
+
+  NS_LOG_INFO ("Create Applications.");
   // Set up some default values for the simulation.
-  Config::SetDefault("ns3::OnOffApplication::PacketSize", UintegerValue(200));
-  Config::SetDefault("ns3::OnOffApplication::OnTime", RandomVariableValue(ConstantVariable(1)));
-  Config::SetDefault("ns3::OnOffApplication::OffTime", RandomVariableValue(ConstantVariable(0)));
-  Config::SetDefault("ns3::OnOffApplication::DataRate", StringValue ("2kbps"));
-  OnOffHelper onoffAB = OnOffHelper ("ns3::Ipv4RawSocketFactory", InetSocketAddress(Ipv4Address ("11.0.0.2")));
-  OnOffHelper onoffBA = OnOffHelper ("ns3::Ipv4RawSocketFactory", InetSocketAddress(Ipv4Address ("11.0.0.1")));
-
+  Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (200));
+  Config::SetDefault ("ns3::OnOffApplication::OnTime", RandomVariableValue (ConstantVariable (1)));
+  Config::SetDefault ("ns3::OnOffApplication::OffTime", RandomVariableValue (ConstantVariable (0)));
+  Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("2kbps"));
+  OnOffHelper onoffAB = OnOffHelper ("ns3::Ipv4RawSocketFactory", InetSocketAddress (Ipv4Address ("100.0.0.2")));
+  OnOffHelper onoffBA = OnOffHelper ("ns3::Ipv4RawSocketFactory", InetSocketAddress (Ipv4Address ("100.0.0.1")));
+  PacketSinkHelper sinkA ("ns3::Ipv4RawSocketFactory", InetSocketAddress (Ipv4Address ("100.0.0.1")));
+  PacketSinkHelper sinkB ("ns3::Ipv4RawSocketFactory", InetSocketAddress (Ipv4Address ("100.0.0.2")));
 
-  ApplicationContainer apps = onoffAB.Install(c.Get(0));
-  apps.Start(Seconds(1.0));
-  apps.Stop (Seconds (10.0));
-  apps = onoffBA.Install(c.Get(1));
-  apps.Start(Seconds(1.0));
-  apps.Stop (Seconds (10.0));
+  ApplicationContainer apps = onoffAB.Install (c.Get (0));
+  apps.Add (onoffBA.Install (c.Get (1)));
+  apps.Add (sinkA.Install (c.Get (0)));
+  apps.Add (sinkB.Install (c.Get (1)));
 
-  // Create a packet sink to receive these packets
-  PacketSinkHelper sinkA("ns3::Ipv4RawSocketFactory", InetSocketAddress(Ipv4Address ("11.0.0.2")));
-  PacketSinkHelper sinkB("ns3::Ipv4RawSocketFactory", InetSocketAddress(Ipv4Address ("11.0.0.2")));
-  apps = sinkA.Install(c.Get(0));
-  apps.Start(Seconds(1.0));
-  apps.Stop (Seconds (10.0));
-  apps = sinkB.Install(c.Get(1));
-  apps.Start(Seconds(1.0));
+  apps.Start (Seconds (1.0));
   apps.Stop (Seconds (10.0));
 
   NS_LOG_INFO ("Run Simulation.");
   Simulator::Run ();
+
+  /*GtkConfigStore config;
+  config.ConfigureAttributes ();*/
+
   Simulator::Destroy ();
   NS_LOG_INFO ("Done.");
 
--- a/src/lte/helper/epc-helper.cc	Fri Jul 29 18:26:35 2011 +0200
+++ b/src/lte/helper/epc-helper.cc	Tue Aug 02 18:22:23 2011 +0200
@@ -20,7 +20,9 @@
 
 #include <ns3/epc-helper.h>
 #include <ns3/log.h>
-
+#include "ns3/inet-socket-address.h"
+#include "ns3/mac48-address.h"
+#include "ns3/epc-gtpu-tunnel-endpoint.h"
 
 
 namespace ns3 {
@@ -29,9 +31,11 @@
 
 NS_OBJECT_ENSURE_REGISTERED (EpcHelper);
 
-EpcHelper::EpcHelper ()
+EpcHelper::EpcHelper () : m_udpPort (2152)
 {
   NS_LOG_FUNCTION (this);
+  m_mask = "255.255.255.0";
+  m_ipv4.SetBase ( "100.0.0.0", m_mask);
 }
 
 EpcHelper::~EpcHelper ()
@@ -49,5 +53,39 @@
   return tid;
 }
 
+void
+EpcHelper::InstallGtpu (Ptr<Node> n)
+{
+  InstallGtpu (n, m_ipv4.NewAddress ());
+}
+
+void
+EpcHelper::InstallGtpu (Ptr<Node> n, Ipv4Address addr)
+{
+  NS_LOG_FUNCTION (this);
+  // UDP socket creation and configuration
+  Ptr<Socket> m_socket = Socket::CreateSocket (n, TypeId::LookupByName ("ns3::UdpSocketFactory"));
+  m_socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), m_udpPort));
+
+  // tap device creation and configuration
+  Ptr<VirtualNetDevice> m_tap = CreateObject<VirtualNetDevice> ();
+  m_tap->SetAddress (Mac48Address::Allocate ());
+
+  n->AddDevice (m_tap);
+  Ptr<Ipv4> ipv4 = n->GetObject<Ipv4> ();
+  uint32_t i = ipv4->AddInterface (m_tap);
+  ipv4->AddAddress (i, Ipv4InterfaceAddress (addr, m_mask));
+  ipv4->SetUp (i);
+  Ptr<GtpuTunnelEndpoint> tunnel = CreateObject<GtpuTunnelEndpoint> (m_tap, m_socket);
+  m_gtpuEndpoint[n] = tunnel;
+}
+
+void
+EpcHelper::CreateGtpuTunnel (Ptr<Node> n, Ipv4Address nAddr, Ptr<Node> m, Ipv4Address mAddr)
+{
+  uint32_t teid = m_gtpuEndpoint[n]->CreateGtpuTunnel (mAddr);
+  m_gtpuEndpoint[m]->CreateGtpuTunnel (nAddr, teid);
+}
+
 
 } // namespace ns3
--- a/src/lte/helper/epc-helper.h	Fri Jul 29 18:26:35 2011 +0200
+++ b/src/lte/helper/epc-helper.h	Tue Aug 02 18:22:23 2011 +0200
@@ -22,9 +22,16 @@
 #define EPC_HELPER_H_
 
 #include "ns3/object.h"
+#include "ns3/ipv4-address.h"
+#include "ns3/ipv4-address-helper.h"
+#include <map>
+
+
 
 namespace ns3 {
 
+class Node;
+class GtpuTunnelEndpoint;
 /**
  * Helper class to handle the creation of the EPC entities and protocols
  */
@@ -46,9 +53,32 @@
    */
   static TypeId GetTypeId (void);
 
+  /**
+   * Creates and configure the necessary instances for the node to act as a
+   * GTP endpoint. The IP address of the new interfaces are within 100.0.0./24
+   * \param n node to install GTPv1-U
+   */
+  void InstallGtpu (Ptr<Node> n);
+  /**
+   * Creates and configure the necessary instances for the node to act as a
+   * GTP endpoint.
+   */
+  void InstallGtpu (Ptr<Node> n, Ipv4Address addr);
 
+  /**
+   * Creates a GTPv1-U tunnel between two nodes, both of them need to have GTPv1-U installed.
+   * \param n First tunnel endpoint node
+   * \param nAddr First tunnel endpoing address
+   * \param m Second tunnel endpoint node
+   * \param mAddr Second tunnel endpoing address
+   */
+  void CreateGtpuTunnel (Ptr<Node> n, Ipv4Address nAddr, Ptr<Node> m, Ipv4Address mAddr);
 
 private:
+  uint16_t m_udpPort;
+  Ipv4AddressHelper m_ipv4;
+  Ipv4Mask m_mask;
+  std::map <Ptr<Node>, Ptr<GtpuTunnelEndpoint> > m_gtpuEndpoint;
 
 };
 
--- a/src/lte/model/epc-gtpu-header.cc	Fri Jul 29 18:26:35 2011 +0200
+++ b/src/lte/model/epc-gtpu-header.cc	Tue Aug 02 18:22:23 2011 +0200
@@ -19,13 +19,12 @@
  */
 
 #include "epc-gtpu-header.h"
-#include <ns3/log.h>
+#include "ns3/log.h"
 #include "ns3/packet.h"
 
 NS_LOG_COMPONENT_DEFINE ("GtpuHeader");
 
-namespace ns3
-{
+namespace ns3 {
 
 /********************************************************
  *        GTP-U-v1 Header
@@ -37,15 +36,22 @@
 GtpuHeader::GetTypeId (void)
 {
   static TypeId tid =
-      TypeId("ns3::GtpuHeader") .SetParent<Header> () .AddConstructor<
-          GtpuHeader> ();
+    TypeId ("ns3::GtpuHeader").SetParent<Header> ().AddConstructor<
+      GtpuHeader> ();
   return tid;
 }
-GtpuHeader::GtpuHeader () :
-  m_version(1), m_protocolType(true), m_extensionHeaderFlag(false),
-      m_sequenceNumberFlag(true), m_nPduNumberFlag(true), m_messageType(255),
-      m_length(0), m_teid(0), m_sequenceNumber(0), m_nPduNumber(0),
-      m_nextExtensionType(0)
+GtpuHeader::GtpuHeader ()
+  : m_version (1),
+    m_protocolType (true),
+    m_extensionHeaderFlag (false),
+    m_sequenceNumberFlag (true),
+    m_nPduNumberFlag (true),
+    m_messageType (255),
+    m_length (0),
+    m_teid (0),
+    m_sequenceNumber (0),
+    m_nPduNumber (0),
+    m_nextExtensionType (0)
 {
 
 }
@@ -57,7 +63,7 @@
 TypeId
 GtpuHeader::GetInstanceTypeId (void) const
 {
-  return GetTypeId();
+  return GetTypeId ();
 }
 
 uint32_t
@@ -71,8 +77,8 @@
   Buffer::Iterator i = start;
   uint8_t firstByte = m_version << 5 | m_protocolType << 4 | 0x1 << 3;
   firstByte |=  m_extensionHeaderFlag << 2 |  m_sequenceNumberFlag << 1 | m_nPduNumberFlag;
-  i.WriteU8(firstByte);
-  i.WriteU8(m_messageType);
+  i.WriteU8 (firstByte);
+  i.WriteU8 (m_messageType);
   i.WriteHtonU16 (m_length);
   i.WriteHtonU32 (m_teid);
   i.WriteHtonU16 (m_sequenceNumber);
@@ -92,10 +98,10 @@
   m_nPduNumberFlag = firstByte & 0x1;
   m_messageType = i.ReadU8 ();
   m_length = i.ReadNtohU16 ();
-  m_teid= i.ReadNtohU32 ();
-  m_sequenceNumber= i.ReadNtohU16 ();
-  m_nPduNumber= i.ReadU8 ();
-  m_nextExtensionType= i.ReadU8 ();
+  m_teid = i.ReadNtohU32 ();
+  m_sequenceNumber = i.ReadNtohU16 ();
+  m_nPduNumber = i.ReadU8 ();
+  m_nextExtensionType = i.ReadU8 ();
   return GetSerializedSize ();
 }
 void
@@ -104,22 +110,22 @@
   os << " version=" << (uint32_t) m_version << " [";
   if (m_protocolType)
     {
-     os << " PT ";
+      os << " PT ";
     }
   if (m_extensionHeaderFlag)
-      {
-       os << " E ";
-      }
+    {
+      os << " E ";
+    }
   if (m_sequenceNumberFlag)
-      {
-       os << " S ";
-      }
+    {
+      os << " S ";
+    }
   if (m_nPduNumberFlag)
-      {
-       os << " PN ";
-      }
+    {
+      os << " PN ";
+    }
   os << "], messageType=" << (uint32_t) m_messageType << ", length=" << (uint32_t) m_length;
-  os << ", teid=" << (uint32_t) m_teid<< ", sequenceNumber=" << (uint32_t) m_sequenceNumber;
+  os << ", teid=" << (uint32_t) m_teid << ", sequenceNumber=" << (uint32_t) m_sequenceNumber;
   os << ", nPduNumber=" << (uint32_t) m_nPduNumber << ", nextExtensionType=" << (uint32_t) m_nextExtensionType;
 }
 
@@ -257,19 +263,19 @@
 }
 
 bool
-GtpuHeader::operator ==(const GtpuHeader& b) const
+GtpuHeader::operator == (const GtpuHeader& b) const
 {
-  if (m_version == b.m_version &&
-      m_protocolType == b.m_protocolType &&
-      m_extensionHeaderFlag == b.m_extensionHeaderFlag &&
-      m_sequenceNumberFlag == b.m_sequenceNumberFlag &&
-      m_nPduNumberFlag == b.m_nPduNumberFlag  &&
-      m_messageType == b.m_messageType &&
-      m_length == b.m_length &&
-      m_teid == b.m_teid &&
-      m_sequenceNumber == b.m_sequenceNumber &&
-      m_nPduNumber == b.m_nPduNumber &&
-      m_nextExtensionType == b.m_nextExtensionType
+  if (m_version == b.m_version
+      && m_protocolType == b.m_protocolType
+      && m_extensionHeaderFlag == b.m_extensionHeaderFlag
+      && m_sequenceNumberFlag == b.m_sequenceNumberFlag
+      && m_nPduNumberFlag == b.m_nPduNumberFlag
+      && m_messageType == b.m_messageType
+      && m_length == b.m_length
+      && m_teid == b.m_teid
+      && m_sequenceNumber == b.m_sequenceNumber
+      && m_nPduNumber == b.m_nPduNumber
+      && m_nextExtensionType == b.m_nextExtensionType
       )
     {
       return true;
--- a/src/lte/model/epc-gtpu-header.h	Fri Jul 29 18:26:35 2011 +0200
+++ b/src/lte/model/epc-gtpu-header.h	Tue Aug 02 18:22:23 2011 +0200
@@ -22,15 +22,20 @@
 #ifndef EPS_GTPU_V1_H
 #define EPS_GTPU_V1_H
 
-#include "ns3/header.h"
-#include "ns3/ptr.h"
-#include "ns3/ipv4-header.h"
-#include <stdint.h>
+#include <ns3/ptr.h>
+#include <ns3/header.h>
+#include <ns3/ipv4-header.h>
 
 namespace ns3 {
 
 class Packet;
 
+
+/**
+ * \ingroup lte
+ *
+ * Implementation of the GTPv1-U Release 10 as per 3Gpp TS 29.281 document
+ */
 class GtpuHeader : public Header
 {
 public:
@@ -70,16 +75,74 @@
 
 
 private:
+  /**
+   * This field is used to determine the version of the GTPU-U protocol. The version number shall be set to 1.
+   */
   uint8_t m_version;   // really a 3 uint3_t
+
+  /**
+   * This bit is used as a protocol discriminator between GTP (when PT is '1') and GTP' (when
+   * PT is '0').
+   */
   bool m_protocolType;
+
+  /**
+   * This flag indicates the presence of a meaningful value of the Next Extension Header
+   * field. When it is set to '0', the Next Extension Header field either is not present
+   * or, if present, shall not be interpreted. When it is set to '1', the Next Extension
+   *  Header field is present, and shall be interpreted
+   */
   bool m_extensionHeaderFlag;
+
+  /**
+   * This flag indicates the presence of a meaningful value of the Sequence Number field.
+   * When it is set to '0', the Sequence Number field either is not present or, if present,
+   * shall not be interpreted. When it is set to '1', the Sequence Number field is present,
+   * and shall be interpreted
+   */
   bool m_sequenceNumberFlag;
+  /**
+   * This flag indicates the presence of a meaningful value of the N-PDU Number field.
+   * When it is set to '0', the N-PDU Number field either is not present, or, if present,
+   * shall not be interpreted. When it is set to '1', the N-PDU Number field is present,
+   * and shall be interpreted
+   */
   bool m_nPduNumberFlag;
+  /**
+   *  This field indicates the type of GTP-U message
+   */
   uint8_t m_messageType;
+  /**
+   *  This field indicates the length in octets of the payload, i.e. the rest of the packet
+   *  following the mandatory part of the GTP header (that is the first 8 octets).
+   *  The Sequence Number, the N-PDU Number or any Extension headers shall be considered
+   *  to be part of the payload, i.e. included in the length count
+   */
   uint16_t m_length;
+
+  /**
+   * This field unambiguously identifies a tunnel endpoint in the receiving GTP-U
+   * protocol entity. The receiving end side of a GTP tunnel locally assigns the
+   * TEID value the transmitting side has to use.
+   */
   uint32_t m_teid;
+  /**
+   * If Sequence Number field is used for G-PDUs (T-PDUs+headers), an increasing
+   * sequence number for T-PDUs is transmitted via GTP-U tunnels, when transmission
+   * order must be preserved
+   */
   uint16_t m_sequenceNumber;
+  /**
+   * This field is used at the Inter SGSN Routeing Area Update procedure and some
+   * inter-system handover procedures (e.g. between 2G and 3G radio access networks).
+   * This field is used to co-ordinate the data transmission for acknowledged mode
+   * of communication between the MS and the SGSN
+   */
   uint8_t m_nPduNumber;
+  /**
+   * This field defines the type of Extension Header that follows this field in
+   * the GTP-PDU
+   */
   uint8_t m_nextExtensionType;
 
 };
--- a/src/lte/model/epc-gtpu-l5-protocol.cc	Fri Jul 29 18:26:35 2011 +0200
+++ b/src/lte/model/epc-gtpu-l5-protocol.cc	Tue Aug 02 18:22:23 2011 +0200
@@ -18,9 +18,8 @@
  * Author: Jaume Nin <jnin@cttc.cat>
  */
 
+#include "ns3/log.h"
 #include "ns3/epc-gtpu-l5-protocol.h"
-#include <ns3/log.h>
-#include <ns3/uinteger.h>
 #include "ns3/epc-gtpu-header.h"
 
 NS_LOG_COMPONENT_DEFINE ("GtpuL5Protocol");
@@ -29,7 +28,7 @@
 
 NS_OBJECT_ENSURE_REGISTERED (GtpuL5Protocol);
 
-TypeId 
+TypeId
 GtpuL5Protocol::GetTypeId (void)
 {
   static TypeId tid = TypeId ("ns3::GtpuL5Protocol")
@@ -82,7 +81,7 @@
   GtpuHeader h;
   p->RemoveHeader (h);
   NS_LOG_DEBUG (this << h);
-  NS_ASSERT( h.GetTeid () == m_teid);
+  NS_ASSERT ( h.GetTeid () == m_teid);
 }
 
 }; // namespace ns3
--- a/src/lte/model/epc-gtpu-l5-protocol.h	Fri Jul 29 18:26:35 2011 +0200
+++ b/src/lte/model/epc-gtpu-l5-protocol.h	Tue Aug 02 18:22:23 2011 +0200
@@ -25,11 +25,13 @@
 #include <ns3/object.h>
 #include <ns3/packet.h>
 
-namespace ns3
-{
+namespace ns3 {
 
 /**
- * Implementation of the GTP-U v1 protocol
+ * \ingroup lte
+ *
+ * Implementation of the GTP-U v1 protocol. Basically, given a TEID, it adds and
+ * removes the GTPU header of the packets going in and out of the tunnel.
  */
 class GtpuL5Protocol : public Object
 {
@@ -40,14 +42,34 @@
   GtpuL5Protocol (uint32_t teid);
   virtual  ~GtpuL5Protocol ();
 
+  /**
+   * \brief Adds the GTPv1-U header to a packet
+   * \param p packet to add the header
+   * \return  packet with the header added
+   */
   Ptr<Packet> AddHeader (Ptr<Packet> p);
+  /**
+   * \brief Strips the GTPv1-U header of a packet and
+   * checks its coherence
+   * \param p packet to strip the header
+   */
   void  RemoveHeader (Ptr<Packet> p);
 
+  /**
+   * \brief Returns the Tunnel Endpoint IDentifier of the the GTPv1-U instance
+   * \return the TEID
+   */
   uint32_t GetTeid (void);
+  /**
+   * \brief Sets the Tunnel Endpoint IDentifier of the the GTPv1-U instance
+   * \param teid the TEID
+   */
   void  SetTeid (uint32_t teid);
 
 private:
-
+  /**
+   * Tunnel Endpoint IDentifier
+   */
   uint32_t m_teid;
 
 };
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lte/model/epc-gtpu-tunnel-endpoint.cc	Tue Aug 02 18:22:23 2011 +0200
@@ -0,0 +1,99 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Jaume Nin <jnin@cttc.cat>
+ */
+
+
+#include "epc-gtpu-tunnel-endpoint.h"
+#include "ns3/log.h"
+#include "ns3/mac48-address.h"
+#include "ns3/ipv4.h"
+#include "ns3/inet-socket-address.h"
+
+namespace ns3 {
+
+NS_LOG_COMPONENT_DEFINE ("GtpuTunnel");
+
+uint16_t GtpuTunnelEndpoint::m_teidCounter = 0;
+uint32_t GtpuTunnelEndpoint::m_indexCounter = 0;
+
+
+TypeId
+GtpuTunnelEndpoint::GetTypeId (void)
+{
+  static TypeId tid = TypeId ("ns3::GtpuTunnel")
+    .SetParent<Object> ();
+  return tid;
+}
+
+GtpuTunnelEndpoint::GtpuTunnelEndpoint (const Ptr<VirtualNetDevice> tap, const Ptr<Socket> s)
+  : m_udpPort (2152)
+{
+  NS_LOG_FUNCTION (this);
+  m_tap = tap;
+  m_tap->SetSendCallback (MakeCallback (&GtpuTunnelEndpoint::GtpuSend, this));
+  m_socket = s;
+  m_socket->SetRecvCallback (MakeCallback (&GtpuTunnelEndpoint::GtpuRecv, this));
+}
+
+uint32_t
+GtpuTunnelEndpoint::CreateGtpuTunnel (Ipv4Address destination)
+{
+  NS_LOG_FUNCTION (this);
+  CreateGtpuTunnel (destination, ++m_teidCounter);
+  return m_teidCounter;
+}
+
+void
+GtpuTunnelEndpoint::CreateGtpuTunnel (Ipv4Address destination, uint32_t teid)
+{
+  NS_LOG_FUNCTION (this);
+  m_gtpuMap[m_indexCounter] = CreateObject<GtpuL5Protocol> (teid);
+  m_dstAddrMap[m_indexCounter] = destination;
+}
+
+
+void
+GtpuTunnelEndpoint::GtpuRecv (Ptr<Socket> socket)
+{
+  NS_LOG_FUNCTION (this);
+  Ptr<Packet> packet = socket->Recv (65535, 0);
+  uint32_t index = 0;
+  m_gtpuMap[index]->RemoveHeader (packet);
+  m_tap->Receive (packet, 0x0800, m_tap->GetAddress (), m_tap->GetAddress (), NetDevice::PACKET_HOST);
+}
+
+bool
+GtpuTunnelEndpoint::GtpuSend (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
+{
+  NS_LOG_FUNCTION (this << source << dest << packet << packet->GetSize ());
+  // TODO: Instead of use always index 0 make use of the TFT classifier class, probably
+  // a mapping between the tunnel index (assigned during the tunnel creation) and the classifier
+  // index (assigned when the first packet is send through) should be maintained.
+  uint32_t index = 0;
+  packet = m_gtpuMap[index]->AddHeader (packet);
+  m_socket->SendTo (packet, 0, InetSocketAddress (m_dstAddrMap[index], m_udpPort));
+  return true;
+}
+
+GtpuTunnelEndpoint::~GtpuTunnelEndpoint ()
+{
+  NS_LOG_FUNCTION_NOARGS ();
+}
+
+}; // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lte/model/epc-gtpu-tunnel-endpoint.h	Tue Aug 02 18:22:23 2011 +0200
@@ -0,0 +1,111 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Jaume Nin <jnin@cttc.cat>
+ */
+
+#ifndef GTPU_TUNNEL_ENDPOINT_H
+#define GTPU_TUNNEL_ENDPOINT_H
+
+#include "ns3/address.h"
+#include "ns3/socket.h"
+#include "ns3/virtual-net-device.h"
+#include "ns3/epc-gtpu-l5-protocol.h"
+#include "ns3/traced-callback.h"
+#include "ns3/callback.h"
+#include "ns3/ptr.h"
+#include "ns3/object.h"
+#include <map>
+
+namespace ns3 {
+
+/**
+ * \ingroup lte
+ *
+ * GTPv1-U endpoint for all the tunnels of a given node. It encapsulates all the tunnel logic for creating tunnels and encapsulating data through it
+ */
+class GtpuTunnelEndpoint : public Object
+{
+
+public:
+  static TypeId GetTypeId (void);
+
+  /**
+   * Method assigned to the send callback of the upper end of the tunnel. It adds
+   * the GTP header and sends it through the tunnel
+   */
+  bool GtpuSend (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
+  /**
+   * Method assigned to the receive callback of the upper end of the tunnel. It strips
+   * the GTP header and sends it up to the application
+   */
+  void GtpuRecv (Ptr<Socket> socket);
+
+  /**
+   * Constructor that binds the tap device to the callback methods.
+   * \param tap VirtualNetDevice used to tunnel the packets
+   * \param s Socket used to send the tunneled packets
+   */
+  GtpuTunnelEndpoint (const Ptr<VirtualNetDevice> tap, const Ptr<Socket> s);
+  virtual ~GtpuTunnelEndpoint (void);
+
+  /**
+   * Creates a GTPv1-U tunnel between the given destination and the enpoint
+   * using the specified TEID.
+   * \param destination IP address of the other end of the tunnel
+   * \param teid Tunnel Endpoint IDentifier to be assigned to the tunnel
+   */
+  void CreateGtpuTunnel (Ipv4Address destination, uint32_t teid);
+
+  /**
+   * Creates a GTPv1-U tunnel between the given destination and the enpoint. The
+   * TEID is automatically sellected.
+   * \param destination IP address of the other end of the tunnel
+   * \return teid Tunnel Endpoint IDentifier assigned to the tunnel
+   */
+  uint32_t CreateGtpuTunnel (Ipv4Address destination);
+
+private:
+  /**
+   * UDP socket to send and receive the packets to and from the tunnel
+   */
+  Ptr<Socket> m_socket;
+  /**
+   * UDP port where the socket is bind, fixed by the standard as 2152
+   */
+  uint16_t m_udpPort;
+  /**
+   * VirtualNetDevice to create the tunnel
+   */
+  Ptr<VirtualNetDevice> m_tap;
+  /**
+   * Map holding the GTP instances of the active tunnels on this endpoint
+   */
+  std::map<uint32_t, Ptr<GtpuL5Protocol> > m_gtpuMap;
+  /**
+   * Map holding the destination address of the active tunnels on this endpoint
+   */
+  std::map<uint32_t, Ipv4Address> m_dstAddrMap;
+
+  static uint16_t m_teidCounter;
+  static uint32_t m_indexCounter;
+};
+
+} //namespace ns3
+
+#endif /* GTPU_TUNNEL_H */
+
--- a/src/lte/model/epc-gtpu-tunnel.cc	Fri Jul 29 18:26:35 2011 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,124 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * Author: Jaume Nin <jnin@cttc.cat>
- */
-
-
-#include "epc-gtpu-tunnel.h"
-#include "ns3/log.h"
-#include "ns3/uinteger.h"
-#include "ns3/integer.h"
-#include "ns3/boolean.h"
-#include "ns3/inet-socket-address.h"
-#include "ns3/ipv4.h"
-#include "ns3/mac48-address.h"
-
-namespace ns3 {
-
-NS_LOG_COMPONENT_DEFINE ("GtpuTunnel");
-
-//m_gtpuPort = 2152;
-
-TypeId
-GtpuTunnel::GetTypeId (void)
-{
-  static TypeId tid = TypeId ("ns3::GtpuTunnel")
-    .SetParent<Object> ();
-  ;
-  return tid;
-}
-
-GtpuTunnel::GtpuTunnel (Ptr<Node> nA, Ptr<Node> nB, Ipv4Address addrA, Ipv4Address addrB, Ipv4Address tAddrA, Ipv4Address tAddrB, Ipv4Mask m, uint32_t teid):
-      m_addressA(addrA), m_addressB(addrB), m_udpPort (2152)
-{
-  NS_LOG_FUNCTION (this);
-  m_gtpu = CreateObject<GtpuL5Protocol> (teid);
-
-  // UDP socket creation and configuration
-  m_socketA = Socket::CreateSocket (nA, TypeId::LookupByName ("ns3::UdpSocketFactory"));
-  m_socketA->Bind (InetSocketAddress (Ipv4Address::GetAny (), m_udpPort));
-  m_socketA->SetRecvCallback (MakeCallback (&GtpuTunnel::GtpuNaRecv, this));
-
-  m_socketB = Socket::CreateSocket (nB, TypeId::LookupByName ("ns3::UdpSocketFactory"));
-  m_socketB->Bind (InetSocketAddress (Ipv4Address::GetAny (), m_udpPort));
-  m_socketB->SetRecvCallback (MakeCallback (&GtpuTunnel::GtpuNbRecv, this));
-
-  // tap device creation and configuration
-  // n0 tap device
-  m_tapA = CreateObject<VirtualNetDevice> ();
-  m_tapA->SetAddress (Mac48Address::Allocate ());
-  m_tapA->SetSendCallback (MakeCallback (&GtpuTunnel::GtpuNaSend, this));
-  nA->AddDevice (m_tapA);
-  Ptr<Ipv4> ipv4 = nA->GetObject<Ipv4> ();
-  uint32_t i = ipv4->AddInterface (m_tapA);
-  ipv4->AddAddress (i, Ipv4InterfaceAddress (tAddrA, m));
-  ipv4->SetUp (i);
-
-  m_tapB = CreateObject<VirtualNetDevice> ();
-  m_tapB->SetAddress (Mac48Address::Allocate ());
-  m_tapB->SetSendCallback (MakeCallback (&GtpuTunnel::GtpuNbSend, this));
-  nB->AddDevice (m_tapB);
-  ipv4 = nB->GetObject<Ipv4> ();
-  i = ipv4->AddInterface (m_tapA);
-  ipv4->AddAddress (i, Ipv4InterfaceAddress (tAddrB, m));
-  ipv4->SetUp (i);
-
-}
-
-void
-GtpuTunnel::GtpuNaRecv (Ptr<Socket> socket)
-{
-  NS_LOG_FUNCTION (this);
-  Ptr<Packet> packet = socket->Recv (65535, 0);
-  m_gtpu->RemoveHeader (packet);
-  m_tapA->Receive (packet, 0x0800, m_tapA->GetAddress (), m_tapA->GetAddress (), NetDevice::PACKET_HOST);
-}
-
-void
-GtpuTunnel::GtpuNbRecv (Ptr<Socket> socket)
-{
-  NS_LOG_FUNCTION (this);
-  Ptr<Packet> packet = socket->Recv (65535, 0);
-  m_gtpu->RemoveHeader (packet);
-  m_tapB->Receive (packet, 0x0800, m_tapB->GetAddress (), m_tapB->GetAddress (), NetDevice::PACKET_HOST);
-}
-
-bool
-GtpuTunnel::GtpuNaSend (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
-{
-  NS_LOG_FUNCTION (this << source << dest << packet << packet->GetSize ());
-  packet = m_gtpu->AddHeader (packet);
-  m_socketA->SendTo (packet, 0, InetSocketAddress (m_addressB, m_udpPort));
-  return true;
-}
-
-bool
-GtpuTunnel::GtpuNbSend (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
-{
-  NS_LOG_FUNCTION (this << source << dest << packet << packet->GetSize ());
-  packet = m_gtpu->AddHeader (packet);
-  m_socketB->SendTo (packet, 0, InetSocketAddress (m_addressA, m_udpPort));
-  return true;
-}
-
-GtpuTunnel::~GtpuTunnel ()
-{
-  NS_LOG_FUNCTION_NOARGS ();
-}
-
-}; // namespace ns3
--- a/src/lte/model/epc-gtpu-tunnel.h	Fri Jul 29 18:26:35 2011 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,65 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * Author: Jaume Nin <jnin@cttc.cat>
- */
-
-#ifndef GTPU_TUNNEL_H
-#define GTPU_TUNNEL_H
-
-#include "ns3/address.h"
-#include "ns3/socket.h"
-#include "ns3/virtual-net-device.h"
-#include "ns3/epc-gtpu-l5-protocol.h"
-#include "ns3/traced-callback.h"
-#include "ns3/callback.h"
-#include "ns3/ptr.h"
-#include "ns3/object.h"
-
-namespace ns3
-{
-
-class GtpuTunnel : public Object
-{
-
-public:
-  static TypeId GetTypeId (void);
-  bool GtpuNaSend (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
-  bool GtpuNbSend (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
-  void GtpuNaRecv (Ptr<Socket> socket);
-  void GtpuNbRecv (Ptr<Socket> socket);
-
-  GtpuTunnel (Ptr<Node> nA, Ptr<Node> nB, Ipv4Address addrA, Ipv4Address addrB, Ipv4Address tAddrA, Ipv4Address tAddrB, Ipv4Mask m, uint32_t teid);
-  virtual ~GtpuTunnel (void);
-
-private:
-
-  Ptr<Socket> m_socketA;
-  Ptr<Socket> m_socketB;
-  Ipv4Address m_addressA;
-  Ipv4Address m_addressB;
-  uint16_t m_udpPort;
-  //static const uint16_t m_gtpuPort;
-  Ptr<VirtualNetDevice> m_tapA;
-  Ptr<VirtualNetDevice> m_tapB;
-  Ptr<GtpuL5Protocol> m_gtpu;
-};
-
-} //namespace ns3
-
-#endif /* GTPU_TUNNEL_H */
-
--- a/src/lte/wscript	Fri Jul 29 18:26:35 2011 +0200
+++ b/src/lte/wscript	Tue Aug 02 18:22:23 2011 +0200
@@ -49,7 +49,7 @@
         'model/pf-ff-mac-scheduler.cc',
         'model/epc-gtpu-header.cc',
         'model/epc-gtpu-l5-protocol.cc',
-        'model/epc-gtpu-tunnel.cc',
+        'model/epc-gtpu-tunnel-endpoint.cc',
         'model/lte-tft.cc',
         'model/eps-tft-classifier.cc',
         ]
@@ -119,7 +119,7 @@
         'model/pf-ff-mac-scheduler.h',
         'model/epc-gtpu-header.h',
         'model/epc-gtpu-l5-protocol.h',
-        'model/epc-gtpu-tunnel.h',
+        'model/epc-gtpu-tunnel-endpoint.h',
         'test/lte-test-downlink-sinr.h',
         'test/lte-test-uplink-sinr.h',
         'test/lte-test-link-adaptation.h',