Documentation
¶
Overview ¶
Package packetsAndErrors provides all necessary functions to analyse network traffic for errors.
From extracting the packets out of a pcap file, over matching of the packets, to calculating the probabilities for errors.
Index ¶
- Constants
- func CalculateAllErrors(leftPcapFiles []string, rightPcapFiles []string, ...) (leftToRightFlowMatchedPackets *MatchedPackets, ...)
- func CalculateDuplicateRate(packets []*PacketAndPositionTuple, flowDirection int8) float64
- func CalculateJitter(packets []*PacketAndPositionTuple) float64
- func CalculateLossRate(packets []*PacketAndPositionTuple, flowDirection int8) float64
- func CalculateMarkovRates(packets []*PacketAndPositionTuple, flowDirection int8, ...) (p02, p20, p21, p12, p03 float64)
- func CalculateReorderRate(numberOfReorderedPackets int64, packetTuples []*PacketAndPositionTuple) float64
- type MatchedPackets
- func (matchedPackets *MatchedPackets) GetCapacityForStatusUpdateChan() int
- func (matchedPackets *MatchedPackets) MatchPackets(layer int8, flowDirection int8) (numberOfReorderedPackets int64, err error)
- func (matchedPackets *MatchedPackets) MatchedPackets() []*PacketAndPositionTuple
- func (matchedPackets *MatchedPackets) Packets() *Packets
- func (matchedPackets *MatchedPackets) RegisterForStatusUpdate(chanToRegister chan int) error
- type PacketAndPosition
- type PacketAndPositionTuple
- type PacketAndPossibleMatches
- type Packets
- func (packets *Packets) DividePacketsBasedOnDirection(macAddressesOnTheLeft []net.HardwareAddr, ...) (leftToRightFlowPackets, rightToLeftFlowPackets *Packets, err error)
- func (packets *Packets) FilterPacketsBasedMacAddresses(macAddresses ...net.HardwareAddr)
- func (packets *Packets) FilterPacketsBasedOnIpAddresses(ipAddresses ...net.IP)
- func (packets *Packets) LeftPackets() []gopacket.Packet
- func (packets *Packets) RemoveAllPacketsWithoutLayer3()
- func (packets *Packets) RightPackets() []gopacket.Packet
Constants ¶
const ( LinkLayer int8 = iota + 2 NetworkLayer )
Public constants for the network layers.
The link layer is 2. the network layer is 3.
const ( FlowLeftToRight int8 = iota FlowRightToLeft )
Public constants for the flow directions.
FlowLeftToRight is 0. FlowRightToLeft is 1.
Variables ¶
This section is empty.
Functions ¶
func CalculateAllErrors ¶
func CalculateAllErrors( leftPcapFiles []string, rightPcapFiles []string, macAddressesOnTheLeftSide []net.HardwareAddr, macAddressesOnTheRightSide []net.HardwareAddr, ipAddressesOnTheLeftSide []net.IP, ipAddressesOnTheRightSide []net.IP, maxNumberOfPacketsReceivedDuringBurst int, ) ( leftToRightFlowMatchedPackets *MatchedPackets, rightToLeftFlowMatchedPackets *MatchedPackets, leftToRightLoss float64, rightToLeftLoss float64, leftToRightMarkovP02, leftToRightMarkovP20, leftToRightMarkovP21, leftToRightMarkovP12, leftToRightMarkovP03 float64, rightToLeftMarkovP02, rightToLeftMarkovP20, rightToLeftMarkovP21, rightToLeftMarkovP12, rightToLeftMarkovP03 float64, leftToRightDuplication float64, rightToLeftDuplication float64, leftToRightReorder float64, rightToLeftReorder float64, leftToRightJitter float64, rightToLeftJitter float64, err []error, )
CalculateAllErrors is a public functions that provides the whole process of error calculation. From reading the packets from the files to calculating all errors.
Takes:
leftPcapFiles []string - a slice which contains the path to the pcap files
recorded on the left side
rightPcapFiles []string - a slice which contains the path to the pcap files
recorded on the right side
macAddressesOnTheLeftSide []net.HardwareAddr - a slice containing the MAC addresses of the systems
which are connected on the left side
macAddressesOnTheRight []net.HardwareAddr - a slice containing the MAC addresses of the systems
which are connected on the left side
ipAddressesOnTheLeft []net.IP - a slice containing the IP addresses of the systems
which are connected on the left side
ipAddressesOnTheRight []net.IP - a slice containing the IP addresses of the systems
which are connected on the left side
maxNumberOfPacketsReceivedDuringBurst int - the number of packets, that can be received
during a burst without changing into state 0
Based on the provided addresses the network layer will be extracted. Layer 3 will be preferred. Addresses form just one side must be provided, at least one address in total.
Returns: All values for the errors, an error if one occurred.
func CalculateDuplicateRate ¶
func CalculateDuplicateRate(packets []*PacketAndPositionTuple, flowDirection int8) float64
CalculateDuplicateRate is a public function that calculates the probability for duplication in a PacketAndPositionTuple slice of matched packets.
Takes:
packets []*PacketAndPositionTuple - a pointer to a slice of matched packets flowDirection int8 - the flow direction of the matched packets
Returns: float64 - the probability for duplication in the matched packets
func CalculateJitter ¶
func CalculateJitter(packets []*PacketAndPositionTuple) float64
CalculateJitter is a public function to calculates the jitter of given packets in ms.
Takes:
packets []*PacketAndPositionTuple - a pointer to a slice of matched packets
Returns:
float64 - the loss in ms
func CalculateLossRate ¶
func CalculateLossRate(packets []*PacketAndPositionTuple, flowDirection int8) float64
CalculateLossRate is a public function that calculates the probability for loss in a PacketAndPositionTuple slice of matched packets.
Takes:
packets []*PacketAndPositionTuple - a pointer to a slice of matched packets flowDirection int8 - the flow direction of the matched packets
Returns: float64 - the probability for loss in the matched packets
func CalculateMarkovRates ¶
func CalculateMarkovRates( packets []*PacketAndPositionTuple, flowDirection int8, maxNumberOfPacketsReceivedDuringBurst int, ) (p02, p20, p21, p12, p03 float64)
CalculateMarkovRates is a public function to calculate the probabilities for the simulation of loss with markov chains. State 0: good reception State 3: loss during good reception State 2: burst loss State 1: good reception during burst
Takes:
packets []*PacketAndPositionTuple - a slice of pointers to matched packets flowDirection int8 - the flow direction maxNumberOfPacketsReceivedDuringBurst int - the number of packets, that can be received during a burst without changing into state 0
Returns:
p02 float64 - probability for transition from state 0 to 2 p20 float64 - probability for transition from state 2 to 0 p12 float64 - probability for transition from state 1 to 2 p21 float64 - probability for transition from state 2 to 1 p04 float64 - probability for transition from state 0 to 3
func CalculateReorderRate ¶
func CalculateReorderRate(numberOfReorderedPackets int64, packetTuples []*PacketAndPositionTuple) float64
CalculateReorderRate is a public function to calculate the probability of reorder in matched packets.
Takes:
numberOfReorderedPackets int64 - the number of reordered packets packetTuples []*PacketAndPositionTuple - a slice of pointers to matched packets
Types ¶
type MatchedPackets ¶
type MatchedPackets struct {
// contains filtered or unexported fields
}
MatchedPackets is a structure to hold foremost a slice containing the pointers to matched packets.
packets *Packets - a pointer to a Packets struct with the packets from two sides that should be matched matchedPackets []*PacketAndPositionTuple - a slice containing pointers to the matched packets, each tuple is one match statusChan chan int - a channel to transfer the index of the currently matched packet for status updates chansToGetStatus []chan int - other parts of the software can register for status updates via a channel, these channels are stored here
func NewMatchedPackets ¶
func NewMatchedPackets(packets *Packets, flowDirection int8) (matchedPacketsPointer *MatchedPackets, err error)
NewMatchedPackets is a constructor for the MatchedPackets struct. Call MatchPackets to match the packets.
Takes:
packets *Packets - a pointer to a Packets struct as cointaining the packets to match flowDirection int8 - the flow direction of the packets, eiter left to right (0) or right to left (1)
Returns:
matchedPacketsPointer *MatchedPackets - a pointer to the MatchedPackets structure, the packets aren't matched err error - the error if one appears, nil if not
func (*MatchedPackets) GetCapacityForStatusUpdateChan ¶
func (matchedPackets *MatchedPackets) GetCapacityForStatusUpdateChan() int
GetCapacityForStatusUpdateChan is a public function to get the minimum capacity of an channel that can be registered for via the RegisterForStatusUpdate function.
Operates on:
matchedPackets *MatchedPackets - a pointer to a MatchedPackets structure of which the needed minimum capacity should be evaluated
Returns: int - the minimum capacity
func (*MatchedPackets) MatchPackets ¶
func (matchedPackets *MatchedPackets) MatchPackets( layer int8, flowDirection int8, ) (numberOfReorderedPackets int64, err error)
MatchPackets is a public function which matches the packets. The matched and unmatched packets can be found in the MatchedPackets field of the MatchedPackets struct. Unmatched packets will have a nil value at the other side of the tuple.
Operates on:
matchedPackets *MatchedPackets - the MatchedPackets struct of which the packets should get matched, after this function it will include the matched packets in the MatchedPackets field
Takes:
layer int8 - the layer at which the packets should match flowDirection int8 - the flow direction of the packets
Returns:
numberOfReorderedPackets int64 - the number how many packets got reordered err error - the error if one appears, nil if not
func (*MatchedPackets) MatchedPackets ¶
func (matchedPackets *MatchedPackets) MatchedPackets() []*PacketAndPositionTuple
MatchedPackets is a public getter funciton for the matchedPackets field of a MatchedPackets structure.
func (*MatchedPackets) Packets ¶
func (matchedPackets *MatchedPackets) Packets() *Packets
Packets is a public getter function for the packets field of a MatchedPackets structure.
func (*MatchedPackets) RegisterForStatusUpdate ¶
func (matchedPackets *MatchedPackets) RegisterForStatusUpdate(chanToRegister chan int) error
RegisterForStatusUpdate is a public function which can be used to register a channel from another part of the program that should receive status updates of the current progress of the packet matching.
Operates on:
matchedPackets *MatchedPackets - a pointer to the MatchedPackets structure which should report the status
Takes:
chanToRegister chan int - the channel to register
Returns:
error - returns nil if the channel is registered and an error describing the registration problem if the registration wasn't possible
type PacketAndPosition ¶
type PacketAndPosition struct {
// contains filtered or unexported fields
}
PacketAndPosition is a structure which contains a pointer to a packet, and it's position in a record.
packet *gopacket.Packet - a pointer to a packet position int - the position of the packet
func (*PacketAndPosition) Packet ¶
func (packetAndPosition *PacketAndPosition) Packet() *gopacket.Packet
Packet is a public getter function for the private packet field of the PacketAndPosition structure
func (*PacketAndPosition) Position ¶
func (packetAndPosition *PacketAndPosition) Position() int
Position is a public getter function for the private position field of the PacketAndPosition structure
type PacketAndPositionTuple ¶
type PacketAndPositionTuple struct {
// contains filtered or unexported fields
}
PacketAndPositionTuple is a structure that contains to PacketAndPosition structures
left *PacketAndPosition - a pointer to the left PacketAndPosition structure of the tuple right *PacketAndPosition - a pointer to the right PacketAndPosition structure of the tuple
func (*PacketAndPositionTuple) Left ¶
func (packetAndPositionTuple *PacketAndPositionTuple) Left() *PacketAndPosition
Left is a public getter function for the private left field of the PacketAndPositionTuple structure
func (*PacketAndPositionTuple) Right ¶
func (packetAndPositionTuple *PacketAndPositionTuple) Right() *PacketAndPosition
Right is a public getter function for the private right field of the PacketAndPositionTuple structure
type PacketAndPossibleMatches ¶
type PacketAndPossibleMatches struct {
// contains filtered or unexported fields
}
PacketAndPossibleMatches is a structure that contains a packet, and its possible matches.
packet *PacketAndPosition - a pointer to a packet possibleMatches []*PacketAndPossibleMatches - a slice of pointers to possible matches of this packet
func (*PacketAndPossibleMatches) Packet ¶
func (packetAndPossibleMatches *PacketAndPossibleMatches) Packet() *PacketAndPosition
Packet is a public getter function for the private packet field of the PacketAndPossibleMatches structure
func (*PacketAndPossibleMatches) PossibleMatches ¶
func (packetAndPossibleMatches *PacketAndPossibleMatches) PossibleMatches() []*PacketAndPossibleMatches
PossibleMatches is a public getter function for the private possibleMatches field of the PacketAndPossibleMatches structure
type Packets ¶
type Packets struct {
// contains filtered or unexported fields
}
Packets includes 2 arrays of packets.
leftPackets []gopacket.Packet - holds the packets recorded on the left side rightPackets []gopacket.Packet - holds the packets recorded on the rightside
func NewPackets ¶
NewPackets is a constructor for the Packets struct.
Takes:
leftPcapFiles []string - a slice which contains the path to the pcap files recorded on the left side rightPcapFiles []string - a slice which contains the path to the pcap files recorded on the right side
Returns:
*Packets - a pointer to the constructed Packets struct. []error - a slice of errors, if errors occurred during opening the files
func (*Packets) DividePacketsBasedOnDirection ¶
func (packets *Packets) DividePacketsBasedOnDirection( macAddressesOnTheLeft []net.HardwareAddr, macAddressesOnTheRight []net.HardwareAddr, ipAddressesOnTheLeft []net.IP, ipAddressesOnTheRight []net.IP, layer int8, ) (leftToRightFlowPackets, rightToLeftFlowPackets *Packets, err error)
DividePacketsBasedOnDirection is a public function to split a Packets structure into 2, where each structure contains only the packets flowing either form left to right or from right to left
Operates on:
packets *Packets - the Packets structure in which the packets should be split by flow direction
Takes:
macAddressesOnTheLeft []net.HardwareAddr - a slice containing the MAC addresses of the systems which are connected on the left side macAddressesOnTheRight []net.HardwareAddr - a slice containing the MAC addresses of the systems which are connected on the left side ipAddressesOnTheLeft []net.IP - a slice containing the IP addresses of the systems which are connected on the left side ipAddressesOnTheRight []net.IP - a slice containing the IP addresses of the systems which are connected on the left side layer int8 - the ISO/OSI layer which should be used for the splitting, either 2 or 3
Based on the used layer the slices of the other layer will not be used and can be empty. Addresses form just one side must be provided, at least one address in total.
Returns:
leftToRightFlowPackets *Packets - a new Packets structure containing only the Packets flowing form left to right rightToLeftFlowPackets *Packets - a new Packets structure containing only the Packets flowing from right to left err error - the error if one occurs, nil if not
func (*Packets) FilterPacketsBasedMacAddresses ¶
func (packets *Packets) FilterPacketsBasedMacAddresses(macAddresses ...net.HardwareAddr)
FilterPacketsBasedMacAddresses is a public function to filter the slices in a Packets structure by given MAC addresses
Operates on:
packets *Packets - the Packets structure with the packet slices that should be filtered, the packet slices will be manipulated
Takes:
ipAddresses ...net.HardwareAddr - one or multiple MAC addresses that should be included as source or destination in the packets
func (*Packets) FilterPacketsBasedOnIpAddresses ¶
FilterPacketsBasedOnIpAddresses is a public function to filter the slices in a Packets structure by given IP addresses
Operates on:
packets *Packets - the Packets structure with the packet slices that should be filtered, the packet slices will be manipulated
Takes:
ipAddresses ...net.IP - one or multiple IP addresses that should be included as source or destination in the packets
func (*Packets) LeftPackets ¶
LeftPackets is a public getter function for the leftPackets field of a Packets structure.
func (*Packets) RemoveAllPacketsWithoutLayer3 ¶
func (packets *Packets) RemoveAllPacketsWithoutLayer3()
RemoveAllPacketsWithoutLayer3 is a public function to remove all packets in a Packets struct which do not include a layer 3 datagram.
Operates on:
packets *Packets - the Packets structure with the packet slices that should be filtered, the packet slices will be manipulated
func (*Packets) RightPackets ¶
RightPackets is a public getter function for teh rightPackets field of a Packets structure.