@@ -175,19 +175,37 @@ def get_data(self):
175
175
return FlowTuple .Data (self .proto , saddr , daddr , sport , dport )
176
176
177
177
def is_ordered (self ):
178
- return (self .is_one_way or self .saddr < self .daddr or
179
- (self .saddr == self .daddr and
180
- self .sport is not None and self .dport is not None and
181
- self .sport < self .dport ))
178
+ """
179
+ Predicate, returns True when this flow tuple is ordered.
180
+
181
+ A flow tuple is ordered when any of the following are true:
182
+
183
+ - It's marked as a one-way flow.
184
+
185
+ - Its source IP address is smaller than its dest IP address, both in
186
+ network byte order (NBO).
187
+
188
+ - The IP addresses are equal and the source port is smaller than the
189
+ dest port, in NBO.
190
+ """
191
+ nbo = self .in_nbo ()
192
+ return (nbo .is_one_way or nbo .saddr < nbo .daddr or
193
+ (nbo .saddr == nbo .daddr and
194
+ nbo .sport is not None and nbo .dport is not None and
195
+ nbo .sport < nbo .dport ))
182
196
183
197
def has_ports (self ):
198
+ """
199
+ Predicate, returns True when this tuple features port numbers.
200
+ """
184
201
return self .sport is not None and self .dport is not None
185
202
186
203
def in_order (self ):
187
204
"""
188
- Returns a copy of this tuple that is ordered canonically. Ie,
189
- regardless of the direction of src/dest, the returned tuple
190
- will be sorted the same way.
205
+ Returns a copy of this tuple that is ordered canonically. Ie, regardless
206
+ of the src/dest IP addresses and ports, the returned tuple will be be
207
+ the same: the source side will contain the smaller endpoint (see
208
+ FlowTuple.is_ordered() for details).
191
209
"""
192
210
if self .is_ordered ():
193
211
return FlowTuple (self .proto , self .saddr , self .daddr ,
0 commit comments