Added missing files for GTP-U tunnel implementation.

This commit is contained in:
jnin
2011-07-11 14:23:33 +02:00
parent 908850086d
commit e7efaaccbe
7 changed files with 565 additions and 0 deletions

View File

@@ -0,0 +1,119 @@
/* -*- 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 <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"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("EpcGtpUTunnelExample");
int
main (int argc, char *argv[])
{
Packet::EnablePrinting ();
// Command line arguments
CommandLine cmd;
cmd.Parse(argc, argv);
ConfigStore inputConfig;
inputConfig.ConfigureDefaults();
// parse again so you can override default values from the command line
cmd.Parse(argc, argv);
NS_LOG_INFO("Create nodes.");
NodeContainer c;
c.Create(2);
InternetStackHelper internet;
internet.Install(c);
// Create the channels first
NS_LOG_INFO("Create channels.");
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560)));
NetDeviceContainer nc = csma.Install(c);
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();
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);
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")));
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));
// 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.Stop (Seconds (10.0));
NS_LOG_INFO ("Run Simulation.");
Simulator::Run ();
Simulator::Destroy ();
NS_LOG_INFO ("Done.");
return 0;
}

View File

@@ -0,0 +1,53 @@
/* -*- 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.es>
*/
#include <ns3/epc-helper.h>
#include <ns3/log.h>
namespace ns3 {
NS_LOG_COMPONENT_DEFINE ("EpcHelper");
NS_OBJECT_ENSURE_REGISTERED (EpcHelper);
EpcHelper::EpcHelper ()
{
NS_LOG_FUNCTION (this);
}
EpcHelper::~EpcHelper ()
{
NS_LOG_FUNCTION (this);
}
TypeId
EpcHelper::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::EpcHelper")
.SetParent<Object> ()
.AddConstructor<EpcHelper> ()
;
return tid;
}
} // namespace ns3

View File

@@ -0,0 +1,57 @@
/* -*- 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.es>
*/
#ifndef EPC_HELPER_H_
#define EPC_HELPER_H_
#include "ns3/object.h"
namespace ns3 {
/**
* Helper class to handle the creation of the EPC entities and protocols
*/
class EpcHelper : public Object
{
public:
/**
* Constructor
*/
EpcHelper ();
/**
* Destructor
*/
virtual ~EpcHelper ();
/**
* Inherited from ns3::Object
*/
static TypeId GetTypeId (void);
private:
};
} // namespace ns3
#endif /* EPC_HELPER_H_ */

View File

@@ -0,0 +1,88 @@
/* -*- 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 "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");
namespace ns3 {
NS_OBJECT_ENSURE_REGISTERED (GtpuL5Protocol);
TypeId
GtpuL5Protocol::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::GtpuL5Protocol")
.SetParent<Object> ()
.AddConstructor<GtpuL5Protocol> ()
/*.AddAttribute ("TEID", "Tunnel Endpoint Identifier of this instance.",
UintegerValue (0),
MakeUintegerAccessor (&GtpuL5Protocol::SetTeid,
&GtpuL5Protocol::GetTeid),
MakeUintegerChecker<uint32_t> ())*/
;
return tid;
}
GtpuL5Protocol::GtpuL5Protocol ()
{
NS_LOG_FUNCTION_NOARGS ();
}
GtpuL5Protocol::GtpuL5Protocol (uint32_t teid)
{
NS_LOG_FUNCTION (this);
//this.SetAttribute("TEID", teid);
m_teid = teid;
}
GtpuL5Protocol::~GtpuL5Protocol ()
{
NS_LOG_FUNCTION_NOARGS ();
}
Ptr<Packet>
GtpuL5Protocol::AddHeader (Ptr<Packet> p)
{
GtpuHeader h;
h.SetTeid (m_teid);
// From 3GPP TS 29.281 v10.0.0 Section 5.1
// Length of the payload + the non obligatory GTP-U header
h.SetLength (p->GetSize () + h.GetSerializedSize () - 8);
p->AddHeader (h);
NS_LOG_FUNCTION (this << h);
return p;
}
void
GtpuL5Protocol::RemoveHeader (Ptr<Packet> p)
{
GtpuHeader h;
p->RemoveHeader (h);
NS_LOG_DEBUG (this << h);
NS_ASSERT( h.GetTeid () == m_teid);
}
}; // namespace ns3

View File

@@ -0,0 +1,58 @@
/* -*- 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 EPS_GTPU_L5_PROTOCOL_H
#define EPS_GTPU_L5_PROTOCOL_H
#include <stdint.h>
#include <ns3/object.h>
#include <ns3/packet.h>
namespace ns3
{
/**
* Implementation of the GTP-U v1 protocol
*/
class GtpuL5Protocol : public Object
{
public:
static TypeId GetTypeId (void);
GtpuL5Protocol ();
GtpuL5Protocol (uint32_t teid);
virtual ~GtpuL5Protocol ();
Ptr<Packet> AddHeader (Ptr<Packet> p);
void RemoveHeader (Ptr<Packet> p);
uint32_t GetTeid (void);
void SetTeid (uint32_t teid);
private:
uint32_t m_teid;
};
}
; // namespace ns3
#endif /* EPS_GTPU_L5_PROTOCOL_H */

View File

@@ -0,0 +1,125 @@
/* -*- 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"
#include "ns3/ppp-header.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

View File

@@ -0,0 +1,65 @@
/* -*- 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 */