Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
749 connectés 

  FORUM HardWare.fr
  Programmation
  C++

  Sending many packets Ethernet simultaneously

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Sending many packets Ethernet simultaneously

n°2074480
sloumanaw
Posté le 07-05-2011 à 14:18:42  profilanswer
 

Hello
 
i'am developping an application with Visual C++ 2010 but i have a problem.
i need to send many packets Ethernet simultaneously from application layer to physical layer (of course with construction of every packet in UDP,IP, and MAC layers), and in Mac layer there is a scheduler that arranges packets (coming from uper layer) in the same line to be send to the physical layer.
 
So i need to know how can i do this?
there is use of threads or sockets?  
i think sockets can be used only for communication between two hosts not in the same host (my case).
 
i hope some one can help me. thank you

mood
Publicité
Posté le 07-05-2011 à 14:18:42  profilanswer
 

n°2074484
gilou
Modérateur
Modzilla
Posté le 07-05-2011 à 15:23:53  profilanswer
 

Citation :

i think sockets can be used only for communication between two hosts not in the same host (my case)

No, you can have a client and a server on the same host.
A+,


---------------
There's more than what can be linked! --    Iyashikei Anime Forever!    --  AngularJS c'est un framework d'engulé!  --
n°2074509
sloumanaw
Posté le 07-05-2011 à 22:00:17  profilanswer
 

how can i use it in my case? who is the server and who is the client?  
for exemple i want to send 3 messages simultaneously from application layer through 3 ports udp to the transport layer so i have to use 3 sockets?  

n°2074519
gilou
Modérateur
Modzilla
Posté le 07-05-2011 à 23:33:26  profilanswer
 

If you don't understand what is a server and a client, how can you expect to program socket code?
 
You want to communicate data between two applications, each one on a machine (it may be the same machine or not)
One software will create a socket and will listen it, waiting for input to arrive. It is named "the server".
It must be running and listening, else, nothing will happen.
The other software will create a socket, try to connect it to the server socket, and if successful, will send some data to the server, to announce its arrival. It is named "the client".
Then data exchange can take place (following a common high level protocol)
 
What is the final destination of your three messages? in term of IP and Ports. The same IP and ports? Same IP and three different ports? This is very unclear from what you wrote.
 
A+,
 
 


---------------
There's more than what can be linked! --    Iyashikei Anime Forever!    --  AngularJS c'est un framework d'engulé!  --
n°2074734
sloumanaw
Posté le 09-05-2011 à 12:35:21  profilanswer
 

thank you for your time gilou,i will explain to you my application. i really need your help so please be patient with me.
 
i read about socket but i don't know if i can use it in my application.
i will explain to you what i want to develop:
i want to send packets from application layer via many UDP ports simultaneously, and in UDP layer the header will be added and all calculs done.after, packets passed to IP layer which add the ip header and do calculs (it is a single ip destination adress not mutlicast adress).then packets passed to Mac layer where is a scheduler (MUX) which regulate all Mac frames to one voice (une seule voix ou une seule ligne) ready to be sent to physical layer with winpcap librairies. in the other hand there is a receiver (in my case i want to implement it in the same host with the transmitter) who will capture these frames from the physical layer with winpcap libraries and passes them to MAC layer where is a scheduler (DEMUX) then to ip layer to UDP layer to application layer.  
so i think about threads to use one transmit thread who will sends frames to the physical layer and receiver thread who will receive frames from physical layer to application layer.
but sockets, i thought that are used only in udp layer to udp layer of the server.
 
Cordialment

n°2074800
gilou
Modérateur
Modzilla
Posté le 09-05-2011 à 16:29:02  profilanswer
 

Citation :

i want to send packets from application layer via many UDP ports simultaneously

OK

Citation :

and in UDP layer the header will be added and all calculs done.after, packets passed to IP layer which add the ip header and do calculs (it is a single ip destination adress not mutlicast adress).then packets passed to Mac layer where is a scheduler (MUX) which regulate all Mac frames to one voice (une seule voix ou une seule ligne) ready to be sent to physical layer with winpcap librairies.

This is basic stuff that we don't have to care about in socket programming.
 
A basic udp client on unix  
- creates a socket with a socket() call with the information on the socket type  
- allocates a struct sockaddr data structure with the information on the server address
- sends its data ( which is in a buffer) using the sendto() call
and that's all
 
A very minimal UDP client has the following structure:
( this is unix/linux code )

