Packages

  • package root

    This is documentation for Mothra, a collection of Scala and Spark library functions for working with Internet-related data.

    This is documentation for Mothra, a collection of Scala and Spark library functions for working with Internet-related data. Some modules contain APIs of general use to Scala programmers. Some modules make those tools more useful on Spark data-processing systems.

    Please see the documentation for the individual packages for more details on their use.

    Scala Packages

    These packages are useful in Scala code without involving Spark:

    org.cert.netsa.data

    This package, which is collected as the netsa-data library, provides types for working with various kinds of information:

    org.cert.netsa.io.ipfix

    The netsa-io-ipfix library provides tools for reading and writing IETF IPFIX data from various connections and files.

    org.cert.netsa.io.silk

    To read and write CERT NetSA SiLK file formats and configuration files, use the netsa-io-silk library.

    org.cert.netsa.util

    The "junk drawer" of netsa-util so far provides only two features: First, a method for equipping Scala scala.collection.Iterators with exception handling. And second, a way to query the versions of NetSA libraries present in a JVM at runtime.

    Spark Packages

    These packages require the use of Apache Spark:

    org.cert.netsa.mothra.datasources

    Spark datasources for CERT file types. This package contains utility features which add methods to Apache Spark DataFrameReader objects, allowing IPFIX and SiLK flows to be opened using simple spark.read... calls.

    The mothra-datasources library contains both IPFIX and SiLK functionality, while mothra-datasources-ipfix and mothra-datasources-silk contain only what's needed for the named datasource.

    org.cert.netsa.mothra.analysis

    A grab-bag of analysis helper functions and example analyses.

    org.cert.netsa.mothra.functions

    This single Scala object provides Spark SQL functions for working with network data. It is the entirety of the mothra-functions library.

    Definition Classes
    root
  • package org
    Definition Classes
    root
  • package cert
    Definition Classes
    org
  • package netsa
    Definition Classes
    cert
  • package mothra
    Definition Classes
    netsa
  • package datasources

    This package contains the Mothra datasources, along with mechanisms for working with those datasources.

    This package contains the Mothra datasources, along with mechanisms for working with those datasources. The primary novel feature of these datasources is the fields mechanism.

    To use the IPFIX or SiLK data sources, you can use the following methods added by the implicit CERTDataFrameReader on DataFrameReader after importing from this package:

    import org.cert.netsa.mothra.datasources._
    val silkDF = spark.read.silkFlow()                                    // to read from the default SiLK repository
    val silkRepoDF = spark.read.silkFlow(repository="...")                // to read from an alternate SiLK repository
    val silkFilesDF = spark.read.silkFlow("/path/to/silk/files")          // to read from loose SiLK files
    val ipfixDF = spark.read.ipfix(repository="/path/to/mothra/data/dir") // for packed Mothra IPFIX data
    val ipfixS3DF = spark.read.ipfix(s3Repository="bucket-name")          // for packed Mothra IPFIX data from an S3 bucket
    val ipfixFilesDF = spark.read.ipfix("/path/to/ipfix/files")           // for loose IPFIX files

    (The additional methods are defined on the implicit class CERTDataFrameReader.)

    Using the fields method allows you to configure which SiLK or IPFIX fields you wish to retrieve. (This is particularly important for IPFIX data, as IPFIX files may contains many many possible fields organized in various ways.)

    import org.cert.netsa.mothra.datasources._
    val silkDF = spark.read.fields("sIP", "dIP").silkFlow(...)
    val ipfixDF = spark.read.fields("sourceIPAddress", "destinationIPAddress").ipfix(...)

    Both of these dataframes will contain only the source and destination IP addresses from the specified data sources. You may also provide column names different from the source field names:

    val silkDF = spark.read.fields("server" -> "sIP", "client" -> "dIP").silkFlow(...)
    val ipfixDF = spark.read.fields("server" -> "sourceIPAddress", "client" -> "destinationIPAddress").ipfix(...)

    You may also mix the mapped and the default names in one call:

    val df = spark.read.fields("sIP", "dIP", "s" -> "sensor").silkFlow(...)
    Definition Classes
    mothra
    See also

    IPFIX datasource

    SiLK flow datasource

  • package ipfix

    A data source as defined by the Spark Data Source API for reading IPFIX records from Mothra data spools and from loose files.

    A data source as defined by the Spark Data Source API for reading IPFIX records from Mothra data spools and from loose files.

    You can use this by importing org.cert.netsa.mothra.datasources._ like this:

    import org.cert.netsa.mothra.datasources._
    val df1 = spark.read.ipfix("path/to/mothra/data/dir") // for packed Mothra IPFIX data
    val df2 = spark.read.ipfix("path/to/ipfix/files")     // for loose IPFIX files

    The IPFIX datasource uses the fields mechanism from org.cert.netsa.mothra.datasources. You can make use of this mechanism like these examples:

    import org.cert.netsa.mothra.datasources._
    val df1 = spark.read.fields(
      "startTime", "endTime", "sourceIPAddress", "destinationIPAddress"
    ).ipfix(...)
    
    val df2 = spark.read.fields(
      "startTime", "endTime", "TOS" -> "ipClassOfService"
    ).ipfix(...)

    with arbitrary sets of fields and field name mappings.

    Default Fields

    The default set of fields (defined in IPFIXFields.default) is:

    • "startTime" -> "func:startTime"
    • "endTime" -> "func:endTime"
    • "sourceIPAddress" -> "func:sourceIPAddress"
    • "sourcePort" -> "func:sourcePort"
    • "destinationIPAddress" -> "func:destinationIPAddress"
    • "destinationPort" -> "func:destinationPort"
    • "protocolIdentifier"
    • "observationDomainId"
    • "vlanId"
    • "reverseVlanId"
    • "silkAppLabel"
    • "packetCount" -> "packetTotalCount|packetDeltaCount"
    • "reversePacketCount" -> "reversePacketTotalCount|reversePacketDeltaCount"
    • "octetCount" -> "octetTotalCount|octetDeltaDcount"
    • "reverseOctetCount" -> "reverseOctetTotalCount|reverseOctetDeltaCount"
    • "initialTCPFlags"
    • "reverseInitialTCPFlags"
    • "unionTCPFlags"
    • "reverseUnionTCPFlags"

    Some of these defaults are defined simply as IPFIX Information Elements. For example, "protocolIdentifier" and "vlanId" are exactly the Information Elements that are named. No "right-hand-side" is given for these definitions, because the name of the field is the same as the name of the Information Element.

    Others have simple expressions. For example, packetCount is defined as "packetTotalCount|packetDeltaCount". This expressions means that the value should be found from the packetTotalCount IE, or if that is not set from the packetDeltaCount IE. This allows this field to be used regardless of which Information Element contains the data.

    Some others are derived in more complex ways from basic IPFIX fields. For example, the startTime field is produced using "func:startTime", which runs the "gauntlet of time" to determine the start time for a flow by whatever means possible. Other time fields are similarly defined.

    Some of the "func:..." fields are actually quite simple. For example, "func:sourceIPAddress", practically speaking, is the same as "sourceIPv4Address|sourceIPv6Address". However, these fields are defined using the func: extension mechanism so that partitioning on them is possible. (This restriction may be lifted in a future Mothra version.)

    Field Types

    The mappings between IPFIX types and Spark types are:

    • octetArray → Array[Byte]
    • unsigned8 → Short
    • unsigned16 → Int
    • unsigned32 → Long
    • unsigned64 → Long
    • signed8 → Byte
    • signed16 → Short
    • signed32 → Int
    • signed64 → Long
    • float32 → Float
    • float64 → Double
    • boolean → Boolean
    • macAddress → String
    • string → String
    • dateTimeSeconds → Timestamp
    • dateTimeMilliseconds → Timestamp
    • dateTimeMicroseconds → Timestamp
    • dateTimeNanoseconds → Timestamp
    • ipv4Address → String
    • ipv6Address → String

    IPFIX's basicList, subTemplateList, and subTemplateMultiList data types are handled differently.

    Field Expressions

    As noted above, field expressions may contain simple IPFIX Information Element names, or collections of names separated by pipe characters to indicate taking the first matching choice. This language has a number of other capabilities which are documented for now in the IPFIX field parser object.

    Functional Fields

    A number of pre-defined "functional fields" are available. Some of these combine other information elements in ways that the expression language cannot (applying the so-called "gauntlet of time", for example). Others provide support for the Mothra repository partitioning system. And finally, a few are for debugging purposes and provide high-level overviews of IPFIX records or point to file locations on disk.

    Function fields are all defined and described in the org.cert.netsa.mothra.datasources.ipfix.fields.func package.

    Definition Classes
    datasources
  • package fields

    Most of these classes and traits relate to the definition of IPFIX fields as IPFIX record processing objects.

    Most of these classes and traits relate to the definition of IPFIX fields as IPFIX record processing objects.

    The IPFIXFieldParsing object defines the parser used for IPFIX field expressions, and includes the documentation for that language.

    Other mechanisms, including implementations of the IPFIXField trait, provide the ability to define new "function" fields and register them into the Func registry. This is an experimental capabilty and is likely to be deprecated and then removed from public access in the future.

    Definition Classes
    ipfix
    Note

    This is an experimental interface and is likely to be removed or made private in a future version.

  • package func

    The objects in this package represent "function fields" usable in the IPFIX data source.

    The objects in this package represent "function fields" usable in the IPFIX data source. These fields may each be accessed by the field expression "func:<fieldName>", for example "func:recordInfo" in a field expression will produce a human-readable string record as described below.

    Definition Classes
    fields
    See also

    org.cert.netsa.mothra.datasources.ipfix for examples of field expressions

    IPFIXFieldParsing for details about the field path grammar

  • ArrayField
  • BasicListField
  • DeepTemplateField
  • Func
  • IPFIXField
  • IPFIXFieldParsing
  • IPFIXFieldSparkVerImpl
  • InfoElementField
  • MapField
  • MatchField
  • SimpleField
  • StructField
  • SubTemplateField
  • TimeGauntlet
  • UnionField

