All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sir_memlist.h
Go to the documentation of this file.
1 /*
2  * sir_memlist.h
3  *
4  * Created on: Apr 4, 2014
5  * Author: root
6  */
7 
8 #ifndef SIR_MEMLIST_H_
9 #define SIR_MEMLIST_H_
10 
11 //#define TEST_CSiriusMemList
12 
13 #include <cvmx.h>
14 #include <cvmx-helper.h>
15 #include <cvmx-csr.h>
16 #include <cvmx-fpa.h>
17 #include <cvmx-pow.h>
18 #include <cvmx-atomic.h>
19 #include <cvmx-utils.h>
20 #include <common.h>
21 
22 #include "common/sir_common.h"
24 #include "common/sir_timer.h"
25 #include "ip/packet-defines.h"
26 
27 //#define MEMLIST_VALIDATE ///< Enable this define for validating the memlist after each process step
28 #define CHECKBYTE 0x55
29 
30 #define CVMX_FPA_MEMLIST_POOL CVMX_FPA_PACKET_POOL
31 #define CVMX_FPA_MEMLIST_POOL_SIZE CVMX_FPA_PACKET_POOL_SIZE
32 
33 #define MEMLISTSEGSIZE ((1 + (sizeof (sir_memlist_seg) - 1)/CVMX_CACHE_LINE_SIZE)*CVMX_CACHE_LINE_SIZE)
34 #define MEMLISTMEMORYSIZE (CVMX_FPA_MEMLIST_POOL_SIZE - MEMLISTSEGSIZE)
35 
36 typedef struct
38 {
39  unsigned char ucMem[MEMLISTMEMORYSIZE];
42 
43 
44 #ifdef TEST_CSiriusMemList
45  void SiriusMemList_Test(void);
46 #endif
47 
52 {
53 public:
55  uint64_t m_ui64PhysEndList;
57  uint64_t m_ui64MarkedItem;
58  uint64_t m_ui64ID1;
59  uint64_t m_ui64ID2;
60  uint64_t m_ui64ID3;
61  uint64_t m_ui64ID4;
62  uint64_t m_ui64ID5;
64  bool m_bIsIPV6;
71  bool m_bIsVlan;
73  bool m_bTagIsSet;
75  uint16_t m_ui16SrcPrt;
76  uint16_t m_ui16DstPrt;
77  uint16_t m_ui16Vlan;
78  uint8_t m_ui8Protocol;
79  CSiriusMemList();
80  ~CSiriusMemList();
81 
83  void Init();
85 
88  void ReInit();
89 
91 
94  void SetTag(uint32_t ui32Tag);
95 
97 
107  sir_memlist_seg * GetNewMemListMember(uint32_t ui32PayloadOffset, uint32_t ui32PayloadSize, unsigned char *pBuffer = NULL);
108 
110 
114  bool DeleteMemList(void);
115 
117 
123  static bool DeleteMember(sir_memlist_seg *ptMember, bool bOnlyFreeFromList = false);
124 
126 
131  sir_memlist_seg * DeleteCurrentMemListMember(bool bOnlyFreeFromList = false);
132 
134 
139  bool AdjustStartOfPayload(int iAdjustment);
140 
142 
148  static bool AdjustStartOfPayload(sir_memlist_seg *ptMember, int iAdjustment);
149 
151 
155  bool RemovePayload(int iAdjustment);
156 
158 
168  sir_memlist_seg * CreateMemList(char* pBuffer, uint32_t ui32PayloadSize, uint32_t ui32MaxCopySizeFirst, uint32_t ui32MaxCopySizeNotFirst, uint32_t ui32PayloadOffsetFirst, uint32_t ui32PayloadOffsetNotFirst);
169 
170 
172 
177  bool ChopPayload(int iAdjustment);
178 
180 
186  static bool ChopPayload(sir_memlist_seg *ptMember, int iAdjustment);
187 
189 
195  cvmx_wqe_t * AddAuxiliaryMemory(int iAuxilaryPool);
196 
198 
202  static void FreeAuxiliaryMemory(void *pAuxMemory, int iPoolNr);
203 
205  /*
206  * @return Number of bytes
207  */
209 
211 
222  sir_memlist_seg* MergePackets(sir_memlist_seg *ptMember, int32_t ui32MaxSize, bool bRetransmit);
223 
225 
229  sir_memlist_seg* GetFirstMember(bool bAdjustCurrentMember = true);
230 
232 
236 
238 
242  sir_memlist_seg* GetNextMember(bool bAdjustCurrentMember = true);
243 
245 
249  sir_memlist_seg* GetPreviousMember(bool bAdjustCurrentMember = true);
250 
252 
256  sir_memlist_seg* GetLastMember(bool bAdjustCurrentMember = true);
257 
259 
262  void SetMarkedMember(sir_memlist_seg *ptMarkMember);
263 
265 
269 
271 
276  bool AddToEndOfList(CSiriusMemList *ptSourceList);
277 
279 
284  bool AddMemberAtCurrentPosition(sir_memlist_seg *ptSource, bool bAddAfterCurrent=false);
285 
287 
292  bool AddMemberAtEndOfList(sir_memlist_seg *ptSource);
293 
295 
301  uint32_t AddMemberAtSortedPosition(sir_memlist_seg *ptSource, uint32_t ui32StartSEQ, bool &bPacketFilledGap);
302 
303 
305 
308  int GetPayloadSize (EPayload_Indicator ePayloadType);
309 
311 
314 
316 
319  static int GetMaxCopySize(int iPayloadOffset);
320 
322 
325  char *GetCurrentAddress();
326 
328  void DumpMemList();
329 
331  void DumpCurrentPayload();
332 
334 
337  static int32_t GetAndAddNrOfMemListResources(int iIncrement);
338 
340 
343  static int32_t GetAndAddNrOfAuxilaryResources(int iIncrement);
344 
346 
349  sir_memlist_seg* DuplicateCurrentMember(int iPayloadSize);
350 
352  /* @param[in] pData Pointer to the data buffer that will receive the data
353  * @param[in] iMaxSize Maximum number of bytes to transfer
354  * @param[in] bRemovePayload. If true, transfered data is removed from the memlist and empty members are deleted
355  * @return Number of bytes transferred from memlist to data buffer
356  */
357  int TransferPayload(char *pData, int iMaxSize, bool bRemovePayload=false);
358 
360  /* @param[in] pDestMemList Pointer to the designated destination list.
361  * @param[in] iMaxSize Maximum number of bytes to transfer.
362  * @return Number of bytes transferred from memlist to data buffer
363  */
364  int TransferPayload(CSiriusMemList *pDestMemList, int iMaxSize);
365 
367 
373  uint32_t CalcChecksum(int iOffset, int iLength, uint32_t ui32StartChecksum, bool bFinish);
374 
375  void operator=(const CSiriusMemList *ptMemList)
376  {
377  this->DeleteMemList();
378  this->AddToEndOfList((CSiriusMemList *)ptMemList);
379  }
380 
381  void operator+=(const CSiriusMemList *ptMemList)
382  {
383  this->AddToEndOfList((CSiriusMemList *)ptMemList);
384  }
385 
387 
390  bool Validate();
391 
392 private:
393  int m_iSequenceNr;
394  CVMX_SHARED static int32_t m_iNrOfMemListPoolInUse; // Nr of MEMLIST pools in use by this class
395  CVMX_SHARED static int32_t m_iNrOfAuxilaryPoolInUse; // Nr of AUXILARY MEM pool in use by this class
396  static bool ValidateMember(sir_memlist_seg *ptMember);
397  bool CheckSEQStartEnd(void);
398  void PrefetchNext(void);
399 };
400 
401 #endif /* SIR_MEMLIST_H_ */
static int32_t GetAndAddNrOfAuxilaryResources(int iIncrement)
Get and add the number use resources for auxiliary memory.
static bool DeleteMember(sir_memlist_seg *ptMember, bool bOnlyFreeFromList=false)
Delete the designated memlist member from the memlist.
void Init()
Initialize the memlist.
EPayload_Indicator
Payload indicator.
uint64_t m_ui64PhysCurrentList
Physical address of current entry in list.
Definition: sir_memlist.h:56
CSiriusMemList()
Constructor to protect user against himself ;-0.
uint32_t CalcChecksum(int iOffset, int iLength, uint32_t ui32StartChecksum, bool bFinish)
Calculate the one&#39;s complements checksum.
uint64_t m_ui64ID2
Identifier for tashtable.
Definition: sir_memlist.h:59
int GetPayloadSizeCurrentMember()
Get number of payload bytes in the current memlist member.
sir_memlist_seg * GetMarkedMember()
Get the designated memlist member that is set as &#39;marked&#39; and set current memlist member to this meml...
uint8_t m_ui8Protocol
Store protocol type of this memlist.
Definition: sir_memlist.h:78
void SetTag(uint32_t ui32Tag)
Set the atomic tag value for this memlist. This.
uint32_t m_ui32PortNrIncoming
Physical port number on which data is coming in.
Definition: sir_memlist.h:67
uint64_t m_ui64MarkedItem
Start address of last item in reassembly list that is contiguous.
Definition: sir_memlist.h:57
uint16_t m_ui16SrcPrt
Far UDP/TCP prt.
Definition: sir_memlist.h:75
bool RemovePayload(int iAdjustment)
Remove payload from the memlist, starting at the current member and remove members if necessary...
static void FreeAuxiliaryMemory(void *pAuxMemory, int iPoolNr)
Remove the auxiliary memory.
sir_memlist_seg * DeleteCurrentMemListMember(bool bOnlyFreeFromList=false)
Delete the current memlist member from the memlist.
int TransferPayload(char *pData, int iMaxSize, bool bRemovePayload=false)
Transfer payload from a memory list to a data buffer.
void SetMarkedMember(sir_memlist_seg *ptMarkMember)
Set the designated memlist member as &#39;marked&#39; and set current memlist member to this memlist member...
sir_memlist_seg * MergePackets(sir_memlist_seg *ptMember, int32_t ui32MaxSize, bool bRetransmit)
Merge the designated memlist member with the current memlist member.
sir_memlist_seg * GetCurrentMember()
Get pointer of current memlist member in list.
bool Validate()
Validate the memlist (Diagnostioc function.
sir_memlist_seg * CreateMemList(char *pBuffer, uint32_t ui32PayloadSize, uint32_t ui32MaxCopySizeFirst, uint32_t ui32MaxCopySizeNotFirst, uint32_t ui32PayloadOffsetFirst, uint32_t ui32PayloadOffsetNotFirst)
Create new memlist members and add them to the memlist.
sir_memlist_seg tSeg
Definition: sir_memlist.h:40
char * GetCurrentAddress()
Get the start address of the payload of the current member.
int m_iPayloadSize
Total payload size of members in list.
Definition: sir_memlist.h:70
#define MEMLISTMEMORYSIZE
Subtract bookkeeping size from original size.
Definition: sir_memlist.h:34
bool m_bIsVlan
Packet has VLAN.
Definition: sir_memlist.h:71
int GetPayloadSize(EPayload_Indicator ePayloadType)
Get number of payload bytes.
static int32_t GetAndAddNrOfMemListResources(int iIncrement)
Get and add the number of resources in use by the memory list.
TIPAddr m_tDestIPAddr
Near IP address.
Definition: sir_memlist.h:66
uint64_t m_ui64ID4
Identifier for tashtable.
Definition: sir_memlist.h:61
void operator=(const CSiriusMemList *ptMemList)
Definition: sir_memlist.h:375
sir_memlist_seg * GetNextMember(bool bAdjustCurrentMember=true)
Get pointer of next memlist member in list and set current memlist member to the next memlist member...
Struct contains an IPV4 or an IPV6 address.
Definition: packet-defines.h:7
cvmx_wqe_t * AddAuxiliaryMemory(int iAuxilaryPool)
Add an auxiliary memory element to the current memlist member.
sir_memlist_seg * GetNewMemListMember(uint32_t ui32PayloadOffset, uint32_t ui32PayloadSize, unsigned char *pBuffer=NULL)
Create a new memlist member.
bool m_bDeleteModifiedCurrentItem
Indicates if a delete advanced the current item.
Definition: sir_memlist.h:72
sir_memlist_seg * GetFirstMember(bool bAdjustCurrentMember=true)
Get pointer of first memlist member in list and set current memlist member to the first memlist membe...
sir_memlist_seg * DuplicateCurrentMember(int iPayloadSize)
Duplicate a memlist member.
bool DeleteMemList(void)
Delete the memlist.
bool AddToEndOfList(CSiriusMemList *ptSourceList)
Add a designated memlist at the end of the memlist.
void ReInit()
Re-initialize the memlist.
uint32_t AddMemberAtSortedPosition(sir_memlist_seg *ptSource, uint32_t ui32StartSEQ, bool &bPacketFilledGap)
Add a designated memlist member at a position, based upon its SEQ value.
uint32_t GetPayloadOffset()
Get payload offset for the current member.
bool AddMemberAtCurrentPosition(sir_memlist_seg *ptSource, bool bAddAfterCurrent=false)
Add a designated memlist member before (default) or after the current memlist member.
~CSiriusMemList()
Destructor to protect user against himself ;-0.
static int GetMaxCopySize(int iPayloadOffset)
Get the maximum available space in a memlist member at a given payload offset.
bool m_bReassemblyComplete
Definition: sir_memlist.h:63
uint32_t m_ui32Tag
Tag value when this list was created.
Definition: sir_memlist.h:74
uint64_t m_ui64PhysEndList
Physical address of last entry in list.
Definition: sir_memlist.h:55
bool m_bIsIPV6
Memlist is IPV6 type.
Definition: sir_memlist.h:64
uint64_t m_ui64ID5
Identifier for tashtable.
Definition: sir_memlist.h:62
TIPAddr m_tSourceIPAddr
Far IP address.
Definition: sir_memlist.h:65
uint16_t m_ui16Vlan
When vlan valid, this is the Vlan ID.
Definition: sir_memlist.h:77
bool m_bTagIsSet
A tag was set for this memlist, so it might be tested for validity.
Definition: sir_memlist.h:73
void DumpMemList()
Dump a summary of the memlist to the standard output.
Most important class of Sirius. Used to maintain and process all kinds of queues. ...
Definition: sir_memlist.h:51
void operator+=(const CSiriusMemList *ptMemList)
Definition: sir_memlist.h:381
Definition of a.
Definition: sir_memlist.h:37
uint64_t m_ui64ID3
Identifier for tashtable.
Definition: sir_memlist.h:60
sir_memlist_seg * GetPreviousMember(bool bAdjustCurrentMember=true)
Get pointer of previous memlist member in list and set current memlist member to the previous memlist...
uint16_t m_ui16DstPrt
Near UDP/TCP prt.
Definition: sir_memlist.h:76
void DumpCurrentPayload()
Dump the payload of the current member to the standard output.
uint32_t m_ui32GroupNrIncoming
Group to which this packet is send.
Definition: sir_memlist.h:68
int m_iNrOfMembersInList
Nr of members in list.
Definition: sir_memlist.h:69
bool ChopPayload(int iAdjustment)
Chop off iAdjustment number of payload bytes from the current memlist member.
sir_memlist_seg * GetLastMember(bool bAdjustCurrentMember=true)
Get pointer of last memlist member in list and set current memlist member to the last memlist member...
uint64_t m_ui64PhysStartList
Physical address of first entry in list.
Definition: sir_memlist.h:54
uint64_t m_ui64ID1
Identifier for tashtable.
Definition: sir_memlist.h:58
bool AdjustStartOfPayload(int iAdjustment)
Increase the space available for payload of the current memlist member.
bool AddMemberAtEndOfList(sir_memlist_seg *ptSource)
Add a designated memlist member at then end of the memlist.