Code :
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <sys/types.h>
  4. #include <sys/socket.h>
  5. #include <netinet/in.h>
  6. #include <netdb.h>  // for gethostbyname
  7. int main(int argc, char *argv[])
  8. {
  9.     // these may be parameters
  10.     char *host = "localhost"; // or the machine name, IP...
  11.     char *port = "1043"; // a port value
  12.     // socket creation
  13.     int sd;  // socket descriptor
  14.     sd = socket(AF_INET, SOCK_DGRAM, 0);
  15.     if (sd < 0) {
  16.         perror("sock_init" );
  17.         exit(1);
  18.     }
  19.     // socket adress  structure initialisation
  20.     struct sockaddr_in in_name;
  21.     struct hostent *hptr;
  22.     memset((char *) &in_name, 0, sizeof(in_name));
  23.     in_name.sin_family = AF_INET;
  24.     in_name.sin_port = htons(port);
  25.     hptr = gethostbyname(host);
  26.     memcpy(&(in_name.sin_in_addr.s_addr), hptr->h_addr, hptr->h_length);
  27.    
  28.     // sending the data
  29.     char *data[256]; // must be less than 65507  
  30.     strcpy(data, "Hello world!" );
  31.     if (sendto(sd, data, strlen(data), &in_name, sizeof(in_name)) < 0) {
  32.         perror("sendto failed" );
  33.         close(sd);
  34.         exit(1);
  35.     }
  36.     close(sd);
  37.     exit(0);
  38. }


 
It sends the string "Hello world!" (non null terminated or else, change strlen(data) by strlen(data)+1 in the sendto call) to a server listening on the corresponding port on the local machine.
Of course, this will fail if you dont have a server running and listening incoming data on the port.
There may be typos in the previous code, I did not try to compile it (I dont have a unix/linus OS installed currently)
 
The windows equivalent code should be:

Code :
  1. #include <winsock2.h>
  2. #include <string.h>
  3. #pragma comment(lib, "ws2_32.lib" )
  4. int main()
  5. {
  6.     WSADATA WSAData;
  7.     // these may be parameters
  8.     char *host = "127.0.0.1"; // 127.0.0.1 is the local host, or use the machine name, IP...
  9.     char *port = "1043"; //
  10.     // windows specific socket initialisation
  11.     WSAStartup(MAKEWORD(2,0), &WSAData); // use version 2.0 of winsock
  12.     // socket creation
  13.     SOCKET sd;
  14.     sd = socket(AF_INET, SOCK_DGRAM, 0);
  15.     // socket adress  structure initialisation
  16.     SOCKADDR_IN in_name;
  17.     in_name.sin_family = AF_INET;
  18.     in_name.sin_port = htons(port);
  19.     in_name.sin_addr.s_addr = inet_addr(host);
  20.     // sending the data
  21.     char *data[256]; // must be less than 65507  
  22.     strcpy(data, "Hello world!" );
  23.     sendto(sd, data, strlen(data), &in_name, sizeof(in_name));
  24.     closesocket(sd);
  25.     // windows specific socket cleanup
  26.     WSACleanup();
  27.     return 0;
  28. }


 
You want to use three UDP ports, fine, just do as previously described with three different ports (and each within its own thread if you want concurrency in your program).
 
A+,


Message édité par gilou le 09-05-2011 à 17:24:29

---------------
There's more than what can be linked! --    Iyashikei Anime Forever!    --  AngularJS c'est un framework d'engulé!  --
n°2074956
sloumanaw
Posté le 10-05-2011 à 13:17:09  profilanswer
 

thank you Gilou. i'm working on windows platform. i will start to develop like you said to me without threads,if it works i will make concurrency in my program. so,i will recap what i have understood: i must have one server for each UDP port which will receive the message (we are now in transport layer,no?).and after i will build my packet with headers and send it with another socket (in this case udp layer is the client) to the Mac layer (the server)?? in this level,i send packet with winpcap librairies to the Ethernet interface (according to its device).  
so did i understood well? if not, please explain to me more.
im sorry to bother you but i really need your help,i have to finish this project before two weeks and you see i'm still having much problems :(

n°2074966
gilou
Modérateur
Modzilla
Posté le 10-05-2011 à 13:45:18  profilanswer
 

Citation :

i will build my packet with headers

Do you mean UDP packets? Why would you do that?

 

When you do this:
sd = socket(AF_INET, SOCK_DGRAM, 0);
You're telling the system that the data that you will write in the socket has to be encapsulated as a UDP packet.

 
Citation :

i must have one server for each UDP port which will receive the message

