NetFlow 101 – TNF – Traditional NetFlow

What is a flow

A flow is defined by the combination of the following seven key fields:
  • Source IP address
  • Destination IP address
  • Source port number
  • Destination port number
  • Layer 3 protocol type
  • Type of service (ToS)
  • Input logical interface

Gathering information

Netflow requires CEF, so before beginning, make sure you enable CEF:
1
R(config)# ip cef
Copied!
Netflow enables a router to gather specific statistics regarding each flow. These statistics include Byte count, Packet count, Start/End Time, QoS markings, and so on. In order to enable NetFlow to gather statistics, you will have to enable it per interface, and per direction of traffic (ingress or egress):
1
R(config-if)# ip flow {ingres|egress}
Copied!
Older IOS versions support only ingress monitoring with the command:
1
R(config-if)# ip route-cache flow
2
! equivalent to ip flow ingress
Copied!
Once NetFlow is enabled, it will start gathering information about each flow of data that is passed on the specified interfaces and in the configured directions. Netflow will gather statistics for all incoming packets (including the ones destined to the router), but will only gather statistics for the transit outgoing packets (not the ones sourced by the router). You can see which interfaces are configured for NetFlow with the command:
1
R# show ip flow interface
Copied!
The router uses a flow-cache to store information about each flow. Statistics about each flow are kept in the cache until the flow expires. Once expired, the flow is exported to the flow collector in order to free the resources in the cache. The netflow process accesses the cache every second and it decides what flows are expired:
  • Flows that are normally ended (by receiving a TCP FIN or RST for example)
  • Flows that have not been updated in the last INACTIVE period (default 15 sec)
  • Long flows that haven’t been inactive more than the INACTIVE period in the last ACTIVE period (default 30 min).
  • In case the cache is almost full, it starts to consider the oldest flows as expired
When a flow is expired, it can (and usually is) exported to the
1
R(config)# ip flow-cache entries SIZE
2
! Default SIZE: 4096
3
R(config)# ip flow-cache timeoute active MIN
4
! Default MIN: 30
5
R(config)# ip flow-cache timeoute inactive SEC
6
! Default SEC: 15
Copied!

Displaying NetFlow data

All this information should be visualized in some way. The simplest way is using the CLI command:
1
R# show cache flow
Copied!
To clear flow statistics on the router, use:
1
R# clear ip flow stats
Copied!

Exporting NetFlow data

It is hard to do complex analysis on this data just looking at the CLI. This is why NetFlow supports exporting the data in a format that can be used by other software, called NetFlow Collectors. When exporting, the router will send small, periodic packets with information regarding the collected flow statistics to the NetFlow Collector. To enable NetFlow export, use:
1
R(config)# ip flow-export destination HOST UDP-PORT
2
R(config)# ip flow-export version VERSION
3
! default: 1. Best option: 9
Copied!
Over the time, the format of NetFlow exports has changed. Before version 9, the format of the Netflow packets was fixed, but version 9 introduced the concept of templates. Because version 9 supports many types of protocols (MPLS, IPv6, Multicast) each flow may be exported using a different template. To make things easy, the router that exports the flow data, also sends the template definition periodically. The template definitions are sent as records in the netflow packets, along with (but also without) netflow data exports. How often is the template information sent? Periodically, based on time passed since the last template was sent or based on the number of packets sent since the last template update (whichever comes first). To configure these values, use:
1
R(config)# ip flow-export template refresh-rate PACKETS
2
! Default PACKETS: 20
3
R(config)# ip flow-export template timeout-rate MIN
4
! Default MIN: 30
Copied!
You can also configure a source IP for the NetFlow packets with:
1
R(config)# ip flow-export source INTERFACE
Copied!

Cache Aggregation

