Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022-present Open Networking Foundation |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 14 | */ |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 15 | |
| 16 | package nbi |
| 17 | |
| 18 | import ( |
| 19 | "bytes" |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 20 | "context" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 21 | "encoding/json" |
| 22 | "net" |
| 23 | "net/http" |
| 24 | "strconv" |
| 25 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 26 | app "voltha-go-controller/internal/pkg/application" |
Hitesh Chhabra | 7d249a0 | 2023-07-04 21:33:49 +0530 | [diff] [blame] | 27 | errorCodes "voltha-go-controller/internal/pkg/errorcodes" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 28 | "voltha-go-controller/internal/pkg/of" |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 29 | "voltha-go-controller/log" |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 30 | |
| 31 | "github.com/google/gopacket/layers" |
| 32 | "github.com/gorilla/mux" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 33 | ) |
| 34 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 35 | // SubscriberDeviceInfo - Subcriber Device Info |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 36 | type SubscriberDeviceInfo struct { |
| 37 | ID string `json:"id"` |
| 38 | NasPortID string `json:"nasPortId"` |
Akash Soni | 53da285 | 2023-03-15 00:31:31 +0530 | [diff] [blame] | 39 | UplinkPort string `json:"uplinkPort"` |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 40 | HardwareIdentifier string `json:"hardwareIdentifier"` |
Akash Soni | 87a1907 | 2023-02-28 00:46:59 +0530 | [diff] [blame] | 41 | IPAddress string `json:"ipAddress"` |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 42 | NasID string `json:"nasId"` |
| 43 | CircuitID string `json:"circuitId"` |
| 44 | RemoteID string `json:"remoteId"` |
| 45 | UniTagList []UniTagInformation `json:"uniTagList"` |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 46 | NniDhcpTrapVid int `json:"nniDhcpTrapVid"` |
| 47 | Slot int `json:"slot"` |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 48 | } |
| 49 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 50 | // UniTagInformation - Service information |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 51 | type UniTagInformation struct { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 52 | UpstreamBandwidthProfile string `json:"upstreamBandwidthProfile"` |
| 53 | DownstreamBandwidthProfile string `json:"downstreamBandwidthProfile"` |
| 54 | UpstreamOltBandwidthProfile string `json:"upstreamOltBandwidthProfile"` |
| 55 | DownstreamOltBandwidthProfile string `json:"downstreamOltBandwidthProfile"` |
| 56 | ServiceName string `json:"serviceName"` |
| 57 | ConfiguredMacAddress string `json:"configuredMacAddress"` |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 58 | UniTagMatch int `json:"uniTagMatch"` |
| 59 | PonCTag int `json:"ponCTag"` |
| 60 | PonSTag int `json:"ponSTag"` |
| 61 | UsPonCTagPriority int `json:"usPonCTagPriority"` |
| 62 | UsPonSTagPriority int `json:"usPonSTagPriority"` |
| 63 | DsPonCTagPriority int `json:"dsPonCTagPriority"` |
| 64 | DsPonSTagPriority int `json:"dsPonSTagPriority"` |
| 65 | TechnologyProfileID int `json:"technologyProfileId"` |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 66 | EnableMacLearning bool `json:"enableMacLearning"` |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 67 | IsDhcpRequired bool `json:"isDhcpRequired"` |
| 68 | IsIgmpRequired bool `json:"isIgmpRequired"` |
| 69 | IsPppoeRequired bool `json:"isPppoeRequired"` |
| 70 | } |
| 71 | |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 72 | func init() { |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 73 | // Setup this package so that it's log level can be modified at run time |
| 74 | var err error |
| 75 | logger, err = log.AddPackageWithDefaultParam() |
| 76 | if err != nil { |
| 77 | panic(err) |
| 78 | } |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 79 | } |
| 80 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 81 | // SubscriberHandle handle SubscriberInfo Requests |
| 82 | type SubscriberHandle struct { |
| 83 | } |
| 84 | |
| 85 | // ServeHTTP to serve http request |
| 86 | func (sh *SubscriberHandle) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
| 87 | logger.Infow(ctx, "Received-northbound-request", log.Fields{"Method": r.Method, "URL": r.URL}) |
| 88 | switch r.Method { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 89 | case cPost: |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 90 | sh.AddSubscriberInfo(context.Background(), w, r) |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 91 | case cDelete: |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 92 | sh.DelSubscriberInfo(context.Background(), w, r) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 93 | default: |
| 94 | logger.Warnw(ctx, "Unsupported Method", log.Fields{"Method": r.Method}) |
Hitesh Chhabra | 7d249a0 | 2023-07-04 21:33:49 +0530 | [diff] [blame] | 95 | err := errorCodes.ErrOperationNotSupported |
| 96 | http.Error(w, err.Error(), http.StatusBadRequest) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | |
Akash Soni | 634d9bf | 2023-07-10 12:11:10 +0530 | [diff] [blame] | 100 | func (sh *SubscriberHandle) StatusServeHTTP(w http.ResponseWriter, r *http.Request) { |
| 101 | logger.Infow(ctx, "Received-northbound-request", log.Fields{"Method": r.Method, "URL": r.URL}) |
| 102 | switch r.Method { |
| 103 | case cGet: |
| 104 | sh.GetSubscriberAndFlowProvisionStatus(context.Background(), w, r) |
| 105 | default: |
| 106 | logger.Warnw(ctx, "Unsupported Method", log.Fields{"Method": r.Method}) |
| 107 | } |
| 108 | } |
| 109 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 110 | // AddSubscriberInfo to add service |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 111 | func (sh *SubscriberHandle) AddSubscriberInfo(cntx context.Context, w http.ResponseWriter, r *http.Request) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 112 | // Get the payload to process the request |
| 113 | d := new(bytes.Buffer) |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 114 | if _, err := d.ReadFrom(r.Body); err != nil { |
Hitesh Chhabra | 8c3f166 | 2023-07-19 13:15:16 +0530 | [diff] [blame] | 115 | logger.Errorw(ctx, "Error reading buffer", log.Fields{"Reason": err.Error()}) |
| 116 | http.Error(w, err.Error(), http.StatusConflict) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 117 | return |
| 118 | } |
| 119 | |
| 120 | // Unmarshal the request into service configuration structure |
| 121 | req := &SubscriberDeviceInfo{} |
| 122 | if err := json.Unmarshal(d.Bytes(), req); err != nil { |
Hitesh Chhabra | 8c3f166 | 2023-07-19 13:15:16 +0530 | [diff] [blame] | 123 | logger.Errorw(ctx, "Failed to Unmarshal Adding Subscriber", log.Fields{"req": req, "Reason": err.Error()}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 124 | http.Error(w, err.Error(), http.StatusConflict) |
| 125 | return |
| 126 | } |
Hitesh Chhabra | 8c3f166 | 2023-07-19 13:15:16 +0530 | [diff] [blame] | 127 | logger.Infow(ctx, "Received-northbound-add-service-request", log.Fields{"req": req}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 128 | |
| 129 | //vsCfgList := getVoltServiceFromSrvInfo(req) |
| 130 | |
Akash Soni | 53da285 | 2023-03-15 00:31:31 +0530 | [diff] [blame] | 131 | addAllService(cntx, req) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 132 | } |
| 133 | |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 134 | func addAllService(cntx context.Context, srvInfo *SubscriberDeviceInfo) { |
Akash Soni | 6f36945 | 2023-09-19 11:18:28 +0530 | [diff] [blame] | 135 | var voltAppIntr app.VoltAppInterface |
| 136 | voltApp := app.GetApplication() |
| 137 | voltAppIntr = voltApp |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 138 | if len(srvInfo.UniTagList) == 0 { |
Hitesh Chhabra | 8c3f166 | 2023-07-19 13:15:16 +0530 | [diff] [blame] | 139 | logger.Infow(ctx, "Received OLT configuration", log.Fields{"req": srvInfo}) |
Akash Soni | 6f36945 | 2023-09-19 11:18:28 +0530 | [diff] [blame] | 140 | err := voltAppIntr.AddDeviceConfig(cntx, srvInfo.ID, srvInfo.HardwareIdentifier, srvInfo.NasID, srvInfo.IPAddress, srvInfo.UplinkPort, srvInfo.NniDhcpTrapVid) |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 141 | if err != nil { |
Hitesh Chhabra | 8c3f166 | 2023-07-19 13:15:16 +0530 | [diff] [blame] | 142 | logger.Warnw(ctx, "Device config addition failed :", log.Fields{"req": srvInfo, "Reason": err.Error()}) |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 143 | } |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 144 | return |
| 145 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 146 | for _, uniTagInfo := range srvInfo.UniTagList { |
Akash Soni | 6f36945 | 2023-09-19 11:18:28 +0530 | [diff] [blame] | 147 | var vs app.VoltServiceCfg |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 148 | |
| 149 | svcname := srvInfo.ID + "_" |
| 150 | svcname = svcname + srvInfo.NasPortID + "-" |
| 151 | svcname = svcname + strconv.Itoa(uniTagInfo.UniTagMatch) + "-" |
| 152 | svcname = svcname + strconv.Itoa(uniTagInfo.PonSTag) + "-" |
| 153 | svcname = svcname + strconv.Itoa(uniTagInfo.PonCTag) + "-" |
| 154 | vs.Name = svcname + strconv.Itoa(uniTagInfo.TechnologyProfileID) |
| 155 | |
| 156 | vs.Port = srvInfo.NasPortID |
| 157 | vs.SVlan = of.VlanType(uniTagInfo.PonSTag) |
| 158 | vs.CVlan = of.VlanType(uniTagInfo.PonCTag) |
| 159 | vs.UniVlan = of.VlanType(uniTagInfo.UniTagMatch) |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 160 | vs.UsPonCTagPriority = of.PbitType(uniTagInfo.UsPonCTagPriority) |
| 161 | vs.UsPonSTagPriority = of.PbitType(uniTagInfo.UsPonSTagPriority) |
| 162 | vs.DsPonCTagPriority = of.PbitType(uniTagInfo.UsPonCTagPriority) |
| 163 | vs.DsPonSTagPriority = of.PbitType(uniTagInfo.UsPonSTagPriority) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 164 | vs.TechProfileID = uint16(uniTagInfo.TechnologyProfileID) |
| 165 | vs.UsMeterProfile = uniTagInfo.UpstreamBandwidthProfile |
| 166 | vs.DsMeterProfile = uniTagInfo.DownstreamBandwidthProfile |
| 167 | vs.IgmpEnabled = uniTagInfo.IsIgmpRequired |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 168 | vs.ServiceType = uniTagInfo.ServiceName |
| 169 | |
Akash Soni | ef452f1 | 2024-12-12 18:20:28 +0530 | [diff] [blame^] | 170 | // Check if the service already exists for same Uniport and TechProfID |
| 171 | if voltApp.CheckServiceExists(vs.Port, vs.TechProfileID) { |
| 172 | logger.Warnw(ctx, "Service already exists for same port and TP Id", log.Fields{"ServiceName": vs.Name, "Port": vs.Port, "TechProfileID": vs.TechProfileID, "SVlan": vs.SVlan}) |
| 173 | continue |
| 174 | } |
| 175 | |
Hitesh Chhabra | 8c3f166 | 2023-07-19 13:15:16 +0530 | [diff] [blame] | 176 | logger.Debugw(ctx, "", log.Fields{"ServiceName": vs.Name}) |
| 177 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 178 | if uniTagInfo.ServiceName == app.DpuMgmtTraffic || |
| 179 | uniTagInfo.ServiceName == app.DpuAncpTraffic || |
| 180 | uniTagInfo.ServiceName == app.FttbSubscriberTraffic { |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 181 | vs.UniVlan = vs.CVlan |
| 182 | vs.Pbits = append(vs.Pbits, of.PbitMatchAll) |
| 183 | } else { |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 184 | if uniTagInfo.UsPonSTagPriority == -1 { |
| 185 | vs.Pbits = append(vs.Pbits, of.PbitMatchAll) |
| 186 | // Process the p-bits received in the request |
| 187 | } else { |
| 188 | if uniTagInfo.UsPonSTagPriority < 8 { |
| 189 | vs.Pbits = append(vs.Pbits, of.PbitType(uniTagInfo.UsPonCTagPriority)) |
| 190 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 191 | |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 192 | if uniTagInfo.UsPonSTagPriority < 8 && uniTagInfo.UsPonSTagPriority != uniTagInfo.DsPonSTagPriority { |
| 193 | vs.Pbits = append(vs.Pbits, of.PbitType(uniTagInfo.DsPonCTagPriority)) |
| 194 | } |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 195 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 196 | } |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 197 | //vs.McastService = uniTagInfo.IsIgmpRequired |
| 198 | if vs.IgmpEnabled { |
| 199 | vs.MvlanProfileName = "mvlan" + strconv.Itoa(uniTagInfo.PonSTag) |
| 200 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 201 | /* |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 202 | var err error |
| 203 | if vs.MacAddr, err = net.ParseMAC(srvInfo.HardwareIdentifier); err != nil { |
| 204 | vs.MacAddr, _ = net.ParseMAC("00:00:00:00:00:00") |
| 205 | }*/ |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 206 | |
| 207 | vs.MacAddr, _ = net.ParseMAC("00:00:00:00:00:00") |
| 208 | if len(vs.Pbits) == 0 { |
| 209 | vs.Pbits = append(vs.Pbits, of.PbitMatchNone) |
| 210 | } |
| 211 | |
| 212 | vnetName := strconv.FormatUint(uint64(vs.SVlan), 10) + "-" |
| 213 | vnetName = vnetName + strconv.FormatUint(uint64(vs.CVlan), 10) + "-" |
| 214 | vnetName = vnetName + strconv.FormatUint(uint64(vs.UniVlan), 10) |
| 215 | |
Hitesh Chhabra | 8c3f166 | 2023-07-19 13:15:16 +0530 | [diff] [blame] | 216 | logger.Debugw(ctx, "", log.Fields{"VnetName": vnetName}) |
| 217 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 218 | vnetcfg := app.VnetConfig{ |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 219 | Name: vnetName, |
| 220 | SVlan: vs.SVlan, |
| 221 | CVlan: vs.CVlan, |
| 222 | UniVlan: vs.UniVlan, |
| 223 | SVlanTpid: layers.EthernetTypeDot1Q, |
| 224 | DhcpRelay: uniTagInfo.IsDhcpRequired, |
| 225 | VnetType: uniTagInfo.ServiceName, |
| 226 | UsPonCTagPriority: vs.UsPonCTagPriority, |
| 227 | UsPonSTagPriority: vs.UsPonSTagPriority, |
| 228 | DsPonCTagPriority: vs.UsPonCTagPriority, |
| 229 | DsPonSTagPriority: vs.UsPonSTagPriority, |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 230 | //ONTEtherTypeClassification: req.ONTEtherTypeClassification, |
| 231 | //VlanControl: app.VlanControl(req.VlanControl), //TODO |
| 232 | } |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 233 | if uniTagInfo.EnableMacLearning { |
| 234 | vnetcfg.MacLearning = app.Learn |
| 235 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 236 | if uniTagInfo.UsPonSTagPriority < 8 { |
| 237 | vnetcfg.UsDhcpPbit = append(vnetcfg.UsDhcpPbit, of.PbitType(uniTagInfo.UsPonSTagPriority)) |
| 238 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 239 | if vs.CVlan != of.VlanAny && vs.SVlan != of.VlanAny { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 240 | if uniTagInfo.ServiceName == app.DpuMgmtTraffic || |
| 241 | uniTagInfo.ServiceName == app.DpuAncpTraffic { |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 242 | vnetcfg.VlanControl = app.ONUCVlan |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 243 | } else if uniTagInfo.ServiceName == app.FttbSubscriberTraffic { |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 244 | vnetcfg.VlanControl = app.OLTSVlan |
| 245 | } else { |
| 246 | vnetcfg.VlanControl = app.ONUCVlanOLTSVlan |
| 247 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 248 | } else if vs.CVlan == of.VlanAny && vs.UniVlan == of.VlanAny { |
| 249 | vnetcfg.VlanControl = app.OLTSVlan |
| 250 | } |
Akash Soni | 6f36945 | 2023-09-19 11:18:28 +0530 | [diff] [blame] | 251 | if err := voltAppIntr.AddVnet(cntx, vnetcfg, nil); err != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 252 | logger.Errorw(ctx, "AddVnet Failed", log.Fields{"VnetName": vnetName, "Error": err}) |
| 253 | } |
Akash Soni | 6f36945 | 2023-09-19 11:18:28 +0530 | [diff] [blame] | 254 | if err := voltAppIntr.AddService(cntx, vs, nil); err != nil { |
Hitesh Chhabra | 8c3f166 | 2023-07-19 13:15:16 +0530 | [diff] [blame] | 255 | logger.Errorw(ctx, "AddService Failed", log.Fields{"Service": vs.Name, "Error": err.Error()}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 256 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | |
| 260 | // DelSubscriberInfo to delete service |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 261 | func (sh *SubscriberHandle) DelSubscriberInfo(cntx context.Context, w http.ResponseWriter, r *http.Request) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 262 | vars := mux.Vars(r) |
| 263 | id := vars["id"] |
| 264 | |
Sridhar Ravindra | b8374ae | 2023-04-14 15:49:25 +0530 | [diff] [blame] | 265 | d := new(bytes.Buffer) |
| 266 | if _, err := d.ReadFrom(r.Body); err != nil { |
Hitesh Chhabra | 8c3f166 | 2023-07-19 13:15:16 +0530 | [diff] [blame] | 267 | logger.Errorw(ctx, "Error reading buffer", log.Fields{"req id": id, "Reason": err.Error()}) |
| 268 | w.WriteHeader(http.StatusConflict) |
Sridhar Ravindra | b8374ae | 2023-04-14 15:49:25 +0530 | [diff] [blame] | 269 | return |
| 270 | } |
| 271 | |
| 272 | // Unmarshal the request into service configuration structure |
| 273 | req := &SubscriberDeviceInfo{} |
| 274 | if err := json.Unmarshal(d.Bytes(), req); err != nil { |
| 275 | logger.Warnw(ctx, "Unmarshal Failed", log.Fields{"Reason": err.Error()}) |
| 276 | http.Error(w, err.Error(), http.StatusConflict) |
| 277 | return |
| 278 | } |
| 279 | |
| 280 | for _, uniTagInfo := range req.UniTagList { |
| 281 | svcname := req.ID + "_" |
| 282 | svcname = svcname + req.NasPortID + "-" |
| 283 | svcname = svcname + strconv.Itoa(uniTagInfo.UniTagMatch) + "-" |
| 284 | svcname = svcname + strconv.Itoa(uniTagInfo.PonSTag) + "-" |
| 285 | svcname = svcname + strconv.Itoa(uniTagInfo.PonCTag) + "-" |
| 286 | svcname = svcname + strconv.Itoa(uniTagInfo.TechnologyProfileID) |
| 287 | |
| 288 | if uniTagInfo.ServiceName == app.FttbSubscriberTraffic { |
| 289 | id = svcname |
| 290 | } |
| 291 | } |
| 292 | |
Hitesh Chhabra | 8c3f166 | 2023-07-19 13:15:16 +0530 | [diff] [blame] | 293 | logger.Infow(ctx, "Received northbound-del-service-req", log.Fields{"ServiceName": id}) |
Hitesh Chhabra | 7d249a0 | 2023-07-04 21:33:49 +0530 | [diff] [blame] | 294 | err := app.GetApplication().DelServiceWithPrefix(cntx, id) |
| 295 | if err != nil { |
| 296 | logger.Warnw(ctx, "northbound-del-service-req failed, Subscriber not exist", log.Fields{"ServiceName": id}) |
| 297 | http.Error(w, err.Error(), http.StatusBadRequest) |
| 298 | return |
| 299 | } |
| 300 | |
| 301 | // HTTP response with 202 accepted for service delete request |
| 302 | w.WriteHeader(http.StatusAccepted) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 303 | } |
Akash Soni | 634d9bf | 2023-07-10 12:11:10 +0530 | [diff] [blame] | 304 | |
| 305 | // DelSubscriberInfo to delete service |
| 306 | func (sh *SubscriberHandle) GetSubscriberAndFlowProvisionStatus(cntx context.Context, w http.ResponseWriter, r *http.Request) { |
| 307 | vars := mux.Vars(r) |
| 308 | portName := vars["portName"] |
| 309 | logger.Debugw(ctx, "Received-northbound-GetSubscriberProvisionStatus-request", log.Fields{"req": portName}) |
Akash Soni | 6f36945 | 2023-09-19 11:18:28 +0530 | [diff] [blame] | 310 | var voltAppIntr app.VoltAppInterface |
| 311 | voltApp := app.GetApplication() |
| 312 | voltAppIntr = voltApp |
| 313 | flowProvisionStatus := voltAppIntr.GetFlowProvisionStatus(portName) |
Akash Soni | 634d9bf | 2023-07-10 12:11:10 +0530 | [diff] [blame] | 314 | flowProvisionStatusRes, err := json.Marshal(flowProvisionStatus) |
| 315 | if err != nil { |
| 316 | logger.Errorw(ctx, "Error occurred while marshaling flowProvisionStatus response", log.Fields{"Error": err}) |
| 317 | w.WriteHeader(http.StatusInternalServerError) |
| 318 | return |
| 319 | } |
| 320 | w.Header().Add("Content-Type", "application/json") |
| 321 | _, err = w.Write(flowProvisionStatusRes) |
| 322 | if err != nil { |
| 323 | logger.Errorw(ctx, "error in sending flowProvisionStatus response", log.Fields{"Error": err}) |
| 324 | w.WriteHeader(http.StatusInternalServerError) |
| 325 | } |
| 326 | } |