func (fs *FlowStatistics) updateTransportLayerStatistics(packet *gopacket.Packet) error { if len(fs.Endpoints) <= int(FlowEndpointLayer_TRANSPORT) { return errors.New("Unable to decode the transport layer") } ep := fs.Endpoints[FlowEndpointLayer_TRANSPORT] var transportLayer gopacket.Layer var srcPort string switch ep.Type { case FlowEndpointType_TCPPORT: transportLayer = (*packet).Layer(layers.LayerTypeTCP) transportPacket, _ := transportLayer.(*layers.TCP) srcPort = transportPacket.SrcPort.String() case FlowEndpointType_UDPPORT: transportLayer = (*packet).Layer(layers.LayerTypeUDP) transportPacket, _ := transportLayer.(*layers.UDP) srcPort = transportPacket.SrcPort.String() case FlowEndpointType_SCTPPORT: transportLayer = (*packet).Layer(layers.LayerTypeSCTP) transportPacket, _ := transportLayer.(*layers.SCTP) srcPort = transportPacket.SrcPort.String() } var e *FlowEndpointStatistics if ep.AB.Value == srcPort { e = ep.AB } else { e = ep.BA } e.Packets += uint64(1) e.Bytes += uint64(len(transportLayer.LayerContents()) + len(transportLayer.LayerPayload())) return nil }
func (fs *FlowStatistics) updateTransportFromGoPacket(packet *gopacket.Packet) error { var transportLayer gopacket.Layer transportLayer = (*packet).Layer(layers.LayerTypeTCP) _, ok := transportLayer.(*layers.TCP) ptype := FlowEndpointType_TCPPORT if !ok { transportLayer = (*packet).Layer(layers.LayerTypeUDP) _, ok := transportLayer.(*layers.UDP) ptype = FlowEndpointType_UDPPORT if !ok { transportLayer = (*packet).Layer(layers.LayerTypeSCTP) _, ok := transportLayer.(*layers.SCTP) ptype = FlowEndpointType_SCTPPORT if !ok { return errors.New("Unable to decode the transport layer") } } } ep := fs.Endpoints[ptype.Value()] var srcPort string switch ptype { case FlowEndpointType_TCPPORT: transportPacket, _ := transportLayer.(*layers.TCP) srcPort = transportPacket.SrcPort.String() case FlowEndpointType_UDPPORT: transportPacket, _ := transportLayer.(*layers.UDP) srcPort = transportPacket.SrcPort.String() case FlowEndpointType_SCTPPORT: transportPacket, _ := transportLayer.(*layers.SCTP) srcPort = transportPacket.SrcPort.String() } var e *FlowEndpointStatistics if ep.AB.Value == srcPort { e = ep.AB } else { e = ep.BA } e.Packets += uint64(1) e.Bytes += uint64(len(transportLayer.LayerContents()) + len(transportLayer.LayerPayload())) return nil }