Skip to content

Commit

Permalink
mptcp patch
Browse files Browse the repository at this point in the history
  • Loading branch information
Kashif-Nadeem committed Aug 13, 2018
1 parent 9deaad5 commit 3c6ec27
Show file tree
Hide file tree
Showing 33 changed files with 8,195 additions and 60 deletions.
88 changes: 88 additions & 0 deletions src/internet/model/mptcp-crypto.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2007 Georgia Tech Research Corporation
*
* 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: Kashif Nadeem <[email protected]>
* Matthieu Coudron <[email protected]>
*
*/

#include <stdint.h>
#include "ns3/mptcp-crypto.h"
#include "ns3/log.h"
#include "ns3/node.h"
#include "ns3/buffer.h"
#include "ns3/assert.h"
#include <cstddef>

#ifdef HAVE_CRYPTO
#include <gcrypt.h>
#else
#include <functional>
#include <iostream>
#include <string>
#endif

NS_LOG_COMPONENT_DEFINE ("MpTcpCrypto");

namespace ns3 {

/* https://www.gnupg.org/documentation/manuals/gcrypt/Working-with-hash-algorithms.html#Working-with-hash-algorithms */
void
GenerateTokenForKey( mptcp_crypto_alg_t ns_alg, uint64_t key, uint32_t& token, uint64_t& idsn)
{
NS_LOG_LOGIC("Generating token/key from key=" << key);
#ifdef HAVE_CRYPTO
gcry_md_algos gcry_algo = GCRY_MD_SHA1;
static const int KEY_SIZE_IN_BYTES = sizeof(key);

/* converts the key into a buffer */
Buffer keyBuff;
keyBuff.AddAtStart(KEY_SIZE_IN_BYTES);
Buffer::Iterator it = keyBuff.Begin();
it.WriteHtonU64(key);
int hash_length = gcry_md_get_algo_dlen( gcry_algo );
unsigned char digest[ 20 ];
Buffer digestBuf; /* to store the generated hash */
digestBuf.AddAtStart(hash_length);
/*
* gcry_md_hash_buffer (int algo, void *digest, const void *buffer, size_t length);
* gcry_md_hash_buffer is a shortcut function to calculate a message digest of a buffer.
* This function does not require a context and immediately returns the message digest
* of the length bytes at buffer. digest must be allocated by the caller,
* large enough to hold the message digest yielded by the the specified algorithm algo.
* This required size may be obtained by using the function gcry_md_get_algo_dlen.
*/

gcry_md_hash_buffer( GCRY_MD_SHA1, digest, keyBuff.PeekData(), KEY_SIZE_IN_BYTES );
Buffer::Iterator it_digest = digestBuf.Begin();
it_digest.Write( digest , hash_length ); // strlen( (const char*)digest)
it_digest = digestBuf.Begin();
token = it_digest.ReadNtohU32();
it_digest.Next( 8 );
idsn = it_digest.ReadNtohU64();
#else
/* the cryptographic library is not available so we rely on a ns3 specific implementation
* that does not comply with the standard.
* In the following, the idsn = the key (could be 0) and the token a truncated key
*/

idsn = key;
token = (uint32_t)key;
#endif // HAVE_CRYPTO
}

} // end of 'ns3'
73 changes: 73 additions & 0 deletions src/internet/model/mptcp-crypto.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2007 Georgia Tech Research Corporation
*
* 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: Kashif Nadeem <[email protected]>
* Matthieu Coudron <[email protected]>
*
*/

#ifndef MPTCP_CRYPTO_H
#define MPTCP_CRYPTO_H