Or you must have a server listening on more than one port, here also, multithreading helps.

 

I don't know what you're trying to do, but if you have never programmed in client/server through sockets, or never programmed a multithreading application, I doubt that 2 weeks is enough to have a working program free of bugs.

 

A+,

 


Message édité par gilou le 10-05-2011 à 13:45:49

---------------
There's more than what can be linked! --    Iyashikei Anime Forever!    --  AngularJS c'est un framework d'engulé!  --
n°2075012
sloumanaw
Posté le 10-05-2011 à 15:29:20  profilanswer
 


i want to send raw packets from application layer to physical layer.when passing by the transport layer i have to add UDP header ,in network layer i add IP header,in data link layer i add MAC layer.so my raw packets will be built to be frames ready for sending with winpcap librairies to physical layer.
 
i have developped a part of code that builds frames and adds all headers and calculs checksum.but my problem is not here.
my problem that i want to run this part of code with three udp ports numbers simultaneously,thats why i thought about threads and sockets. i hope you can understand my problem.please if you have a solution.
 
 
 
 


Message édité par sloumanaw le 10-05-2011 à 15:44:34
n°2075014
gilou
Modérateur
Modzilla
Posté le 10-05-2011 à 15:45:02  profilanswer
 

Citation :

i want to send raw packets from application layer

If you do all that by hand, you dont need sockets at all!
All you have to do is to buid up your packets (eventually in parallel threads) and send them using pcap_sendpacket or pcap_sendqueue_transmit.
UDP port number is just a value that you set in the UDP packet header, this should not require any specific handling.
A+,


Message édité par gilou le 10-05-2011 à 15:46:58

---------------
There's more than what can be linked! --    Iyashikei Anime Forever!    --  AngularJS c'est un framework d'engulé!  --
mood
Publicité
Posté le 10-05-2011 à 15:45:02  profilanswer
 

n°2075015
sloumanaw
Posté le 10-05-2011 à 15:46:01  profilanswer
 

i will do my best to finish this program in two weeks.it will be hard but i hope i will have good results

n°2075016
sloumanaw
Posté le 10-05-2011 à 15:51:51  profilanswer
 

ok then.i think you understand exactly what i want to do :)
i have prepared the code to build my packets and i know about winpcap functions. my only problem is how can i use threads? do i have to use one thread to transmit or many threads as the number of UDP port used? means one thread for each port? and please if you have some links that can help me. thank soooo much gilou for your time

n°2075017
kadreg
profil: Utilisateur
Posté le 10-05-2011 à 15:54:45  profilanswer
 

[:clem104:2]


---------------
brisez les rêves des gens, il en restera toujours quelque chose...  -- laissez moi troller sur discu !
n°2075019
sloumanaw
Posté le 10-05-2011 à 15:56:10  profilanswer
 

if UDP port number is just a value in UDP header so how can we send raw packet from application layer to UDP layer without port.it can be communication port or SAP port.each communication port is assigned to an UDP port.

n°2075020
gilou
Modérateur
Modzilla
Posté le 10-05-2011 à 15:56:14  profilanswer
 

Writing raw UDP packets is easy, the hard part will be multitasking.
If you have a lot of incoming data that you need to split and schedule for sending through UDP (eg real time voice processing), with some data dropping when some delay for sending is exceeded, this may be tricky.  
A+,


---------------
There's more than what can be linked! --    Iyashikei Anime Forever!    --  AngularJS c'est un framework d'engulé!  --
n°2075022
gilou
Modérateur
Modzilla
Posté le 10-05-2011 à 16:00:27  profilanswer
 

You dont send raw packet from application layer to UDP layer. :heink:  
If your packet is built in your application layer as a UDP packet, with IP pseudo header, you give it to the raw layer (ie the wincap library), as it is a raw packet ready for sending.
A+,


Message édité par gilou le 10-05-2011 à 16:00:54

---------------
There's more than what can be linked! --    Iyashikei Anime Forever!    --  AngularJS c'est un framework d'engulé!  --
n°2075030
sloumanaw
Posté le 10-05-2011 à 16:07:04  profilanswer
 

raw packets will be send to transport layer via communication ports,each one is assigned to one UDP port. i will not use so many incoming data to split or schedule for sending through UDP.i will only have some tests with this project so i think i need some handling between ports that all. i need your help in the use of multithread. so please can you explain to me how can i use threads? do i have to use one thread to transmit or many threads as the number of UDP ports (communication ports) used? means one thread for each port?

