blob: abf4950edc8aad6f5b94f1eb7e38c606a3523fdb [file] [log] [blame]
Tinoj Josephec742f62022-09-29 19:11:10 +05301/*
Tinoj Joseph429b9d92022-11-16 18:51:05 +05302
Tinoj Josephec742f62022-09-29 19:11:10 +05303* Copyright 2022-present Open Networking Foundation
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
Akash Sonib3abf522022-12-19 13:20:02 +053015 */
Tinoj Josephec742f62022-09-29 19:11:10 +053016
17package onos_nbi
18
19import (
Akash Sonib3abf522022-12-19 13:20:02 +053020 "fmt"
Tinoj Josephec742f62022-09-29 19:11:10 +053021 "strconv"
Tinoj Josephec742f62022-09-29 19:11:10 +053022 app "voltha-go-controller/internal/pkg/application"
Tinoj Joseph429b9d92022-11-16 18:51:05 +053023 "voltha-go-controller/internal/pkg/controller"
Akash Sonib3abf522022-12-19 13:20:02 +053024
25 "voltha-go-controller/internal/pkg/of"
Tinoj Josephec742f62022-09-29 19:11:10 +053026)
27
28const (
Akash Sonib3abf522022-12-19 13:20:02 +053029 /** Switch input port. */
30 IN_PORT string = "IN_PORT"
Tinoj Josephec742f62022-09-29 19:11:10 +053031
Akash Sonib3abf522022-12-19 13:20:02 +053032 /** Switch physical input port. */
33 IN_PHY_PORT string = "IN_PHY_PORT"
Tinoj Josephec742f62022-09-29 19:11:10 +053034
Akash Sonib3abf522022-12-19 13:20:02 +053035 /** Metadata passed between tables. */
36 METADATA string = "METADATA"
Tinoj Josephec742f62022-09-29 19:11:10 +053037
Akash Sonib3abf522022-12-19 13:20:02 +053038 /** Ethernet destination address. */
39 ETH_DST string = "ETH_DST"
Tinoj Josephec742f62022-09-29 19:11:10 +053040
Akash Sonib3abf522022-12-19 13:20:02 +053041 /** Ethernet destination address with masking. */
42 ETH_DST_MASKED = "ETH_DST_MASKED"
Tinoj Josephec742f62022-09-29 19:11:10 +053043
Akash Sonib3abf522022-12-19 13:20:02 +053044 /** Ethernet source address. */
45 ETH_SRC string = "ETH_SRC"
Tinoj Josephec742f62022-09-29 19:11:10 +053046
Akash Sonib3abf522022-12-19 13:20:02 +053047 /** Ethernet source address with masking. */
48 ETH_SRC_MASKED string = "ETH_SRC_MASKED"
Tinoj Josephec742f62022-09-29 19:11:10 +053049
Akash Sonib3abf522022-12-19 13:20:02 +053050 /** Ethernet frame type. */
51 ETH_TYPE string = "ETH_TYPE"
Tinoj Josephec742f62022-09-29 19:11:10 +053052
Akash Sonib3abf522022-12-19 13:20:02 +053053 /** VLAN id. */
54 VLAN_VID string = "VLAN_VID"
Tinoj Josephec742f62022-09-29 19:11:10 +053055
Akash Sonib3abf522022-12-19 13:20:02 +053056 /** VLAN priority. */
57 VLAN_PCP string = "VLAN_PCP"
58 /**
59 * Inner VLAN id.
60 *
61 * Note: Some drivers may not support this.
62 */
63 INNER_VLAN_VID string = "INNER_VLAN_VID"
Tinoj Josephec742f62022-09-29 19:11:10 +053064
Akash Sonib3abf522022-12-19 13:20:02 +053065 /**
66 * Inner VLAN pcp.
67 *
68 * Note: Some drivers may not support this.
69 */
70 INNER_VLAN_PCP string = "INNER_VLAN_PCP"
Tinoj Josephec742f62022-09-29 19:11:10 +053071
Akash Sonib3abf522022-12-19 13:20:02 +053072 /** IP DSCP (6 bits in ToS field). */
73 IP_DSCP string = "IP_DSCP"
Tinoj Josephec742f62022-09-29 19:11:10 +053074
Akash Sonib3abf522022-12-19 13:20:02 +053075 /** IP ECN (2 bits in ToS field). */
76 IP_ECN string = "IP_ECN"
Tinoj Josephec742f62022-09-29 19:11:10 +053077
Akash Sonib3abf522022-12-19 13:20:02 +053078 /** IP protocol. */
79 IP_PROTO string = "IP_PROTO"
Tinoj Josephec742f62022-09-29 19:11:10 +053080
Akash Sonib3abf522022-12-19 13:20:02 +053081 /** IPv4 source address. */
82 IPV4_SRC string = "IPV4_SRC"
Tinoj Josephec742f62022-09-29 19:11:10 +053083
Akash Sonib3abf522022-12-19 13:20:02 +053084 /** IPv4 destination address. */
85 IPV4_DST string = "IPV4_DST"
Tinoj Josephec742f62022-09-29 19:11:10 +053086
Akash Sonib3abf522022-12-19 13:20:02 +053087 /** TCP source port. */
88 TCP_SRC string = "TCP_SRC"
Tinoj Josephec742f62022-09-29 19:11:10 +053089
Akash Sonib3abf522022-12-19 13:20:02 +053090 /** TCP source port with masking. */
91 TCP_SRC_MASKED string = "TCP_SRC_MASKED"
Tinoj Josephec742f62022-09-29 19:11:10 +053092
Akash Sonib3abf522022-12-19 13:20:02 +053093 /** TCP destination port. */
94 TCP_DST string = "TCP_DST"
Tinoj Josephec742f62022-09-29 19:11:10 +053095
Akash Sonib3abf522022-12-19 13:20:02 +053096 /** TCP destination port with masking. */
97 TCP_DST_MASKED string = "TCP_DST"
Tinoj Josephec742f62022-09-29 19:11:10 +053098
Akash Sonib3abf522022-12-19 13:20:02 +053099 /** UDP source port. */
100 UDP_SRC string = "UDP_SRC"
Tinoj Josephec742f62022-09-29 19:11:10 +0530101
Akash Sonib3abf522022-12-19 13:20:02 +0530102 /** UDP source port with masking. */
103 UDP_SRC_MASKED string = "UDP_SRC_MASKED"
Tinoj Josephec742f62022-09-29 19:11:10 +0530104
Akash Sonib3abf522022-12-19 13:20:02 +0530105 /** UDP destination port. */
106 UDP_DST string = "UDP_DST"
Tinoj Josephec742f62022-09-29 19:11:10 +0530107
Akash Sonib3abf522022-12-19 13:20:02 +0530108 /** UDP destination port with masking. */
109 UDP_DST_MASKED string = "UDP_DST_MASKED"
Tinoj Josephec742f62022-09-29 19:11:10 +0530110
Akash Sonib3abf522022-12-19 13:20:02 +0530111 /** SCTP source port. */
112 SCTP_SRC string = "SCTP_SRC"
Tinoj Josephec742f62022-09-29 19:11:10 +0530113
Akash Sonib3abf522022-12-19 13:20:02 +0530114 /** SCTP source port with masking. */
115 SCTP_SRC_MASKED string = "SCTP_SRC_MASKED"
Tinoj Josephec742f62022-09-29 19:11:10 +0530116
Akash Sonib3abf522022-12-19 13:20:02 +0530117 /** SCTP destination port. */
118 SCTP_DST string = "SCTP_DST"
Tinoj Josephec742f62022-09-29 19:11:10 +0530119
Akash Sonib3abf522022-12-19 13:20:02 +0530120 /** SCTP destination port with masking. */
121 SCTP_DST_MASKED string = "SCTP_DST_MASKED"
Tinoj Josephec742f62022-09-29 19:11:10 +0530122
Akash Sonib3abf522022-12-19 13:20:02 +0530123 /** ICMP type. */
124 ICMPV4_TYPE string = "ICMPV4_TYPE"
Tinoj Josephec742f62022-09-29 19:11:10 +0530125
Akash Sonib3abf522022-12-19 13:20:02 +0530126 /** ICMP code. */
127 ICMPV4_CODE string = "ICMPV4_CODE"
Tinoj Josephec742f62022-09-29 19:11:10 +0530128
Akash Sonib3abf522022-12-19 13:20:02 +0530129 /** ARP opcode. */
130 ARP_OP string = "ARP_OP"
Tinoj Josephec742f62022-09-29 19:11:10 +0530131
Akash Sonib3abf522022-12-19 13:20:02 +0530132 /** ARP source IPv4 address. */
133 ARP_SPA string = "ARP_SPA"
Tinoj Josephec742f62022-09-29 19:11:10 +0530134
Akash Sonib3abf522022-12-19 13:20:02 +0530135 /** ARP target IPv4 address. */
136 ARP_TPA string = "ARP_TPA"
Tinoj Josephec742f62022-09-29 19:11:10 +0530137
Akash Sonib3abf522022-12-19 13:20:02 +0530138 /** ARP source hardware address. */
139 ARP_THA string = "ARP_THA"
Tinoj Josephec742f62022-09-29 19:11:10 +0530140
Akash Sonib3abf522022-12-19 13:20:02 +0530141 /** IPv6 source address. */
142 IPV6_SRC string = "IPV6_SRC"
Tinoj Josephec742f62022-09-29 19:11:10 +0530143
Akash Sonib3abf522022-12-19 13:20:02 +0530144 /** IPv6 destination address. */
145 IPV6_DST string = "IPV6_DST"
Tinoj Josephec742f62022-09-29 19:11:10 +0530146
Akash Sonib3abf522022-12-19 13:20:02 +0530147 /** IPv6 Flow Label. */
148 IPV6_FLABEL string = "IPV6_FLABEL"
Tinoj Josephec742f62022-09-29 19:11:10 +0530149
Akash Sonib3abf522022-12-19 13:20:02 +0530150 /** ICMPv6 type. */
151 ICMPV6_TYPE string = "ICMPV6_TYPE"
Tinoj Josephec742f62022-09-29 19:11:10 +0530152
Akash Sonib3abf522022-12-19 13:20:02 +0530153 /** ICMPv6 code. */
154 ICMPV6_CODE string = "ICMPV6_CODE"
Tinoj Josephec742f62022-09-29 19:11:10 +0530155
Akash Sonib3abf522022-12-19 13:20:02 +0530156 /** Target address for ND. */
157 IPV6_ND_TARGET string = "IPV6_ND_TARGET"
Tinoj Josephec742f62022-09-29 19:11:10 +0530158
Akash Sonib3abf522022-12-19 13:20:02 +0530159 /** Source link-layer for ND. */
160 IPV6_ND_SLL string = "IPV6_ND_SLL"
Tinoj Josephec742f62022-09-29 19:11:10 +0530161
Akash Sonib3abf522022-12-19 13:20:02 +0530162 /** Target link-layer for ND. */
163 IPV6_ND_TLL string = "IPV6_ND_TLL"
Tinoj Josephec742f62022-09-29 19:11:10 +0530164
Akash Sonib3abf522022-12-19 13:20:02 +0530165 /** MPLS label. */
166 MPLS_LABEL string = "MPLS_LABEL"
Tinoj Josephec742f62022-09-29 19:11:10 +0530167
Akash Sonib3abf522022-12-19 13:20:02 +0530168 /** MPLS TC. */
169 MPLS_TC string = "MPLS_TC"
Tinoj Josephec742f62022-09-29 19:11:10 +0530170
Akash Sonib3abf522022-12-19 13:20:02 +0530171 /** MPLS BoS bit. */
172 MPLS_BOS string = "MPLS_BOS"
Tinoj Josephec742f62022-09-29 19:11:10 +0530173
Akash Sonib3abf522022-12-19 13:20:02 +0530174 /** PBB I-SID. */
175 PBB_ISID string = "PBB_ISID"
Tinoj Josephec742f62022-09-29 19:11:10 +0530176
Akash Sonib3abf522022-12-19 13:20:02 +0530177 /** Logical Port Metadata. */
178 TUNNEL_ID string = "TUNNEL_ID"
Tinoj Josephec742f62022-09-29 19:11:10 +0530179
Akash Sonib3abf522022-12-19 13:20:02 +0530180 /** IPv6 Extension Header pseudo-field. */
181 IPV6_EXTHDR string = "IPV6_EXTHDR"
Tinoj Josephec742f62022-09-29 19:11:10 +0530182
Akash Sonib3abf522022-12-19 13:20:02 +0530183 /** Unassigned value: 40. */
184 UNASSIGNED_40 string = "UNASSIGNED_40"
Tinoj Josephec742f62022-09-29 19:11:10 +0530185
Akash Sonib3abf522022-12-19 13:20:02 +0530186 /** PBB UCA header field. */
187 PBB_UCA string = "PBB_UCA"
Tinoj Josephec742f62022-09-29 19:11:10 +0530188
Akash Sonib3abf522022-12-19 13:20:02 +0530189 /** TCP flags. */
190 TCP_FLAGS string = "TCP_FLAGS"
Tinoj Josephec742f62022-09-29 19:11:10 +0530191
Akash Sonib3abf522022-12-19 13:20:02 +0530192 /** Output port from action set metadata. */
193 ACTSET_OUTPUT string = "ACTSET_OUTPUT"
Tinoj Josephec742f62022-09-29 19:11:10 +0530194
Akash Sonib3abf522022-12-19 13:20:02 +0530195 /** Packet type value. */
196 PACKET_TYPE string = "PACKET_TYPE"
Tinoj Josephec742f62022-09-29 19:11:10 +0530197
Akash Sonib3abf522022-12-19 13:20:02 +0530198 //
199 // NOTE: Everything below is defined elsewhere: ONOS-specific,
200 // extensions, etc.
201 //
202 /** Optical channel signal ID (lambda). */
203 OCH_SIGID string = "OCH_SIGID"
Tinoj Josephec742f62022-09-29 19:11:10 +0530204
Akash Sonib3abf522022-12-19 13:20:02 +0530205 /** Optical channel signal type (fixed or flexible). */
206 OCH_SIGTYPE string = "OCH_SIGTYPE"
Tinoj Josephec742f62022-09-29 19:11:10 +0530207
Akash Sonib3abf522022-12-19 13:20:02 +0530208 /** ODU (Optical channel Data Unit) signal ID. */
209 ODU_SIGID string = "ODU_SIGID"
Tinoj Josephec742f62022-09-29 19:11:10 +0530210
Akash Sonib3abf522022-12-19 13:20:02 +0530211 /** ODU (Optical channel Data Unit) signal type. */
212 ODU_SIGTYPE string = "ODU_SIGTYPE"
Tinoj Josephec742f62022-09-29 19:11:10 +0530213
Akash Sonib3abf522022-12-19 13:20:02 +0530214 /** Protocol-independent. */
215 PROTOCOL_INDEPENDENT string = "PROTOCOL_INDEPENDENT"
Tinoj Josephec742f62022-09-29 19:11:10 +0530216
Akash Sonib3abf522022-12-19 13:20:02 +0530217 /** Extension criterion. */
218 EXTENSION string = "EXTENSION"
Tinoj Josephec742f62022-09-29 19:11:10 +0530219
Akash Sonib3abf522022-12-19 13:20:02 +0530220 /** An empty criterion. */
221 DUMMY string = "DUMMY"
Tinoj Josephec742f62022-09-29 19:11:10 +0530222
223 /* OUTPUT instruction */
224 OUTPUT string = "OUTPUT"
225
226 /* METER instruction */
227 METER string = "METER"
228
229 /* L2MODIFICATION instruction type */
230 L2MODIFICATION string = "L2MODIFICATION"
231
232 /* VLAN_PUSH operation */
233 VLAN_PUSH string = "VLAN_PUSH"
234
235 /* VLAN_ID instruction */
236 VLAN_ID string = "VLAN_ID"
237
238 /* VLAN_POP operation */
239 VLAN_POP string = "VLAN_POP"
240
241 /* VLAN_SET operation */
242 VLAN_SET string = "VLAN_SET"
Akash Sonib3abf522022-12-19 13:20:02 +0530243
244 ALL string = "ALL"
245
246 ADDED string = "ADDED"
247
248 FAILED string = "FAILED"
249
250 PENDING string = "PENDING"
Akash Soni1db5e492023-03-27 14:14:07 +0530251
252 FAILED_ADD string = "FAILED_ADD"
253
254 PENDING_ADD string = "PENDING_ADD"
255
256 PENDING_REMOVE string = "PENDING_REMOVE"
Tinoj Josephec742f62022-09-29 19:11:10 +0530257)
258
259// Selector Critrtion structs
Akash Sonib3abf522022-12-19 13:20:02 +0530260type Criterion interface {
Tinoj Josephec742f62022-09-29 19:11:10 +0530261 GetType() string
262}
263
264type PortSelector struct {
Akash Sonib3abf522022-12-19 13:20:02 +0530265 Type string `json:"type"`
266 Port int `json:"port,omitempty"`
Tinoj Josephec742f62022-09-29 19:11:10 +0530267}
268
269func (s PortSelector) GetType() string {
270 return s.Type
271}
Akash Sonib3abf522022-12-19 13:20:02 +0530272
Tinoj Josephec742f62022-09-29 19:11:10 +0530273type EthTypeSelector struct {
Akash Sonib3abf522022-12-19 13:20:02 +0530274 Type string `json:"type"`
275 EthType string `json:"ethType,omitempty"`
Tinoj Josephec742f62022-09-29 19:11:10 +0530276}
Akash Sonib3abf522022-12-19 13:20:02 +0530277
Tinoj Josephec742f62022-09-29 19:11:10 +0530278func (s EthTypeSelector) GetType() string {
279 return s.Type
280}
281
282type ProtocolSelector struct {
283 Type string `json:"type"`
284 Protocol int `json:"protocol,omitempty"`
285}
Akash Sonib3abf522022-12-19 13:20:02 +0530286
Tinoj Josephec742f62022-09-29 19:11:10 +0530287func (s ProtocolSelector) GetType() string {
288 return s.Type
289}
290
291type UDPPortSelector struct {
Akash Sonib3abf522022-12-19 13:20:02 +0530292 Type string `json:"type"`
293 UDPPort int `json:"udpPort,omitempty"`
Tinoj Josephec742f62022-09-29 19:11:10 +0530294}
Akash Sonib3abf522022-12-19 13:20:02 +0530295
Tinoj Josephec742f62022-09-29 19:11:10 +0530296func (s UDPPortSelector) GetType() string {
297 return s.Type
298}
299
300type VlanSelector struct {
Akash Sonib3abf522022-12-19 13:20:02 +0530301 Type string `json:"type"`
302 VlanID int `json:"vlanId,omitempty"`
Tinoj Josephec742f62022-09-29 19:11:10 +0530303}
Akash Sonib3abf522022-12-19 13:20:02 +0530304
Tinoj Josephec742f62022-09-29 19:11:10 +0530305func (s VlanSelector) GetType() string {
306 return s.Type
307}
308
309type EthSrcSelector struct {
Akash Sonib3abf522022-12-19 13:20:02 +0530310 Type string `json:"type"`
311 EthSrc string `json:"ethsrc,omitempty"`
Tinoj Josephec742f62022-09-29 19:11:10 +0530312}
313
314func (s EthSrcSelector) GetType() string {
315 return s.Type
316}
317
318type EthDstSelector struct {
Akash Sonib3abf522022-12-19 13:20:02 +0530319 Type string `json:"type"`
320 DstSrc string `json:"ethdst,omitempty"`
Tinoj Josephec742f62022-09-29 19:11:10 +0530321}
322
323func (s EthDstSelector) GetType() string {
324 return s.Type
325}
326
327type MetaDataSelector struct {
328 Type string `json:"type"`
329 Metadata uint64 `json:"metadata,omitempty"`
330}
331
332func (s MetaDataSelector) GetType() string {
333 return s.Type
334}
Akash Sonib3abf522022-12-19 13:20:02 +0530335
Tinoj Josephec742f62022-09-29 19:11:10 +0530336///////// END of selector interfaces
337
338type SelectorInfo struct {
Akash Sonib3abf522022-12-19 13:20:02 +0530339 Criteria []Criterion `json:"criteria"`
Tinoj Josephec742f62022-09-29 19:11:10 +0530340}
341
342// Instruction structs are defined here
343type Instruction interface {
344 GetInstructionType() string
345}
346
347type PortInstruction struct {
348 Type string `json:"type"`
349 Port string `json:"port"`
350}
351
352func (i PortInstruction) GetInstructionType() string {
353 return i.Type
354}
355
356type PushVlanInstruction struct {
Akash Sonib3abf522022-12-19 13:20:02 +0530357 Type string `json:"type"`
358 SubType string `json:"subtype"`
Tinoj Josephec742f62022-09-29 19:11:10 +0530359 EthernetType string `json:"ethernetType"`
360}
361
362func (i PushVlanInstruction) GetInstructionType() string {
363 return i.Type
364}
365
366type VlanInstruction struct {
Akash Sonib3abf522022-12-19 13:20:02 +0530367 Type string `json:"type"`
Tinoj Josephec742f62022-09-29 19:11:10 +0530368 SubType string `json:"subtype"`
Akash Sonib3abf522022-12-19 13:20:02 +0530369 VlanID int `json:"vlanId"`
Tinoj Josephec742f62022-09-29 19:11:10 +0530370}
371
372func (i VlanInstruction) GetInstructionType() string {
373 return i.Type
374}
375
376type PopVlanInstruction struct {
Akash Sonib3abf522022-12-19 13:20:02 +0530377 Type string `json:"type"`
Tinoj Josephec742f62022-09-29 19:11:10 +0530378 SubType string `json:"subtype"`
379}
380
381func (i PopVlanInstruction) GetInstructionType() string {
382 return i.Type
383}
384
385type MeterInstruction struct {
Akash Sonib3abf522022-12-19 13:20:02 +0530386 Type string `json:"type"`
Tinoj Josephec742f62022-09-29 19:11:10 +0530387 MeterID string `json:"meterId"`
388}
389
390func (i MeterInstruction) GetInstructionType() string {
391 return i.Type
392}
393
394type TreatmentInfo struct {
395 Instructions []Instruction `json:"instructions"`
Akash Sonib3abf522022-12-19 13:20:02 +0530396 Deferred []interface{} `json:"deferred"`
Tinoj Josephec742f62022-09-29 19:11:10 +0530397}
398type Flow struct {
399 GroupID int `json:"groupId"`
400 State string `json:"state"`
401 Life int `json:"life"`
402 LiveType string `json:"liveType"`
403 LastSeen int64 `json:"lastSeen"`
404 Packets int `json:"packets"`
405 Bytes int `json:"bytes"`
406 ID string `json:"id"`
407 AppID string `json:"appId"`
408 Priority int `json:"priority"`
409 Timeout int `json:"timeout"`
410 IsPermanent bool `json:"isPermanent"`
411 DeviceID string `json:"deviceId"`
412 TableID int `json:"tableId"`
413 TableName string `json:"tableName"`
414 Treatment TreatmentInfo `json:"treatment"`
415 Selector SelectorInfo `json:"selector"`
416}
417
418type FlowEntry struct {
419 Flows []Flow `json:"flows"`
420}
421
Akash Sonib3abf522022-12-19 13:20:02 +0530422//Meter struct
423type Meters struct {
424 ID string `json:"id"`
425 Life int `json:"life"`
426 Packets int `json:"packets"`
427 Bytes int `json:"bytes"`
428 ReferenceCount int `json:"referenceCount"`
429 Unit string `json:"unit"`
430 Burst bool `json:"burst"`
431 DeviceID string `json:"deviceId"`
432 AppID string `json:"appId"`
433 State string `json:"state"`
434 MeterBands []Bands `json:"bands"`
435}
436
437type Bands struct {
438 Type string `json:"type"`
439 Rate int `json:"rate"`
440 Packets int `json:"packets"`
441 Bytes int `json:"bytes"`
442 BurstSize int `json:"burstSize"`
443 Prec int `json:"prec,omitempty"`
444}
445
446type GroupsInfo struct {
447 ID int `json:"id"`
448 State string `json:"state"`
449 Life int `json:"life"`
450 Packets int `json:"packets"`
451 Bytes int `json:"bytes"`
452 ReferenceCount int `json:"referenceCount"`
453 Type string `json:"type"`
454 DeviceID string `json:"deviceId"`
455 AppID string `json:"appId"`
456 AppCookie string `json:"appCookie"`
457 Buckets []Bucket `json:"buckets"`
458}
459
460type Bucket struct {
461 Type string `json:"type"`
462 Weight int `json:"weight"`
463 Packets int `json:"packets"`
464 Bytes int `json:"bytes"`
465 BucketID int `json:"bucketId"`
466 Treatment Treatment `json:"treatment"`
467}
468
469type Treatment struct {
470 Instructions []Instructions `json:"instructions"`
471 Deferred []interface{} `json:"deferred"`
472}
473
474type Instructions struct {
475 Type string `json:"type"`
476 Port string `json:"port"`
477}
478
479type MeterList struct {
480 Meters []Meters `json:"meters"`
481}
482
483type GroupList struct {
484 Groups []*GroupsInfo `json:"groups"`
485}
486
487type SubscribersList struct {
488 Subscribers []SubscriberInfo `json:"subscribers"`
489}
490
Akash Soni87a19072023-02-28 00:46:59 +0530491type OltFlowServiceConfig struct {
492 OltFlowService app.OltFlowService `json:"oltFlowService"`
493}
494
495type DeviceConfigPayload struct {
496 DeviceConfig *app.DeviceConfig `json:"deviceConfig"`
497}
498
Akash Sonib3abf522022-12-19 13:20:02 +0530499func ConvertFlowToFlowEntry(subFlow *of.VoltSubFlow) FlowEntry {
Tinoj Josephec742f62022-09-29 19:11:10 +0530500 var flowEntry FlowEntry
Tinoj Joseph429b9d92022-11-16 18:51:05 +0530501 flowEntry.Flows = []Flow{}
Tinoj Josephec742f62022-09-29 19:11:10 +0530502 flow := ConvertVoltSubFlowToOnosFlow(subFlow)
503 flowEntry.Flows = append(flowEntry.Flows, flow)
504 return flowEntry
505}
506
Akash Sonib3abf522022-12-19 13:20:02 +0530507func ConvertFlowsToFlowEntry(subFlows []*of.VoltSubFlow) FlowEntry {
Tinoj Josephec742f62022-09-29 19:11:10 +0530508 var flowEntry FlowEntry
Tinoj Joseph429b9d92022-11-16 18:51:05 +0530509 flowEntry.Flows = []Flow{}
Tinoj Josephec742f62022-09-29 19:11:10 +0530510 for _, subFlow := range subFlows {
511 flow := ConvertVoltSubFlowToOnosFlow(subFlow)
512 flowEntry.Flows = append(flowEntry.Flows, flow)
513 }
514 return flowEntry
515}
516
Akash Soni1db5e492023-03-27 14:14:07 +0530517func FlowStateMapping(state uint8) string {
518 var flowState string
519 if state == of.FlowAddSuccess {
520 flowState = ADDED
521 } else if state == of.FlowAddFailure {
522 flowState = FAILED_ADD
523 } else if state == of.FlowAddPending {
524 flowState = PENDING_ADD
525 } else if state == of.FlowDelPending {
526 flowState = PENDING_REMOVE
527 }
528 return flowState
529}
530
Tinoj Josephec742f62022-09-29 19:11:10 +0530531func ConvertVoltSubFlowToOnosFlow(subFlow *of.VoltSubFlow) Flow {
532 var flow Flow
533 flow.ID = strconv.FormatUint(subFlow.Cookie, 10)
534 flow.TableID = int(subFlow.TableID)
535 flow.Priority = int(subFlow.Priority)
Akash Soni1db5e492023-03-27 14:14:07 +0530536 state := FlowStateMapping(subFlow.State)
537 flow.State = state
Tinoj Josephec742f62022-09-29 19:11:10 +0530538 // Fill Match criteria
539 if subFlow.InPort != 0 {
Akash Sonib3abf522022-12-19 13:20:02 +0530540 portSelector := PortSelector{
Tinoj Josephec742f62022-09-29 19:11:10 +0530541 Type: IN_PORT,
542 Port: int(subFlow.InPort),
543 }
544 flow.Selector.Criteria = append(flow.Selector.Criteria, Criterion(portSelector))
545 }
546 if subFlow.MatchVlan != of.VlanNone {
Akash Sonib3abf522022-12-19 13:20:02 +0530547 vlanSelector := VlanSelector{
548 Type: VLAN_VID,
Tinoj Josephec742f62022-09-29 19:11:10 +0530549 VlanID: int(subFlow.MatchVlan),
550 }
551 flow.Selector.Criteria = append(flow.Selector.Criteria, Criterion(vlanSelector))
552 }
553 if subFlow.SrcMacMatch {
Akash Sonib3abf522022-12-19 13:20:02 +0530554 ethSrcSelector := EthSrcSelector{
555 Type: ETH_SRC,
Tinoj Josephec742f62022-09-29 19:11:10 +0530556 EthSrc: subFlow.SrcMacAddr.String(),
557 }
558 flow.Selector.Criteria = append(flow.Selector.Criteria, Criterion(ethSrcSelector))
559 }
560 if subFlow.DstMacMatch {
Akash Sonib3abf522022-12-19 13:20:02 +0530561 ethDstSelector := EthDstSelector{
562 Type: ETH_DST,
Tinoj Josephec742f62022-09-29 19:11:10 +0530563 DstSrc: subFlow.DstMacAddr.String(),
564 }
565 flow.Selector.Criteria = append(flow.Selector.Criteria, Criterion(ethDstSelector))
566 }
567 if subFlow.L3Protocol != of.EtherTypeAny {
Akash Sonib3abf522022-12-19 13:20:02 +0530568 ethTypeSelector := EthTypeSelector{
569 Type: ETH_TYPE,
570 EthType: strconv.FormatUint(uint64(subFlow.L3Protocol), 16),
Tinoj Josephec742f62022-09-29 19:11:10 +0530571 }
572 flow.Selector.Criteria = append(flow.Selector.Criteria, Criterion(ethTypeSelector))
573 }
574 if subFlow.L4Protocol != of.IPProtocolIgnore {
Akash Sonib3abf522022-12-19 13:20:02 +0530575 protocolSelector := ProtocolSelector{
576 Type: IP_PROTO,
577 Protocol: int(subFlow.L4Protocol),
Tinoj Josephec742f62022-09-29 19:11:10 +0530578 }
579 flow.Selector.Criteria = append(flow.Selector.Criteria, Criterion(protocolSelector))
580 }
581 if subFlow.SrcPort != 0 {
Akash Sonib3abf522022-12-19 13:20:02 +0530582 udpPortSelector := UDPPortSelector{
583 Type: UDP_SRC,
584 UDPPort: int(subFlow.SrcPort),
Tinoj Josephec742f62022-09-29 19:11:10 +0530585 }
586 flow.Selector.Criteria = append(flow.Selector.Criteria, Criterion(udpPortSelector))
587 }
588 if subFlow.DstPort != 0 {
Akash Sonib3abf522022-12-19 13:20:02 +0530589 udpPortSelector := UDPPortSelector{
590 Type: UDP_DST,
591 UDPPort: int(subFlow.DstPort),
Tinoj Josephec742f62022-09-29 19:11:10 +0530592 }
593 flow.Selector.Criteria = append(flow.Selector.Criteria, Criterion(udpPortSelector))
594 }
595 if subFlow.TableMetadata != 0 {
Akash Sonib3abf522022-12-19 13:20:02 +0530596 metaDataSelector := MetaDataSelector{
597 Type: METADATA,
598 Metadata: subFlow.TableMetadata,
Tinoj Josephec742f62022-09-29 19:11:10 +0530599 }
600 flow.Selector.Criteria = append(flow.Selector.Criteria, Criterion(metaDataSelector))
601 }
602
603 // Fill actions
604 if subFlow.Output != 0 {
Akash Sonib3abf522022-12-19 13:20:02 +0530605 portInstruction := PortInstruction{
Tinoj Josephec742f62022-09-29 19:11:10 +0530606 Type: OUTPUT,
607 }
608 switch subFlow.Output {
609 case of.OutputTypeToController:
610 portInstruction.Port = "CONTROLLER"
611 case of.OutputTypeToNetwork:
Akash Sonib3abf522022-12-19 13:20:02 +0530612 portInstruction.Port = strconv.FormatUint(uint64(subFlow.OutPort), 10)
Tinoj Josephec742f62022-09-29 19:11:10 +0530613 case of.OutputTypeGoToTable:
Akash Sonib3abf522022-12-19 13:20:02 +0530614 portInstruction.Port = strconv.FormatUint(uint64(subFlow.GoToTableID), 10)
Tinoj Josephec742f62022-09-29 19:11:10 +0530615 }
616 flow.Treatment.Instructions = append(flow.Treatment.Instructions, Instruction(portInstruction))
617 }
618 if len(subFlow.PushVlan) != 0 {
619 for _, vlan := range subFlow.PushVlan {
620 if vlan == of.VlanNone {
621 continue
622 }
Akash Sonib3abf522022-12-19 13:20:02 +0530623 pushVlanInstruction := PushVlanInstruction{
624 Type: L2MODIFICATION,
625 SubType: VLAN_PUSH,
626 EthernetType: "0x8100",
Tinoj Josephec742f62022-09-29 19:11:10 +0530627 }
628 flow.Treatment.Instructions = append(flow.Treatment.Instructions, Instruction(pushVlanInstruction))
Akash Sonib3abf522022-12-19 13:20:02 +0530629 vlanInstruction := VlanInstruction{
630 Type: L2MODIFICATION,
Tinoj Josephec742f62022-09-29 19:11:10 +0530631 SubType: VLAN_ID,
Akash Sonib3abf522022-12-19 13:20:02 +0530632 VlanID: int(vlan),
Tinoj Josephec742f62022-09-29 19:11:10 +0530633 }
634 flow.Treatment.Instructions = append(flow.Treatment.Instructions, Instruction(vlanInstruction))
635 }
636 }
637 if subFlow.SetVlan != of.VlanNone {
Akash Sonib3abf522022-12-19 13:20:02 +0530638 vlanInstruction := VlanInstruction{
639 Type: L2MODIFICATION,
Tinoj Josephec742f62022-09-29 19:11:10 +0530640 SubType: VLAN_SET,
Akash Sonib3abf522022-12-19 13:20:02 +0530641 VlanID: int(subFlow.SetVlan),
Tinoj Josephec742f62022-09-29 19:11:10 +0530642 }
643 flow.Treatment.Instructions = append(flow.Treatment.Instructions, Instruction(vlanInstruction))
644 }
645 if subFlow.RemoveVlan != 0 {
Akash Sonib3abf522022-12-19 13:20:02 +0530646 popVlanInstruction := PopVlanInstruction{
647 Type: L2MODIFICATION,
Tinoj Josephec742f62022-09-29 19:11:10 +0530648 SubType: VLAN_POP,
649 }
650 flow.Treatment.Instructions = append(flow.Treatment.Instructions, Instruction(popVlanInstruction))
651 }
652 if subFlow.MeterID != 0 {
Akash Sonib3abf522022-12-19 13:20:02 +0530653 meterInstruction := MeterInstruction{
654 Type: METER,
Tinoj Josephec742f62022-09-29 19:11:10 +0530655 MeterID: strconv.FormatUint(uint64(subFlow.MeterID), 10),
656 }
657 flow.Treatment.Instructions = append(flow.Treatment.Instructions, Instruction(meterInstruction))
658 }
659 return flow
660}
661
Akash Sonib3abf522022-12-19 13:20:02 +0530662func convertServiceToSubscriberInfo(svcs []*app.VoltService) []SubscriberInfo {
663 subs := []SubscriberInfo{}
664 for _, vs := range svcs {
Tinoj Josephec742f62022-09-29 19:11:10 +0530665 pbit := vs.GetServicePbit()
Akash Sonib3abf522022-12-19 13:20:02 +0530666 sub := SubscriberInfo{
667 Location: vs.Device,
668 TagInfo: UniTagInformation{
669 UniTagMatch: int(vs.UniVlan),
670 PonCTag: int(vs.CVlan),
671 PonSTag: int(vs.SVlan),
672 UsPonCTagPriority: pbit,
673 UsPonSTagPriority: pbit,
674 DsPonCTagPriority: pbit,
675 DsPonSTagPriority: pbit,
676 TechnologyProfileID: int(vs.TechProfileID),
677 UpstreamBandwidthProfile: vs.UsMeterProfile,
678 DownstreamBandwidthProfile: vs.DsMeterProfile,
679 UpstreamOltBandwidthProfile: vs.UsMeterProfile,
680 DownstreamOltBandwidthProfile: vs.DsMeterProfile,
681 ServiceName: vs.Name,
682 EnableMacLearning: vs.MacLearning == app.Learn,
683 ConfiguredMacAddress: vs.MacAddr.String(),
684 IsDhcpRequired: vs.MacLearning == app.Learn,
685 IsIgmpRequired: vs.IgmpEnabled,
686 IsPppoeRequired: false,
687 },
688 }
689 subs = append(subs, sub)
690 }
691 return subs
Tinoj Josephec742f62022-09-29 19:11:10 +0530692}
693
Tinoj Joseph429b9d92022-11-16 18:51:05 +0530694type DeviceEntry struct {
695 Devices []Device `json:"devices"`
696}
697
698type Device struct {
Akash Sonib3abf522022-12-19 13:20:02 +0530699 ID string `json:"id"`
700 Type string `json:"type"`
701 Available bool `json:"available"`
702 Role string `json:"role"`
703 Mfr string `json:"mfr"`
704 Hw string `json:"hw"`
705 Sw string `json:"sw"`
706 Serial string `json:"serial"`
707 Driver string `json:"driver"`
708 ChassisID string `json:"chassisId"`
709 LastUpdate string `json:"lastUpdate"`
710 HumanReadableLastUpdate string `json:"humanReadableLastUpdate"`
Tinoj Joseph429b9d92022-11-16 18:51:05 +0530711 Annotations DeviceAnnotations `json:"annotations"`
712}
713type DeviceAnnotations struct {
714 ChannelID string `json:"channelId"`
715 ManagementAddress string `json:"managementAddress"`
716 Protocol string `json:"protocol"`
717}
718
719func convertVoltDeviceToDevice(voltDevice *app.VoltDevice) Device {
720 var device Device
721
722 d, err := controller.GetController().GetDevice(voltDevice.Name)
723 if err != nil {
724 device.ID = voltDevice.Name
725 return device
726 }
727 device.ID = d.ID
728 if d.State == controller.DeviceStateUP {
729 device.Available = true
730 } else {
731 device.Available = false
732 }
733 device.Serial = d.SerialNum
Akash Sonib3abf522022-12-19 13:20:02 +0530734 device.Mfr = d.MfrDesc
735 device.Hw = d.HwDesc
736 device.Sw = d.SwDesc
Tinoj Joseph429b9d92022-11-16 18:51:05 +0530737 device.LastUpdate = d.TimeStamp.String()
738 device.HumanReadableLastUpdate = d.TimeStamp.String()
739 return device
740}
Akash Sonib3abf522022-12-19 13:20:02 +0530741
Tinoj Joseph429b9d92022-11-16 18:51:05 +0530742type PortEntry struct {
743 Ports []Port `json:"ports"`
744}
745
Akash Soni1db5e492023-03-27 14:14:07 +0530746type DevicePortEntry struct {
747 Device Device `json:"device"`
748 Ports []Port `json:"ports"`
749}
750
Tinoj Joseph429b9d92022-11-16 18:51:05 +0530751type Port struct {
Akash Sonib3abf522022-12-19 13:20:02 +0530752 Element string `json:"element"`
753 Port string `json:"port"`
754 IsEnabled bool `json:"isEnabled"`
755 Type string `json:"type"`
756 PortSpeed int `json:"portSpeed"`
Tinoj Joseph429b9d92022-11-16 18:51:05 +0530757 Annotations PortAnnotations `json:"annotations"`
758}
759type PortAnnotations struct {
760 AdminState string `json:"adminState"`
761 PortMac string `json:"portMac"`
762 PortName string `json:"portName"`
763}
764
765func convertVoltPortToPort(voltPort *app.VoltPort) Port {
766 var port Port
767 port.Port = strconv.Itoa(int(voltPort.ID))
768 port.Element = voltPort.Device
769 if voltPort.State == app.PortStateUp {
770 port.IsEnabled = true
771 } else {
772 port.IsEnabled = false
773 }
774 if voltPort.Type == app.VoltPortTypeNni {
775 port.Type = "fiber"
776 } else {
777 port.Type = "copper"
778 }
779 port.Annotations.AdminState = "enabled"
780 port.Annotations.PortName = voltPort.Name
781
782 device, err := controller.GetController().GetDevice(voltPort.Device)
783 if err != nil {
784 return port
785 }
786
787 devicePort := device.GetPortByName(voltPort.Name)
788 if devicePort != nil {
789 port.PortSpeed = int(devicePort.MaxSpeed)
790 port.Annotations.PortMac = devicePort.HwAddr
791 }
792 return port
793}
Akash Sonib3abf522022-12-19 13:20:02 +0530794func (gh *GroupsHandle) convertGroupsToOnosGroup(groupsInfo *of.Group) *GroupsInfo {
795 logger.Info(ctx, "Entering into convertGroupsToOnosGroup")
796 var groups *GroupsInfo
797 var bucket []Bucket
798 Instruction := []Instructions{}
799 if groupsInfo != nil {
800 for _, buckets := range groupsInfo.Buckets {
801 inst := Instructions{
802 Type: ALL,
803 Port: fmt.Sprint(buckets),
804 }
805 Instruction = append(Instruction, inst)
806 trtmt := Treatment{
807 Instructions: Instruction,
808 }
809 bkt := Bucket{
810 Type: ALL,
811 Treatment: trtmt,
812 }
813 bucket = append(bucket, bkt)
814 }
815 if groupsInfo.State == of.GroupOperSuccess {
816 groups.State = ADDED
817 } else if groupsInfo.State == of.GroupOperFailure {
818 groups.State = FAILED
819 } else if groupsInfo.State == of.GroupOperPending {
820 groups.State = PENDING
821 }
822 groups = &GroupsInfo{
823 DeviceID: groupsInfo.Device,
824 ID: int(groupsInfo.GroupID),
825 State: groups.State,
826 Type: ALL,
827 Buckets: bucket,
828 }
829 }
830 return groups
831}
832
833func (mh *MetersHandle) MeterObjectMapping(meterInfo *of.Meter, deviceId string) Meters {
834 var meter Meters
835 var bd []Bands
836 for _, band := range meterInfo.Bands {
837 bnd := Bands{
838 Type: fmt.Sprint(band.Type),
839 Rate: int(band.Rate),
840 BurstSize: int(band.BurstSize),
841 }
842 bd = append(bd, bnd)
843 }
844 if meterInfo.State == of.MeterOperSuccess {
845 meter.State = ADDED
846 } else if meterInfo.State == of.MeterOperFailure {
847 meter.State = FAILED
848 } else if meterInfo.State == of.MeterOperPending {
849 meter.State = PENDING
850 }
851 meter = Meters{
852 ID: fmt.Sprint(meterInfo.ID),
853 State: meter.State,
854 DeviceID: deviceId,
855 MeterBands: bd,
856 }
857 return meter
858
859}