blob: 0b7ebff1940743f03666b5aee18b5b95b72c12df [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
vinokuma926cb3e2023-03-29 11:41:06 +053017package onosnbi
Tinoj Josephec742f62022-09-29 19:11:10 +053018
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. */
vinokuma926cb3e2023-03-29 11:41:06 +053030 InPort string = "IN_PORT"
Tinoj Josephec742f62022-09-29 19:11:10 +053031
Akash Sonib3abf522022-12-19 13:20:02 +053032 /** Switch physical input port. */
vinokuma926cb3e2023-03-29 11:41:06 +053033 InPhyPort string = "IN_PHY_PORT"
Tinoj Josephec742f62022-09-29 19:11:10 +053034
Akash Sonib3abf522022-12-19 13:20:02 +053035 /** Metadata passed between tables. */
vinokuma926cb3e2023-03-29 11:41:06 +053036 MetaData string = "METADATA"
Tinoj Josephec742f62022-09-29 19:11:10 +053037
Akash Sonib3abf522022-12-19 13:20:02 +053038 /** Ethernet destination address. */
vinokuma926cb3e2023-03-29 11:41:06 +053039 EthDst string = "ETH_DST"
Tinoj Josephec742f62022-09-29 19:11:10 +053040
Akash Sonib3abf522022-12-19 13:20:02 +053041 /** Ethernet destination address with masking. */
vinokuma926cb3e2023-03-29 11:41:06 +053042 EthDstMasked = "ETH_DST_MASKED"
Tinoj Josephec742f62022-09-29 19:11:10 +053043
Akash Sonib3abf522022-12-19 13:20:02 +053044 /** Ethernet source address. */
vinokuma926cb3e2023-03-29 11:41:06 +053045 EthSrc string = "ETH_SRC"
Tinoj Josephec742f62022-09-29 19:11:10 +053046
Akash Sonib3abf522022-12-19 13:20:02 +053047 /** Ethernet source address with masking. */
vinokuma926cb3e2023-03-29 11:41:06 +053048 EthSrcMasked string = "ETH_SRC_MASKED"
Tinoj Josephec742f62022-09-29 19:11:10 +053049
Akash Sonib3abf522022-12-19 13:20:02 +053050 /** Ethernet frame type. */
vinokuma926cb3e2023-03-29 11:41:06 +053051 EthType string = "ETH_TYPE"
Tinoj Josephec742f62022-09-29 19:11:10 +053052
Akash Sonib3abf522022-12-19 13:20:02 +053053 /** VLAN id. */
vinokuma926cb3e2023-03-29 11:41:06 +053054 VlanVID string = "VLAN_VID"
Tinoj Josephec742f62022-09-29 19:11:10 +053055
Akash Sonib3abf522022-12-19 13:20:02 +053056 /** VLAN priority. */
vinokuma926cb3e2023-03-29 11:41:06 +053057 VlanPcp string = "VLAN_PCP"
Akash Sonib3abf522022-12-19 13:20:02 +053058 /**
59 * Inner VLAN id.
60 *
61 * Note: Some drivers may not support this.
62 */
vinokuma926cb3e2023-03-29 11:41:06 +053063 InnerVlanVID 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 */
vinokuma926cb3e2023-03-29 11:41:06 +053070 InnerVlanPcp 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). */
vinokuma926cb3e2023-03-29 11:41:06 +053073 IPDscp 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). */
vinokuma926cb3e2023-03-29 11:41:06 +053076 IPEcn string = "IP_ECN"
Tinoj Josephec742f62022-09-29 19:11:10 +053077
Akash Sonib3abf522022-12-19 13:20:02 +053078 /** IP protocol. */
vinokuma926cb3e2023-03-29 11:41:06 +053079 IPProto string = "IP_PROTO"
Tinoj Josephec742f62022-09-29 19:11:10 +053080
Akash Sonib3abf522022-12-19 13:20:02 +053081 /** IPv4 source address. */
vinokuma926cb3e2023-03-29 11:41:06 +053082 Ipv4Src string = "IPV4_SRC"
Tinoj Josephec742f62022-09-29 19:11:10 +053083
Akash Sonib3abf522022-12-19 13:20:02 +053084 /** IPv4 destination address. */
vinokuma926cb3e2023-03-29 11:41:06 +053085 Ipv4Dst string = "IPV4_DST"
Tinoj Josephec742f62022-09-29 19:11:10 +053086
Akash Sonib3abf522022-12-19 13:20:02 +053087 /** TCP source port. */
vinokuma926cb3e2023-03-29 11:41:06 +053088 TCPSrc string = "TCP_SRC"
Tinoj Josephec742f62022-09-29 19:11:10 +053089
Akash Sonib3abf522022-12-19 13:20:02 +053090 /** TCP source port with masking. */
vinokuma926cb3e2023-03-29 11:41:06 +053091 TCPSrcMasked string = "TCP_SRC_MASKED"
Tinoj Josephec742f62022-09-29 19:11:10 +053092
Akash Sonib3abf522022-12-19 13:20:02 +053093 /** TCP destination port. */
vinokuma926cb3e2023-03-29 11:41:06 +053094 TCPDst string = "TCP_DST"
Tinoj Josephec742f62022-09-29 19:11:10 +053095
Akash Sonib3abf522022-12-19 13:20:02 +053096 /** TCP destination port with masking. */
vinokuma926cb3e2023-03-29 11:41:06 +053097 TCPDstMasked string = "TCP_DST"
Tinoj Josephec742f62022-09-29 19:11:10 +053098
Akash Sonib3abf522022-12-19 13:20:02 +053099 /** UDP source port. */
vinokuma926cb3e2023-03-29 11:41:06 +0530100 UDPSrc string = "UDP_SRC"
Tinoj Josephec742f62022-09-29 19:11:10 +0530101
Akash Sonib3abf522022-12-19 13:20:02 +0530102 /** UDP source port with masking. */
vinokuma926cb3e2023-03-29 11:41:06 +0530103 UDPSrcMasked string = "UDP_SRC_MASKED"
Tinoj Josephec742f62022-09-29 19:11:10 +0530104
Akash Sonib3abf522022-12-19 13:20:02 +0530105 /** UDP destination port. */
vinokuma926cb3e2023-03-29 11:41:06 +0530106 UDPDst string = "UDP_DST"
Tinoj Josephec742f62022-09-29 19:11:10 +0530107
Akash Sonib3abf522022-12-19 13:20:02 +0530108 /** UDP destination port with masking. */
vinokuma926cb3e2023-03-29 11:41:06 +0530109 UDPDstMasked string = "UDP_DST_MASKED"
Tinoj Josephec742f62022-09-29 19:11:10 +0530110
Akash Sonib3abf522022-12-19 13:20:02 +0530111 /** SCTP source port. */
vinokuma926cb3e2023-03-29 11:41:06 +0530112 SctpSrc string = "SCTP_SRC"
Tinoj Josephec742f62022-09-29 19:11:10 +0530113
Akash Sonib3abf522022-12-19 13:20:02 +0530114 /** SCTP source port with masking. */
vinokuma926cb3e2023-03-29 11:41:06 +0530115 SctpSrcMasked string = "SCTP_SRC_MASKED"
Tinoj Josephec742f62022-09-29 19:11:10 +0530116
Akash Sonib3abf522022-12-19 13:20:02 +0530117 /** SCTP destination port. */
vinokuma926cb3e2023-03-29 11:41:06 +0530118 SctpDst string = "SCTP_DST"
Tinoj Josephec742f62022-09-29 19:11:10 +0530119
Akash Sonib3abf522022-12-19 13:20:02 +0530120 /** SCTP destination port with masking. */
vinokuma926cb3e2023-03-29 11:41:06 +0530121 SctpDstMasked string = "SCTP_DST_MASKED"
Tinoj Josephec742f62022-09-29 19:11:10 +0530122
Akash Sonib3abf522022-12-19 13:20:02 +0530123 /** ICMP type. */
vinokuma926cb3e2023-03-29 11:41:06 +0530124 Icmpv4Type string = "ICMPV4_TYPE"
Tinoj Josephec742f62022-09-29 19:11:10 +0530125
Akash Sonib3abf522022-12-19 13:20:02 +0530126 /** ICMP code. */
vinokuma926cb3e2023-03-29 11:41:06 +0530127 Icmpv4Code string = "ICMPV4_CODE"
Tinoj Josephec742f62022-09-29 19:11:10 +0530128
Akash Sonib3abf522022-12-19 13:20:02 +0530129 /** ARP opcode. */
vinokuma926cb3e2023-03-29 11:41:06 +0530130 ArpOp string = "ARP_OP"
Tinoj Josephec742f62022-09-29 19:11:10 +0530131
Akash Sonib3abf522022-12-19 13:20:02 +0530132 /** ARP source IPv4 address. */
vinokuma926cb3e2023-03-29 11:41:06 +0530133 ArpSpa string = "ARP_SPA"
Tinoj Josephec742f62022-09-29 19:11:10 +0530134
Akash Sonib3abf522022-12-19 13:20:02 +0530135 /** ARP target IPv4 address. */
vinokuma926cb3e2023-03-29 11:41:06 +0530136 ArpTpa string = "ARP_TPA"
Tinoj Josephec742f62022-09-29 19:11:10 +0530137
Akash Sonib3abf522022-12-19 13:20:02 +0530138 /** ARP source hardware address. */
vinokuma926cb3e2023-03-29 11:41:06 +0530139 ArpTha string = "ARP_THA"
Tinoj Josephec742f62022-09-29 19:11:10 +0530140
Akash Sonib3abf522022-12-19 13:20:02 +0530141 /** IPv6 source address. */
vinokuma926cb3e2023-03-29 11:41:06 +0530142 Ipv6Src string = "IPV6_SRC"
Tinoj Josephec742f62022-09-29 19:11:10 +0530143
Akash Sonib3abf522022-12-19 13:20:02 +0530144 /** IPv6 destination address. */
vinokuma926cb3e2023-03-29 11:41:06 +0530145 Ipv6Dst string = "IPV6_DST"
Tinoj Josephec742f62022-09-29 19:11:10 +0530146
Akash Sonib3abf522022-12-19 13:20:02 +0530147 /** IPv6 Flow Label. */
vinokuma926cb3e2023-03-29 11:41:06 +0530148 Ipv6Flabel string = "IPV6_FLABEL"
Tinoj Josephec742f62022-09-29 19:11:10 +0530149
Akash Sonib3abf522022-12-19 13:20:02 +0530150 /** ICMPv6 type. */
vinokuma926cb3e2023-03-29 11:41:06 +0530151 Icmpv6Type string = "ICMPV6_TYPE"
Tinoj Josephec742f62022-09-29 19:11:10 +0530152
Akash Sonib3abf522022-12-19 13:20:02 +0530153 /** ICMPv6 code. */
vinokuma926cb3e2023-03-29 11:41:06 +0530154 Icmpv6Code string = "ICMPV6_CODE"
Tinoj Josephec742f62022-09-29 19:11:10 +0530155
Akash Sonib3abf522022-12-19 13:20:02 +0530156 /** Target address for ND. */
vinokuma926cb3e2023-03-29 11:41:06 +0530157 Ipv6NdTarget 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. */
vinokuma926cb3e2023-03-29 11:41:06 +0530160 Ipv6NdSll 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. */
vinokuma926cb3e2023-03-29 11:41:06 +0530163 Ipv6NdTll string = "IPV6_ND_TLL"
Tinoj Josephec742f62022-09-29 19:11:10 +0530164
Akash Sonib3abf522022-12-19 13:20:02 +0530165 /** MPLS label. */
vinokuma926cb3e2023-03-29 11:41:06 +0530166 MplsLabel string = "MPLS_LABEL"
Tinoj Josephec742f62022-09-29 19:11:10 +0530167
Akash Sonib3abf522022-12-19 13:20:02 +0530168 /** MPLS TC. */
vinokuma926cb3e2023-03-29 11:41:06 +0530169 MplsTc string = "MPLS_TC"
Tinoj Josephec742f62022-09-29 19:11:10 +0530170
Akash Sonib3abf522022-12-19 13:20:02 +0530171 /** MPLS BoS bit. */
vinokuma926cb3e2023-03-29 11:41:06 +0530172 MplsBos string = "MPLS_BOS"
Tinoj Josephec742f62022-09-29 19:11:10 +0530173
Akash Sonib3abf522022-12-19 13:20:02 +0530174 /** PBB I-SID. */
vinokuma926cb3e2023-03-29 11:41:06 +0530175 PbbIsID string = "PBB_ISID"
Tinoj Josephec742f62022-09-29 19:11:10 +0530176
Akash Sonib3abf522022-12-19 13:20:02 +0530177 /** Logical Port Metadata. */
vinokuma926cb3e2023-03-29 11:41:06 +0530178 TunnelID string = "TUNNEL_ID"
Tinoj Josephec742f62022-09-29 19:11:10 +0530179
Akash Sonib3abf522022-12-19 13:20:02 +0530180 /** IPv6 Extension Header pseudo-field. */
vinokuma926cb3e2023-03-29 11:41:06 +0530181 Ipv6Exthdr string = "IPV6_EXTHDR"
Tinoj Josephec742f62022-09-29 19:11:10 +0530182
Akash Sonib3abf522022-12-19 13:20:02 +0530183 /** Unassigned value: 40. */
vinokuma926cb3e2023-03-29 11:41:06 +0530184 Unassigned40 string = "UNASSIGNED_40"
Tinoj Josephec742f62022-09-29 19:11:10 +0530185
Akash Sonib3abf522022-12-19 13:20:02 +0530186 /** PBB UCA header field. */
vinokuma926cb3e2023-03-29 11:41:06 +0530187 PbbUca string = "PBB_UCA"
Tinoj Josephec742f62022-09-29 19:11:10 +0530188
Akash Sonib3abf522022-12-19 13:20:02 +0530189 /** TCP flags. */
vinokuma926cb3e2023-03-29 11:41:06 +0530190 TCPFlags 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. */
vinokuma926cb3e2023-03-29 11:41:06 +0530193 ActsetOutput string = "ACTSET_OUTPUT"
Tinoj Josephec742f62022-09-29 19:11:10 +0530194
Akash Sonib3abf522022-12-19 13:20:02 +0530195 /** Packet type value. */
vinokuma926cb3e2023-03-29 11:41:06 +0530196 PacketType 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). */
vinokuma926cb3e2023-03-29 11:41:06 +0530203 OchSigID 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). */
vinokuma926cb3e2023-03-29 11:41:06 +0530206 OchSigType 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. */
vinokuma926cb3e2023-03-29 11:41:06 +0530209 OduSigID 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. */
vinokuma926cb3e2023-03-29 11:41:06 +0530212 OduSigType string = "ODU_SIGTYPE"
Tinoj Josephec742f62022-09-29 19:11:10 +0530213
Akash Sonib3abf522022-12-19 13:20:02 +0530214 /** Protocol-independent. */
vinokuma926cb3e2023-03-29 11:41:06 +0530215 ProtocolIndependent string = "PROTOCOL_INDEPENDENT"
Tinoj Josephec742f62022-09-29 19:11:10 +0530216
Akash Sonib3abf522022-12-19 13:20:02 +0530217 /** Extension criterion. */
vinokuma926cb3e2023-03-29 11:41:06 +0530218 Extension string = "EXTENSION"
Tinoj Josephec742f62022-09-29 19:11:10 +0530219
Akash Sonib3abf522022-12-19 13:20:02 +0530220 /** An empty criterion. */
vinokuma926cb3e2023-03-29 11:41:06 +0530221 Dummy string = "DUMMY"
Tinoj Josephec742f62022-09-29 19:11:10 +0530222
223 /* OUTPUT instruction */
vinokuma926cb3e2023-03-29 11:41:06 +0530224 Output string = "OUTPUT"
Tinoj Josephec742f62022-09-29 19:11:10 +0530225
226 /* METER instruction */
vinokuma926cb3e2023-03-29 11:41:06 +0530227 Meter string = "METER"
Tinoj Josephec742f62022-09-29 19:11:10 +0530228
229 /* L2MODIFICATION instruction type */
vinokuma926cb3e2023-03-29 11:41:06 +0530230 L2Modification string = "L2MODIFICATION"
Tinoj Josephec742f62022-09-29 19:11:10 +0530231
232 /* VLAN_PUSH operation */
vinokuma926cb3e2023-03-29 11:41:06 +0530233 VlanPush string = "VLAN_PUSH"
Tinoj Josephec742f62022-09-29 19:11:10 +0530234
235 /* VLAN_ID instruction */
vinokuma926cb3e2023-03-29 11:41:06 +0530236 VlanID string = "VLAN_ID"
Tinoj Josephec742f62022-09-29 19:11:10 +0530237
238 /* VLAN_POP operation */
vinokuma926cb3e2023-03-29 11:41:06 +0530239 VlanPop string = "VLAN_POP"
Tinoj Josephec742f62022-09-29 19:11:10 +0530240
241 /* VLAN_SET operation */
vinokuma926cb3e2023-03-29 11:41:06 +0530242 VlanSet string = "VLAN_SET"
Akash Sonib3abf522022-12-19 13:20:02 +0530243
vinokuma926cb3e2023-03-29 11:41:06 +0530244 All string = "ALL"
Akash Sonib3abf522022-12-19 13:20:02 +0530245
vinokuma926cb3e2023-03-29 11:41:06 +0530246 Added string = "ADDED"
Akash Sonib3abf522022-12-19 13:20:02 +0530247
vinokuma926cb3e2023-03-29 11:41:06 +0530248 Failed string = "FAILED"
Akash Sonib3abf522022-12-19 13:20:02 +0530249
vinokuma926cb3e2023-03-29 11:41:06 +0530250 FailedAdd string = "FAILED_ADD"
Akash Soni1db5e492023-03-27 14:14:07 +0530251
vinokuma926cb3e2023-03-29 11:41:06 +0530252 PendingAdd string = "PENDING_ADD"
Akash Soni1db5e492023-03-27 14:14:07 +0530253
vinokuma926cb3e2023-03-29 11:41:06 +0530254 PendingRemove string = "PENDING_REMOVE"
Akash Soni1db5e492023-03-27 14:14:07 +0530255
vinokuma926cb3e2023-03-29 11:41:06 +0530256 Pending string = "PENDING"
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 {
Tinoj Josephec742f62022-09-29 19:11:10 +0530399 State string `json:"state"`
Tinoj Josephec742f62022-09-29 19:11:10 +0530400 LiveType string `json:"liveType"`
Tinoj Josephec742f62022-09-29 19:11:10 +0530401 ID string `json:"id"`
402 AppID string `json:"appId"`
Tinoj Josephec742f62022-09-29 19:11:10 +0530403 DeviceID string `json:"deviceId"`
Tinoj Josephec742f62022-09-29 19:11:10 +0530404 TableName string `json:"tableName"`
405 Treatment TreatmentInfo `json:"treatment"`
406 Selector SelectorInfo `json:"selector"`
vinokuma926cb3e2023-03-29 11:41:06 +0530407 LastSeen int64 `json:"lastSeen"`
408 TableID int `json:"tableId"`
409 Priority int `json:"priority"`
410 Timeout int `json:"timeout"`
411 GroupID int `json:"groupId"`
412 Life int `json:"life"`
413 Packets int `json:"packets"`
414 Bytes int `json:"bytes"`
415 IsPermanent bool `json:"isPermanent"`
Tinoj Josephec742f62022-09-29 19:11:10 +0530416}
417
418type FlowEntry struct {
419 Flows []Flow `json:"flows"`
420}
421
vinokuma926cb3e2023-03-29 11:41:06 +0530422// Meter struct
Akash Sonib3abf522022-12-19 13:20:02 +0530423type Meters struct {
424 ID string `json:"id"`
Akash Sonib3abf522022-12-19 13:20:02 +0530425 Unit string `json:"unit"`
Akash Sonib3abf522022-12-19 13:20:02 +0530426 DeviceID string `json:"deviceId"`
427 AppID string `json:"appId"`
428 State string `json:"state"`
429 MeterBands []Bands `json:"bands"`
vinokuma926cb3e2023-03-29 11:41:06 +0530430 Life int `json:"life"`
431 Packets int `json:"packets"`
432 Bytes int `json:"bytes"`
433 ReferenceCount int `json:"referenceCount"`
434 Burst bool `json:"burst"`
Akash Sonib3abf522022-12-19 13:20:02 +0530435}
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 {
Akash Sonib3abf522022-12-19 13:20:02 +0530447 Type string `json:"type"`
448 DeviceID string `json:"deviceId"`
449 AppID string `json:"appId"`
450 AppCookie string `json:"appCookie"`
vinokuma926cb3e2023-03-29 11:41:06 +0530451 State string `json:"state"`
Akash Sonib3abf522022-12-19 13:20:02 +0530452 Buckets []Bucket `json:"buckets"`
vinokuma926cb3e2023-03-29 11:41:06 +0530453 ID int `json:"id"`
454 Life int `json:"life"`
455 Packets int `json:"packets"`
456 Bytes int `json:"bytes"`
457 ReferenceCount int `json:"referenceCount"`
Akash Sonib3abf522022-12-19 13:20:02 +0530458}
459
460type Bucket struct {
461 Type string `json:"type"`
vinokuma926cb3e2023-03-29 11:41:06 +0530462 Treatment Treatment `json:"treatment"`
Akash Sonib3abf522022-12-19 13:20:02 +0530463 Weight int `json:"weight"`
464 Packets int `json:"packets"`
465 Bytes int `json:"bytes"`
466 BucketID int `json:"bucketId"`
Akash Sonib3abf522022-12-19 13:20:02 +0530467}
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 {
vinokuma926cb3e2023-03-29 11:41:06 +0530520 flowState = Added
Akash Soni1db5e492023-03-27 14:14:07 +0530521 } else if state == of.FlowAddFailure {
vinokuma926cb3e2023-03-29 11:41:06 +0530522 flowState = FailedAdd
Akash Soni1db5e492023-03-27 14:14:07 +0530523 } else if state == of.FlowAddPending {
vinokuma926cb3e2023-03-29 11:41:06 +0530524 flowState = PendingAdd
Akash Soni1db5e492023-03-27 14:14:07 +0530525 } else if state == of.FlowDelPending {
vinokuma926cb3e2023-03-29 11:41:06 +0530526 flowState = PendingRemove
Akash Soni1db5e492023-03-27 14:14:07 +0530527 }
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{
vinokuma926cb3e2023-03-29 11:41:06 +0530541 Type: InPort,
Tinoj Josephec742f62022-09-29 19:11:10 +0530542 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{
vinokuma926cb3e2023-03-29 11:41:06 +0530548 Type: VlanVID,
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{
vinokuma926cb3e2023-03-29 11:41:06 +0530555 Type: EthSrc,
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{
vinokuma926cb3e2023-03-29 11:41:06 +0530562 Type: EthDst,
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{
vinokuma926cb3e2023-03-29 11:41:06 +0530569 Type: EthType,
Akash Sonib3abf522022-12-19 13:20:02 +0530570 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{
vinokuma926cb3e2023-03-29 11:41:06 +0530576 Type: IPProto,
Akash Sonib3abf522022-12-19 13:20:02 +0530577 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{
vinokuma926cb3e2023-03-29 11:41:06 +0530583 Type: UDPSrc,
Akash Sonib3abf522022-12-19 13:20:02 +0530584 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{
vinokuma926cb3e2023-03-29 11:41:06 +0530590 Type: UDPDst,
Akash Sonib3abf522022-12-19 13:20:02 +0530591 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{
vinokuma926cb3e2023-03-29 11:41:06 +0530597 Type: MetaData,
Akash Sonib3abf522022-12-19 13:20:02 +0530598 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{
vinokuma926cb3e2023-03-29 11:41:06 +0530606 Type: Output,
Tinoj Josephec742f62022-09-29 19:11:10 +0530607 }
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{
vinokuma926cb3e2023-03-29 11:41:06 +0530624 Type: L2Modification,
625 SubType: VlanPush,
Akash Sonib3abf522022-12-19 13:20:02 +0530626 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{
vinokuma926cb3e2023-03-29 11:41:06 +0530630 Type: L2Modification,
631 SubType: VlanID,
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{
vinokuma926cb3e2023-03-29 11:41:06 +0530639 Type: L2Modification,
640 SubType: VlanSet,
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{
vinokuma926cb3e2023-03-29 11:41:06 +0530647 Type: L2Modification,
648 SubType: VlanPop,
Tinoj Josephec742f62022-09-29 19:11:10 +0530649 }
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{
vinokuma926cb3e2023-03-29 11:41:06 +0530654 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,
Sridhar Ravindrab8374ae2023-04-14 15:49:25 +0530681 ServiceName: vs.ServiceType,
Akash Sonib3abf522022-12-19 13:20:02 +0530682 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"`
Akash Sonib3abf522022-12-19 13:20:02 +0530701 Role string `json:"role"`
702 Mfr string `json:"mfr"`
703 Hw string `json:"hw"`
704 Sw string `json:"sw"`
705 Serial string `json:"serial"`
706 Driver string `json:"driver"`
707 ChassisID string `json:"chassisId"`
708 LastUpdate string `json:"lastUpdate"`
709 HumanReadableLastUpdate string `json:"humanReadableLastUpdate"`
Tinoj Joseph429b9d92022-11-16 18:51:05 +0530710 Annotations DeviceAnnotations `json:"annotations"`
vinokuma926cb3e2023-03-29 11:41:06 +0530711 Available bool `json:"available"`
Tinoj Joseph429b9d92022-11-16 18:51:05 +0530712}
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"`
Akash Sonib3abf522022-12-19 13:20:02 +0530754 Type string `json:"type"`
Tinoj Joseph429b9d92022-11-16 18:51:05 +0530755 Annotations PortAnnotations `json:"annotations"`
vinokuma926cb3e2023-03-29 11:41:06 +0530756 PortSpeed int `json:"portSpeed"`
757 IsEnabled bool `json:"isEnabled"`
Tinoj Joseph429b9d92022-11-16 18:51:05 +0530758}
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 {
Hitesh Chhabraaf80b832023-07-21 15:27:20 +0530795 logger.Debug(ctx, "Entering into convertGroupsToOnosGroup")
Akash Sonib3abf522022-12-19 13:20:02 +0530796 var groups *GroupsInfo
797 var bucket []Bucket
798 Instruction := []Instructions{}
799 if groupsInfo != nil {
800 for _, buckets := range groupsInfo.Buckets {
801 inst := Instructions{
vinokuma926cb3e2023-03-29 11:41:06 +0530802 Type: All,
Akash Sonib3abf522022-12-19 13:20:02 +0530803 Port: fmt.Sprint(buckets),
804 }
805 Instruction = append(Instruction, inst)
806 trtmt := Treatment{
807 Instructions: Instruction,
808 }
809 bkt := Bucket{
vinokuma926cb3e2023-03-29 11:41:06 +0530810 Type: All,
Akash Sonib3abf522022-12-19 13:20:02 +0530811 Treatment: trtmt,
812 }
813 bucket = append(bucket, bkt)
814 }
815 if groupsInfo.State == of.GroupOperSuccess {
vinokuma926cb3e2023-03-29 11:41:06 +0530816 groups.State = Added
Akash Sonib3abf522022-12-19 13:20:02 +0530817 } else if groupsInfo.State == of.GroupOperFailure {
vinokuma926cb3e2023-03-29 11:41:06 +0530818 groups.State = Failed
Akash Sonib3abf522022-12-19 13:20:02 +0530819 } else if groupsInfo.State == of.GroupOperPending {
vinokuma926cb3e2023-03-29 11:41:06 +0530820 groups.State = Pending
Akash Sonib3abf522022-12-19 13:20:02 +0530821 }
822 groups = &GroupsInfo{
823 DeviceID: groupsInfo.Device,
824 ID: int(groupsInfo.GroupID),
825 State: groups.State,
vinokuma926cb3e2023-03-29 11:41:06 +0530826 Type: All,
Akash Sonib3abf522022-12-19 13:20:02 +0530827 Buckets: bucket,
828 }
829 }
830 return groups
831}
832
vinokuma926cb3e2023-03-29 11:41:06 +0530833func (mh *MetersHandle) MeterObjectMapping(meterInfo *of.Meter, deviceID string) Meters {
Akash Sonib3abf522022-12-19 13:20:02 +0530834 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 {
vinokuma926cb3e2023-03-29 11:41:06 +0530845 meter.State = Added
Akash Sonib3abf522022-12-19 13:20:02 +0530846 } else if meterInfo.State == of.MeterOperFailure {
vinokuma926cb3e2023-03-29 11:41:06 +0530847 meter.State = Failed
Akash Sonib3abf522022-12-19 13:20:02 +0530848 } else if meterInfo.State == of.MeterOperPending {
vinokuma926cb3e2023-03-29 11:41:06 +0530849 meter.State = Pending
Akash Sonib3abf522022-12-19 13:20:02 +0530850 }
851 meter = Meters{
852 ID: fmt.Sprint(meterInfo.ID),
853 State: meter.State,
vinokuma926cb3e2023-03-29 11:41:06 +0530854 DeviceID: deviceID,
Akash Sonib3abf522022-12-19 13:20:02 +0530855 MeterBands: bd,
856 }
857 return meter
Akash Sonib3abf522022-12-19 13:20:02 +0530858}