feat: api-trace
[govpp.git] / api / trace.go
1 //  Copyright (c) 2021 Cisco and/or its affiliates.
2 //
3 //  Licensed under the Apache License, Version 2.0 (the "License");
4 //  you may not use this file except in compliance with the License.
5 //  You may obtain a copy of the License at:
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 //  Unless required by applicable law or agreed to in writing, software
10 //  distributed under the License is distributed on an "AS IS" BASIS,
11 //  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 //  See the License for the specific language governing permissions and
13 //  limitations under the License.
14
15 package api
16
17 import (
18         "time"
19 )
20
21 // Trace gives access to the API trace tool, capturing outcoming and incoming messages
22 // to and from GoVPP.
23 type Trace interface {
24         // Enable allows to enable or disable API trace for a connection.
25         Enable(enable bool)
26
27         // GetRecords retrieves all messages collected (from all channels if they are used)
28         // since the point the trace was enabled or cleared.
29         GetRecords() []*Record
30
31         // GetRecordsForChannel retrieves messages collected by the given channel since
32         // the point the trace was enabled or cleared.
33         GetRecordsForChannel(chId uint16) []*Record
34
35         // Clear erases messages captured so far.
36         Clear()
37 }
38
39 // Record contains essential information about traced message, its timestamp and whether
40 // the message was received or sent
41 type Record struct {
42         Message    Message
43         Timestamp  time.Time
44         IsReceived bool
45         ChannelID  uint16
46 }