cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
toe_utils.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2016 -- 2021 IBM Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
30 #include "toe_utils.hpp"
31 
32 
35 #define THIS_NAME "ToeUtils"
36 
37 
43 const char *getEventName(EventType evType) {
44  switch (evType) {
45  case TX_EVENT:
46  return "TX";
47  case RT_EVENT:
48  return "RT";
49  case ACK_EVENT:
50  return "ACK";
51  case SYN_EVENT:
52  return "SYN";
53  case SYN_ACK_EVENT:
54  return "SYN_ACK";
55  case FIN_EVENT:
56  return "";
57  case RST_EVENT:
58  return "";
59  case ACK_NODELAY_EVENT:
60  return "ACK_NODELAY";
61  default:
62  return "ERROR: UNKNOWN EVENT!";
63  }
64 }
65 
66 
73 void printFourTuple(const char *callerName, int src, FourTuple fourTuple) {
74  SocketPair socketPair;
75  switch (src) {
76  case FROM_RXe:
77  socketPair.src.addr = byteSwap32(fourTuple.theirIp);
78  socketPair.src.port = byteSwap16(fourTuple.theirPort);
79  socketPair.dst.addr = byteSwap32(fourTuple.myIp);
80  socketPair.dst.port = byteSwap16(fourTuple.myPort);
81  break;
82  case FROM_TAi:
83  socketPair.src.addr = byteSwap32(fourTuple.myIp);
84  socketPair.src.port = byteSwap16(fourTuple.myPort);
85  socketPair.dst.addr = byteSwap32(fourTuple.theirIp);
86  socketPair.dst.port = byteSwap16(fourTuple.theirPort);
87  break;
88  default:
89  printFatal(callerName, "Unknown request source %d.\n", src);
90  break;
91  }
92  printSockPair(callerName, socketPair);
93 }
94 
Ip4Addr addr
Definition: nts_types.hpp:209
Ly4Port port
Definition: nts_types.hpp:210
SockAddr dst
Definition: nts_types.hpp:249
SockAddr src
Definition: nts_types.hpp:248
void printFourTuple(const char *callerName, int src, FourTuple fourTuple)
Print a socket pair association from an internal FourTuple encoding.
Definition: toe_utils.cpp:73
EventType
Definition: toe.hpp:273
const char * getEventName(EventType evType)
Returns the name of an enum-based event as a user friendly string.
Definition: toe_utils.cpp:43
@ RST_EVENT
Definition: toe.hpp:274
@ SYN_EVENT
Definition: toe.hpp:273
@ ACK_EVENT
Definition: toe.hpp:273
@ FIN_EVENT
Definition: toe.hpp:274
@ SYN_ACK_EVENT
Definition: toe.hpp:274
@ TX_EVENT
Definition: toe.hpp:273
@ RT_EVENT
Definition: toe.hpp:273
@ ACK_NODELAY_EVENT
Definition: toe.hpp:274
#define FROM_TAi
Definition: nts_types.hpp:381
#define FROM_RXe
Definition: nts_types.hpp:380
void printSockPair(const char *callerName, SocketPair sockPair)
Print a socket pair association.
Definition: nts_utils.cpp:114
#define printFatal(callerName, format,...)
A macro to print a fatal error message and exit.
Definition: nts_utils.hpp:208
: Utilities and helpers for the TCP Offload Engine (TOE)
ap_uint< 32 > byteSwap32(ap_uint< 32 > inputVector)
Definition: udp.cpp:78
ap_uint< 16 > byteSwap16(ap_uint< 16 > inputVector)
Definition: udp.cpp:82