cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
test_dhcp_client.cpp File Reference

: Testbench for the DHCP-client. More...

#include "../src/dhcp_client.hpp"
#include <iostream>
#include <fstream>
Include dependency graph for test_dhcp_client.cpp:

Go to the source code of this file.

Functions

void getOffer (stream< UdpWord > &outData)
 
void getAck (stream< UdpWord > &outData)
 
int main ()
 

Detailed Description

: Testbench for the DHCP-client.

Copyright (c) 2015, Xilinx, Inc.

All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

System: : cloudFPGA Component : Shell, Network Transport Stack (NTS) Language : Vivado HLS

Definition in file test_dhcp_client.cpp.

Function Documentation

◆ getAck()

void getAck ( stream< UdpWord > &  outData)

Definition at line 151 of file test_dhcp_client.cpp.

152 {
153  static ap_uint<6> wordCount = 0;
154  static bool done = false;
155 
156  UdpWord sendWord;
157  if (!done)
158  {
159  switch (wordCount)
160  {
161  case 0:
162  sendWord.tdata = 0x34aad42800060102;
163  break;
164  case 1: //seconds, flags, clientip
165  case 5: //clientMac padding + severhostname
166  case 6:
167  case 7:
168  case 8:
169  case 9:
170  case 10:
171  case 11:
172  case 12:
173  case 13:
174  case 14:
175  case 15: //boot filename
176  case 16:
177  case 17:
178  case 18:
179  case 19:
180  case 20:
181  case 21:
182  case 22:
183  case 23:
184  case 24:
185  case 25:
186  case 26:
187  case 27:
188  case 28:
189  sendWord.tdata = 0;
190  break;
191  case 2:
192  sendWord.tdata = 0x0105050a0a05050a; //your ip, next server ip
193  break;
194  case 3:
195  sendWord.tdata = 0x0304050600000000;
196  break;
197  case 4:
198  sendWord.tdata = 0x0000000000000102; //clientMac 2nd part
199  break;
200  /*case 13:
201  sendWord.data = 0x6c65707800000000;
202  break;
203  case 14:
204  sendWord.data = 0x0000302e78756e69;
205  break;*/
206  case 29:
207  sendWord.tdata = 0x6353826300000000; //Magic Cookie
208  break;
209  case 30:
210  sendWord.tdata = 0x05050a0436050135; //dhcp option 53, 54
211  break;
212  case 31:
213  sendWord.tdata = 0x0158020000043301; //54, 51, 1
214  break;
215  case 32:
216  sendWord.tdata = 0x0a040300ffffff04; //
217  break;
218  case 33:
219  sendWord.tdata = 0x05050a041c010505; //
220  break;
221  case 34:
222  sendWord.tdata = 0x7265746e69140fff; //1, 28, 15
223  break;
224  case 35:
225  sendWord.tdata = 0x6d6178652e6c616e; //15
226  break;
227  case 36:
228  sendWord.tdata = 0xff67726f2e656c70; //15, done
229  break;
230  case 37:
231  sendWord.tdata = 0; //padding
232  done = true;
233  break;
234 /* case 38:
235  sendWord.data = 0x6863027a68746504; //119
236  break;
237  case 39:
238  sendWord.data = 0x00000000ff04c000; //119, done
239  done = true;
240  break;*/
241  } //switch
242  if (!done)
243  {
244  sendWord.tkeep = 0xff;
245  sendWord.tlast = 0;
246  }
247  else
248  {
249  sendWord.tkeep = 0x0f;
250  sendWord.tlast = 1;
251  }
252  outData.write(sendWord);
253  wordCount++;
254  } //done
255 }
ap_uint< 64 > tdata
ap_uint< 1 > tlast
ap_uint< 8 > tkeep
Here is the caller graph for this function:

◆ getOffer()

void getOffer ( stream< UdpWord > &  outData)

Definition at line 44 of file test_dhcp_client.cpp.

