two routers are connected and ospf is enabled , after creating adjacency , how router is knowing that hello packet is a just a hello packet to keep the adjacency up .
OSPF keeps a finite state machine (FSM) for each neighbor, after having reached the adjacency FULL state receiving timely hellos makes this neighbor status to be stable.
Each received hello resets the dead interval timer for that neighbor.
To be noted from Two way state the received hello packet contains the OSPF router-ids of the OSPF neighbors existing on that specific interface, so the local router can see its own OSPF RID in each of the received Hello packets.
section 10.3 Neighbor state machine
Hope to help
During the initial adjacency, the routers will send hello packets with their router-id listed in that packet. If the router-id exists in the neighbor table, then it's considered a keep-alive and the dead interval is incremented. If the router-id is new and doesn't exist in the neighbor table, then the adjacency process begins.
Neighbor ID Pri State Dead Time Address Interface
192.168.12.1 1 FULL/BDR 00:00:37 192.168.12.1 FastEthernet0/0
If I brought up another interface on another router with router-id 192.168.12.2, the adjacency process would start. Otherwise, if I'm receiving hello packets from the above router with router-id 192.168.12.1 then it's considered a hello packet and the dead time increases back to 4 times the hello period. (10 second hellos and 40 second dead interval).