Cache aggregation is a method of aggregating netflow information in order to reduce the bandwidth requirements of sending detailed flow information to the NetFlow Collector. A flow is added to the aggregated cache only after it expires in the main cache!
To enable cache aggregation, use the command:
1
R(config)# ip flow-aggregation cache METHOD
Copied!
After this, additional configurations can be done:
1
R(config-flow-cache)# export destination HOST UDP-PORT
2
R(config-flow-cache)# export version [8|9]
3
! Only versions 8 and 9 support aggregation
4
R(config-flow-cache)# export template {refresh-rate PACKETS| timeout-rate MIN}
5
! Default PACKETS: 20, Default MIN: 30
6
R(config-flow-cache)# cache entries SIZE
7
! Default 4096
8
R(config-flow-cache)# cache timeout {active MIN | inactive SEC}
9
! Default MIN: 30, Default SEC: 15
10
R(config-flow-cache# enabled
11
! MUST USE to enable the cache! Otherwise, it is not used
Copied!
Verify if it is on by running:
1
R# show ip flow export
Copied!

Netflow reliable export using SCTP

When netflow data are used for accounting (and billing), you need a reliable method to export netflow data. By default Netflow data uses UDP for transport which is unreliable. SCTP stand for Stream Control Transport Protocol and is a transport layer protocol (Protocol numeber 132). SCTP uses a mechanism similar to TCP to control the flow rate (it caches flows locally until the destination aggregator has enough resources to process them) and also retransmits them until they are acknowledged. To enable export of Netflow using SCTP, use:
1
R(config)# ip flow-export destination DEST-IP PORT sctp
Copied!
You will enter a subconfig mode where you can define the parametors for SCTP export:
1
R(config-flow-export-sctp)#backup destination BKP-IP BKP-PORT
2
! Add a backup SCTP destination in case the primary fails:
3
R(config-flow-export-sctp)# backup failover FAILOVER-TIME
4
! How much to wait before declaring the primary destination failed. Default 25 msec
5
R(config-flow-export-sctp)# backup restore-time RESTORE-TIME
6
! How much to wait before declaring the primary destination active again
7
R(config-flow-export-sctp)# backup mode {redundant|fail-over}
8
! In redundant mode it keeps a connection open with the backup all the time.
9
! In fail-over mode it only opens the connection when needed
10
R(config-flow-export-sctp)# reliability {full|none|partial buffer-limit BUFFER-SIZE}
11
! Default: full reliability. Partial reliability only buffers a limited amount of data. None - doesn't buffer anything.
Copied!

NetFlow Top Talkers

Netflow top talkers enable the router to do some a limited ammount of netflow stats locally for quick viewing.
1
R(config)# ip flow-top-talkers
2
! Limit the matching traffic
3
R(config-flow-top-talkers)# match ?
4
byte-range Match a range of bytes
5
class-map Match a class
6
destination Match destination criteria
7
direction Match direction
8
flow-sampler Match a flow sampler
9
input-interface Match input interface
10
nexthop-address Match next hop
11
output-interface Match output interface
12
packet-range Match a range of packets
13
protocol Match protocol
14
source Match source criteria
15
tos Match TOS
16
! Sort flows by packets or bytes
17
R(config-flow-top-talkers)# sort-by {bytes|packets}
18
! Limit number of displayed flows:
19
R(config-flow-top-talkers)# top NUMBER
Copied!
Then, display top talkers statistics, using:
1
R# show ip flow top-talkers
Copied!

Filtering and Samping – MQC based NetFlow

You can limit the type of traffic that is sampled, by using NetFlow in a service policy. First, define the type of traffic that is interesting:
1
R(config)# class-map CLASS-MAP
2
R(config-cmap)# match access-group ACL
Copied!
Then, define a flow-sampler map:
1
R(config)# flow-sampler-map NETFLOW-MAP
2
! Define a sampling frequency
3
R(config-sampler)# mode random one-out-of N
4
! It will only sample 1 packet every N packets
Copied!
Then add this flow-sampler-map to the CLASS-MAP in a POLICY-MAP:
1
R(config)# policy-map POLICY-MAP
2
R(config-pmap)# class {CLASS-MAP|class-default}
3
R(config-pmap-c)# netflow-sampler NETFLOW-MAP
Copied!
Then, apply the policy on an interface:
1
R(config-if)# service-policy {input|output} POLICY-MAP
Copied!
Last modified 24d ago