45 {
46  static ap_uint<6> wordCount = 0;
47  static bool done = false;
48 
49  UdpWord sendWord;
50  if (!done)
51  {
52  switch (wordCount)
53  {
54  case 0:
55  sendWord.tdata = 0x34aad42800060102;
56  break;
57  case 1: //seconds, flags, clientip
58  case 5: //clientMac padding + severhostname
59  case 6:
60  case 7:
61  case 8:
62  case 9:
63  case 10:
64  case 11:
65  case 12:
66  case 13:
67  case 14:
68  case 15: //boot filename
69  case 16:
70  case 17:
71  case 18:
72  case 19:
73  case 20:
74  case 21:
75  case 22:
76  case 23:
77  case 24:
78  case 25:
79  case 26:
80  case 27:
81  case 28:
82  sendWord.tdata = 0;
83  break;
84  case 2:
85  sendWord.tdata = 0x0105050a0a05050a; //your ip, next server ip
86  break;
87  case 3:
88  sendWord.tdata = 0x0304050600000000;
89  break;
90  case 4:
91  sendWord.tdata = 0x0000000000000102; //clientMac 2nd part
92  break;
93  /*case 13:
94  sendWord.data = 0x6c65707800000000;
95  break;
96  case 14:
97  sendWord.data = 0x0000302e78756e69;
98  break;*/
99  case 29:
100  sendWord.tdata = 0x6353826300000000; //Magic Cookie
101  break;
102  case 30:
103  sendWord.tdata = 0x05050a0436020135; //dhcp option 53, 54
104  break;
105  case 31:
106  sendWord.tdata = 0x0158020000043301; //54, 51, 58
107  break;
108  case 32:
109  sendWord.tdata = 0x0a040300ffffff04; // 58, 59
110  break;
111  case 33:
112  sendWord.tdata = 0x05050a041c010505; // 59, 1
113  break;
114  case 34:
115  sendWord.tdata = 0x7265746e69140fff; //1, 3, 15
116  break;
117  case 35:
118  sendWord.tdata = 0x6d6178652e6c616e; //15
119  break;
120  case 36:
121  sendWord.tdata = 0xff67726f2e656c70; //15, done
122  break;
123  case 37:
124  sendWord.tdata = 0; //padding
125  done = true;
126  break;
127 /* case 38:
128  sendWord.data = 0x6863027a68746504; //119
129  break;
130  case 39:
131  sendWord.data = 0x00000000ff04c000; //119, done
132  done = true;
133  break;*/
134  } //switch
135  if (!done)
136  {
137  sendWord.tkeep = 0xff;
138  sendWord.tlast = 0;
139  }
140  else
141  {
142  sendWord.tkeep = 0x0f;
143  sendWord.tlast = 1;
144  }
145  outData.write(sendWord);
146  wordCount++;
147  } //done
148 }
Here is the caller graph for this function:

◆ main()

int main ( )

Definition at line 258 of file test_dhcp_client.cpp.

