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 15 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 @@ -19,6 +19,7 @@ add_library(
src/IcmpLayer.cpp
src/IcmpV6Layer.cpp
src/IgmpLayer.cpp
src/InfiniBandLayer.cpp
src/IPReassembly.cpp
src/IPSecLayer.cpp
src/IPv4Layer.cpp
Expand Down
288 changes: 288 additions & 0 deletions Packet++/header/InfiniBandLayer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,288 @@
#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.
*/
FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved

#define RXE_ICRC_SIZE 4
#define RXE_MAX_HDR_LENGTH 80

/**
* @struct bth
* Represents an Base Transport Header
*/
#pragma pack(push, 1)
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;
};
#pragma pack(pop)

#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:
/**
* A constructor that creates the layer from an existing packet raw data
* @param[in] data A pointer to the raw data (will be casted to bth_header)
* @param[in] dataLen Size of the data in bytes
* @param[in] prevLayer A pointer to the previous layer
* @param[in] packet A pointer to the Packet instance where layer will be stored in
*/
InfiniBandLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
: Layer(data, dataLen, prevLayer, packet, Infiniband)
{}

/**
* A constructor that creates a new rxe_bth header and allocates the data
* @param[in] opcode The operation code
* @param[in] se The solicited event
* @param[in] mig The migration state
* @param[in] pad The pad count
* @param[in] pkey The partition key
* @param[in] qpn The destination queue pair (QP) number
* @param[in] ack_req The acknowledgment request
* @param[in] psn The packet sequence number
FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved
*/
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

/**
* Get a pointer to the BTH header. Notice this points directly to the data, so every change will change
* the actual packet data
* @return A pointer to the bth_header
*/
rxe_bth* getBthHeader() const
{
return reinterpret_cast<rxe_bth*>(m_Data);
}
FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved

/**
* @return The operation code which defines the interpretation of the remaining header and payload bytes
*/
uint8_t getOpcode() const;

/**
* Set operation code
* @param[in] opcode The opcode to set
*/
void setOpcode(uint8_t opcode) const;

/**
* @return solicited event that the responder shall invoke the CQ event handler
*/
uint8_t getSe() const;

/**
* Set solicited event
* @param[in] se The solicited event to set
*/
void setSe(int se) const;
FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved

/**
* @return migreq which used to communicate migration state
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is migreq? 🤔

*/
uint8_t getMig() const;

/**
* Set migreq
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto: What is migreq?

* @param[in] mig The migration state to set. If set to one, indicates the connection or EE context has been
* migrated; if set to zero, it means there is no change in the current migration state.
*/
void setMig(uint8_t mig) const;

/**
* @return PadCount which Packet payloads are sent as a multiple of 4-byte quantities.
* Pad count indicates the number of pad bytes - 0 to 3 - that are appended to the packetpayload.
* Pads are used to “stretch” the payload (payloads may be zero or more bytes in length) to be a multiple of 4
* bytes
*/
uint8_t getPad() const;

/**
* Set PadCount
* @param[in] pad The PadCount to set
*/
void setPad(uint8_t pad) const;

/**
* @return Transport Header Version that specifies the version of the IBA Transport used for this packet
*/
uint8_t getTver() const;

/**
* Set Transport Header Version
* @param[in] tvr The transport header version to set
*/
void setTver(uint8_t tver) const;

/**
* @return partition key identifying the partition
* that the destination QP (RC, UC, UD, XRC) or EE Context (RD) is a member.
*/
uint16_t getPkey() const;

/**
* Set partition key
* @param[in] pkey The partition key to set
*/
void setPkey(uint16_t pkey) const;

/**
* @return destination queue pair (QP) identifier
*/
uint32_t getQpn() const;

/**
* Set Queue Pair Number
* @param[in] qpn The queue pair number to set
*/
void setQpn(uint32_t qpn) const;

/**
* @return FECN
* F (FECN): 0 indicates that a FECN indication was not received.
* 1 indicates that the packet went through a point of congestion
*/
int getFecn() const;
FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved

/**
* Set Fecn
FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved
* @param[in] fecn The FECN to set
*/
void setfecn(int fecn) const;

/**
* @return BECN
* B (BECN): 0 the packet did not go through a point of congestion or went
* through a point of congestion but was not marked. 1 indicates that the
* packet indicated by this header was subject to forward congestion. The B
* bit is set in an ACK or CN BTH
*/
int getBecn() const;

/**
* Set BECN
* @param[in] becn The BECN to set
*/
void setbecn(int becn) const;
FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved

/**
* @return Reserved (variant) - 6 bits. Transmitted as 0, ignored on receive.
*/
uint8_t getResv6a() const;

/**
* Set Reserved 6 bits
*/
void setResv6a() const;
FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved

/**
* @return ackreq that requests responder to schedule an acknowledgment on the associated QP.
*/
int getAck() const;

/**
* Set acknowledgment for requests
* @param[in] ack The acknowledgment to set
*/
void setAck(int ack) const;

/**
* Transmitted as 0, ignored on receive.
*/
void setResv7() const;
FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved

/**
* @return packet sequence number that is used to identify the position of a packet
* within a sequence of packets.
*/
uint32_t getPsn() const;

/**
* Set packet sequence number
* @param[in] psn The packet sequence number to set
*/
void setPsn(uint32_t psn) const;

/**
* Currently identifies the following next layers sets to PayloadLayer
*/
FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved
void parseNextLayer() override;

/**
* @return Size of rxe_bth header
*/
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;
}

/**
* A static method that check whether is inifiniband RoCE port
* @param[in] port The port from UDP destination port
* @return True if the port is inifiniband RoCE and can represent an rxe packet
*/
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
*/
const ProtocolType Infiniband = 57;
FlashBarryAllen marked this conversation as resolved.
Show resolved Hide resolved

/**
* An enum representing OSI model layers
*/
Expand Down
Loading
Loading