CN Algorithm
CN Algorithm
SNMPServer Algorithm
1. Initialize Server:
a. Create a DatagramSocket on port 8086 (SNMP typically uses UDP).
2. Server Ready:
a. Display a message indicating that the SNMP Server is running.
3. Main Loop (Continuous Listening):
a. Continuously wait for incoming SNMP requests.
4. Receive Request:
a. Create a DatagramPacket to hold incoming data.
b. Receive data from the client and store it in the packet.
c. Convert the received data into a string format (interpreted as an SNMP
request).
5. Print Request:
a. Display the received SNMP request.
6. Prepare Response:
a. Create a response message that includes the original request.
b. Convert the response message to bytes.
7. Send Response:
a. Retrieve the client’s IP address and port from the received packet.
b. Create a new DatagramPacket for the response data.
c. Send the response packet back to the client.
8. Repeat:
a. Go back to the listening state and wait for the next incoming request.
SNMPClient Algorithm
1. Initialize Client:
a. Set up a reader to take input from the user.
b. Create a DatagramSocket for sending and receiving data.
c. Set the server’s IP address and port (use "localhost" and port 8086 in this
case).
2. Get User Input:
a. Prompt the user to enter an SNMP request.
b. Read the request string from the user.
3. Send Request:
a. Convert the request string into bytes.
b. Create a DatagramPacket with the request data, targeting the server’s IP
and port.
c. Send the packet to the server.
4. Receive Response:
a. Prepare a DatagramPacket to receive the server’s response.
b. Wait and receive the response packet from the server.
5. Print Response:
a. Convert the received data into a string format.
b. Display the received SNMP response.
6. Close Socket:
a. Close the socket to end the client session.
TraceRouteServer Algorithm
1. Initialize Server:
a. Bind a DatagramSocket to port 33434 to listen for incoming UDP
packets.
2. Listen for Packets:
a. Start a loop to continuously listen for packets.
3. Receive Packet:
a. Allocate a buffer and receive a packet from a client.
b. Extract the client’s message, IP address, and port number.
4. Respond to Client:
a. Prepare a response message with the server’s IP address.
b. Send this response packet back to the client.
5. Repeat:
a. Continue listening and responding to new packets.
TraceRouteClient Algorithm
1. Initialize Client:
a. Define the server address (localhost in this case) and the destination
port (33434).
b. Set maxHops to the desired maximum number of hops (e.g., 30).
2. Tracing Route:
a. Loop through each TTL value from 1 to maxHops.
3. Create and Send Packet:
a. Set up a new DatagramSocket with a 3-second timeout.
b. Set the packet’s TTL to the current hop count.
c. Record the start time and send the packet to the server.
4. Receive Response or Timeout:
a. Try to receive a response packet from the server.
b. If successful, calculate the round-trip time (RTT) and display the router
address and RTT for the current hop.
c. If the response IP matches the server IP, print "Reached destination" and
exit the loop.
d. If a timeout occurs, indicate that the request timed out.
5. Close Socket and Repeat:
a. Close the socket and move to the next hop until reaching the destination
or the maximum hops limit.