object IPFIXFieldParsing extends RegexParsers

Parser for IPFIX field expressions.

Note that whitespace is allowed anywhere and not significant except between quotes.

fieldUnion ::=
  | field "|" fieldUnion
  | field

fieldUnion is the top-level entrypoint. A fieldUnion is a set of one or more fields separated by pipes, allowing for the first match. fieldUnions can appear inside parentheses in sub-expressions.

field ::=
  | "(" fieldUnion ")"
  | "array" "(" fieldUnion ")"
  | "match" "(" fieldUnion "," id "," fieldUnion ")"
  | "struct" "(" namedFieldList ")"
  | "**" "/" field
  | wildId ":" wildId "/" field
  | wildId "/" field
  | wildId "[" elemId "]"
  | funcId
  | elemId

field is the place most stuff happens. Here are all of the different sorts of fields:

Fields may be grouped by parentheses like (<field> [ | <field> ... ]), and field unions may appear inside the parenthesis.

To collect all values from the given field into an array, array(<fieldUnion>) may be used.

match(<fieldUnion>, <value>, <fieldUnion>) takes the results of two field expressions in parallel. The first field is the "key field", the value is the "target value", and the second field is the "value field". If the key field's iterator's value ki in a given position i matches the target value, then the result field's iterators value vi at that same location is included in the result of the match. (The value is parsed in the same way as an ID, and is taken as a literal value, a string or integral value depending on the type of the matched field.)

