At any particular point of time, a TCP connection is uniquely determined by a 4-tuple: source IP address, destination IP address, source port number, and destination port number, thus we can tell which connection a given packet belongs to by looking at the IP and TCP header of the packet.
An individual packet will either travel upstream or downstream.
If we denote a connection as a 4-tuple
, one direction is expressed as
and the other is expressed as
.
There are two packet streams in one connection for each of the directions, but we currently treat each of them independently.
Directions are defined with regards to an intruder's actual origin, so we say the direction of a packet stream is upstream if the packets are moving toward the intruder, and downstream if the packets are moving toward the target host.