tree checksum vpatch file split hunks

all signers: asciilifeform diana_coman

antecedents: mt_prng udp_errata_asciilifeform

press order:

udp_genesisasciilifeform diana_coman
udp_errata_asciilifeformasciilifeform diana_coman
udp_fix_ip_nullcharsdiana_coman
mt_prngdiana_coman
udp_testerdiana_coman

patch:

- 0CE47E877E69CDC718556D94802736A36D5289BAC7D5C58F4FAFFC75F0FE8F461F4799705E9B29F89E071C51141BD88B2D73917271170F7FD771ED288AD07215
+ 7FEB3510444D5888F8CD5566F7BEB042274F44E6535C9CC2B3FE05B922D8778E5940911B56CA064490DC67C985476C769ACF23CD25AC62BBFA57EF652D7D7A05
udp/libudp/restrict.adc
(27 . 10)(27 . 10)
5 pragma Restrictions(No_Access_Parameter_Allocators);
6 pragma Restrictions(No_Allocators);
7 pragma Restrictions(No_Asynchronous_Control);
8 pragma Restrictions(No_Calendar);
9 --pragma Restrictions(No_Calendar);
10 pragma Restrictions(No_Coextensions);
11 pragma Restrictions(No_Default_Stream_Attributes);
12 pragma Restrictions(No_Delay);
13 --pragma Restrictions(No_Delay);
14 pragma Restrictions(No_Dispatch);
15 pragma Restrictions(No_Dispatching_Calls);
16 pragma Restrictions(No_Dynamic_Attachment);
(45 . 7)(45 . 6)
18 pragma Restrictions(No_Floating_Point);
19 pragma Restrictions(No_Implementation_Aspect_Specifications);
20 pragma Restrictions(No_Implementation_Units);
21 pragma Restrictions(No_Implicit_Conditionals);
22 pragma Restrictions(No_Implicit_Dynamic_Code);
23 pragma Restrictions(No_Implicit_Heap_Allocations);
24 pragma Restrictions(No_Implicit_Protected_Object_Allocations);
(57 . 7)(56 . 7)
26 pragma Restrictions(No_Nested_Finalization);
27 pragma Restrictions(No_Protected_Type_Allocators);
28 pragma Restrictions(No_Protected_Types);
29 pragma Restrictions(No_Relative_Delay);
30 --pragma Restrictions(No_Relative_Delay);
31 pragma Restrictions(No_Requeue_Statements);
32 pragma Restrictions(No_Secondary_Stack);
33 pragma Restrictions(No_Select_Statements);
(80 . 4)(79 . 5)
35 pragma Restrictions(Simple_Barriers);
36 pragma Restrictions(Static_Priorities);
37 pragma Restrictions(Static_Storage_Size);
38 --pragma Restrictions(No_Implicit_Conditionals);
39 pragma Validity_Checks(ALL_CHECKS);
- DE0CEC9CED66F9D083E9C7DD1F2E02586E36481701F3B8C988F500F521454DC8CA51797961E1E773EDFFB7A96AD6D9B4F277B47AAB056B7E313C23B8677BAFF3
+ 84814D47643F564F51FE5A03835B373812EE8902FA209175522DE3B447C11916C8457B747FEE05B87F05BD9C2C172000717B1621A22999E457E7BC5C4250A1B4
udp/libudp/udp.adb
(18 . 9)(18 . 29)
44 ------------------------------------------------------------------------------
45
46 package body UDP is
47
48 -- Bit-level compare of 2 payloads, returns number of different bits
49 function Bit_Compare(A: in Payload; B: in Payload) return Natural is
50 V : Unsigned_8;
51 Count : Natural := 0;
52 begin
53 for I in Payload'Range loop
54 -- obtain bits that are different
55 V := A(I) xor B(I);
56 -- count the bits that are 1, if any
57 Counting_Loop:
58 while V /= 0 loop
59 Count := Count + Natural((V and Unsigned_8(1)));
60 V := Shift_Right(V, 1);
61 end loop Counting_Loop;
62 end loop;
63
64 return Count;
65 end Bit_Compare;
66
67 -- Generate a human representation of a (local-endian) IP Address
68 function IP_To_String(IP : in IP_Address) return IP_Address_Text is
69 function IP_To_String(IP : in IP_Address)
70 return IP_Address_Text is
71 Text : IP_Address_Text := (others => ' ');
72 begin
73 Unix_UDP_IP_To_String(IP, Text'Address, Text'Length);
(94 . 10)(114 . 10)
75 Close_Socket(S);
76 raise UDP_Failed_Transmit;
77 when others =>
78 -- No eggog, but must check if sent all bytes:
79 if (Result /= Payload'Length) then
80 Close_Socket(S);
81 raise UDP_Truncated_Send;
82 if Result /= Payload'Length then
83 -- fail as message was truncated/not sent in full
84 Close_Socket(S);
85 raise UDP_Truncated_Send;
86 end if;
87 end case;
88 end Transmit;
(107 . 7)(127 . 7)
90 procedure Receive(S : in out Socket;
91 Origin : out Endpoint;
92 Payload_Buf : out Payload;
93 Valid : out Boolean) is
94 Recv_Len : out Unsigned_32) is
95
96 -- Scratch pad (if not successful, the call has no outputs)
97 Incoming_Payload : aliased Payload := (others => 0);
(121 . 7)(141 . 8)
99 Payload_Buf => Incoming_Payload'Address,
100 Payload_Len => Payload'Length);
101 begin
102 Valid := False;
103 -- Valid := False;
104 Recv_Len := 0;
105 case Result is
106 when -1 =>
107 Close_Socket(S);
(133 . 9)(154 . 10)
109 Payload_Buf := Incoming_Payload;
110
111 -- Was a full-length payload?
112 if (Result = Payload'Length) then
113 Valid := True;
114 end if;
115 --if (Result = Payload'Length) then
116 -- Valid := True;
117 --end if;
118 Recv_Len := Unsigned_32( Result );
119 end case;
120 end Receive;
121
- 41D0512D8759CBCB10D753A22A86B6BDAF96FCCF779E2BBDABF4A1C7EFCA7A4F8F9047984D6CC2350B7625715AAC26C0CCD49C7BACA765811E0C0BCC0ABABF22
+ A7E2A069125E5476D4EAFA10C4B674A1776325568DA5700B2E8ADF626F9BB3AA07C28B1435DFF4BE3C085AEF3C963DD90A22C91F3D47ABF4A5B205B0B84AB842
udp/libudp/udp.ads
(20 . 14)(20 . 13)
126 with Interfaces, Interfaces.C; use Interfaces, Interfaces.C;
127 with System; use System;
128
129 generic
130 Payload_Size : in Positive; -- to allow for diff sizes at runtime
131
132 package UDP is
133
134 pragma Preelaborate;
135
136 -- This is subject to debate:
137 Payload_Size : constant Positive := 512;
138
139
140 type Payload is array(1 .. Payload_Size) of Unsigned_8;
141
142 subtype IP_Address is Unsigned_32;
(35 . 6)(34 . 9)
144
145 -- Magic that puts emitter on 'any' local interface
146 INADDR_ANY : constant Unsigned_32 := 0;
147
148 -- Bit-level compare of 2 payloads, returns number of different bits
149 function Bit_Compare(A: in Payload; B: in Payload) return Natural;
150
151 -- An local or remote address:port
152 type Endpoint is
(72 . 10)(74 . 11)
154
155 -- Wait (potentially forever!) for a Payload, via Socket; save its Origin,
156 -- and whether the received Payload was valid (i.e. expected length):
157 -- replaced Valid with actual received length for testing purpose
158 procedure Receive(S : in out Socket;
159 Origin : out Endpoint;
160 Payload_Buf : out Payload;
161 Valid : out Boolean);
162 Recv_Len : out Unsigned_32);
163
164 -- Eggogology:
165 UDP_Invalid_Text_IP : exception;
- 6B46C9CC494C5F0ECCE1C653D6F34AD30D366B0D4A1D9AB169E94FFBC17BE09CAC3DBF85F5B571516161712FD201E50581CD2C247AA5B7442F94B69CFDC907EB
+ 7AE4EC290548713F623A1CAE18025750324170D9B22A618BE1D2A1A95C02C1B10F605EBC109A7983BD14B23B01A497567D5A7796DB212B9F76D209CB4FF5CA14
udp/manifest
(2 . 3)(2 . 4)
170 543081 udp_errata_asciilifeform diana_coman Regrind of asciilifeform's errata on his UDP lib: adds closing socket calls, corrects and adds to comments.
171 543082 udp_fix_nullchars diana_coman Fix for issue in unix_udp.c that returns null characters at end of IPs shorter than 16 characters in length.
172 543083 mt_prng diana_coman Ada implementation of Mersenne Twister pseudorandom number generator + automated tests for it.
173 543084 udp_tester diana_coman Sender and Receiver for testing UDP communication over a range of packet sizes. NB: this makes some changes to UDP lib for *testing* purposes - those changes are NOT required in production.
-
+ 5FDBAE897EB301A711BF95707F329517DB540E34C182A5BEEC96E93D5D0D856CEC2ED6B01C1191F865E8D1C45709A462C70C3005D4AA3676EB445D1479EDF2E5
udp/udp_tester/bin/README
(0 . 0)(1 . 1)
178 Placeholder.
-
+ 50F9B127E6AE2019779520D8998BEA7F559496B1847C7C66B6CE6A6F3FC20DB67D45F1FBF7A9318C86EBBA0694DB73DE168F409D8328A751F3104C1474A83A0D
udp/udp_tester/obj/README
(0 . 0)(1 . 1)
183 obj
-
+ 6B510BCD314548708EF8D5C03595599E1A65A31882876C9ED538C0C92FDB6DC6F5854F35BFC6AD7F569EB225BBCB3ED990830CA21483C4DE37BC527372D78862
udp/udp_tester/tester.gpr
(0 . 0)(1 . 54)
188 -- S.MG, 2018
189 -- Sender for testing UDP transmissions
190
191 with "../libudp/udp.gpr"; -- UDP lib
192 with "../libmt/mt.gpr"; -- mersenne twister prng
193
194 project Tester is
195
196 for Object_Dir use "obj";
197
198 type Mode_Type is ("debug", "release");
199 Mode : Mode_Type := external ("mode", "release");
200
201 for Languages use ("Ada");
202 for Source_Dirs use (".");
203 for Exec_Dir use "bin";
204 for Main use ("udp_sender.adb", "udp_receiver.adb");
205
206 package Compiler is
207 case Mode is
208 when "debug" =>
209 for Switches ("Ada")
210 use ("-g");
211 when "release" =>
212 for Switches ("Ada")
213 use ("-O2", "-fdump-scos", "-gnata", "-fstack-check",
214 "-gnatyd", "-gnatym",
215 "-fdata-sections", "-ffunction-sections");
216 end case;
217 end Compiler;
218
219 package Binder is
220 case Mode is
221 when "debug" =>
222 for Switches ("Ada")
223 use ();
224 when "release" =>
225 for Switches ("Ada")
226 use ("-static");
227 end case;
228 end Binder;
229
230 package Linker is
231 case Mode is
232 when "debug" =>
233 for Switches ("Ada")
234 use ();
235 when "release" =>
236 for Switches ("Ada")
237 use ("-Wl,--gc-sections", "-static");
238 end case;
239 end Linker;
240
241 end Tester;
-
+ 951BDCCFB137311E6CDCFDCDEBD1C8AF3EDB598AE2A28278765BF439F4F6EA497A2592A15C70FCFFD3F11F42B693867ED1A612633907D8C85A3EB1C08D0F2FE1
udp/udp_tester/udp_receiver.adb
(0 . 0)(1 . 12)
246 -- S.MG, 2018
247
248 with UDP_Tester;
249
250 procedure UDP_Receiver is
251 -- Port to listen on
252 Receiver_Port : constant := 9000;
253 begin
254
255 UDP_Tester.Receiver( Receiver_Port );
256
257 end UDP_Receiver;
-
+ 72774E64A2E5FBEE5F5865E2EC24244FBDE193C530203E1B8CE49F1DF80491F03B7DF3F5B728069C07B9656A2EBB39B5AC9E863E75371715EC937579F322EA43
udp/udp_tester/udp_sender.adb
(0 . 0)(1 . 16)
262 -- S.MG, 2018
263
264 with UDP_Tester;
265
266 procedure UDP_Sender is
267 -- Sender and Receiver addresses + ports
268 Receiver_IP : constant String := "127.0.0.1"; --SET THIS to your address!
269 Receiver_Port : constant := 9000;
270
271 Sender_Port : constant := 8000;
272
273 begin
274
275 UDP_Tester.Sender( Receiver_IP, Receiver_Port, Sender_Port) ;
276
277 end UDP_Sender;
-
+ B7560776B05822024C15F66648C6EA0777A6EF23B817DF4418A8C52D1319F62F3348DB65E4EE905D4730ECBC2BCA800628F3FEC21D5E9AC62FDD5B293D1E9973
udp/udp_tester/udp_tester.adb
(0 . 0)(1 . 310)
282 -- UDP transmissions tester for the libUDP
283 -- S.MG, 2018
284
285 with Ada.Text_IO; use Ada.Text_IO;
286 with Ada.Calendar; use Ada.Calendar; -- for local time
287 with Ada.Calendar.Time_Zones; use Ada.Calendar.Time_Zones; -- UTC_Time_Offset
288 with Ada.Calendar.Formatting; use Ada.Calendar.Formatting; -- for unix-like
289 with Ada.Directories; use Ada.Directories; -- for log files checks
290 with Interfaces; use Interfaces; --Unsigned_8 for payload
291
292 with UDP;
293 with MT;
294
295 package body UDP_Tester is
296
297 procedure Create_If_Not_Exists( Filename: in String; Header: in String) is
298 F : File_Type;
299 begin
300 begin
301 Open(File => F, Mode => Append_File, Name => Filename);
302 Close(File => F);
303 exception
304 when Ada.Text_IO.Name_Error =>
305 Create( File => F, Mode => Out_File, Name => Filename);
306 Put_Line(F, Header);
307 Close(F);
308 Put_Line("Created file " & Filename);
309 end;
310 end Create_If_Not_Exists;
311
312 procedure Sender( Receiver_IP: in String;
313 Receiver_Port: in Unsigned_16;
314 Sender_Port: in Unsigned_16 ) is
315
316 -- payload sizes to choose from
317 Sizes : array(1..Max_Len-Header_Len+1) of Natural;
318 Len_Sizes : Natural := Sizes'Length;
319 Packet_Size : Positive;
320 Pos : Natural;
321
322 -- log file for sender
323 OutFile : File_Type;
324 OutFileName : constant String := "sender_udp_log.txt";
325 HeaderOutFile : constant String :=
326 "SizeSent" &
327 ",TimeSent" &
328 ",DestinationIP" &
329 ",DestinationPort" &
330 ",Seed";
331
332 -- seed for initialising the MT PRNG
333 Seed : constant MT.U32 := MT.U32(Ada.Calendar.Clock - Epoch);
334 begin
335 -- create log file and add header to it if it doesn't exist already
336 Create_If_Not_Exists( OutFileName, HeaderOutFile);
337
338 -- initialize MT rpng
339 MT.Init_Genrand(Seed);
340
341 -- initialize payload sizes to choose from
342 for I in Sizes'Range loop
343 Sizes(I) := I - 1;
344 end loop;
345
346 -- send packages in a loop
347 Sending_Loop:
348 while Len_Sizes > 0 loop
349
350 --a delay of 1 sec to avoid saturating the link with burst-mode
351 delay 1.0;
352
353 -- pick randomly one of the available sizes for payload
354 Pos := Natural(MT.Gen_U32 mod MT.U32(Len_Sizes)) + 1;
355 Packet_Size := Sizes( Pos ) + Header_Len;
356
357 -- shift available sizes to exclude the latest pick
358 if Pos<Len_Sizes and Len_Sizes>Sizes'First then
359 Sizes(Pos..Len_Sizes-1) := Sizes(Pos+1..Len_Sizes);
360 end if;
361 -- decrease length of available sizes
362 Len_Sizes := Len_Sizes - 1;
363
364 -- instantiate UDP sender of picked size and send packet
365 declare
366 K : constant Positive := Packet_Size;
367 -- sender will have *current* size of UDP packet
368 package UDP_Sdr is new UDP( Payload_Size => K );
369
370 -- socket, addr, port
371 Socket : UDP_Sdr.Socket;
372
373 Local_Endpoint : UDP_Sdr.Endpoint :=
374 (Address => UDP_Sdr.INADDR_ANY,
375 Port => Sender_Port);
376
377 Remote_Endpoint : UDP_Sdr.Endpoint :=
378 (Address => UDP_Sdr.IP_From_String(Receiver_IP),
379 Port => Receiver_Port);
380
381 Sent_Payload : UDP_Sdr.Payload;
382
383 TimeUTC : Ada.Calendar.Time;
384 TimeUnix : Interfaces.Unsigned_32;
385
386 begin
387 -- message to console
388 Put_Line("Sending packet Len_Sizes= " & Integer'Image(Len_Sizes) &
389 " with length " & Positive'Image(Sent_Payload'Length));
390
391 -- fill the payload, so starting after header octets
392 for I in (Sent_Payload'First + Header_Len) .. Sent_Payload'Last loop
393 Sent_Payload(I) := Interfaces.Unsigned_8(I mod 256);
394 end loop;
395
396 -- fill the header part
397 -- time (UTC): year, month, day, seconds since midnight (2 octets)
398 TimeUTC := Ada.Calendar.Clock;
399 TimeUnix := Interfaces.Unsigned_32(TimeUTC - Epoch);
400
401 Sent_Payload(Sent_Payload'First+3) := Interfaces.Unsigned_8(
402 TimeUnix mod 256 );
403 TimeUnix := Shift_Right(TimeUnix, 8);
404
405 Sent_Payload(Sent_Payload'First+2) := Interfaces.Unsigned_8(
406 TimeUnix mod 256 );
407 TimeUnix := Shift_Right(TimeUnix, 8);
408
409 Sent_Payload(Sent_Payload'First+1) := Interfaces.Unsigned_8(
410 TimeUnix mod 256 );
411 TimeUnix := Shift_Right(TimeUnix, 8);
412 Sent_Payload(Sent_Payload'First) := Interfaces.Unsigned_8(
413 TimeUnix mod 256 );
414
415
416 -- size of message (full, payload+header)
417 Sent_Payload(Sent_Payload'First + 4) := Interfaces.Unsigned_8(
418 Sent_Payload'Length / 256);
419
420 Sent_Payload(Sent_Payload'First + 5) := Interfaces.Unsigned_8(
421 Sent_Payload'Length mod 256);
422
423 -- send packet
424 UDP_Sdr.Open_Socket(Socket, Local_Endpoint);
425 UDP_Sdr.Transmit(Socket, Remote_Endpoint, Sent_Payload);
426 UDP_Sdr.Close_Socket(Socket);
427
428 -- log the packet
429 TimeUnix := Interfaces.Unsigned_32(TimeUTC - Epoch);
430
431 Open(File => OutFile,
432 Mode => Append_File,
433 Name => OutFileName);
434 Put(OutFile, Integer'Image(Sent_Payload'Length));
435 Put(OutFile, "," & Unsigned_32'Image(TimeUnix));
436 Put(OutFile, "," & Receiver_IP);
437 Put(OutFile, "," & Unsigned_16'Image(Receiver_Port));
438 Put_Line(OutFile, "," & MT.U32'Image(Seed));
439
440 Close(File => OutFile);
441 end;
442 end loop Sending_Loop;
443 end Sender;
444
445 procedure Receiver( Receiver_Port: in Unsigned_16 ) is
446 -- receiver HAS to have max len for UDP size; it doesn't know it in advance
447 package UDP_Rcv is new UDP( Payload_Size => Max_Len );
448
449 -- socket and local endpoint to receive on
450 Socket : UDP_Rcv.Socket;
451 Local_Endpoint : UDP_Rcv.Endpoint := (Address => UDP_Rcv.INADDR_ANY,
452 Port => Receiver_Port);
453
454 -- received payload and source information
455 Received_Payload : UDP_Rcv.Payload;
456 Received_Origin : UDP_Rcv.Endpoint;
457 Received_Len : Unsigned_32;
458
459 -- for logging
460 TimeUTC : Ada.Calendar.Time;
461 TimeUnix : Interfaces.Unsigned_32;
462 TimeSent : Interfaces.Unsigned_32;
463 SizeSent : Interfaces.Unsigned_32;
464 Expected : Interfaces.Unsigned_8; --one octet of payload
465 ErrCount : Natural;
466
467 -- log file
468 OutFile : File_Type;
469 ErrFile : File_Type;
470 OutFileName : constant String := "receiver_udp_log.txt";
471 ErrFileName : constant String := "receiver_udp_err_log.txt";
472 HeaderOutFile : constant String :=
473 "SizeSent" &
474 ",TimeSent" &
475 ",SourceIP" &
476 ",SourcePort" &
477 ",SizeReceived" &
478 ",TimeReceived" &
479 ",ErrorOctetsCount";
480 HeaderErrFile : constant String :=
481 "SizeSent" &
482 ",TimeSent" &
483 ",SourceIP" &
484 ",SourcePort" &
485 ",SizeReceived" &
486 ",TimeReceived" &
487 "(,Position" & --position in payload of err octet
488 ",ValueReceived" &
489 ",ValueExpected)*";
490
491 begin
492 -- create log files and add headers to them if they don't exist already
493 Create_If_Not_Exists( OutFileName, HeaderOutFile);
494 Create_If_Not_Exists( ErrFileName, HeaderErrFile);
495
496 Put_Line("Opening socket on local endpoint " &
497 UDP_Rcv.IP_To_String(Local_Endpoint.Address) &
498 " :" & UDP_Rcv.IP_Port'Image(Local_Endpoint.Port) & "...");
499
500 UDP_Rcv.Open_Socket(Socket, Local_Endpoint);
501
502 Put_Line("Waiting for payloads...");
503
504 -- endless, receiving loop
505 Receiving_Loop:
506 loop
507 -- receive a payload
508 UDP_Rcv.Receive(Socket, Received_Origin, Received_Payload, Received_Len);
509
510 -- log the received payload
511 -- -- get local, arrival time
512 TimeUTC := Ada.Calendar.Clock;
513 TimeUnix := Unsigned_32(TimeUTC - Epoch); -- local, arrival time
514
515 -- -- append to log file(s)
516 Open(File => OutFile, -- main log
517 Mode => Append_File,
518 Name => OutFileName);
519
520 Open(File => ErrFile, -- error log
521 Mode => Append_File,
522 Name => ErrFileName);
523
524 -- -- info from the received package itself
525 TimeSent := 0;
526 for I in 1..4 loop
527 TimeSent := Shift_Left(TimeSent, 8);
528 TimeSent := TimeSent + Unsigned_32(Received_Payload(I));
529 end loop;
530
531 SizeSent := Shift_Left(Unsigned_32(Received_Payload(5)), 8) +
532 Unsigned_32(Received_Payload(6));
533
534 Put(OutFile, Unsigned_32'Image(SizeSent));
535 Put(OutFile, "," & Unsigned_32'Image(TimeSent));
536
537 -- -- info from receiver end
538 Put(OutFile, "," & UDP_Rcv.IP_To_String(Received_Origin.Address));
539 Put(OutFile, "," & UDP_Rcv.IP_Port'Image(Received_Origin.Port));
540 Put(OutFile, "," & Unsigned_32'Image(Received_Len));
541 Put(OutFile, "," & Unsigned_32'Image(TimeUnix));
542
543 -- any octets that are different from expected (i.e. errors)
544 ErrCount := 0;
545 for I in Header_Len+1 .. Natural(Received_Len) loop
546 Expected := Unsigned_8(I mod 256);
547 if Received_Payload(I) /= Expected then
548 ErrCount := ErrCount + 1;
549
550 -- first time *only*, add all the package info as well
551 if ErrCount = 1 then
552 Put(ErrFile, Unsigned_32'Image(SizeSent));
553 Put(ErrFile, "," & Unsigned_32'Image(TimeSent));
554 Put(ErrFile, "," & UDP_Rcv.IP_To_String(Received_Origin.Address));
555 Put(ErrFile, "," & UDP_Rcv.IP_Port'Image(Received_Origin.Port));
556 Put(ErrFile, "," & Unsigned_32'Image(Received_Len));
557 Put(ErrFile, "," & Unsigned_32'Image(TimeUnix));
558 end if;
559
560 -- at all times: add the error details - position, received, expected
561 Put(ErrFile, "," & Natural'Image(I) & "," &
562 Unsigned_8'Image( Received_Payload(I) ) & "," &
563 Unsigned_8'Image( Expected )
564 );
565 end if;
566 end loop;
567 -- if there was at least an error, move to next line in error log
568 if ErrCount > 0 then
569 New_Line(File => ErrFile);
570 end if;
571
572 -- in all cases, record ErrCount in main log file too
573 Put_Line(OutFile, "," & Natural'Image(ErrCount));
574
575 -- logging done for this entry, close the log files
576 Close(File => OutFile);
577 Close(File => ErrFile);
578
579 Put_Line("Received payload from " &
580 UDP_Rcv.IP_To_String(Received_Origin.Address) &
581 " :" & UDP_Rcv.IP_Port'Image(Received_Origin.Port) &
582 " with length " & Unsigned_32'Image(Received_Len));
583
584 end loop Receiving_Loop; -- infinite, receiving loop
585
586 -- close the socket and tidy up
587 UDP_Rcv.Close_Socket(Socket);
588
589 end Receiver;
590
591 end UDP_Tester;
-
+ 1DD063E7677409E44FA53DB1551400F6C3256B47B925DD789A8AF51C2BEBD15AD1F9418F372FCF7D0DDDD33908336178C734E69358F88A0AD03F57BAE2367196
udp/udp_tester/udp_tester.ads
(0 . 0)(1 . 48)
596 -- S.MG, 2018
597 -- Tester for UDP communications relying on libudp and libmt
598
599 with Ada.Calendar; use Ada.Calendar; -- for local time
600 with Ada.Calendar.Time_Zones; use Ada.Calendar.Time_Zones; -- UTC_Time_Offset
601 with Ada.Calendar.Formatting; use Ada.Calendar.Formatting; -- for unix-like
602 with Interfaces; use Interfaces;
603
604 with UDP;
605 with MT;
606
607 package UDP_Tester is
608
609 -- knobs for Tester, change as required
610
611 -- used for obtaining Unix-like time from value ret by Ada.Calendar.Clock
612 Epoch : constant Time := Formatting.Time_Of(1970, 1, 1, 0.0);
613
614 -- Header of each packet is:
615 -- 4 octets local time unix format;
616 -- 2 octets total length of message (header+payload)
617 Header_Len : constant Positive := 6;
618 -- packages sent will be between Header_Len and Max_Len
619 Max_Len : constant Positive := 2048;
620
621 -- helper methods
622 procedure Create_If_Not_Exists( Filename: in String; Header: in String);
623
624 -- will send messages with lengths between Header_Len and Max_Len
625 -- messages are sent at 1 second intervals (i.e. 1 second between 2 messages)
626 -- sizes are chosen based on MT prng with seed = unixtime when sender starts
627 -- payloads are simply I mod 256 where I is position of octet in message
628 -- data for all sent messages is logged in a .txt file in current dir
629 -- if the log files exist, new content will be APPENDED to it
630 -- if the log file does not exist, it will be created
631 procedure Sender( Receiver_IP: in String;
632 Receiver_Port: in Unsigned_16;
633 Sender_Port: in Unsigned_16 );
634
635 -- receiver method with endless loop, receiving UDP messages on given port
636 -- data for all received messages is logged in a .txt file in current dir
637 -- an additional err log contains any octets that are different from expected
638 -- if the log files exist, new content will be APPENDED to it
639 -- if the log file does not exist, it will be created
640 procedure Receiver( Receiver_Port: in Unsigned_16 );
641
642
643 end UDP_Tester;