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