### :school: TEEP 2024_RT LAB_ORAN DPDK
#### :book: Technology Background
:::success
List the essential information of this chapter.
1. Networking Programming - Ping
:::
---
### Networking Programming - Ping
#### Definitions
The /usr/sbin/ping command sends an Internet Control Message Protocol (ICMP) ECHO_REQUEST to obtain an ICMP ECHO_RESPONSE from a host or gateway. The ping command is useful for:
* Determining the status of the network and various foreign hosts.
* Tracking and isolating hardware and software problems.
* Testing, measuring, and managing networks.
If the host is operational and on the network, it responds to the echo. Each echo request contains an Internet Protocol (IP) and ICMP header, followed by a ping PID and a timeval structure, and enough bytes to fill out the packet. The default is to continuously send echo requests until an Interrupt is received (Ctrl-C).
The ping command sends one datagram per second and prints one line of output for every response received. The ping command calculates round-trip times and packet loss statistics, and displays a brief summary on completion. The ping command completes when the program times out or on receipt of a SIGINT signal. The Host parameter is either a valid host name or Internet address.
By default, the ping command will continue to send echo requests to the display until an Interrupt is received (Ctrl-C). The Interrupt key can be changed by using the stty command.
Because of the load that continuous echo requests can place on the system, repeated requests should be used primarily for problem isolation.
#### Ping Flags
| Items | Descriptions |
| ------------ | ------------ |
| -c Count | Specifies the number of echo requests, as indicated by the Count variable, to be sent (and received). |
| -w timeout | This option works only with the -c option. It causes ping to wait for a maximum of 'timeout' seconds for a reply (after sending the last packet). |
| -d | Starts socket-level debugging. |
| -D |This option causes a hex dump to standard output of ICMP ECHO_REPLY packets. |
| -f |Specifies flood-ping option. The -f flag "floods" or outputs packets as fast as they come back or one hundred times per second, whichever is more. For every ECHO_REQUEST sent, a . (period) is printed, while for every ECHO_REPLY received, a backspace is printed. This provides a rapid display of how many packets are being dropped. Only the root user may use this option. “Note: This can be very hard on a network and should be used with caution. Flood pinging is only permitted by the root user. The -f flag is incompatible with the -i Wait flag.” |
| -I a.b.c.d |Specifies that the interface specified by a.b.c.d is to be used for outgoing IPv4 multicasts. The -I flag is an uppercase i. |
| -o interface |Specifies that interface is to be used for outgoing IPv6 multicasts. The interface is specified in the form 'en0', 'tr0' etc. |
| -i Wait | Waits the number of seconds specified by the Wait variable between the sending of each packet. The default is to wait for one second between each packet. This option is incompatible with the -f flag. |
| -L |Disables local loopback for multicast pings. |
| -l Preload |Sends the number of packets specified by the Preload variable as fast as possible before falling into normal mode of behavior (one per second). The -l flag is a lowercase l. |
| -n |Specifies numeric output only. No attempt is made to look up symbolic names for host addresses. |
| -p Pattern |Specifies up to 16 'pad' bytes to fill out the packet you send. This is useful for diagnosing data-dependent problems in a network. For example, -p ff fills the packet with all 1's. |
| -q |Specifies quiet output. Nothing is displayed except the summary lines at startup time and when finished. |
| -r |Bypasses the routing tables and sends directly to a host on an attached network. If the Host is not on a directly connected network, the ping command generates an error message. This option can be used to ping a local host through an interface that no longer has a route through it. |
| -R |Specifies record route option. The -R flag includes the RECORD_ROUTE option in the ECHO_REQUEST packet and displays the route buffer on returned packets. “Note: The IP header is only large enough for nine such routes. Also, many hosts and gateways ignore this option.” |
|-a addr_family|Maps the destination address of the ICMP packets to IPv6 format if addr_family is equal to "inet6". |
|-s PacketSize |Specifies the number of data bytes to be sent. The default is 56, which translates into 64 ICMP data bytes when combined with the 8 bytes of ICMP header data. |
|-S hostname/IP addr|Uses the IP address as the source address in outgoing ping packets. On hosts with more than one IP address, the -S flag can be used to force the source address to be something other than the IP address of the interface on which the packet is sent. If the IP address is not one of the machine's interface addresses, an error is returned and nothing is sent. |
|-T ttl |Specifies that the time-to-live for a multicast packet is ttl seconds. |
|-v |Requests verbose output, which lists ICMP packets that are received in addition to echo responses. |
#### Ping Parameters
| Items | Descriptions |
| -------- | -------- |
| PacketSize|Specifies the number of data bytes to be sent. The default is 56, which translates into 64 ICMP data bytes when combined with the 8 bytes of ICMP header data. This parameter is included for compatibility with previous versions of the ping command. |
|Count |Specifies the number of echo requests to be sent (and received). This parameter is included for compatibility with previous versions of the ping command. |
#### Examples Using Ping Command in Linux
The basic ping syntax includes ping followed by a hostname, a name of a website, or the exact IP address.
```=
ping [option] [hostname] or [IP address]
```
Hence, to check whether a remote host is up, in this case, google.com, type in your terminal:
```=
ping google.com
```

1. `from`: The destination and its IP address. Note that the IP address may be different for a website depending on your geographical location.
2. `icmp_seq=1`: The sequence number of each ICMP packet. Increases by one for every subsequent echo request.
3. `ttl=250`: The Time to Live value from 1 to 255. It represents the number of network hops a packet can take before a router discards it.
4. `time=18.7 ms`: The time it took a packet to reach the destination and come back to the source. Expressed in milliseconds.
**ping “localhost” to Check Local Network**
```=
ping localhost
```
You can use the name to ping localhost. The name refers to your computer, and when we use this command, we say: “ping this computer.”

**Change Time Interval Between Ping Packets**
The default interval between each ping request is set to one second. You can increase or decrease that time using the -i switch. To decrease the ping interval, use values lower than 1.
```=
ping -i 0.5 google.com
```

**Change Ping Packet Size**
In some scenarios, you may want to use -s to increase the packet size from the default value of 56 (84) bytes. The number in parenthesis represents the ping bytes sent including 28 bytes of the header packet.
For example, to increase the packet size to 1000 bytes:
```=
ping -s 1000 google.com
```

**Limit Number of Ping Packets**
```=
ping -c 2 google.com
```
