5 changed files with 510 additions and 0 deletions
@ -0,0 +1,277 @@
|
||||
/* -*- 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-v1.h" |
||||
#include "ns3/packet.h" |
||||
|
||||
namespace ns3 |
||||
{ |
||||
|
||||
/********************************************************
|
||||
* GTP-U-v1 Header |
||||
********************************************************/ |
||||
|
||||
NS_OBJECT_ENSURE_REGISTERED (GtpuHeader); |
||||
|
||||
TypeId |
||||
GtpuHeader::GetTypeId (void) |
||||
{ |
||||
static TypeId tid = |
||||
TypeId("ns3::GtpuHeader") .SetParent<Header> () .AddConstructor< |
||||
GtpuHeader> (); |
||||
return tid; |
||||
} |
||||
GtpuHeader::GtpuHeader () : |
||||
m_version(1), m_protocolType(true), m_extensionHeaderFlag(false), |
||||
m_sequenceNumberFlag(false), m_nPduNumberFlag(false), m_messageType(0), |
||||
m_length(0), m_teid(0), m_sequenceNumber(0), m_nPduNumber(0), |
||||
m_nextExtensionType(0) |
||||
{ |
||||
|
||||
} |
||||
|
||||
GtpuHeader::~GtpuHeader () |
||||
{ |
||||
} |
||||
|
||||
TypeId |
||||
GtpuHeader::GetInstanceTypeId (void) const |
||||
{ |
||||
return GetTypeId(); |
||||
} |
||||
|
||||
uint32_t |
||||
GtpuHeader::GetSerializedSize (void) const |
||||
{ |
||||
return 12; |
||||
} |
||||
void |
||||
GtpuHeader::Serialize (Buffer::Iterator start) const |
||||
{ |
||||
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.WriteHtonU16 (m_length); |
||||
i.WriteHtonU32 (m_teid); |
||||
i.WriteHtonU16 (m_sequenceNumber); |
||||
i.WriteU8 (m_nPduNumber); |
||||
i.WriteU8 (m_nextExtensionType); |
||||
|
||||
} |
||||
uint32_t |
||||
GtpuHeader::Deserialize (Buffer::Iterator start) |
||||
{ |
||||
uint8_t firstByte = start.ReadU8 (); |
||||
m_version = firstByte >> 5 & 0x7; |
||||
m_protocolType = firstByte >> 4 & 0x1; |
||||
m_extensionHeaderFlag = firstByte >> 2 & 0x1; |
||||
m_sequenceNumberFlag = firstByte >> 1 & 0x1; |
||||
m_nPduNumberFlag = firstByte & 0x1; |
||||
m_messageType = start.ReadU8 (); |
||||
m_length = start.ReadNtohU16 (); |
||||
m_teid= start.ReadNtohU32 (); |
||||
m_sequenceNumber= start.ReadNtohU16 (); |
||||
m_nPduNumber= start.ReadU8 (); |
||||
m_nextExtensionType= start.ReadU8 (); |
||||
return 4; |
||||
} |
||||
void |
||||
GtpuHeader::Print (std::ostream &os) const |
||||
{ |
||||
os << "version=" << (uint32_t) m_version << " ["; |
||||
if (m_protocolType) |
||||
{ |
||||
os << " PT "; |
||||
} |
||||
if (m_extensionHeaderFlag) |
||||
{ |
||||
os << " E "; |
||||
} |
||||
if (m_sequenceNumberFlag) |
||||
{ |
||||
os << " S "; |
||||
} |
||||
if (m_nPduNumberFlag) |
||||
{ |
||||
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 << ", nPduNumber=" << (uint32_t) m_nPduNumber << ", nextExtensionType=" << (uint32_t) m_nextExtensionType; |
||||
} |
||||
|
||||
bool |
||||
GtpuHeader::GetExtensionHeaderFlag () const |
||||
{ |
||||
return m_extensionHeaderFlag; |
||||
} |
||||
|
||||
uint16_t |
||||
GtpuHeader::GetLength () const |
||||
{ |
||||
return m_length; |
||||
} |
||||
|
||||
uint8_t |
||||
GtpuHeader::GetMessageType () const |
||||
{ |
||||
return m_messageType; |
||||
} |
||||
|
||||
uint8_t |
||||
GtpuHeader::GetNPduNumber () const |
||||
{ |
||||
return m_nPduNumber; |
||||
} |
||||
|
||||
bool |
||||
GtpuHeader::GetNPduNumberFlag () const |
||||
{ |
||||
return m_nPduNumberFlag; |
||||
} |
||||
|
||||
uint8_t |
||||
GtpuHeader::GetNextExtensionType () const |
||||
{ |
||||
return m_nextExtensionType; |
||||
} |
||||
|
||||
bool |
||||
GtpuHeader::GetProtocolType () const |
||||
{ |
||||
return m_protocolType; |
||||
} |
||||
|
||||
uint16_t |
||||
GtpuHeader::GetSequenceNumber () const |
||||
{ |
||||
return m_sequenceNumber; |
||||
} |
||||
|
||||
bool |
||||
GtpuHeader::GetSequenceNumberFlag () const |
||||
{ |
||||
return m_sequenceNumberFlag; |
||||
} |
||||
|
||||
uint32_t |
||||
GtpuHeader::GetTeid () const |
||||
{ |
||||
return m_teid; |
||||
} |
||||
|
||||
uint8_t |
||||
GtpuHeader::GetVersion () const |
||||
{ |
||||
return m_version; |
||||
} |
||||
|
||||
void |
||||
GtpuHeader::SetExtensionHeaderFlag (bool m_extensionHeaderFlag) |
||||
{ |
||||
this->m_extensionHeaderFlag = m_extensionHeaderFlag; |
||||
} |
||||
|
||||
void |
||||
GtpuHeader::SetLength (uint16_t m_length) |
||||
{ |
||||
this->m_length = m_length; |
||||
} |
||||
|
||||
void |
||||
GtpuHeader::SetMessageType (uint8_t m_messageType) |
||||
{ |
||||
this->m_messageType = m_messageType; |
||||
} |
||||
|
||||
void |
||||
GtpuHeader::SetNPduNumber (uint8_t m_nPduNumber) |
||||
{ |
||||
this->m_nPduNumber = m_nPduNumber; |
||||
} |
||||
|
||||
void |
||||
GtpuHeader::SetNPduNumberFlag (bool m_nPduNumberFlag) |
||||
{ |
||||
this->m_nPduNumberFlag = m_nPduNumberFlag; |
||||
} |
||||
|
||||
void |
||||
GtpuHeader::SetNextExtensionType (uint8_t m_nextExtensionType) |
||||
{ |
||||
this->m_nextExtensionType = m_nextExtensionType; |
||||
} |
||||
|
||||
void |
||||
GtpuHeader::SetProtocolType (bool m_protocolType) |
||||
{ |
||||
this->m_protocolType = m_protocolType; |
||||
} |
||||
|
||||
void |
||||
GtpuHeader::SetSequenceNumber (uint16_t m_sequenceNumber) |
||||
{ |
||||
this->m_sequenceNumber = m_sequenceNumber; |
||||
} |
||||
|
||||
void |
||||
GtpuHeader::SetSequenceNumberFlag (bool m_sequenceNumberFlag) |
||||
{ |
||||
this->m_sequenceNumberFlag = m_sequenceNumberFlag; |
||||
} |
||||
|
||||
void |
||||
GtpuHeader::SetTeid (uint32_t m_teid) |
||||
{ |
||||
this->m_teid = m_teid; |
||||
} |
||||
|
||||
void |
||||
GtpuHeader::SetVersion (uint8_t m_version) |
||||
{ |
||||
// m_version is a uint3_t
|
||||
this->m_version = m_version & 0x7; |
||||
} |
||||
|
||||
bool |
||||
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 |
||||
) |
||||
{ |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
} // namespace ns3
|
||||
|
@ -0,0 +1,89 @@
|
||||
/* -*- 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_V1_H |
||||
#define EPS_GTPU_V1_H |
||||
|
||||
#include "ns3/header.h" |
||||
#include "ns3/ptr.h" |
||||
#include "ns3/ipv4-header.h" |
||||
#include <stdint.h> |
||||
|
||||
namespace ns3 { |
||||
|
||||
class Packet; |
||||
|
||||
class GtpuHeader : public Header |
||||
{ |
||||
public: |
||||
static TypeId GetTypeId (void); |
||||
GtpuHeader (); |
||||
virtual ~GtpuHeader (); |
||||
virtual TypeId GetInstanceTypeId (void) const; |
||||
virtual uint32_t GetSerializedSize (void) const; |
||||
virtual void Serialize (Buffer::Iterator start) const; |
||||
virtual uint32_t Deserialize (Buffer::Iterator start); |
||||
virtual void Print (std::ostream &os) const; |
||||
|
||||
bool GetExtensionHeaderFlag () const; |
||||
uint16_t GetLength () const; |
||||
uint8_t GetMessageType () const; |
||||
uint8_t GetNPduNumber () const; |
||||
bool GetNPduNumberFlag () const; |
||||
uint8_t GetNextExtensionType () const; |
||||
bool GetProtocolType () const; |
||||
uint16_t GetSequenceNumber () const; |
||||
bool GetSequenceNumberFlag () const; |
||||
uint32_t GetTeid () const; |
||||
uint8_t GetVersion () const; |
||||
void SetExtensionHeaderFlag (bool m_extensionHeaderFlag); |
||||
void SetLength (uint16_t m_length); |
||||
void SetMessageType (uint8_t m_messageType); |
||||
void SetNPduNumber (uint8_t m_nPduNumber); |
||||
void SetNPduNumberFlag (bool m_nPduNumberFlag); |
||||
void SetNextExtensionType (uint8_t m_nextExtensionType); |
||||
void SetProtocolType (bool m_protocolType); |
||||
void SetSequenceNumber (uint16_t m_sequenceNumber); |
||||
void SetSequenceNumberFlag (bool m_sequenceNumberFlag); |
||||
void SetTeid (uint32_t m_teid); |
||||
void SetVersion (uint8_t m_version); |
||||
|
||||
bool operator == (const GtpuHeader& b) const; |
||||
|
||||
|
||||
private: |
||||
uint8_t m_version; // really a 3 uint3_t
|
||||
bool m_protocolType; |
||||
bool m_extensionHeaderFlag; |
||||
bool m_sequenceNumberFlag; |
||||
bool m_nPduNumberFlag; |
||||
uint8_t m_messageType; |
||||
uint16_t m_length; |
||||
uint32_t m_teid; |
||||
uint16_t m_sequenceNumber; |
||||
uint8_t m_nPduNumber; |
||||
uint8_t m_nextExtensionType; |
||||
|
||||
}; |
||||
|
||||
} // namespace ns3
|
||||
|
||||
#endif /* EPS_GTPU_V1_H */ |
@ -0,0 +1,86 @@
|
||||
/* -*- 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 "ns3/log.h" |
||||
#include "ns3/object.h" |
||||
#include "ns3/packet.h" |
||||
|
||||
#include "ns3/epc-gtpu-v1.h" |
||||
#include "ns3/epc-test-gtpu-v1.h" |
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("EpcGtpuTest"); |
||||
|
||||
using namespace ns3; |
||||
|
||||
|
||||
/**
|
||||
* TestSuite |
||||
*/ |
||||
|
||||
EpsGtpuTestSuite::EpsGtpuTestSuite () |
||||
: TestSuite ("epc-gtpu-v1", SYSTEM) |
||||
{ |
||||
AddTestCase (new EpsGtpuHeaderTestCase ()); |
||||
} |
||||
|
||||
static EpsGtpuTestSuite epsGtpuTestSuite; |
||||
|
||||
|
||||
/**
|
||||
* TestCase |
||||
*/ |
||||
|
||||
EpsGtpuHeaderTestCase::EpsGtpuHeaderTestCase () |
||||
: TestCase ("Check header coding and decoding") |
||||
{ |
||||
NS_LOG_INFO ("Creating EpsGtpuHeaderTestCase"); |
||||
} |
||||
|
||||
EpsGtpuHeaderTestCase::~EpsGtpuHeaderTestCase () |
||||
{ |
||||
} |
||||
|
||||
void |
||||
EpsGtpuHeaderTestCase::DoRun (void) |
||||
{ |
||||
LogLevel logLevel = (LogLevel)(LOG_PREFIX_FUNC | LOG_PREFIX_TIME | LOG_LEVEL_ALL); |
||||
|
||||
LogComponentEnable ("EpcGtpuTest", logLevel); |
||||
GtpuHeader header1; |
||||
header1.SetExtensionHeaderFlag (true); |
||||
header1.SetLength (1234); |
||||
header1.SetMessageType (123); |
||||
header1.SetNPduNumber (123); |
||||
header1.SetNPduNumberFlag (true); |
||||
header1.SetNextExtensionType (123); |
||||
header1.SetProtocolType (true); |
||||
header1.SetSequenceNumber (1234); |
||||
header1.SetSequenceNumberFlag (true); |
||||
header1.SetTeid (1234567); |
||||
header1.SetVersion (123); |
||||
|
||||
Packet p; |
||||
GtpuHeader header2; |
||||
p.AddHeader (header1); |
||||
p.RemoveHeader (header2); |
||||
|
||||
NS_TEST_ASSERT_MSG_EQ (header1, header2, "Wrong value!"); |
||||
} |
@ -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 <jaume.nin@cttc.cat> |
||||
*/ |
||||
|
||||
#ifndef EPC_TEST_GTPU_V1_H |
||||
#define EPC_TEST_GTPU_V1_H |
||||
|
||||
#include "ns3/epc-gtpu-v1.h" |
||||
|
||||
#include "ns3/test.h" |
||||
|
||||
|
||||
using namespace ns3; |
||||
|
||||
|
||||
|
||||
class EpsGtpuTestSuite : public TestSuite |
||||
{ |
||||
public: |
||||
EpsGtpuTestSuite (); |
||||
}; |
||||
|
||||
/**
|
||||
* Test 1.Check header coding and decoding |
||||
*/ |
||||
class EpsGtpuHeaderTestCase : public TestCase |
||||
{ |
||||
public: |
||||
EpsGtpuHeaderTestCase (); |
||||
virtual ~EpsGtpuHeaderTestCase (); |
||||
|
||||
private: |
||||
virtual void DoRun (void); |
||||
}; |
||||
|
||||
|
||||
#endif /* EPC_TEST_GTPU_V1_H */ |
Loading…
Reference in new issue