To produce a structured value, struct(<namedField>[, <namedField> ...]) takes multiple field expressions in parallel to produce a possibly nested record structure. All of the sub-fields' iterators are zipped together to produce an iterator of records.

**/<field> may be used to apply the given field in this record or a subrecord at any depth. This is useful for cases where you don't know where an Information Element might appear in a record.

To access nested SubTemplateList or SubTemplateMultiList data, <listElemName> [: <templateName>] / <field> will find the given field in a subrecord in the given STL- or STML-typed information element, and optionally under a template that has been given the provided name. Either templateElemName or templateName can be * for a wildcard.

func:<funcName> will use the registered function field with this name on the current record and produce the result.

Finally, the most basic <elemName> will find the named information element in the current record.

namedFieldList ::=
  | namedField "," namedFieldList
  | namedField

A namedFieldList is a comma-separated list of named fields, as arguments to struct or match.

namedField ::=
  | id "=" fieldUnion
  | fieldUnion

A namedField gives a field a name--for example, in the fields of a struct(<namedField>[, <namedField ...]) call, to give names ot the nested structure. If a name isn't given for the field, one will be generated from the field expression in a unspecified manner.

id ::=
  | [not whitespace or any of '/:()\"']+
  | '"' ([not '\' or '"']+ | "\" [any of 'btnfr\"''])* '"'

An ID can't have a number of special symbols in it, but you can put an escaped ID in quotes that can have anything at all.

wildId ::= id | '*'

Wildcard IDs (for subrecord IE names and subtemplate names) can be an ID or * for "any".

funcId ::= "func:" id

Calls to function fields are identified with "func:<id>". See the func package for details on what function fields are defined.

elemId ::= id - "array"

Individual element fields can can be any ID other than "array" (unless it's in quotes).

Linear Supertypes
RegexParsers, Parsers, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. IPFIXFieldParsing
  2. RegexParsers
  3. Parsers
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. type Elem = Char
    Definition Classes
    RegexParsers → Parsers
  2. case class Error extends NoSuccess with Product with Serializable
    Definition Classes
    Parsers
  3. case class Failure extends NoSuccess with Product with Serializable
    Definition Classes
    Parsers
  4. type Input = Reader[Elem]
    Definition Classes
    Parsers
  5. sealed abstract class NoSuccess extends ParseResult[Nothing]
    Definition Classes
    Parsers
  6. trait OnceParser[+T] extends Parser[T]
    Definition Classes
    Parsers
  7. sealed abstract class ParseResult[+T] extends AnyRef
    Definition Classes
    Parsers
  8. abstract class Parser[+T] extends (Input) => ParseResult[T]
    Definition Classes
    Parsers
  9. case class Success[+T] extends ParseResult[T] with Product with Serializable
    Definition Classes
    Parsers
  10. case class ~[+a, +b] extends Product with Serializable
    Definition Classes
    Parsers

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def OnceParser[T](f: (Input) => ParseResult[T]): Parser[T] with OnceParser[T]
    Definition Classes
    Parsers
  5. def Parser[T](f: (Input) => ParseResult[T]): Parser[T]
    Definition Classes
    Parsers
  6. def accept[U](expected: String, f: PartialFunction[Elem, U]): Parser[U]
    Definition Classes
    Parsers
  7. def accept[ES](es: ES)(implicit f: (ES) => List[Elem]): Parser[List[Elem]]
    Definition Classes
    Parsers
  8. implicit def accept(e: Elem): Parser[Elem]
    Definition Classes
    Parsers
  9. def acceptIf(p: (Elem) => Boolean)(err: (Elem) => String): Parser[Elem]
    Definition Classes
    Parsers
  10. def acceptMatch[U](expected: String, f: PartialFunction[Elem, U]): Parser[U]
    Definition Classes
    Parsers
  11. def acceptSeq[ES](es: ES)(implicit f: (ES) => Iterable[Elem]): Parser[List[Elem]]
    Definition Classes
    Parsers
  12. def apply[T](input: String): IPFIXField[T]
  13. def arrayField: Parser[IPFIXField[Any]]
  14. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  15. def atomId: Parser[String]
  16. def basicListField: Parser[IPFIXField[Any]]
  17. def chainl1[T, U](first: => Parser[T], p: => Parser[U], q: => Parser[(T, U) => T]): Parser[T]
    Definition Classes
    Parsers
  18. def chainl1[T](p: => Parser[T], q: => Parser[(T, T) => T]): Parser[T]
    Definition Classes
    Parsers
  19. def chainr1[T, U](p: => Parser[T], q: => Parser[(T, U) => U], combine: (T, U) => U, first: U): Parser[U]
    Definition Classes
    Parsers
  20. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  21. def commit[T](p: => Parser[T]): Parser[T]
    Definition Classes
    Parsers
  22. def deepTemplateField: Parser[IPFIXField[Any]]
  23. def elem(e: Elem): Parser[Elem]
    Definition Classes
    Parsers
  24. def elem(kind: String, p: (Elem) => Boolean): Parser[Elem]
    Definition Classes
    Parsers
  25. def elemField: Parser[IPFIXField[Any]]
  26. def elemId: Parser[String]
  27. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  28. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  29. def err(msg: String): Parser[Nothing]
    Definition Classes
    Parsers
  30. def failure(msg: String): Parser[Nothing]
    Definition Classes
    Parsers
  31. def field: Parser[IPFIXField[Any]]
  32. def fieldUnion: Parser[IPFIXField[Any]]
  33. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  34. def funcField: Parser[IPFIXField[Any]]
  35. def funcId: Parser[String]
  36. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  37. def guard[T](p: => Parser[T]): Parser[T]
    Definition Classes
    Parsers
  38. def handleWhiteSpace(source: CharSequence, offset: Int): Int
    Attributes
    protected
    Definition Classes
    RegexParsers
  39. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  40. def id: Parser[String]
  41. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  42. implicit def literal(s: String): Parser[String]
    Definition Classes
    RegexParsers
  43. def log[T](p: => Parser[T])(name: String): Parser[T]
    Definition Classes
    Parsers
  44. def lookupFunc(name: String): IPFIXField[Any]
  45. def matchField: Parser[IPFIXField[Any]]
  46. def mkList[T]: (~[T, List[T]]) => List[T]
    Definition Classes
    Parsers
  47. def namedField: Parser[(String, IPFIXField[Any])]
  48. def namedFieldList: Parser[Seq[(String, IPFIXField[Any])]]
  49. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  50. def not[T](p: => Parser[T]): Parser[Unit]
    Definition Classes
    Parsers
  51. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  52. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  53. def opt[T](p: => Parser[T]): Parser[Option[T]]
    Definition Classes
    Parsers
  54. def parse[T](p: Parser[T], in: Reader): ParseResult[T]
    Definition Classes
    RegexParsers
  55. def parse[T](p: Parser[T], in: CharSequence): ParseResult[T]
    Definition Classes
    RegexParsers
  56. def parse[T](p: Parser[T], in: Reader[Char]): ParseResult[T]
    Definition Classes
    RegexParsers
  57. def parseAll[T](p: Parser[T], in: CharSequence): ParseResult[T]
    Definition Classes
    RegexParsers
  58. def parseAll[T](p: Parser[T], in: Reader): ParseResult[T]
    Definition Classes
    RegexParsers
  59. def parseAll[T](p: Parser[T], in: Reader[Char]): ParseResult[T]
    Definition Classes
    RegexParsers
  60. def phrase[T](p: Parser[T]): Parser[T]
    Definition Classes
    RegexParsers → Parsers
  61. def positioned[T <: Positional](p: => Parser[T]): Parser[T]
    Definition Classes
    RegexParsers → Parsers
  62. def quotedId: Parser[String]
  63. implicit def regex(r: Regex): Parser[String]
    Definition Classes
    RegexParsers
  64. def rep[T](p: => Parser[T]): Parser[List[T]]
    Definition Classes
    Parsers
  65. def rep1[T](first: => Parser[T], p0: => Parser[T]): Parser[List[T]]
    Definition Classes
    Parsers
    Annotations
    @migration
    Migration

    (Changed in version 2.9.0) The p0 call-by-name arguments is evaluated at most once per constructed Parser object, instead of on every need that arises during parsing.

  66. def rep1[T](p: => Parser[T]): Parser[List[T]]
    Definition Classes
    Parsers
  67. def rep1sep[T](p: => Parser[T], q: => Parser[Any]): Parser[List[T]]
    Definition Classes
    Parsers
  68. def repN[T](num: Int, p: => Parser[T]): Parser[List[T]]
    Definition Classes
    Parsers
  69. def repsep[T](p: => Parser[T], q: => Parser[Any]): Parser[List[T]]
    Definition Classes
    Parsers
  70. def skipWhitespace: Boolean
    Definition Classes
    RegexParsers
  71. def structField: Parser[IPFIXField[Any]]
  72. def subTemplateField: Parser[IPFIXField[Any]]
  73. def success[T](v: T): Parser[T]
    Definition Classes
    Parsers
  74. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  75. def toString(): String
    Definition Classes
    AnyRef → Any
  76. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  77. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  78. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  79. val whiteSpace: Regex
    Attributes
    protected
    Definition Classes
    RegexParsers
  80. def wild(p: Parser[String]): Parser[Option[String]]

Inherited from RegexParsers

Inherited from Parsers

Inherited from AnyRef

Inherited from Any

Ungrouped