All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sir_ip.h
Go to the documentation of this file.
1 /*
2  * sirius_ip.h
3  *
4  * Created on: Mar 6, 2014
5  * Author: root
6  */
7 
8 #ifndef SIRIUS_IP_H_
9 #define SIRIUS_IP_H_
10 
11 #include <cvmx.h>
12 #include <cvmx-version.h>
13 #include <cvmx-atomic.h>
14 #include <cvmx-rwlock.h>
15 #include <cvmx-tim.h>
16 #include <cvmx-access.h>
17 #include <common.h>
19 #include "tcp/sir_tcp_includes.h"
20 #include "eth/sir_eth_includes.h"
21 #include "ip/packet-defines.h"
22 #include "socket/sir_socket_defs.h"
23 
24 #define DEFAULTMTUSIZE 1500 // Set the default MTU size
25 #define MAXDATAGRAMSIZE 65536 // Max IP datagram size
26 #define IPREASSTIMEOUT 15000 // IP reassembly timeout is 15 secs
27 
28 #define CVMX_FPA_IPREASS_POOL CVMX_FPA_PACKET_POOL
29 #define CVMX_FPA_IPREASS_POOL_SIZE CVMX_FPA_PACKET_POOL_SIZE
30 
31 // IP error codes
32 #define SIR_IP_OK 0
33 #define SIR_IP_NOHEADERSPACE 1 // No space for IP header in buffer
34 #define SIR_IP_MAXSIZEEXCEEDED 2 // Max datagram size exceeded
35 #define SIR_IP_ETHERROR 3 // Ip layer received error from ethernet layer
36 #define SIR_IP_NOPAYLOADMEMORY 4 // No payload memory available
37 #define SIR_IP_MEMTOOSMALL 5 // Allocated memory too small for efficient use
38 #define SIR_IP_NULLPOINTER 6 // No allocated memory
39 #define SIR_IP_NOARP 7 // No ARP entry available for this IP address
40 
41 // Struct for IP reassembly timeout timer packet
43 {
44  uint64_t ui64Ticks;
47 };
48 
49 class CSiriusIP
50 {
51  friend class CSirius;
52 public:
53  static CSiriusIP* Instance(void); // Singleton
54  bool Init(int iInstance);
55  void Diagnostics(uint16_t Selection, uint16_t *pOffset, uint8_t *pBytes, int iLength);
56  bool IP_Timing();
57  bool PacketIsARP(cvmx_wqe_t* pWQE);
58  bool PacketIsICMP(cvmx_wqe_t* pWQE);
59  bool HandleARPandICMP(int iPortNr, cvmx_wqe_t* pWQE);
60  uint64_t GetMACOfPort(int iPortNr);
61  static int IPHeaderSize();
62  CSiriusMemList* IPV4HandleIncoming(cvmx_wqe_t *pWQE, bool &bDigested);
63  bool IPGetSocketAddr(CSiriusMemList *ptMemList, sir_ip_sockaddr_t &tSockaddr);
64  int IPSendIP(uint32_t ui32DestIP, uint32_t ui32SrcIP, uint32_t ui32OrgSrcIP, char* pBuffer, uint32_t ui32PayloadSize, uint8_t ui8Protocol, int iPortNr = -1);
65  int IPSendIP(uint32_t ui32DestIP, uint32_t ui32SrcIP, uint32_t ui32OrgSrcIP, CSiriusMemList *pMemList, uint32_t ui32PayloadSize, uint8_t ui8Protocol, volatile void *pAddr, int iPortNr = -1 );
66  int IPSendIPFast(TSendAccelerate *ptAccelerate, uint32_t ui32DestIP, uint32_t ui32SrcIP, uint32_t ui32OrgSrcIP, CSiriusMemList *pMemList, uint32_t ui32PayloadSize, uint8_t ui8Protocol, volatile void *pAddr, int iPortNr);
67 // int IPSendIPFast(sir_so_socket_t *ptSocket, uint32_t ui32DestIP, CSiriusMemList *pMemList, uint32_t ui32PayloadSize, volatile void *pAddr, bool bIsAddr);
68  uint16_t IPGetMTUSize();
69  void IPSetMTUSize(uint16_t ui16MTUSize);
70  CSiriusMemList* IPHandle_Packet(cvmx_wqe_t *pWQE, bool &bPacketDigested);
71  bool IPDeleteFragmentedList(CSiriusMemList *ptMemList);
72  bool IPTransferFragmentedList(CSiriusMemList *ptDestMemList, CSiriusMemList *ptSrcMemList);
73  bool IPSetReAssTimerUnused(uint8_t ui8ReAssTim);
74  static bool IPHandle_Unused_Static(cvmx_wqe_t *pWQE, void *pThis);
75  int IPGetAndAddNrOfResourcesInUse(int iIncrement);
76 
78 private:
79  struct TGlobalVar
80  {
81  cvmx_rwlock_wp_lock_t tRW_ListenSockLock; // RW lock
82  int32_t i32Identification; // Counter for Identification generation in case of fragmentation
83  uint32_t ui32MtuSize; // MTU size for this system
84  bool bAlreadyInited;
85  };
86 
87  CTashTable<TDoubleID, sizeof (CSiriusMemList)> m_cIpReAssHash; // Bookkeeping for IP reassembly
88 
89  TGlobalVar *m_ptGlobalVarStorage;
90  uint32_t m_ui32IpOffset;
91  int m_iInstance;
92  CCoremask m_cCoremask;
93  uint8_t m_ui8Unused; // Unused value for reassembly timeout timer
94  CVMX_SHARED static int m_iDiagStart; // shared between cores
95  CVMX_SHARED static int m_iDiagStop;
96 
97  CVMX_SHARED static int32_t m_iNrOfIPReasstPoolInUse; // Nr of IPReassembly pools in use by this class
98 
99  uint16_t GetNextIdentification();
100  int CreateIPHeader(char *pBuffer, uint32_t ui32Payloadsize, uint32_t ui32DestIP, uint32_t ui32SrcIP, uint8_t ui8Protocol);
101  int FillIPHeaderFragment(char *pBuffer, uint16_t ui16Id, uint8_t ui8Flags, uint16_t ui16FragmentOffset);
102  bool IPHandle_Unused(cvmx_wqe_t *pWQE);
103 };
104 #endif /* SIRIUS_IP_H_ */
bool PacketIsARP(cvmx_wqe_t *pWQE)
uint64_t ui64Ticks
Definition: sir_ip.h:44
static CSiriusIP * Instance(void)
sir_timer_t tEndTime
Definition: sir_ip.h:45
static bool IPHandle_Unused_Static(cvmx_wqe_t *pWQE, void *pThis)
bool IPDeleteFragmentedList(CSiriusMemList *ptMemList)
bool IPTransferFragmentedList(CSiriusMemList *ptDestMemList, CSiriusMemList *ptSrcMemList)
bool IPGetSocketAddr(CSiriusMemList *ptMemList, sir_ip_sockaddr_t &tSockaddr)
TDoubleID tDoubleID
Definition: sir_ip.h:46
int IPSendIPFast(TSendAccelerate *ptAccelerate, uint32_t ui32DestIP, uint32_t ui32SrcIP, uint32_t ui32OrgSrcIP, CSiriusMemList *pMemList, uint32_t ui32PayloadSize, uint8_t ui8Protocol, volatile void *pAddr, int iPortNr)
bool IP_Timing()
int IPSendIP(uint32_t ui32DestIP, uint32_t ui32SrcIP, uint32_t ui32OrgSrcIP, char *pBuffer, uint32_t ui32PayloadSize, uint8_t ui8Protocol, int iPortNr=-1)
bool IPSetReAssTimerUnused(uint8_t ui8ReAssTim)
CSiriusMemList * IPHandle_Packet(cvmx_wqe_t *pWQE, bool &bPacketDigested)
int IPGetAndAddNrOfResourcesInUse(int iIncrement)
bool PacketIsICMP(cvmx_wqe_t *pWQE)
CSiriusMemList * IPV4HandleIncoming(cvmx_wqe_t *pWQE, bool &bDigested)
void * pMemList
Definition: sir_cmemlist.h:16
Struct contains address information.
bool HandleARPandICMP(int iPortNr, cvmx_wqe_t *pWQE)
uint16_t IPGetMTUSize()
uint64_t sir_timer_t
Sirius main class.
Definition: sir_socket.h:40
void IPSetMTUSize(uint16_t ui16MTUSize)
bool m_bAcceptFarAddresses
Definition: sir_ip.h:77
bool Init(int iInstance)
static int IPHeaderSize()
Most important class of Sirius. Used to maintain and process all kinds of queues. ...
Definition: sir_memlist.h:51
uint64_t GetMACOfPort(int iPortNr)
void Diagnostics(uint16_t Selection, uint16_t *pOffset, uint8_t *pBytes, int iLength)