Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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 | |
| 17 | package sadis |
| 18 | |
| 19 | import ( |
| 20 | "encoding/json" |
| 21 | "net/http" |
| 22 | "strings" |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 23 | |
| 24 | "github.com/gorilla/mux" |
| 25 | "github.com/opencord/bbsim/internal/bbsim/devices" |
| 26 | "github.com/opencord/bbsim/internal/common" |
| 27 | log "github.com/sirupsen/logrus" |
| 28 | ) |
| 29 | |
| 30 | var sadisLogger = log.WithFields(log.Fields{ |
| 31 | "module": "SADIS", |
| 32 | }) |
| 33 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame^] | 34 | type SadisServer struct { |
| 35 | Olt *devices.OltDevice |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | // bandwidthProfiles contains some dummy profiles |
Matteo Scandolo | 51d6a31 | 2020-03-12 15:54:43 -0700 | [diff] [blame] | 39 | var bandwidthProfiles = []*SadisBWPEntry{ |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 40 | {ID: "User_Bandwidth1", AIR: 100000, CBS: 10000, CIR: 30000, EBS: 1000, EIR: 100000}, |
| 41 | {ID: "User_Bandwidth2", AIR: 100000, CBS: 5000, CIR: 100000, EBS: 5000, EIR: 100000}, |
| 42 | {ID: "User_Bandwidth3", AIR: 100000, CBS: 5000, CIR: 1000000, EBS: 5000, EIR: 1000000}, |
| 43 | {ID: "Default", AIR: 100000, CBS: 30, CIR: 600, EBS: 30, EIR: 400}, |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | // SadisConfig is the top-level SADIS configuration struct |
| 47 | type SadisConfig struct { |
| 48 | Sadis SadisEntries `json:"sadis"` |
| 49 | BandwidthProfile BandwidthProfileEntries `json:"bandwidthprofile"` |
| 50 | } |
| 51 | |
| 52 | type SadisEntries struct { |
| 53 | Integration SadisIntegration `json:"integration"` |
| 54 | Entries []interface{} `json:"entries,omitempty"` |
| 55 | } |
| 56 | type BandwidthProfileEntries struct { |
| 57 | Integration SadisIntegration `json:"integration"` |
Matteo Scandolo | 51d6a31 | 2020-03-12 15:54:43 -0700 | [diff] [blame] | 58 | Entries []*SadisBWPEntry `json:"entries,omitempty"` |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | type SadisIntegration struct { |
| 62 | URL string `json:"url,omitempty"` |
| 63 | Cache struct { |
| 64 | Enabled bool `json:"enabled"` |
| 65 | MaxSize int `json:"maxsize"` |
| 66 | TTL string `json:"ttl"` |
| 67 | } `json:"cache"` |
| 68 | } |
| 69 | |
| 70 | type SadisOltEntry struct { |
| 71 | ID string `json:"id"` |
| 72 | HardwareIdentifier string `json:"hardwareIdentifier"` |
| 73 | IPAddress string `json:"ipAddress"` |
| 74 | NasID string `json:"nasId"` |
| 75 | UplinkPort int `json:"uplinkPort"` |
| 76 | } |
| 77 | |
Anand S Katti | b409ee0 | 2020-02-20 20:10:00 +0530 | [diff] [blame] | 78 | type SadisOnuEntryV2 struct { |
| 79 | ID string `json:"id"` |
| 80 | NasPortID string `json:"nasPortId"` |
| 81 | CircuitID string `json:"circuitId"` |
| 82 | RemoteID string `json:"remoteId"` |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 83 | UniTagList []SadisUniTag `json:"uniTagList"` // this can be SadisUniTagAtt, SadisUniTagDt |
Anand S Katti | b409ee0 | 2020-02-20 20:10:00 +0530 | [diff] [blame] | 84 | } |
| 85 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 86 | type SadisUniTag struct { |
| 87 | UniTagMatch int `json:"uniTagMatch,omitempty"` |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 88 | PonCTag int `json:"ponCTag,omitempty"` |
| 89 | PonSTag int `json:"ponSTag,omitempty"` |
| 90 | TechnologyProfileID int `json:"technologyProfileId,omitempty"` |
| 91 | UpstreamBandwidthProfile string `json:"upstreamBandwidthProfile,omitempty"` |
| 92 | DownstreamBandwidthProfile string `json:"downstreamBandwidthProfile,omitempty"` |
| 93 | IsDhcpRequired bool `json:"isDhcpRequired,omitempty"` |
| 94 | IsIgmpRequired bool `json:"isIgmpRequired,omitempty"` |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 95 | ConfiguredMacAddress string `json:"configuredMacAddress,omitempty"` |
Matteo Scandolo | 8d28137 | 2020-09-03 16:23:37 -0700 | [diff] [blame] | 96 | UsPonCTagPriority uint8 `json:"usPonCTagPriority,omitempty"` |
| 97 | UsPonSTagPriority uint8 `json:"usPonSTagPriority,omitempty"` |
| 98 | DsPonCTagPriority uint8 `json:"dsPonCTagPriority,omitempty"` |
| 99 | DsPonSTagPriority uint8 `json:"dsPonSTagPriority,omitempty"` |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 100 | ServiceName string `json:"serviceName,omitempty"` |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 103 | // SADIS BandwithProfile Entry |
| 104 | type SadisBWPEntry struct { |
| 105 | ID string `json:"id"` |
| 106 | AIR int `json:"air"` |
| 107 | CBS int `json:"cbs"` |
| 108 | CIR int `json:"cir"` |
| 109 | EBS int `json:"ebs"` |
| 110 | EIR int `json:"eir"` |
| 111 | } |
| 112 | |
| 113 | // GetSadisConfig returns a full SADIS configuration struct ready to be marshalled into JSON |
Anand S Katti | b409ee0 | 2020-02-20 20:10:00 +0530 | [diff] [blame] | 114 | func GetSadisConfig(olt *devices.OltDevice, version string) *SadisConfig { |
| 115 | sadisEntries, _ := GetSadisEntries(olt, version) |
| 116 | bwpEntries := getBWPEntries(version) |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 117 | |
| 118 | conf := &SadisConfig{} |
| 119 | conf.Sadis = *sadisEntries |
| 120 | conf.BandwidthProfile = *bwpEntries |
| 121 | |
| 122 | return conf |
| 123 | } |
| 124 | |
Anand S Katti | b409ee0 | 2020-02-20 20:10:00 +0530 | [diff] [blame] | 125 | func GetSadisEntries(olt *devices.OltDevice, version string) (*SadisEntries, error) { |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 126 | solt, _ := GetOltEntry(olt) |
| 127 | |
| 128 | entries := []interface{}{} |
| 129 | entries = append(entries, solt) |
| 130 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 131 | a := strings.Split(common.Config.BBSim.SadisRestAddress, ":") |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 132 | port := a[len(a)-1] |
| 133 | |
| 134 | integration := SadisIntegration{} |
Anand S Katti | b409ee0 | 2020-02-20 20:10:00 +0530 | [diff] [blame] | 135 | integration.URL = "http://bbsim:" + port + "/" + version + "/subscribers/%s" |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 136 | integration.Cache.Enabled = false |
| 137 | integration.Cache.MaxSize = 50 |
| 138 | integration.Cache.TTL = "PT0m" |
| 139 | |
| 140 | sadis := &SadisEntries{ |
| 141 | integration, |
| 142 | entries, |
| 143 | } |
| 144 | |
| 145 | return sadis, nil |
| 146 | } |
| 147 | |
| 148 | func GetOltEntry(olt *devices.OltDevice) (*SadisOltEntry, error) { |
| 149 | ip, _ := common.GetIPAddr("nni") // TODO verify which IP to report |
| 150 | solt := &SadisOltEntry{ |
| 151 | ID: olt.SerialNumber, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 152 | HardwareIdentifier: common.Config.Olt.DeviceId, |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 153 | IPAddress: ip, |
| 154 | NasID: olt.SerialNumber, |
Anand S Katti | b409ee0 | 2020-02-20 20:10:00 +0530 | [diff] [blame] | 155 | UplinkPort: 1048576, // TODO currently assumes we only have one NNI port |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 156 | } |
| 157 | return solt, nil |
| 158 | } |
| 159 | |
Anand S Katti | b409ee0 | 2020-02-20 20:10:00 +0530 | [diff] [blame] | 160 | func GetOnuEntryV2(olt *devices.OltDevice, onu *devices.Onu, uniId string) (*SadisOnuEntryV2, error) { |
| 161 | uniSuffix := "-" + uniId |
| 162 | |
| 163 | sonuv2 := &SadisOnuEntryV2{ |
Matteo Scandolo | df08044 | 2020-10-09 11:57:38 -0700 | [diff] [blame] | 164 | ID: onu.Sn() + uniSuffix, |
Anand S Katti | b409ee0 | 2020-02-20 20:10:00 +0530 | [diff] [blame] | 165 | } |
Matteo Scandolo | 51d6a31 | 2020-03-12 15:54:43 -0700 | [diff] [blame] | 166 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 167 | // createUniTagList |
| 168 | for _, s := range onu.Services { |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 169 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 170 | service := s.(*devices.Service) |
| 171 | |
| 172 | tag := SadisUniTag{ |
| 173 | ServiceName: service.Name, |
| 174 | IsIgmpRequired: service.NeedsIgmp, |
| 175 | IsDhcpRequired: service.NeedsDhcp, |
| 176 | TechnologyProfileID: service.TechnologyProfileID, |
| 177 | UpstreamBandwidthProfile: "User_Bandwidth1", |
| 178 | DownstreamBandwidthProfile: "User_Bandwidth2", |
| 179 | PonCTag: service.CTag, |
| 180 | PonSTag: service.STag, |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 181 | } |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 182 | |
| 183 | if service.UniTagMatch != 0 { |
| 184 | tag.UniTagMatch = service.UniTagMatch |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 185 | } |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 186 | |
| 187 | if service.ConfigureMacAddress { |
| 188 | tag.ConfiguredMacAddress = service.HwAddress.String() |
| 189 | } |
| 190 | |
| 191 | if service.UsPonCTagPriority != 0 { |
| 192 | tag.UsPonCTagPriority = service.UsPonCTagPriority |
| 193 | } |
| 194 | |
| 195 | if service.UsPonSTagPriority != 0 { |
| 196 | tag.UsPonSTagPriority = service.UsPonSTagPriority |
| 197 | } |
| 198 | |
| 199 | if service.DsPonCTagPriority != 0 { |
| 200 | tag.DsPonCTagPriority = service.DsPonCTagPriority |
| 201 | } |
| 202 | |
| 203 | if service.DsPonSTagPriority != 0 { |
| 204 | tag.DsPonSTagPriority = service.DsPonSTagPriority |
| 205 | } |
| 206 | |
| 207 | sonuv2.UniTagList = append(sonuv2.UniTagList, tag) |
Anand S Katti | b409ee0 | 2020-02-20 20:10:00 +0530 | [diff] [blame] | 208 | } |
Matteo Scandolo | 51d6a31 | 2020-03-12 15:54:43 -0700 | [diff] [blame] | 209 | |
Anand S Katti | b409ee0 | 2020-02-20 20:10:00 +0530 | [diff] [blame] | 210 | return sonuv2, nil |
| 211 | } |
| 212 | |
| 213 | func getBWPEntries(version string) *BandwidthProfileEntries { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 214 | a := strings.Split(common.Config.BBSim.SadisRestAddress, ":") |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 215 | port := a[len(a)-1] |
| 216 | |
| 217 | integration := SadisIntegration{} |
Anand S Katti | b409ee0 | 2020-02-20 20:10:00 +0530 | [diff] [blame] | 218 | integration.URL = "http://bbsim:" + port + "/" + version + "/bandwidthprofiles/%s" |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 219 | integration.Cache.Enabled = true |
| 220 | integration.Cache.MaxSize = 40 |
| 221 | integration.Cache.TTL = "PT1m" |
| 222 | |
| 223 | bwp := &BandwidthProfileEntries{ |
| 224 | Integration: integration, |
| 225 | } |
| 226 | |
| 227 | return bwp |
| 228 | } |
| 229 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame^] | 230 | func (s *SadisServer) ServeBaseConfig(w http.ResponseWriter, r *http.Request) { |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 231 | w.Header().Set("Content-Type", "application/json") |
| 232 | w.WriteHeader(http.StatusOK) |
Anand S Katti | b409ee0 | 2020-02-20 20:10:00 +0530 | [diff] [blame] | 233 | vars := mux.Vars(r) |
| 234 | |
| 235 | if vars["version"] != "v1" && vars["version"] != "v2" { |
| 236 | w.WriteHeader(http.StatusNotFound) |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 237 | _, _ = w.Write([]byte("{}")) |
Anand S Katti | b409ee0 | 2020-02-20 20:10:00 +0530 | [diff] [blame] | 238 | return |
| 239 | } |
| 240 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame^] | 241 | sadisConf := GetSadisConfig(s.Olt, vars["version"]) |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 242 | |
| 243 | sadisJSON, _ := json.Marshal(sadisConf) |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 244 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 245 | _, _ = w.Write([]byte(sadisJSON)) |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 246 | |
| 247 | } |
| 248 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame^] | 249 | func (s *SadisServer) ServeStaticConfig(w http.ResponseWriter, r *http.Request) { |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 250 | w.Header().Set("Content-Type", "application/json") |
| 251 | w.WriteHeader(http.StatusOK) |
Anand S Katti | b409ee0 | 2020-02-20 20:10:00 +0530 | [diff] [blame] | 252 | vars := mux.Vars(r) |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame^] | 253 | sadisConf := GetSadisConfig(s.Olt, vars["version"]) |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 254 | |
| 255 | sadisConf.Sadis.Integration.URL = "" |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame^] | 256 | for i := range s.Olt.Pons { |
| 257 | for _, onu := range s.Olt.Pons[i].Onus { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 258 | if vars["version"] == "v2" { |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame^] | 259 | sonuV2, _ := GetOnuEntryV2(s.Olt, onu, "1") |
Anand S Katti | b409ee0 | 2020-02-20 20:10:00 +0530 | [diff] [blame] | 260 | sadisConf.Sadis.Entries = append(sadisConf.Sadis.Entries, sonuV2) |
Anand S Katti | b409ee0 | 2020-02-20 20:10:00 +0530 | [diff] [blame] | 261 | } |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | |
| 265 | sadisConf.BandwidthProfile.Integration.URL = "" |
| 266 | sadisConf.BandwidthProfile.Entries = bandwidthProfiles |
| 267 | |
| 268 | sadisJSON, _ := json.Marshal(sadisConf) |
| 269 | sadisLogger.Tracef("SADIS JSON: %s", sadisJSON) |
| 270 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 271 | _, _ = w.Write([]byte(sadisJSON)) |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 272 | |
| 273 | } |
| 274 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame^] | 275 | func (s *SadisServer) ServeEntry(w http.ResponseWriter, r *http.Request) { |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 276 | w.Header().Set("Content-Type", "application/json") |
| 277 | vars := mux.Vars(r) |
| 278 | |
| 279 | // check if the requested ID is for the OLT |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame^] | 280 | if s.Olt.SerialNumber == vars["ID"] { |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 281 | sadisLogger.WithFields(log.Fields{ |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame^] | 282 | "OltSn": s.Olt.SerialNumber, |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 283 | }).Debug("Received SADIS OLT request") |
| 284 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame^] | 285 | sadisConf, _ := GetOltEntry(s.Olt) |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 286 | |
| 287 | w.WriteHeader(http.StatusOK) |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 288 | _ = json.NewEncoder(w).Encode(sadisConf) |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 289 | return |
| 290 | } |
| 291 | |
| 292 | i := strings.Split(vars["ID"], "-") // split ID to get serial number and uni port |
| 293 | if len(i) != 2 { |
| 294 | w.WriteHeader(http.StatusUnprocessableEntity) |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 295 | _, _ = w.Write([]byte("{}")) |
Anand S Katti | b409ee0 | 2020-02-20 20:10:00 +0530 | [diff] [blame] | 296 | sadisLogger.Warnf("Received invalid SADIS SubscriberId: %s", vars["ID"]) |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 297 | return |
| 298 | } |
| 299 | sn, uni := i[0], i[len(i)-1] |
| 300 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame^] | 301 | onu, err := s.Olt.FindOnuBySn(sn) |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 302 | if err != nil { |
| 303 | w.WriteHeader(http.StatusNotFound) |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 304 | _, _ = w.Write([]byte("{}")) |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 305 | sadisLogger.WithFields(log.Fields{ |
| 306 | "OnuSn": sn, |
| 307 | "OnuId": "NA", |
Anand S Katti | b409ee0 | 2020-02-20 20:10:00 +0530 | [diff] [blame] | 308 | }).Warnf("Requested Subscriber entry not found for OnuSn: %s", vars["ID"]) |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 309 | return |
| 310 | } |
| 311 | |
| 312 | sadisLogger.WithFields(log.Fields{ |
| 313 | "OnuId": onu.ID, |
| 314 | "OnuSn": sn, |
| 315 | "OnuPortNo": uni, |
| 316 | }).Debug("Received SADIS request") |
| 317 | |
Anand S Katti | b409ee0 | 2020-02-20 20:10:00 +0530 | [diff] [blame] | 318 | if vars["version"] == "v1" { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 319 | // TODO format error |
| 320 | w.WriteHeader(http.StatusBadRequest) |
| 321 | _ = json.NewEncoder(w).Encode("Sadis v1 is not supported anymore, please go back to an earlier BBSim version") |
Anand S Katti | b409ee0 | 2020-02-20 20:10:00 +0530 | [diff] [blame] | 322 | } else if vars["version"] == "v2" { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 323 | w.WriteHeader(http.StatusOK) |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame^] | 324 | sadisConf, _ := GetOnuEntryV2(s.Olt, onu, uni) |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 325 | _ = json.NewEncoder(w).Encode(sadisConf) |
Anand S Katti | b409ee0 | 2020-02-20 20:10:00 +0530 | [diff] [blame] | 326 | } |
| 327 | |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 328 | } |
| 329 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame^] | 330 | func (s *SadisServer) ServeBWPEntry(w http.ResponseWriter, r *http.Request) { |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 331 | w.Header().Set("Content-Type", "application/json") |
| 332 | vars := mux.Vars(r) |
| 333 | id := vars["ID"] |
Anand S Katti | b409ee0 | 2020-02-20 20:10:00 +0530 | [diff] [blame] | 334 | |
| 335 | if vars["version"] != "v1" && vars["version"] != "v2" { |
| 336 | w.WriteHeader(http.StatusNotFound) |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 337 | _, _ = w.Write([]byte("{}")) |
Anand S Katti | b409ee0 | 2020-02-20 20:10:00 +0530 | [diff] [blame] | 338 | return |
| 339 | } |
| 340 | |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 341 | sadisLogger.Debugf("Received request for SADIS bandwidth profile %s", id) |
| 342 | |
Matteo Scandolo | 51d6a31 | 2020-03-12 15:54:43 -0700 | [diff] [blame] | 343 | for _, bwpEntry := range bandwidthProfiles { |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 344 | if bwpEntry.ID == id { |
| 345 | w.WriteHeader(http.StatusOK) |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 346 | _ = json.NewEncoder(w).Encode(bwpEntry) |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 347 | return |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | w.WriteHeader(http.StatusNotFound) |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 352 | _, _ = w.Write([]byte("{}")) |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 353 | } |