本文整理匯總了Golang中github.com/elastic/beats/packetbeat/protos.ProtocolData函數的典型用法代碼示例。如果您正苦於以下問題:Golang ProtocolData函數的具體用法?Golang ProtocolData怎麽用?Golang ProtocolData使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ProtocolData函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestAmqp_ChannelCloseErrorMethod
func TestAmqp_ChannelCloseErrorMethod(t *testing.T) {
if testing.Verbose() {
logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"amqp", "amqpdetailed"})
}
amqp := amqpModForTests()
data, err := hex.DecodeString("0100010000009000140028019685505245434f4e444" +
"954494f4e5f4641494c4544202d20696e6571756976616c656e74206172672027617574" +
"6f5f64656c6574652720666f722065786368616e676520277465737445786368616e676" +
"52720696e2076686f737420272f273a207265636569766564202774727565272062757" +
"42063757272656e74206973202766616c7365270028000ace")
assert.Nil(t, err)
data2, err := hex.DecodeString("0100010000000400280033ce")
assert.Nil(t, err)
tcptuple := testTCPTuple()
req := protos.Packet{Payload: data}
private := protos.ProtocolData(new(amqpPrivateData))
private = amqp.Parse(&req, tcptuple, 0, private)
req = protos.Packet{Payload: data2}
amqp.Parse(&req, tcptuple, 1, private)
trans := expectTransaction(t, amqp)
assert.Equal(t, "channel.close", trans["method"])
assert.Equal(t, "amqp", trans["type"])
assert.Equal(t, common.ERROR_STATUS, trans["status"])
assert.Nil(t, trans["notes"])
}
示例2: TestAmqp_MultipleBodyFrames
func TestAmqp_MultipleBodyFrames(t *testing.T) {
if testing.Verbose() {
logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"amqp", "amqpdetailed"})
}
amqp := amqpModForTests()
amqp.sendRequest = true
data, err := hex.DecodeString("0100010000000e003c00280000000568656c6c6f00ce" +
"02000100000021003c0000000000000000002a80400a746578742f706c61696e00000000" +
"56a22873ce030001000000202a2a2a68656c6c6f2049206c696b6520746f207075626c69" +
"736820626967206dce")
assert.Nil(t, err)
data2, err := hex.DecodeString("0300010000000a657373616765732a2a2ace")
assert.Nil(t, err)
tcptuple := testTCPTuple()
req := protos.Packet{Payload: data}
private := protos.ProtocolData(new(amqpPrivateData))
private = amqp.Parse(&req, tcptuple, 0, private)
req = protos.Packet{Payload: data2}
amqp.Parse(&req, tcptuple, 0, private)
trans := expectTransaction(t, amqp)
assert.Equal(t, "basic.publish", trans["method"])
assert.Equal(t, "***hello I like to publish big messages***", trans["request"])
}
示例3: TestAmqp_ConnectionCloseNoError
func TestAmqp_ConnectionCloseNoError(t *testing.T) {
if testing.Verbose() {
logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"amqp", "amqpdetailed"})
}
amqp := amqpModForTests()
amqp.hideConnectionInformation = false
data, err := hex.DecodeString("01000000000012000a003200c8076b74687862616900000000ce")
assert.Nil(t, err)
data2, err := hex.DecodeString("01000000000004000a0033ce")
assert.Nil(t, err)
tcptuple := testTCPTuple()
req := protos.Packet{Payload: data}
private := protos.ProtocolData(new(amqpPrivateData))
private = amqp.Parse(&req, tcptuple, 0, private)
req = protos.Packet{Payload: data2}
amqp.Parse(&req, tcptuple, 1, private)
trans := expectTransaction(t, amqp)
assert.Equal(t, "connection.close", trans["method"])
assert.Equal(t, "amqp", trans["type"])
assert.Equal(t, common.OK_STATUS, trans["status"])
assert.Nil(t, trans["notes"])
fields, ok := trans["amqp"].(common.MapStr)
assert.True(t, ok)
code, ok := fields["reply-code"].(uint16)
assert.True(t, ok)
assert.Equal(t, uint16(200), code)
}
示例4: TestAmqp_RejectMessage
func TestAmqp_RejectMessage(t *testing.T) {
if testing.Verbose() {
logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"amqp", "amqpdetailed"})
}
amqp := amqpModForTests()
amqp.sendRequest = true
data, err := hex.DecodeString("0100010000000d003c005a000000000000000101ce")
assert.Nil(t, err)
tcptuple := testTCPTuple()
req := protos.Packet{Payload: data}
private := protos.ProtocolData(new(amqpPrivateData))
//method frame
amqp.Parse(&req, tcptuple, 0, private)
trans := expectTransaction(t, amqp)
assert.Equal(t, "basic.reject", trans["method"])
assert.Equal(t, "basic.reject 1", trans["request"])
assert.Equal(t, "amqp", trans["type"])
assert.Equal(t, common.ERROR_STATUS, trans["status"])
fields, ok := trans["amqp"].(common.MapStr)
if !ok {
t.Errorf("Field should be present")
}
assert.Equal(t, true, fields["multiple"])
}
示例5: TestGapResponse
// Verify that a gap during the response publish the request with Notes
func TestGapResponse(t *testing.T) {
dns := newDns(testing.Verbose())
q := sophosTxtTcp.request
r := sophosTxtTcp.response[:10]
tcptuple := testTcpTuple()
private := protos.ProtocolData(new(dnsPrivateData))
packet := newPacket(forward, q)
private = dns.Parse(packet, tcptuple, tcp.TcpDirectionOriginal, private)
assert.Equal(t, 1, dns.transactions.Size(), "There should be one transaction.")
packet = newPacket(reverse, r)
private = dns.Parse(packet, tcptuple, tcp.TcpDirectionReverse, private)
assert.Equal(t, 1, dns.transactions.Size(), "There should be one transaction.")
private, drop := dns.GapInStream(tcptuple, tcp.TcpDirectionReverse, 10, private)
assert.Equal(t, true, drop)
private = dns.ReceivedFin(tcptuple, tcp.TcpDirectionReverse, private)
client := dns.results.(publisher.ChanClient)
close(client.Channel)
mapStr := <-client.Channel
assert.NotNil(t, mapStr, "One result should have been published.")
assert.Equal(t, mapStr["notes"], "Response packet's data could not be decoded as DNS.")
assert.Nil(t, mapStr["answers"])
}
示例6: parseTcpRequestResponse
// parseTcpRequestResponse parses a request then a response packet and validates
// the published result.
func parseTcpRequestResponse(t testing.TB, dns *Dns, q DnsTestMessage) {
packet := newPacket(forward, q.request)
tcptuple := testTcpTuple()
private := protos.ProtocolData(new(dnsPrivateData))
dns.Parse(packet, tcptuple, tcp.TcpDirectionOriginal, private)
packet = newPacket(reverse, q.response)
dns.Parse(packet, tcptuple, tcp.TcpDirectionReverse, private)
assert.Empty(t, dns.transactions.Size(), "There should be no transactions.")
m := expectResult(t, dns)
assert.Equal(t, "tcp", mapValue(t, m, "transport"))
assert.Equal(t, len(q.request), mapValue(t, m, "bytes_in"))
assert.Equal(t, len(q.response), mapValue(t, m, "bytes_out"))
assert.NotNil(t, mapValue(t, m, "responsetime"))
if assert.ObjectsAreEqual("NOERROR", mapValue(t, m, "dns.response_code")) {
assert.Equal(t, common.OK_STATUS, mapValue(t, m, "status"))
} else {
assert.Equal(t, common.ERROR_STATUS, mapValue(t, m, "status"))
}
assert.Nil(t, mapValue(t, m, "notes"))
assertMapStrData(t, m, q)
}
示例7: TestAmqp_GetEmptyMethod
func TestAmqp_GetEmptyMethod(t *testing.T) {
if testing.Verbose() {
logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"amqp", "amqpdetailed"})
}
amqp := amqpModForTests()
amqp.sendRequest = true
data, err := hex.DecodeString("01000100000013003c004600000b526f626269" +
"654b65616e6501ce")
assert.Nil(t, err)
data2, err := hex.DecodeString("01000100000005003c004800ce")
assert.Nil(t, err)
tcptuple := testTCPTuple()
req := protos.Packet{Payload: data}
private := protos.ProtocolData(new(amqpPrivateData))
private = amqp.Parse(&req, tcptuple, 0, private)
req = protos.Packet{Payload: data2}
amqp.Parse(&req, tcptuple, 1, private)
trans := expectTransaction(t, amqp)
assert.Equal(t, "basic.get-empty", trans["method"])
assert.Equal(t, "basic.get RobbieKeane", trans["request"])
assert.Equal(t, "amqp", trans["type"])
assert.Equal(t, common.OK_STATUS, trans["status"])
}
示例8: TestAmqp_NoWaitQueueDeleteMethod
func TestAmqp_NoWaitQueueDeleteMethod(t *testing.T) {
if testing.Verbose() {
logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"amqp", "amqpdetailed"})
}
amqp := amqpModForTests()
amqp.sendRequest = true
data, err := hex.DecodeString("010001000000120032002800000a546573745468" +
"6f6d617304ce")
assert.Nil(t, err)
tcptuple := testTCPTuple()
req := protos.Packet{Payload: data}
private := protos.ProtocolData(new(amqpPrivateData))
amqp.Parse(&req, tcptuple, 0, private)
trans := expectTransaction(t, amqp)
assert.Equal(t, "queue.delete", trans["method"])
assert.Equal(t, "queue.delete TestThomas", trans["request"])
assert.Equal(t, "amqp", trans["type"])
fields, ok := trans["amqp"].(common.MapStr)
if !ok {
t.Errorf("Field should be present")
}
assert.Equal(t, true, fields["no-wait"])
assert.Equal(t, false, fields["if-empty"])
assert.Equal(t, false, fields["if-unused"])
assert.Equal(t, "TestThomas", fields["queue"])
}
示例9: TestAmqp_GetMethod
func TestAmqp_GetMethod(t *testing.T) {
if testing.Verbose() {
logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"amqp", "amqpdetailed"})
}
amqp := amqpModForTests()
amqp.sendRequest = true
amqp.sendResponse = true
data, err := hex.DecodeString("0100010000000f003c0046000007546573744" +
"7657401ce")
assert.Nil(t, err)
data2, err := hex.DecodeString("0100010000001a003c00470000000000000001" +
"0000075465737447657400000001ce02000100000019003c000000000000000000" +
"1280000a746578742f706c61696ece03000100000012476574206d6520696620796" +
"f752064617265ce")
assert.Nil(t, err)
tcptuple := testTCPTuple()
req := protos.Packet{Payload: data}
private := protos.ProtocolData(new(amqpPrivateData))
private = amqp.Parse(&req, tcptuple, 0, private)
req = protos.Packet{Payload: data2}
amqp.Parse(&req, tcptuple, 1, private)
trans := expectTransaction(t, amqp)
assert.Equal(t, "basic.get", trans["method"])
assert.Equal(t, "basic.get TestGet", trans["request"])
assert.Equal(t, "amqp", trans["type"])
assert.Equal(t, common.OK_STATUS, trans["status"])
assert.Equal(t, "Get me if you dare", trans["response"])
}
示例10: TestAmqp_RecoverMethod
func TestAmqp_RecoverMethod(t *testing.T) {
if testing.Verbose() {
logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"amqp", "amqpdetailed"})
}
amqp := amqpModForTests()
amqp.sendRequest = true
data, err := hex.DecodeString("01000100000005003c006e01ce")
assert.Nil(t, err)
data2, err := hex.DecodeString("01000100000004003c006fce")
assert.Nil(t, err)
tcptuple := testTCPTuple()
req := protos.Packet{Payload: data}
private := protos.ProtocolData(new(amqpPrivateData))
private = amqp.Parse(&req, tcptuple, 0, private)
req = protos.Packet{Payload: data2}
amqp.Parse(&req, tcptuple, 1, private)
trans := expectTransaction(t, amqp)
assert.Equal(t, "basic.recover", trans["method"])
assert.Equal(t, "basic.recover", trans["request"])
assert.Equal(t, "amqp", trans["type"])
assert.Equal(t, common.OK_STATUS, trans["status"])
assert.Equal(t, common.MapStr{"requeue": true}, trans["amqp"])
}
示例11: benchmarkTcp
// Benchmarks TCP parsing for the given test message.
func benchmarkTcp(b *testing.B, q DnsTestMessage) {
dns := newDns(false)
for i := 0; i < b.N; i++ {
packet := newPacket(forward, q.request)
tcptuple := testTcpTuple()
private := protos.ProtocolData(new(dnsPrivateData))
dns.Parse(packet, tcptuple, tcp.TcpDirectionOriginal, private)
packet = newPacket(reverse, q.response)
tcptuple = testTcpTuple()
private = protos.ProtocolData(new(dnsPrivateData))
dns.Parse(packet, tcptuple, tcp.TcpDirectionOriginal, private)
client := dns.results.(publisher.ChanClient)
<-client.Channel
}
}
示例12: TestParseTcp_malformedPacket
// Verify that a malformed packet is safely handled (no panics).
func TestParseTcp_malformedPacket(t *testing.T) {
dns := newDns(testing.Verbose())
garbage := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}
tcptuple := testTcpTuple()
packet := newPacket(forward, garbage)
private := protos.ProtocolData(new(dnsPrivateData))
dns.Parse(packet, tcptuple, tcp.TcpDirectionOriginal, private)
assert.Empty(t, dns.transactions.Size(), "There should be no transactions.")
}
示例13: BenchmarkParallelTcpParse
// Benchmark that runs with parallelism to help find concurrency related
// issues. To run with parallelism, the 'go test' cpu flag must be set
// greater than 1, otherwise it just runs concurrently but not in parallel.
func BenchmarkParallelTcpParse(b *testing.B) {
rand.Seed(22)
numMessages := len(messagesTcp)
dns := newDns(false)
client := dns.results.(publisher.ChanClient)
// Drain the results channal while the test is running.
go func() {
totalMessages := 0
for r := range client.Channel {
_ = r
totalMessages++
}
fmt.Printf("Parsed %d messages.\n", totalMessages)
}()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
// Each iteration parses one message, either a request or a response.
// The request and response could be parsed on different goroutines.
for pb.Next() {
q := messagesTcp[rand.Intn(numMessages)]
var packet *protos.Packet
var tcptuple *common.TcpTuple
var private protos.ProtocolData
if rand.Intn(2) == 0 {
packet = newPacket(forward, q.request)
tcptuple = testTcpTuple()
private = protos.ProtocolData(new(dnsPrivateData))
} else {
packet = newPacket(reverse, q.response)
tcptuple = testTcpTuple()
private = protos.ProtocolData(new(dnsPrivateData))
}
dns.Parse(packet, tcptuple, tcp.TcpDirectionOriginal, private)
}
})
defer close(client.Channel)
}
示例14: TestParseTcp_requestPacket
// Verify that the lone request packet is parsed.
func TestParseTcp_requestPacket(t *testing.T) {
dns := newDns(testing.Verbose())
packet := newPacket(forward, elasticATcp.request)
tcptuple := testTcpTuple()
private := protos.ProtocolData(new(dnsPrivateData))
dns.Parse(packet, tcptuple, tcp.TcpDirectionOriginal, private)
assert.Equal(t, 1, dns.transactions.Size(), "There should be one transaction.")
client := dns.results.(publisher.ChanClient)
close(client.Channel)
assert.Nil(t, <-client.Channel, "No result should have been published.")
}
示例15: TestThrift_GapInStream_response
func TestThrift_GapInStream_response(t *testing.T) {
if testing.Verbose() {
logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"thrift", "thriftdetailed"})
}
var thrift Thrift
thrift.Init(true, nil)
thrift.Idl = thriftIdlForTesting(t, `
exception InvalidOperation {
1: i32 what,
2: string why
}
service Test {
i32 calculate(1:i32 logid, 2:Work w) throws (1:InvalidOperation ouch),
}
`)
thrift.PublishQueue = make(chan *ThriftTransaction, 10)
tcptuple := testTcpTuple()
req := createTestPacket(t, "800100010000000963616c63756c6174650000000008000"+
"1000000010c00020800010000000108000200000000080003000000040000")
// missing last few bytes
repl := createTestPacket(t, "800100020000000963616c63756c617465000000000c00"+
"01080001000000040b00020000001243616e6e6f742064697669646520")
private := protos.ProtocolData(new(thriftPrivateData))
private = thrift.Parse(req, tcptuple, 0, private)
private = thrift.Parse(repl, tcptuple, 1, private)
private, drop := thrift.GapInStream(tcptuple, 1, 5, private)
if drop == false {
t.Error("GapInStream returned drop=false")
}
trans := expectThriftTransaction(t, thrift)
// The exception is not captured, but otherwise the values from the request
// are correct
if trans.Request.Method != "calculate" ||
trans.Request.Params != "(logid: 1, w: (1: 1, 2: 0, 3: 4))" ||
trans.Reply.ReturnValue != "" ||
trans.Reply.Exceptions != `` ||
trans.Reply.HasException ||
trans.Request.Service != "Test" ||
trans.Reply.Notes[0] != "Packet loss while capturing the response" {
t.Error("trans.Reply.Exceptions", trans.Reply.Exceptions)
t.Error("trans.Reply.HasException", trans.Reply.HasException)
}
}