All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sir_socket.h
Go to the documentation of this file.
1 /*
2  * sirius_socket.h
3  *
4  * Created on: Mar 6, 2014
5  * Author: root
6  */
7 
8 
9 #ifndef SIRIUS_SOCKET_H_
10 #define SIRIUS_SOCKET_H_
11 
12 #include <cvmx.h>
13 #include <cvmx-version.h>
14 #include <cvmx-rwlock.h>
16 #include "socket/sir_socket_misc.h"
17 #include "tcp/sir_tcp_includes.h"
18 #include "udp/sir_udp_includes.h"
19 
20 #define SIR_SO_HANDLE_ID 0xdeadbeef12345678ULL
21 
22 // Error related issues
23 #define set_last_error(err) sir_errno = err
24 
25 #define SIRIUS_SLOW_TIMER_INTERVAL 500
26 #define SIRIUS_FAST_TIMER_INTERVAL 100
27 #define MAX_TXOVERFLOW_SIZE (64*1024)
28 #define MAX_UDP_DEMO_TIME 8ull // Max UDP demo time is 8 hour
29 
30 
31 #define CVMX_FPA_SOCKET_POOL CVMX_FPA_PACKET_POOL
32 
33 #define POW2_ENTRIES_SOCKET 16 // 2^16 = 65536 entries in hash table for sockets
34 #define POW2_ENTRIES_BOUNDSOCKET 8 // 2^8=256 Entries in hash table for bound sockets
35 #define FD_TO_INDEX(fd) (((fd) >> 8) & ((1<<POW2_ENTRIES_BOUNDSOCKET)-1))
36 
38 
40 class CSirius : public CSocketMisc
41 {
42  friend class CSiriusTCP;
43 private:
44  struct TGlobalVar
45  {
46  cvmx_spinlock_t tPortConfigLock;
47  int64_t i64Signature;
48  };
49 
50  // Bookkeeping for 500 ms slow timer
51  struct sir_timer_slow
52  {
53  uint64_t ui64Ticks;
54  };
55 
56  // Bookkeeping for 10 ms slow timer
57  struct sir_timer_fast
58  {
59  uint64_t ui64Ticks;
60  };
61 
62 
63  char m_cMemoryName[40];
64  char m_cLookupFdName[40];
65  int m_iInstance;
66  int m_iMaxTXOverflowSize;
67  sir_timer_t m_tMaxUDPTime; // Max allowed time when UDP/RAW in demo mode
68 
69  CCoremask m_cCoremask;
70  ISirius *m_pISirius;
71  uint8_t m_ui8UnusedSlowTimer;
72  uint8_t m_ui8UnusedFastTimer;
73  uint8_t m_ui8UnusedRetransmit;
74  //TIPAddr m_tIPV4MappedPrefix; // IPV4 mapped IPV6 address prefix, comes in handy
75  //TIPAddr m_tIPV4MappedMask; // IPV4 mapped IPV6 address mask, comes in handy
76 
77  CVMX_SHARED static int m_iDiagStart; // shared between all cores
78  CVMX_SHARED static int m_iDiagStop;
79 
80  CVMX_SHARED static int m_iNrOfPoolResourcesInUse;
81 
82  TGlobalVar *m_ptGlobalVarStorage;
83  CTashTable<TDoubleID, sizeof (sir_so_socket_t)> m_cBoundSockets; // Bookkeeping for sockets that have been bound by So_Bind
84  CTashTable<TDoubleID, sizeof (sir_so_socket_t)> m_cSockets; // Bookkeeping for all sockets that are not listen sockets.
85  CLookupTable2Fd m_cUdpSrcPrt2Fd; // Lookup table for udp src-prt -> fd
86  CLookupTable2Fd m_cTcpSrcPrt2Fd; // Lookup table for tcp src-prt -> fd
87  CLookupTable2Fd m_cProtocol2Fd; // Lookup table for protocol -> fd (raw sockets)
88  CSiriusMemList m_cLocStorage; // Storage for UDP/RAW data that is handled by this core
89 
90  bool Handle_Timing_Slow();
91  bool Handle_Timing_Fast();
92  int SocketsAreListening(sir_ip_sockaddr_t &tSockaddr, int iProtocol, int &iSocketType);
93  sir_so_socket_t *SecureGetSocketAndSwitchTag(int fd, bool bSocketIsBound = false);
94  void RemoveSocketResource(sir_so_socket_t *ptSocket);
95  bool RemoveSocketPort(sir_so_socket_t *ptSocket);
96  bool RemoveSocket(int fd);
97  int CalculateMSS(sir_so_socket_t *ptSocket);
98  static bool Handle_Unused_Slow_Timer_Static(cvmx_wqe_t *pWQE, void *pThis);
99  bool Handle_Unused_Slow_Timer(cvmx_wqe_t *pWQE);
100  static bool Handle_Unused_Fast_Timer_Static(cvmx_wqe_t *pWQE, void *pThis);
101  bool Handle_Unused_Fast_Timer(cvmx_wqe_t *pWQE);
102  static bool Handle_Unused_Retransmit_Static(cvmx_wqe_t *pWQE, void *pThis);
103  bool Handle_Unused_Retransmit(cvmx_wqe_t *pWQE);
104  bool LockBoundSocket(int fd);
105  bool UnlockBoundSocket(int fd);
106  bool TransferFragmentedList(CSiriusMemList *ptDestMemList, CSiriusMemList *ptSrcMemList);
107  bool DeleteFragmentedList(CSiriusMemList *ptMemList);
108 
109 public:
110 
112 
115  {
116  uint64_t ui64RxPackets;
117  uint64_t ui64RxPacketsOOO;
118  uint64_t ui64TxPackets;
120  uint64_t ui64TxRTPackets;
121  };
122 
124 
132  int Init(int iGroup, void *pCSiriusI, ILogging *pILogging = NULL);
133 
135 
142  bool Handle_Packet(cvmx_wqe_t *pWQE, CSiriusMemList *ptDestList = NULL);
143 
145 
147  int GetLastError();
148 
150 
162  int So_Accept(int fd, sir_ip_sockaddr_t *ptSockaddr);
163 
165 
176  int So_Socket(int domain, int type, int protocol);
177 
179 
196  int So_Bind (int fd, sir_ip_sockaddr_t *ptSockaddr);
197 
199 
219  int So_BindOverload (int fd, sir_ip_sockaddr_t *ptSockaddr, const int iPortNr);
220 
222 
230  int So_Listen(int fd, int backlog);
231 
233 
249  int So_Connect(int fd, const sir_ip_sockaddr_t *ptSockaddr);
250 
252 
258  int So_Close(int fd);
259 
261 
267  int So_Abort(int fd);
268 
270 
278  int So_Notify(int fd, void *pReference);
279 
281 
288  void* So_Notify(int fd);
289 
291 
305  int So_Recv(int fd, char *pBuf, int iLen, int iFlags);
306 
308 
325  int So_RecvFrom(int fd, char *pBuf, int iLen, int iFlags, sir_ip_sockaddr_t *ptSrc_Addr);
326 
328 
341  int So_RecvFast(int fd, int iLen, CSiriusMemList *pMemList);
342 
344 
357  int So_RecvFromFast(int fd, int iLen, CSiriusMemList *pMemList, sir_ip_sockaddr_t *ptSrc_Addr);
358 
360 
375  int So_SendTo(int fd, char *pBuf, int iLen, const sir_ip_sockaddr_t *ptSockaddr = NULL);
376 
378 
385  int So_CanSend(int fd);
386 
388 
407  int So_SendToFast(int fd, CSiriusMemList *pMemList, const sir_ip_sockaddr_t *ptSockaddr = NULL, CSiriusMemList *ptRemains = NULL);
408 
410 
428  int So_SendToFastRetransmit(int fd, CSiriusMemList *ptMemList, const sir_ip_sockaddr_t *ptSockAddr, void *pVoid, int iSize, int iGrp = -1);
429 
431 
441  uint32_t So_GetAppTag(int fd);
442 
444 
452  int So_SetAppTag(int fd, uint32_t ui32AppTag);
453 
455 
463  int So_GetAvailableData(int fd, EPayload_Indicator ePayloadIndicator);
464 
465 
467 
477  int So_SetSockOpt(int fd, ESockOptLevel eSockLevel, ESockOptName eSockOptName, char *pValue, int iValueLength);
478 
480 
490  int So_GetSockOpt(int fd, ESockOptLevel eSockLevel, ESockOptName eSockOptName, char *pValue, int iValueLength);
491 
493 
500  int So_GetSockName(int fd, sir_ip_sockaddr_t *ptSockaddr);
501 
503 
510  sir_tcp_tcb* So_GetTCB(int fd);
511 
512  int So_PushOverflowQueue(int fd, void *pContext);
513 
514 
516 
520  bool AddPort(int iPortNr);
521 
523 
534  bool AddPort(int iPortNr, int iIpv4NrOfArpEntries, int iIpv4NrOfVlans,
535  int iIpv6NrOfCacheEntriesPow2, int iIpv6NrOfInterfaceEntries,
536  int iIpv6NrOfRouterEntries, int iIpv6NrOfPrefixEntries,
537  bool bIpv6SlaacEnabled);
538 
540 
546  bool AddIPV6Vlan(int iPortNr, uint16_t ui16VLAN);
547 
549 
553 
555 
564  bool AddIPV4Address(int iPortNr, uint32_t ui32IP, uint32_t ui32Gateway, uint32_t ui32Netmask, uint16_t ui16VLan = 0);
565 
567 
576  bool AddIPV4Address(int iPortNr, uint32_t ui32IP, uint32_t ui32Gateway, uint8_t ui8BitMask, uint16_t ui16VLan);
577 
579 
586  bool RemoveIPV4Address(int iPortNr, uint32_t ui32IP, uint16_t ui16VLan);
587 
588 
590 
599  bool AddIPV6Address(int iPortNr, TIPAddr tIP, TIPAddr tGateway, uint8_t ui8BitMask, uint16_t ui16VLan = 0);
600 
601 
602 
604 
611  bool RemoveIPV6Address(int iPortNr, TIPAddr tIp, uint16_t ui16VLan = 0);
612 
613 
615 
623  bool GetPortConfig(EPortConfig ePortConfig, int iPortNr, struct sir_port_config_t *ptPortConfig, bool bFirst = false);
624 
626 
628  void EnableTimeStamp(bool bTimeStampOn);
629 
631 
634  bool TimeStampEnabled();
635 
637 
639  void EnableSACK(bool bSACKOn);
640 
642 
645  bool SACKEnabled();
646 
648 
650  int AddAndGetSocketResourcesInUse(int iIncrement);
651 
653 
655  int AddAndGetcSocketResourcesInUse(int iIncrement);
656 
658 
660  int AddAndGetcBoundSocketResourcesInUse(int iIncrement);
661 
662 
664 
666  int GetArpHashResources(int iPortNr);
667 
669 
672  bool DisplayARPStats(int iPortNr);
673 
675 
677  int GetNrOfResourcesInUse(EResourceType eResourceType, int iAux);
678 
680 
682  void *GetReferenceOfResource(EResourceType eResourceType, int iAux);
683 
685 
690  void Diagnostics(uint16_t ui16Selection, uint16_t *pOffset, uint8_t *pui8Bytes, int iLength);
691 };
692 
693 #endif /* SIRIUS_SOCKET_H_ */
Sirius interface class.
Definition: sir_isocket.h:20
int So_SendToFast(int fd, CSiriusMemList *pMemList, const sir_ip_sockaddr_t *ptSockaddr=NULL, CSiriusMemList *ptRemains=NULL)
Send a memory list on a socket (using CSiriusMemList)
bool AddIPV6Vlan(int iPortNr, uint16_t ui16VLAN)
Add a VLAN to a physical port. This VLAN will only be used under an IPV6 configuration.
int So_BindOverload(int fd, sir_ip_sockaddr_t *ptSockaddr, const int iPortNr)
Bind the socket to physical port and overload the source IP address with the value in ptSockaddr-&gt;ui3...
int So_RecvFrom(int fd, char *pBuf, int iLen, int iFlags, sir_ip_sockaddr_t *ptSrc_Addr)
Get message from socket.
EPayload_Indicator
Payload indicator.
int So_Recv(int fd, char *pBuf, int iLen, int iFlags)
Get data from socket.
void EnableTimeStamp(bool bTimeStampOn)
Enable the time stamp option. Defaults to ON.
void EnableSACK(bool bSACKOn)
Enable the SACK option. Defaults to ON.
int AddAndGetcBoundSocketResourcesInUse(int iIncrement)
Diagnostic function. Get nr of resources in cBoundSocket hash table.
int So_GetAvailableData(int fd, EPayload_Indicator ePayloadIndicator)
Get the size of data that is waiting in the receive queue of the specified session.
Sirius Misc class.
int GetNrOfResourcesInUse(EResourceType eResourceType, int iAux)
Diagnostic function. Get resource in use.
int So_CanSend(int fd)
Check the number of bytes that can be send on this session.
bool AddIPV4Address(int iPortNr, uint32_t ui32IP, uint32_t ui32Gateway, uint32_t ui32Netmask, uint16_t ui16VLan=0)
Add an IPV4 address to a physical port.
int AddAndGetcSocketResourcesInUse(int iIncrement)
Diagnostic function. Get nr of resources in cSocket hash table.
uint64_t ui64TxAckOnlyPackets
Total number of packets that have not been retransmitted.
Definition: sir_socket.h:119
int GetLastError()
Retrieve last error from stack.
void Diagnostics(uint16_t ui16Selection, uint16_t *pOffset, uint8_t *pui8Bytes, int iLength)
Diagnostic function. Display diagnostic information on the console.
uint64_t ui64RxPacketsOOO
Total number of received packets that are out of order.
Definition: sir_socket.h:117
bool Handle_Packet(cvmx_wqe_t *pWQE, CSiriusMemList *ptDestList=NULL)
Process packet designated in pWQE.
uint32_t So_GetAppTag(int fd)
Switch to the application tag.
uint64_t ui64TxRTPackets
Total number of packets that have been retransmitted.
Definition: sir_socket.h:120
bool SACKEnabled()
Check if SACK option is on.
int So_Bind(int fd, sir_ip_sockaddr_t *ptSockaddr)
Bind the socket to a local IP address and port number.
ESockOptName
SetSocknames enumeration.
bool DisplayARPStats(int iPortNr)
Diagnostic function. Display ARP status of physical port.
Struct contains an IPV4 or an IPV6 address.
Definition: packet-defines.h:7
int So_Notify(int fd, void *pReference)
Set the context for the fd.
int So_GetSockOpt(int fd, ESockOptLevel eSockLevel, ESockOptName eSockOptName, char *pValue, int iValueLength)
Get socket option.
void * pMemList
Definition: sir_cmemlist.h:16
Struct contains address information.
int So_Close(int fd)
Closes the file descriptor so that it no longer refers to a session.
int So_SetAppTag(int fd, uint32_t ui32AppTag)
Set the application tag.
int So_Connect(int fd, const sir_ip_sockaddr_t *ptSockaddr)
Connect the socket to the address specified in ptSockAddr.
int So_SendToFastRetransmit(int fd, CSiriusMemList *ptMemList, const sir_ip_sockaddr_t *ptSockAddr, void *pVoid, int iSize, int iGrp=-1)
Send a memory list on a UDP or RAW socket (using CSiriusMemList) and do not delete the packet after i...
int AddAndGetSocketResourcesInUse(int iIncrement)
Diagnostic function. Get nr of allocated memory segments by sockets.
bool AddIPV6Address(int iPortNr, TIPAddr tIP, TIPAddr tGateway, uint8_t ui8BitMask, uint16_t ui16VLan=0)
Add an IPV6 address to a physical port.
int So_GetSockName(int fd, sir_ip_sockaddr_t *ptSockaddr)
Get the current address to which the socket is bound.
int So_Abort(int fd)
Abort the file descriptor. It is terminated immediately.
uint64_t sir_timer_t
Sirius main class.
Definition: sir_socket.h:40
int So_Socket(int domain, int type, int protocol)
Create a new socket.
int So_SendTo(int fd, char *pBuf, int iLen, const sir_ip_sockaddr_t *ptSockaddr=NULL)
Send data on a socket.
bool RemoveIPV6Address(int iPortNr, TIPAddr tIp, uint16_t ui16VLan=0)
Remove an IPV6 address from a physical port.
bool GetPortConfig(EPortConfig ePortConfig, int iPortNr, struct sir_port_config_t *ptPortConfig, bool bFirst=false)
Get configuration info from a physical port.
int Init(int iGroup, void *pCSiriusI, ILogging *pILogging=NULL)
Initialize Sirius TCP stack.
int So_PushOverflowQueue(int fd, void *pContext)
TCP Statistics.
Definition: sir_socket.h:114
bool AddPort(int iPortNr)
Add port configuration to Sirius stack using default parameters.
bool TimeStampEnabled()
Check if time stamp option is on.
EResourceType
ESockOptLevel
SetSocklevels.
Most important class of Sirius. Used to maintain and process all kinds of queues. ...
Definition: sir_memlist.h:51
EPortConfig
Enumerations for port config.
int So_SetSockOpt(int fd, ESockOptLevel eSockLevel, ESockOptName eSockOptName, char *pValue, int iValueLength)
Set socket option.
int So_RecvFast(int fd, int iLen, CSiriusMemList *pMemList)
Get message from socket (using CSiriusMemList)
int So_RecvFromFast(int fd, int iLen, CSiriusMemList *pMemList, sir_ip_sockaddr_t *ptSrc_Addr)
Get message from socket (using CSiriusMemList)
sir_tcp_tcb * So_GetTCB(int fd)
Get pointer to TCB which belongs to the file descriptor.
uint64_t ui64TxPackets
Total number of transmitted packets.
Definition: sir_socket.h:118
CSystemInfo::prt_linkstatus_t GetLinkStatus(int iPortNr)
Get link status of physical port.
bool RemoveIPV4Address(int iPortNr, uint32_t ui32IP, uint16_t ui16VLan)
Remove an IPV4 address from a physical port.
int So_Listen(int fd, int backlog)
Prepare the socket to be used for accept incoming connections using So_Accept.
uint64_t ui64RxPackets
Total number of received packets.
Definition: sir_socket.h:116
int So_Accept(int fd, sir_ip_sockaddr_t *ptSockaddr)
Create a new connection on socket fd.
int GetArpHashResources(int iPortNr)
Diagnostic function. Get nr of resources in ARP hash table.
void * GetReferenceOfResource(EResourceType eResourceType, int iAux)
Helper function. Get reference of designated resource.