| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1 | /* |
| Joey Armstrong | 11f5a57 | 2024-01-12 19:11:32 -0500 | [diff] [blame] | 2 | * Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 3 | |
| 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. |
| 15 | */ |
| 16 | |
| Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 17 | // Package core provides the utility for olt devices, flows and statistics |
| Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 18 | package core |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 19 | |
| 20 | import ( |
| 21 | "context" |
| Matteo Scandolo | 6056e82 | 2019-11-13 14:05:29 -0800 | [diff] [blame] | 22 | "encoding/hex" |
| Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 23 | "errors" |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 24 | "fmt" |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 25 | "strconv" |
| serkant.uluderya | 4aff186 | 2020-09-17 23:35:26 +0300 | [diff] [blame] | 26 | "strings" |
| 27 | "sync" |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 28 | "time" |
| serkant.uluderya | 4aff186 | 2020-09-17 23:35:26 +0300 | [diff] [blame] | 29 | |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 30 | "github.com/opencord/voltha-lib-go/v7/pkg/meters" |
| Mahir Gunyel | 199570a | 2021-07-04 15:39:36 -0700 | [diff] [blame] | 31 | |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 32 | "github.com/opencord/voltha-lib-go/v7/pkg/flows" |
| 33 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 34 | plt "github.com/opencord/voltha-lib-go/v7/pkg/platform" |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 35 | tp "github.com/opencord/voltha-lib-go/v7/pkg/techprofile" |
| Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 36 | rsrcMgr "github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager" |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 37 | "github.com/opencord/voltha-protos/v5/go/common" |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 38 | ia "github.com/opencord/voltha-protos/v5/go/inter_adapter" |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 39 | ofp "github.com/opencord/voltha-protos/v5/go/openflow_13" |
| 40 | openoltpb2 "github.com/opencord/voltha-protos/v5/go/openolt" |
| 41 | tp_pb "github.com/opencord/voltha-protos/v5/go/tech_profile" |
| 42 | "github.com/opencord/voltha-protos/v5/go/voltha" |
| Chaitrashree G S | 579fe73 | 2019-08-20 20:50:47 -0400 | [diff] [blame] | 43 | |
| Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 44 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors" |
| Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 45 | "google.golang.org/grpc/codes" |
| 46 | "google.golang.org/grpc/status" |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 47 | ) |
| 48 | |
| 49 | const ( |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 50 | // IPProtoDhcp flow category |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 51 | IPProtoDhcp = 17 |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 52 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 53 | // IgmpProto proto value |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 54 | IgmpProto = 2 |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 55 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 56 | // EapEthType eapethtype value |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 57 | EapEthType = 0x888e |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 58 | // LldpEthType lldp ethtype value |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 59 | LldpEthType = 0x88cc |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 60 | // IPv4EthType IPv4 ethernet type value |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 61 | IPv4EthType = 0x800 |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 62 | // PPPoEDEthType PPPoE discovery ethernet type value |
| Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 63 | PPPoEDEthType = 0x8863 |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 64 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 65 | // ReservedVlan Transparent Vlan (Masked Vlan, VLAN_ANY in ONOS Flows) |
| Andrea Campanella | 7acc0b9 | 2020-02-14 09:20:49 +0100 | [diff] [blame] | 66 | ReservedVlan = 4096 |
| Harsh Awasthi | ea45af7 | 2019-08-26 02:39:00 -0400 | [diff] [blame] | 67 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 68 | // DefaultMgmtVlan default vlan value |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 69 | DefaultMgmtVlan = 4091 |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 70 | |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 71 | // Openolt Flow |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 72 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 73 | // Upstream constant |
| David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 74 | Upstream = "upstream" |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 75 | // Downstream constant |
| David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 76 | Downstream = "downstream" |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 77 | // Multicast constant |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 78 | Multicast = "multicast" |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 79 | // PacketTagType constant |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 80 | PacketTagType = "pkt_tag_type" |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 81 | // Untagged constant |
| David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 82 | Untagged = "untagged" |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 83 | // SingleTag constant |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 84 | SingleTag = "single_tag" |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 85 | // DoubleTag constant |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 86 | DoubleTag = "double_tag" |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 87 | |
| 88 | // classifierInfo |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 89 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 90 | // EthType constant |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 91 | EthType = "eth_type" |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 92 | // EthDst constant |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 93 | EthDst = "eth_dst" |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 94 | // EthSrc constant |
| Girish Gowdra | ffa52e5 | 2022-02-16 15:48:10 -0800 | [diff] [blame] | 95 | EthSrc = "eth_src" |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 96 | // TPID constant |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 97 | TPID = "tpid" |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 98 | // IPProto constant |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 99 | IPProto = "ip_proto" |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 100 | // InPort constant |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 101 | InPort = "in_port" |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 102 | // VlanVid constant |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 103 | VlanVid = "vlan_vid" |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 104 | // VlanPcp constant |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 105 | VlanPcp = "vlan_pcp" |
| 106 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 107 | // UDPDst constant |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 108 | UDPDst = "udp_dst" |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 109 | // UDPSrc constant |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 110 | UDPSrc = "udp_src" |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 111 | // Ipv4Dst constant |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 112 | Ipv4Dst = "ipv4_dst" |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 113 | // Ipv4Src constant |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 114 | Ipv4Src = "ipv4_src" |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 115 | // Metadata constant |
| David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 116 | Metadata = "metadata" |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 117 | // TunnelID constant |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 118 | TunnelID = "tunnel_id" |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 119 | // Output constant |
| David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 120 | Output = "output" |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 121 | // GroupID constant |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 122 | GroupID = "group_id" |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 123 | // Actions |
| 124 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 125 | // PopVlan constant |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 126 | PopVlan = "pop_vlan" |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 127 | // PushVlan constant |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 128 | PushVlan = "push_vlan" |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 129 | // TrapToHost constant |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 130 | TrapToHost = "trap_to_host" |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 131 | // MaxMeterBand constant |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 132 | MaxMeterBand = 2 |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 133 | // VlanPCPMask contant |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 134 | VlanPCPMask = 0xFF |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 135 | // VlanvIDMask constant |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 136 | VlanvIDMask = 0xFFF |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 137 | // IntfID constant |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 138 | IntfID = "intfId" |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 139 | // OnuID constant |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 140 | OnuID = "onuId" |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 141 | // UniID constant |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 142 | UniID = "uniId" |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 143 | // PortNo constant |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 144 | PortNo = "portNo" |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 145 | // AllocID constant |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 146 | AllocID = "allocId" |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 147 | // GemID constant |
| Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 148 | GemID = "gemId" |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 149 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 150 | // NoneOnuID constant |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 151 | NoneOnuID = -1 |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 152 | // NoneUniID constant |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 153 | NoneUniID = -1 |
| Matteo Scandolo | 738c52a | 2020-08-03 11:14:22 -0700 | [diff] [blame] | 154 | |
| Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 155 | // Max number of flows that can be queued per ONU |
| 156 | maxConcurrentFlowsPerOnu = 20 |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 157 | |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 158 | bitMapPrefix = "0b" |
| 159 | pbit1 = '1' |
| 160 | ) |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 161 | |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 162 | type schedQueue struct { |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 163 | tpInst interface{} |
| 164 | flowMetadata *ofp.FlowMetadata |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 165 | direction tp_pb.Direction |
| 166 | intfID uint32 |
| Sridhar Ravindra | d104e8d | 2025-06-02 13:04:49 +0530 | [diff] [blame] | 167 | nniIntfID uint32 |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 168 | onuID uint32 |
| 169 | uniID uint32 |
| 170 | tpID uint32 |
| 171 | uniPort uint32 |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 172 | meterID uint32 |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 175 | type flowContext struct { |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 176 | classifier map[string]interface{} |
| 177 | action map[string]interface{} |
| 178 | logicalFlow *ofp.OfpFlowStats |
| 179 | pbitToGem map[uint32]uint32 |
| 180 | gemToAes map[uint32]bool |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 181 | intfID uint32 |
| 182 | onuID uint32 |
| 183 | uniID uint32 |
| 184 | portNo uint32 |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 185 | allocID uint32 |
| 186 | gemPortID uint32 |
| 187 | tpID uint32 |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 188 | } |
| 189 | |
| Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 190 | // This control block is created per flow add/remove and pushed on the incomingFlows channel slice |
| 191 | // The flowControlBlock is then picked by the perOnuFlowHandlerRoutine for further processing. |
| 192 | // There is on perOnuFlowHandlerRoutine routine per ONU that constantly monitors for any incoming |
| 193 | // flow and processes it serially |
| 194 | type flowControlBlock struct { |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 195 | ctx context.Context // Flow handler context |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 196 | flow *ofp.OfpFlowStats // Flow message |
| 197 | flowMetadata *ofp.FlowMetadata // FlowMetadata that contains flow meter information. This can be nil for Flow remove |
| 198 | errChan *chan error // channel to report the Flow handling error |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 199 | addFlow bool // if true flow to be added, else removed |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 200 | } |
| 201 | |
| Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 202 | // OpenOltFlowMgr creates the Structure of OpenOltFlowMgr obj |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 203 | type OpenOltFlowMgr struct { |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 204 | techprofile tp.TechProfileIf |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 205 | deviceHandler *DeviceHandler |
| 206 | grpMgr *OpenOltGroupMgr |
| 207 | resourceMgr *rsrcMgr.OpenOltResourceMgr |
| 208 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 209 | packetInGemPort map[rsrcMgr.PacketInInfoKey]uint32 // packet in gem port local cache |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 210 | |
| Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 211 | // Slice of channels. Each channel in slice, index by ONU ID, queues flows per ONU. |
| 212 | // A go routine per ONU, waits on the unique channel (indexed by ONU ID) for incoming flows (add/remove) |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 213 | incomingFlows []chan flowControlBlock |
| 214 | stopFlowHandlerRoutine []chan bool |
| 215 | flowHandlerRoutineActive []bool |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 216 | packetInGemPortLock sync.RWMutex |
| 217 | |
| 218 | ponPortIdx uint32 // Pon Port this FlowManager is responsible for |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 219 | } |
| 220 | |
| Holger Hildebrandt | 143b5be | 2023-02-10 08:28:15 +0000 | [diff] [blame] | 221 | // CloseKVClient closes open KV clients |
| 222 | func (f *OpenOltFlowMgr) CloseKVClient(ctx context.Context) { |
| 223 | if f.techprofile != nil { |
| 224 | f.techprofile.CloseKVClient(ctx) |
| 225 | } |
| 226 | } |
| 227 | |
| Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 228 | // NewFlowManager creates OpenOltFlowMgr object and initializes the parameters |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 229 | func NewFlowManager(ctx context.Context, dh *DeviceHandler, rMgr *rsrcMgr.OpenOltResourceMgr, grpMgr *OpenOltGroupMgr, ponPortIdx uint32) *OpenOltFlowMgr { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 230 | logger.Infow(ctx, "initializing-flow-manager", log.Fields{"device-id": dh.device.Id}) |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 231 | var flowMgr OpenOltFlowMgr |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 232 | var err error |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 233 | |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 234 | flowMgr.deviceHandler = dh |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 235 | flowMgr.ponPortIdx = ponPortIdx |
| Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 236 | flowMgr.grpMgr = grpMgr |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 237 | flowMgr.resourceMgr = rMgr |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 238 | // dh.totalPonPorts is reserved for NNI trap flows. It doesn't need a tech profile |
| 239 | if ponPortIdx != dh.totalPonPorts { |
| 240 | if err = flowMgr.populateTechProfileForCurrentPonPort(ctx); err != nil { |
| 241 | logger.Errorw(ctx, "error-while-populating-tech-profile-mgr", log.Fields{"err": err}) |
| 242 | return nil |
| 243 | } |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 244 | } |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 245 | flowMgr.packetInGemPort = make(map[rsrcMgr.PacketInInfoKey]uint32) |
| Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 246 | |
| 247 | // Create a slice of buffered channels for handling concurrent flows per ONU. |
| 248 | // The additional entry (+1) is to handle the NNI trap flows on a separate channel from individual ONUs channel |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 249 | flowMgr.incomingFlows = make([]chan flowControlBlock, plt.MaxOnusPerPon+1) |
| 250 | flowMgr.stopFlowHandlerRoutine = make([]chan bool, plt.MaxOnusPerPon+1) |
| 251 | flowMgr.flowHandlerRoutineActive = make([]bool, plt.MaxOnusPerPon+1) |
| Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 252 | for i := range flowMgr.incomingFlows { |
| 253 | flowMgr.incomingFlows[i] = make(chan flowControlBlock, maxConcurrentFlowsPerOnu) |
| Girish Gowdra | ae56c72 | 2021-11-22 14:31:11 -0800 | [diff] [blame] | 254 | flowMgr.stopFlowHandlerRoutine[i] = make(chan bool) |
| Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 255 | // Spin up a go routine to handling incoming flows (add/remove). |
| 256 | // There will be on go routine per ONU. |
| 257 | // This routine will be blocked on the flowMgr.incomingFlows[onu-id] channel for incoming flows. |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 258 | flowMgr.flowHandlerRoutineActive[i] = true |
| 259 | go flowMgr.perOnuFlowHandlerRoutine(i, flowMgr.incomingFlows[i], flowMgr.stopFlowHandlerRoutine[i]) |
| Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 260 | } |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 261 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 262 | // load interface to multicast queue map from kv store |
| Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 263 | flowMgr.grpMgr.LoadInterfaceToMulticastQueueMap(ctx) |
| balaji.nagarajan | 31db4ea | 2026-01-28 09:13:55 +0530 | [diff] [blame] | 264 | logger.Debugw(ctx, "initialization-of-flow-manager-success", log.Fields{"device-id": dh.device.Id}) |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 265 | return &flowMgr |
| 266 | } |
| 267 | |
| Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 268 | func (f *OpenOltFlowMgr) registerFlow(ctx context.Context, flowFromCore *ofp.OfpFlowStats, deviceFlow *openoltpb2.Flow) error { |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 269 | // In case of nni trap flow |
| 270 | if deviceFlow.AccessIntfId == -1 { |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 271 | return f.resourceMgr.RegisterFlowIDForGem(ctx, uint32(deviceFlow.AccessIntfId), flowFromCore) |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 272 | } |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 273 | if !deviceFlow.ReplicateFlow && deviceFlow.GemportId > 0 { |
| 274 | // Flow is not replicated in this case, we need to register the flow for a single gem-port |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 275 | return f.resourceMgr.RegisterFlowIDForGem(ctx, uint32(deviceFlow.GemportId), flowFromCore) |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 276 | } else if deviceFlow.ReplicateFlow && len(deviceFlow.PbitToGemport) > 0 { |
| 277 | // Flow is replicated in this case. We need to register the flow for all the gem-ports it is replicated to. |
| 278 | for _, gemPort := range deviceFlow.PbitToGemport { |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 279 | if err := f.resourceMgr.RegisterFlowIDForGem(ctx, gemPort, flowFromCore); err != nil { |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 280 | return err |
| 281 | } |
| Matteo Scandolo | 738c52a | 2020-08-03 11:14:22 -0700 | [diff] [blame] | 282 | } |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 283 | } |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 284 | return nil |
| 285 | } |
| 286 | |
| Sridhar Ravindra | d104e8d | 2025-06-02 13:04:49 +0530 | [diff] [blame] | 287 | func (f *OpenOltFlowMgr) processAddFlow(ctx context.Context, intfID uint32, nni_port uint32, onuID uint32, uniID uint32, portNo uint32, |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 288 | classifierInfo map[string]interface{}, actionInfo map[string]interface{}, flow *ofp.OfpFlowStats, TpID uint32, |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 289 | UsMeterID uint32, DsMeterID uint32, flowMetadata *ofp.FlowMetadata) error { |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 290 | var allocID uint32 |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 291 | var gemPorts []uint32 |
| Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 292 | var TpInst interface{} |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 293 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 294 | logger.Infow(ctx, "dividing-flow", log.Fields{ |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 295 | "device-id": f.deviceHandler.device.Id, |
| 296 | "intf-id": intfID, |
| 297 | "onu-id": onuID, |
| 298 | "uni-id": uniID, |
| 299 | "port-no": portNo, |
| Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 300 | "classifier": classifierInfo, |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 301 | "action": actionInfo, |
| 302 | "usmeter-iD": UsMeterID, |
| 303 | "dsmeter-iD": DsMeterID, |
| 304 | "tp-id": TpID}) |
| Matt Jeanneret | 7719961 | 2019-07-26 18:08:35 -0400 | [diff] [blame] | 305 | // only create tcont/gemports if there is actually an onu id. otherwise BAL throws an error. Usually this |
| 306 | // is because the flow is an NNI flow and there would be no onu resources associated with it |
| 307 | // TODO: properly deal with NNI flows |
| Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 308 | if onuID == 0 { |
| Andrea Campanella | bfe0843 | 2020-09-11 17:07:03 +0200 | [diff] [blame] | 309 | cause := "no-onu-id-for-flow" |
| 310 | fields := log.Fields{ |
| 311 | "onu": onuID, |
| 312 | "port-no": portNo, |
| 313 | "classifer": classifierInfo, |
| 314 | "action": actionInfo, |
| 315 | "device-id": f.deviceHandler.device.Id} |
| 316 | logger.Errorw(ctx, cause, fields) |
| 317 | return olterrors.NewErrNotFound(cause, fields, nil) |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 318 | } |
| 319 | |
| Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 320 | uni := getUniPortPath(f.deviceHandler.device.Id, intfID, int32(onuID), int32(uniID)) |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 321 | logger.Debugw(ctx, "uni-port-path", log.Fields{ |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 322 | "uni": uni, |
| 323 | "device-id": f.deviceHandler.device.Id}) |
| Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 324 | |
| Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 325 | logger.Debugw(ctx, "dividing-flow-create-tcont-gem-ports", log.Fields{ |
| 326 | "device-id": f.deviceHandler.device.Id, |
| 327 | "intf-id": intfID, |
| 328 | "onu-id": onuID, |
| 329 | "uni-id": uniID, |
| 330 | "port-no": portNo, |
| 331 | "classifier": classifierInfo, |
| 332 | "action": actionInfo, |
| 333 | "usmeter-id": UsMeterID, |
| 334 | "dsmeter-id": DsMeterID, |
| 335 | "tp-id": TpID}) |
| Sridhar Ravindra | d104e8d | 2025-06-02 13:04:49 +0530 | [diff] [blame] | 336 | allocID, gemPorts, TpInst = f.createTcontGemports(ctx, intfID, nni_port, onuID, uniID, uni, portNo, TpID, UsMeterID, DsMeterID, flowMetadata) |
| Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 337 | if allocID == 0 || gemPorts == nil || TpInst == nil { |
| 338 | logger.Error(ctx, "alloc-id-gem-ports-tp-unavailable") |
| 339 | return olterrors.NewErrNotFound( |
| 340 | "alloc-id-gem-ports-tp-unavailable", |
| 341 | nil, nil) |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 342 | } |
| Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 343 | args := make(map[string]uint32) |
| 344 | args[IntfID] = intfID |
| 345 | args[OnuID] = onuID |
| 346 | args[UniID] = uniID |
| 347 | args[PortNo] = portNo |
| 348 | args[AllocID] = allocID |
| 349 | |
| 350 | /* Flows can be added specific to gemport if p-bits are received. |
| 351 | * If no pbit mentioned then adding flows for all gemports |
| 352 | */ |
| Gamze Abaka | 6d0a64f | 2021-11-18 08:08:33 +0000 | [diff] [blame] | 353 | return f.checkAndAddFlow(ctx, args, classifierInfo, actionInfo, flow, TpInst, gemPorts, TpID, uni) |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 354 | } |
| 355 | |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 356 | // CreateSchedulerQueues creates traffic schedulers on the device with the given scheduler configuration and traffic shaping info |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 357 | // nolint: gocyclo |
| npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 358 | func (f *OpenOltFlowMgr) CreateSchedulerQueues(ctx context.Context, sq schedQueue) error { |
| nikesh.krishnan | 81ec744 | 2023-10-31 17:19:34 +0530 | [diff] [blame] | 359 | logger.Debugw(ctx, "CreateSchedulerQueues", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 360 | log.Fields{"dir": sq.direction, |
| 361 | "intf-id": sq.intfID, |
| Sridhar Ravindra | d104e8d | 2025-06-02 13:04:49 +0530 | [diff] [blame] | 362 | "nniIntfID": sq.nniIntfID, |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 363 | "onu-id": sq.onuID, |
| 364 | "uni-id": sq.uniID, |
| 365 | "tp-id": sq.tpID, |
| 366 | "meter-id": sq.meterID, |
| 367 | "tp-inst": sq.tpInst, |
| 368 | "flowmetadata": sq.flowMetadata, |
| 369 | "device-id": f.deviceHandler.device.Id}) |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 370 | |
| Girish Gowdra | 6071f38 | 2021-12-14 12:52:04 +0530 | [diff] [blame] | 371 | direction, err := verifyMeterIDAndGetDirection(sq.meterID, sq.direction) |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 372 | if err != nil { |
| 373 | return err |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 374 | } |
| 375 | |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 376 | var TrafficShaping *tp_pb.TrafficShapingInfo |
| 377 | if sq.flowMetadata == nil || len(sq.flowMetadata.Meters) != 1 { |
| 378 | return olterrors.NewErrInvalidValue(log.Fields{ |
| 379 | "reason": "invalid-meter-config", |
| 380 | "meter-id": sq.meterID, |
| 381 | "device-id": f.deviceHandler.device.Id}, nil) |
| 382 | } |
| 383 | |
| 384 | if TrafficShaping, err = meters.GetTrafficShapingInfo(ctx, sq.flowMetadata.Meters[0]); err != nil { |
| 385 | return olterrors.NewErrInvalidValue(log.Fields{ |
| 386 | "reason": "invalid-meter-config", |
| 387 | "meter-id": sq.meterID, |
| 388 | "device-id": f.deviceHandler.device.Id}, nil) |
| 389 | } |
| 390 | |
| 391 | var SchedCfg *tp_pb.SchedulerConfig |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 392 | switch sq.direction { |
| 393 | case tp_pb.Direction_UPSTREAM: |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 394 | SchedCfg = f.techprofile.GetUsScheduler(sq.tpInst.(*tp_pb.TechProfileInstance)) |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 395 | case tp_pb.Direction_DOWNSTREAM: |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 396 | SchedCfg = f.techprofile.GetDsScheduler(sq.tpInst.(*tp_pb.TechProfileInstance)) |
| 397 | } |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 398 | trafficSched := f.techprofile.GetTrafficScheduler(sq.tpInst.(*tp_pb.TechProfileInstance), SchedCfg, TrafficShaping) |
| 399 | trafficSched.TechProfileId = sq.tpID |
| 400 | TrafficSched := []*tp_pb.TrafficScheduler{trafficSched} |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 401 | |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 402 | /* Lets make a simple assumption that if the meter-id is present on the KV store, |
| 403 | * then the scheduler and queues configuration is applied on the OLT device |
| 404 | * in the given direction. |
| 405 | */ |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 406 | meterInfo, err := f.resourceMgr.GetMeterInfoForOnu(ctx, direction, sq.onuID, sq.uniID, sq.tpID) |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 407 | if err != nil { |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 408 | return olterrors.NewErrNotFound("meter", |
| 409 | log.Fields{"intf-id": sq.intfID, |
| 410 | "onu-id": sq.onuID, |
| 411 | "uni-id": sq.uniID, |
| 412 | "device-id": f.deviceHandler.device.Id}, err) |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 413 | } |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 414 | |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 415 | // update reference count and return if the meter was already installed before |
| Girish Gowdra | 6071f38 | 2021-12-14 12:52:04 +0530 | [diff] [blame] | 416 | if meterInfo != nil && meterInfo.MeterID == sq.meterID { |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 417 | logger.Infow(ctx, "scheduler-already-created-for-direction", |
| Girish Gowdra | 6071f38 | 2021-12-14 12:52:04 +0530 | [diff] [blame] | 418 | log.Fields{"device-id": f.deviceHandler.device.Id, "direction": direction, "meter-id": sq.meterID}) |
| balaji.nagarajan | 29be8bc | 2026-01-26 16:31:41 +0530 | [diff] [blame] | 419 | if err = f.resourceMgr.HandleMeterInfoRefCntUpdate(ctx, meterInfo, direction, sq.onuID, sq.uniID, sq.tpID, true); err != nil { |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 420 | return err |
| 421 | } |
| 422 | |
| 423 | if allocExists := f.isAllocUsedByAnotherUNI(ctx, sq); allocExists { |
| 424 | // Alloc object was already created as part of flow setup on another uni of the onu for the same service. |
| 425 | // Just create gem ports and traffic queues on the current uni for the given service |
| 426 | logger.Infow(ctx, "alloc in use on another uni, schedulers already created, creating queues only", |
| 427 | log.Fields{"intf-id": sq.intfID, |
| 428 | "onu-id": sq.onuID, |
| 429 | "uni-id": sq.uniID, |
| 430 | "tp-id": sq.tpID, |
| 431 | "device-id": f.deviceHandler.device.Id}) |
| 432 | // The upstream scheduler is already created. We only need to create the queues |
| 433 | // If there are multiple upstream flows on a given uni, then it is possible that |
| 434 | // we call pushTrafficQueues multiple times, but that is OK as BAL returns OK. |
| 435 | // TODO: Find better mechanism to not duplicate request. |
| 436 | if err = f.pushTrafficQueues(ctx, sq, TrafficSched); err != nil { |
| 437 | return olterrors.NewErrAdapter("failure-pushing-traffic-queues-to-device", |
| 438 | log.Fields{"intf-id": sq.intfID, |
| 439 | "direction": sq.direction, |
| 440 | "device-id": f.deviceHandler.device.Id}, err) |
| 441 | } |
| 442 | } else { |
| 443 | logger.Infow(ctx, "alloc not in use on another uni, only meter ref cnt updated", |
| 444 | log.Fields{"intf-id": sq.intfID, |
| 445 | "onu-id": sq.onuID, |
| 446 | "uni-id": sq.uniID, |
| 447 | "tp-id": sq.tpID, |
| 448 | "device-id": f.deviceHandler.device.Id}) |
| 449 | } |
| 450 | return err |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 451 | } |
| Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 452 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 453 | logger.Debugw(ctx, "meter-does-not-exist-creating-new", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 454 | log.Fields{ |
| 455 | "meter-id": sq.meterID, |
| Girish Gowdra | 6071f38 | 2021-12-14 12:52:04 +0530 | [diff] [blame] | 456 | "direction": direction, |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 457 | "device-id": f.deviceHandler.device.Id}) |
| Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 458 | |
| Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 459 | found := false |
| 460 | meterInfo = &rsrcMgr.MeterInfo{} |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 461 | if sq.flowMetadata != nil { |
| 462 | for _, meter := range sq.flowMetadata.Meters { |
| 463 | if sq.meterID == meter.MeterId { |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 464 | meterInfo.MeterID = meter.MeterId |
| Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 465 | meterInfo.RefCnt = 1 // initialize it to 1, since this is the first flow that referenced the meter id. |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 466 | logger.Debugw(ctx, "found-meter-config-from-flowmetadata", |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 467 | log.Fields{"meter": meter, |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 468 | "device-id": f.deviceHandler.device.Id}) |
| Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 469 | found = true |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 470 | break |
| 471 | } |
| 472 | } |
| 473 | } else { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 474 | logger.Errorw(ctx, "flow-metadata-not-present-in-flow", log.Fields{"device-id": f.deviceHandler.device.Id}) |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 475 | } |
| Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 476 | if !found { |
| Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 477 | return olterrors.NewErrNotFound("meterbands", log.Fields{ |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 478 | "reason": "Could-not-get-meterbands-from-flowMetadata", |
| 479 | "flow-metadata": sq.flowMetadata, |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 480 | "meter-id": sq.meterID, |
| 481 | "device-id": f.deviceHandler.device.Id}, nil) |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 482 | } |
| Gamze Abaka | 0117442 | 2021-03-10 06:55:27 +0000 | [diff] [blame] | 483 | |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 484 | if err := f.pushSchedulerQueuesToDevice(ctx, sq, TrafficSched); err != nil { |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 485 | return olterrors.NewErrAdapter("failure-pushing-traffic-scheduler-and-queues-to-device", |
| 486 | log.Fields{"intf-id": sq.intfID, |
| 487 | "direction": sq.direction, |
| 488 | "device-id": f.deviceHandler.device.Id}, err) |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 489 | } |
| 490 | |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 491 | /* After we successfully applied the scheduler configuration on the OLT device, |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 492 | * store the meter id on the KV store, for further reference. |
| 493 | */ |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 494 | if err := f.resourceMgr.StoreMeterInfoForOnu(ctx, direction, sq.onuID, sq.uniID, sq.tpID, meterInfo); err != nil { |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 495 | return olterrors.NewErrAdapter("failed-updating-meter-id", |
| 496 | log.Fields{"onu-id": sq.onuID, |
| 497 | "meter-id": sq.meterID, |
| 498 | "device-id": f.deviceHandler.device.Id}, err) |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 499 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 500 | logger.Infow(ctx, "updated-meter-info-into-kv-store-successfully", |
| Girish Gowdra | 6071f38 | 2021-12-14 12:52:04 +0530 | [diff] [blame] | 501 | log.Fields{"direction": direction, |
| Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 502 | "meter-info": meterInfo, |
| 503 | "device-id": f.deviceHandler.device.Id}) |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 504 | return nil |
| 505 | } |
| 506 | |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 507 | func (f *OpenOltFlowMgr) pushTrafficQueues(ctx context.Context, sq schedQueue, TrafficSched []*tp_pb.TrafficScheduler) error { |
| 508 | trafficQueues, err := f.techprofile.GetTrafficQueues(ctx, sq.tpInst.(*tp_pb.TechProfileInstance), sq.direction) |
| 509 | if err != nil { |
| 510 | return olterrors.NewErrAdapter("unable-to-construct-traffic-queue-configuration", |
| 511 | log.Fields{"intf-id": sq.intfID, |
| 512 | "direction": sq.direction, |
| 513 | "device-id": f.deviceHandler.device.Id}, err) |
| 514 | } |
| 515 | logger.Debugw(ctx, "sending-traffic-queues-create-to-device", |
| 516 | log.Fields{"direction": sq.direction, |
| 517 | "traffic-queues": trafficQueues, |
| 518 | "device-id": f.deviceHandler.device.Id}) |
| Sridhar Ravindra | d104e8d | 2025-06-02 13:04:49 +0530 | [diff] [blame] | 519 | queues := &tp_pb.TrafficQueues{IntfId: sq.intfID, NetworkIntfId: sq.nniIntfID, OnuId: sq.onuID, |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 520 | UniId: sq.uniID, PortNo: sq.uniPort, |
| 521 | TrafficQueues: trafficQueues, |
| 522 | TechProfileId: TrafficSched[0].TechProfileId} |
| bseeniva | a162211 | 2025-12-11 18:24:02 +0530 | [diff] [blame] | 523 | subCtx1, cancel1 := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), f.deviceHandler.cfg.RPCTimeout) |
| 524 | if _, err = f.deviceHandler.Client.CreateTrafficQueues(subCtx1, queues); err != nil { |
| 525 | cancel1() |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 526 | if len(queues.TrafficQueues) > 1 { |
| 527 | logger.Debug(ctx, "removing-queues-for-1tcont-multi-gem", log.Fields{"intfID": sq.intfID, "onuID": sq.onuID, "dir": sq.direction}) |
| bseeniva | a162211 | 2025-12-11 18:24:02 +0530 | [diff] [blame] | 528 | subCtx2, cancel2 := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), f.deviceHandler.cfg.RPCTimeout) |
| 529 | _, _ = f.deviceHandler.Client.RemoveTrafficQueues(subCtx2, queues) |
| 530 | cancel2() |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 531 | } |
| 532 | return olterrors.NewErrAdapter("failed-to-create-traffic-queues-in-device", log.Fields{"traffic-queues": trafficQueues}, err) |
| 533 | } |
| bseeniva | a162211 | 2025-12-11 18:24:02 +0530 | [diff] [blame] | 534 | cancel1() |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 535 | return err |
| 536 | } |
| 537 | |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 538 | func (f *OpenOltFlowMgr) pushSchedulerQueuesToDevice(ctx context.Context, sq schedQueue, TrafficSched []*tp_pb.TrafficScheduler) error { |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 539 | trafficQueues, err := f.techprofile.GetTrafficQueues(ctx, sq.tpInst.(*tp_pb.TechProfileInstance), sq.direction) |
| Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 540 | |
| 541 | if err != nil { |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 542 | return olterrors.NewErrAdapter("unable-to-construct-traffic-queue-configuration", |
| 543 | log.Fields{"intf-id": sq.intfID, |
| 544 | "direction": sq.direction, |
| 545 | "device-id": f.deviceHandler.device.Id}, err) |
| Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 546 | } |
| 547 | |
| Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 548 | if allocExists := f.isAllocUsedByAnotherUNI(ctx, sq); !allocExists { |
| 549 | logger.Debugw(ctx, "sending-traffic-scheduler-create-to-device", |
| 550 | log.Fields{ |
| 551 | "direction": sq.direction, |
| 552 | "TrafficScheds": TrafficSched, |
| 553 | "device-id": f.deviceHandler.device.Id, |
| 554 | "intfID": sq.intfID, |
| Sridhar Ravindra | d104e8d | 2025-06-02 13:04:49 +0530 | [diff] [blame] | 555 | "nniIntfID": sq.nniIntfID, |
| Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 556 | "onuID": sq.onuID, |
| 557 | "uniID": sq.uniID}) |
| bseeniva | a162211 | 2025-12-11 18:24:02 +0530 | [diff] [blame] | 558 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), f.deviceHandler.cfg.RPCTimeout) |
| 559 | if _, err := f.deviceHandler.Client.CreateTrafficSchedulers(subCtx, &tp_pb.TrafficSchedulers{ |
| Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 560 | IntfId: sq.intfID, OnuId: sq.onuID, |
| 561 | UniId: sq.uniID, PortNo: sq.uniPort, |
| 562 | TrafficScheds: TrafficSched}); err != nil { |
| bseeniva | a162211 | 2025-12-11 18:24:02 +0530 | [diff] [blame] | 563 | cancel() |
| Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 564 | return olterrors.NewErrAdapter("failed-to-create-traffic-schedulers-in-device", log.Fields{"TrafficScheds": TrafficSched}, err) |
| 565 | } |
| bseeniva | a162211 | 2025-12-11 18:24:02 +0530 | [diff] [blame] | 566 | cancel() |
| balaji.nagarajan | 31db4ea | 2026-01-28 09:13:55 +0530 | [diff] [blame] | 567 | logger.Debugw(ctx, "successfully-created-traffic-schedulers", log.Fields{ |
| Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 568 | "direction": sq.direction, |
| 569 | "traffic-queues": trafficQueues, |
| 570 | "device-id": f.deviceHandler.device.Id}) |
| Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | // On receiving the CreateTrafficQueues request, the driver should create corresponding |
| 574 | // downstream queues. |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 575 | logger.Debugw(ctx, "sending-traffic-queues-create-to-device", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 576 | log.Fields{"direction": sq.direction, |
| 577 | "traffic-queues": trafficQueues, |
| 578 | "device-id": f.deviceHandler.device.Id}) |
| Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 579 | queues := &tp_pb.TrafficQueues{IntfId: sq.intfID, OnuId: sq.onuID, |
| Sridhar Ravindra | d104e8d | 2025-06-02 13:04:49 +0530 | [diff] [blame] | 580 | NetworkIntfId: sq.nniIntfID, |
| 581 | UniId: sq.uniID, PortNo: sq.uniPort, |
| Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 582 | TrafficQueues: trafficQueues, |
| 583 | TechProfileId: TrafficSched[0].TechProfileId} |
| bseeniva | a162211 | 2025-12-11 18:24:02 +0530 | [diff] [blame] | 584 | subCtx1, cancel1 := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), f.deviceHandler.cfg.RPCTimeout) |
| 585 | if _, err := f.deviceHandler.Client.CreateTrafficQueues(subCtx1, queues); err != nil { |
| 586 | cancel1() |
| Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 587 | if len(queues.TrafficQueues) > 1 { |
| 588 | logger.Debug(ctx, "removing-queues-for-1tcont-multi-gem", log.Fields{"intfID": sq.intfID, "onuID": sq.onuID, "dir": sq.direction}) |
| bseeniva | a162211 | 2025-12-11 18:24:02 +0530 | [diff] [blame] | 589 | subCtx2, cancel2 := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), f.deviceHandler.cfg.RPCTimeout) |
| 590 | _, _ = f.deviceHandler.Client.RemoveTrafficQueues(subCtx2, queues) |
| 591 | cancel2() |
| Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 592 | } |
| 593 | f.revertScheduler(ctx, sq, TrafficSched) |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 594 | return olterrors.NewErrAdapter("failed-to-create-traffic-queues-in-device", log.Fields{"traffic-queues": trafficQueues}, err) |
| Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 595 | } |
| bseeniva | a162211 | 2025-12-11 18:24:02 +0530 | [diff] [blame] | 596 | cancel1() |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 597 | logger.Infow(ctx, "successfully-created-traffic-schedulers", log.Fields{ |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 598 | "direction": sq.direction, |
| 599 | "traffic-queues": trafficQueues, |
| 600 | "device-id": f.deviceHandler.device.Id}) |
| Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 601 | |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 602 | if sq.direction == tp_pb.Direction_DOWNSTREAM { |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 603 | multicastTrafficQueues := f.techprofile.GetMulticastTrafficQueues(ctx, sq.tpInst.(*tp_pb.TechProfileInstance)) |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 604 | if len(multicastTrafficQueues) > 0 { |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 605 | if _, present := f.grpMgr.GetInterfaceToMcastQueueMap(sq.intfID); !present { // assumed that there is only one queue per PON for the multicast service |
| 606 | // the default queue with multicastQueuePerPonPort.Priority per a pon interface is used for multicast service |
| 607 | // just put it in interfaceToMcastQueueMap to use for building group members |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 608 | logger.Debugw(ctx, "multicast-traffic-queues", log.Fields{"device-id": f.deviceHandler.device.Id}) |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 609 | multicastQueuePerPonPort := multicastTrafficQueues[0] |
| Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 610 | val := &QueueInfoBrief{ |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 611 | gemPortID: multicastQueuePerPonPort.GemportId, |
| 612 | servicePriority: multicastQueuePerPonPort.Priority, |
| 613 | } |
| Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 614 | f.grpMgr.UpdateInterfaceToMcastQueueMap(sq.intfID, val) |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 615 | // also store the queue info in kv store |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 616 | if err := f.resourceMgr.AddMcastQueueForIntf(ctx, multicastQueuePerPonPort.GemportId, multicastQueuePerPonPort.Priority); err != nil { |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 617 | logger.Errorw(ctx, "failed-to-add-mcast-queue", log.Fields{"err": err}) |
| Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 618 | return err |
| 619 | } |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 620 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 621 | logger.Infow(ctx, "multicast-queues-successfully-updated", log.Fields{"device-id": f.deviceHandler.device.Id}) |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 622 | } |
| 623 | } |
| 624 | } |
| Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 625 | return nil |
| 626 | } |
| 627 | |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 628 | // RemoveQueues removes the traffic queues from the device based on the given schedQueue info |
| 629 | func (f *OpenOltFlowMgr) RemoveQueues(ctx context.Context, sq schedQueue) error { |
| 630 | var err error |
| 631 | logger.Infow(ctx, "removing-queue-in-olt", |
| 632 | log.Fields{ |
| 633 | "direction": sq.direction, |
| 634 | "intf-id": sq.intfID, |
| Sridhar Ravindra | d104e8d | 2025-06-02 13:04:49 +0530 | [diff] [blame] | 635 | "nniIntfID": sq.nniIntfID, |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 636 | "onu-id": sq.onuID, |
| 637 | "uni-id": sq.uniID, |
| 638 | "uni-port": sq.uniPort, |
| 639 | "device-id": f.deviceHandler.device.Id}) |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 640 | |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 641 | TrafficQueues, err := f.techprofile.GetTrafficQueues(ctx, sq.tpInst.(*tp_pb.TechProfileInstance), sq.direction) |
| 642 | if err != nil { |
| 643 | return olterrors.NewErrAdapter("unable-to-construct-traffic-queue-configuration", |
| 644 | log.Fields{ |
| 645 | "intf-id": sq.intfID, |
| 646 | "direction": sq.direction, |
| 647 | "device-id": f.deviceHandler.device.Id}, err) |
| 648 | } |
| 649 | |
| bseeniva | a162211 | 2025-12-11 18:24:02 +0530 | [diff] [blame] | 650 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), f.deviceHandler.cfg.RPCTimeout) |
| 651 | defer cancel() |
| 652 | if _, err = f.deviceHandler.Client.RemoveTrafficQueues(subCtx, |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 653 | &tp_pb.TrafficQueues{IntfId: sq.intfID, OnuId: sq.onuID, |
| Sridhar Ravindra | d104e8d | 2025-06-02 13:04:49 +0530 | [diff] [blame] | 654 | NetworkIntfId: sq.nniIntfID, |
| 655 | UniId: sq.uniID, PortNo: sq.uniPort, |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 656 | TrafficQueues: TrafficQueues, |
| 657 | TechProfileId: sq.tpID}); err != nil { |
| 658 | return olterrors.NewErrAdapter("unable-to-remove-traffic-queues-from-device", |
| 659 | log.Fields{ |
| 660 | "intf-id": sq.intfID, |
| 661 | "traffic-queues": TrafficQueues, |
| 662 | "device-id": f.deviceHandler.device.Id}, err) |
| 663 | } |
| balaji.nagarajan | 31db4ea | 2026-01-28 09:13:55 +0530 | [diff] [blame] | 664 | logger.Debugw(ctx, "removed-traffic-queues-successfully", log.Fields{"device-id": f.deviceHandler.device.Id, "trafficQueues": TrafficQueues}) |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 665 | |
| 666 | return err |
| 667 | } |
| 668 | |
| 669 | // RemoveScheduler removes the traffic scheduler from the device based on the given schedQueue info |
| 670 | func (f *OpenOltFlowMgr) RemoveScheduler(ctx context.Context, sq schedQueue) error { |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 671 | var Direction string |
| 672 | var SchedCfg *tp_pb.SchedulerConfig |
| 673 | var err error |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 674 | logger.Infow(ctx, "removing-scheduler-in-olt", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 675 | log.Fields{ |
| 676 | "direction": sq.direction, |
| 677 | "intf-id": sq.intfID, |
| 678 | "onu-id": sq.onuID, |
| 679 | "uni-id": sq.uniID, |
| 680 | "uni-port": sq.uniPort, |
| 681 | "device-id": f.deviceHandler.device.Id}) |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 682 | switch sq.direction { |
| 683 | case tp_pb.Direction_UPSTREAM: |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 684 | SchedCfg = f.techprofile.GetUsScheduler(sq.tpInst.(*tp_pb.TechProfileInstance)) |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 685 | Direction = "upstream" |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 686 | case tp_pb.Direction_DOWNSTREAM: |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 687 | SchedCfg = f.techprofile.GetDsScheduler(sq.tpInst.(*tp_pb.TechProfileInstance)) |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 688 | Direction = "downstream" |
| 689 | } |
| 690 | |
| Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 691 | TrafficShaping := &tp_pb.TrafficShapingInfo{} // this info is not really useful for the agent during flow removal. Just use default values. |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 692 | |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 693 | trafficSched := f.techprofile.GetTrafficScheduler(sq.tpInst.(*tp_pb.TechProfileInstance), SchedCfg, TrafficShaping) |
| 694 | trafficSched.TechProfileId = sq.tpID |
| 695 | TrafficSched := []*tp_pb.TrafficScheduler{trafficSched} |
| Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 696 | |
| bseeniva | a162211 | 2025-12-11 18:24:02 +0530 | [diff] [blame] | 697 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), f.deviceHandler.cfg.RPCTimeout) |
| 698 | if _, err = f.deviceHandler.Client.RemoveTrafficSchedulers(subCtx, &tp_pb.TrafficSchedulers{ |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 699 | IntfId: sq.intfID, OnuId: sq.onuID, |
| 700 | UniId: sq.uniID, PortNo: sq.uniPort, |
| 701 | TrafficScheds: TrafficSched}); err != nil { |
| bseeniva | a162211 | 2025-12-11 18:24:02 +0530 | [diff] [blame] | 702 | cancel() |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 703 | return olterrors.NewErrAdapter("unable-to-remove-traffic-schedulers-from-device", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 704 | log.Fields{ |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 705 | "intf-id": sq.intfID, |
| 706 | "traffic-schedulers": TrafficSched, |
| 707 | "onu-id": sq.onuID, |
| 708 | "uni-id": sq.uniID, |
| 709 | "uni-port": sq.uniPort}, err) |
| Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 710 | } |
| bseeniva | a162211 | 2025-12-11 18:24:02 +0530 | [diff] [blame] | 711 | cancel() |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 712 | logger.Infow(ctx, "removed-traffic-schedulers-successfully", |
| 713 | log.Fields{"device-id": f.deviceHandler.device.Id, |
| 714 | "intf-id": sq.intfID, |
| 715 | "onu-id": sq.onuID, |
| 716 | "uni-id": sq.uniID, |
| 717 | "uni-port": sq.uniPort}) |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 718 | |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 719 | if sq.direction == tp_pb.Direction_UPSTREAM { |
| 720 | allocID := sq.tpInst.(*tp_pb.TechProfileInstance).UsScheduler.AllocId |
| 721 | // Delete the TCONT on the ONU. |
| 722 | uni := getUniPortPath(f.deviceHandler.device.Id, sq.intfID, int32(sq.onuID), int32(sq.uniID)) |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 723 | tpPath := f.getTPpath(ctx, uni, sq.tpID) |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 724 | if err = f.sendDeleteTcontToChild(ctx, sq.intfID, sq.onuID, sq.uniID, allocID, tpPath); err != nil { |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 725 | logger.Errorw(ctx, "error-processing-delete-tcont-towards-onu", |
| Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 726 | log.Fields{ |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 727 | "intf": sq.intfID, |
| 728 | "onu-id": sq.onuID, |
| 729 | "uni-id": sq.uniID, |
| 730 | "device-id": f.deviceHandler.device.Id, |
| 731 | "alloc-id": allocID}) |
| Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 732 | } |
| 733 | } |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 734 | |
| 735 | /* After we successfully remove the scheduler configuration on the OLT device, |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 736 | * delete the meter id on the KV store. |
| 737 | */ |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 738 | err = f.removeMeterReference(ctx, Direction, sq) |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 739 | return err |
| 740 | } |
| 741 | |
| Girish Gowdra | 197acc1 | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 742 | // We are trying to force remove the schedulers and queues here if one exists for the given key. |
| 743 | // We ignore any errors encountered in the process. The errors most likely are encountered when |
| 744 | // the schedulers and queues are already cleared for the given key. |
| 745 | func (f *OpenOltFlowMgr) forceRemoveSchedulerQueues(ctx context.Context, sq schedQueue) { |
| Girish Gowdra | 197acc1 | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 746 | var schedCfg *tp_pb.SchedulerConfig |
| Girish Gowdra | 197acc1 | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 747 | logger.Infow(ctx, "removing-schedulers-and-queues-in-olt", |
| 748 | log.Fields{ |
| 749 | "direction": sq.direction, |
| 750 | "intf-id": sq.intfID, |
| 751 | "onu-id": sq.onuID, |
| 752 | "uni-id": sq.uniID, |
| 753 | "uni-port": sq.uniPort, |
| 754 | "tp-id": sq.tpID, |
| 755 | "device-id": f.deviceHandler.device.Id}) |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 756 | switch sq.direction { |
| 757 | case tp_pb.Direction_UPSTREAM: |
| Girish Gowdra | 197acc1 | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 758 | schedCfg = f.techprofile.GetUsScheduler(sq.tpInst.(*tp_pb.TechProfileInstance)) |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 759 | case tp_pb.Direction_DOWNSTREAM: |
| Girish Gowdra | 197acc1 | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 760 | schedCfg = f.techprofile.GetDsScheduler(sq.tpInst.(*tp_pb.TechProfileInstance)) |
| 761 | } |
| 762 | |
| 763 | TrafficShaping := &tp_pb.TrafficShapingInfo{} // this info is not really useful for the agent during flow removal. Just use default values. |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 764 | trafficSched := f.techprofile.GetTrafficScheduler(sq.tpInst.(*tp_pb.TechProfileInstance), schedCfg, TrafficShaping) |
| 765 | trafficSched.TechProfileId = sq.tpID |
| 766 | TrafficSched := []*tp_pb.TrafficScheduler{trafficSched} |
| Girish Gowdra | 197acc1 | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 767 | |
| 768 | // Remove traffic queues. Ignore any errors, just log them. |
| 769 | if TrafficQueues, err := f.techprofile.GetTrafficQueues(ctx, sq.tpInst.(*tp_pb.TechProfileInstance), sq.direction); err != nil { |
| 770 | logger.Errorw(ctx, "error retrieving traffic queue", log.Fields{ |
| 771 | "direction": sq.direction, |
| 772 | "intf-id": sq.intfID, |
| 773 | "onu-id": sq.onuID, |
| 774 | "uni-id": sq.uniID, |
| 775 | "uni-port": sq.uniPort, |
| 776 | "tp-id": sq.tpID, |
| 777 | "device-id": f.deviceHandler.device.Id, |
| 778 | "err": err}) |
| 779 | } else { |
| bseeniva | a162211 | 2025-12-11 18:24:02 +0530 | [diff] [blame] | 780 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), f.deviceHandler.cfg.RPCTimeout) |
| 781 | if _, err := f.deviceHandler.Client.RemoveTrafficQueues(subCtx, |
| Girish Gowdra | 197acc1 | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 782 | &tp_pb.TrafficQueues{IntfId: sq.intfID, OnuId: sq.onuID, |
| 783 | UniId: sq.uniID, PortNo: sq.uniPort, |
| 784 | TrafficQueues: TrafficQueues, |
| 785 | TechProfileId: TrafficSched[0].TechProfileId}); err != nil { |
| 786 | logger.Warnw(ctx, "error removing traffic queue", log.Fields{ |
| 787 | "direction": sq.direction, |
| 788 | "intf-id": sq.intfID, |
| 789 | "onu-id": sq.onuID, |
| 790 | "uni-id": sq.uniID, |
| 791 | "uni-port": sq.uniPort, |
| 792 | "tp-id": sq.tpID, |
| 793 | "device-id": f.deviceHandler.device.Id, |
| 794 | "err": err}) |
| Girish Gowdra | 197acc1 | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 795 | } else { |
| balaji.nagarajan | 31db4ea | 2026-01-28 09:13:55 +0530 | [diff] [blame] | 796 | logger.Debugw(ctx, "removed-traffic-queues-successfully", log.Fields{"device-id": f.deviceHandler.device.Id, |
| Girish Gowdra | 197acc1 | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 797 | "direction": sq.direction, |
| 798 | "intf-id": sq.intfID, |
| 799 | "onu-id": sq.onuID, |
| 800 | "uni-id": sq.uniID, |
| 801 | "uni-port": sq.uniPort, |
| 802 | "tp-id": sq.tpID}) |
| 803 | } |
| bseeniva | a162211 | 2025-12-11 18:24:02 +0530 | [diff] [blame] | 804 | cancel() |
| Girish Gowdra | 197acc1 | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 805 | } |
| 806 | |
| bseeniva | a162211 | 2025-12-11 18:24:02 +0530 | [diff] [blame] | 807 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), f.deviceHandler.cfg.RPCTimeout) |
| Girish Gowdra | 197acc1 | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 808 | // Remove traffic schedulers. Ignore any errors, just log them. |
| bseeniva | a162211 | 2025-12-11 18:24:02 +0530 | [diff] [blame] | 809 | if _, err := f.deviceHandler.Client.RemoveTrafficSchedulers(subCtx, &tp_pb.TrafficSchedulers{ |
| Girish Gowdra | 197acc1 | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 810 | IntfId: sq.intfID, OnuId: sq.onuID, |
| 811 | UniId: sq.uniID, PortNo: sq.uniPort, |
| 812 | TrafficScheds: TrafficSched}); err != nil { |
| 813 | logger.Warnw(ctx, "error removing traffic scheduler", log.Fields{ |
| 814 | "direction": sq.direction, |
| 815 | "intf-id": sq.intfID, |
| 816 | "onu-id": sq.onuID, |
| 817 | "uni-id": sq.uniID, |
| 818 | "uni-port": sq.uniPort, |
| 819 | "tp-id": sq.tpID, |
| 820 | "device-id": f.deviceHandler.device.Id, |
| 821 | "err": err}) |
| 822 | } else { |
| balaji.nagarajan | 31db4ea | 2026-01-28 09:13:55 +0530 | [diff] [blame] | 823 | logger.Debugw(ctx, "removed-traffic-schedulers-successfully", log.Fields{"device-id": f.deviceHandler.device.Id, |
| Girish Gowdra | 197acc1 | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 824 | "direction": sq.direction, |
| 825 | "intf-id": sq.intfID, |
| 826 | "onu-id": sq.onuID, |
| 827 | "uni-id": sq.uniID, |
| 828 | "uni-port": sq.uniPort, |
| 829 | "tp-id": sq.tpID}) |
| 830 | } |
| bseeniva | a162211 | 2025-12-11 18:24:02 +0530 | [diff] [blame] | 831 | cancel() |
| Girish Gowdra | 197acc1 | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 832 | } |
| 833 | |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 834 | // This function allocates tconts and GEM ports for an ONU |
| Sridhar Ravindra | d104e8d | 2025-06-02 13:04:49 +0530 | [diff] [blame] | 835 | func (f *OpenOltFlowMgr) createTcontGemports(ctx context.Context, intfID uint32, nniIntfID uint32, onuID uint32, uniID uint32, uni string, uniPort uint32, TpID uint32, UsMeterID uint32, DsMeterID uint32, flowMetadata *ofp.FlowMetadata) (uint32, []uint32, interface{}) { |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 836 | var allocIDs []uint32 |
| 837 | var allgemPortIDs []uint32 |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 838 | var gemPortIDs []uint32 |
| Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 839 | tpInstanceExists := false |
| Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 840 | var err error |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 841 | allocIDs = f.resourceMgr.GetCurrentAllocIDsForOnu(ctx, onuID, uniID) |
| 842 | allgemPortIDs = f.resourceMgr.GetCurrentGEMPortIDsForOnu(ctx, onuID, uniID) |
| 843 | tpPath := f.getTPpath(ctx, uni, TpID) |
| Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 844 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 845 | logger.Debugw(ctx, "creating-new-tcont-and-gem", log.Fields{ |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 846 | "intf-id": intfID, |
| 847 | "onu-id": onuID, |
| 848 | "uni-id": uniID, |
| 849 | "device-id": f.deviceHandler.device.Id, |
| 850 | "tp-id": TpID}) |
| Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 851 | |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 852 | // Check tech profile instance already exists for derived port name |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 853 | techProfileInstance, _ := f.techprofile.GetTPInstance(ctx, tpPath) |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 854 | if techProfileInstance == nil { |
| balaji.nagarajan | 31db4ea | 2026-01-28 09:13:55 +0530 | [diff] [blame] | 855 | logger.Debugw(ctx, "tp-instance-not-found--creating-new", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 856 | log.Fields{ |
| 857 | "path": tpPath, |
| 858 | "device-id": f.deviceHandler.device.Id}) |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 859 | techProfileInstance, err = f.techprofile.CreateTechProfileInstance(ctx, TpID, uni, intfID) |
| Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 860 | if err != nil { |
| Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 861 | // This should not happen, something wrong in KV backend transaction |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 862 | logger.Errorw(ctx, "tp-instance-create-failed", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 863 | log.Fields{ |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 864 | "err": err, |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 865 | "tp-id": TpID, |
| 866 | "device-id": f.deviceHandler.device.Id}) |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 867 | return 0, nil, nil |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 868 | } |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 869 | if err := f.resourceMgr.UpdateTechProfileIDForOnu(ctx, onuID, uniID, TpID); err != nil { |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 870 | logger.Warnw(ctx, "failed-to-update-tech-profile-id", log.Fields{"err": err}) |
| Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 871 | } |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 872 | } else { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 873 | logger.Debugw(ctx, "tech-profile-instance-already-exist-for-given port-name", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 874 | log.Fields{ |
| 875 | "uni": uni, |
| 876 | "device-id": f.deviceHandler.device.Id}) |
| Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 877 | tpInstanceExists = true |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 878 | } |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 879 | |
| Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 880 | switch tpInst := techProfileInstance.(type) { |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 881 | case *tp_pb.TechProfileInstance: |
| Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 882 | if UsMeterID != 0 { |
| Sridhar Ravindra | d104e8d | 2025-06-02 13:04:49 +0530 | [diff] [blame] | 883 | sq := schedQueue{direction: tp_pb.Direction_UPSTREAM, intfID: intfID, nniIntfID: nniIntfID, onuID: onuID, uniID: uniID, tpID: TpID, |
| Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 884 | uniPort: uniPort, tpInst: techProfileInstance, meterID: UsMeterID, flowMetadata: flowMetadata} |
| 885 | if err := f.CreateSchedulerQueues(ctx, sq); err != nil { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 886 | logger.Errorw(ctx, "CreateSchedulerQueues-failed-upstream", |
| Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 887 | log.Fields{ |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 888 | "err": err, |
| Matteo Scandolo | 2f6b5bc | 2020-09-17 13:58:10 -0700 | [diff] [blame] | 889 | "onu-id": onuID, |
| 890 | "uni-id": uniID, |
| 891 | "intf-id": intfID, |
| Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 892 | "meter-id": UsMeterID, |
| 893 | "device-id": f.deviceHandler.device.Id}) |
| Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 894 | f.revertTechProfileInstance(ctx, sq) |
| Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 895 | return 0, nil, nil |
| 896 | } |
| 897 | } |
| 898 | if DsMeterID != 0 { |
| Sridhar Ravindra | d104e8d | 2025-06-02 13:04:49 +0530 | [diff] [blame] | 899 | sq := schedQueue{direction: tp_pb.Direction_DOWNSTREAM, intfID: intfID, nniIntfID: nniIntfID, onuID: onuID, uniID: uniID, tpID: TpID, |
| Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 900 | uniPort: uniPort, tpInst: techProfileInstance, meterID: DsMeterID, flowMetadata: flowMetadata} |
| 901 | if err := f.CreateSchedulerQueues(ctx, sq); err != nil { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 902 | logger.Errorw(ctx, "CreateSchedulerQueues-failed-downstream", |
| Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 903 | log.Fields{ |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 904 | "err": err, |
| Matteo Scandolo | 2f6b5bc | 2020-09-17 13:58:10 -0700 | [diff] [blame] | 905 | "onu-id": onuID, |
| 906 | "uni-id": uniID, |
| 907 | "intf-id": intfID, |
| Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 908 | "meter-id": DsMeterID, |
| 909 | "device-id": f.deviceHandler.device.Id}) |
| Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 910 | f.revertTechProfileInstance(ctx, sq) |
| Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 911 | return 0, nil, nil |
| 912 | } |
| 913 | } |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 914 | allocID := tpInst.UsScheduler.AllocId |
| Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 915 | for _, gem := range tpInst.UpstreamGemPortAttributeList { |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 916 | gemPortIDs = append(gemPortIDs, gem.GemportId) |
| Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 917 | } |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 918 | allocIDs = appendUnique32bit(allocIDs, allocID) |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 919 | |
| Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 920 | if tpInstanceExists { |
| 921 | return allocID, gemPortIDs, techProfileInstance |
| 922 | } |
| 923 | |
| 924 | for _, gemPortID := range gemPortIDs { |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 925 | allgemPortIDs = appendUnique32bit(allgemPortIDs, gemPortID) |
| Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 926 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 927 | logger.Infow(ctx, "allocated-tcont-and-gem-ports", |
| Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 928 | log.Fields{ |
| Matteo Scandolo | 8458537 | 2021-03-18 14:21:22 -0700 | [diff] [blame] | 929 | "intf-id": intfID, |
| 930 | "onu-id": onuID, |
| 931 | "uni-id": uniID, |
| Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 932 | "alloc-ids": allocIDs, |
| 933 | "gemports": allgemPortIDs, |
| 934 | "device-id": f.deviceHandler.device.Id}) |
| 935 | // Send Tconts and GEM ports to KV store |
| 936 | f.storeTcontsGEMPortsIntoKVStore(ctx, intfID, onuID, uniID, allocIDs, allgemPortIDs) |
| Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 937 | return allocID, gemPortIDs, techProfileInstance |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 938 | case *tp_pb.EponTechProfileInstance: |
| Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 939 | // CreateSchedulerQueues for EPON needs to be implemented here |
| 940 | // when voltha-protos for EPON is completed. |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 941 | allocID := tpInst.AllocId |
| Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 942 | for _, gem := range tpInst.UpstreamQueueAttributeList { |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 943 | gemPortIDs = append(gemPortIDs, gem.GemportId) |
| Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 944 | } |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 945 | allocIDs = appendUnique32bit(allocIDs, allocID) |
| Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 946 | |
| 947 | if tpInstanceExists { |
| 948 | return allocID, gemPortIDs, techProfileInstance |
| 949 | } |
| 950 | |
| 951 | for _, gemPortID := range gemPortIDs { |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 952 | allgemPortIDs = appendUnique32bit(allgemPortIDs, gemPortID) |
| Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 953 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 954 | logger.Infow(ctx, "allocated-tcont-and-gem-ports", |
| Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 955 | log.Fields{ |
| 956 | "alloc-ids": allocIDs, |
| 957 | "gemports": allgemPortIDs, |
| 958 | "device-id": f.deviceHandler.device.Id}) |
| 959 | // Send Tconts and GEM ports to KV store |
| 960 | f.storeTcontsGEMPortsIntoKVStore(ctx, intfID, onuID, uniID, allocIDs, allgemPortIDs) |
| 961 | return allocID, gemPortIDs, techProfileInstance |
| 962 | default: |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 963 | logger.Errorw(ctx, "unknown-tech", |
| Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 964 | log.Fields{ |
| 965 | "tpInst": tpInst}) |
| 966 | return 0, nil, nil |
| Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 967 | } |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 968 | } |
| 969 | |
| npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 970 | func (f *OpenOltFlowMgr) storeTcontsGEMPortsIntoKVStore(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, allocID []uint32, gemPortIDs []uint32) { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 971 | logger.Debugw(ctx, "storing-allocated-tconts-and-gem-ports-into-KV-store", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 972 | log.Fields{ |
| 973 | "intf-id": intfID, |
| 974 | "onu-id": onuID, |
| 975 | "uni-id": uniID, |
| 976 | "alloc-id": allocID, |
| 977 | "gemport-ids": gemPortIDs, |
| 978 | "device-id": f.deviceHandler.device.Id}) |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 979 | /* Update the allocated alloc_id and gem_port_id for the ONU/UNI to KV store */ |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 980 | if err := f.resourceMgr.UpdateAllocIdsForOnu(ctx, onuID, uniID, allocID); err != nil { |
| yasin sapli | 9e4c509 | 2022-02-01 13:52:33 +0000 | [diff] [blame] | 981 | logger.Errorw(ctx, "error-while-uploading-allocid-to-kv-store", log.Fields{"device-id": f.deviceHandler.device.Id, "onuID": onuID, "allocID": allocID}) |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 982 | } |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 983 | if err := f.resourceMgr.UpdateGEMPortIDsForOnu(ctx, onuID, uniID, gemPortIDs); err != nil { |
| yasin sapli | 9e4c509 | 2022-02-01 13:52:33 +0000 | [diff] [blame] | 984 | logger.Errorw(ctx, "error-while-uploading-gemports-to-kv-store", log.Fields{"device-id": f.deviceHandler.device.Id, "onuID": onuID, "gemPort": gemPortIDs}) |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 985 | } |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 986 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 987 | logger.Infow(ctx, "stored-tconts-and-gem-into-kv-store-successfully", log.Fields{"device-id": f.deviceHandler.device.Id}) |
| balaji.nagarajan | 29be8bc | 2026-01-26 16:31:41 +0530 | [diff] [blame] | 988 | if err := f.resourceMgr.AddGemToOnuGemInfo(ctx, onuID, gemPortIDs); err != nil { |
| 989 | logger.Errorw(ctx, "error-while-uploading-onugeminfos-to-kv-store", log.Fields{"device-id": f.deviceHandler.device.Id, "onuID": onuID, "gemPort": gemPortIDs}) |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 990 | } |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 991 | } |
| 992 | |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 993 | func (f *OpenOltFlowMgr) populateTechProfileForCurrentPonPort(ctx context.Context) error { |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 994 | for _, techRange := range f.resourceMgr.DevInfo.Ranges { |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 995 | for _, intfID := range techRange.IntfIds { |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 996 | if intfID == f.ponPortIdx { // initialize only for the pon port that this flow manager is managing |
| 997 | var err error |
| pnalmas | 937a24d | 2025-01-16 18:48:30 +0530 | [diff] [blame] | 998 | f.techprofile, err = tp.NewTechProfile(ctx, intfID, f.resourceMgr.DeviceID, f.resourceMgr.PonRsrMgr, f.resourceMgr.PonRsrMgr.Backend, |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 999 | f.resourceMgr.PonRsrMgr.Address, f.deviceHandler.cm.Backend.PathPrefix) |
| 1000 | if err != nil || f.techprofile == nil { |
| 1001 | logger.Errorw(ctx, "failed-to-allocate-to-techprofile-for-pon-port", log.Fields{"intfID": intfID, "err": err}) |
| 1002 | return fmt.Errorf("failed-to-allocate-tech-profile-for-pon-port--pon-%v-err-%v", intfID, err) |
| 1003 | } |
| 1004 | logger.Debugw(ctx, "init-tech-profile-done", |
| 1005 | log.Fields{ |
| 1006 | "intf-id": intfID, |
| 1007 | "device-id": f.deviceHandler.device.Id}) |
| 1008 | return nil |
| Girish Gowdra | 4c3d460 | 2021-07-22 16:33:37 -0700 | [diff] [blame] | 1009 | } |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1010 | } |
| 1011 | } |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 1012 | logger.Errorw(ctx, "pon port not found in the the device pon port range", log.Fields{"intfID": f.ponPortIdx}) |
| 1013 | return fmt.Errorf("pon-port-idx-not-found-in-the-device-info-pon-port-range-%v", f.ponPortIdx) |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1014 | } |
| 1015 | |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1016 | func (f *OpenOltFlowMgr) addUpstreamDataPathFlow(ctx context.Context, flowContext *flowContext) error { |
| Girish Gowdra | ffa52e5 | 2022-02-16 15:48:10 -0800 | [diff] [blame] | 1017 | flowContext.classifier[PacketTagType] = SingleTag |
| 1018 | // extract the cvid/inner-vid from the write metadata |
| 1019 | writeMetadata := flows.GetMetadataFromWriteMetadataAction(ctx, flowContext.logicalFlow) |
| 1020 | if writeMetadata != 0 { |
| 1021 | // Writemetadata field is 8 bytes |
| 1022 | // cvid is on the outer most two bytes of the write metadata |
| 1023 | cvid := (writeMetadata & 0xffff000000000000) >> 48 |
| 1024 | // if the cvid does not match the classifier vlan, then this indicates it is a double tagged packet |
| 1025 | if cvid != flowContext.classifier[VlanVid] && cvid != 0 { |
| 1026 | flowContext.classifier[PacketTagType] = DoubleTag |
| 1027 | } |
| 1028 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1029 | logger.Debugw(ctx, "adding-upstream-data-flow", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1030 | log.Fields{ |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1031 | "uplinkClassifier": flowContext.classifier, |
| 1032 | "uplinkAction": flowContext.action}) |
| 1033 | return f.addSymmetricDataPathFlow(ctx, flowContext, Upstream) |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1034 | } |
| 1035 | |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1036 | func (f *OpenOltFlowMgr) addDownstreamDataPathFlow(ctx context.Context, flowContext *flowContext) error { |
| 1037 | downlinkClassifier := flowContext.classifier |
| 1038 | downlinkAction := flowContext.action |
| Girish Gowdra | ffa52e5 | 2022-02-16 15:48:10 -0800 | [diff] [blame] | 1039 | // default to single tag. If we detect an inner cvid from write-metadata, then we mark the PacketTagType as DoubleTag |
| 1040 | downlinkClassifier[PacketTagType] = SingleTag |
| 1041 | // extract the cvid/inner-vid from the write metadata |
| 1042 | writeMetadata := flows.GetMetadataFromWriteMetadataAction(ctx, flowContext.logicalFlow) |
| 1043 | if writeMetadata != 0 { |
| 1044 | // Writemetadata field is 8 bytes |
| 1045 | // cvid is on the outer most two bytes of the write metadata |
| 1046 | if cvid := (writeMetadata & 0xffff000000000000) >> 48; cvid != 0 { |
| 1047 | downlinkClassifier[PacketTagType] = DoubleTag |
| 1048 | } |
| Andrea Campanella | faa4215 | 2021-10-28 11:50:56 +0530 | [diff] [blame] | 1049 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1050 | logger.Debugw(ctx, "adding-downstream-data-flow", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1051 | log.Fields{ |
| 1052 | "downlinkClassifier": downlinkClassifier, |
| 1053 | "downlinkAction": downlinkAction}) |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1054 | |
| Girish Gowdra | ffa52e5 | 2022-02-16 15:48:10 -0800 | [diff] [blame] | 1055 | // If Pop Vlan action is specified, set the vlan to be popped from the classifier vlan match field. |
| 1056 | // The matched vlan is the one that is getting popped. |
| 1057 | if val, ok := downlinkAction[PopVlan]; ok && val.(bool) { |
| 1058 | // vlan_vid is a uint32. must be type asserted as such or conversion fails |
| 1059 | dlClVid, ok := downlinkClassifier[VlanVid].(uint32) |
| 1060 | if ok { |
| 1061 | downlinkAction[VlanVid] = dlClVid & 0xfff |
| 1062 | } |
| Girish Gowdra | 26f344b | 2019-10-23 14:39:13 +0530 | [diff] [blame] | 1063 | } |
| 1064 | |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1065 | return f.addSymmetricDataPathFlow(ctx, flowContext, Downstream) |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1066 | } |
| 1067 | |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1068 | func (f *OpenOltFlowMgr) addSymmetricDataPathFlow(ctx context.Context, flowContext *flowContext, direction string) error { |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1069 | intfID := flowContext.intfID |
| 1070 | onuID := flowContext.onuID |
| 1071 | uniID := flowContext.uniID |
| 1072 | classifier := flowContext.classifier |
| 1073 | action := flowContext.action |
| 1074 | allocID := flowContext.allocID |
| 1075 | gemPortID := flowContext.gemPortID |
| 1076 | tpID := flowContext.tpID |
| 1077 | logicalFlow := flowContext.logicalFlow |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1078 | logger.Infow(ctx, "adding-hsia-flow", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1079 | log.Fields{ |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 1080 | "intf-id": intfID, |
| 1081 | "onu-id": onuID, |
| 1082 | "uni-id": uniID, |
| 1083 | "device-id": f.deviceHandler.device.Id, |
| 1084 | "classifier": classifier, |
| 1085 | "action": action, |
| 1086 | "direction": direction, |
| 1087 | "alloc-id": allocID, |
| 1088 | "gemport-id": gemPortID, |
| 1089 | "flow-id": logicalFlow.Id}) |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1090 | |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 1091 | present, err := f.resourceMgr.IsFlowOnKvStore(ctx, int32(onuID), logicalFlow.Id) |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1092 | if present { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1093 | logger.Infow(ctx, "flow-already-exists", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1094 | log.Fields{ |
| 1095 | "device-id": f.deviceHandler.device.Id, |
| 1096 | "intf-id": intfID, |
| 1097 | "onu-id": onuID}) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1098 | return nil |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1099 | } else if err != nil { |
| 1100 | logger.Errorw(ctx, "aborting-addSymmetricDataPathFlow--flow-may-already-exist", |
| 1101 | log.Fields{"intf-id": intfID, "onu-id": onuID, "flow-id": logicalFlow.Id}) |
| 1102 | return err |
| Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1103 | } |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1104 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1105 | classifierProto, err := makeOpenOltClassifierField(classifier) |
| 1106 | if err != nil { |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1107 | return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifier, "device-id": f.deviceHandler.device.Id}, err).Log() |
| Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1108 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1109 | logger.Debugw(ctx, "created-classifier-proto", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1110 | log.Fields{ |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 1111 | "classifier": classifierProto.String(), |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1112 | "device-id": f.deviceHandler.device.Id}) |
| Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1113 | actionProto, err := makeOpenOltActionField(action, classifier) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1114 | if err != nil { |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1115 | return olterrors.NewErrInvalidValue(log.Fields{"action": action, "device-id": f.deviceHandler.device.Id}, err).Log() |
| Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1116 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1117 | logger.Debugw(ctx, "created-action-proto", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1118 | log.Fields{ |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 1119 | "action": actionProto.String(), |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1120 | "device-id": f.deviceHandler.device.Id}) |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1121 | networkIntfID, err := getNniIntfID(ctx, classifier, action) |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1122 | if err != nil { |
| Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1123 | return olterrors.NewErrNotFound("nni-interface-id", |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1124 | log.Fields{ |
| 1125 | "classifier": classifier, |
| 1126 | "action": action, |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1127 | "device-id": f.deviceHandler.device.Id, |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1128 | }, err).Log() |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1129 | } |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1130 | |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1131 | flow := openoltpb2.Flow{AccessIntfId: int32(intfID), |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1132 | OnuId: int32(onuID), |
| 1133 | UniId: int32(uniID), |
| 1134 | FlowId: logicalFlow.Id, |
| 1135 | FlowType: direction, |
| 1136 | AllocId: int32(allocID), |
| 1137 | NetworkIntfId: int32(networkIntfID), |
| 1138 | GemportId: int32(gemPortID), |
| 1139 | Classifier: classifierProto, |
| 1140 | Action: actionProto, |
| 1141 | Priority: int32(logicalFlow.Priority), |
| 1142 | Cookie: logicalFlow.Cookie, |
| 1143 | PortNo: flowContext.portNo, |
| 1144 | TechProfileId: tpID, |
| 1145 | ReplicateFlow: len(flowContext.pbitToGem) > 0, |
| 1146 | PbitToGemport: flowContext.pbitToGem, |
| 1147 | GemportToAes: flowContext.gemToAes, |
| Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1148 | } |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1149 | if err := f.addFlowToDevice(ctx, logicalFlow, &flow); err != nil { |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1150 | return olterrors.NewErrFlowOp("add", logicalFlow.Id, nil, err).Log() |
| Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1151 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1152 | logger.Infow(ctx, "hsia-flow-added-to-device-successfully", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1153 | log.Fields{"direction": direction, |
| 1154 | "device-id": f.deviceHandler.device.Id, |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 1155 | "flow-id": flow.FlowId, |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1156 | "intf-id": intfID, |
| 1157 | "onu-id": onuID}) |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1158 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1159 | return nil |
| Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1160 | } |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1161 | |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1162 | func (f *OpenOltFlowMgr) addDHCPTrapFlow(ctx context.Context, flowContext *flowContext) error { |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1163 | intfID := flowContext.intfID |
| 1164 | onuID := flowContext.onuID |
| 1165 | uniID := flowContext.uniID |
| 1166 | logicalFlow := flowContext.logicalFlow |
| 1167 | classifier := flowContext.classifier |
| 1168 | action := flowContext.action |
| Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1169 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1170 | networkIntfID, err := getNniIntfID(ctx, classifier, action) |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1171 | if err != nil { |
| Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1172 | return olterrors.NewErrNotFound("nni-interface-id", log.Fields{ |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1173 | "classifier": classifier, |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1174 | "action": action, |
| 1175 | "device-id": f.deviceHandler.device.Id}, |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1176 | err).Log() |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1177 | } |
| Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1178 | |
| 1179 | // Clear the action map |
| 1180 | for k := range action { |
| 1181 | delete(action, k) |
| 1182 | } |
| 1183 | |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1184 | action[TrapToHost] = true |
| 1185 | classifier[UDPSrc] = uint32(68) |
| 1186 | classifier[UDPDst] = uint32(67) |
| 1187 | classifier[PacketTagType] = SingleTag |
| Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1188 | |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 1189 | present, err := f.resourceMgr.IsFlowOnKvStore(ctx, int32(onuID), logicalFlow.Id) |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1190 | if present { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1191 | logger.Infow(ctx, "flow-exists--not-re-adding", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1192 | log.Fields{ |
| 1193 | "device-id": f.deviceHandler.device.Id, |
| 1194 | "intf-id": intfID, |
| 1195 | "onu-id": onuID}) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1196 | return nil |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1197 | } else if err != nil { |
| 1198 | logger.Errorw(ctx, "aborting-addDHCPTrapFlow--flow-may-already-exist", |
| 1199 | log.Fields{"intf-id": intfID, "onu-id": onuID, "flow-id": logicalFlow.Id}) |
| 1200 | return err |
| Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1201 | } |
| Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1202 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1203 | logger.Debugw(ctx, "creating-ul-dhcp-flow", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1204 | log.Fields{ |
| 1205 | "ul_classifier": classifier, |
| 1206 | "ul_action": action, |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1207 | "uplinkFlowId": logicalFlow.Id, |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1208 | "intf-id": intfID, |
| 1209 | "onu-id": onuID, |
| 1210 | "device-id": f.deviceHandler.device.Id}) |
| Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1211 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1212 | classifierProto, err := makeOpenOltClassifierField(classifier) |
| 1213 | if err != nil { |
| Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1214 | return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifier}, err).Log() |
| Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1215 | } |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 1216 | logger.Debugw(ctx, "created-classifier-proto", log.Fields{"classifier": classifierProto.String()}) |
| Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1217 | actionProto, err := makeOpenOltActionField(action, classifier) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1218 | if err != nil { |
| Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1219 | return olterrors.NewErrInvalidValue(log.Fields{"action": action}, err).Log() |
| Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1220 | } |
| 1221 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1222 | dhcpFlow := openoltpb2.Flow{AccessIntfId: int32(intfID), |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1223 | OnuId: int32(onuID), |
| 1224 | UniId: int32(uniID), |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1225 | FlowId: logicalFlow.Id, |
| David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1226 | FlowType: Upstream, |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1227 | AllocId: int32(flowContext.allocID), |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1228 | NetworkIntfId: int32(networkIntfID), |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1229 | GemportId: int32(flowContext.gemPortID), |
| Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1230 | Classifier: classifierProto, |
| 1231 | Action: actionProto, |
| 1232 | Priority: int32(logicalFlow.Priority), |
| 1233 | Cookie: logicalFlow.Cookie, |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1234 | PortNo: flowContext.portNo, |
| 1235 | TechProfileId: flowContext.tpID, |
| 1236 | ReplicateFlow: len(flowContext.pbitToGem) > 0, |
| 1237 | PbitToGemport: flowContext.pbitToGem, |
| 1238 | GemportToAes: flowContext.gemToAes, |
| Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1239 | } |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1240 | if err := f.addFlowToDevice(ctx, logicalFlow, &dhcpFlow); err != nil { |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 1241 | return olterrors.NewErrFlowOp("add", logicalFlow.Id, log.Fields{"dhcp-flow-id": dhcpFlow.FlowId}, err).Log() |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1242 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1243 | logger.Infow(ctx, "dhcp-ul-flow-added-to-device-successfully", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1244 | log.Fields{ |
| 1245 | "device-id": f.deviceHandler.device.Id, |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1246 | "flow-id": logicalFlow.Id, |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1247 | "intf-id": intfID, |
| 1248 | "onu-id": onuID}) |
| Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1249 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1250 | return nil |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1251 | } |
| 1252 | |
| Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 1253 | // addIGMPTrapFlow creates IGMP trap-to-host flow |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1254 | func (f *OpenOltFlowMgr) addIGMPTrapFlow(ctx context.Context, flowContext *flowContext) error { |
| 1255 | delete(flowContext.classifier, VlanVid) |
| 1256 | return f.addUpstreamTrapFlow(ctx, flowContext) |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1257 | } |
| 1258 | |
| Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 1259 | // addUpstreamTrapFlow creates a trap-to-host flow |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1260 | func (f *OpenOltFlowMgr) addUpstreamTrapFlow(ctx context.Context, flowContext *flowContext) error { |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1261 | intfID := flowContext.intfID |
| 1262 | onuID := flowContext.onuID |
| 1263 | uniID := flowContext.uniID |
| 1264 | logicalFlow := flowContext.logicalFlow |
| 1265 | classifier := flowContext.classifier |
| 1266 | action := flowContext.action |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1267 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1268 | networkIntfID, err := getNniIntfID(ctx, classifier, action) |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1269 | if err != nil { |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1270 | return olterrors.NewErrNotFound("nni-interface-id", |
| 1271 | log.Fields{ |
| 1272 | "classifier": classifier, |
| 1273 | "action": action, |
| 1274 | "device-id": f.deviceHandler.device.Id}, |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1275 | err).Log() |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | // Clear the action map |
| 1279 | for k := range action { |
| 1280 | delete(action, k) |
| 1281 | } |
| 1282 | |
| 1283 | action[TrapToHost] = true |
| 1284 | classifier[PacketTagType] = SingleTag |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1285 | |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 1286 | present, err := f.resourceMgr.IsFlowOnKvStore(ctx, int32(onuID), logicalFlow.Id) |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1287 | if present { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1288 | logger.Infow(ctx, "flow-exists-not-re-adding", log.Fields{"device-id": f.deviceHandler.device.Id}) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1289 | return nil |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1290 | } else if err != nil { |
| 1291 | logger.Errorw(ctx, "aborting-addUpstreamTrapFlow--flow-may-already-exist", |
| 1292 | log.Fields{"intf-id": intfID, "onu-id": onuID, "flow-id": logicalFlow.Id}) |
| 1293 | return err |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1294 | } |
| 1295 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1296 | logger.Debugw(ctx, "creating-upstream-trap-flow", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1297 | log.Fields{ |
| 1298 | "ul_classifier": classifier, |
| 1299 | "ul_action": action, |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1300 | "uplinkFlowId": logicalFlow.Id, |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1301 | "device-id": f.deviceHandler.device.Id, |
| 1302 | "intf-id": intfID, |
| 1303 | "onu-id": onuID}) |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1304 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1305 | classifierProto, err := makeOpenOltClassifierField(classifier) |
| 1306 | if err != nil { |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1307 | return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifier, "device-id": f.deviceHandler.device.Id}, err).Log() |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1308 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1309 | logger.Debugw(ctx, "created-classifier-proto", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1310 | log.Fields{ |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 1311 | "classifier": classifierProto.String(), |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1312 | "device-id": f.deviceHandler.device.Id}) |
| Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1313 | actionProto, err := makeOpenOltActionField(action, classifier) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1314 | if err != nil { |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1315 | return olterrors.NewErrInvalidValue(log.Fields{"action": action, "device-id": f.deviceHandler.device.Id}, err).Log() |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1316 | } |
| 1317 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1318 | flow := openoltpb2.Flow{AccessIntfId: int32(intfID), |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1319 | OnuId: int32(onuID), |
| 1320 | UniId: int32(uniID), |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1321 | FlowId: logicalFlow.Id, |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1322 | FlowType: Upstream, |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1323 | AllocId: int32(flowContext.allocID), |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1324 | NetworkIntfId: int32(networkIntfID), |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1325 | GemportId: int32(flowContext.gemPortID), |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1326 | Classifier: classifierProto, |
| 1327 | Action: actionProto, |
| 1328 | Priority: int32(logicalFlow.Priority), |
| 1329 | Cookie: logicalFlow.Cookie, |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1330 | PortNo: flowContext.portNo, |
| 1331 | TechProfileId: flowContext.tpID, |
| 1332 | ReplicateFlow: len(flowContext.pbitToGem) > 0, |
| 1333 | PbitToGemport: flowContext.pbitToGem, |
| 1334 | GemportToAes: flowContext.gemToAes, |
| Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1335 | } |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1336 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1337 | if err := f.addFlowToDevice(ctx, logicalFlow, &flow); err != nil { |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 1338 | return olterrors.NewErrFlowOp("add", logicalFlow.Id, log.Fields{"flow-id": flow.FlowId, "device-id": f.deviceHandler.device.Id}, err).Log() |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1339 | } |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1340 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1341 | return nil |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1342 | } |
| 1343 | |
| Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1344 | // Add EthType flow to device with mac, vlanId as classifier for upstream and downstream |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1345 | func (f *OpenOltFlowMgr) addEthTypeBasedFlow(ctx context.Context, flowContext *flowContext, vlanID uint32, ethType uint32) error { |
| 1346 | intfID := flowContext.intfID |
| 1347 | onuID := flowContext.onuID |
| 1348 | uniID := flowContext.uniID |
| 1349 | portNo := flowContext.portNo |
| 1350 | allocID := flowContext.allocID |
| 1351 | gemPortID := flowContext.gemPortID |
| 1352 | logicalFlow := flowContext.logicalFlow |
| 1353 | classifier := flowContext.classifier |
| 1354 | action := flowContext.action |
| 1355 | |
| Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1356 | logger.Infow(ctx, "adding-ethType-flow-to-device", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1357 | log.Fields{ |
| 1358 | "intf-id": intfID, |
| 1359 | "onu-id": onuID, |
| 1360 | "port-no": portNo, |
| 1361 | "alloc-id": allocID, |
| 1362 | "gemport-id": gemPortID, |
| 1363 | "vlan-id": vlanID, |
| Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1364 | "flow": logicalFlow, |
| 1365 | "ethType": ethType}) |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1366 | |
| 1367 | uplinkClassifier := make(map[string]interface{}) |
| 1368 | uplinkAction := make(map[string]interface{}) |
| Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1369 | |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1370 | // Fill Classfier |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1371 | uplinkClassifier[EthType] = ethType |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1372 | uplinkClassifier[PacketTagType] = SingleTag |
| 1373 | uplinkClassifier[VlanVid] = vlanID |
| Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1374 | uplinkClassifier[VlanPcp] = classifier[VlanPcp] |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1375 | // Fill action |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1376 | uplinkAction[TrapToHost] = true |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 1377 | present, err := f.resourceMgr.IsFlowOnKvStore(ctx, int32(onuID), logicalFlow.Id) |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1378 | if present { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1379 | logger.Infow(ctx, "flow-exists-not-re-adding", log.Fields{ |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1380 | "device-id": f.deviceHandler.device.Id, |
| 1381 | "onu-id": onuID, |
| Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1382 | "intf-id": intfID, |
| 1383 | "ethType": ethType}) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1384 | return nil |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1385 | } else if err != nil { |
| 1386 | logger.Errorw(ctx, "aborting-addEthTypeBasedFlow--flow-may-already-exist", |
| 1387 | log.Fields{"intf-id": intfID, "onu-id": onuID, "flow-id": logicalFlow.Id}) |
| 1388 | return err |
| Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1389 | } |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 1390 | // Add Uplink EthType Flow |
| Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1391 | logger.Debugw(ctx, "creating-ul-ethType-flow", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1392 | log.Fields{ |
| 1393 | "ul_classifier": uplinkClassifier, |
| 1394 | "ul_action": uplinkAction, |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1395 | "uplinkFlowId": logicalFlow.Id, |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1396 | "device-id": f.deviceHandler.device.Id, |
| 1397 | "intf-id": intfID, |
| 1398 | "onu-id": onuID}) |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1399 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1400 | classifierProto, err := makeOpenOltClassifierField(uplinkClassifier) |
| 1401 | if err != nil { |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1402 | return olterrors.NewErrInvalidValue(log.Fields{ |
| 1403 | "classifier": uplinkClassifier, |
| 1404 | "device-id": f.deviceHandler.device.Id}, err).Log() |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1405 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1406 | logger.Debugw(ctx, "created-classifier-proto", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1407 | log.Fields{ |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 1408 | "classifier": classifierProto.String(), |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1409 | "device-id": f.deviceHandler.device.Id}) |
| Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1410 | actionProto, err := makeOpenOltActionField(uplinkAction, uplinkClassifier) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1411 | if err != nil { |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1412 | return olterrors.NewErrInvalidValue(log.Fields{"action": uplinkAction, "device-id": f.deviceHandler.device.Id}, err).Log() |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1413 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1414 | logger.Debugw(ctx, "created-action-proto", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1415 | log.Fields{ |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 1416 | "action": actionProto.String(), |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1417 | "device-id": f.deviceHandler.device.Id}) |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1418 | networkIntfID, err := getNniIntfID(ctx, classifier, action) |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1419 | if err != nil { |
| Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1420 | return olterrors.NewErrNotFound("nni-interface-id", log.Fields{ |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1421 | "classifier": classifier, |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1422 | "action": action, |
| 1423 | "device-id": f.deviceHandler.device.Id}, |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1424 | err).Log() |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1425 | } |
| 1426 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1427 | upstreamFlow := openoltpb2.Flow{AccessIntfId: int32(intfID), |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1428 | OnuId: int32(onuID), |
| 1429 | UniId: int32(uniID), |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1430 | FlowId: logicalFlow.Id, |
| David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1431 | FlowType: Upstream, |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1432 | AllocId: int32(allocID), |
| 1433 | NetworkIntfId: int32(networkIntfID), |
| 1434 | GemportId: int32(gemPortID), |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1435 | Classifier: classifierProto, |
| 1436 | Action: actionProto, |
| 1437 | Priority: int32(logicalFlow.Priority), |
| 1438 | Cookie: logicalFlow.Cookie, |
| Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1439 | PortNo: portNo, |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1440 | TechProfileId: flowContext.tpID, |
| 1441 | ReplicateFlow: len(flowContext.pbitToGem) > 0, |
| 1442 | PbitToGemport: flowContext.pbitToGem, |
| 1443 | GemportToAes: flowContext.gemToAes, |
| Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1444 | } |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1445 | if err := f.addFlowToDevice(ctx, logicalFlow, &upstreamFlow); err != nil { |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 1446 | return olterrors.NewErrFlowOp("add", logicalFlow.Id, log.Fields{"flow-id": upstreamFlow.FlowId}, err).Log() |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1447 | } |
| Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1448 | logger.Infow(ctx, "ethType-ul-flow-added-to-device-successfully", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1449 | log.Fields{ |
| 1450 | "device-id": f.deviceHandler.device.Id, |
| 1451 | "onu-id": onuID, |
| 1452 | "intf-id": intfID, |
| Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1453 | "ethType": ethType, |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1454 | }) |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1455 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1456 | return nil |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1457 | } |
| 1458 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1459 | func makeOpenOltClassifierField(classifierInfo map[string]interface{}) (*openoltpb2.Classifier, error) { |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1460 | var classifier openoltpb2.Classifier |
| David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1461 | |
| 1462 | classifier.EthType, _ = classifierInfo[EthType].(uint32) |
| 1463 | classifier.IpProto, _ = classifierInfo[IPProto].(uint32) |
| 1464 | if vlanID, ok := classifierInfo[VlanVid].(uint32); ok { |
| Andrea Campanella | 7acc0b9 | 2020-02-14 09:20:49 +0100 | [diff] [blame] | 1465 | if vlanID != ReservedVlan { |
| 1466 | vid := vlanID & VlanvIDMask |
| Harsh Awasthi | ea45af7 | 2019-08-26 02:39:00 -0400 | [diff] [blame] | 1467 | classifier.OVid = vid |
| 1468 | } |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1469 | } |
| Girish Gowdra | b23f1de | 2022-03-24 12:01:17 -0700 | [diff] [blame] | 1470 | // The classifierInfo[Metadata] is set for the following flows |
| 1471 | // - In the Downstream datapath flow table0 and table1. From the OLT perspective, only table0 downstream flow is relevant. |
| 1472 | // - Mcast flow that points to a group in the treatment |
| 1473 | // This value, when present and valid (not 0 and not 4096), is interpreted as below |
| 1474 | // - inner vid for a double tagged packet in the datapath flow |
| 1475 | // - outer vid for a single tagged packet in the datapath flow |
| 1476 | // - inner vid in the mcast flow that points to a group |
| David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1477 | if metadata, ok := classifierInfo[Metadata].(uint64); ok { |
| 1478 | vid := uint32(metadata) |
| Andrea Campanella | faa4215 | 2021-10-28 11:50:56 +0530 | [diff] [blame] | 1479 | // Set the OVid or IVid classifier based on the whether OLT is using a transparent tag or not |
| 1480 | // If OLT is using transparent tag mechanism, then it classifies whatever tag it sees to/from ONU which |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 1481 | // is OVid from the perspective of the OLT. When OLT also places or pops the outer tag, then classifierInfo[Metadata] |
| Andrea Campanella | faa4215 | 2021-10-28 11:50:56 +0530 | [diff] [blame] | 1482 | // becomes the IVid. |
| 1483 | if classifier.OVid != 0 && classifier.OVid != ReservedVlan { // This is case when classifier.OVid is not set |
| 1484 | if vid != ReservedVlan { |
| 1485 | classifier.IVid = vid |
| 1486 | } |
| 1487 | } else { |
| 1488 | if vid != ReservedVlan { |
| 1489 | classifier.OVid = vid |
| 1490 | } |
| Harsh Awasthi | ea45af7 | 2019-08-26 02:39:00 -0400 | [diff] [blame] | 1491 | } |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1492 | } |
| Girish Gowdra | fae935c | 2020-02-17 19:21:44 +0530 | [diff] [blame] | 1493 | // Use VlanPCPMask (0xff) to signify NO PCP. Else use valid PCP (0 to 7) |
| David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1494 | if vlanPcp, ok := classifierInfo[VlanPcp].(uint32); ok { |
| Girish Gowdra | fae935c | 2020-02-17 19:21:44 +0530 | [diff] [blame] | 1495 | classifier.OPbits = vlanPcp |
| 1496 | } else { |
| 1497 | classifier.OPbits = VlanPCPMask |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1498 | } |
| David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1499 | classifier.SrcPort, _ = classifierInfo[UDPSrc].(uint32) |
| 1500 | classifier.DstPort, _ = classifierInfo[UDPDst].(uint32) |
| 1501 | classifier.DstIp, _ = classifierInfo[Ipv4Dst].(uint32) |
| 1502 | classifier.SrcIp, _ = classifierInfo[Ipv4Src].(uint32) |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1503 | classifier.DstMac, _ = classifierInfo[EthDst].([]uint8) |
| Girish Gowdra | ffa52e5 | 2022-02-16 15:48:10 -0800 | [diff] [blame] | 1504 | classifier.SrcMac, _ = classifierInfo[EthSrc].([]uint8) |
| David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1505 | if pktTagType, ok := classifierInfo[PacketTagType].(string); ok { |
| 1506 | classifier.PktTagType = pktTagType |
| 1507 | |
| 1508 | switch pktTagType { |
| 1509 | case SingleTag: |
| 1510 | case DoubleTag: |
| 1511 | case Untagged: |
| 1512 | default: |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1513 | return nil, olterrors.NewErrInvalidValue(log.Fields{"packet-tag-type": pktTagType}, nil) |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1514 | } |
| 1515 | } |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1516 | return &classifier, nil |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1517 | } |
| 1518 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 1519 | // nolint: unparam |
| 1520 | // TODO: Improvise the function & remove the unparam lint, currently it is always returning 'nil' as error. |
| Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1521 | func makeOpenOltActionField(actionInfo map[string]interface{}, classifierInfo map[string]interface{}) (*openoltpb2.Action, error) { |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1522 | var actionCmd openoltpb2.ActionCmd |
| 1523 | var action openoltpb2.Action |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1524 | action.Cmd = &actionCmd |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1525 | if _, ok := actionInfo[PopVlan]; ok { |
| Girish Gowdra | ffa52e5 | 2022-02-16 15:48:10 -0800 | [diff] [blame] | 1526 | // Pop outer vid |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1527 | action.Cmd.RemoveOuterTag = true |
| Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1528 | if _, ok := actionInfo[VlanPcp]; ok { |
| Girish Gowdra | ffa52e5 | 2022-02-16 15:48:10 -0800 | [diff] [blame] | 1529 | // Remark inner pbit |
| Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1530 | action.Cmd.RemarkInnerPbits = true |
| 1531 | action.IPbits = actionInfo[VlanPcp].(uint32) |
| 1532 | if _, ok := actionInfo[VlanVid]; ok { |
| Girish Gowdra | ffa52e5 | 2022-02-16 15:48:10 -0800 | [diff] [blame] | 1533 | // Remark inner vid |
| Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1534 | action.Cmd.TranslateInnerTag = true |
| 1535 | action.IVid = actionInfo[VlanVid].(uint32) |
| 1536 | } |
| 1537 | } |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1538 | } else if _, ok := actionInfo[PushVlan]; ok { |
| Girish Gowdra | ffa52e5 | 2022-02-16 15:48:10 -0800 | [diff] [blame] | 1539 | // push outer vid |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1540 | action.OVid = actionInfo[VlanVid].(uint32) |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1541 | action.Cmd.AddOuterTag = true |
| Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1542 | if _, ok := actionInfo[VlanPcp]; ok { |
| Girish Gowdra | ffa52e5 | 2022-02-16 15:48:10 -0800 | [diff] [blame] | 1543 | // translate outer pbit |
| Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1544 | action.OPbits = actionInfo[VlanPcp].(uint32) |
| 1545 | action.Cmd.RemarkOuterPbits = true |
| 1546 | if _, ok := classifierInfo[VlanVid]; ok { |
| Girish Gowdra | ffa52e5 | 2022-02-16 15:48:10 -0800 | [diff] [blame] | 1547 | // translate inner vid |
| Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1548 | action.IVid = classifierInfo[VlanVid].(uint32) |
| 1549 | action.Cmd.TranslateInnerTag = true |
| 1550 | } |
| 1551 | } |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1552 | } else if _, ok := actionInfo[TrapToHost]; ok { |
| 1553 | action.Cmd.TrapToHost = actionInfo[TrapToHost].(bool) |
| Girish Gowdra | ffa52e5 | 2022-02-16 15:48:10 -0800 | [diff] [blame] | 1554 | } else if _, ok := actionInfo[VlanVid]; ok { |
| 1555 | // Translate outer vid |
| 1556 | action.Cmd.TranslateOuterTag = true |
| 1557 | action.OVid = actionInfo[VlanVid].(uint32) |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1558 | } |
| Andrea Campanella | faa4215 | 2021-10-28 11:50:56 +0530 | [diff] [blame] | 1559 | // When OLT is transparent to vlans no-action is valid. |
| 1560 | /* |
| 1561 | else { |
| 1562 | return nil, olterrors.NewErrInvalidValue(log.Fields{"action-command": actionInfo}, nil) |
| 1563 | } |
| 1564 | */ |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1565 | return &action, nil |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1566 | } |
| 1567 | |
| Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 1568 | // getTPpath return the ETCD path for a given UNI port |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 1569 | func (f *OpenOltFlowMgr) getTPpath(ctx context.Context, uniPath string, TpID uint32) string { |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1570 | return f.techprofile.GetTechProfileInstanceKey(ctx, TpID, uniPath) |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1571 | } |
| 1572 | |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1573 | // DeleteTechProfileInstances removes the tech profile instances from persistent storage |
| Girish Gowdra | 197acc1 | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 1574 | // We also force release scheduler and queues associated with the tp instance. Theoretically there could be |
| 1575 | // an issue if the upstream scheduler (DBA) is shared across multiple UNI and we force release it, given that |
| 1576 | // this function is only meant to clean up TP instances of a given UNI. But in practicality this routine |
| 1577 | // is only meant to be called when the clean up of resource for the whole ONU is taking place. |
| 1578 | // The reason for introducing the force cleanup of scheduler and queues (on the OLT) was introduced here |
| 1579 | // because it was observed that if the ONU device was deleted too soon after the flows were |
| 1580 | // unprovisioned on that ONU, the scheduler and queue removal pertinent to that ONU would remain |
| 1581 | // uncleaned on the OLT. So we force clean up here and ignore any error that OLT returns during the |
| 1582 | // force cleanup (possible if the OLT has already cleared those resources). |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1583 | func (f *OpenOltFlowMgr) DeleteTechProfileInstances(ctx context.Context, intfID uint32, onuID uint32, uniID uint32) error { |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 1584 | tpIDList := f.resourceMgr.GetTechProfileIDForOnu(ctx, onuID, uniID) |
| Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 1585 | uniPortName := getUniPortPath(f.deviceHandler.device.Id, intfID, int32(onuID), int32(uniID)) |
| 1586 | |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1587 | for _, tpID := range tpIDList { |
| Girish Gowdra | 197acc1 | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 1588 | // Force cleanup scheduler/queues -- start |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 1589 | uniPortNum := plt.MkUniPortNum(ctx, intfID, onuID, uniID) |
| Girish Gowdra | 197acc1 | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 1590 | uni := getUniPortPath(f.deviceHandler.device.Id, intfID, int32(onuID), int32(uniID)) |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 1591 | tpPath := f.getTPpath(ctx, uni, tpID) |
| Girish Gowdra | 197acc1 | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 1592 | tpInst, err := f.techprofile.GetTPInstance(ctx, tpPath) |
| 1593 | if err != nil || tpInst == nil { // This should not happen, something wrong in KV backend transaction |
| 1594 | logger.Warnw(ctx, "tech-profile-not-in-kv-store", |
| 1595 | log.Fields{ |
| 1596 | "tp-id": tpID, |
| 1597 | "path": tpPath}) |
| 1598 | } |
| 1599 | switch tpInstance := tpInst.(type) { |
| 1600 | case *tp_pb.TechProfileInstance: |
| 1601 | f.forceRemoveSchedulerQueues(ctx, schedQueue{direction: tp_pb.Direction_UPSTREAM, intfID: intfID, onuID: onuID, uniID: uniID, tpID: tpID, uniPort: uniPortNum, tpInst: tpInstance}) |
| 1602 | f.forceRemoveSchedulerQueues(ctx, schedQueue{direction: tp_pb.Direction_DOWNSTREAM, intfID: intfID, onuID: onuID, uniID: uniID, tpID: tpID, uniPort: uniPortNum, tpInst: tpInstance}) |
| 1603 | } |
| 1604 | // Force cleanup scheduler/queues -- end |
| 1605 | |
| 1606 | // Now remove the tp instance |
| npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1607 | if err := f.DeleteTechProfileInstance(ctx, intfID, onuID, uniID, uniPortName, tpID); err != nil { |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1608 | logger.Errorw(ctx, "delete-tech-profile-failed", log.Fields{"err": err, "device-id": f.deviceHandler.device.Id}) |
| Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 1609 | // return err |
| 1610 | // We should continue to delete tech-profile instances for other TP IDs |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1611 | } |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1612 | logger.Debugw(ctx, "tech-profile-instance-deleted", log.Fields{"device-id": f.deviceHandler.device.Id, "uniPortName": uniPortName, "tp-id": tpID}) |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1613 | } |
| 1614 | return nil |
| 1615 | } |
| 1616 | |
| 1617 | // DeleteTechProfileInstance removes the tech profile instance from persistent storage |
| npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1618 | func (f *OpenOltFlowMgr) DeleteTechProfileInstance(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, uniPortName string, tpID uint32) error { |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1619 | if uniPortName == "" { |
| Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 1620 | uniPortName = getUniPortPath(f.deviceHandler.device.Id, intfID, int32(onuID), int32(uniID)) |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1621 | } |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1622 | if err := f.techprofile.DeleteTechProfileInstance(ctx, tpID, uniPortName); err != nil { |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1623 | return olterrors.NewErrAdapter("failed-to-delete-tp-instance-from-kv-store", |
| 1624 | log.Fields{ |
| 1625 | "tp-id": tpID, |
| 1626 | "uni-port-name": uniPortName, |
| 1627 | "device-id": f.deviceHandler.device.Id}, err) |
| Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 1628 | } |
| 1629 | return nil |
| 1630 | } |
| 1631 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1632 | func (f *OpenOltFlowMgr) addFlowToDevice(ctx context.Context, logicalFlow *ofp.OfpFlowStats, deviceFlow *openoltpb2.Flow) error { |
| Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 1633 | var intfID uint32 |
| 1634 | /* For flows which trap out of the NNI, the AccessIntfId is invalid |
| 1635 | (set to -1). In such cases, we need to refer to the NetworkIntfId . |
| 1636 | */ |
| 1637 | if deviceFlow.AccessIntfId != -1 { |
| 1638 | intfID = uint32(deviceFlow.AccessIntfId) |
| 1639 | } else { |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1640 | // We need to log the valid interface ID. |
| 1641 | // For trap-on-nni flows, the access_intf_id is invalid (-1), so choose the network_intf_id. |
| Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 1642 | intfID = uint32(deviceFlow.NetworkIntfId) |
| 1643 | } |
| 1644 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1645 | logger.Debugw(ctx, "sending-flow-to-device-via-grpc", log.Fields{ |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 1646 | "flow-id": deviceFlow.FlowId, |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1647 | "device-id": f.deviceHandler.device.Id, |
| 1648 | "intf-id": intfID}) |
| bseeniva | a162211 | 2025-12-11 18:24:02 +0530 | [diff] [blame] | 1649 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), f.deviceHandler.cfg.RPCTimeout) |
| 1650 | _, err := f.deviceHandler.Client.FlowAdd(subCtx, deviceFlow) |
| 1651 | cancel() |
| Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 1652 | |
| 1653 | st, _ := status.FromError(err) |
| 1654 | if st.Code() == codes.AlreadyExists { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1655 | logger.Debug(ctx, "flow-already-exists", log.Fields{ |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 1656 | "err": err, |
| 1657 | "flow-id": deviceFlow.FlowId, |
| 1658 | "device-id": f.deviceHandler.device.Id, |
| 1659 | "intf-id": intfID}) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1660 | return nil |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1661 | } |
| Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 1662 | |
| 1663 | if err != nil { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1664 | logger.Errorw(ctx, "failed-to-add-flow-to-device", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1665 | log.Fields{"err": err, |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 1666 | "flow-id": deviceFlow.FlowId, |
| 1667 | "device-id": f.deviceHandler.device.Id, |
| 1668 | "intf-id": intfID}) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1669 | return err |
| Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 1670 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1671 | logger.Infow(ctx, "flow-added-to-device-successfully ", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1672 | log.Fields{ |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 1673 | "flow-id": deviceFlow.FlowId, |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1674 | "device-id": f.deviceHandler.device.Id, |
| 1675 | "intf-id": intfID}) |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1676 | |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1677 | if err := f.registerFlow(ctx, logicalFlow, deviceFlow); err != nil { |
| 1678 | logger.Errorw(ctx, "failed-to-register-flow", log.Fields{"err": err}) |
| 1679 | return err |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1680 | } |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1681 | return nil |
| Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1682 | } |
| 1683 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1684 | func (f *OpenOltFlowMgr) removeFlowFromDevice(ctx context.Context, deviceFlow *openoltpb2.Flow, ofFlowID uint64) error { |
| 1685 | logger.Debugw(ctx, "sending-flow-to-device-via-grpc", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1686 | log.Fields{ |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 1687 | "flow-id": deviceFlow.FlowId, |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1688 | "device-id": f.deviceHandler.device.Id}) |
| bseeniva | a162211 | 2025-12-11 18:24:02 +0530 | [diff] [blame] | 1689 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), f.deviceHandler.cfg.RPCTimeout) |
| 1690 | _, err := f.deviceHandler.Client.FlowRemove(subCtx, deviceFlow) |
| 1691 | cancel() |
| Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1692 | if err != nil { |
| serkant.uluderya | 245caba | 2019-09-24 23:15:29 -0700 | [diff] [blame] | 1693 | if f.deviceHandler.device.ConnectStatus == common.ConnectStatus_UNREACHABLE { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1694 | logger.Warnw(ctx, "can-not-remove-flow-from-device--unreachable", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1695 | log.Fields{ |
| 1696 | "err": err, |
| 1697 | "deviceFlow": deviceFlow, |
| 1698 | "device-id": f.deviceHandler.device.Id}) |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 1699 | // Assume the flow is removed |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1700 | return nil |
| serkant.uluderya | 245caba | 2019-09-24 23:15:29 -0700 | [diff] [blame] | 1701 | } |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1702 | return olterrors.NewErrFlowOp("remove", deviceFlow.FlowId, log.Fields{"deviceFlow": deviceFlow}, err) |
| Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1703 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1704 | logger.Infow(ctx, "flow-removed-from-device-successfully", log.Fields{ |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1705 | "of-flow-id": ofFlowID, |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 1706 | "flow-id": deviceFlow.FlowId, |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1707 | "device-id": f.deviceHandler.device.Id, |
| 1708 | }) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1709 | return nil |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1710 | } |
| 1711 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1712 | func (f *OpenOltFlowMgr) addLLDPFlow(ctx context.Context, flow *ofp.OfpFlowStats, portNo uint32) error { |
| Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1713 | classifierInfo := make(map[string]interface{}) |
| 1714 | actionInfo := make(map[string]interface{}) |
| 1715 | |
| 1716 | classifierInfo[EthType] = uint32(LldpEthType) |
| 1717 | classifierInfo[PacketTagType] = Untagged |
| 1718 | actionInfo[TrapToHost] = true |
| 1719 | |
| 1720 | // LLDP flow is installed to trap LLDP packets on the NNI port. |
| 1721 | // We manage flow_id resource pool on per PON port basis. |
| 1722 | // Since this situation is tricky, as a hack, we pass the NNI port |
| 1723 | // index (network_intf_id) as PON port Index for the flow_id resource |
| 1724 | // pool. Also, there is no ONU Id available for trapping LLDP packets |
| 1725 | // on NNI port, use onu_id as -1 (invalid) |
| 1726 | // ****************** CAVEAT ******************* |
| 1727 | // This logic works if the NNI Port Id falls within the same valid |
| 1728 | // range of PON Port Ids. If this doesn't work for some OLT Vendor |
| 1729 | // we need to have a re-look at this. |
| 1730 | // ********************************************* |
| 1731 | |
| 1732 | var onuID = -1 |
| 1733 | var uniID = -1 |
| 1734 | var gemPortID = -1 |
| 1735 | |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 1736 | networkInterfaceID, err := plt.IntfIDFromNniPortNum(ctx, portNo) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1737 | if err != nil { |
| Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1738 | return olterrors.NewErrInvalidValue(log.Fields{"nni-port-number": portNo}, err).Log() |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1739 | } |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 1740 | present, err := f.resourceMgr.IsFlowOnKvStore(ctx, int32(onuID), flow.Id) |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1741 | if present { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1742 | logger.Infow(ctx, "flow-exists--not-re-adding", log.Fields{"device-id": f.deviceHandler.device.Id}) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1743 | return nil |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1744 | } else if err != nil { |
| 1745 | logger.Errorw(ctx, "aborting-addLLDPFlow--flow-may-already-exist", |
| 1746 | log.Fields{"intf-id": networkInterfaceID, "onu-id": onuID, "flow-id": flow.Id}) |
| 1747 | return err |
| Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1748 | } |
| Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1749 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1750 | classifierProto, err := makeOpenOltClassifierField(classifierInfo) |
| 1751 | if err != nil { |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1752 | return olterrors.NewErrInvalidValue( |
| 1753 | log.Fields{ |
| 1754 | "classifier": classifierInfo, |
| 1755 | "device-id": f.deviceHandler.device.Id}, err) |
| Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1756 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1757 | logger.Debugw(ctx, "created-classifier-proto", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1758 | log.Fields{ |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 1759 | "classifier": classifierProto.String(), |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1760 | "device-id": f.deviceHandler.device.Id}) |
| Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1761 | actionProto, err := makeOpenOltActionField(actionInfo, classifierInfo) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1762 | if err != nil { |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1763 | return olterrors.NewErrInvalidValue( |
| 1764 | log.Fields{ |
| 1765 | "action": actionInfo, |
| 1766 | "device-id": f.deviceHandler.device.Id}, err) |
| Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1767 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1768 | logger.Debugw(ctx, "created-action-proto", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1769 | log.Fields{ |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 1770 | "action": actionProto.String(), |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1771 | "device-id": f.deviceHandler.device.Id}) |
| Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1772 | |
| 1773 | downstreamflow := openoltpb2.Flow{AccessIntfId: int32(-1), // AccessIntfId not required |
| 1774 | OnuId: int32(onuID), // OnuId not required |
| 1775 | UniId: int32(uniID), // UniId not used |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1776 | FlowId: flow.Id, |
| Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1777 | FlowType: Downstream, |
| 1778 | NetworkIntfId: int32(networkInterfaceID), |
| 1779 | GemportId: int32(gemPortID), |
| 1780 | Classifier: classifierProto, |
| 1781 | Action: actionProto, |
| 1782 | Priority: int32(flow.Priority), |
| 1783 | Cookie: flow.Cookie, |
| 1784 | PortNo: portNo} |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1785 | if err := f.addFlowToDevice(ctx, flow, &downstreamflow); err != nil { |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1786 | return olterrors.NewErrFlowOp("add", flow.Id, |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1787 | log.Fields{ |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 1788 | "flow-id": downstreamflow.FlowId, |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1789 | "device-id": f.deviceHandler.device.Id}, err) |
| Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1790 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1791 | logger.Infow(ctx, "lldp-trap-on-nni-flow-added-to-device-successfully", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1792 | log.Fields{ |
| 1793 | "device-id": f.deviceHandler.device.Id, |
| 1794 | "onu-id": onuID, |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1795 | "flow-id": flow.Id}) |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1796 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1797 | return nil |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1798 | } |
| 1799 | |
| Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 1800 | func getUniPortPath(oltID string, intfID uint32, onuID int32, uniID int32) string { |
| 1801 | return fmt.Sprintf("olt-{%s}/pon-{%d}/onu-{%d}/uni-{%d}", oltID, intfID, onuID, uniID) |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1802 | } |
| 1803 | |
| Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 1804 | // getOnuDevice to fetch onu from cache or core. |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1805 | func (f *OpenOltFlowMgr) getOnuDevice(ctx context.Context, intfID uint32, onuID uint32) (*OnuDevice, error) { |
| Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1806 | onuKey := f.deviceHandler.formOnuKey(intfID, onuID) |
| 1807 | onuDev, ok := f.deviceHandler.onus.Load(onuKey) |
| 1808 | if !ok { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1809 | logger.Debugw(ctx, "couldnt-find-onu-in-cache", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1810 | log.Fields{ |
| 1811 | "intf-id": intfID, |
| 1812 | "onu-id": onuID, |
| 1813 | "device-id": f.deviceHandler.device.Id}) |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1814 | onuDevice, err := f.getChildDevice(ctx, intfID, onuID) |
| Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1815 | if err != nil { |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1816 | return nil, olterrors.NewErrNotFound("onu-child-device", |
| 1817 | log.Fields{ |
| 1818 | "onu-id": onuID, |
| 1819 | "intf-id": intfID, |
| 1820 | "device-id": f.deviceHandler.device.Id}, err) |
| Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1821 | } |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1822 | onuDev = NewOnuDevice(onuDevice.Id, onuDevice.Type, onuDevice.SerialNumber, onuDevice.ProxyAddress.OnuId, onuDevice.ProxyAddress.ChannelId, onuDevice.ProxyAddress.DeviceId, false, onuDevice.AdapterEndpoint) |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 1823 | // better to ad the device to cache here. |
| Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1824 | f.deviceHandler.StoreOnuDevice(onuDev.(*OnuDevice)) |
| 1825 | } else { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1826 | logger.Debugw(ctx, "found-onu-in-cache", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1827 | log.Fields{ |
| 1828 | "intf-id": intfID, |
| 1829 | "onu-id": onuID, |
| 1830 | "device-id": f.deviceHandler.device.Id}) |
| Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1831 | } |
| 1832 | |
| 1833 | return onuDev.(*OnuDevice), nil |
| 1834 | } |
| 1835 | |
| Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 1836 | // getChildDevice to fetch onu |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1837 | func (f *OpenOltFlowMgr) getChildDevice(ctx context.Context, intfID uint32, onuID uint32) (*voltha.Device, error) { |
| 1838 | logger.Infow(ctx, "GetChildDevice", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1839 | log.Fields{ |
| 1840 | "pon-port": intfID, |
| 1841 | "onu-id": onuID, |
| 1842 | "device-id": f.deviceHandler.device.Id}) |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 1843 | parentPortNo := plt.IntfIDToPortNo(intfID, voltha.Port_PON_OLT) |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1844 | onuDevice, err := f.deviceHandler.GetChildDevice(ctx, parentPortNo, onuID) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1845 | if err != nil { |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1846 | return nil, olterrors.NewErrNotFound("onu", |
| 1847 | log.Fields{ |
| 1848 | "interface-id": parentPortNo, |
| 1849 | "onu-id": onuID, |
| 1850 | "device-id": f.deviceHandler.device.Id}, |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1851 | err) |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1852 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1853 | logger.Infow(ctx, "successfully-received-child-device-from-core", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1854 | log.Fields{ |
| 1855 | "device-id": f.deviceHandler.device.Id, |
| 1856 | "child_device_id": onuDevice.Id, |
| 1857 | "child_device_sn": onuDevice.SerialNumber}) |
| Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1858 | return onuDevice, nil |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1859 | } |
| 1860 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1861 | func (f *OpenOltFlowMgr) sendDeleteGemPortToChild(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, gemPortID uint32, tpPath string) error { |
| 1862 | onuDev, err := f.getOnuDevice(ctx, intfID, onuID) |
| Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1863 | if err != nil { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1864 | logger.Debugw(ctx, "couldnt-find-onu-child-device", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1865 | log.Fields{ |
| 1866 | "intf-id": intfID, |
| 1867 | "onu-id": onuID, |
| 1868 | "uni-id": uniID, |
| 1869 | "device-id": f.deviceHandler.device.Id}) |
| Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1870 | return err |
| Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1871 | } |
| 1872 | |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1873 | delGemPortMsg := &ia.DeleteGemPortMessage{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1874 | DeviceId: onuDev.deviceID, |
| 1875 | UniId: uniID, |
| 1876 | TpInstancePath: tpPath, |
| 1877 | GemPortId: gemPortID, |
| 1878 | } |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 1879 | logger.Debugw(ctx, "sending-gem-port-delete-to-openonu-adapter", log.Fields{"msg": delGemPortMsg.String(), "child-device-id": onuDev.deviceID}) |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1880 | |
| 1881 | if err := f.deviceHandler.sendDeleteGemPortToChildAdapter(ctx, onuDev.adapterEndpoint, delGemPortMsg); err != nil { |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1882 | return olterrors.NewErrCommunication("send-delete-gem-port-to-onu-adapter", |
| 1883 | log.Fields{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1884 | "from-adapter": f.deviceHandler.openOLT.config.AdapterEndpoint, |
| 1885 | "to-adapter": onuDev.adapterEndpoint, |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1886 | "onu-id": onuDev.deviceID, |
| 1887 | "proxyDeviceID": onuDev.proxyDeviceID, |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1888 | "device-id": f.deviceHandler.device.Id}, err) |
| Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1889 | } |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1890 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1891 | logger.Infow(ctx, "success-sending-del-gem-port-to-onu-adapter", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1892 | log.Fields{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1893 | "msg": delGemPortMsg, |
| 1894 | "from-adapter": f.deviceHandler.device.Type, |
| 1895 | "to-adapter": onuDev.deviceType, |
| 1896 | "device-id": f.deviceHandler.device.Id, |
| 1897 | "child-device-id": onuDev.deviceID}) |
| Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1898 | return nil |
| 1899 | } |
| 1900 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1901 | func (f *OpenOltFlowMgr) sendDeleteTcontToChild(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, allocID uint32, tpPath string) error { |
| 1902 | onuDev, err := f.getOnuDevice(ctx, intfID, onuID) |
| Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1903 | if err != nil { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1904 | logger.Warnw(ctx, "couldnt-find-onu-child-device", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1905 | log.Fields{ |
| 1906 | "intf-id": intfID, |
| 1907 | "onu-id": onuID, |
| 1908 | "uni-id": uniID, |
| 1909 | "device-id": f.deviceHandler.device.Id}) |
| Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1910 | return err |
| Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1911 | } |
| 1912 | |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1913 | delTcontMsg := &ia.DeleteTcontMessage{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1914 | DeviceId: onuDev.deviceID, |
| 1915 | UniId: uniID, |
| 1916 | TpInstancePath: tpPath, |
| 1917 | AllocId: allocID, |
| 1918 | } |
| 1919 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1920 | logger.Debugw(ctx, "sending-tcont-delete-to-openonu-adapter", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1921 | log.Fields{ |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 1922 | "msg": delTcontMsg.String(), |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1923 | "device-id": f.deviceHandler.device.Id}) |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1924 | |
| 1925 | if err := f.deviceHandler.sendDeleteTContToChildAdapter(ctx, onuDev.adapterEndpoint, delTcontMsg); err != nil { |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1926 | return olterrors.NewErrCommunication("send-delete-tcont-to-onu-adapter", |
| 1927 | log.Fields{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1928 | "from-adapter": f.deviceHandler.openOLT.config.AdapterEndpoint, |
| 1929 | "to-adapter": onuDev.adapterEndpoint, |
| 1930 | "onu-id": onuDev.deviceID, |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1931 | "proxyDeviceID": onuDev.proxyDeviceID, |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1932 | "device-id": f.deviceHandler.device.Id}, err) |
| Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1933 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1934 | logger.Infow(ctx, "success-sending-del-tcont-to-onu-adapter", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1935 | log.Fields{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1936 | "msg": delTcontMsg, |
| 1937 | "device-id": f.deviceHandler.device.Id, |
| 1938 | "child-device-id": onuDev.deviceID}) |
| Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1939 | return nil |
| 1940 | } |
| 1941 | |
| Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 1942 | // clearResources clears pon resources in kv store and the device |
| Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 1943 | // nolint: gocyclo |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1944 | func (f *OpenOltFlowMgr) clearResources(ctx context.Context, intfID uint32, onuID int32, uniID int32, |
| Sridhar Ravindra | d104e8d | 2025-06-02 13:04:49 +0530 | [diff] [blame] | 1945 | flowID uint64, portNum uint32, tpID uint32, sendDeleteGemRequest bool, nniIntfID uint32) error { |
| Gamze Abaka | 745ccb7 | 2021-11-18 11:29:58 +0000 | [diff] [blame] | 1946 | logger.Debugw(ctx, "clearing-resources", log.Fields{"intfID": intfID, "onuID": onuID, "uniID": uniID, "tpID": tpID}) |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1947 | |
| Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 1948 | uni := getUniPortPath(f.deviceHandler.device.Id, intfID, onuID, uniID) |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 1949 | tpPath := f.getTPpath(ctx, uni, tpID) |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1950 | logger.Debugw(ctx, "getting-techprofile-instance-for-subscriber", |
| 1951 | log.Fields{ |
| 1952 | "tpPath": tpPath, |
| 1953 | "device-id": f.deviceHandler.device.Id}) |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1954 | |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1955 | techprofileInst, err := f.techprofile.GetTPInstance(ctx, tpPath) |
| Girish Gowdra | 78fd63d | 2021-10-18 14:34:53 -0700 | [diff] [blame] | 1956 | if err != nil || techprofileInst == nil { |
| 1957 | // The child device is possibly deleted which in turn had cleaned up all the resources (including tp instances), check.. |
| 1958 | childDevice, _ := f.getChildDevice(ctx, intfID, uint32(onuID)) // do not care about the error code |
| 1959 | if childDevice == nil { |
| 1960 | // happens when subscriber un-provision is immediately followed by child device delete |
| 1961 | // before all the flow removes are processed, the child device delete has already arrived and cleaned up all the resources |
| 1962 | logger.Warnw(ctx, "child device and its associated resources are already cleared", log.Fields{"intfID": intfID, "onuID": onuID, "uniID": uniID}) |
| 1963 | return nil |
| 1964 | } |
| Elia Battiston | 2aaf434 | 2022-02-07 15:16:38 +0100 | [diff] [blame] | 1965 | // If the tech profile is not found, since we want to delete it, there is no need to throw an error |
| 1966 | _ = olterrors.NewErrNotFound("tech-profile-in-kv-store", |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1967 | log.Fields{ |
| 1968 | "tp-id": tpID, |
| Elia Battiston | 2aaf434 | 2022-02-07 15:16:38 +0100 | [diff] [blame] | 1969 | "path": tpPath}, err).Log() |
| 1970 | return nil |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1971 | } |
| Gamze Abaka | 745ccb7 | 2021-11-18 11:29:58 +0000 | [diff] [blame] | 1972 | |
| 1973 | var allGemPortsFree = true |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1974 | switch techprofileInst := techprofileInst.(type) { |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1975 | case *tp_pb.TechProfileInstance: |
| Gamze Abaka | 745ccb7 | 2021-11-18 11:29:58 +0000 | [diff] [blame] | 1976 | for _, gemPort := range techprofileInst.UpstreamGemPortAttributeList { |
| 1977 | gemPortID := gemPort.GemportId |
| Girish Gowdra | b4c3330 | 2022-03-18 15:07:38 -0700 | [diff] [blame] | 1978 | flowIDs, err := f.resourceMgr.GetFlowIDsForGem(ctx, gemPortID) |
| 1979 | if err != nil { |
| 1980 | return err |
| 1981 | } |
| 1982 | used := false |
| 1983 | for _, id := range flowIDs { |
| 1984 | if flowID != id { |
| 1985 | used = true |
| 1986 | break |
| yasin sapli | 9e4c509 | 2022-02-01 13:52:33 +0000 | [diff] [blame] | 1987 | } |
| Girish Gowdra | b4c3330 | 2022-03-18 15:07:38 -0700 | [diff] [blame] | 1988 | } |
| 1989 | if used { |
| Gamze Abaka | 745ccb7 | 2021-11-18 11:29:58 +0000 | [diff] [blame] | 1990 | for i, flowIDinMap := range flowIDs { |
| 1991 | if flowIDinMap == flowID { |
| 1992 | flowIDs = append(flowIDs[:i], flowIDs[i+1:]...) |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 1993 | if err := f.resourceMgr.UpdateFlowIDsForGem(ctx, gemPortID, flowIDs); err != nil { |
| Gamze Abaka | 745ccb7 | 2021-11-18 11:29:58 +0000 | [diff] [blame] | 1994 | return err |
| 1995 | } |
| 1996 | break |
| 1997 | } |
| 1998 | } |
| 1999 | logger.Debugw(ctx, "gem-port-id-is-still-used-by-other-flows", |
| 2000 | log.Fields{ |
| 2001 | "gemport-id": gemPortID, |
| 2002 | "usedByFlows": flowIDs, |
| 2003 | "currentFlow": flowID, |
| 2004 | "device-id": f.deviceHandler.device.Id}) |
| 2005 | allGemPortsFree = false |
| 2006 | } |
| 2007 | } |
| 2008 | if !allGemPortsFree { |
| 2009 | return nil |
| 2010 | } |
| 2011 | } |
| 2012 | |
| 2013 | logger.Debugw(ctx, "all-gem-ports-are-free-to-be-deleted", log.Fields{"intfID": intfID, "onuID": onuID, "uniID": uniID, "tpID": tpID}) |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2014 | |
| 2015 | // Free TPInstance, TPID, GemPorts and Traffic Queues. AllocID and Schedulers will be cleared later only if they are not shared across all the UNIs |
| Gamze Abaka | 745ccb7 | 2021-11-18 11:29:58 +0000 | [diff] [blame] | 2016 | switch techprofileInst := techprofileInst.(type) { |
| 2017 | case *tp_pb.TechProfileInstance: |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2018 | for _, gemPort := range techprofileInst.UpstreamGemPortAttributeList { |
| 2019 | gemPortID := gemPort.GemportId |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2020 | _ = f.resourceMgr.RemoveGemFromOnuGemInfo(ctx, uint32(onuID), gemPortID) // ignore error and proceed. |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2021 | |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2022 | if err := f.resourceMgr.DeleteFlowIDsForGem(ctx, gemPortID); err != nil { |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2023 | logger.Errorw(ctx, "error-removing-flow-ids-of-gem-port", |
| 2024 | log.Fields{ |
| 2025 | "err": err, |
| 2026 | "intf": intfID, |
| 2027 | "onu-id": onuID, |
| 2028 | "uni-id": uniID, |
| 2029 | "device-id": f.deviceHandler.device.Id, |
| 2030 | "gemport-id": gemPortID}) |
| 2031 | } |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2032 | } |
| 2033 | // Remove queues at OLT in upstream and downstream direction |
| Sridhar Ravindra | d104e8d | 2025-06-02 13:04:49 +0530 | [diff] [blame] | 2034 | schedQ := schedQueue{tpInst: techprofileInst, direction: tp_pb.Direction_UPSTREAM, intfID: intfID, nniIntfID: nniIntfID, onuID: uint32(onuID), uniID: uint32(uniID), tpID: tpID, uniPort: portNum} |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2035 | if err := f.RemoveQueues(ctx, schedQ); err != nil { |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2036 | logger.Warn(ctx, err) |
| 2037 | } |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2038 | schedQ.direction = tp_pb.Direction_DOWNSTREAM |
| 2039 | if err := f.RemoveQueues(ctx, schedQ); err != nil { |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2040 | logger.Warn(ctx, err) |
| 2041 | } |
| 2042 | } |
| 2043 | |
| 2044 | switch techprofileInst := techprofileInst.(type) { |
| 2045 | case *tp_pb.TechProfileInstance: |
| 2046 | // Proceed to free allocid and cleanup schedulers (US/DS) if no other references are found for this TP across all the UNIs on the ONU |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2047 | schedQ := schedQueue{direction: tp_pb.Direction_UPSTREAM, intfID: intfID, onuID: uint32(onuID), uniID: uint32(uniID), tpID: tpID, uniPort: portNum, tpInst: techprofileInst} |
| 2048 | allocExists := f.isAllocUsedByAnotherUNI(ctx, schedQ) |
| Andrea Campanella | 8a0d050 | 2022-01-31 15:31:59 +0100 | [diff] [blame] | 2049 | if !allocExists { |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2050 | // all alloc object references removed, remove upstream scheduler |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2051 | if KvStoreMeter, _ := f.resourceMgr.GetMeterInfoForOnu(ctx, "upstream", uint32(onuID), uint32(uniID), tpID); KvStoreMeter != nil { |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2052 | if err := f.RemoveScheduler(ctx, schedQ); err != nil { |
| Andrea Campanella | 8a0d050 | 2022-01-31 15:31:59 +0100 | [diff] [blame] | 2053 | logger.Warn(ctx, err) |
| 2054 | } |
| 2055 | } |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2056 | // remove alloc id from resource pool by setting the 'freeFromResourcePool' to true |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2057 | f.resourceMgr.FreeAllocID(ctx, uint32(onuID), uint32(uniID), techprofileInst.UsScheduler.AllocId, true) |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2058 | } else { |
| 2059 | // just remove meter reference for the upstream direction for the current pon/onu/uni |
| 2060 | // The upstream scheduler, alloc id and meter-reference for the last remaining pon/onu/uni will be removed when no other alloc references that TP |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2061 | if err := f.removeMeterReference(ctx, "upstream", schedQ); err != nil { |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2062 | return err |
| Andrea Campanella | 8a0d050 | 2022-01-31 15:31:59 +0100 | [diff] [blame] | 2063 | } |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2064 | // setting 'freeFromResourcePool' to false in resourceMgr.FreeAllocID will only remove alloc-id data for the given pon/onu/uni |
| 2065 | // but still preserve it on the resource pool. |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2066 | f.resourceMgr.FreeAllocID(ctx, uint32(onuID), uint32(uniID), techprofileInst.UsScheduler.AllocId, false) |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2067 | } |
| Andrea Campanella | 8a0d050 | 2022-01-31 15:31:59 +0100 | [diff] [blame] | 2068 | |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2069 | // Downstream scheduler removal is simple, just invoke RemoveScheduler without all the complex handling we do for the alloc object. |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2070 | schedQ.direction = tp_pb.Direction_DOWNSTREAM |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2071 | if KvStoreMeter, _ := f.resourceMgr.GetMeterInfoForOnu(ctx, "downstream", uint32(onuID), uint32(uniID), tpID); KvStoreMeter != nil { |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2072 | if err := f.RemoveScheduler(ctx, schedQ); err != nil { |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2073 | logger.Warn(ctx, err) |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2074 | } |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2075 | } |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2076 | case *tp_pb.EponTechProfileInstance: |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2077 | // Delete the TCONT on the ONU. |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2078 | if err := f.sendDeleteTcontToChild(ctx, intfID, uint32(onuID), uint32(uniID), techprofileInst.AllocId, tpPath); err != nil { |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2079 | logger.Errorw(ctx, "error-processing-delete-tcont-towards-onu", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2080 | log.Fields{ |
| Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 2081 | "intf": intfID, |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2082 | "onu-id": onuID, |
| 2083 | "uni-id": uniID, |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2084 | "device-id": f.deviceHandler.device.Id, |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2085 | "alloc-id": techprofileInst.AllocId, |
| 2086 | "error": err}) |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 2087 | } |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2088 | f.resourceMgr.FreeAllocID(ctx, uint32(onuID), uint32(uniID), techprofileInst.AllocId, true) |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 2089 | if err := f.resourceMgr.RemoveTechProfileIDForOnu(ctx, uint32(onuID), uint32(uniID), tpID); err != nil { |
| 2090 | logger.Warn(ctx, err) |
| 2091 | } |
| 2092 | if err := f.DeleteTechProfileInstance(ctx, intfID, uint32(onuID), uint32(uniID), "", tpID); err != nil { |
| 2093 | logger.Warn(ctx, err) |
| 2094 | } |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2095 | default: |
| 2096 | logger.Errorw(ctx, "error-unknown-tech", |
| 2097 | log.Fields{ |
| 2098 | "techprofileInst": techprofileInst}) |
| Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 2099 | } |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2100 | |
| 2101 | // Free TPInstance, TPID, GemPorts and Traffic Queues. AllocID and Schedulers will be cleared later only if they are not shared across all the UNIs |
| 2102 | switch techprofileInst := techprofileInst.(type) { |
| 2103 | case *tp_pb.TechProfileInstance: |
| 2104 | for _, gemPort := range techprofileInst.UpstreamGemPortAttributeList { |
| 2105 | // Delete the gem port on the ONU. |
| 2106 | if sendDeleteGemRequest { |
| 2107 | if err := f.sendDeleteGemPortToChild(ctx, intfID, uint32(onuID), uint32(uniID), gemPort.GemportId, tpPath); err != nil { |
| 2108 | logger.Errorw(ctx, "error-processing-delete-gem-port-towards-onu", |
| 2109 | log.Fields{ |
| 2110 | "err": err, |
| 2111 | "intfID": intfID, |
| 2112 | "onu-id": onuID, |
| 2113 | "uni-id": uniID, |
| 2114 | "device-id": f.deviceHandler.device.Id, |
| 2115 | "gemport-id": gemPort.GemportId}) |
| 2116 | } |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2117 | f.resourceMgr.FreeGemPortID(ctx, uint32(onuID), uint32(uniID), gemPort.GemportId) |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2118 | } |
| 2119 | } |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2120 | // Delete the tp instance and the techprofileid for onu at the end |
| Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 2121 | if err := f.DeleteTechProfileInstance(ctx, intfID, uint32(onuID), uint32(uniID), "", tpID); err != nil { |
| 2122 | logger.Warn(ctx, err) |
| 2123 | } |
| 2124 | if err := f.resourceMgr.RemoveTechProfileIDForOnu(ctx, uint32(onuID), uint32(uniID), tpID); err != nil { |
| 2125 | logger.Warn(ctx, err) |
| 2126 | } |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2127 | } |
| 2128 | |
| Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2129 | return nil |
| 2130 | } |
| 2131 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2132 | // nolint: gocyclo |
| Sridhar Ravindra | d104e8d | 2025-06-02 13:04:49 +0530 | [diff] [blame] | 2133 | func (f *OpenOltFlowMgr) clearFlowFromDeviceAndResourceManager(ctx context.Context, flow *ofp.OfpFlowStats, flowDirection string, nni_port uint32) error { |
| balaji.nagarajan | 31db4ea | 2026-01-28 09:13:55 +0530 | [diff] [blame] | 2134 | logger.Debugw(ctx, "clear-flow-from-resource-manager", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2135 | log.Fields{ |
| 2136 | "flowDirection": flowDirection, |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 2137 | "flow-id": flow.Id, |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2138 | "device-id": f.deviceHandler.device.Id}) |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2139 | |
| 2140 | if flowDirection == Multicast { |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2141 | return f.clearMulticastFlowFromResourceManager(ctx, flow) |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2142 | } |
| 2143 | |
| Girish Gowdra | 5c00ef1 | 2021-12-01 17:19:41 +0530 | [diff] [blame] | 2144 | var ethType, ipProto, inPort uint32 |
| 2145 | for _, field := range flows.GetOfbFields(flow) { |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 2146 | switch field.Type { |
| 2147 | case flows.IP_PROTO: |
| Girish Gowdra | 5c00ef1 | 2021-12-01 17:19:41 +0530 | [diff] [blame] | 2148 | ipProto = field.GetIpProto() |
| 2149 | logger.Debugw(ctx, "field-type-ip-proto", log.Fields{"ipProto": ipProto}) |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 2150 | case flows.ETH_TYPE: |
| Girish Gowdra | 5c00ef1 | 2021-12-01 17:19:41 +0530 | [diff] [blame] | 2151 | ethType = field.GetEthType() |
| 2152 | logger.Debugw(ctx, "field-type-eth-type", log.Fields{"ethType": ethType}) |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 2153 | case flows.IN_PORT: |
| Girish Gowdra | 5c00ef1 | 2021-12-01 17:19:41 +0530 | [diff] [blame] | 2154 | inPort = field.GetPort() |
| 2155 | logger.Debugw(ctx, "field-type-in-port", log.Fields{"inPort": inPort}) |
| 2156 | } |
| 2157 | } |
| 2158 | portType := plt.IntfIDToPortTypeName(inPort) |
| 2159 | if (ethType == uint32(LldpEthType) || ipProto == uint32(IPProtoDhcp) || ipProto == uint32(IgmpProto)) && |
| 2160 | (portType == voltha.Port_ETHERNET_NNI) { |
| 2161 | removeFlowMessage := openoltpb2.Flow{FlowId: flow.Id, AccessIntfId: -1, OnuId: -1, UniId: -1, TechProfileId: 0, FlowType: Downstream} |
| 2162 | logger.Debugw(ctx, "nni-trap-flow-to-be-deleted", log.Fields{"flow": flow}) |
| 2163 | return f.removeFlowFromDevice(ctx, &removeFlowMessage, flow.Id) |
| 2164 | // No more processing needed for trap from nni flows. |
| 2165 | } |
| Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2166 | |
| Girish Gowdra | 5c00ef1 | 2021-12-01 17:19:41 +0530 | [diff] [blame] | 2167 | portNum, Intf, onu, uni, _, _, err := plt.FlowExtractInfo(ctx, flow, flowDirection) |
| Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2168 | if err != nil { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2169 | logger.Error(ctx, err) |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2170 | return err |
| Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2171 | } |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2172 | onuID := int32(onu) |
| 2173 | uniID := int32(uni) |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2174 | tpID, err := getTpIDFromFlow(ctx, flow) |
| 2175 | if err != nil { |
| 2176 | return olterrors.NewErrNotFound("tp-id", |
| 2177 | log.Fields{ |
| 2178 | "flow": flow, |
| 2179 | "intf-id": Intf, |
| 2180 | "onu-id": onuID, |
| 2181 | "uni-id": uniID, |
| 2182 | "device-id": f.deviceHandler.device.Id}, err) |
| 2183 | } |
| Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2184 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2185 | logger.Infow(ctx, "extracted-access-info-from-flow-to-be-deleted", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2186 | log.Fields{ |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2187 | "flow-id": flow.Id, |
| 2188 | "intf-id": Intf, |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2189 | "onu-id": onuID, |
| 2190 | "uni-id": uniID}) |
| Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2191 | |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2192 | removeFlowMessage := openoltpb2.Flow{FlowId: flow.Id, AccessIntfId: int32(Intf), OnuId: onuID, UniId: uniID, TechProfileId: tpID, FlowType: flowDirection} |
| 2193 | logger.Debugw(ctx, "flow-to-be-deleted", log.Fields{"flow": flow}) |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2194 | if err = f.removeFlowFromDevice(ctx, &removeFlowMessage, flow.Id); err != nil { |
| 2195 | return err |
| 2196 | } |
| Girish Gowdra | 82c8098 | 2021-03-26 16:22:02 -0700 | [diff] [blame] | 2197 | |
| Sridhar Ravindra | d104e8d | 2025-06-02 13:04:49 +0530 | [diff] [blame] | 2198 | if err = f.clearResources(ctx, Intf, onuID, uniID, flow.Id, portNum, tpID, true, nni_port); err != nil { |
| Gamze Abaka | 745ccb7 | 2021-11-18 11:29:58 +0000 | [diff] [blame] | 2199 | logger.Errorw(ctx, "failed-to-clear-resources-for-flow", log.Fields{ |
| 2200 | "flow-id": flow.Id, |
| 2201 | "device-id": f.deviceHandler.device.Id, |
| 2202 | "onu-id": onuID, |
| 2203 | "intf": Intf, |
| 2204 | "err": err, |
| 2205 | }) |
| 2206 | return err |
| Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2207 | } |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2208 | |
| Girish Gowdra | 82c8098 | 2021-03-26 16:22:02 -0700 | [diff] [blame] | 2209 | // Decrement reference count for the meter associated with the given <(pon_id, onu_id, uni_id)>/<tp_id>/meter_id/<direction> |
| balaji.nagarajan | 29be8bc | 2026-01-26 16:31:41 +0530 | [diff] [blame] | 2210 | if err := f.resourceMgr.HandleMeterInfoRefCntUpdate(ctx, nil, flowDirection, uint32(onuID), uint32(uniID), tpID, false); err != nil { |
| Girish Gowdra | 82c8098 | 2021-03-26 16:22:02 -0700 | [diff] [blame] | 2211 | return err |
| 2212 | } |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2213 | return nil |
| Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 2214 | } |
| 2215 | |
| Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 2216 | // RemoveFlow removes the flow from the device |
| Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2217 | func (f *OpenOltFlowMgr) RemoveFlow(ctx context.Context, flow *ofp.OfpFlowStats) error { |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 2218 | logger.Debugw(ctx, "removing-flow", log.Fields{"flow-id": flow.Id}) |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2219 | var direction string |
| 2220 | actionInfo := make(map[string]interface{}) |
| Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 2221 | |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2222 | for _, action := range flows.GetActions(flow) { |
| 2223 | if action.Type == flows.OUTPUT { |
| 2224 | if out := action.GetOutput(); out != nil { |
| 2225 | actionInfo[Output] = out.GetPort() |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2226 | logger.Debugw(ctx, "action-type-output", log.Fields{"out_port": actionInfo[Output].(uint32)}) |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2227 | } else { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2228 | logger.Error(ctx, "invalid-output-port-in-action") |
| Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2229 | return olterrors.NewErrInvalidValue(log.Fields{"invalid-out-port-action": 0}, nil) |
| Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 2230 | } |
| 2231 | } |
| 2232 | } |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2233 | |
| 2234 | if flows.HasGroup(flow) { |
| 2235 | direction = Multicast |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 2236 | } else if plt.IsUpstream(actionInfo[Output].(uint32)) { |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2237 | direction = Upstream |
| 2238 | } else { |
| 2239 | direction = Downstream |
| 2240 | } |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2241 | |
| Sridhar Ravindra | d104e8d | 2025-06-02 13:04:49 +0530 | [diff] [blame] | 2242 | var nni_port uint32 |
| 2243 | if direction == Upstream { |
| 2244 | if !plt.IsControllerBoundFlow(actionInfo[Output].(uint32)) { |
| 2245 | nni_port = actionInfo[Output].(uint32) & 0x1f // convert e.g. 16777220 to port 4 |
| 2246 | } |
| 2247 | } else { |
| 2248 | classifierInfo := make(map[string]interface{}) |
| 2249 | formulateClassifierInfoFromFlow(ctx, classifierInfo, flow) |
| 2250 | nni_port = classifierInfo[InPort].(uint32) & 0x1f // convert e.g. 16777220 to port 4 |
| 2251 | } |
| 2252 | |
| Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2253 | // Serialize flow removes on a per subscriber basis |
| Sridhar Ravindra | d104e8d | 2025-06-02 13:04:49 +0530 | [diff] [blame] | 2254 | err := f.clearFlowFromDeviceAndResourceManager(ctx, flow, direction, nni_port) |
| Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2255 | |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2256 | return err |
| Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 2257 | } |
| 2258 | |
| Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 2259 | // isIgmpTrapDownstreamFlow return true if the flow is a downsteam IGMP trap-to-host flow; false otherwise |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2260 | func isIgmpTrapDownstreamFlow(classifierInfo map[string]interface{}) bool { |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 2261 | if portType := plt.IntfIDToPortTypeName(classifierInfo[InPort].(uint32)); portType == voltha.Port_ETHERNET_NNI { |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2262 | if ethType, ok := classifierInfo[EthType]; ok { |
| 2263 | if ethType.(uint32) == IPv4EthType { |
| 2264 | if ipProto, ok := classifierInfo[IPProto]; ok { |
| 2265 | if ipProto.(uint32) == IgmpProto { |
| 2266 | return true |
| 2267 | } |
| 2268 | } |
| 2269 | } |
| 2270 | } |
| 2271 | } |
| 2272 | return false |
| 2273 | } |
| 2274 | |
| Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 2275 | // RouteFlowToOnuChannel routes incoming flow to ONU specific channel |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2276 | func (f *OpenOltFlowMgr) RouteFlowToOnuChannel(ctx context.Context, flow *ofp.OfpFlowStats, addFlow bool, flowMetadata *ofp.FlowMetadata) error { |
| Girish Gowdra | 20e3dcd | 2021-11-18 22:56:49 -0800 | [diff] [blame] | 2277 | if f.deviceHandler.getDeviceDeletionInProgressFlag() { |
| 2278 | // The device itself is going to be reset as part of deletion. So nothing to be done. |
| 2279 | logger.Infow(ctx, "device-deletion-in-progress--not-handling-flows-or-groups", log.Fields{"device-id": f.deviceHandler.device.Id}) |
| 2280 | return nil |
| 2281 | } |
| Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 2282 | // Step1 : Fill flowControlBlock |
| 2283 | // Step2 : Push the flowControlBlock to ONU channel |
| 2284 | // Step3 : Wait on response channel for response |
| 2285 | // Step4 : Return error value |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2286 | startTime := time.Now() |
| 2287 | logger.Infow(ctx, "process-flow", log.Fields{"flow": flow, "addFlow": addFlow}) |
| Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 2288 | errChan := make(chan error) |
| 2289 | flowCb := flowControlBlock{ |
| 2290 | ctx: ctx, |
| 2291 | addFlow: addFlow, |
| 2292 | flow: flow, |
| 2293 | flowMetadata: flowMetadata, |
| 2294 | errChan: &errChan, |
| 2295 | } |
| 2296 | inPort, outPort := getPorts(flow) |
| 2297 | var onuID uint32 |
| 2298 | if inPort != InvalidPort && outPort != InvalidPort { |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 2299 | _, _, onuID, _ = plt.ExtractAccessFromFlow(inPort, outPort) |
| Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 2300 | } |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2301 | if f.flowHandlerRoutineActive[onuID] { |
| 2302 | // inPort or outPort is InvalidPort for trap-from-nni flows. |
| 2303 | // In the that case onuID is 0 which is the reserved index for trap-from-nni flows in the f.incomingFlows slice |
| 2304 | // Send the flowCb on the ONU flow channel |
| 2305 | f.incomingFlows[onuID] <- flowCb |
| 2306 | // Wait on the channel for flow handlers return value |
| 2307 | err := <-errChan |
| balaji.nagarajan | 31db4ea | 2026-01-28 09:13:55 +0530 | [diff] [blame] | 2308 | logger.Debugw(ctx, "process-flow-received-resp", log.Fields{"err": err, "totalTimeSeconds": time.Since(startTime).Seconds()}) |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2309 | return err |
| 2310 | } |
| 2311 | logger.Errorw(ctx, "flow handler routine not active for onu", log.Fields{"onuID": onuID, "ponPortIdx": f.ponPortIdx}) |
| 2312 | return fmt.Errorf("flow-handler-routine-not-active-for-onu-%v-pon-%d", onuID, f.ponPortIdx) |
| Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 2313 | } |
| 2314 | |
| 2315 | // This routine is unique per ONU ID and blocks on flowControlBlock channel for incoming flows |
| 2316 | // Each incoming flow is processed in a synchronous manner, i.e., the flow is processed to completion before picking another |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2317 | func (f *OpenOltFlowMgr) perOnuFlowHandlerRoutine(handlerRoutineIndex int, subscriberFlowChannel chan flowControlBlock, stopHandler chan bool) { |
| Girish Gowdra | 20e3dcd | 2021-11-18 22:56:49 -0800 | [diff] [blame] | 2318 | var flowCb flowControlBlock |
| Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 2319 | for { |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2320 | select { |
| Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 2321 | // block on the channel to receive an incoming flow |
| 2322 | // process the flow completely before proceeding to handle the next flow |
| Girish Gowdra | 20e3dcd | 2021-11-18 22:56:49 -0800 | [diff] [blame] | 2323 | case flowCb = <-subscriberFlowChannel: |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2324 | if flowCb.addFlow { |
| balaji.nagarajan | 31db4ea | 2026-01-28 09:13:55 +0530 | [diff] [blame] | 2325 | logger.Debug(flowCb.ctx, "adding-flow-start") |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2326 | startTime := time.Now() |
| 2327 | err := f.AddFlow(flowCb.ctx, flowCb.flow, flowCb.flowMetadata) |
| balaji.nagarajan | 31db4ea | 2026-01-28 09:13:55 +0530 | [diff] [blame] | 2328 | logger.Infow(flowCb.ctx, "adding-flow-complete", log.Fields{"processTimeSecs": time.Since(startTime).Seconds(), "flow": flowCb.flow}) |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2329 | // Pass the return value over the return channel |
| 2330 | *flowCb.errChan <- err |
| 2331 | } else { |
| balaji.nagarajan | 31db4ea | 2026-01-28 09:13:55 +0530 | [diff] [blame] | 2332 | logger.Debug(flowCb.ctx, "removing-flow-start") |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2333 | startTime := time.Now() |
| 2334 | err := f.RemoveFlow(flowCb.ctx, flowCb.flow) |
| balaji.nagarajan | 31db4ea | 2026-01-28 09:13:55 +0530 | [diff] [blame] | 2335 | logger.Infow(flowCb.ctx, "removing-flow-complete", log.Fields{"processTimeSecs": time.Since(startTime).Seconds(), "flow": flowCb.flow}) |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2336 | // Pass the return value over the return channel |
| 2337 | *flowCb.errChan <- err |
| 2338 | } |
| 2339 | case <-stopHandler: |
| 2340 | f.flowHandlerRoutineActive[handlerRoutineIndex] = false |
| 2341 | return |
| Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 2342 | } |
| 2343 | } |
| 2344 | } |
| 2345 | |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2346 | // StopAllFlowHandlerRoutines stops all flow handler routines. Call this when device is being rebooted or deleted |
| Girish Gowdra | 20e3dcd | 2021-11-18 22:56:49 -0800 | [diff] [blame] | 2347 | func (f *OpenOltFlowMgr) StopAllFlowHandlerRoutines(ctx context.Context, wg *sync.WaitGroup) { |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2348 | for i, v := range f.stopFlowHandlerRoutine { |
| 2349 | if f.flowHandlerRoutineActive[i] { |
| Girish Gowdra | 20e3dcd | 2021-11-18 22:56:49 -0800 | [diff] [blame] | 2350 | select { |
| 2351 | case v <- true: |
| 2352 | case <-time.After(time.Second * 5): |
| 2353 | logger.Warnw(ctx, "timeout stopping flow handler routine", log.Fields{"onuID": i, "deviceID": f.deviceHandler.device.Id}) |
| 2354 | } |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2355 | } |
| Holger Hildebrandt | 143b5be | 2023-02-10 08:28:15 +0000 | [diff] [blame] | 2356 | f.stopFlowHandlerRoutine[i] = nil |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2357 | } |
| Holger Hildebrandt | 143b5be | 2023-02-10 08:28:15 +0000 | [diff] [blame] | 2358 | f.stopFlowHandlerRoutine = nil |
| 2359 | |
| 2360 | if f.incomingFlows != nil { |
| 2361 | for k := range f.incomingFlows { |
| 2362 | if f.incomingFlows[k] != nil { |
| 2363 | f.incomingFlows[k] = nil |
| 2364 | } |
| 2365 | } |
| 2366 | f.incomingFlows = nil |
| 2367 | } |
| 2368 | |
| Girish Gowdra | 20e3dcd | 2021-11-18 22:56:49 -0800 | [diff] [blame] | 2369 | wg.Done() |
| Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2370 | logger.Debugw(ctx, "stopped all flow handler routines", log.Fields{"ponPortIdx": f.ponPortIdx}) |
| 2371 | } |
| 2372 | |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2373 | // AddFlow add flow to device |
| Naga Manjunath | b8438aa | 2020-01-02 17:52:33 +0530 | [diff] [blame] | 2374 | // nolint: gocyclo |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2375 | func (f *OpenOltFlowMgr) AddFlow(ctx context.Context, flow *ofp.OfpFlowStats, flowMetadata *ofp.FlowMetadata) error { |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2376 | classifierInfo := make(map[string]interface{}) |
| 2377 | actionInfo := make(map[string]interface{}) |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 2378 | var UsMeterID uint32 |
| 2379 | var DsMeterID uint32 |
| 2380 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2381 | logger.Infow(ctx, "adding-flow", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2382 | log.Fields{ |
| 2383 | "flow": flow, |
| Matteo Scandolo | f16389e | 2021-05-18 00:47:08 +0000 | [diff] [blame] | 2384 | "flowmetadata": flowMetadata}) |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2385 | formulateClassifierInfoFromFlow(ctx, classifierInfo, flow) |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2386 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2387 | err := formulateActionInfoFromFlow(ctx, actionInfo, classifierInfo, flow) |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2388 | if err != nil { |
| 2389 | // Error logging is already done in the called function |
| 2390 | // So just return in case of error |
| Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2391 | return err |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 2392 | } |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2393 | |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2394 | if flows.HasGroup(flow) { |
| 2395 | // handle multicast flow |
| Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2396 | return f.handleFlowWithGroup(ctx, actionInfo, classifierInfo, flow) |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2397 | } |
| 2398 | |
| manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 2399 | /* Controller bound trap flows */ |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2400 | err = formulateControllerBoundTrapFlowInfo(ctx, actionInfo, classifierInfo, flow) |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2401 | if err != nil { |
| 2402 | // error if any, already logged in the called function |
| Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2403 | return err |
| manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 2404 | } |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2405 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2406 | logger.Debugw(ctx, "flow-ports", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2407 | log.Fields{ |
| 2408 | "classifierinfo_inport": classifierInfo[InPort], |
| 2409 | "action_output": actionInfo[Output]}) |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 2410 | portNo, intfID, onuID, uniID := plt.ExtractAccessFromFlow(classifierInfo[InPort].(uint32), actionInfo[Output].(uint32)) |
| A R Karthick | 1f85b80 | 2019-10-11 05:06:05 +0000 | [diff] [blame] | 2411 | |
| Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 2412 | if ethType, ok := classifierInfo[EthType]; ok { |
| 2413 | if ethType.(uint32) == LldpEthType { |
| balaji.nagarajan | 31db4ea | 2026-01-28 09:13:55 +0530 | [diff] [blame] | 2414 | logger.Debug(ctx, "adding-lldp-flow") |
| Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2415 | return f.addLLDPFlow(ctx, flow, portNo) |
| Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 2416 | } |
| Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 2417 | if ethType.(uint32) == PPPoEDEthType { |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 2418 | if voltha.Port_ETHERNET_NNI == plt.IntfIDToPortTypeName(classifierInfo[InPort].(uint32)) { |
| Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 2419 | logger.Debug(ctx, "trap-pppoed-from-nni-flow") |
| 2420 | return f.addTrapFlowOnNNI(ctx, flow, classifierInfo, portNo) |
| 2421 | } |
| 2422 | } |
| Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 2423 | } |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2424 | if ipProto, ok := classifierInfo[IPProto]; ok { |
| 2425 | if ipProto.(uint32) == IPProtoDhcp { |
| 2426 | if udpSrc, ok := classifierInfo[UDPSrc]; ok { |
| Naga Manjunath | b8438aa | 2020-01-02 17:52:33 +0530 | [diff] [blame] | 2427 | if udpSrc.(uint32) == uint32(67) || udpSrc.(uint32) == uint32(546) { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2428 | logger.Debug(ctx, "trap-dhcp-from-nni-flow") |
| Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 2429 | return f.addTrapFlowOnNNI(ctx, flow, classifierInfo, portNo) |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2430 | } |
| 2431 | } |
| 2432 | } |
| 2433 | } |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2434 | if isIgmpTrapDownstreamFlow(classifierInfo) { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2435 | logger.Debug(ctx, "trap-igmp-from-nni-flow") |
| Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2436 | return f.addIgmpTrapFlowOnNNI(ctx, flow, classifierInfo, portNo) |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2437 | } |
| A R Karthick | 1f85b80 | 2019-10-11 05:06:05 +0000 | [diff] [blame] | 2438 | |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2439 | f.resourceMgr.AddUniPortToOnuInfo(ctx, onuID, portNo) |
| A R Karthick | 1f85b80 | 2019-10-11 05:06:05 +0000 | [diff] [blame] | 2440 | |
| Girish Gowdra | 6071f38 | 2021-12-14 12:52:04 +0530 | [diff] [blame] | 2441 | tpID, err := getTpIDFromFlow(ctx, flow) |
| Chaitrashree G S | 90a1795 | 2019-11-14 21:51:21 -0500 | [diff] [blame] | 2442 | if err != nil { |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2443 | return olterrors.NewErrNotFound("tpid-for-flow", |
| 2444 | log.Fields{ |
| 2445 | "flow": flow, |
| 2446 | "intf-id": IntfID, |
| 2447 | "onu-id": onuID, |
| 2448 | "uni-id": uniID}, err) |
| Chaitrashree G S | 90a1795 | 2019-11-14 21:51:21 -0500 | [diff] [blame] | 2449 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2450 | logger.Debugw(ctx, "tpid-for-this-subcriber", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2451 | log.Fields{ |
| Girish Gowdra | 6071f38 | 2021-12-14 12:52:04 +0530 | [diff] [blame] | 2452 | "tp-id": tpID, |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2453 | "intf-id": intfID, |
| 2454 | "onu-id": onuID, |
| 2455 | "uni-id": uniID}) |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 2456 | if plt.IsUpstream(actionInfo[Output].(uint32)) { |
| Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 2457 | UsMeterID = flows.GetMeterIdFromFlow(flow) |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2458 | logger.Debugw(ctx, "upstream-flow-meter-id", log.Fields{"us-meter-id": UsMeterID}) |
| Girish Gowdra | 6071f38 | 2021-12-14 12:52:04 +0530 | [diff] [blame] | 2459 | if err := f.validateMeter(ctx, Upstream, UsMeterID, intfID, onuID, uniID, tpID); err != nil { |
| 2460 | logger.Errorw(ctx, "meter-validation-failed", log.Fields{"err": err}) |
| 2461 | return err |
| 2462 | } |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 2463 | } else { |
| Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 2464 | DsMeterID = flows.GetMeterIdFromFlow(flow) |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2465 | logger.Debugw(ctx, "downstream-flow-meter-id", log.Fields{"ds-meter-id": DsMeterID}) |
| Girish Gowdra | 6071f38 | 2021-12-14 12:52:04 +0530 | [diff] [blame] | 2466 | if err := f.validateMeter(ctx, Downstream, DsMeterID, intfID, onuID, uniID, tpID); err != nil { |
| 2467 | logger.Errorw(ctx, "meter-validation-failed", log.Fields{"err": err}) |
| 2468 | return err |
| 2469 | } |
| Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 2470 | } |
| Sridhar Ravindra | d104e8d | 2025-06-02 13:04:49 +0530 | [diff] [blame] | 2471 | |
| 2472 | var nni_port uint32 |
| 2473 | if plt.IsUpstream(actionInfo[Output].(uint32)) { |
| 2474 | if !plt.IsControllerBoundFlow(actionInfo[Output].(uint32)) { |
| 2475 | nni_port = actionInfo[Output].(uint32) & 0x1f // convert e.g. 16777220 to port 4 |
| 2476 | } |
| 2477 | } else { |
| 2478 | nni_port = classifierInfo[InPort].(uint32) & 0x1f // convert e.g. 16777220 to port 4 |
| 2479 | } |
| 2480 | |
| 2481 | return f.processAddFlow(ctx, intfID, nni_port, onuID, uniID, portNo, classifierInfo, actionInfo, flow, tpID, UsMeterID, DsMeterID, flowMetadata) |
| Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 2482 | } |
| Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 2483 | |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2484 | // handleFlowWithGroup adds multicast flow to the device. |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2485 | func (f *OpenOltFlowMgr) handleFlowWithGroup(ctx context.Context, actionInfo, classifierInfo map[string]interface{}, flow *ofp.OfpFlowStats) error { |
| Himani Chawla | b6296c4 | 2021-10-28 11:50:56 +0530 | [diff] [blame] | 2486 | classifierInfo[PacketTagType] = getPacketTypeFromClassifiers(classifierInfo) |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2487 | logger.Debugw(ctx, "add-multicast-flow", log.Fields{ |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2488 | "classifier-info": classifierInfo, |
| 2489 | "actionInfo": actionInfo}) |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2490 | |
| Esin Karaman | 65409d8 | 2020-03-18 10:58:18 +0000 | [diff] [blame] | 2491 | networkInterfaceID, err := f.getNNIInterfaceIDOfMulticastFlow(ctx, classifierInfo) |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2492 | if err != nil { |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2493 | return olterrors.NewErrNotFound("multicast-in-port", log.Fields{"classifier": classifierInfo}, err) |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2494 | } |
| Esin Karaman | fcddfcf | 2020-03-04 13:34:38 +0000 | [diff] [blame] | 2495 | |
| Esin Karaman | fcddfcf | 2020-03-04 13:34:38 +0000 | [diff] [blame] | 2496 | delete(classifierInfo, EthType) |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2497 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2498 | onuID := NoneOnuID |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2499 | |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2500 | present, err := f.resourceMgr.IsFlowOnKvStore(ctx, int32(onuID), flow.Id) |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 2501 | if present { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2502 | logger.Infow(ctx, "multicast-flow-exists-not-re-adding", log.Fields{"classifier-info": classifierInfo}) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2503 | return nil |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 2504 | } else if err != nil { |
| 2505 | logger.Errorw(ctx, "aborting-handleFlowWithGroup--flow-may-already-exist", |
| 2506 | log.Fields{"intf-id": networkInterfaceID, "onu-id": onuID, "flow-id": flow.Id}) |
| 2507 | return err |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2508 | } |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 2509 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2510 | classifierProto, err := makeOpenOltClassifierField(classifierInfo) |
| 2511 | if err != nil { |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2512 | return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifierInfo}, err) |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2513 | } |
| 2514 | groupID := actionInfo[GroupID].(uint32) |
| 2515 | multicastFlow := openoltpb2.Flow{ |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2516 | FlowId: flow.Id, |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2517 | FlowType: Multicast, |
| 2518 | NetworkIntfId: int32(networkInterfaceID), |
| 2519 | GroupId: groupID, |
| 2520 | Classifier: classifierProto, |
| 2521 | Priority: int32(flow.Priority), |
| 2522 | Cookie: flow.Cookie} |
| 2523 | |
| Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 2524 | if err := f.addFlowToDevice(ctx, flow, &multicastFlow); err != nil { |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 2525 | return olterrors.NewErrFlowOp("add", flow.Id, log.Fields{"flow-id": multicastFlow.FlowId}, err) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2526 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2527 | logger.Info(ctx, "multicast-flow-added-to-device-successfully") |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2528 | // get cached group |
| Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 2529 | if group, _, err := f.grpMgr.getFlowGroupFromKVStore(ctx, groupID, true); err == nil { |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2530 | // calling groupAdd to set group members after multicast flow creation |
| Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 2531 | if err := f.grpMgr.ModifyGroup(ctx, group); err != nil { |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2532 | return olterrors.NewErrGroupOp("modify", groupID, log.Fields{"group": group}, err) |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2533 | } |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2534 | // cached group can be removed now |
| Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 2535 | if err := f.resourceMgr.RemoveFlowGroupFromKVStore(ctx, groupID, true); err != nil { |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2536 | logger.Warnw(ctx, "failed-to-remove-flow-group", log.Fields{"group-id": groupID, "err": err}) |
| Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 2537 | } |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2538 | } |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2539 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2540 | return nil |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2541 | } |
| 2542 | |
| Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 2543 | // getNNIInterfaceIDOfMulticastFlow returns associated NNI interface id of the inPort criterion if exists; returns the first NNI interface of the device otherwise |
| Esin Karaman | 65409d8 | 2020-03-18 10:58:18 +0000 | [diff] [blame] | 2544 | func (f *OpenOltFlowMgr) getNNIInterfaceIDOfMulticastFlow(ctx context.Context, classifierInfo map[string]interface{}) (uint32, error) { |
| 2545 | if inPort, ok := classifierInfo[InPort]; ok { |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 2546 | nniInterfaceID, err := plt.IntfIDFromNniPortNum(ctx, inPort.(uint32)) |
| Esin Karaman | 65409d8 | 2020-03-18 10:58:18 +0000 | [diff] [blame] | 2547 | if err != nil { |
| 2548 | return 0, olterrors.NewErrInvalidValue(log.Fields{"nni-in-port-number": inPort}, err) |
| 2549 | } |
| 2550 | return nniInterfaceID, nil |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2551 | } |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2552 | |
| 2553 | // TODO: For now we support only one NNI port in VOLTHA. We shall use only the first NNI port, i.e., interface-id 0. |
| 2554 | return 0, nil |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2555 | } |
| 2556 | |
| Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 2557 | // sendTPDownloadMsgToChild send payload |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 2558 | func (f *OpenOltFlowMgr) sendTPDownloadMsgToChild(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, uni string, TpID uint32, tpInst *tp_pb.TechProfileInstance) error { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2559 | onuDev, err := f.getOnuDevice(ctx, intfID, onuID) |
| Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 2560 | if err != nil { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2561 | logger.Errorw(ctx, "couldnt-find-onu-child-device", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2562 | log.Fields{ |
| 2563 | "intf-id": intfID, |
| 2564 | "onu-id": onuID, |
| 2565 | "uni-id": uniID}) |
| Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 2566 | return err |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 2567 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2568 | logger.Debugw(ctx, "got-child-device-from-olt-device-handler", log.Fields{"onu-id": onuDev.deviceID}) |
| manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 2569 | |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2570 | tpPath := f.getTPpath(ctx, uni, TpID) |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2571 | tpDownloadMsg := &ia.TechProfileDownloadMessage{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2572 | DeviceId: onuDev.deviceID, |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2573 | UniId: uniID, |
| 2574 | TpInstancePath: tpPath, |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 2575 | TechTpInstance: &ia.TechProfileDownloadMessage_TpInstance{TpInstance: tpInst}, |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2576 | } |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 2577 | logger.Debugw(ctx, "sending-load-tech-profile-request-to-brcm-onu-adapter", log.Fields{"tpDownloadMsg": tpDownloadMsg.String()}) |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2578 | |
| 2579 | err = f.deviceHandler.sendDownloadTechProfileToChildAdapter(ctx, onuDev.adapterEndpoint, tpDownloadMsg) |
| 2580 | if err != nil { |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2581 | return olterrors.NewErrCommunication("send-techprofile-download-request", |
| 2582 | log.Fields{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2583 | "from-adapter": f.deviceHandler.openOLT.config.AdapterEndpoint, |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2584 | "to-adapter": onuDev.deviceType, |
| 2585 | "onu-id": onuDev.deviceID, |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2586 | "proxyDeviceID": onuDev.proxyDeviceID}, err) |
| manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 2587 | } |
| balaji.nagarajan | 31db4ea | 2026-01-28 09:13:55 +0530 | [diff] [blame] | 2588 | logger.Debugw(ctx, "success-sending-load-tech-profile-request-to-brcm-onu-adapter", log.Fields{"tpid": TpID}) |
| Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 2589 | return nil |
| manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 2590 | } |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2591 | |
| Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 2592 | // GetLogicalPortFromPacketIn function computes logical port UNI/NNI port from packet-in indication and returns the same |
| npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2593 | func (f *OpenOltFlowMgr) GetLogicalPortFromPacketIn(ctx context.Context, packetIn *openoltpb2.PacketIndication) (uint32, error) { |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2594 | var logicalPortNum uint32 |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2595 | |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 2596 | switch packetIn.IntfType { |
| 2597 | case "pon": |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2598 | // packet indication does not have serial number , so sending as nil |
| Esin Karaman | df392e1 | 2020-12-16 13:33:09 +0000 | [diff] [blame] | 2599 | // get onu and uni ids associated with the given pon and gem ports |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2600 | onuID, uniID := packetIn.OnuId, packetIn.UniId |
| 2601 | logger.Debugf(ctx, "retrieved ONU and UNI IDs [%d, %d] by interface:%d, gem:%d", packetIn.OnuId, packetIn.UniId, packetIn.GemportId) |
| Esin Karaman | df392e1 | 2020-12-16 13:33:09 +0000 | [diff] [blame] | 2602 | |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2603 | if packetIn.PortNo != 0 { |
| 2604 | logicalPortNum = packetIn.PortNo |
| 2605 | } else { |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 2606 | logicalPortNum = plt.MkUniPortNum(ctx, packetIn.IntfId, onuID, uniID) |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2607 | } |
| 2608 | // Store the gem port through which the packet_in came. Use the same gem port for packet_out |
| Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 2609 | f.UpdateGemPortForPktIn(ctx, packetIn.IntfId, onuID, logicalPortNum, packetIn.GemportId, packetIn.Pkt) |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 2610 | case "nni": |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 2611 | logicalPortNum = plt.IntfIDToPortNo(packetIn.IntfId, voltha.Port_ETHERNET_NNI) |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2612 | } |
| Girish Gowdra | eb45029 | 2020-10-26 10:03:39 -0700 | [diff] [blame] | 2613 | |
| 2614 | if logger.V(log.DebugLevel) { |
| 2615 | logger.Debugw(ctx, "retrieved-logicalport-from-packet-in", |
| 2616 | log.Fields{ |
| 2617 | "logical-port-num": logicalPortNum, |
| 2618 | "intf-type": packetIn.IntfType, |
| 2619 | "packet": hex.EncodeToString(packetIn.Pkt), |
| 2620 | }) |
| 2621 | } |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2622 | return logicalPortNum, nil |
| 2623 | } |
| 2624 | |
| Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 2625 | // GetPacketOutGemPortID returns gemPortId |
| Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 2626 | func (f *OpenOltFlowMgr) GetPacketOutGemPortID(ctx context.Context, intfID uint32, onuID uint32, portNum uint32, packet []byte) (uint32, error) { |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2627 | var gemPortID uint32 |
| Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 2628 | |
| 2629 | ctag, priority, err := getCTagFromPacket(ctx, packet) |
| 2630 | if err != nil { |
| 2631 | return 0, err |
| 2632 | } |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2633 | |
| Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 2634 | pktInkey := rsrcMgr.PacketInInfoKey{IntfID: intfID, OnuID: onuID, LogicalPort: portNum, VlanID: ctag, Priority: priority} |
| Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 2635 | var ok bool |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2636 | f.packetInGemPortLock.RLock() |
| Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 2637 | gemPortID, ok = f.packetInGemPort[pktInkey] |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2638 | f.packetInGemPortLock.RUnlock() |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2639 | if ok { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2640 | logger.Debugw(ctx, "found-gemport-for-pktin-key", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2641 | log.Fields{ |
| 2642 | "pktinkey": pktInkey, |
| 2643 | "gem": gemPortID}) |
| Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 2644 | |
| 2645 | return gemPortID, nil |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2646 | } |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2647 | // If gem is not found in cache try to get it from kv store, if found in kv store, update the cache and return. |
| Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 2648 | gemPortID, err = f.resourceMgr.GetGemPortFromOnuPktIn(ctx, pktInkey) |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2649 | if err == nil { |
| 2650 | if gemPortID != 0 { |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2651 | f.packetInGemPortLock.Lock() |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2652 | f.packetInGemPort[pktInkey] = gemPortID |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2653 | f.packetInGemPortLock.Unlock() |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2654 | logger.Infow(ctx, "found-gem-port-from-kv-store-and-updating-cache-with-gemport", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2655 | log.Fields{ |
| 2656 | "pktinkey": pktInkey, |
| 2657 | "gem": gemPortID}) |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2658 | return gemPortID, nil |
| 2659 | } |
| 2660 | } |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2661 | return uint32(0), olterrors.NewErrNotFound("gem-port", |
| 2662 | log.Fields{ |
| 2663 | "pktinkey": pktInkey, |
| 2664 | "gem": gemPortID}, err) |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2665 | } |
| 2666 | |
| Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 2667 | func (f *OpenOltFlowMgr) addTrapFlowOnNNI(ctx context.Context, logicalFlow *ofp.OfpFlowStats, classifier map[string]interface{}, portNo uint32) error { |
| 2668 | logger.Debug(ctx, "adding-trap-of-nni-flow") |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2669 | action := make(map[string]interface{}) |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2670 | classifier[PacketTagType] = DoubleTag |
| 2671 | action[TrapToHost] = true |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2672 | /* We manage flowId resource pool on per PON port basis. |
| 2673 | Since this situation is tricky, as a hack, we pass the NNI port |
| 2674 | index (network_intf_id) as PON port Index for the flowId resource |
| Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 2675 | pool. Also, there is no ONU Id available for trapping packets |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2676 | on NNI port, use onu_id as -1 (invalid) |
| 2677 | ****************** CAVEAT ******************* |
| 2678 | This logic works if the NNI Port Id falls within the same valid |
| 2679 | range of PON Port Ids. If this doesn't work for some OLT Vendor |
| 2680 | we need to have a re-look at this. |
| 2681 | ********************************************* |
| 2682 | */ |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2683 | onuID := -1 |
| 2684 | uniID := -1 |
| 2685 | gemPortID := -1 |
| 2686 | allocID := -1 |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2687 | networkInterfaceID, err := getNniIntfID(ctx, classifier, action) |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2688 | if err != nil { |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2689 | return olterrors.NewErrNotFound("nni-intreface-id", |
| 2690 | log.Fields{ |
| 2691 | "classifier": classifier, |
| 2692 | "action": action}, |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2693 | err) |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2694 | } |
| 2695 | |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2696 | present, err := f.resourceMgr.IsFlowOnKvStore(ctx, int32(onuID), logicalFlow.Id) |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 2697 | if present { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2698 | logger.Info(ctx, "flow-exists-not-re-adding") |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2699 | return nil |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 2700 | } else if err != nil { |
| 2701 | logger.Errorw(ctx, "aborting-addTrapFlowOnNNI--flow-may-already-exist", |
| 2702 | log.Fields{"intf-id": networkInterfaceID, "onu-id": onuID, "flow-id": logicalFlow.Id}) |
| 2703 | return err |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2704 | } |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2705 | |
| Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 2706 | logger.Debugw(ctx, "creating-trap-of-nni-flow", |
| 2707 | log.Fields{ |
| 2708 | "classifier": classifier, |
| 2709 | "action": action, |
| 2710 | "flowId": logicalFlow.Id, |
| 2711 | "intf-id": networkInterfaceID}) |
| 2712 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2713 | classifierProto, err := makeOpenOltClassifierField(classifier) |
| 2714 | if err != nil { |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2715 | return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifier}, err) |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2716 | } |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 2717 | logger.Debugw(ctx, "created-classifier-proto", log.Fields{"classifier": classifierProto.String()}) |
| Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 2718 | actionProto, err := makeOpenOltActionField(action, classifier) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2719 | if err != nil { |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2720 | return olterrors.NewErrInvalidValue(log.Fields{"action": action}, err) |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2721 | } |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 2722 | logger.Debugw(ctx, "created-action-proto", log.Fields{"action": actionProto.String()}) |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2723 | downstreamflow := openoltpb2.Flow{AccessIntfId: int32(-1), // AccessIntfId not required |
| 2724 | OnuId: int32(onuID), // OnuId not required |
| 2725 | UniId: int32(uniID), // UniId not used |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2726 | FlowId: logicalFlow.Id, |
| David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 2727 | FlowType: Downstream, |
| Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2728 | AllocId: int32(allocID), // AllocId not used |
| 2729 | NetworkIntfId: int32(networkInterfaceID), |
| 2730 | GemportId: int32(gemPortID), // GemportId not used |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2731 | Classifier: classifierProto, |
| 2732 | Action: actionProto, |
| 2733 | Priority: int32(logicalFlow.Priority), |
| 2734 | Cookie: logicalFlow.Cookie, |
| 2735 | PortNo: portNo} |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2736 | if err := f.addFlowToDevice(ctx, logicalFlow, &downstreamflow); err != nil { |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 2737 | return olterrors.NewErrFlowOp("add", logicalFlow.Id, log.Fields{"flow-id": downstreamflow.FlowId}, err) |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2738 | } |
| Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 2739 | logger.Info(ctx, "trap-on-nni-flow-added–to-device-successfully") |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2740 | return nil |
| manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2741 | } |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2742 | |
| Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 2743 | // getPacketTypeFromClassifiers finds and returns packet type of a flow by checking flow classifiers |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2744 | func getPacketTypeFromClassifiers(classifierInfo map[string]interface{}) string { |
| 2745 | var packetType string |
| 2746 | ovid, ivid := false, false |
| 2747 | if vlanID, ok := classifierInfo[VlanVid].(uint32); ok { |
| 2748 | vid := vlanID & VlanvIDMask |
| 2749 | if vid != ReservedVlan { |
| 2750 | ovid = true |
| 2751 | } |
| 2752 | } |
| Girish Gowdra | b23f1de | 2022-03-24 12:01:17 -0700 | [diff] [blame] | 2753 | |
| 2754 | // The classifierInfo[Metadata] is set for the following flows |
| 2755 | // - In the Downstream datapath flow table0 and table1. From the OLT perspective, only table0 downstream flow is relevant. |
| 2756 | // - Mcast flow that points to a group in the action/treatment |
| 2757 | // This value, when present and valid (not 0 and not 4096), is interpreted as below |
| 2758 | // - inner vid for a double tagged packet in the datapath flow |
| 2759 | // - outer vid for a single tagged packet in the datapath flow |
| 2760 | // - inner vid in the mcast flow that points to a group |
| 2761 | |
| 2762 | // It is to be noted though that for DT FTTH downstream table0 flow, the classifierInfo[Metadata] is absent. |
| 2763 | // And consequently the ivid is not set to true. This will result in packetType being set to singleTag which is not true |
| 2764 | // Interestingly enough, this function `getPacketTypeFromClassifiers` is called only by Mcast flow handlers and |
| 2765 | // it is to be used with caution elsewhere as it could result in wrong packetType to be returned to the caller. |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2766 | if metadata, ok := classifierInfo[Metadata].(uint64); ok { |
| 2767 | vid := uint32(metadata) |
| 2768 | if vid != ReservedVlan { |
| 2769 | ivid = true |
| 2770 | } |
| 2771 | } |
| 2772 | if ovid && ivid { |
| 2773 | packetType = DoubleTag |
| 2774 | } else if !ovid && !ivid { |
| 2775 | packetType = Untagged |
| 2776 | } else { |
| 2777 | packetType = SingleTag |
| 2778 | } |
| 2779 | return packetType |
| 2780 | } |
| 2781 | |
| Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 2782 | // addIgmpTrapFlowOnNNI adds a trap-to-host flow on NNI |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2783 | func (f *OpenOltFlowMgr) addIgmpTrapFlowOnNNI(ctx context.Context, logicalFlow *ofp.OfpFlowStats, classifier map[string]interface{}, portNo uint32) error { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2784 | logger.Infow(ctx, "adding-igmp-trap-of-nni-flow", log.Fields{"classifier-info": classifier}) |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2785 | action := make(map[string]interface{}) |
| 2786 | classifier[PacketTagType] = getPacketTypeFromClassifiers(classifier) |
| 2787 | action[TrapToHost] = true |
| 2788 | /* We manage flowId resource pool on per PON port basis. |
| 2789 | Since this situation is tricky, as a hack, we pass the NNI port |
| 2790 | index (network_intf_id) as PON port Index for the flowId resource |
| 2791 | pool. Also, there is no ONU Id available for trapping packets |
| 2792 | on NNI port, use onu_id as -1 (invalid) |
| 2793 | ****************** CAVEAT ******************* |
| 2794 | This logic works if the NNI Port Id falls within the same valid |
| 2795 | range of PON Port Ids. If this doesn't work for some OLT Vendor |
| 2796 | we need to have a re-look at this. |
| 2797 | ********************************************* |
| 2798 | */ |
| 2799 | onuID := -1 |
| 2800 | uniID := -1 |
| 2801 | gemPortID := -1 |
| 2802 | allocID := -1 |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2803 | networkInterfaceID, err := getNniIntfID(ctx, classifier, action) |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2804 | if err != nil { |
| Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 2805 | return olterrors.NewErrNotFound("nni-interface-id", log.Fields{ |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2806 | "classifier": classifier, |
| 2807 | "action": action}, |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2808 | err) |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2809 | } |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2810 | present, err := f.resourceMgr.IsFlowOnKvStore(ctx, int32(onuID), logicalFlow.Id) |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 2811 | if present { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2812 | logger.Info(ctx, "igmp-flow-exists-not-re-adding") |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2813 | return nil |
| yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 2814 | } else if err != nil { |
| 2815 | logger.Errorw(ctx, "aborting-addIgmpTrapFlowOnNNI--flow-may-already-exist", |
| 2816 | log.Fields{"intf-id": networkInterfaceID, "onu-id": onuID, "flow-id": logicalFlow.Id}) |
| 2817 | return err |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2818 | } |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2819 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2820 | classifierProto, err := makeOpenOltClassifierField(classifier) |
| 2821 | if err != nil { |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2822 | return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifier}, err) |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2823 | } |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 2824 | logger.Debugw(ctx, "created-classifier-proto-for-the-igmp-flow", log.Fields{"classifier": classifierProto.String()}) |
| Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 2825 | actionProto, err := makeOpenOltActionField(action, classifier) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2826 | if err != nil { |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2827 | return olterrors.NewErrInvalidValue(log.Fields{"action": action}, err) |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2828 | } |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 2829 | logger.Debugw(ctx, "created-action-proto-for-the-igmp-flow", log.Fields{"action": actionProto.String()}) |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2830 | downstreamflow := openoltpb2.Flow{AccessIntfId: int32(-1), // AccessIntfId not required |
| 2831 | OnuId: int32(onuID), // OnuId not required |
| 2832 | UniId: int32(uniID), // UniId not used |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2833 | FlowId: logicalFlow.Id, |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2834 | FlowType: Downstream, |
| 2835 | AllocId: int32(allocID), // AllocId not used |
| 2836 | NetworkIntfId: int32(networkInterfaceID), |
| 2837 | GemportId: int32(gemPortID), // GemportId not used |
| 2838 | Classifier: classifierProto, |
| 2839 | Action: actionProto, |
| 2840 | Priority: int32(logicalFlow.Priority), |
| 2841 | Cookie: logicalFlow.Cookie, |
| 2842 | PortNo: portNo} |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2843 | if err := f.addFlowToDevice(ctx, logicalFlow, &downstreamflow); err != nil { |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 2844 | return olterrors.NewErrFlowOp("add", logicalFlow.Id, log.Fields{"flow-id": downstreamflow.FlowId}, err) |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2845 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2846 | logger.Info(ctx, "igmp-trap-on-nni-flow-added-to-device-successfully") |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2847 | |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2848 | return nil |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2849 | } |
| 2850 | |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2851 | func verifyMeterIDAndGetDirection(MeterID uint32, Dir tp_pb.Direction) (string, error) { |
| 2852 | if MeterID == 0 { // This should never happen |
| Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 2853 | return "", olterrors.NewErrInvalidValue(log.Fields{"meter-id": MeterID}, nil).Log() |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2854 | } |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 2855 | switch Dir { |
| 2856 | case tp_pb.Direction_UPSTREAM: |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2857 | return "upstream", nil |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 2858 | case tp_pb.Direction_DOWNSTREAM: |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2859 | return "downstream", nil |
| 2860 | } |
| 2861 | return "", nil |
| 2862 | } |
| 2863 | |
| Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 2864 | // nolint: gocyclo |
| npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2865 | func (f *OpenOltFlowMgr) checkAndAddFlow(ctx context.Context, args map[string]uint32, classifierInfo map[string]interface{}, |
| Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 2866 | actionInfo map[string]interface{}, flow *ofp.OfpFlowStats, TpInst interface{}, gemPorts []uint32, |
| Gamze Abaka | 6d0a64f | 2021-11-18 08:08:33 +0000 | [diff] [blame] | 2867 | tpID uint32, uni string) error { |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2868 | var gemPortID uint32 |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 2869 | intfID := args[IntfID] |
| 2870 | onuID := args[OnuID] |
| 2871 | uniID := args[UniID] |
| 2872 | portNo := args[PortNo] |
| Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 2873 | allocID := args[AllocID] |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2874 | pbitToGem := make(map[uint32]uint32) |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2875 | gemToAes := make(map[uint32]bool) |
| 2876 | |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2877 | var attributes []*tp_pb.GemPortAttributes |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2878 | var direction = tp_pb.Direction_UPSTREAM |
| 2879 | switch TpInst := TpInst.(type) { |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2880 | case *tp_pb.TechProfileInstance: |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 2881 | if plt.IsUpstream(actionInfo[Output].(uint32)) { |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2882 | attributes = TpInst.UpstreamGemPortAttributeList |
| 2883 | } else { |
| 2884 | attributes = TpInst.DownstreamGemPortAttributeList |
| 2885 | direction = tp_pb.Direction_DOWNSTREAM |
| 2886 | } |
| 2887 | default: |
| 2888 | logger.Errorw(ctx, "unsupported-tech", log.Fields{"tpInst": TpInst}) |
| Gamze Abaka | 6d0a64f | 2021-11-18 08:08:33 +0000 | [diff] [blame] | 2889 | return olterrors.NewErrInvalidValue(log.Fields{"tpInst": TpInst}, nil) |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2890 | } |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2891 | |
| 2892 | if len(gemPorts) == 1 { |
| 2893 | // If there is only single gemport use that and do not populate pbitToGem map |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2894 | gemPortID = gemPorts[0] |
| 2895 | gemToAes[gemPortID], _ = strconv.ParseBool(attributes[0].AesEncryption) |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2896 | } else if pcp, ok := classifierInfo[VlanPcp]; !ok { |
| 2897 | for idx, gemID := range gemPorts { |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2898 | pBitMap := attributes[idx].PbitMap |
| 2899 | // Trim the bitMapPrefix form the binary string and then iterate each character in the binary string. |
| 2900 | // If the character is set to pbit1, extract the pcp value from the position of this character in the string. |
| 2901 | // Update the pbitToGem map with key being the pcp bit and the value being the gemPortID that consumes |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2902 | // this pcp bit traffca. |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2903 | for pos, pbitSet := range strings.TrimPrefix(pBitMap, bitMapPrefix) { |
| 2904 | if pbitSet == pbit1 { |
| 2905 | pcp := uint32(len(strings.TrimPrefix(pBitMap, bitMapPrefix))) - 1 - uint32(pos) |
| 2906 | pbitToGem[pcp] = gemID |
| 2907 | gemToAes[gemID], _ = strconv.ParseBool(attributes[idx].AesEncryption) |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2908 | } |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2909 | } |
| 2910 | } |
| 2911 | } else { // Extract the exact gemport which maps to the PCP classifier in the flow |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2912 | if gem := f.techprofile.GetGemportForPbit(ctx, TpInst, direction, pcp.(uint32)); gem != nil { |
| 2913 | gemPortID = gem.(*tp_pb.GemPortAttributes).GemportId |
| 2914 | gemToAes[gemPortID], _ = strconv.ParseBool(gem.(*tp_pb.GemPortAttributes).AesEncryption) |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2915 | } |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2916 | } |
| 2917 | |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2918 | flowContext := &flowContext{classifierInfo, actionInfo, flow, pbitToGem, gemToAes, intfID, onuID, uniID, portNo, allocID, gemPortID, tpID} |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2919 | |
| Sridhar Ravindra | d104e8d | 2025-06-02 13:04:49 +0530 | [diff] [blame] | 2920 | var nni_port uint32 |
| 2921 | if plt.IsUpstream(actionInfo[Output].(uint32)) { |
| 2922 | if !plt.IsControllerBoundFlow(actionInfo[Output].(uint32)) { |
| 2923 | nni_port = actionInfo[Output].(uint32) & 0x1f // convert e.g. 16777220 to port 4 (starting with 0) |
| 2924 | } |
| 2925 | } else { |
| 2926 | nni_port = classifierInfo[InPort].(uint32) & 0x1f // convert e.g. 16777220 to port 4 (starting with 0) |
| 2927 | } |
| 2928 | |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2929 | if ipProto, ok := classifierInfo[IPProto]; ok { |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 2930 | switch ipProto.(uint32) { |
| 2931 | case IPProtoDhcp: |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2932 | logger.Infow(ctx, "adding-dhcp-flow", log.Fields{ |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2933 | "tp-id": tpID, |
| 2934 | "alloc-id": allocID, |
| 2935 | "intf-id": intfID, |
| 2936 | "onu-id": onuID, |
| 2937 | "uni-id": uniID, |
| 2938 | }) |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2939 | // Adding DHCP upstream flow |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2940 | if err := f.addDHCPTrapFlow(ctx, flowContext); err != nil { |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2941 | logger.Warn(ctx, err) |
| Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 2942 | logger.Errorw(ctx, "reverting-scheduler-and-queue-for-onu", log.Fields{"intf-id": intfID, "onu-id": onuID, "uni-id": uniID, "flow-id": flow.Id, "tp-id": tpID}) |
| Sridhar Ravindra | d104e8d | 2025-06-02 13:04:49 +0530 | [diff] [blame] | 2943 | _ = f.clearResources(ctx, intfID, int32(onuID), int32(uniID), flow.Id, portNo, tpID, false, nni_port) |
| Gamze Abaka | 6d0a64f | 2021-11-18 08:08:33 +0000 | [diff] [blame] | 2944 | return err |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2945 | } |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 2946 | case IgmpProto: |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2947 | logger.Infow(ctx, "adding-us-igmp-flow", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2948 | log.Fields{ |
| 2949 | "intf-id": intfID, |
| 2950 | "onu-id": onuID, |
| 2951 | "uni-id": uniID, |
| 2952 | "classifier-info:": classifierInfo}) |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2953 | if err := f.addIGMPTrapFlow(ctx, flowContext); err != nil { |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2954 | logger.Warn(ctx, err) |
| Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 2955 | logger.Errorw(ctx, "reverting-scheduler-and-queue-for-onu", log.Fields{"intf-id": intfID, "onu-id": onuID, "uni-id": uniID, "flow-id": flow.Id, "tp-id": tpID}) |
| Sridhar Ravindra | d104e8d | 2025-06-02 13:04:49 +0530 | [diff] [blame] | 2956 | _ = f.clearResources(ctx, intfID, int32(onuID), int32(uniID), flow.Id, portNo, tpID, false, nni_port) |
| Gamze Abaka | 6d0a64f | 2021-11-18 08:08:33 +0000 | [diff] [blame] | 2957 | return err |
| Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2958 | } |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 2959 | default: |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2960 | logger.Errorw(ctx, "invalid-classifier-to-handle", log.Fields{"classifier": classifierInfo, "action": actionInfo}) |
| Gamze Abaka | 6d0a64f | 2021-11-18 08:08:33 +0000 | [diff] [blame] | 2961 | return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifierInfo, "action": actionInfo}, nil) |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2962 | } |
| 2963 | } else if ethType, ok := classifierInfo[EthType]; ok { |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 2964 | switch ethType.(uint32) { |
| 2965 | case EapEthType: |
| Marcos Aurelio Carrero (Furukawa) | 1dc2bfb | 2021-02-17 15:10:12 -0300 | [diff] [blame] | 2966 | logger.Infow(ctx, "adding-eapol-flow", log.Fields{ |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2967 | "intf-id": intfID, |
| 2968 | "onu-id": onuID, |
| 2969 | "uni-id": uniID, |
| Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 2970 | "ethType": ethType, |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2971 | }) |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2972 | var vlanID uint32 |
| 2973 | if val, ok := classifierInfo[VlanVid]; ok { |
| 2974 | vlanID = (val.(uint32)) & VlanvIDMask |
| 2975 | } else { |
| 2976 | vlanID = DefaultMgmtVlan |
| 2977 | } |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2978 | if err := f.addEthTypeBasedFlow(ctx, flowContext, vlanID, ethType.(uint32)); err != nil { |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2979 | logger.Warn(ctx, err) |
| Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 2980 | logger.Errorw(ctx, "reverting-scheduler-and-queue-for-onu", log.Fields{"intf-id": intfID, "onu-id": onuID, "uni-id": uniID, "flow-id": flow.Id, "tp-id": tpID}) |
| Sridhar Ravindra | d104e8d | 2025-06-02 13:04:49 +0530 | [diff] [blame] | 2981 | _ = f.clearResources(ctx, intfID, int32(onuID), int32(uniID), flow.Id, portNo, tpID, false, nni_port) |
| Gamze Abaka | 6d0a64f | 2021-11-18 08:08:33 +0000 | [diff] [blame] | 2982 | return err |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2983 | } |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 2984 | case PPPoEDEthType: |
| Marcos Aurelio Carrero (Furukawa) | 1dc2bfb | 2021-02-17 15:10:12 -0300 | [diff] [blame] | 2985 | logger.Infow(ctx, "adding-pppoed-flow", log.Fields{ |
| 2986 | "tp-id": tpID, |
| 2987 | "alloc-id": allocID, |
| 2988 | "intf-id": intfID, |
| 2989 | "onu-id": onuID, |
| 2990 | "uni-id": uniID, |
| 2991 | }) |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 2992 | // Adding PPPOED upstream flow |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2993 | if err := f.addUpstreamTrapFlow(ctx, flowContext); err != nil { |
| Marcos Aurelio Carrero (Furukawa) | 1dc2bfb | 2021-02-17 15:10:12 -0300 | [diff] [blame] | 2994 | logger.Warn(ctx, err) |
| Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 2995 | logger.Errorw(ctx, "reverting-scheduler-and-queue-for-onu", log.Fields{"intf-id": intfID, "onu-id": onuID, "uni-id": uniID, "flow-id": flow.Id, "tp-id": tpID}) |
| Sridhar Ravindra | d104e8d | 2025-06-02 13:04:49 +0530 | [diff] [blame] | 2996 | _ = f.clearResources(ctx, intfID, int32(onuID), int32(uniID), flow.Id, portNo, tpID, false, nni_port) |
| Gamze Abaka | 6d0a64f | 2021-11-18 08:08:33 +0000 | [diff] [blame] | 2997 | return err |
| Marcos Aurelio Carrero (Furukawa) | 1dc2bfb | 2021-02-17 15:10:12 -0300 | [diff] [blame] | 2998 | } |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2999 | } |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 3000 | } else if direction == tp_pb.Direction_UPSTREAM { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3001 | logger.Infow(ctx, "adding-upstream-data-rule", log.Fields{ |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 3002 | "intf-id": intfID, |
| 3003 | "onu-id": onuID, |
| 3004 | "uni-id": uniID, |
| 3005 | }) |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 3006 | // Adding HSIA upstream flow |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 3007 | if err := f.addUpstreamDataPathFlow(ctx, flowContext); err != nil { |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3008 | logger.Warn(ctx, err) |
| Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 3009 | logger.Errorw(ctx, "reverting-scheduler-and-queue-for-onu", log.Fields{"intf-id": intfID, "onu-id": onuID, "uni-id": uniID, "flow-id": flow.Id, "tp-id": tpID}) |
| Sridhar Ravindra | d104e8d | 2025-06-02 13:04:49 +0530 | [diff] [blame] | 3010 | _ = f.clearResources(ctx, intfID, int32(onuID), int32(uniID), flow.Id, portNo, tpID, false, nni_port) |
| Gamze Abaka | 6d0a64f | 2021-11-18 08:08:33 +0000 | [diff] [blame] | 3011 | return err |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3012 | } |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 3013 | } else if direction == tp_pb.Direction_DOWNSTREAM { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3014 | logger.Infow(ctx, "adding-downstream-data-rule", log.Fields{ |
| Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 3015 | "intf-id": intfID, |
| 3016 | "onu-id": onuID, |
| 3017 | "uni-id": uniID, |
| 3018 | }) |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 3019 | // Adding HSIA downstream flow |
| Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 3020 | if err := f.addDownstreamDataPathFlow(ctx, flowContext); err != nil { |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3021 | logger.Warn(ctx, err) |
| Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 3022 | logger.Errorw(ctx, "reverting-scheduler-and-queue-for-onu", log.Fields{"intf-id": intfID, "onu-id": onuID, "uni-id": uniID, "flow-id": flow.Id, "tp-id": tpID}) |
| Sridhar Ravindra | d104e8d | 2025-06-02 13:04:49 +0530 | [diff] [blame] | 3023 | _ = f.clearResources(ctx, intfID, int32(onuID), int32(uniID), flow.Id, portNo, tpID, false, nni_port) |
| Gamze Abaka | 6d0a64f | 2021-11-18 08:08:33 +0000 | [diff] [blame] | 3024 | return err |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3025 | } |
| 3026 | } else { |
| Gamze Abaka | 6d0a64f | 2021-11-18 08:08:33 +0000 | [diff] [blame] | 3027 | return olterrors.NewErrInvalidValue(log.Fields{ |
| 3028 | "intf-id": intfID, |
| 3029 | "onu-id": onuID, |
| 3030 | "uni-id": uniID, |
| 3031 | "classifier": classifierInfo, |
| 3032 | "action": actionInfo, |
| 3033 | "flow": flow}, |
| 3034 | nil).Log() |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3035 | } |
| 3036 | // Send Techprofile download event to child device in go routine as it takes time |
| Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 3037 | go func() { |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 3038 | if err := f.sendTPDownloadMsgToChild(ctx, intfID, onuID, uniID, uni, tpID, TpInst.(*tp_pb.TechProfileInstance)); err != nil { |
| Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 3039 | logger.Warn(ctx, err) |
| 3040 | } |
| 3041 | }() |
| Gamze Abaka | 6d0a64f | 2021-11-18 08:08:33 +0000 | [diff] [blame] | 3042 | return nil |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3043 | } |
| 3044 | |
| Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 3045 | func (f *OpenOltFlowMgr) isAllocUsedByAnotherUNI(ctx context.Context, sq schedQueue) bool { |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3046 | tpInst := sq.tpInst.(*tp_pb.TechProfileInstance) |
| 3047 | if tpInst.InstanceControl.Onu == "single-instance" && sq.direction == tp_pb.Direction_UPSTREAM { |
| 3048 | tpInstances := f.techprofile.FindAllTpInstances(ctx, f.deviceHandler.device.Id, sq.tpID, sq.intfID, sq.onuID).([]tp_pb.TechProfileInstance) |
| Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 3049 | for i := 0; i < len(tpInstances); i++ { |
| bseeniva | 0b9cbcb | 2026-02-12 19:11:11 +0530 | [diff] [blame^] | 3050 | tpI := &tpInstances[i] |
| Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 3051 | if tpI.SubscriberIdentifier != tpInst.SubscriberIdentifier && |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3052 | tpI.UsScheduler.AllocId == tpInst.UsScheduler.AllocId { |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 3053 | logger.Debugw(ctx, "alloc-is-in-use-on-another-uni", |
| Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 3054 | log.Fields{ |
| 3055 | "device-id": f.deviceHandler.device.Id, |
| 3056 | "intfID": sq.intfID, |
| 3057 | "onuID": sq.onuID, |
| 3058 | "uniID": sq.uniID, |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3059 | "allocID": tpI.UsScheduler.AllocId, |
| Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 3060 | }) |
| 3061 | return true |
| Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 3062 | } |
| 3063 | } |
| 3064 | } |
| Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 3065 | return false |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3066 | } |
| 3067 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3068 | func formulateClassifierInfoFromFlow(ctx context.Context, classifierInfo map[string]interface{}, flow *ofp.OfpFlowStats) { |
| Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3069 | for _, field := range flows.GetOfbFields(flow) { |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3070 | switch field.Type { |
| 3071 | case flows.ETH_TYPE: |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3072 | classifierInfo[EthType] = field.GetEthType() |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3073 | logger.Debug(ctx, "field-type-eth-type", log.Fields{"classifierInfo[ETH_TYPE]": classifierInfo[EthType].(uint32)}) |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3074 | case flows.ETH_DST: |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3075 | classifierInfo[EthDst] = field.GetEthDst() |
| Girish Gowdra | ffa52e5 | 2022-02-16 15:48:10 -0800 | [diff] [blame] | 3076 | logger.Debug(ctx, "field-type-eth-dst", log.Fields{"classifierInfo[ETH_DST]": classifierInfo[EthDst].([]uint8)}) |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3077 | case flows.ETH_SRC: |
| Girish Gowdra | ffa52e5 | 2022-02-16 15:48:10 -0800 | [diff] [blame] | 3078 | classifierInfo[EthSrc] = field.GetEthSrc() |
| 3079 | logger.Debug(ctx, "field-type-eth-src", log.Fields{"classifierInfo[ETH_SRC]": classifierInfo[EthSrc].([]uint8)}) |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3080 | case flows.IP_PROTO: |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3081 | classifierInfo[IPProto] = field.GetIpProto() |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3082 | logger.Debug(ctx, "field-type-ip-proto", log.Fields{"classifierInfo[IP_PROTO]": classifierInfo[IPProto].(uint32)}) |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3083 | case flows.IN_PORT: |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3084 | classifierInfo[InPort] = field.GetPort() |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3085 | logger.Debug(ctx, "field-type-in-port", log.Fields{"classifierInfo[IN_PORT]": classifierInfo[InPort].(uint32)}) |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3086 | case flows.VLAN_VID: |
| Andrea Campanella | faa4215 | 2021-10-28 11:50:56 +0530 | [diff] [blame] | 3087 | // The ReservedVlan is used to signify transparent vlan. Do not do any classification when we see ReservedVlan |
| 3088 | if field.GetVlanVid() != ReservedVlan { |
| 3089 | classifierInfo[VlanVid] = field.GetVlanVid() & 0xfff |
| 3090 | logger.Debug(ctx, "field-type-vlan-vid", log.Fields{"classifierInfo[VLAN_VID]": classifierInfo[VlanVid].(uint32)}) |
| 3091 | } |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3092 | case flows.VLAN_PCP: |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3093 | classifierInfo[VlanPcp] = field.GetVlanPcp() |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3094 | logger.Debug(ctx, "field-type-vlan-pcp", log.Fields{"classifierInfo[VLAN_PCP]": classifierInfo[VlanPcp].(uint32)}) |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3095 | case flows.UDP_DST: |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3096 | classifierInfo[UDPDst] = field.GetUdpDst() |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3097 | logger.Debug(ctx, "field-type-udp-dst", log.Fields{"classifierInfo[UDP_DST]": classifierInfo[UDPDst].(uint32)}) |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3098 | case flows.UDP_SRC: |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3099 | classifierInfo[UDPSrc] = field.GetUdpSrc() |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3100 | logger.Debug(ctx, "field-type-udp-src", log.Fields{"classifierInfo[UDP_SRC]": classifierInfo[UDPSrc].(uint32)}) |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3101 | case flows.IPV4_DST: |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3102 | classifierInfo[Ipv4Dst] = field.GetIpv4Dst() |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3103 | logger.Debug(ctx, "field-type-ipv4-dst", log.Fields{"classifierInfo[IPV4_DST]": classifierInfo[Ipv4Dst].(uint32)}) |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3104 | case flows.IPV4_SRC: |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3105 | classifierInfo[Ipv4Src] = field.GetIpv4Src() |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3106 | logger.Debug(ctx, "field-type-ipv4-src", log.Fields{"classifierInfo[IPV4_SRC]": classifierInfo[Ipv4Src].(uint32)}) |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3107 | case flows.METADATA: |
| David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 3108 | classifierInfo[Metadata] = field.GetTableMetadata() |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3109 | logger.Debug(ctx, "field-type-metadata", log.Fields{"classifierInfo[Metadata]": classifierInfo[Metadata].(uint64)}) |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3110 | case flows.TUNNEL_ID: |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3111 | classifierInfo[TunnelID] = field.GetTunnelId() |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3112 | logger.Debug(ctx, "field-type-tunnelId", log.Fields{"classifierInfo[TUNNEL_ID]": classifierInfo[TunnelID].(uint64)}) |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3113 | default: |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3114 | logger.Errorw(ctx, "un-supported-field-type", log.Fields{"type": field.Type}) |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3115 | return |
| 3116 | } |
| 3117 | } |
| 3118 | } |
| 3119 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3120 | func formulateActionInfoFromFlow(ctx context.Context, actionInfo, classifierInfo map[string]interface{}, flow *ofp.OfpFlowStats) error { |
| Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3121 | for _, action := range flows.GetActions(flow) { |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3122 | switch action.Type { |
| 3123 | case flows.OUTPUT: |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3124 | if out := action.GetOutput(); out != nil { |
| David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 3125 | actionInfo[Output] = out.GetPort() |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3126 | logger.Debugw(ctx, "action-type-output", log.Fields{"out-port": actionInfo[Output].(uint32)}) |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3127 | } else { |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3128 | return olterrors.NewErrInvalidValue(log.Fields{"output-port": nil}, nil) |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3129 | } |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3130 | case flows.POP_VLAN: |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3131 | actionInfo[PopVlan] = true |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3132 | logger.Debugw(ctx, "action-type-pop-vlan", log.Fields{"in_port": classifierInfo[InPort].(uint32)}) |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3133 | case flows.PUSH_VLAN: |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3134 | if out := action.GetPush(); out != nil { |
| 3135 | if tpid := out.GetEthertype(); tpid != 0x8100 { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3136 | logger.Errorw(ctx, "invalid ethertype in push action", log.Fields{"ethertype": actionInfo[PushVlan].(int32)}) |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3137 | } else { |
| 3138 | actionInfo[PushVlan] = true |
| 3139 | actionInfo[TPID] = tpid |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3140 | logger.Debugw(ctx, "action-type-push-vlan", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3141 | log.Fields{ |
| 3142 | "push-tpid": actionInfo[TPID].(uint32), |
| 3143 | "in-port": classifierInfo[InPort].(uint32)}) |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3144 | } |
| 3145 | } |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3146 | case flows.SET_FIELD: |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3147 | if out := action.GetSetField(); out != nil { |
| 3148 | if field := out.GetField(); field != nil { |
| 3149 | if ofClass := field.GetOxmClass(); ofClass != ofp.OfpOxmClass_OFPXMC_OPENFLOW_BASIC { |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3150 | return olterrors.NewErrInvalidValue(log.Fields{"openflow-class": ofClass}, nil) |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3151 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3152 | /*logger.Debugw(ctx, "action-type-set-field",log.Fields{"field": field, "in_port": classifierInfo[IN_PORT].(uint32)})*/ |
| 3153 | formulateSetFieldActionInfoFromFlow(ctx, field, actionInfo) |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3154 | } |
| 3155 | } |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3156 | case flows.GROUP: |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3157 | formulateGroupActionInfoFromFlow(ctx, action, actionInfo) |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3158 | default: |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3159 | return olterrors.NewErrInvalidValue(log.Fields{"action-type": action.Type}, nil) |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3160 | } |
| 3161 | } |
| 3162 | return nil |
| 3163 | } |
| 3164 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3165 | func formulateSetFieldActionInfoFromFlow(ctx context.Context, field *ofp.OfpOxmField, actionInfo map[string]interface{}) { |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3166 | if ofbField := field.GetOfbField(); ofbField != nil { |
| Gamze Abaka | c43a66e | 2020-05-11 11:00:42 +0000 | [diff] [blame] | 3167 | fieldtype := ofbField.GetType() |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3168 | switch fieldtype { |
| 3169 | case ofp.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID: |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3170 | if vlan := ofbField.GetVlanVid(); vlan != 0 { |
| 3171 | actionInfo[VlanVid] = vlan & 0xfff |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3172 | logger.Debugw(ctx, "action-set-vlan-vid", log.Fields{"actionInfo[VLAN_VID]": actionInfo[VlanVid].(uint32)}) |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3173 | } else { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3174 | logger.Error(ctx, "no-invalid-vlan-id-in-set-vlan-vid-action") |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3175 | } |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3176 | case ofp.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_PCP: |
| Gamze Abaka | c43a66e | 2020-05-11 11:00:42 +0000 | [diff] [blame] | 3177 | pcp := ofbField.GetVlanPcp() |
| 3178 | actionInfo[VlanPcp] = pcp |
| Girish Kumar | a1ea2aa | 2020-08-19 18:14:22 +0000 | [diff] [blame] | 3179 | logger.Debugw(ctx, "action-set-vlan-pcp", log.Fields{"actionInfo[VLAN_PCP]": actionInfo[VlanPcp].(uint32)}) |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3180 | default: |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3181 | logger.Errorw(ctx, "unsupported-action-set-field-type", log.Fields{"type": fieldtype}) |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3182 | } |
| 3183 | } |
| 3184 | } |
| 3185 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3186 | func formulateGroupActionInfoFromFlow(ctx context.Context, action *ofp.OfpAction, actionInfo map[string]interface{}) { |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3187 | if action.GetGroup() == nil { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3188 | logger.Warn(ctx, "no-group-entry-found-in-the-group-action") |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3189 | } else { |
| 3190 | actionInfo[GroupID] = action.GetGroup().GroupId |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3191 | logger.Debugw(ctx, "action-group-id", log.Fields{"actionInfo[GroupID]": actionInfo[GroupID].(uint32)}) |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3192 | } |
| 3193 | } |
| 3194 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3195 | func formulateControllerBoundTrapFlowInfo(ctx context.Context, actionInfo, classifierInfo map[string]interface{}, flow *ofp.OfpFlowStats) error { |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3196 | if isControllerFlow := plt.IsControllerBoundFlow(actionInfo[Output].(uint32)); isControllerFlow { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3197 | logger.Debug(ctx, "controller-bound-trap-flows--getting-inport-from-tunnelid") |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3198 | /* Get UNI port/ IN Port from tunnel ID field for upstream controller bound flows */ |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3199 | if portType := plt.IntfIDToPortTypeName(classifierInfo[InPort].(uint32)); portType == voltha.Port_PON_OLT { |
| Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3200 | if uniPort := flows.GetChildPortFromTunnelId(flow); uniPort != 0 { |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3201 | classifierInfo[InPort] = uniPort |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3202 | logger.Debugw(ctx, "upstream-pon-to-controller-flow--inport-in-tunnelid", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3203 | log.Fields{ |
| 3204 | "newinport": classifierInfo[InPort].(uint32), |
| 3205 | "outport": actionInfo[Output].(uint32)}) |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3206 | } else { |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3207 | return olterrors.NewErrNotFound("child-in-port", |
| 3208 | log.Fields{ |
| 3209 | "reason": "upstream-pon-to-controller-flow--no-inport-in-tunnelid", |
| 3210 | "flow": flow}, nil) |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3211 | } |
| 3212 | } |
| 3213 | } else { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3214 | logger.Debug(ctx, "non-controller-flows--getting-uniport-from-tunnelid") |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3215 | // Downstream flow from NNI to PON port , Use tunnel ID as new OUT port / UNI port |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3216 | if portType := plt.IntfIDToPortTypeName(actionInfo[Output].(uint32)); portType == voltha.Port_PON_OLT { |
| Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3217 | if uniPort := flows.GetChildPortFromTunnelId(flow); uniPort != 0 { |
| David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 3218 | actionInfo[Output] = uniPort |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3219 | logger.Debugw(ctx, "downstream-nni-to-pon-port-flow, outport-in-tunnelid", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3220 | log.Fields{ |
| 3221 | "newoutport": actionInfo[Output].(uint32), |
| 3222 | "outport": actionInfo[Output].(uint32)}) |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3223 | } else { |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3224 | return olterrors.NewErrNotFound("out-port", |
| 3225 | log.Fields{ |
| 3226 | "reason": "downstream-nni-to-pon-port-flow--no-outport-in-tunnelid", |
| 3227 | "flow": flow}, nil) |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3228 | } |
| 3229 | // Upstream flow from PON to NNI port , Use tunnel ID as new IN port / UNI port |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3230 | } else if portType := plt.IntfIDToPortTypeName(classifierInfo[InPort].(uint32)); portType == voltha.Port_PON_OLT { |
| Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3231 | if uniPort := flows.GetChildPortFromTunnelId(flow); uniPort != 0 { |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3232 | classifierInfo[InPort] = uniPort |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3233 | logger.Debugw(ctx, "upstream-pon-to-nni-port-flow, inport-in-tunnelid", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3234 | log.Fields{ |
| 3235 | "newinport": actionInfo[Output].(uint32), |
| 3236 | "outport": actionInfo[Output].(uint32)}) |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3237 | } else { |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3238 | return olterrors.NewErrNotFound("nni-port", |
| 3239 | log.Fields{ |
| 3240 | "reason": "upstream-pon-to-nni-port-flow--no-inport-in-tunnelid", |
| 3241 | "in-port": classifierInfo[InPort].(uint32), |
| 3242 | "out-port": actionInfo[Output].(uint32), |
| 3243 | "flow": flow}, nil) |
| salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3244 | } |
| 3245 | } |
| 3246 | } |
| 3247 | return nil |
| 3248 | } |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3249 | |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3250 | func getTpIDFromFlow(ctx context.Context, flow *ofp.OfpFlowStats) (uint32, error) { |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3251 | /* Metadata 8 bytes: |
| 3252 | Most Significant 2 Bytes = Inner VLAN |
| 3253 | Next 2 Bytes = Tech Profile ID(TPID) |
| 3254 | Least Significant 4 Bytes = Port ID |
| 3255 | Flow Metadata carries Tech-Profile (TP) ID and is mandatory in all |
| 3256 | subscriber related flows. |
| 3257 | */ |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3258 | metadata := flows.GetMetadataFromWriteMetadataAction(ctx, flow) |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3259 | if metadata == 0 { |
| Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3260 | return 0, olterrors.NewErrNotFound("metadata", log.Fields{"flow": flow}, nil) |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3261 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3262 | TpID := flows.GetTechProfileIDFromWriteMetaData(ctx, metadata) |
| Chaitrashree G S | 90a1795 | 2019-11-14 21:51:21 -0500 | [diff] [blame] | 3263 | return uint32(TpID), nil |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3264 | } |
| 3265 | |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3266 | func appendUnique32bit(slice []uint32, item uint32) []uint32 { |
| Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3267 | for _, sliceElement := range slice { |
| 3268 | if sliceElement == item { |
| 3269 | return slice |
| 3270 | } |
| 3271 | } |
| 3272 | return append(slice, item) |
| 3273 | } |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3274 | |
| yasin sapli | e87d4bd | 2021-12-06 09:04:03 +0000 | [diff] [blame] | 3275 | func appendUnique64bit(slice []uint64, item uint64) []uint64 { |
| 3276 | for _, sliceElement := range slice { |
| 3277 | if sliceElement == item { |
| 3278 | return slice |
| 3279 | } |
| 3280 | } |
| 3281 | return append(slice, item) |
| 3282 | } |
| 3283 | |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3284 | // getNniIntfID gets nni intf id from the flow classifier/action |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3285 | func getNniIntfID(ctx context.Context, classifier map[string]interface{}, action map[string]interface{}) (uint32, error) { |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3286 | portType := plt.IntfIDToPortTypeName(classifier[InPort].(uint32)) |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3287 | switch portType { |
| 3288 | case voltha.Port_PON_OLT: |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3289 | intfID, err := plt.IntfIDFromNniPortNum(ctx, action[Output].(uint32)) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3290 | if err != nil { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3291 | logger.Debugw(ctx, "invalid-action-port-number", |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3292 | log.Fields{ |
| 3293 | "port-number": action[Output].(uint32), |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3294 | "err": err}) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3295 | return uint32(0), err |
| 3296 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3297 | logger.Infow(ctx, "output-nni-intfId-is", log.Fields{"intf-id": intfID}) |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3298 | return intfID, nil |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3299 | case voltha.Port_ETHERNET_NNI: |
| Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3300 | intfID, err := plt.IntfIDFromNniPortNum(ctx, classifier[InPort].(uint32)) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3301 | if err != nil { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3302 | logger.Debugw(ctx, "invalid-classifier-port-number", |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3303 | log.Fields{ |
| 3304 | "port-number": action[Output].(uint32), |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3305 | "err": err}) |
| David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3306 | return uint32(0), err |
| 3307 | } |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3308 | logger.Infow(ctx, "input-nni-intfId-is", log.Fields{"intf-id": intfID}) |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3309 | return intfID, nil |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3310 | case voltha.Port_ETHERNET_UNI: |
| Sridhar Ravindra | d104e8d | 2025-06-02 13:04:49 +0530 | [diff] [blame] | 3311 | if _, ok := action[Output]; ok { |
| 3312 | intfID, err := plt.IntfIDFromNniPortNum(ctx, action[Output].(uint32)) |
| 3313 | if err != nil { |
| 3314 | logger.Debugw(ctx, "invalid-action-port-number", |
| 3315 | log.Fields{ |
| 3316 | "port-number": action[Output].(uint32), |
| 3317 | "err": err}) |
| 3318 | return uint32(0), nil |
| 3319 | } |
| 3320 | logger.Infow(ctx, "output-nni-intfId-is", log.Fields{"intf-id": intfID}) |
| 3321 | return intfID, nil |
| 3322 | } else { |
| 3323 | logger.Debugw(ctx, "action-port-number-empty", |
| 3324 | log.Fields{ |
| 3325 | "action": action}) |
| 3326 | return uint32(0), nil |
| 3327 | } |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3328 | } |
| 3329 | return uint32(0), nil |
| 3330 | } |
| 3331 | |
| 3332 | // UpdateGemPortForPktIn updates gemport for packet-in in to the cache and to the kv store as well. |
| Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 3333 | func (f *OpenOltFlowMgr) UpdateGemPortForPktIn(ctx context.Context, intfID uint32, onuID uint32, logicalPort uint32, gemPort uint32, pkt []byte) { |
| 3334 | cTag, priority, err := getCTagFromPacket(ctx, pkt) |
| 3335 | if err != nil { |
| 3336 | logger.Errorw(ctx, "unable-to-update-gem-port-for-packet-in", |
| 3337 | log.Fields{"intfID": intfID, "onuID": onuID, "logicalPort": logicalPort, "gemPort": gemPort, "err": err}) |
| 3338 | return |
| 3339 | } |
| 3340 | pktInkey := rsrcMgr.PacketInInfoKey{IntfID: intfID, OnuID: onuID, LogicalPort: logicalPort, VlanID: cTag, Priority: priority} |
| Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 3341 | |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3342 | f.packetInGemPortLock.RLock() |
| Matt Jeanneret | 1719a07 | 2019-12-20 14:50:14 -0500 | [diff] [blame] | 3343 | lookupGemPort, ok := f.packetInGemPort[pktInkey] |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3344 | f.packetInGemPortLock.RUnlock() |
| 3345 | |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3346 | if ok { |
| Matt Jeanneret | 1719a07 | 2019-12-20 14:50:14 -0500 | [diff] [blame] | 3347 | if lookupGemPort == gemPort { |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3348 | logger.Infow(ctx, "pktin-key/value-found-in-cache--no-need-to-update-kv--assume-both-in-sync", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3349 | log.Fields{ |
| 3350 | "pktinkey": pktInkey, |
| 3351 | "gem": gemPort}) |
| Matt Jeanneret | 1719a07 | 2019-12-20 14:50:14 -0500 | [diff] [blame] | 3352 | return |
| 3353 | } |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3354 | } |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3355 | f.packetInGemPortLock.Lock() |
| Matt Jeanneret | 1719a07 | 2019-12-20 14:50:14 -0500 | [diff] [blame] | 3356 | f.packetInGemPort[pktInkey] = gemPort |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3357 | f.packetInGemPortLock.Unlock() |
| Matt Jeanneret | 1719a07 | 2019-12-20 14:50:14 -0500 | [diff] [blame] | 3358 | |
| npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 3359 | f.resourceMgr.UpdateGemPortForPktIn(ctx, pktInkey, gemPort) |
| Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3360 | logger.Infow(ctx, "pktin-key-not-found-in-local-cache-value-is-different--updating-cache-and-kv-store", |
| Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3361 | log.Fields{ |
| 3362 | "pktinkey": pktInkey, |
| 3363 | "gem": gemPort}) |
| Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3364 | } |
| 3365 | |
| Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 3366 | // getCTagFromPacket retrieves and returns c-tag and priority value from a packet. |
| Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 3367 | func getCTagFromPacket(ctx context.Context, packet []byte) (uint16, uint8, error) { |
| mgouda | 8654358 | 2025-10-29 20:58:16 +0530 | [diff] [blame] | 3368 | if len(packet) < 18 { |
| Girish Kumar | a1ea2aa | 2020-08-19 18:14:22 +0000 | [diff] [blame] | 3369 | logger.Error(ctx, "unable-get-c-tag-from-the-packet--invalid-packet-length ") |
| Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 3370 | return 0, 0, errors.New("invalid packet length") |
| 3371 | } |
| 3372 | outerEthType := (uint16(packet[12]) << 8) | uint16(packet[13]) |
| 3373 | innerEthType := (uint16(packet[16]) << 8) | uint16(packet[17]) |
| 3374 | |
| 3375 | var index int8 |
| 3376 | if outerEthType == 0x8100 { |
| 3377 | if innerEthType == 0x8100 { |
| 3378 | // q-in-q 802.1ad or 802.1q double tagged packet. |
| 3379 | // get the inner vlanId |
| 3380 | index = 18 |
| 3381 | } else { |
| 3382 | index = 14 |
| 3383 | } |
| 3384 | priority := (packet[index] >> 5) & 0x7 |
| Akash Kankanala | 041a212 | 2024-10-16 15:49:22 +0530 | [diff] [blame] | 3385 | // 13 bits composes vlanId value |
| Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 3386 | vlan := ((uint16(packet[index]) << 8) & 0x0fff) | uint16(packet[index+1]) |
| 3387 | return vlan, priority, nil |
| 3388 | } |
| 3389 | logger.Debugf(ctx, "No vlanId found in the packet. Returning zero as c-tag") |
| 3390 | return 0, 0, nil |
| 3391 | } |
| 3392 | |
| Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 3393 | // clearMulticastFlowFromResourceManager removes a multicast flow from the KV store and |
| Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 3394 | // clears resources reserved for this multicast flow |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3395 | func (f *OpenOltFlowMgr) clearMulticastFlowFromResourceManager(ctx context.Context, flow *ofp.OfpFlowStats) error { |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3396 | removeFlowMessage := openoltpb2.Flow{FlowId: flow.Id, FlowType: Multicast} |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3397 | logger.Debugw(ctx, "multicast-flow-to-be-deleted", |
| 3398 | log.Fields{ |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3399 | "flow": flow, |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3400 | "flow-id": flow.Id, |
| 3401 | "device-id": f.deviceHandler.device.Id}) |
| 3402 | // Remove from device |
| 3403 | if err := f.removeFlowFromDevice(ctx, &removeFlowMessage, flow.Id); err != nil { |
| 3404 | // DKB |
| 3405 | logger.Errorw(ctx, "failed-to-remove-multicast-flow", |
| 3406 | log.Fields{ |
| 3407 | "flow-id": flow.Id, |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3408 | "err": err}) |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3409 | return err |
| 3410 | } |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3411 | |
| 3412 | return nil |
| Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3413 | } |
| 3414 | |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 3415 | func (f *OpenOltFlowMgr) getTechProfileDownloadMessage(ctx context.Context, tpPath string, uniID uint32, onuDeviceID string) (*ia.TechProfileDownloadMessage, error) { |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3416 | tpInst, err := f.techprofile.GetTPInstance(ctx, tpPath) |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3417 | if err != nil { |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3418 | logger.Errorw(ctx, "error-fetching-tp-instance", log.Fields{"tpPath": tpPath}) |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 3419 | return nil, err |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3420 | } |
| 3421 | |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3422 | switch tpInst := tpInst.(type) { |
| 3423 | case *tp_pb.TechProfileInstance: |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 3424 | logger.Debugw(ctx, "fetched-tp-instance-successfully-formulating-tp-download-msg", log.Fields{"tpPath": tpPath}) |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 3425 | return &ia.TechProfileDownloadMessage{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 3426 | DeviceId: onuDeviceID, |
| 3427 | UniId: uniID, |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3428 | TpInstancePath: tpPath, |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 3429 | TechTpInstance: &ia.TechProfileDownloadMessage_TpInstance{TpInstance: tpInst}, |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 3430 | }, nil |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 3431 | case *tp_pb.EponTechProfileInstance: |
| 3432 | return &ia.TechProfileDownloadMessage{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 3433 | DeviceId: onuDeviceID, |
| 3434 | UniId: uniID, |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3435 | TpInstancePath: tpPath, |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 3436 | TechTpInstance: &ia.TechProfileDownloadMessage_EponTpInstance{EponTpInstance: tpInst}, |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 3437 | }, nil |
| Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3438 | default: |
| 3439 | logger.Errorw(ctx, "unknown-tech", log.Fields{"tpPath": tpPath}) |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3440 | } |
| khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 3441 | return &ia.TechProfileDownloadMessage{ |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 3442 | DeviceId: onuDeviceID, |
| 3443 | UniId: uniID, |
| 3444 | TpInstancePath: tpPath, |
| 3445 | TechTpInstance: nil, |
| 3446 | }, nil |
| Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3447 | } |
| 3448 | |
| Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 3449 | // revertTechProfileInstance is called when CreateScheduler or CreateQueues request fails |
| 3450 | func (f *OpenOltFlowMgr) revertTechProfileInstance(ctx context.Context, sq schedQueue) { |
| Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 3451 | intfID := sq.intfID |
| 3452 | onuID := sq.onuID |
| 3453 | uniID := sq.uniID |
| 3454 | tpID := sq.tpID |
| 3455 | |
| 3456 | var reverseDirection string |
| 3457 | if sq.direction == tp_pb.Direction_UPSTREAM { |
| 3458 | reverseDirection = "downstream" |
| 3459 | } else { |
| 3460 | reverseDirection = "upstream" |
| 3461 | } |
| 3462 | |
| 3463 | // check reverse direction - if reverse meter exists, tech profile instance is in use - do not delete |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 3464 | if KvStoreMeter, _ := f.resourceMgr.GetMeterInfoForOnu(ctx, reverseDirection, onuID, uniID, tpID); KvStoreMeter != nil { |
| Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 3465 | return |
| 3466 | } |
| 3467 | |
| 3468 | // revert-delete tech-profile instance and delete tech profile id for onu |
| 3469 | logger.Warnw(ctx, "reverting-tech-profile-instance-and-tech-profile-id-for-onu", log.Fields{"intf-id": intfID, "onu-id": onuID, "uni-id": uniID, "tp-id": tpID}) |
| 3470 | uniPortName := getUniPortPath(f.deviceHandler.device.Id, intfID, int32(onuID), int32(uniID)) |
| 3471 | _ = f.DeleteTechProfileInstance(ctx, intfID, onuID, uniID, uniPortName, tpID) |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 3472 | _ = f.resourceMgr.RemoveTechProfileIDForOnu(ctx, onuID, uniID, tpID) |
| Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 3473 | |
| 3474 | // free gem/alloc |
| 3475 | switch techprofileInst := sq.tpInst.(type) { |
| 3476 | case *tp_pb.TechProfileInstance: |
| 3477 | for _, gem := range techprofileInst.UpstreamGemPortAttributeList { |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 3478 | f.resourceMgr.FreeGemPortID(ctx, onuID, uniID, gem.GemportId) |
| Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 3479 | } |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 3480 | f.resourceMgr.FreeAllocID(ctx, onuID, uniID, techprofileInst.UsScheduler.AllocId, true) |
| Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 3481 | } |
| 3482 | } |
| 3483 | |
| 3484 | // revertSchduler is called when CreateQueues request fails |
| 3485 | func (f *OpenOltFlowMgr) revertScheduler(ctx context.Context, sq schedQueue, TrafficSched []*tp_pb.TrafficScheduler) { |
| 3486 | // revert scheduler |
| 3487 | logger.Warnw(ctx, "reverting-scheduler-for-onu", log.Fields{"intf-id": sq.intfID, "onu-id": sq.onuID, "uni-id": sq.uniID, "tp-id": sq.tpID}) |
| bseeniva | a162211 | 2025-12-11 18:24:02 +0530 | [diff] [blame] | 3488 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), f.deviceHandler.cfg.RPCTimeout) |
| 3489 | _, _ = f.deviceHandler.Client.RemoveTrafficSchedulers(subCtx, &tp_pb.TrafficSchedulers{ |
| Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 3490 | IntfId: sq.intfID, OnuId: sq.onuID, |
| 3491 | UniId: sq.uniID, PortNo: sq.uniPort, |
| 3492 | TrafficScheds: TrafficSched}) |
| bseeniva | a162211 | 2025-12-11 18:24:02 +0530 | [diff] [blame] | 3493 | cancel() |
| Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 3494 | } |
| Girish Gowdra | 6071f38 | 2021-12-14 12:52:04 +0530 | [diff] [blame] | 3495 | |
| 3496 | // validateMeter validates if there is a meter mismatch for the given direction. It also clears the stale meter if the reference count is zero |
| 3497 | func (f *OpenOltFlowMgr) validateMeter(ctx context.Context, direction string, meterID uint32, intfID uint32, onuID uint32, uniID uint32, tpID uint32) error { |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 3498 | meterInfo, err := f.resourceMgr.GetMeterInfoForOnu(ctx, direction, onuID, uniID, tpID) |
| Girish Gowdra | 6071f38 | 2021-12-14 12:52:04 +0530 | [diff] [blame] | 3499 | if err != nil { |
| 3500 | return olterrors.NewErrNotFound("meter", |
| 3501 | log.Fields{"intf-id": intfID, |
| 3502 | "onu-id": onuID, |
| 3503 | "uni-id": uniID, |
| 3504 | "device-id": f.deviceHandler.device.Id}, err) |
| 3505 | } |
| 3506 | |
| 3507 | if meterInfo != nil { |
| 3508 | // If RefCnt become 0 clear the meter information from the DB. |
| 3509 | if meterInfo.MeterID != meterID && meterInfo.RefCnt == 0 { |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 3510 | if err := f.resourceMgr.RemoveMeterInfoForOnu(ctx, direction, onuID, uniID, tpID); err != nil { |
| Girish Gowdra | 6071f38 | 2021-12-14 12:52:04 +0530 | [diff] [blame] | 3511 | return err |
| 3512 | } |
| 3513 | } else if meterInfo.MeterID != meterID { |
| 3514 | logger.Errorw(ctx, "meter-mismatch-for-direction", |
| 3515 | log.Fields{"direction": direction, |
| 3516 | "kv-store-meter-id": meterInfo.MeterID, |
| 3517 | "meter-id-in-flow": meterID, |
| 3518 | "device-id": f.deviceHandler.device.Id}) |
| 3519 | return olterrors.NewErrInvalidValue(log.Fields{ |
| 3520 | "unsupported": "meter-id", |
| 3521 | "kv-store-meter-id": meterInfo.MeterID, |
| 3522 | "meter-id-in-flow": meterID, |
| 3523 | "device-id": f.deviceHandler.device.Id}, nil) |
| 3524 | } |
| 3525 | } |
| 3526 | return nil |
| 3527 | } |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 3528 | |
| 3529 | func (f *OpenOltFlowMgr) removeMeterReference(ctx context.Context, direction string, sq schedQueue) error { |
| 3530 | /* After we successfully remove the scheduler configuration on the OLT device, |
| 3531 | * delete the meter id on the KV store. |
| 3532 | */ |
| yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 3533 | err := f.resourceMgr.RemoveMeterInfoForOnu(ctx, direction, sq.onuID, sq.uniID, sq.tpID) |
| Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 3534 | if err != nil { |
| 3535 | return olterrors.NewErrAdapter("unable-to-remove-meter", |
| 3536 | log.Fields{ |
| 3537 | "onu": sq.onuID, |
| 3538 | "device-id": f.deviceHandler.device.Id, |
| 3539 | "intf-id": sq.intfID, |
| 3540 | "onu-id": sq.onuID, |
| 3541 | "uni-id": sq.uniID, |
| 3542 | "uni-port": sq.uniPort}, err) |
| 3543 | } |
| 3544 | logger.Debugw(ctx, "removed-meter-from-KV-store-successfully", |
| 3545 | log.Fields{ |
| 3546 | "dir": direction, |
| 3547 | "device-id": f.deviceHandler.device.Id, |
| 3548 | "intf-id": sq.intfID, |
| 3549 | "onu-id": sq.onuID, |
| 3550 | "uni-id": sq.uniID, |
| 3551 | "uni-port": sq.uniPort}) |
| 3552 | return err |
| 3553 | } |