n°2075032
sloumanaw
Posté le 10-05-2011 à 16:08:27  profilanswer
 

so i do not need even communication ports?

n°2075035
sloumanaw
Posté le 10-05-2011 à 16:11:25  profilanswer
 

in the specifications of the project there is communication ports between udp layer and application layer.if it is not necessary i will not use it. if it will be more simple without so i wil no use :)

n°2075037
gilou
Modérateur
Modzilla
Posté le 10-05-2011 à 16:15:17  profilanswer
 

sloumanaw a écrit :

in the specifications of the project there is communication ports between udp layer and application layer.if it is not necessary i will not use it. if it will be more simple without so i wil no use :)

Communication ports? That does not makes any sense.
What is your UDP layer in your specification? some independant software or service?
A+,
 


---------------
There's more than what can be linked! --    Iyashikei Anime Forever!    --  AngularJS c'est un framework d'engulé!  --
n°2075045
sloumanaw
Posté le 10-05-2011 à 16:25:09  profilanswer
 

my UDP layer is the same for Ethernet and model OSI. but communication ports is another service. but i don't have problem with it.i only have problem with the use of threads in multithreading application.so please can you help my only in this point, i know that i asked you so many questions but please how can i use threads? do i have to use one thread to transmit or many threads as the number of UDP port used? means one thread for each port? and please if you have some links that can help me.
thak you so much.

n°2075051
gilou
Modérateur
Modzilla
Posté le 10-05-2011 à 16:35:27  profilanswer
 

Citation :

my UDP layer is the same for Ethernet and model OSI. but communication ports is another service.

This does not tell me anything. My question was clear.
What do you call your UDP layer?
Is it a set of functions in your software? Is it a service running in the background? or else?
 
No I can't help you on the multitasking aspect, as a correct usage will depend on the kind and rate of data you have to packetize, if you can drop packets, etc etc, and I have no idea about it.
A+,
 


---------------
There's more than what can be linked! --    Iyashikei Anime Forever!    --  AngularJS c'est un framework d'engulé!  --
n°2075057
sloumanaw
Posté le 10-05-2011 à 16:44:25  profilanswer
 

my UDP layer is a set of functions in my software.
thank you very much for your time gilou,i will try to cherche about multithreading applications :)

n°2075065
gilou
Modérateur
Modzilla
Posté le 10-05-2011 à 16:57:47  profilanswer
 

Citation :

my UDP layer is a set of functions in my software

Therefore, speaking of port does not make sense,as you will communicate data to the function through a buffer or a buffer address.
A+,


---------------
There's more than what can be linked! --    Iyashikei Anime Forever!    --  AngularJS c'est un framework d'engulé!  --
n°2075070
sloumanaw
Posté le 10-05-2011 à 17:03:33  profilanswer
 

yes you are right :)

n°2075074
sloumanaw
Posté le 10-05-2011 à 17:08:23  profilanswer
 

please another question gilou,if we want to send these packets with a rate.  means BAG=2ms Bandwidth Allocation Gap, between every two consecutive frames

n°2075097
gilou
Modérateur
Modzilla
Posté le 10-05-2011 à 17:58:40  profilanswer
 

It seems (winpcap is unclear on this) that the timestamp value is taken into account when the sync parameter of pcap_sendqueue_transmit is set:

Citation :

sync determines if the send operation must be synchronized: if it is non-zero, the packets are sent respecting the timestamps, otherwise they are sent as fast as possible.


This is pretty unclear, so you will have to find out how exactly it works.
But if you add packets in a queue with timesamps incremented by the BAG, this may work.
A+,


Message édité par gilou le 10-05-2011 à 17:59:00

---------------
There's more than what can be linked! --    Iyashikei Anime Forever!    --  AngularJS c'est un framework d'engulé!  --
n°2075116
sloumanaw
Posté le 10-05-2011 à 18:47:30  profilanswer
 

ok thank you i will try it :)

mood
Publicité
Posté le   profilanswer
 


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C++

  Sending many packets Ethernet simultaneously

 

Sujets relatifs
design many to one hibernateEF & C# : relation many to many
[Suppression doublons>3] ==> Ora-00913: too many values ...[MySQL] too many connections
ZEND - gestion MySQL - too many connexionnhibernate : one-to-many
Demarrer/Eteindre un PC via ethernetComment utiliser le port Ethernet en .net (VB .net si possible) ?
C++ ==> \stdlib.h too many arguments to function 
Plus de sujets relatifs à : Sending many packets Ethernet simultaneously


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR