cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
SimArpPacket.hpp
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 #ifndef _SIM_ARP_PACKET_
31 #define _SIM_ARP_PACKET_
32 
33 #include "nts.hpp"
34 #include "nts_utils.hpp"
35 
36 
37 
49 class SimArpPacket {
50 
51  private:
52  int len; // In bytes
53  std::deque<AxisArp> pktQ; // A double-ended queue to store ARP chunks
54  const char *myName;
55 
56  // Set the length of this ARP packet (in bytes)
57  void setLen(int pktLen) {
58  this->len = pktLen;
59  }
60  // Get the length of this ARP packet (in bytes)
61  int getLen() {
62  return this->len;
63  }
64 
65  // Clear the content of the ARP packet queue
66  void clear() {
67  this->pktQ.clear();
68  this->len = 0;
69  }
70  // Return the front chunk element of the ARP packet but do not remove it from the queue
71  AxisArp front() {
72  return this->pktQ.front();
73  }
74  // Remove the first chunk element of the ARP packet queue
75  void pop_front() {
76  this->pktQ.pop_front();
77  }
78  // Add an element at the end of the ARP packet queue
79  void push_back(AxisArp arpChunk) {
80  this->pktQ.push_back(arpChunk);
81  }
82 
83  public:
84 
85  // Default Constructor: Constructs a packet of 'pktLen' bytes.
86  SimArpPacket(int pktLen) {
87  this->myName = "SimArpPacket";
88  setLen(0);
89  if (pktLen > 0 && pktLen <= MTU) {
90  int noBytes = pktLen;
91  while(noBytes > 8) {
92  pushChunk(AxisArp(0x0000000000000000, 0xFF, 0));
93  noBytes -= 8;
94  }
95  pushChunk(AxisArp(0x0000000000000000, lenToLE_tKeep(noBytes), TLAST));
96  }
97  }
99  this->myName = "SimArpPacket";
100  setLen(0);
101  }
102 
103  // Add a chunk of bytes at the end of the double-ended queue
104  void pushChunk(AxisArp arpChunk) {
105  if (this->size() > 0) {
106  // Always clear 'TLAST' bit of previous chunck
107  this->pktQ[this->size()-1].setLE_TLast(0);
108  }
109  this->push_back(arpChunk);
110  this->setLen(this->getLen() + arpChunk.getLen());
111  }
112  // Return the chunk at the front of the queue and remove that chunk from the queue
114  AxisArp headingChunk = this->front();
115  this->pop_front();
116  setLen(getLen() - headingChunk.getLen());
117  return headingChunk;
118  }
119  // Return the length of the ARP packet (in bytes)
120  int length() {
121  return this->len;
122  }
123  // Return the number of chunks in the ARP packet (in axis-words)
124  int size() {
125  return this->pktQ.size();
126  }
127 
128  // Set the Hardware Type (HTYPE) field
129  void setHardwareType(ArpHwType htype) { pktQ[0].setArpHardwareType(htype); }
130  // Get the Hardware Type (HTYPE) field
131  ArpHwType getHardwareType() { return pktQ[0].getArpHardwareType(); }
132  // Set the Protocol type (PTYPE) field
133  void setProtocolType(ArpProtType ptype) { pktQ[0].setArpProtocolType(ptype); }
134  // Get the Protocol type (PTYPE) field
135  ArpProtType getProtocolType() { return pktQ[0].getArpProtocolType(); }
136  // Set the Hardware Address Length (HLEN) field
137  void setHardwareLength(ArpHwLen hlen) { pktQ[0].setArpHardwareLength(hlen);}
138  ArpHwLen getHardwareLength() { return pktQ[0].getArpHardwareLength(); }
139  // Set-Get Protocol Address length (PLEN) field
140  void setProtocolLength(ArpProtLen plen) { pktQ[0].setArpProtocolLength(plen);}
141  ArpProtLen getProtocolLength() { return pktQ[0].getArpProtocolLength(); }
142  // Set the Operation code (OPER) field
143  void setOperation(ArpOper oper) { pktQ[0].setArpOperation(oper); }
144  // Get the Operation code (OPER) field
145  ArpProtType getOperation() { return pktQ[0].getArpOperation(); }
146  // Set-Get the Sender Hardware Address (SHA)
147  void setSenderHwAddr(ArpSendHwAddr sha) { pktQ[1].setArpSenderHwAddr(sha); }
148  ArpSendHwAddr getSenderHwAddr() { return pktQ[1].getArpSenderHwAddr(); }
149  // Set the Sender Protocol Address (SPA)
150  void setSenderProtAddr(ArpSendProtAddr spa) { pktQ[1].setArpSenderProtAddrHi(spa);
151  pktQ[2].setArpSenderProtAddrLo(spa); }
152  // Get the Sender Protocol Address (SPA)
153  ArpSendProtAddr getSenderProtAddr() { ArpSendProtAddr spaHi = ((ArpSendProtAddr)(pktQ[1].getArpSenderProtAddrHi()) << 16);
154  ArpSendProtAddr spaLo = ((ArpSendProtAddr)(pktQ[2].getArpSenderProtAddrLo()) << 0);
155  return(spaHi | spaLo); }
156  // Set the Target Hardware Address (SHA)
157  void setTargetHwAddr(ArpTargHwAddr tha) { pktQ[2].setArpTargetHwAddr(tha); }
158  // Get the Target Hardware Address (SHA)
159  ArpTargHwAddr getTargetHwAddr() { return pktQ[2].getArpTargetHwAddr(); }
160  // Set the Target Protocol Address (TPA)
161  void setTargetProtAddr(ArpTargProtAddr tpa) { pktQ[3].setArpTargetProtAddr(tpa); }
162  // Get the Target Protocol Address (TPA)
163  ArpTargProtAddr getTargetProtAddr() { return pktQ[3].getArpTargetProtAddr(); }
164 
165 }; // End-of: SimArpPacket
166 
167 #endif
168 
int getLen() const
Definition: AxisRaw.hpp:411
Class ARP Packet for simulation.
ArpTargHwAddr getTargetHwAddr()
void setSenderProtAddr(ArpSendProtAddr spa)
ArpProtType getProtocolType()
void pushChunk(AxisArp arpChunk)
void setHardwareType(ArpHwType htype)
void setTargetHwAddr(ArpTargHwAddr tha)
ArpTargProtAddr getTargetProtAddr()
void setSenderHwAddr(ArpSendHwAddr sha)
ArpProtLen getProtocolLength()
void setTargetProtAddr(ArpTargProtAddr tpa)
SimArpPacket(int pktLen)
AxisArp pullChunk()
ArpSendProtAddr getSenderProtAddr()
void setProtocolLength(ArpProtLen plen)
ArpProtType getOperation()
ArpSendHwAddr getSenderHwAddr()
void setHardwareLength(ArpHwLen hlen)
ArpHwType getHardwareType()
void setOperation(ArpOper oper)
ArpHwLen getHardwareLength()
void setProtocolType(ArpProtType ptype)
ap_uint< 16 > ArpProtType
Definition: AxisArp.hpp:96
ap_uint< 48 > ArpSendHwAddr
Definition: AxisArp.hpp:100
LE_tKeep lenToLE_tKeep(ap_uint< 4 > noValidBytes)
A function to set a number of '1' in an 8-bit field. It is used here to set the number of valid bytes...
Definition: nts_utils.cpp:307
ap_uint< 8 > ArpProtLen
Definition: AxisArp.hpp:98
ap_uint< 32 > ArpSendProtAddr
Definition: AxisArp.hpp:101
ap_uint< 32 > ArpTargProtAddr
Definition: AxisArp.hpp:103
ap_uint< 8 > ArpHwLen
Definition: AxisArp.hpp:97
ap_uint< 16 > ArpOper
Definition: AxisArp.hpp:99
ap_uint< 48 > ArpTargHwAddr
Definition: AxisArp.hpp:102
ap_uint< 16 > ArpHwType
Definition: AxisArp.hpp:95
#define TLAST
Definition: AxisRaw.hpp:116
: Definition of the Network Transport Stack (NTS) component as if it was an HLS IP core.
: Utilities and helpers for the Network-Transport-Stack (NTS) components.
#define MTU
Definition: udp.hpp:71