/**
* Token: A locally unique identifier given to a multipath connection
* by a host. May also be referred to as a "Connection ID".
*
* In this specification, with only the SHA-1 algorithm
* (bit "H") specified and selected, the token MUST be a truncated (most
* significant 32 bits) SHA-1 hash ([4], [15]) of the key. A different,
* 64-bit truncation (the least significant 64 bits) of the SHA-1 hash
* of the key MUST be used as the initial data sequence number. Note
* that the key MUST be hashed in network byte order. Also note that
* the "least significant" bits MUST be the rightmost bits of the SHA-1
* digest, as per [4]. Future specifications of the use of the crypto
* bits may choose to specify different algorithms for token and IDSN
* generation.
*/
namespace ns3
{
/**
* \brief Only SHA1 is defined in the RFC up to now.
*/
enum mptcp_crypto_alg_t
{
HMAC_SHA1 = 1 /**< Default choice */
/* more may come in the future depending on the standardization */
};

/**
* \brief This function generates the token and idsn based on the passed key
*
* \note This function operates in different modes depending on if the library libgcrypt
* was available when running ./waf config . The result conforms to the standard when libgcrypt
* is present, otherwise it relies on a simpler incompatible ns3 implementation.
*
* In the case of sha1 (only one standardized), the token MUST be a truncated (most
* significant 32 bits) SHA-1 hash according to \rfc{6824}.
* The least significant 64 bits of the SHA-1 hash
* of the key MUST be used as the initial data sequence number.
*
* \param alg The hmac algorith m to use to generate the hash
* \param key Given key for a connection
* \param token Resulting token generated from the key
* \param idsn Resulting initial data sequence number generated from the key
*/
void
GenerateTokenForKey( mptcp_crypto_alg_t alg, uint64_t key, uint32_t& token, uint64_t& idsn);
}

#endif
77 changes: 77 additions & 0 deletions src/internet/model/mptcp-fullmesh.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@

/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2007 Georgia Tech Research Corporation
* Copyright (c) 2010 Adrian Sai-wah Tam
*
* 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: Kashif Nadeem <[email protected]>
*
*/

#include "ns3/mptcp-fullmesh.h"
#include "ns3/mptcp-socket-base.h"
#include "ns3/mptcp-subflow.h"
#include "ns3/tcp-socket-base.h"
#include "ns3/tcp-l4-protocol.h"
#include "ns3/ipv4-end-point.h"
#include "ns3/ipv4-header.h"
#include "ns3/log.h"

namespace ns3 {

NS_LOG_COMPONENT_DEFINE ("MpTcpFullMesh");

NS_OBJECT_ENSURE_REGISTERED (MpTcpFullMesh);

TypeId
MpTcpFullMesh::GetTypeId (void)
{
static TypeId tid = TypeId ("ns::MpTcpFullMesh")
.SetParent<Object> ()
.AddConstructor<MpTcpFullMesh> ()
.SetGroupName ("Internet")

;
return tid;
}

MpTcpFullMesh::MpTcpFullMesh (void)
: Object()
{
NS_LOG_FUNCTION (this);
}

MpTcpFullMesh::~MpTcpFullMesh (void)
{
NS_LOG_FUNCTION (this);
}

TypeId
MpTcpFullMesh::GetInstanceTypeId () const
{
return MpTcpFullMesh::GetTypeId ();
}

void
MpTcpFullMesh::CreateMesh(Ptr<MpTcpSocketBase> meta)
{
NS_LOG_FUNCTION(this<<meta);

meta->AddLocalAddresses(); // Add local addresses to vector LocalAddressInfo;
meta->CreateSubflowsForMesh();
}

} //namespace ns3
71 changes: 71 additions & 0 deletions src/internet/model/mptcp-fullmesh.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2007 Georgia Tech Research Corporation
* Copyright (c) 2010 Adrian Sai-wah Tam
*
* 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: Kashif Nadeem <[email protected]>
*
*/
#ifndef MPTCP_FULLMESH_H
#define MPTCP_FULLMESH_H

#include "ns3/mptcp-socket-base.h"
#include "ns3/ipv4-header.h"
#include "ns3/object.h"

namespace ns3 {

/**
* \ingroup socket
* \ingroup mptcp
*
* \brief A base class for implementation of a MPTCP Fullmesh Path Manager.
*
* This class contains the functionality to create mesh of subflows between
* sender and receiver. This class makes calls to add addresses of the local
* host to the container. Makes call to the function CreateSubflowsForMesh
* from MPTCP socket base to create subflows
*/
class MpTcpFullMesh : public Object
{
public:
/**
* Get the type ID.
* \brief Get the type ID.
* \return the object TypeId
*/
static TypeId GetTypeId (void);

/**
* \brief Get the instance TypeId
* \return the instance TypeId
*/
virtual TypeId GetInstanceTypeId () const;

MpTcpFullMesh (void);
virtual ~MpTcpFullMesh (void);
/**
* Creates the mesh of subflows between the sender and receiver
* based on the available IP addresses
* \param meta the pointer to the MpTcpSocketBase
*/

virtual void CreateMesh(Ptr<MpTcpSocketBase> meta);

};

} //namespace ns3
#endif //MPTCP_FULLMESH_H
Loading

0 comments on commit 3c6ec27

Please sign in to comment.