flow.proto 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. syntax = "proto3";
  2. package netmaker.flow;
  3. option go_package = "github.com/gravitl/netmaker/grpc/flow";
  4. // ============================================================
  5. // BUILD COMMAND:
  6. //
  7. // protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative grpc/flow/flow.proto
  8. //
  9. // ============================================================
  10. // ============================================================
  11. // ENUMS
  12. // ============================================================
  13. /**
  14. * Lifecycle stage of a flow event as seen by an netclient.
  15. * A flow produces:
  16. * - EVENT_START when conntrack entry is created
  17. * - EVENT_DESTROY when conntrack entry is removed
  18. */
  19. enum EventType {
  20. EVENT_TYPE_UNSPECIFIED = 0;
  21. EVENT_START = 1;
  22. EVENT_DESTROY = 2;
  23. }
  24. /**
  25. * Identifies what kind of participant an IP belongs to.
  26. */
  27. enum ParticipantType {
  28. PARTICIPANT_UNSPECIFIED = 0;
  29. PARTICIPANT_NODE = 1;
  30. PARTICIPANT_USER = 2;
  31. PARTICIPANT_EXTCLIENT = 3;
  32. PARTICIPANT_EGRESS_ROUTE = 4;
  33. PARTICIPANT_EXTERNAL = 5; // anything not part of the Netmaker network
  34. }
  35. /**
  36. * Direction of the flow relative to the observing node.
  37. */
  38. enum Direction {
  39. DIR_UNSPECIFIED = 0;
  40. DIR_INGRESS = 1;
  41. DIR_EGRESS = 2;
  42. }
  43. // ============================================================
  44. // PARTICIPANT STRUCTURE
  45. // ============================================================
  46. /**
  47. * Fully enriched representation of one endpoint of a flow.
  48. */
  49. message FlowParticipant {
  50. string ip = 1;
  51. ParticipantType type = 2;
  52. string id = 3;
  53. string name = 4;
  54. }
  55. // ============================================================
  56. // RAW AGENT EVENT
  57. // ============================================================
  58. /**
  59. * Flow event generated by netclient.
  60. */
  61. message FlowEvent {
  62. // Flow lifecycle event type (START or DESTROY)
  63. EventType type = 1;
  64. // Stable identity
  65. string flow_id = 2; // unique per flow
  66. string host_id = 3; // node reporting this event
  67. string host_name = 4; // name of the node reporting this event
  68. string network_id = 5; // network this flow belongs to
  69. // L3/L4 metadata
  70. uint32 protocol = 6;
  71. uint32 src_port = 7;
  72. uint32 dst_port = 8;
  73. uint32 icmp_type = 9;
  74. uint32 icmp_code = 10;
  75. Direction direction = 11;
  76. // Participants — enriched by client
  77. FlowParticipant src = 12;
  78. FlowParticipant dst = 13;
  79. // Timestamps (milliseconds since epoch)
  80. int64 start_ts_ms = 14;
  81. int64 end_ts_ms = 15;
  82. // Traffic counters (only valid for destroy events)
  83. uint64 bytes_sent = 16;
  84. uint64 bytes_recv = 17;
  85. uint64 packets_sent = 18;
  86. uint64 packets_recv = 19;
  87. // Netfilter conntrack status flags (bitmask)
  88. uint32 status = 20;
  89. /**
  90. * Version used by ClickHouse for merging.
  91. * Must be strictly increasing for START → DESTROY.
  92. * Usually equal to the netclient event timestamp (ms).
  93. */
  94. int64 version = 21;
  95. }
  96. // ============================================================
  97. // BATCHING AND STREAMING
  98. // ============================================================
  99. /**
  100. * Envelope sent by netclients containing multiple FlowEvents.
  101. */
  102. message FlowEnvelope {
  103. repeated FlowEvent events = 1;
  104. }
  105. /**
  106. * Response from server acknowledging receipt of a batch.
  107. */
  108. message FlowResponse {
  109. bool success = 1; // true if batch was accepted
  110. string error = 2; // optional error information
  111. }
  112. // ============================================================
  113. // SERVICE
  114. // ============================================================
  115. /**
  116. * Bidirectional streaming:
  117. * - Agents continuously send FlowEnvelope batches.
  118. * - Server replies with FlowResponse ACKs.
  119. */
  120. service FlowService {
  121. rpc StreamFlows(stream FlowEnvelope) returns (stream FlowResponse);
  122. }