|
| 1 | +// Copyright 2026 Antrea Authors |
| 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 v1 |
| 16 | + |
| 17 | +// JSON-serializable flow types for the SSE API, mirroring the protobuf Flow message. |
| 18 | + |
| 19 | +type FlowType int32 |
| 20 | + |
| 21 | +const ( |
| 22 | + FlowTypeUnspecified FlowType = 0 |
| 23 | + FlowTypeIntraNode FlowType = 1 |
| 24 | + FlowTypeInterNode FlowType = 2 |
| 25 | + FlowTypeToExternal FlowType = 3 |
| 26 | + FlowTypeFromExternal FlowType = 4 |
| 27 | +) |
| 28 | + |
| 29 | +type NetworkPolicyType int32 |
| 30 | + |
| 31 | +const ( |
| 32 | + NetworkPolicyTypeUnspecified NetworkPolicyType = 0 |
| 33 | + NetworkPolicyTypeK8s NetworkPolicyType = 1 |
| 34 | + NetworkPolicyTypeANP NetworkPolicyType = 2 |
| 35 | + NetworkPolicyTypeACNP NetworkPolicyType = 3 |
| 36 | +) |
| 37 | + |
| 38 | +type NetworkPolicyRuleAction int32 |
| 39 | + |
| 40 | +const ( |
| 41 | + NetworkPolicyRuleActionNoAction NetworkPolicyRuleAction = 0 |
| 42 | + NetworkPolicyRuleActionAllow NetworkPolicyRuleAction = 1 |
| 43 | + NetworkPolicyRuleActionDrop NetworkPolicyRuleAction = 2 |
| 44 | + NetworkPolicyRuleActionReject NetworkPolicyRuleAction = 3 |
| 45 | +) |
| 46 | + |
| 47 | +type IPVersion int32 |
| 48 | + |
| 49 | +const ( |
| 50 | + IPVersionUnspecified IPVersion = 0 |
| 51 | + IPVersionIPv4 IPVersion = 4 |
| 52 | + IPVersionIPv6 IPVersion = 6 |
| 53 | +) |
| 54 | + |
| 55 | +type FlowEndReason int32 |
| 56 | + |
| 57 | +const ( |
| 58 | + FlowEndReasonUnspecified FlowEndReason = 0 |
| 59 | + FlowEndReasonIdleTimeout FlowEndReason = 1 |
| 60 | + FlowEndReasonActiveTimeout FlowEndReason = 2 |
| 61 | + FlowEndReasonEndOfFlow FlowEndReason = 3 |
| 62 | + FlowEndReasonForcedEnd FlowEndReason = 4 |
| 63 | + FlowEndReasonLackOfResources FlowEndReason = 5 |
| 64 | +) |
| 65 | + |
| 66 | +type FlowStats struct { |
| 67 | + PacketTotalCount uint64 `json:"packetTotalCount"` |
| 68 | + PacketDeltaCount uint64 `json:"packetDeltaCount"` |
| 69 | + OctetTotalCount uint64 `json:"octetTotalCount"` |
| 70 | + OctetDeltaCount uint64 `json:"octetDeltaCount"` |
| 71 | + Throughput uint64 `json:"throughput,omitempty"` |
| 72 | +} |
| 73 | + |
| 74 | +type FlowTCP struct { |
| 75 | + StateName string `json:"stateName"` |
| 76 | +} |
| 77 | + |
| 78 | +type FlowTransport struct { |
| 79 | + ProtocolNumber uint32 `json:"protocolNumber"` |
| 80 | + SourcePort uint32 `json:"sourcePort"` |
| 81 | + DestinationPort uint32 `json:"destinationPort"` |
| 82 | + TCP *FlowTCP `json:"tcp,omitempty"` |
| 83 | +} |
| 84 | + |
| 85 | +type FlowIP struct { |
| 86 | + Version IPVersion `json:"version"` |
| 87 | + Source string `json:"source"` |
| 88 | + Destination string `json:"destination"` |
| 89 | +} |
| 90 | + |
| 91 | +type FlowKubernetes struct { |
| 92 | + FlowType FlowType `json:"flowType"` |
| 93 | + |
| 94 | + SourcePodNamespace string `json:"sourcePodNamespace"` |
| 95 | + SourcePodName string `json:"sourcePodName"` |
| 96 | + SourcePodUid string `json:"sourcePodUid"` |
| 97 | + SourcePodLabels map[string]string `json:"sourcePodLabels,omitempty"` |
| 98 | + |
| 99 | + SourceNodeName string `json:"sourceNodeName"` |
| 100 | + SourceNodeUid string `json:"sourceNodeUid"` |
| 101 | + |
| 102 | + DestinationPodNamespace string `json:"destinationPodNamespace"` |
| 103 | + DestinationPodName string `json:"destinationPodName"` |
| 104 | + DestinationPodUid string `json:"destinationPodUid"` |
| 105 | + DestinationPodLabels map[string]string `json:"destinationPodLabels,omitempty"` |
| 106 | + |
| 107 | + DestinationNodeName string `json:"destinationNodeName"` |
| 108 | + DestinationNodeUid string `json:"destinationNodeUid"` |
| 109 | + |
| 110 | + DestinationClusterIp string `json:"destinationClusterIp"` |
| 111 | + DestinationServicePort uint32 `json:"destinationServicePort"` |
| 112 | + DestinationServicePortName string `json:"destinationServicePortName"` |
| 113 | + DestinationServiceUid string `json:"destinationServiceUid"` |
| 114 | + |
| 115 | + IngressNetworkPolicyType NetworkPolicyType `json:"ingressNetworkPolicyType"` |
| 116 | + IngressNetworkPolicyNamespace string `json:"ingressNetworkPolicyNamespace"` |
| 117 | + IngressNetworkPolicyName string `json:"ingressNetworkPolicyName"` |
| 118 | + IngressNetworkPolicyUid string `json:"ingressNetworkPolicyUid"` |
| 119 | + IngressNetworkPolicyRuleName string `json:"ingressNetworkPolicyRuleName"` |
| 120 | + IngressNetworkPolicyRuleAction NetworkPolicyRuleAction `json:"ingressNetworkPolicyRuleAction"` |
| 121 | + |
| 122 | + EgressNetworkPolicyType NetworkPolicyType `json:"egressNetworkPolicyType"` |
| 123 | + EgressNetworkPolicyNamespace string `json:"egressNetworkPolicyNamespace"` |
| 124 | + EgressNetworkPolicyName string `json:"egressNetworkPolicyName"` |
| 125 | + EgressNetworkPolicyUid string `json:"egressNetworkPolicyUid"` |
| 126 | + EgressNetworkPolicyRuleName string `json:"egressNetworkPolicyRuleName"` |
| 127 | + EgressNetworkPolicyRuleAction NetworkPolicyRuleAction `json:"egressNetworkPolicyRuleAction"` |
| 128 | + |
| 129 | + EgressName string `json:"egressName,omitempty"` |
| 130 | + EgressIp string `json:"egressIp,omitempty"` |
| 131 | + EgressNodeName string `json:"egressNodeName,omitempty"` |
| 132 | + EgressNodeUid string `json:"egressNodeUid,omitempty"` |
| 133 | + EgressUid string `json:"egressUid,omitempty"` |
| 134 | +} |
| 135 | + |
| 136 | +type Flow struct { |
| 137 | + ID string `json:"id"` |
| 138 | + StartTs string `json:"startTs"` |
| 139 | + EndTs string `json:"endTs"` |
| 140 | + EndReason FlowEndReason `json:"endReason"` |
| 141 | + IP FlowIP `json:"ip"` |
| 142 | + Transport FlowTransport `json:"transport"` |
| 143 | + K8s FlowKubernetes `json:"k8s"` |
| 144 | + Stats FlowStats `json:"stats"` |
| 145 | + ReverseStats FlowStats `json:"reverseStats"` |
| 146 | +} |
| 147 | + |
| 148 | +// FlowStreamEvent carries flow data and/or a dropped count from the stream. |
| 149 | +// When Flows is non-empty, the SSE handler emits a "flow" event. |
| 150 | +// When DroppedCount is non-zero, the SSE handler emits a "dropped" event. |
| 151 | +type FlowStreamEvent struct { |
| 152 | + Flows []Flow `json:"flows,omitempty"` |
| 153 | + DroppedCount uint64 `json:"droppedCount,omitempty"` |
| 154 | +} |
| 155 | + |
| 156 | +// FlowStreamDroppedEvent is the JSON payload for an SSE "dropped" event. |
| 157 | +type FlowStreamDroppedEvent struct { |
| 158 | + DroppedCount uint64 `json:"droppedCount"` |
| 159 | +} |
| 160 | + |
| 161 | +// FlowStreamErrorEvent is the JSON payload for an SSE "error" event. |
| 162 | +type FlowStreamErrorEvent struct { |
| 163 | + Message string `json:"message"` |
| 164 | +} |
0 commit comments