Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infiniband soft_RoCE implement #1603

Open
wants to merge 25 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
64cbd61
add infinibandlayer rxe for pcapp
FlashBarryAllen Sep 10, 2024
9f6016f
add bth definiction
FlashBarryAllen Sep 10, 2024
bb61530
Merge branch 'dev' into master
FlashBarryAllen Oct 4, 2024
3a7dfaf
fix C-cast and add override to code
FlashBarryAllen Oct 4, 2024
05333c8
fix pre-commit errors
FlashBarryAllen Oct 4, 2024
008eab7
fix macro and coding style
FlashBarryAllen Oct 5, 2024
86d3a58
IB toString use more efficient style
FlashBarryAllen Oct 5, 2024
5cbc3f9
IB coding style fix
FlashBarryAllen Oct 5, 2024
b6f3c04
add documentation of IB
FlashBarryAllen Oct 13, 2024
b7a2a74
add IB creation test case
FlashBarryAllen Oct 13, 2024
5d2402e
Merge branch 'dev' into master
FlashBarryAllen Oct 13, 2024
9579f68
fix IB code format
FlashBarryAllen Oct 14, 2024
33308c1
Merge branch 'dev' into master
FlashBarryAllen Oct 14, 2024
342367e
doxygen fix
FlashBarryAllen Oct 15, 2024
d9aaee5
Merge branch 'master' of github.com:FlashBarryAllen/PcapPlusPlus
FlashBarryAllen Oct 15, 2024
254231f
Merge branch 'dev' into master
FlashBarryAllen Oct 19, 2024
09a9e92
IB code style fix
FlashBarryAllen Oct 19, 2024
451aa5c
Merge branch 'master' of github.com:FlashBarryAllen/PcapPlusPlus
FlashBarryAllen Oct 19, 2024
1f0935e
Merge branch 'dev' into master
FlashBarryAllen Oct 22, 2024
0623403
Merge branch 'dev' into master
FlashBarryAllen Oct 26, 2024
8a05842
IB add pcap
FlashBarryAllen Oct 26, 2024
4a02168
Merge branch 'dev' into master
FlashBarryAllen Nov 3, 2024
e2d8f04
fix IB argument type
FlashBarryAllen Nov 3, 2024
dd63809
Merge branch 'master' of github.com:FlashBarryAllen/PcapPlusPlus
FlashBarryAllen Nov 3, 2024
6db4619
Merge branch 'dev' into master
FlashBarryAllen Nov 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Packet++/CMakeLists.txt
FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ add_library(
src/TLVData.cpp
src/TpktLayer.cpp
src/UdpLayer.cpp
src/InfiniBandLayer.cpp
FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved
src/VlanLayer.cpp
src/VrrpLayer.cpp
src/VxlanLayer.cpp
Expand Down
128 changes: 128 additions & 0 deletions Packet++/header/InfiniBandLayer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#pragma once

#include "Layer.h"

/// @file

/**
* \namespace pcpp
* \brief The main namespace for the PcapPlusPlus lib
*/
namespace pcpp
{
/*
* IBA header types and methods
*
* Some of these are for reference and completeness only since
* rxe does not currently support RD transport
* most of this could be moved into Infiniband core. ib_pack.h has
* part of this but is incomplete
*
* Header specific routines to insert/extract values to/from headers
* the routines that are named __hhh_(set_)fff() take a pointer to a
* hhh header and get(set) the fff field. The routines named
* hhh_(set_)fff take a packet info struct and find the
* header and field based on the opcode in the packet.
* Conversion to/from network byte order from cpu order is also done.
*/

#define RXE_ICRC_SIZE 4
#define RXE_MAX_HDR_LENGTH 80

/* Base Transport Header */
struct rxe_bth
FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved
FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved
{
uint8_t opcode;
uint8_t flags;
uint16_t pkey;
uint32_t qpn;
uint32_t apsn;
};

#define BTH_TVER 0x0
#define BTH_DEF_PKEY 0xffff

#define BTH_SE_MASK 0x80
#define BTH_MIG_MASK 0x40
#define BTH_PAD_MASK 0x30
#define BTH_TVER_MASK 0x0f
#define BTH_FECN_MASK 0x80000000
#define BTH_BECN_MASK 0x40000000
#define BTH_RESV6A_MASK 0x3f000000
#define BTH_QPN_MASK 0x00ffffff
#define BTH_ACK_MASK 0x80000000
#define BTH_RESV7_MASK 0x7f000000
#define BTH_PSN_MASK 0x00ffffff
FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved

/**
* @class InfiniBandLayer
* Represents an InfiniBand protocol layer
*/
class InfiniBandLayer : public Layer
FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved
{
public:

InfiniBandLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
: Layer(data, dataLen, prevLayer, packet, Infiniband)
{}

InfiniBandLayer(uint8_t opcode, int se, int mig, int pad, uint16_t pkey, uint32_t qpn, int ack_req,
uint32_t psn);
FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved

rxe_bth* getBthHeader() const
{
return reinterpret_cast<rxe_bth*>(m_Data);
}
FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved

uint8_t getOpcode() const;
void setOpcode(uint8_t opcode) const;
uint8_t getSe() const;
void setSe(int se) const;
uint8_t getMig() const;
void setMig(uint8_t mig) const;
uint8_t getPad() const;
void setPad(uint8_t pad) const;
uint8_t getTver() const;
void setTver(uint8_t tver) const;
uint16_t getPkey() const;
void setPkey(uint16_t pkey) const;
uint32_t getQpn() const;
void setQpn(uint32_t qpn) const;
int getFecn() const;
FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved
void setfecn(int fecn) const;
int getBecn() const;
void setbecn(int becn) const;
FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved
uint8_t getResv6a() const;
void setResv6a() const;
int getAck() const;
void setAck(int ack) const;
void setResv7() const;
FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved
uint32_t getPsn() const;
void setPsn(uint32_t psn) const;

void parseNextLayer() override;

size_t getHeaderLen() const override
{
return sizeof(rxe_bth);
}

/**
* Calculate @ref udphdr#headerChecksum field
*/
FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved
void computeCalculateFields() override;

std::string toString() const override;

OsiModelLayer getOsiModelLayer() const override
{
return OsiModelTransportLayer;
}

static inline bool isInfiniBandPort(uint16_t port)
{
return (port == 4791);
}
};

} // namespace pcpp
5 changes: 5 additions & 0 deletions Packet++/header/ProtocolType.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,11 @@ namespace pcpp
*/
const ProtocolType WireGuard = 56;

/*
* infiniband protocol
FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved
*/
const ProtocolType Infiniband = 57;
FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved

/**
* An enum representing OSI model layers
*/
Expand Down
201 changes: 201 additions & 0 deletions Packet++/src/InfiniBandLayer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
#include "InfiniBandLayer.h"
#include "PayloadLayer.h"
#include "PacketUtils.h"
#include "Logger.h"
#include <string.h>
#include "EndianPortable.h"

namespace pcpp
{

InfiniBandLayer::InfiniBandLayer(uint8_t opcode, int se, int mig, int pad, uint16_t pkey, uint32_t qpn, int ack_req,
uint32_t psn)
{
const size_t headerLen = sizeof(rxe_bth);
m_DataLen = headerLen;
m_Data = new uint8_t[headerLen];
memset(m_Data, 0, headerLen);
rxe_bth* bthHdr = reinterpret_cast<rxe_bth*>(m_Data);

bthHdr->opcode = opcode;
bthHdr->flags = (pad << 4) & BTH_PAD_MASK;
if (se)
bthHdr->flags |= BTH_SE_MASK;
if (mig)
bthHdr->flags |= BTH_MIG_MASK;
bthHdr->pkey = htobe16(pkey);
bthHdr->qpn = htobe32(qpn & BTH_QPN_MASK);
psn &= BTH_PSN_MASK;
if (ack_req)
psn |= BTH_ACK_MASK;
bthHdr->apsn = htobe32(psn);
m_Protocol = Infiniband;
}

void InfiniBandLayer::parseNextLayer()
{
if (m_DataLen <= sizeof(rxe_bth))
return;

uint8_t* bthData = m_Data + sizeof(rxe_bth);
size_t bthDataLen = m_DataLen - sizeof(rxe_bth);

m_NextLayer = new PayloadLayer(bthData, bthDataLen, this, m_Packet);
}

void InfiniBandLayer::computeCalculateFields()
{}
FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved

std::string InfiniBandLayer::toString() const
{
std::ostringstream ss;
ss << "InfiniBand Layer, Opcode: " << getOpcode();
FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved
return ss.str();
}


uint8_t InfiniBandLayer::getOpcode() const
{
return getBthHeader()->opcode;
}

void InfiniBandLayer::setOpcode(uint8_t opcode) const
{
getBthHeader()->opcode = opcode;
}

uint8_t InfiniBandLayer::getSe() const
{
return 0 != (BTH_SE_MASK & getBthHeader()->flags);
}

void InfiniBandLayer::setSe(int se) const
{
if (se)
getBthHeader()->flags |= BTH_SE_MASK;
else
getBthHeader()->flags &= ~BTH_SE_MASK;
}

uint8_t InfiniBandLayer::getMig() const
{
return 0 != (BTH_MIG_MASK & getBthHeader()->flags);
}

void InfiniBandLayer::setMig(uint8_t mig) const
{
if (mig)
getBthHeader()->flags |= BTH_MIG_MASK;
else
getBthHeader()->flags &= ~BTH_MIG_MASK;
}

uint8_t InfiniBandLayer::getPad() const
{
return (BTH_PAD_MASK & getBthHeader()->flags) >> 4;
}

void InfiniBandLayer::setPad(uint8_t pad) const
{
getBthHeader()->flags = (BTH_PAD_MASK & (pad << 4)) | (~BTH_PAD_MASK & getBthHeader()->flags);
}

uint8_t InfiniBandLayer::getTver() const
{
return BTH_TVER_MASK & getBthHeader()->flags;
}

void InfiniBandLayer::setTver(uint8_t tver) const
{
getBthHeader()->flags = (BTH_TVER_MASK & tver) | (~BTH_TVER_MASK & getBthHeader()->flags);
}

uint16_t InfiniBandLayer::getPkey() const
{
return be16toh(getBthHeader()->pkey);
}

void InfiniBandLayer::setPkey(uint16_t pkey) const
{
getBthHeader()->pkey = htobe16(pkey);
}

uint32_t InfiniBandLayer::getQpn() const
{
return BTH_QPN_MASK & be32toh(getBthHeader()->qpn);
}

void InfiniBandLayer::setQpn(uint32_t qpn) const
{

FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved
uint32_t resvqpn = be32toh(getBthHeader()->qpn);

getBthHeader()->qpn = htobe32((BTH_QPN_MASK & qpn) | (~BTH_QPN_MASK & resvqpn));
}

int InfiniBandLayer::getFecn() const
{
return 0 != (htobe32(BTH_FECN_MASK) & getBthHeader()->qpn);
}

void InfiniBandLayer::setfecn(int fecn) const
{
if (fecn)
getBthHeader()->qpn |= htobe32(BTH_FECN_MASK);
else
getBthHeader()->qpn &= ~htobe32(BTH_FECN_MASK);
}

int InfiniBandLayer::getBecn() const
{
return 0 != (htobe32(BTH_BECN_MASK) & getBthHeader()->qpn);
}

void InfiniBandLayer::setbecn(int becn) const
{
if (becn)
getBthHeader()->qpn |= htobe32(BTH_BECN_MASK);
else
getBthHeader()->qpn &= ~htobe32(BTH_BECN_MASK);
}

uint8_t InfiniBandLayer::getResv6a() const
{
return (BTH_RESV6A_MASK & be32toh(getBthHeader()->qpn)) >> 24;
}

void InfiniBandLayer::setResv6a() const
{
getBthHeader()->qpn = htobe32(~BTH_RESV6A_MASK);
}

int InfiniBandLayer::getAck() const
{
return 0 != (htobe32(BTH_ACK_MASK) & getBthHeader()->apsn);
}

void InfiniBandLayer::setAck(int ack) const
{
if (ack)
getBthHeader()->apsn |= htobe32(BTH_ACK_MASK);
else
getBthHeader()->apsn &= ~htobe32(BTH_ACK_MASK);
}

void InfiniBandLayer::setResv7() const
{
getBthHeader()->apsn &= ~htobe32(BTH_RESV7_MASK);
}

uint32_t InfiniBandLayer::getPsn() const
{
return BTH_PSN_MASK & be32toh(getBthHeader()->apsn);
}

void InfiniBandLayer::setPsn(uint32_t psn) const
{
uint32_t apsn = be32toh(getBthHeader()->apsn);

getBthHeader()->apsn = htobe32((BTH_PSN_MASK & psn) | (~BTH_PSN_MASK & apsn));
}
} // namespace pcpp
3 changes: 3 additions & 0 deletions Packet++/src/UdpLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "PayloadLayer.h"
#include "IPv4Layer.h"
#include "IPv6Layer.h"
#include "InfiniBandLayer.h"
#include "DnsLayer.h"
#include "DhcpLayer.h"
#include "DhcpV6Layer.h"
Expand Down Expand Up @@ -142,6 +143,8 @@ namespace pcpp
if (!m_NextLayer)
m_NextLayer = new PayloadLayer(udpData, udpDataLen, this, m_Packet);
}
else if (InfiniBandLayer::isInfiniBandPort(portDst))
FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved
m_NextLayer = new InfiniBandLayer(udpData, udpDataLen, this, m_Packet);
else
m_NextLayer = new PayloadLayer(udpData, udpDataLen, this, m_Packet);
}
Expand Down
1 change: 1 addition & 0 deletions Tests/Packet++Test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ add_executable(
Tests/TcpTests.cpp
Tests/TelnetTests.cpp
Tests/TpktTests.cpp
Tests/InfiniBandTests.cpp
FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved
Tests/VlanMplsTests.cpp
Tests/VrrpTest.cpp
Tests/WakeOnLanTests.cpp
Expand Down
3 changes: 3 additions & 0 deletions Tests/Packet++Test/TestDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,6 @@ PTF_TEST_CASE(WireGuardCookieReplyParsingTest);
PTF_TEST_CASE(WireGuardTransportDataParsingTest);
PTF_TEST_CASE(WireGuardCreationTest);
PTF_TEST_CASE(WireGuardEditTest);

// Implemented in InfiniBandTests.cpp
PTF_TEST_CASE(InfiniBandPacketParsing);
Loading
Loading