259 {
260  stream<ap_uint<16> > openPort("openPort");
261  stream<bool> confirmPortStatus("confirmPortStatus");
262  //stream<ap_uint<16> >& realeasePort,
263  stream<UdpMeta> dataInMeta("dataInMeta");
264  stream<UdpWord> dataIn("dataIn");
265  stream<UdpMeta> dataOutMeta("dataOutMeta");
266  stream<UdpPLen> dataOutLength("dataOutLength");
267  stream<UdpWord> dataOut("dataOut");
268  ap_uint<32> ipAddressOut;
269  ap_uint<1> dhcpEnable = 0;
270  ap_uint<32> inputIpAddress = 0x0C0C0C0C;
271  ap_uint<48> myMacAddress = 0x010203040506;
272 
273  int count = 0;
274  ap_uint<16> port;
275 
276  ifstream goldenFile;
277  ofstream outputFile;
278 
279  outputFile.open("../../../../test/out.dat");
280  if (!outputFile) {
281  cout << "Error: could not open output vector file." << endl;
282  return -1;
283  }
284  goldenFile.open("../../../../test/out.gold");
285  if (!goldenFile) {
286  cout << "Error: could not open golden output vector file." << endl;
287  return -1;
288  }
289  while (count < 1000) {
290  dhcp_client(
291  dhcpEnable,
292  myMacAddress,
293  ipAddressOut,
294  confirmPortStatus,
295  openPort,
296  dataIn,
297  dataInMeta,
298  dataOut,
299  dataOutMeta,
300  dataOutLength);
301 
302  if (!openPort.empty()) {
303  openPort.read(port);
304  confirmPortStatus.write(true);
305  //std::cout << "Port: " << port << "opened." << std::endl;
306  }
307 
308  if (count == 120)
309  dhcpEnable = 1;
310  else if (count == 800)
311  dhcpEnable = 0;
312  if (count > 200 && count < 300) {
313  //std::cout << "Incoming DHCP offer" << std::endl;
314  getOffer(dataIn);
315  }
316  else if (count > 300) {
317  //std::cout << "Incoming DHCP ACK" << std::endl;
318  getAck(dataIn);
319  }
320  count++;
321  //std::cout << std::hex << count << " - " << ipAddressOut << std::endl;
322  }
323 
324  UdpWord outWord;
325  UdpMeta outMeta;
326  ap_uint<16> outLen;
327  bool wasLast = true;
328  int outCount = 0;
329  uint16_t keepTemp;
330  uint64_t dataTemp;
331  uint16_t lastTemp;
332  int errCount = 0;
333 
334  while (!dataOut.empty()) {
335  if (wasLast && !dataOutMeta.empty()) {
336  dataOutMeta.read(outMeta);
337  std::cout << "Src: " << outMeta.src.addr(31, 24)<< "." << outMeta.src.addr(23, 16) << ".";
338  std::cout << outMeta.src.addr(15, 8)<< "." << outMeta.src.addr(7, 0) << ":";
339  std::cout << ":" << outMeta.src.port << std::endl;
340  std::cout << "Dst: " << outMeta.dst.addr(31, 24)<< "." << outMeta.dst.addr(23, 16) << ".";
341  std::cout << outMeta.dst.addr(15, 8)<< "." << outMeta.dst.addr(7, 0) << ":";
342  std::cout << outMeta.dst.port << std::endl;
343  }
344  if (wasLast && !dataOutLength.empty()) {
345  dataOutLength.read(outLen);
346  std::cout << "Length: " << outLen << std::endl;
347  }
348  dataOut.read(outWord);
349  std::cout << std::hex << std::setfill('0');
350  std::cout << std::setw(8) << ((uint32_t) outWord.tdata(63, 32)) << std::setw(8) << ((uint32_t) outWord.tdata(31, 0)) << "\t";
351  std::cout << std::setw(2) << outWord.tkeep << " " << outWord.tlast << std::endl;
352  wasLast = outWord.tlast;
353 
354  outputFile << std::hex << std::noshowbase;
355  outputFile << std::setfill('0');
356  outputFile << std::setw(8) << ((uint32_t) outWord.tdata(63, 32));
357  outputFile << std::setw(8) << ((uint32_t) outWord.tdata(31, 0));
358  outputFile << " " << std::setw(2) << ((uint32_t) outWord.tkeep) << " ";
359  outputFile << std::setw(1) << ((uint32_t) outWord.tlast) << std::endl;
360 
361  goldenFile >> std::hex >> dataTemp >> keepTemp >> lastTemp;
362 
363  if (outWord.tdata != dataTemp || outWord.tkeep != keepTemp || outWord.tlast != lastTemp) { // Compare results
364  errCount++;
365  cerr << "X";
366  } else {
367  cerr << ".";
368  }
369 
370  outCount++;
371  if (outWord.tlast) {
372  std::cout << "computed length: " << std::dec << (outCount*8) << std::endl;
373  outCount = 0;
374  }
375  }
376 
377  std::cout << std::dec<< "IP Address: " << ipAddressOut(7,0) << "." << ipAddressOut(15,8) << ".";
378  std::cout << ipAddressOut(23,16) << "." << ipAddressOut(31,24) << std::endl;
379  outputFile.close();
380  goldenFile.close();
381  cerr << " done." << endl << endl;
382 
383  printf("#####################################################\n");
384  if (errCount) {
385  printf("## ERROR - TESTBENCH FAILED (RC=%d) !!! ##\n", errCount);
386  errCount = 1;
387  }
388  else
389  printf("## SUCCESSFULL END OF TESTBENCH (RC=0) ##\n");
390 
391  printf("#####################################################\n");
392 
393  return(errCount);
394 
395 }
void dhcp_client(ap_uint< 1 > &piMMIO_This_Enable, ap_uint< 48 > &piMMIO_This_MacAddress, ap_uint< 32 > &poTHIS_Nts_IpAddress, stream< AxisAck > &siUDMX_This_OpnAck, stream< UdpPort > &soTHIS_Udmx_OpnReq, stream< UdpWord > &siUDMX_This_Data, stream< UdpMeta > &siUDMX_This_Meta, stream< UdpWord > &soTHIS_Udmx_Data, stream< UdpMeta > &soTHIS_Udmx_Meta, stream< UdpPort > &soTHIS_Udmx_PLen)
Main process of the DHCP-client.
ap_uint< 16 > port
ap_uint< 32 > addr
SocketAddr src
SocketAddr dst
void getAck(stream< UdpWord > &outData)
void getOffer(stream< UdpWord > &outData)
Here is the call graph for this function: