Takahiro Suzuki | d7bf820 | 2020-12-17 20:21:59 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020-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 | package core |
| 17 | |
| 18 | import ( |
| 19 | "context" |
| 20 | "encoding/binary" |
| 21 | "errors" |
| 22 | "fmt" |
| 23 | "strings" |
| 24 | "time" |
| 25 | |
| 26 | "github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore" |
| 27 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 28 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/core/l2oam" |
| 29 | oop "github.com/opencord/voltha-protos/v3/go/openolt" |
| 30 | "github.com/opencord/voltha-protos/v3/go/voltha" |
| 31 | ) |
| 32 | |
| 33 | func readTechProfile() { |
| 34 | address := "172.17.0.1:2379" |
| 35 | timeout := time.Second * 10 |
| 36 | |
| 37 | client, err := kvstore.NewEtcdClient(context.Background(), address, timeout, log.FatalLevel) |
| 38 | if err != nil { |
| 39 | return |
| 40 | } |
| 41 | defer client.Close(context.Background()) |
| 42 | ctx, cancel := context.WithTimeout(context.Background(), timeout) |
| 43 | resp, err := client.Get(ctx, "service/voltha/technology_profiles/EPON/64") |
| 44 | cancel() |
| 45 | if resp == nil || err != nil { |
| 46 | l2oam.OnuPkgType = l2oam.OnuPkgTypeB |
| 47 | logger.Error(ctx, fmt.Sprintf("readTechProfile() etcd get error. resp=%v, err=%v", resp, err)) |
| 48 | return |
| 49 | } |
| 50 | bytes := resp.Value.([]byte) |
| 51 | bytesString := string(bytes) |
| 52 | logger.Debug(ctx, fmt.Sprintf("readTechProfile() bytes string=%s", bytesString)) |
| 53 | if strings.Index(bytesString, "\"profile_type\":\"EPON\"") > 0 && strings.Index(bytesString, "\"package_type\":\"B\"") > 0 { |
| 54 | l2oam.OnuPkgType = l2oam.OnuPkgTypeB |
| 55 | } else { |
| 56 | l2oam.OnuPkgType = l2oam.OnuPkgTypeA |
| 57 | } |
| 58 | logger.Debug(ctx, fmt.Sprintf("readTechProfile() onu package=%s", l2oam.OnuPkgType)) |
| 59 | |
| 60 | } |
| 61 | |
| 62 | // L2oamGetDeviceInfo provides GetDeviceInfo for L2OAM |
| 63 | func L2oamGetDeviceInfo(ctx context.Context, dh *DeviceHandler) (*oop.DeviceInfo, error) { |
| 64 | logger.Debug(ctx, "GetDeviceInfo() Start.") |
| 65 | readTechProfile() |
| 66 | |
| 67 | dstMac := dh.device.MacAddress |
| 68 | deviceInfo := &oop.DeviceInfo{ |
| 69 | Vendor: "Tibit", |
| 70 | // Model string `protobuf:"bytes,2,opt,name=model,proto3" json:"model,omitempty"` |
| 71 | // HardwareVersion string `protobuf:"bytes,3,opt,name=hardware_version,json=hardwareVersion,proto3" json:"hardware_version,omitempty"` |
| 72 | // FirmwareVersion string `protobuf:"bytes,4,opt,name=firmware_version,json=firmwareVersion,proto3" json:"firmware_version,omitempty"` |
| 73 | DeviceId: dstMac, |
| 74 | // DeviceSerialNumber string `protobuf:"bytes,17,opt,name=device_serial_number,json=deviceSerialNumber,proto3" json:"device_serial_number,omitempty"` |
| 75 | PonPorts: 1, |
| 76 | Technology: "EPON", |
| 77 | OnuIdStart: 1, |
| 78 | OnuIdEnd: 128, |
| 79 | AllocIdStart: 5121, |
| 80 | AllocIdEnd: 9216, |
| 81 | GemportIdStart: 1, |
| 82 | GemportIdEnd: 65535, |
| 83 | FlowIdStart: 1, |
| 84 | FlowIdEnd: 16383, |
| 85 | // Ranges []*DeviceInfo_DeviceResourceRanges protobuf:"bytes,15,rep,name=ranges,proto3" json:"ranges,omitempty"` |
| 86 | } |
| 87 | olt := FindL2oamDevice(dstMac) |
| 88 | if olt == nil { |
| 89 | olt, _ = NewL2oamOltDevice(dstMac, dh) |
| 90 | olt.startKeepAlive() |
| 91 | } |
| 92 | |
| 93 | err00 := sendDiscoverySOLICIT(ctx, olt) |
| 94 | logger.Debug(ctx, fmt.Sprintf("Sequence returts: %v", err00)) |
| 95 | vendorName, err01 := sendGetVendorName(ctx, olt) |
| 96 | moduleNumber, err02 := sendGetModuleNumber(ctx, olt) |
| 97 | manuFacturer, err03 := sendManuFacturerInfo(ctx, olt) |
| 98 | firmwareVersion, err04 := sendGetFirmwareVersion(ctx, olt) |
| 99 | macAddress, err05 := sendGetMacAddress(ctx, olt) |
| 100 | serialNumber, err06 := sendGetSerialNumber(ctx, olt) |
| 101 | deviceInfo.Vendor = vendorName |
| 102 | deviceInfo.Model = moduleNumber |
| 103 | deviceInfo.HardwareVersion = manuFacturer |
| 104 | deviceInfo.FirmwareVersion = firmwareVersion |
| 105 | deviceInfo.DeviceId = macAddress |
| 106 | deviceInfo.DeviceSerialNumber = serialNumber |
| 107 | logger.Debug(ctx, fmt.Sprintf("Sequence returts: deviceInfo=%v, %v, %v, %v, %v, %v, %v, %v", deviceInfo, err00, err01, err02, err03, err04, err05, err06)) |
| 108 | |
| 109 | dh.device.SerialNumber = deviceInfo.DeviceSerialNumber |
| 110 | olt.setActiveState(ctx, true) |
| 111 | return deviceInfo, nil |
| 112 | } |
| 113 | |
| 114 | // L2oamEnableIndication runs EnableIndication sequence |
| 115 | func L2oamEnableIndication(ctx context.Context, dh *DeviceHandler) { |
| 116 | logger.Debug(ctx, "L2oamEnableIndication() Start.") |
| 117 | |
| 118 | olt := FindL2oamDeviceByDeviceID(dh.device.Id) |
| 119 | if olt == nil { |
| 120 | logger.Error(ctx, fmt.Sprintf("L2oamEnableIndication() FindL2oamDeviceByDeviceId() error. olt not found. deviceId=%s", dh.device.Id)) |
| 121 | return |
| 122 | } |
| 123 | |
| 124 | err01 := sendSetHbtxPeriod(ctx, olt) |
| 125 | err02 := sendSetHbtxTemplate(ctx, olt) |
| 126 | ponMode, err03 := sendGetPonMode(ctx, olt) |
| 127 | err04 := sendSetMPCPSync(ctx, olt) |
| 128 | err05 := sendSetAdminState(ctx, olt, true) |
| 129 | ponPortAction := sendSetGenericActionCreate(ctx, olt, l2oam.ActionTypeProtocolFilter) |
| 130 | if ponPortAction == nil { |
| 131 | return |
| 132 | } |
| 133 | actionIDPonPort := binary.BigEndian.Uint32(ponPortAction.GetTrafficProfile()) |
| 134 | err07 := sendSetIngressPort(ctx, olt, actionIDPonPort, true) |
| 135 | err08 := sendSetCaptureProtocols(ctx, olt, actionIDPonPort) |
| 136 | ethPortAction := sendSetGenericActionCreate(ctx, olt, l2oam.ActionTypeProtocolFilter) |
| 137 | if ethPortAction == nil { |
| 138 | return |
| 139 | } |
| 140 | actionIDEthPort := binary.BigEndian.Uint32(ethPortAction.GetTrafficProfile()) |
| 141 | err09 := sendSetIngressPort(ctx, olt, actionIDEthPort, false) |
| 142 | err10 := sendSetCaptureProtocols(ctx, olt, actionIDEthPort) |
| 143 | |
| 144 | oltDev := olt.(*L2oamOltDevice) |
| 145 | oltDev.Base.ActionIds = make(map[int]uint32) |
| 146 | oltDev.Base.ActionIds[ActionIDFilterPonPort] = actionIDPonPort |
| 147 | oltDev.Base.ActionIds[ActionIDFilterEthPort] = actionIDEthPort |
| 148 | olt.updateMap() |
| 149 | |
| 150 | err06 := sendSetAdminState(ctx, olt, false) |
| 151 | olt.setAutonomousFlag(true) |
| 152 | |
| 153 | logger.Debug(ctx, fmt.Sprintf("Sequence returns: ponMode=%s, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v", |
| 154 | ponMode, err01, err02, err03, err04, err05, err06, err07, err08, err09, err10)) |
| 155 | |
| 156 | } |
| 157 | |
| 158 | // L2oamAfterKeepAlive ... [obsoluted] |
| 159 | func L2oamAfterKeepAlive(ctx context.Context, dh *DeviceHandler) error { |
| 160 | |
| 161 | |
| 162 | |
| 163 | return nil |
| 164 | } |
| 165 | |
| 166 | //var flowVersion int = 1 // run add-flow each OLT |
| 167 | //var flowVersion int = 2 // run add-flow each ONU |
| 168 | var flowVersion int = 3 // run add-flow at specified ONU |
| 169 | |
| 170 | // L2oamAddFlow runs add-flow sequence |
| 171 | func L2oamAddFlow(ctx context.Context, dh *DeviceHandler, cmd *L2oamCmd) { |
| 172 | logger.Debug(ctx, "L2oamAddFlow() Start.") |
| 173 | if cmd.OnuDeviceID == "" { |
| 174 | flowVersion = 2 |
| 175 | } else { |
| 176 | flowVersion = 3 |
| 177 | } |
| 178 | |
| 179 | olt := FindL2oamDeviceByDeviceID(dh.device.Id) |
| 180 | if olt == nil { |
| 181 | logger.Error(ctx, fmt.Sprintf("L2oamAddFlow() FindL2oamDeviceByDeviceId() error. olt not found. deviceId=%s", dh.device.Id)) |
| 182 | return |
| 183 | } |
| 184 | |
| 185 | if flowVersion == 1 { |
| 186 | oc := &l2oam.TomiObjectContext{ |
| 187 | Branch: 0x0c, |
| 188 | Type: 0x0011, |
| 189 | Length: 4, |
| 190 | Instance: 0x00000002, |
| 191 | } |
| 192 | getTrafficControl := sendGetTrafficControlReferenceTable(ctx, olt, oc) |
| 193 | if getTrafficControl == nil { |
| 194 | logger.Error(ctx, "L2oamAddFlow() sendGetTrafficControlReferenceTable() error. ") |
| 195 | return |
| 196 | } |
| 197 | downProfile := sendSetGenericActionCreate(ctx, olt, l2oam.ActionTypeTrafficProfile) |
| 198 | if downProfile == nil { |
| 199 | logger.Error(ctx, "L2oamAddFlow() sendSetGenericActionCreate(down) error. ") |
| 200 | return |
| 201 | } |
| 202 | upProfile := sendSetGenericActionCreate(ctx, olt, l2oam.ActionTypeTrafficProfile) |
| 203 | if upProfile == nil { |
| 204 | logger.Error(ctx, "L2oamAddFlow() sendSetGenericActionCreate(up) error. ") |
| 205 | return |
| 206 | } |
| 207 | olt.setReferenceTable(getTrafficControl) |
| 208 | olt.setProfile(downProfile, upProfile) |
| 209 | olt.updateMap() |
| 210 | |
| 211 | err01 := sendSetTrafficControl(ctx, olt, getTrafficControl.GetReferenceControlDown(), downProfile.GetTrafficProfile()) |
| 212 | err02 := sendSetTrafficControl(ctx, olt, getTrafficControl.GetReferenceControlUp(), upProfile.GetTrafficProfile()) |
| 213 | |
| 214 | err03 := sendSetPriority(ctx, olt, downProfile.GetTrafficProfile()) |
| 215 | err04 := sendSetGuranteedRate(ctx, olt, cmd.Cir, downProfile.GetTrafficProfile()) |
| 216 | err05 := sendSetGuranteedRate(ctx, olt, cmd.Cir, upProfile.GetTrafficProfile()) |
| 217 | err06 := sendSetBestEffortRate(ctx, olt, cmd.Pir, downProfile.GetTrafficProfile()) |
| 218 | err07 := sendSetBestEffortRate(ctx, olt, cmd.Pir, upProfile.GetTrafficProfile()) |
| 219 | |
| 220 | logger.Debug(ctx, fmt.Sprintf("Sequence results: %v, %v, %v, %v, %v, %v, %v", err01, err02, err03, err04, err05, err06, err07)) |
| 221 | } else if flowVersion == 2 { |
| 222 | // add-flow to all ONUs |
| 223 | // Traffic Profile(priority, guranteed rate, best effort rate) are set as common settings |
| 224 | onuDevices, err := dh.coreProxy.GetChildDevices(ctx, dh.device.Id) |
| 225 | if err != nil { |
| 226 | logger.Error(ctx, fmt.Sprintf("catnnot-get-child-devices: %v", err)) |
| 227 | return |
| 228 | } |
| 229 | |
| 230 | isFirst := true |
| 231 | var downProfile *l2oam.SetGenericActionCreateRes |
| 232 | var upProfile *l2oam.SetGenericActionCreateRes |
| 233 | for _, onuDevice := range onuDevices.Items { |
| 234 | //onu := FindL2oamDevice(onuDevice.MacAddress) |
| 235 | onu := FindL2oamDeviceByDeviceID(onuDevice.Id) |
| 236 | if onu == nil { |
| 237 | logger.Error(ctx, fmt.Sprintf("catnnot-get-onu-device. device-id:%s, mac-address:%s", |
| 238 | onuDevice.Id, onuDevice.MacAddress)) |
| 239 | continue |
| 240 | } |
| 241 | if !(onu.(*L2oamOnuDevice)).Base.isActive() { |
| 242 | logger.Debug(ctx, fmt.Sprintf("onu is not active. device-id:%s, mac-address:%s", |
| 243 | onuDevice.Id, onuDevice.MacAddress)) |
| 244 | continue |
| 245 | } |
| 246 | logger.Debug(ctx, fmt.Sprintf("add-flow-for-onu. device-id:%s, mac-address:%s", |
| 247 | onuDevice.Id, onuDevice.MacAddress)) |
| 248 | |
| 249 | oc := onu.getObjectContext() |
| 250 | if oc == nil { |
| 251 | logger.Error(ctx, fmt.Sprintf("catnnot-get-onu-object-context. device-id:%s, mac-address:%s", |
| 252 | onuDevice.Id, onuDevice.MacAddress)) |
| 253 | continue |
| 254 | } |
| 255 | getTrafficControl := sendGetTrafficControlReferenceTable(ctx, olt, oc) |
| 256 | if getTrafficControl == nil { |
| 257 | logger.Error(ctx, "L2oamAddFlow() sendGetTrafficControlReferenceTable() error. ") |
| 258 | continue |
| 259 | } |
| 260 | onu.setReferenceTable(getTrafficControl) |
| 261 | onu.updateMap() |
| 262 | |
| 263 | // create one Traffic Profile at OLT |
| 264 | if isFirst { |
| 265 | downProfile = sendSetGenericActionCreate(ctx, olt, l2oam.ActionTypeTrafficProfile) |
| 266 | if downProfile == nil { |
| 267 | logger.Error(ctx, "L2oamAddFlow() sendSetGenericActionCreate(down) error. ") |
| 268 | break |
| 269 | } |
| 270 | upProfile = sendSetGenericActionCreate(ctx, olt, l2oam.ActionTypeTrafficProfile) |
| 271 | if upProfile == nil { |
| 272 | logger.Error(ctx, "L2oamAddFlow() sendSetGenericActionCreate(up) error. ") |
| 273 | break |
| 274 | } |
| 275 | olt.setProfile(downProfile, upProfile) |
| 276 | olt.updateMap() |
| 277 | } |
| 278 | |
| 279 | err01 := sendSetTrafficControl(ctx, olt, getTrafficControl.GetReferenceControlDown(), downProfile.GetTrafficProfile()) |
| 280 | err02 := sendSetTrafficControl(ctx, olt, getTrafficControl.GetReferenceControlUp(), upProfile.GetTrafficProfile()) |
| 281 | logger.Debug(ctx, fmt.Sprintf("traffic-control/traffic-profile results: %v, %v", err01, err02)) |
| 282 | |
| 283 | if isFirst { |
| 284 | err03 := sendSetPriority(ctx, olt, downProfile.GetTrafficProfile()) |
| 285 | err04 := sendSetGuranteedRate(ctx, olt, cmd.Cir, downProfile.GetTrafficProfile()) |
| 286 | err05 := sendSetGuranteedRate(ctx, olt, cmd.Cir, upProfile.GetTrafficProfile()) |
| 287 | err06 := sendSetBestEffortRate(ctx, olt, cmd.Pir, downProfile.GetTrafficProfile()) |
| 288 | err07 := sendSetBestEffortRate(ctx, olt, cmd.Pir, upProfile.GetTrafficProfile()) |
| 289 | isFirst = false |
| 290 | logger.Debug(ctx, fmt.Sprintf("traffic-profile-settings-results: %v, %v, %v, %v, %v", |
| 291 | err03, err04, err05, err06, err07)) |
| 292 | } |
| 293 | } |
| 294 | } else if flowVersion == 3 { |
| 295 | if err := olt.addFlow(ctx, cmd); err != nil { |
| 296 | logger.Errorf(ctx, "failed-to-add-flow: %v", err) |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | // L2oamAddFlowAndMount adds flow to device and start mount sequence |
| 302 | func (d *DeviceHandler) L2oamAddFlowAndMount(ctx context.Context, onuDeviceID string, vid []byte, ivid []byte) { |
| 303 | l2oamCmd := &L2oamCmd{ |
| 304 | Type: "add-flow-dev", |
| 305 | Tpid: []byte{0x88, 0xa8}, |
| 306 | Vid: vid, |
| 307 | Itpid: []byte{0x81, 0x00}, |
| 308 | Ivid: ivid, |
| 309 | OnuDeviceID: onuDeviceID, |
| 310 | } |
| 311 | olt := FindL2oamDeviceByDeviceID(d.device.Id) |
| 312 | if olt == nil { |
| 313 | logger.Errorf(ctx, "olt not found.") |
| 314 | } |
| 315 | if err := olt.updateFlow(ctx, l2oamCmd); err != nil { |
| 316 | logger.Errorf(ctx, "failed-to-update-flow. %v", err) |
| 317 | } else { |
| 318 | onu := FindL2oamDeviceByDeviceID(onuDeviceID) |
| 319 | if onu == nil { |
| 320 | logger.Debug(ctx, fmt.Sprintf("L2oamAddFlowAndMount() FindL2oamDevice() onu not found. deviceId=%s", onuDeviceID)) |
| 321 | } else { |
| 322 | // start ONU mount sequence |
| 323 | onu.startMountSequence(ctx, l2oam.OnuPkgType, l2oamCmd) |
| 324 | } |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | // L2oamAddFlowToDeviceAll adds a flow to specified device. |
| 329 | // If some flows are added already, all flows are removed from all devices before adding. |
| 330 | func L2oamAddFlowToDeviceAll(ctx context.Context, dh *DeviceHandler, cmd *L2oamCmd) error { |
| 331 | logger.Debug(ctx, "L2oamAddFlowToDeviceAll() Start.") |
| 332 | |
| 333 | olt := FindL2oamDeviceByDeviceID(dh.device.Id) |
| 334 | if olt == nil { |
| 335 | logger.Error(ctx, fmt.Sprintf("L2oamAddFlowToDeviceAll() FindL2oamDeviceByDeviceId() error. olt not found. deviceId=%s", dh.device.Id)) |
| 336 | return nil |
| 337 | } |
| 338 | |
| 339 | oc := olt.getObjectContext() |
| 340 | var onuList []*L2oamOnuDevice |
| 341 | onuDeviceID := cmd.OnuDeviceID |
| 342 | onu := FindL2oamDeviceByDeviceID(onuDeviceID) |
| 343 | if onu == nil { |
| 344 | return nil |
| 345 | } |
| 346 | onuDev, ok := onu.(*L2oamOnuDevice) |
| 347 | if !ok { |
| 348 | return nil |
| 349 | } |
| 350 | if oc != nil { |
| 351 | onuDevices, err := dh.coreProxy.GetChildDevices(ctx, dh.device.Id) |
| 352 | if err != nil { |
| 353 | logger.Error(ctx, fmt.Sprintf("catnnot-get-child-devices: %v", err)) |
| 354 | return err |
| 355 | } |
| 356 | // create flow added onu list |
| 357 | reflow := false |
| 358 | for _, onuDevice := range onuDevices.Items { |
| 359 | //onu := FindL2oamDevice(onuDevice.MacAddress) |
| 360 | onu := FindL2oamDeviceByDeviceID(onuDevice.Id) |
| 361 | if onu != nil { |
| 362 | if onuDev, ok := onu.(*L2oamOnuDevice); ok { |
| 363 | if onuDev.Base.FlowAdded { |
| 364 | onuList = append(onuList, onuDev) |
| 365 | if onuDeviceID == onuDev.Base.DeviceID { |
| 366 | reflow = true |
| 367 | } |
| 368 | } |
| 369 | } |
| 370 | } |
| 371 | } |
| 372 | if !reflow { |
| 373 | onuList = append(onuList, onuDev) |
| 374 | } |
| 375 | L2oamRemoveFlowFromDevice(ctx, dh, onuDevices) |
| 376 | } else { |
| 377 | onuList = append(onuList, onuDev) |
| 378 | } |
| 379 | localCmd := *cmd |
| 380 | for _, onuDev := range onuList { |
| 381 | localCmd.OnuDeviceID = onuDev.Base.DeviceID |
| 382 | if err := L2oamAddFlowToDevice(ctx, dh, &localCmd); err != nil { |
| 383 | continue |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | return nil |
| 388 | } |
| 389 | |
| 390 | // L2oamAddFlowToDevice runs add-flow-device sequence |
| 391 | func L2oamAddFlowToDevice(ctx context.Context, dh *DeviceHandler, cmd *L2oamCmd) error { |
| 392 | if flowVersion == 1 { |
| 393 | oc := L2oamAddFlowToDeviceDS(ctx, dh, cmd) |
| 394 | if oc == nil { |
| 395 | return errors.New("failed-to-add-flow-to-device-for-down-stream") |
| 396 | } |
| 397 | L2oamAddFlowToDeviceUS(ctx, dh, oc, cmd) |
| 398 | } else if flowVersion > 1 { |
| 399 | logger.Debug(ctx, "L2oamAddFlowToDevice() Start.") |
| 400 | |
| 401 | olt := FindL2oamDeviceByDeviceID(dh.device.Id) |
| 402 | if olt == nil { |
| 403 | logger.Error(ctx, fmt.Sprintf("L2oamAddFlowToDevice() FindL2oamDeviceByDeviceId() error. olt not found. deviceId=%s", dh.device.Id)) |
| 404 | return nil |
| 405 | } |
| 406 | |
| 407 | // add flow for downstream |
| 408 | oc := olt.getObjectContext() |
| 409 | var err01 error |
| 410 | var err02 error |
| 411 | onuDeviceID := cmd.OnuDeviceID |
| 412 | // "Generic/Action Create, L2 Switching Domain/Action Inlet entry" is created only first |
| 413 | if oc == nil { |
| 414 | oc, err01 = sendSetGenericActionCreateForDS(ctx, olt) |
| 415 | if oc == nil { |
| 416 | logger.Error(ctx, fmt.Sprintf("error. %v", err01)) |
| 417 | return errors.New("failed-to-add-flow-to-device-for-down-stream") |
| 418 | } |
| 419 | // TODO ignore tpid, vid after the second time |
| 420 | err02 = sendSetL2SwitchingDomainForDS(ctx, olt, oc, cmd.Tpid, cmd.Vid) |
| 421 | olt.setL2oamCmd(cmd) |
| 422 | olt.setObjectContext(oc) |
| 423 | if oltDev, ok := olt.(*L2oamOltDevice); ok { |
| 424 | oltDev.Base.FlowAdded = true |
| 425 | } |
| 426 | olt.updateMap() |
| 427 | } else { |
| 428 | cmd = olt.getL2oamCmd() |
| 429 | } |
| 430 | |
| 431 | onu := FindL2oamDeviceByDeviceID(onuDeviceID) |
| 432 | if onu == nil { |
| 433 | logger.Debug(ctx, fmt.Sprintf("L2oamCmdRequest() FindL2oamDevice() onu not found. deviceId=%s", onuDeviceID)) |
| 434 | } else { |
| 435 | onuID := onu.getObjectContext() |
| 436 | if onuID == nil { |
| 437 | logger.Error(ctx, "catnnot-get-onu-object-context.") |
| 438 | } else { |
| 439 | err03 := sendSetDefaultOutlet(ctx, olt, oc, onuID) |
| 440 | err04 := sendSetL2SwitchingDomainForUS(ctx, olt, oc, cmd.Tpid, cmd.Vid, onuID) |
| 441 | |
| 442 | logger.Debug(ctx, fmt.Sprintf("Sequence results: %v, %v, %v, %v", err01, err02, err03, err04)) |
| 443 | if onuDev, ok := onu.(*L2oamOnuDevice); ok { |
| 444 | onuDev.Base.FlowAdded = true |
| 445 | onu.updateMap() |
| 446 | } else { |
| 447 | logger.Error(ctx, fmt.Sprintf("assertion failed. device-id:%s", onuDeviceID)) |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | } |
| 452 | return nil |
| 453 | } |
| 454 | |
| 455 | // L2oamAddFlowToDeviceDS runs add-flow-device sequence for downstream |
| 456 | func L2oamAddFlowToDeviceDS(ctx context.Context, dh *DeviceHandler, cmd *L2oamCmd) *l2oam.TomiObjectContext { |
| 457 | logger.Debug(ctx, "L2oamAddFlowToDeviceDS() Start.") |
| 458 | |
| 459 | olt := FindL2oamDeviceByDeviceID(dh.device.Id) |
| 460 | if olt == nil { |
| 461 | logger.Error(ctx, fmt.Sprintf("L2oamAddFlowToDeviceDS() FindL2oamDeviceByDeviceId() error. olt not found. deviceId=%s", dh.device.Id)) |
| 462 | } |
| 463 | |
| 464 | oc, err01 := sendSetGenericActionCreateForDS(ctx, olt) |
| 465 | if oc != nil { |
| 466 | onuID := &l2oam.TomiObjectContext{ |
| 467 | Branch: 0x0c, |
| 468 | Type: 0x0011, |
| 469 | Length: 4, |
| 470 | Instance: 0x00000001, |
| 471 | } |
| 472 | err02 := sendSetL2SwitchingDomainForDS(ctx, olt, oc, cmd.Tpid, cmd.Vid) |
| 473 | err03 := sendSetDefaultOutlet(ctx, olt, oc, onuID) |
| 474 | logger.Debug(ctx, fmt.Sprintf("Sequence results: %v, %v, %v", err01, err02, err03)) |
| 475 | } else { |
| 476 | logger.Debug(ctx, fmt.Sprintf("Sequence results: %v", err01)) |
| 477 | } |
| 478 | olt.setL2oamCmd(cmd) |
| 479 | olt.setObjectContext(oc) |
| 480 | olt.updateMap() |
| 481 | |
| 482 | return oc |
| 483 | } |
| 484 | |
| 485 | // L2oamAddFlowToDeviceUS runs add-flow-device sequence for upstream |
| 486 | func L2oamAddFlowToDeviceUS(ctx context.Context, dh *DeviceHandler, oc *l2oam.TomiObjectContext, cmd *L2oamCmd) { |
| 487 | logger.Debug(ctx, "L2oamAddFlowToDeviceUS() Start.") |
| 488 | |
| 489 | olt := FindL2oamDeviceByDeviceID(dh.device.Id) |
| 490 | if olt == nil { |
| 491 | logger.Error(ctx, fmt.Sprintf("L2oamAddFlowToDeviceUS() FindL2oamDeviceByDeviceId() error. olt not found. deviceId=%s", dh.device.Id)) |
| 492 | } |
| 493 | |
| 494 | onuID := &l2oam.TomiObjectContext{ |
| 495 | Branch: 0x0c, |
| 496 | Type: 0x0011, |
| 497 | Length: 4, |
| 498 | Instance: 0x00000002, |
| 499 | } |
| 500 | err01 := sendSetL2SwitchingDomainForUS(ctx, olt, oc, cmd.Tpid, cmd.Vid, onuID) |
| 501 | |
| 502 | logger.Debug(ctx, fmt.Sprintf("Sequence results: %v", err01)) |
| 503 | } |
| 504 | |
| 505 | // L2oamRebootDevice reboots the device |
| 506 | func L2oamRebootDevice(ctx context.Context, dh *DeviceHandler, device *voltha.Device) { |
| 507 | logger.Debug(ctx, "L2oamRebootDevice() Start.") |
| 508 | |
| 509 | L2oamDisableOlt(ctx, dh) |
| 510 | |
| 511 | olt := FindL2oamDeviceByDeviceID(dh.device.Id) |
| 512 | if olt == nil { |
| 513 | logger.Error(ctx, fmt.Sprintf("L2oamRebootDevice() FindL2oamDeviceByDeviceId() error. olt not found. deviceId=%s", dh.device.Id)) |
| 514 | return |
| 515 | } |
| 516 | |
| 517 | err01 := sendSetActionReset(ctx, olt) |
| 518 | |
| 519 | logger.Debug(ctx, fmt.Sprintf("Sequence results: %v", err01)) |
| 520 | |
| 521 | } |
| 522 | |
| 523 | // L2oamDeleteOlt deletes the OLT device |
| 524 | func L2oamDeleteOlt(ctx context.Context, dh *DeviceHandler) { |
| 525 | logger.Debug(ctx, fmt.Sprintf("L2oamDeleteOlt() Start. deviceId=%s", dh.device.Id)) |
| 526 | |
| 527 | olt := FindL2oamDeviceByDeviceID(dh.device.Id) |
| 528 | if olt == nil { |
| 529 | logger.Error(ctx, fmt.Sprintf("L2oamDeleteOlt() FindL2oamDeviceByDeviceId() error. olt not found. deviceId=%s", dh.device.Id)) |
| 530 | return |
| 531 | } |
| 532 | olt.setAutonomousFlag(false) |
| 533 | if !SetupL2oamDeleteFlag(dh.device.Id) { |
| 534 | logger.Warn(ctx, fmt.Sprintf("L2oamDeleteOlt() olt deleted deviceId=%s", dh.device.Id)) |
| 535 | return |
| 536 | } |
| 537 | err01 := sendSetAdminState(ctx, olt, true) |
| 538 | DeleteAllDevice() |
| 539 | |
| 540 | logger.Debug(ctx, fmt.Sprintf("L2oamDeleteOlt() End. deviceId=%s, %v", dh.device.Id, err01)) |
| 541 | } |
| 542 | |
| 543 | // L2oamDisableOlt disables the OLT device |
| 544 | func L2oamDisableOlt(ctx context.Context, dh *DeviceHandler) { |
| 545 | olt := FindL2oamDeviceByDeviceID(dh.device.Id) |
| 546 | if olt == nil { |
| 547 | logger.Error(ctx, fmt.Sprintf("L2oamDisableOlt() FindL2oamDeviceByDeviceId() error. olt not found. deviceId=%s", dh.device.Id)) |
| 548 | return |
| 549 | } |
| 550 | olt.setAutonomousFlag(false) |
| 551 | |
| 552 | onuDevices, err := dh.coreProxy.GetChildDevices(ctx, dh.device.Id) |
| 553 | if err != nil { |
| 554 | logger.Error(ctx, fmt.Sprintf("catnnot-get-child-devices: %v", err)) |
| 555 | } |
| 556 | |
| 557 | if err = olt.removeFlow(ctx); err != nil { |
| 558 | logger.Error(ctx, fmt.Sprintf("failed-to-remove-flows: %v", err)) |
| 559 | } |
| 560 | L2oamRemoveFlow(ctx, dh, onuDevices) |
| 561 | L2oamChildDeviceLost(ctx, dh, onuDevices) |
| 562 | L2oamDisableDevice(ctx, dh) |
| 563 | resetFlowMap() |
| 564 | } |
| 565 | |
| 566 | // L2oamRemoveFlowFromDevice removes flows from the device |
| 567 | func L2oamRemoveFlowFromDevice(ctx context.Context, dh *DeviceHandler, onuDevices *voltha.Devices) { |
| 568 | logger.Debug(ctx, "L2oamRemoveFlowFromDeviceDS() Start.") |
| 569 | |
| 570 | olt := FindL2oamDeviceByDeviceID(dh.device.Id) |
| 571 | |
| 572 | if olt == nil { |
| 573 | logger.Error(ctx, fmt.Sprintf("L2oamRemoveFlowFromDeviceDS() FindL2oamDeviceByDeviceId() error. olt not found. deviceId=%s", dh.device.Id)) |
| 574 | } |
| 575 | oc := olt.getObjectContext() |
| 576 | cmd := olt.getL2oamCmd() |
| 577 | if cmd == nil { |
| 578 | logger.Warn(ctx, fmt.Sprintf("L2oamRemoveFlowFromDeviceDS() tpid, vid are not specified. deviceId=%s", |
| 579 | dh.device.Id)) |
| 580 | return |
| 581 | } |
| 582 | logger.Debug(ctx, fmt.Sprintf("TPID:%v, VID:%v", cmd.Tpid, cmd.Vid)) |
| 583 | |
| 584 | for _, onuDevice := range onuDevices.Items { |
| 585 | //onu := FindL2oamDevice(onuDevice.MacAddress) |
| 586 | onu := FindL2oamDeviceByDeviceID(onuDevice.Id) |
| 587 | if onu == nil { |
| 588 | logger.Error(ctx, fmt.Sprintf("catnnot-get-onu-device. device-id:%s, mac-address:%s", |
| 589 | onuDevice.Id, onuDevice.MacAddress)) |
| 590 | continue |
| 591 | } |
| 592 | var onuDev *L2oamOnuDevice |
| 593 | var ok bool |
| 594 | if onuDev, ok = onu.(*L2oamOnuDevice); ok { |
| 595 | if !onuDev.Base.FlowAdded { |
| 596 | logger.Error(ctx, fmt.Sprintf("flow is not added. device-id:%s, mac-address:%s", |
| 597 | onuDevice.Id, onuDevice.MacAddress)) |
| 598 | continue |
| 599 | } |
| 600 | } else { |
| 601 | logger.Error(ctx, fmt.Sprintf("assertion failed. device-id:%s, mac-address:%s", |
| 602 | onuDevice.Id, onuDevice.MacAddress)) |
| 603 | continue |
| 604 | } |
| 605 | onuID := onu.getObjectContext() |
| 606 | if onuID == nil { |
| 607 | logger.Error(ctx, fmt.Sprintf("catnnot-get-onu-object-context. device-id:%s, mac-address:%s", |
| 608 | onuDevice.Id, onuDevice.MacAddress)) |
| 609 | continue |
| 610 | } |
| 611 | logger.Debug(ctx, fmt.Sprintf("Switching Domain/Action Remove Inlet entry. device-id:%s, instance-id:%d", |
| 612 | onuDevice.Id, onuID.Instance)) |
| 613 | err := sendSetActionInletEntryUsDel(ctx, olt, oc, cmd.Tpid, cmd.Vid, onuID) |
| 614 | logger.Debug(ctx, fmt.Sprintf("Sequence results: %v", err)) |
| 615 | onuDev.Base.FlowAdded = false |
| 616 | onu.updateMap() |
| 617 | } |
| 618 | |
| 619 | if oltDev, ok := olt.(*L2oamOltDevice); ok { |
| 620 | if oltDev.Base.FlowAdded { |
| 621 | err02 := sendSetActionInletEntryDsDel(ctx, olt, oc, cmd.Tpid, cmd.Vid) |
| 622 | err03 := sendSetActionDeleteStream(ctx, olt, oc) |
| 623 | |
| 624 | logger.Debug(ctx, fmt.Sprintf("Sequence results: %v, %v", err02, err03)) |
| 625 | olt.setObjectContext(nil) |
| 626 | oltDev.Base.FlowAdded = false |
| 627 | olt.updateMap() |
| 628 | } else { |
| 629 | logger.Debug(ctx, fmt.Sprintf("flow is not added. device-id:%s", dh.device.Id)) |
| 630 | } |
| 631 | } else { |
| 632 | logger.Debug(ctx, fmt.Sprintf("assersion failed. device-id:%s", dh.device.Id)) |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | // L2oamRemoveFlow removes flows |
| 637 | func L2oamRemoveFlow(ctx context.Context, dh *DeviceHandler, onuDevices *voltha.Devices) { |
| 638 | logger.Debug(ctx, "L2oamRemoveFlow() Start.") |
| 639 | |
| 640 | olt := FindL2oamDeviceByDeviceID(dh.device.Id) |
| 641 | if olt == nil { |
| 642 | logger.Error(ctx, fmt.Sprintf("L2oamRemoveFlow() FindL2oamDeviceByDeviceId() error. olt not found. deviceId=%s", dh.device.Id)) |
| 643 | } |
| 644 | |
| 645 | if flowVersion == 2 { |
| 646 | //refTbl := olt.getReferenceTable() |
| 647 | downProfile, upProfile := olt.getProfile() |
| 648 | //if refTbl == nil || downProfile == nil || upProfile == nil { |
| 649 | if downProfile == nil || upProfile == nil { |
| 650 | logger.Warn(ctx, fmt.Sprintf("L2oamRemoveFlow() profiles are not specified. deviceId=%s", |
| 651 | dh.device.Id)) |
| 652 | return |
| 653 | } |
| 654 | downInstanceID := downProfile.GetTrafficProfile() |
| 655 | upInstanceID := upProfile.GetTrafficProfile() |
| 656 | //err01 := sendSetTrafficProfile(ctx, olt, |
| 657 | // refTbl.GetReferenceControlDown(), downInstanceId) |
| 658 | //err02 := sendSetTrafficProfile(ctx, olt, |
| 659 | // refTbl.GetReferenceControlUp(), upInstanceId) |
| 660 | err03 := sendSetActionDelete(ctx, olt, downInstanceID, l2oam.ActionTypeTrafficProfile) |
| 661 | err04 := sendSetActionDelete(ctx, olt, upInstanceID, l2oam.ActionTypeTrafficProfile) |
| 662 | olt.setProfile(nil, nil) |
| 663 | olt.updateMap() |
| 664 | |
| 665 | //logger.Debug(ctx, fmt.Sprintf("Sequence results: %v, %v, %v, %v", err01, err02, err03, err04)) |
| 666 | logger.Debug(ctx, fmt.Sprintf("Sequence results: %v, %v", err03, err04)) |
| 667 | } else if flowVersion == 3 { |
| 668 | for _, onuDevice := range onuDevices.Items { |
| 669 | logger.Debugf(ctx, "remove-traffic-schedule. onu-device-id:%s", onuDevice.Id) |
| 670 | onu := FindL2oamDeviceByDeviceID(onuDevice.Id) |
| 671 | if onu == nil { |
| 672 | logger.Errorf(ctx, "catnnot-get-onu-device") |
| 673 | continue |
| 674 | } |
| 675 | refTbl := onu.getReferenceTable() |
| 676 | if refTbl == nil { |
| 677 | logger.Debug(ctx, "traffic-profile-is-not-created") |
| 678 | continue |
| 679 | } |
| 680 | downProfile, upProfile := onu.getProfile() |
| 681 | if downProfile == nil || upProfile == nil { |
| 682 | logger.Debug(ctx, "flow is not added") |
| 683 | continue |
| 684 | } |
| 685 | downInstanceID := downProfile.GetTrafficProfile() |
| 686 | upInstanceID := upProfile.GetTrafficProfile() |
| 687 | err01 := sendSetTrafficProfile(ctx, olt, |
| 688 | refTbl.GetReferenceControlDown(), downInstanceID) |
| 689 | err02 := sendSetTrafficProfile(ctx, olt, |
| 690 | refTbl.GetReferenceControlUp(), upInstanceID) |
| 691 | err03 := sendSetActionDelete(ctx, olt, downInstanceID, l2oam.ActionTypeTrafficProfile) |
| 692 | err04 := sendSetActionDelete(ctx, olt, upInstanceID, l2oam.ActionTypeTrafficProfile) |
| 693 | onu.setReferenceTable(nil) |
| 694 | onu.setProfile(nil, nil) |
| 695 | onu.updateMap() |
| 696 | logger.Debug(ctx, fmt.Sprintf("remove-traffic-schedule-results: %v, %v, %v, %v", err01, err02, err03, err04)) |
| 697 | } |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | // L2oamChildDeviceLost sends DeviceLost message |
| 702 | func L2oamChildDeviceLost(ctx context.Context, dh *DeviceHandler, onuDevices *voltha.Devices) { |
| 703 | logger.Debug(ctx, "L2oamChildDeviceLost() Start.") |
| 704 | if onuDevices == nil { |
| 705 | return |
| 706 | } |
| 707 | |
| 708 | olt := FindL2oamDeviceByDeviceID(dh.device.Id) |
| 709 | if olt == nil { |
| 710 | logger.Error(ctx, fmt.Sprintf("L2oamChildDeviceLost() FindL2oamDeviceByDeviceId() error. olt not found. deviceId=%s", dh.device.Id)) |
| 711 | } |
| 712 | |
| 713 | for _, onuDevice := range onuDevices.Items { |
| 714 | //onu := FindL2oamDevice(onuDevice.MacAddress) |
| 715 | onu := FindL2oamDeviceByDeviceID(onuDevice.Id) |
| 716 | if onu == nil { |
| 717 | logger.Error(ctx, fmt.Sprintf("catnnot-get-onu-device. device-id:%s, mac-address:%s", |
| 718 | onuDevice.Id, onuDevice.MacAddress)) |
| 719 | } else { |
| 720 | oc := onu.getObjectContext() |
| 721 | if oc == nil { |
| 722 | logger.Error(ctx, fmt.Sprintf("catnnot-get-onu-object-context. device-id:%s, mac-address:%s", |
| 723 | onuDevice.Id, onuDevice.MacAddress)) |
| 724 | } else { |
| 725 | logger.Debug(ctx, fmt.Sprintf("onu-object-context. instance-id:%x", oc.Instance)) |
| 726 | err01 := sendSetActionDeleteOnu(ctx, olt, oc) |
| 727 | |
| 728 | logger.Debug(ctx, fmt.Sprintf("Sequence results: %v", err01)) |
| 729 | } |
| 730 | } |
| 731 | } |
| 732 | } |
| 733 | |
| 734 | // L2oamDisableDevice disables the device |
| 735 | func L2oamDisableDevice(ctx context.Context, dh *DeviceHandler) { |
| 736 | logger.Debug(ctx, "L2oamDisableDevice() Start.") |
| 737 | |
| 738 | olt := FindL2oamDeviceByDeviceID(dh.device.Id) |
| 739 | if olt == nil { |
| 740 | logger.Error(ctx, fmt.Sprintf("L2oamDisableDevice() FindL2oamDeviceByDeviceId() error. olt not found. deviceId=%s", dh.device.Id)) |
| 741 | } |
| 742 | |
| 743 | oltDev := olt.(*L2oamOltDevice) |
| 744 | if oltDev.Base.ActionIds != nil { |
| 745 | var bytes [4]byte |
| 746 | if id, ok := oltDev.Base.ActionIds[ActionIDFilterPonPort]; ok { |
| 747 | binary.BigEndian.PutUint32(bytes[:], id) |
| 748 | if err := sendSetActionDelete(ctx, olt, bytes[:], l2oam.ActionTypeProtocolFilter); err != nil { |
| 749 | return |
| 750 | } |
| 751 | } |
| 752 | if id, ok := oltDev.Base.ActionIds[ActionIDFilterEthPort]; ok { |
| 753 | binary.BigEndian.PutUint32(bytes[:], id) |
| 754 | if err := sendSetActionDelete(ctx, olt, bytes[:], l2oam.ActionTypeProtocolFilter); err != nil { |
| 755 | return |
| 756 | } |
| 757 | } |
| 758 | oltDev.Base.ActionIds = nil |
| 759 | olt.updateMap() |
| 760 | } |
| 761 | err01 := sendSetAdminState(ctx, olt, true) |
| 762 | err02 := sendSetManagementLock(ctx, olt) |
| 763 | |
| 764 | logger.Debug(ctx, fmt.Sprintf("Sequence results: %v, %v", err01, err02)) |
| 765 | } |
| 766 | |
| 767 | func sendDiscoverySOLICIT(ctx context.Context, device L2oamDevice) error { |
| 768 | if err := device.send(l2oam.GenerateDiscoverySOLICIT()); err != nil { |
| 769 | return nil |
| 770 | } |
| 771 | |
| 772 | ether, err := device.waitResponse(ResponseTimer) |
| 773 | if err != nil { |
| 774 | return fmt.Errorf("[%s] sendDiscoverySOLICIT() Send Error: %v", device.getDeviceName(), err) |
| 775 | } |
| 776 | |
| 777 | packet := &l2oam.DiscoveryHello{} |
| 778 | if err := packet.Decode(ether.Payload); err != nil { |
| 779 | return nil |
| 780 | } |
| 781 | logger.Debug(ctx, fmt.Sprintf("[%s] sendDiscoverySOLICIT() Success, response=%x:%s", device.getDeviceName(), ether.Payload, packet)) |
| 782 | return nil |
| 783 | } |
| 784 | |
| 785 | func sendGetVendorName(ctx context.Context, device L2oamDevice) (string, error) { |
| 786 | if err := device.send(l2oam.GnerateGetVendorName()); err != nil { |
| 787 | return "", nil |
| 788 | } |
| 789 | |
| 790 | ether, err := device.waitResponse(ResponseTimer) |
| 791 | if err != nil { |
| 792 | return "", fmt.Errorf("[%s] sendGetVendorName() Send Error: %v", device.getDeviceName(), err) |
| 793 | } |
| 794 | |
| 795 | packet := &l2oam.GetVendorNameRes{} |
| 796 | if err := packet.Decode(ether.Payload); err != nil { |
| 797 | return "", nil |
| 798 | } |
| 799 | logger.Debug(ctx, fmt.Sprintf("[%s] sendGetVendorName() Success, response=%x:%s", device.getDeviceName(), ether.Payload, packet)) |
| 800 | return packet.GetVendorName(), nil |
| 801 | } |
| 802 | |
| 803 | func sendGetModuleNumber(ctx context.Context, device L2oamDevice) (string, error) { |
| 804 | if err := device.send(l2oam.GenerateGetModuleNumber()); err != nil { |
| 805 | return "", nil |
| 806 | } |
| 807 | |
| 808 | ether, err := device.waitResponse(ResponseTimer) |
| 809 | if err != nil { |
| 810 | return "", fmt.Errorf("[%s] sendGetModuleNumber() Send Error: %v", device.getDeviceName(), err) |
| 811 | } |
| 812 | packet := &l2oam.GetModuleNumberRes{} |
| 813 | if err := packet.Decode(ether.Payload); err != nil { |
| 814 | return "", nil |
| 815 | } |
| 816 | logger.Debug(ctx, fmt.Sprintf("[%s] sendGetModuleNumber() Success, response=%x:%s", device.getDeviceName(), ether.Payload, packet)) |
| 817 | return packet.GetModuleNumber(), nil |
| 818 | } |
| 819 | |
| 820 | func sendManuFacturerInfo(ctx context.Context, device L2oamDevice) (string, error) { |
| 821 | if err := device.send(l2oam.GenerateManuFacturerInfo()); err != nil { |
| 822 | return "", nil |
| 823 | } |
| 824 | |
| 825 | ether, err := device.waitResponse(ResponseTimer) |
| 826 | if err != nil { |
| 827 | return "", fmt.Errorf("[%s] sendManuFacturerInfo() Send Error: %v", device.getDeviceName(), err) |
| 828 | } |
| 829 | |
| 830 | packet := &l2oam.GetManufacturerRes{} |
| 831 | if err := packet.Decode(ether.Payload); err != nil { |
| 832 | return "", nil |
| 833 | } |
| 834 | logger.Debug(ctx, fmt.Sprintf("[%s] sendManuFacturerInfo() Success, response=%x:%s", device.getDeviceName(), ether.Payload, packet)) |
| 835 | return packet.GetManufacturer(), nil |
| 836 | } |
| 837 | |
| 838 | func sendGetFirmwareVersion(ctx context.Context, device L2oamDevice) (string, error) { |
| 839 | if err := device.send(l2oam.GenerateGetFirmwareVersion()); err != nil { |
| 840 | return "", nil |
| 841 | } |
| 842 | |
| 843 | ether, err := device.waitResponse(ResponseTimer) |
| 844 | if err != nil { |
| 845 | return "", fmt.Errorf("[%s] sendGetFirmwareVersion() Send Error: %v", device.getDeviceName(), err) |
| 846 | } |
| 847 | |
| 848 | packet := &l2oam.GetFirmwareVersionRes{} |
| 849 | if err := packet.Decode(ether.Payload); err != nil { |
| 850 | return "", nil |
| 851 | } |
| 852 | logger.Debug(ctx, fmt.Sprintf("[%s] sendGetFirmwareVersion() Success, response=%x:%s", device.getDeviceName(), ether.Payload, packet)) |
| 853 | return packet.GetFirmwareVersionNumber(), nil |
| 854 | } |
| 855 | |
| 856 | func sendGetMacAddress(ctx context.Context, device L2oamDevice) (string, error) { |
| 857 | if err := device.send(l2oam.GenerateGetMacAddress()); err != nil { |
| 858 | return "", nil |
| 859 | } |
| 860 | |
| 861 | ether, err := device.waitResponse(ResponseTimer) |
| 862 | if err != nil { |
| 863 | return "", fmt.Errorf("[%s] sendGetMacAddress() Send Error: %v", device.getDeviceName(), err) |
| 864 | } |
| 865 | |
| 866 | packet := &l2oam.GetMacAddressRes{} |
| 867 | if err := packet.Decode(ether.Payload); err != nil { |
| 868 | return "", nil |
| 869 | } |
| 870 | logger.Debug(ctx, fmt.Sprintf("[%s] sendGetMacAddress() Success, response=%x:%s", device.getDeviceName(), ether.Payload, packet)) |
| 871 | return packet.GetMacAddress(), nil |
| 872 | } |
| 873 | |
| 874 | func sendGetSerialNumber(ctx context.Context, device L2oamDevice) (string, error) { |
| 875 | if err := device.send(l2oam.GenerateGetSerialNumber()); err != nil { |
| 876 | return "", nil |
| 877 | } |
| 878 | |
| 879 | ether, err := device.waitResponse(ResponseTimer) |
| 880 | if err != nil { |
| 881 | return "", fmt.Errorf("[%s] sendGetSerialNumber() Send Error: %v", device.getDeviceName(), err) |
| 882 | } |
| 883 | |
| 884 | packet := &l2oam.GetSerialNumberRes{} |
| 885 | if err := packet.Decode(ether.Payload); err != nil { |
| 886 | return "", nil |
| 887 | } |
| 888 | logger.Debug(ctx, fmt.Sprintf("[%s] sendGetSerialNumber() Success, response=%x:%s", device.getDeviceName(), ether.Payload, packet)) |
| 889 | return packet.GetSerialNumber(), nil |
| 890 | } |
| 891 | |
| 892 | func sendSetHbtxTemplate(ctx context.Context, device L2oamDevice) error { |
| 893 | if err := device.send(l2oam.GenerateSetHbtxTemplate()); err != nil { |
| 894 | return nil |
| 895 | } |
| 896 | |
| 897 | ether, err := device.waitResponse(ResponseTimer) |
| 898 | if err != nil { |
| 899 | return fmt.Errorf("[%s] sendSetHbtxTemplate() Send Error: %v", device.getDeviceName(), err) |
| 900 | } |
| 901 | |
| 902 | packet := &l2oam.TOAMSetResponse{} |
| 903 | if err := packet.Decode(ether.Payload); err != nil { |
| 904 | return nil |
| 905 | } |
| 906 | logger.Debug(ctx, fmt.Sprintf("[%s] sendSetHbtxTemplate() Success, response=%x:%s", device.getDeviceName(), ether.Payload, packet)) |
| 907 | return nil |
| 908 | } |
| 909 | |
| 910 | func sendGetPonMode(ctx context.Context, device L2oamDevice) (string, error) { |
| 911 | if err := device.send(l2oam.GenerateGetPonMode()); err != nil { |
| 912 | return "", nil |
| 913 | } |
| 914 | |
| 915 | ether, err := device.waitResponse(ResponseTimer) |
| 916 | if err != nil { |
| 917 | return "", fmt.Errorf("[%s] sendGetPonMode() Send Error: %v", device.getDeviceName(), err) |
| 918 | } |
| 919 | |
| 920 | packet := &l2oam.GetPonMode{} |
| 921 | if err := packet.Decode(ether.Payload); err != nil { |
| 922 | return "", nil |
| 923 | } |
| 924 | logger.Debug(ctx, fmt.Sprintf("[%s] sendGetPonMode() Success, response=%x:%s", device.getDeviceName(), ether.Payload, packet)) |
| 925 | return packet.GetPonMode(), nil |
| 926 | } |
| 927 | |
| 928 | func sendSetMPCPSync(ctx context.Context, device L2oamDevice) error { |
| 929 | if err := device.send(l2oam.GenerateSetMPCPSync()); err != nil { |
| 930 | return nil |
| 931 | } |
| 932 | |
| 933 | ether, err := device.waitResponse(ResponseTimer) |
| 934 | if err != nil { |
| 935 | return fmt.Errorf("[%s] sendSetMPCPSync() Send Error: %v", device.getDeviceName(), err) |
| 936 | } |
| 937 | |
| 938 | packet := &l2oam.TOAMSetResponse{} |
| 939 | if err := packet.Decode(ether.Payload); err != nil { |
| 940 | return nil |
| 941 | } |
| 942 | logger.Debug(ctx, fmt.Sprintf("[%s] sendSetMPCPSync() Success, response=%x:%s", device.getDeviceName(), ether.Payload, packet)) |
| 943 | return nil |
| 944 | } |
| 945 | |
| 946 | func sendSetAdminState(ctx context.Context, device L2oamDevice, isDelete bool) error { |
| 947 | if isDelete { |
| 948 | if err := device.send(l2oam.GenerateSetAdminStateDelete()); err != nil { |
| 949 | return nil |
| 950 | } |
| 951 | } else { |
| 952 | if err := device.send(l2oam.GenerateSetAdminState()); err != nil { |
| 953 | return nil |
| 954 | } |
| 955 | } |
| 956 | |
| 957 | ether, err := device.waitResponse(ResponseTimer) |
| 958 | if err != nil { |
| 959 | return fmt.Errorf("[%s] sendSetAdminState() Send Error: isDelete=%v, %v", device.getDeviceName(), isDelete, err) |
| 960 | } |
| 961 | |
| 962 | packet := &l2oam.TOAMSetResponse{} |
| 963 | if err := packet.Decode(ether.Payload); err != nil { |
| 964 | return nil |
| 965 | } |
| 966 | logger.Debug(ctx, fmt.Sprintf("[%s] sendSetAdminState() Success, response=%x:%s", device.getDeviceName(), ether.Payload, packet)) |
| 967 | return nil |
| 968 | } |
| 969 | |
| 970 | func sendSetHbtxPeriod(ctx context.Context, device L2oamDevice) error { |
| 971 | if err := device.send(l2oam.GenerateSetHbtxPeriod()); err != nil { |
| 972 | return nil |
| 973 | } |
| 974 | |
| 975 | ether, err := device.waitResponse(ResponseTimer) |
| 976 | if err != nil { |
| 977 | return fmt.Errorf("[%s] sendSetHbtxPeriod() Send Error: %v", device.getDeviceName(), err) |
| 978 | } |
| 979 | packet := &l2oam.TOAMSetResponse{} |
| 980 | if err := packet.Decode(ether.Payload); err != nil { |
| 981 | return nil |
| 982 | } |
| 983 | logger.Debug(ctx, fmt.Sprintf("[%s] sendSetHbtxPeriod() Success, response=%x:%s", device.getDeviceName(), ether.Payload, packet)) |
| 984 | |
| 985 | return nil |
| 986 | } |
| 987 | |
| 988 | func sendSetIngressPort(ctx context.Context, device L2oamDevice, actionID uint32, isPonPort bool) error { |
| 989 | if err := device.send(l2oam.GenerateIngressPort(actionID, isPonPort)); err != nil { |
| 990 | return nil |
| 991 | } |
| 992 | _, err := device.waitResponse(ResponseTimer) |
| 993 | if err != nil { |
| 994 | logger.Error(ctx, fmt.Sprintf("sendSetIngressPort() send error. %s ", err)) |
| 995 | return nil |
| 996 | } |
| 997 | |
| 998 | return nil |
| 999 | } |
| 1000 | |
| 1001 | func sendSetCaptureProtocols(ctx context.Context, device L2oamDevice, actionID uint32) error { |
| 1002 | if err := device.send(l2oam.GenerateCaptureProtocols(actionID)); err != nil { |
| 1003 | return nil |
| 1004 | } |
| 1005 | _, err := device.waitResponse(ResponseTimer) |
| 1006 | if err != nil { |
| 1007 | logger.Error(ctx, fmt.Sprintf("sendSetCaptureProtocols() send error. %s ", err)) |
| 1008 | return nil |
| 1009 | } |
| 1010 | |
| 1011 | return nil |
| 1012 | } |
| 1013 | |
| 1014 | func sendGetTrafficControlReferenceTable(ctx context.Context, device L2oamDevice, oc *l2oam.TomiObjectContext) *l2oam.GetTrafficControlReferenceTableRes { |
| 1015 | if err := device.send(l2oam.GenerateGetTrafficControlReferenceTableReq(oc)); err != nil { |
| 1016 | return nil |
| 1017 | } |
| 1018 | ether, err := device.waitResponse(ResponseTimer) |
| 1019 | if err != nil { |
| 1020 | logger.Error(ctx, fmt.Sprintf("sendGetTrafficControlReferenceTable() send error. %s ", err)) |
| 1021 | return nil |
| 1022 | } |
| 1023 | packet := &l2oam.GetTrafficControlReferenceTableRes{} |
| 1024 | if err := packet.Decode(ether.Payload); err != nil { |
| 1025 | return nil |
| 1026 | } |
| 1027 | return packet |
| 1028 | } |
| 1029 | |
| 1030 | func sendSetGenericActionCreate(ctx context.Context, device L2oamDevice, actionType int) *l2oam.SetGenericActionCreateRes { |
| 1031 | if err := device.send(l2oam.GenerateGenericActionCreate(actionType)); err != nil { |
| 1032 | return nil |
| 1033 | } |
| 1034 | |
| 1035 | ether, err := device.waitResponse(ResponseTimer) |
| 1036 | if err != nil { |
| 1037 | logger.Error(ctx, fmt.Sprintf("[%s] sendSetGenericActionCreate() Send Error: %v", device.getDeviceName(), err)) |
| 1038 | return nil |
| 1039 | } |
| 1040 | packet := &l2oam.SetGenericActionCreateRes{} |
| 1041 | if err := packet.Decode(ether.Payload); err != nil { |
| 1042 | return nil |
| 1043 | } |
| 1044 | logger.Debug(ctx, fmt.Sprintf("[%s] sendSetGenericActionCreate() Success, response=%x:%s", device.getDeviceName(), ether.Payload, packet)) |
| 1045 | |
| 1046 | return packet |
| 1047 | } |
| 1048 | |
| 1049 | func sendSetTrafficControl(ctx context.Context, device L2oamDevice, trafficControl []byte, trafficProfile []byte) error { |
| 1050 | |
| 1051 | if err := device.send(l2oam.GenerateTrafficControlTrafficProfile(trafficControl, trafficProfile)); err != nil { |
| 1052 | return nil |
| 1053 | } |
| 1054 | |
| 1055 | ether, err := device.waitResponse(ResponseTimer) |
| 1056 | if err != nil { |
| 1057 | return fmt.Errorf("[%s] sendSetTrafficControl() Send Error: %v", device.getDeviceName(), err) |
| 1058 | } |
| 1059 | packet := &l2oam.TOAMSetResponse{} |
| 1060 | |
| 1061 | logger.Debug(ctx, fmt.Sprintf("[%s] sendSetTrafficControl() Success, response=%x:%s", device.getDeviceName(), ether.Payload, packet)) |
| 1062 | |
| 1063 | return nil |
| 1064 | } |
| 1065 | |
| 1066 | func sendSetPriority(ctx context.Context, device L2oamDevice, trafficProfile []byte) error { |
| 1067 | if err := device.send(l2oam.GeneratePriority(trafficProfile)); err != nil { |
| 1068 | return nil |
| 1069 | } |
| 1070 | |
| 1071 | ether, err := device.waitResponse(ResponseTimer) |
| 1072 | if err != nil { |
| 1073 | return fmt.Errorf("[%s] sendSetPriority() Send Error: %v", device.getDeviceName(), err) |
| 1074 | } |
| 1075 | packet := &l2oam.TOAMSetResponse{} |
| 1076 | |
| 1077 | logger.Debug(ctx, fmt.Sprintf("[%s] sendSetPriority() Success, response=%x:%s", device.getDeviceName(), ether.Payload, packet)) |
| 1078 | |
| 1079 | return nil |
| 1080 | } |
| 1081 | |
| 1082 | func sendSetGuranteedRate(ctx context.Context, device L2oamDevice, cir []byte, trafficProfile []byte) error { |
| 1083 | if err := device.send(l2oam.GenerateGuaranteedRate(cir, trafficProfile)); err != nil { |
| 1084 | return nil |
| 1085 | } |
| 1086 | |
| 1087 | ether, err := device.waitResponse(ResponseTimer) |
| 1088 | if err != nil { |
| 1089 | return fmt.Errorf("[%s] sendSetGuranteedRate() Send Error: %v", device.getDeviceName(), err) |
| 1090 | } |
| 1091 | packet := &l2oam.TOAMSetResponse{} |
| 1092 | |
| 1093 | logger.Debug(ctx, fmt.Sprintf("[%s] sendSetGuranteedRate() Success, response=%x:%s", device.getDeviceName(), ether.Payload, packet)) |
| 1094 | |
| 1095 | return nil |
| 1096 | } |
| 1097 | |
| 1098 | // func sendSetGuranteedMbs(ctx context.Context, device L2oamDevice) error { |
| 1099 | // if err := device.send(l2oam.GenerateGuaranteedMbs()); err != nil { |
| 1100 | // return nil |
| 1101 | // } |
| 1102 | |
| 1103 | // ether, err := device.waitResponse(ResponseTimer) |
| 1104 | // if err != nil { |
| 1105 | // return fmt.Errorf("[%s] sendSetGuranteedMbs() Send Error: %v", device.getDeviceName(), err) |
| 1106 | // } |
| 1107 | // packet := &l2oam.TOAMSetResponse{} |
| 1108 | // //packet.Decode(ether.Payload) |
| 1109 | |
| 1110 | // logger.Debug(ctx, fmt.Sprintf("[%s] sendSetGuranteedMbs() Success, response=%x:%s", device.getDeviceName(), ether.Payload, packet)) |
| 1111 | |
| 1112 | // return nil |
| 1113 | // } |
| 1114 | |
| 1115 | func sendSetBestEffortRate(ctx context.Context, device L2oamDevice, pir []byte, trafficProfile []byte) error { |
| 1116 | if err := device.send(l2oam.GenerateBestEffortRate(pir, trafficProfile)); err != nil { |
| 1117 | return nil |
| 1118 | } |
| 1119 | |
| 1120 | ether, err := device.waitResponse(ResponseTimer) |
| 1121 | if err != nil { |
| 1122 | return fmt.Errorf("[%s] sendSetBestEffortRate() Send Error: %v", device.getDeviceName(), err) |
| 1123 | } |
| 1124 | packet := &l2oam.TOAMSetResponse{} |
| 1125 | |
| 1126 | logger.Debug(ctx, fmt.Sprintf("[%s] sendSetBestEffortRate() Success, response=%x:%s", device.getDeviceName(), ether.Payload, packet)) |
| 1127 | |
| 1128 | return nil |
| 1129 | } |
| 1130 | |
| 1131 | // func sendSetBestEffortMbs(ctx context.Context, device L2oamDevice) error { |
| 1132 | // if err := device.send(l2oam.GenerateBestEffortMbs()); err != nil { |
| 1133 | // return nil |
| 1134 | // } |
| 1135 | |
| 1136 | // ether, err := device.waitResponse(ResponseTimer) |
| 1137 | // if err != nil { |
| 1138 | // return fmt.Errorf("[%s] sendSetBestEffortMbs() Send Error: %v", device.getDeviceName(), err) |
| 1139 | // } |
| 1140 | // packet := &l2oam.TOAMSetResponse{} |
| 1141 | // //packet.Decode(ether.Payload) |
| 1142 | |
| 1143 | // logger.Debug(ctx, fmt.Sprintf("[%s] sendSetBestEffortMbs() Success, response=%x:%s", device.getDeviceName(), ether.Payload, packet)) |
| 1144 | |
| 1145 | // return nil |
| 1146 | // } |
| 1147 | |
| 1148 | func sendSetGenericActionCreateForDS(ctx context.Context, device L2oamDevice) (*l2oam.TomiObjectContext, error) { |
| 1149 | if err := device.send(l2oam.GenerateGenericActionCreateDs()); err != nil { |
| 1150 | return nil, nil |
| 1151 | } |
| 1152 | |
| 1153 | ether, err := device.waitResponse(ResponseTimer) |
| 1154 | if err != nil { |
| 1155 | return nil, fmt.Errorf("[%s] sendSetGenericActionCreateForDS() Send Error: %v", device.getDeviceName(), err) |
| 1156 | } |
| 1157 | oc := &l2oam.TomiObjectContext{} |
| 1158 | |
| 1159 | i := 29 |
| 1160 | oc.Branch = ether.Payload[i] |
| 1161 | i++ |
| 1162 | oc.Type = binary.BigEndian.Uint16(ether.Payload[i : i+2]) |
| 1163 | i += 2 |
| 1164 | oc.Length = ether.Payload[i] |
| 1165 | i++ |
| 1166 | oc.Instance = binary.BigEndian.Uint32(ether.Payload[i : i+4]) |
| 1167 | |
| 1168 | logger.Debug(ctx, fmt.Sprintf("[%s] sendSetGenericActionCreateForDS() Success, response=%x, branch=%x, type=%x, length=%x, instance=%x", |
| 1169 | device.getDeviceName(), ether.Payload, oc.Branch, oc.Type, oc.Length, oc.Instance)) |
| 1170 | |
| 1171 | return oc, nil |
| 1172 | } |
| 1173 | |
| 1174 | func sendSetL2SwitchingDomainForDS(ctx context.Context, device L2oamDevice, oc *l2oam.TomiObjectContext, tpid []byte, vid []byte) error { |
| 1175 | tibitData := l2oam.GenerateL2switchingDomainActionLnletEntryDs(oc, tpid, vid) |
| 1176 | if err := device.send(tibitData); err != nil { |
| 1177 | return nil |
| 1178 | } |
| 1179 | |
| 1180 | ether, err := device.waitResponse(ResponseTimer) |
| 1181 | if err != nil { |
| 1182 | return fmt.Errorf("[%s] sendSetL2SwitchingDomain() Send Error: %v", device.getDeviceName(), err) |
| 1183 | } |
| 1184 | |
| 1185 | packet := &l2oam.TOAMSetResponse{} |
| 1186 | |
| 1187 | logger.Debug(ctx, fmt.Sprintf("[%s] sendSetL2SwitchingDomain() Success, response=%x:%s", device.getDeviceName(), ether.Payload, packet)) |
| 1188 | |
| 1189 | return nil |
| 1190 | } |
| 1191 | |
| 1192 | func sendSetDefaultOutlet(ctx context.Context, device L2oamDevice, oc *l2oam.TomiObjectContext, onuID *l2oam.TomiObjectContext) error { |
| 1193 | tibitData := l2oam.GenerateSetDefaultOutlet(oc, onuID) |
| 1194 | if err := device.send(tibitData); err != nil { |
| 1195 | return nil |
| 1196 | } |
| 1197 | |
| 1198 | ether, err := device.waitResponse(ResponseTimer) |
| 1199 | if err != nil { |
| 1200 | return fmt.Errorf("[%s] sendSetDefaultOutlet() Send Error: %v", device.getDeviceName(), err) |
| 1201 | } |
| 1202 | |
| 1203 | packet := &l2oam.TOAMSetResponse{} |
| 1204 | |
| 1205 | logger.Debug(ctx, fmt.Sprintf("[%s] sendSetDefaultOutlet() Success, response=%x:%s", device.getDeviceName(), ether.Payload, packet)) |
| 1206 | |
| 1207 | return nil |
| 1208 | } |
| 1209 | |
| 1210 | func sendSetL2SwitchingDomainForUS(ctx context.Context, device L2oamDevice, oc *l2oam.TomiObjectContext, |
| 1211 | tpid []byte, vid []byte, onuID *l2oam.TomiObjectContext) error { |
| 1212 | tibitData := l2oam.GenerateL2switchingDomainActionLnletEntryUs(oc, tpid, vid, onuID) |
| 1213 | if err := device.send(tibitData); err != nil { |
| 1214 | return nil |
| 1215 | } |
| 1216 | |
| 1217 | ether, err := device.waitResponse(ResponseTimer) |
| 1218 | if err != nil { |
| 1219 | return fmt.Errorf("[%s] sendSetL2SwitchingDomainForUS() Send Error: %v", device.getDeviceName(), err) |
| 1220 | } |
| 1221 | |
| 1222 | packet := &l2oam.TOAMSetResponse{} |
| 1223 | |
| 1224 | logger.Debug(ctx, fmt.Sprintf("[%s] sendSetL2SwitchingDomainForUS() Success, response=%x:%s", device.getDeviceName(), ether.Payload, packet)) |
| 1225 | |
| 1226 | return nil |
| 1227 | } |
| 1228 | |
| 1229 | func sendSetActionReset(ctx context.Context, device L2oamDevice) error { |
| 1230 | if err := device.send(l2oam.GenerateSetActionReset()); err != nil { |
| 1231 | return nil |
| 1232 | } |
| 1233 | |
| 1234 | ether, err := device.waitResponse(ResponseTimer) |
| 1235 | if err != nil { |
| 1236 | return fmt.Errorf("[%s] sendSetActionReset() Send Error: %v", device.getDeviceName(), err) |
| 1237 | } |
| 1238 | |
| 1239 | packet := &l2oam.TOAMSetResponse{} |
| 1240 | if err := packet.Decode(ether.Payload); err != nil { |
| 1241 | return nil |
| 1242 | } |
| 1243 | logger.Debug(ctx, fmt.Sprintf("[%s] sendSetActionReset() Success, response=%x:%s", device.getDeviceName(), ether.Payload, packet)) |
| 1244 | return nil |
| 1245 | } |
| 1246 | |
| 1247 | func sendSetTrafficProfile(ctx context.Context, device L2oamDevice, |
| 1248 | trafficControl []byte, trafficProfile []byte) error { |
| 1249 | if err := device.send(l2oam.GenerateSetTrafficProfile(trafficControl, trafficProfile)); err != nil { |
| 1250 | return err |
| 1251 | } |
| 1252 | |
| 1253 | if _, err := device.waitResponse(ResponseTimer); err != nil { |
| 1254 | return fmt.Errorf("[%s] sendSetTrafficProfile() Send Error: %v", device.getDeviceName(), err) |
| 1255 | } |
| 1256 | |
| 1257 | return nil |
| 1258 | } |
| 1259 | |
| 1260 | func sendSetActionDelete(ctx context.Context, device L2oamDevice, trafficProfile []byte, actionType int) error { |
| 1261 | if err := device.send(l2oam.GenerateSetActionDelete(trafficProfile, actionType)); err != nil { |
| 1262 | return nil |
| 1263 | } |
| 1264 | |
| 1265 | _, err := device.waitResponse(ResponseTimer) |
| 1266 | if err != nil { |
| 1267 | return fmt.Errorf("[%s] sendSetActionDelete() Send Error: %v", device.getDeviceName(), err) |
| 1268 | } |
| 1269 | |
| 1270 | return nil |
| 1271 | } |
| 1272 | |
| 1273 | func sendSetActionDeleteOnu(ctx context.Context, device L2oamDevice, oc *l2oam.TomiObjectContext) error { |
| 1274 | logger.Debug(ctx, "sendSetActionDeleteOnu() Start.") |
| 1275 | if err := device.send(l2oam.GenerateSetActionDeleteOnu(oc)); err != nil { |
| 1276 | return nil |
| 1277 | } |
| 1278 | |
| 1279 | _, err := device.waitResponse(ResponseTimer) |
| 1280 | if err != nil { |
| 1281 | return fmt.Errorf("[%s] sendSetActionDeleteOnu() Send Error: %v", device.getDeviceName(), err) |
| 1282 | } |
| 1283 | |
| 1284 | return nil |
| 1285 | } |
| 1286 | |
| 1287 | func sendSetManagementLock(ctx context.Context, device L2oamDevice) error { |
| 1288 | if err := device.send(l2oam.GenerateSetManagementLock()); err != nil { |
| 1289 | return nil |
| 1290 | } |
| 1291 | |
| 1292 | _, err := device.waitResponse(ResponseTimer) |
| 1293 | if err != nil { |
| 1294 | return fmt.Errorf("[%s] sendSetManagementLock() Send Error: %v", device.getDeviceName(), err) |
| 1295 | } |
| 1296 | |
| 1297 | return nil |
| 1298 | } |
| 1299 | |
| 1300 | func sendSetActionInletEntryDsDel(ctx context.Context, device L2oamDevice, |
| 1301 | oc *l2oam.TomiObjectContext, tpid []byte, vid []byte) error { |
| 1302 | if err := device.send(l2oam.GenerateL2switchingDomainActionInletEntryDsDel(oc, tpid, vid)); err != nil { |
| 1303 | return nil |
| 1304 | } |
| 1305 | |
| 1306 | _, err := device.waitResponse(ResponseTimer) |
| 1307 | if err != nil { |
| 1308 | return fmt.Errorf("[%s] sendSetActionInletEntryDsDel() Send Error: %v", device.getDeviceName(), err) |
| 1309 | } |
| 1310 | |
| 1311 | return nil |
| 1312 | } |
| 1313 | |
| 1314 | func sendSetActionInletEntryUsDel(ctx context.Context, device L2oamDevice, |
| 1315 | oc *l2oam.TomiObjectContext, tpid []byte, vid []byte, onuID *l2oam.TomiObjectContext) error { |
| 1316 | if err := device.send(l2oam.GenerateL2switchingDomainActionInletEntryUsDel(oc, tpid, vid, onuID)); err != nil { |
| 1317 | return nil |
| 1318 | } |
| 1319 | |
| 1320 | _, err := device.waitResponse(ResponseTimer) |
| 1321 | if err != nil { |
| 1322 | return fmt.Errorf("[%s] sendSetActionInletEntryUsDel() Send Error: %v", device.getDeviceName(), err) |
| 1323 | } |
| 1324 | |
| 1325 | return nil |
| 1326 | } |
| 1327 | |
| 1328 | func sendSetActionDeleteStream(ctx context.Context, device L2oamDevice, oc *l2oam.TomiObjectContext) error { |
| 1329 | if err := device.send(l2oam.GenerateSetActionDeleteStream(oc)); err != nil { |
| 1330 | return nil |
| 1331 | } |
| 1332 | |
| 1333 | _, err := device.waitResponse(ResponseTimer) |
| 1334 | if err != nil { |
| 1335 | return fmt.Errorf("[%s] sendSetActionDeleteStream() Send Error: %v", device.getDeviceName(), err) |
| 1336 | } |
| 1337 | |
| 1338 | return nil |
| 1339 | } |