britram / python-ipfix

IPFIX implementation for Python 3.x
GNU Lesser General Public License v3.0
40 stars 20 forks source link

How are option templates created? #20

Closed nickbroon closed 6 years ago

nickbroon commented 7 years ago

The example for a regular template is given as something like:

ipfix.ie.use_iana_default()

tmpl = ipfix.template.for_specs(261, "flowStartMilliseconds", 
                                     "flowEndMilliseconds", 
                                     "sourceIPv4Address", 
                                     "destinationIPv4Address",
                                     "sourceTransportPort",
                                     "destinationTransportPort",
                                     "protocolIdentifier",
                                     "octetDeltaCount", 
                                     "packetDeltaCount")

msg = ipfix.message.MessageBuffer()
msg.begin_export(8304)
msg.add_template(tmpl)
msg.export_new_set(261)
msg.export_namedict({ 'flowStartMilliseconds':    iso8601('2012-10-22 09:29:07.170000'),
                      'flowEndMilliseconds':      iso8601('2012-10-22 09:29:33.916000'),
                      'sourceIPv4Address':        ip_address('192.0.2.11'),
                      'destinationIPv4Address':   ip_address('192.0.2.212'),
                      'sourceTransportPort':      32798,
                      'destinationTransportPort': 80,
                      'protocolIdentifier':       6,
                      'packetDeltaCount':         17,
                      'octetDeltaCount':          3329})

But how would a message containing a option template be constructed? The below creates the template and data records, but how is the template identified as an option template and the scope length set to 1?

ipfix.ie.use_iana_default()

tmpl = ipfix.template.for_specs(262, "applicationId", 
                                     "applicationName")

msg = ipfix.message.MessageBuffer()
msg.begin_export(8304)
msg.add_template(tmpl)
msg.export_new_set(262)
msg.export_namedict({ 'applicationId':    2345,
                      'applicationName':      'foobar'})
britram commented 6 years ago

Short answer: you can't create an options template from a spec list without a hack. RFC 7013 section 10 suggests you should be able to do this by putting a {scope} context on the IEs you want to be scope elements, but python-ipfix doesn't implement this.

The hack is to manually set the scope count after creating the template:

tmpl = ipfix.template.for_specs(262, "applicationId", 
                                     "applicationName")
tmpl.scopecount = 1
nickbroon commented 6 years ago

Thanks for the tip Brian.