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).
This kind of thing is for advanced programmer who knows how to use threads and set them up.
Basically the thoughts I have is I would set up a class with thread stuff and socket stuff, with a static boolean for a send. Create all these classes to the count I need and I would have structure to maintain them. Basically these classes are the full maintaining structure of the data I want to send and thread loop control for doing the sending work. The static boolean is a switch to start the work for as many of these things I create.
Start all the threads and their corresponding sockets. Make sure they are communicating properly and are created. In the Thread/socket class they should be polling the boolean send. It should be a default false.
Then in Where I want to start the mass send I just change that boolean and let the individual threads do the work of the sending. I am not sure how close you might get to simultaneous you might get but it should be pretty close depending on the traffic flow between the client threads and the receiving server.
Remember sockets on any one given computer get bottlenecked down to the tcp/ip protocol and sent across the network, so nothing is really simultaneous it is piped one right after the other as fast as it can.
Another note this is the basic design of a Denial of Service attack program. That is why I am not going to help with code. I hope I have given you some food for thought on how to set up the code for what you are trying to do.
thank you so much for your time Azagaros, i was thinking about:
i have to buid up my packets by hand using functions to add headers (UDP,IP,MAC) and to calculate checksums (UDP,IP) and send them using pcap_sendpacket or pcap_sendqueue_transmit (winpcap libraries). so in this case i think i will not need any socket but eventually i will need parallel threads to try to send simultaneous frames or semi-simultaneous frames.
i will give you a simple exemple of what i want to do:
i prepared my part of code that build and send packets.
but i want to send packets via port UDP number= 2000
and at the same time packets via UDP port number=2001
i hope u have understood me.
so how can i handle this? i think this can be done with threads but i 'am working on windows platform and i don't know much about the use of threads. so please i need your help if you can explain to me the number of threads to be used or if there will be one thread for each Udp port? i hope you have some links that could help me.
You do the multiplexing within the app, perhaps in a single thread that does the writes. One reason you might want to do this is to guarantee sequence numbers if your packets have them.
yesss my packets have sequence numbers and in MAC layer i have to use a MUX that will arrange all packets coming from upper layers. i have to mesure latency of sending and i must have a very high speed sending. so what you advise me to do?
Decent server network cards can help out in a variety of ways. If you start bypassing layers you don't get the benefit of improved hardware.
EDIT: Latency--you can time network roundtrip times between two hosts, of if you can have a multi-homed box, you can time between the interfaces. I don't know the context in which you're working.
i don't use interfaces for this moment in my application,i'm working with mode console under windows.
Can i use GetTickCount() in mesuring latency?
and have you a function for adding sequence number? or for incrementing it? because i have to put a sequence number basis in a range of 0 to 255. i initializes the sequence number as 0 and increments by one for each consecutive frame. When the value reaches 255, it wraps-around to 1 instead of 0...
another question: i send frames using pcap_sendpacket or pcap_sendqueue_transmit (winpcap libraries) so i hope sending my frames with a rate means i want to have minimum time between two consecutive frames which called the BAG:Bandwidth Allocation Gap.
there is sleep() and wait() functions but they don't give me the precision that i want =<1ms
so i thought about Multimedia Timer: QueryPerformanceCounter(), i found an information that its precision is>4ms, is that true? or it can be useful for a bag=1ms for exemple?
i don't use interfaces for this moment in my application,i'm working with mode console under windows.
By interface, I mean network interface.
Can i use GetTickCount() in mesuring latency?
You can, but I'd recomend QueryPerformanceTimer().
...because i have to put a sequence number basis in a range of 0 to 255.
Where are you putting this number? Surely you can use any size number you like--it's your packet right?
i send frames using pcap_sendpacket or pcap_sendqueue_transmit ... so i hope sending my frames with a rate means i want to have minimum time between two consecutive frames which called the BAG:Bandwidth Allocation Gap
pcap_sendpacket sets up a buffer and calls WriteFile to the device, this isn't any different from WinSock's send/sendto(). I can't really comment further other than to say it's not any faster doing it your way.
there is sleep() and wait() functions but they don't give me the precision that i want =<1ms
In the end, Windows is not a real time OS. Sleep(1) sleeps for more than 1ms contrary to the documentation. You can't do your timings that way, you have to work on the aggregate times; i.e. much larger chunks of time as the your timings as your doing them can be upto 200% out.