Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [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 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 17 | package devices |
| 18 | |
| 19 | import ( |
| 20 | "context" |
| 21 | "errors" |
| 22 | "fmt" |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 23 | "github.com/opencord/voltha-protos/go/openolt" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 24 | "github.com/looplab/fsm" |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 25 | "github.com/opencord/voltha-protos/go/tech_profile" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 26 | log "github.com/sirupsen/logrus" |
| 27 | "google.golang.org/grpc" |
| 28 | "net" |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 29 | "os" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 30 | "sync" |
| 31 | ) |
| 32 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 33 | var oltLogger = log.WithFields(log.Fields{ |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 34 | "module": "OLT", |
| 35 | }) |
| 36 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 37 | func init() { |
| 38 | //log.SetReportCaller(true) |
| 39 | log.SetLevel(log.DebugLevel) |
| 40 | } |
| 41 | |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 42 | var olt = OltDevice{} |
| 43 | |
| 44 | func GetOLT() OltDevice { |
| 45 | return olt |
| 46 | } |
| 47 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 48 | func CreateOLT(seq int, nni int, pon int, onuPerPon int) OltDevice { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 49 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 50 | "ID": seq, |
| 51 | "NumNni":nni, |
| 52 | "NumPon":pon, |
| 53 | "NumOnuPerPon":onuPerPon, |
| 54 | }).Debug("CreateOLT") |
| 55 | |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 56 | olt = OltDevice{ |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 57 | ID: seq, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 58 | OperState: getOperStateFSM(func(e *fsm.Event) { |
| 59 | oltLogger.Debugf("Changing OLT OperState from %s to %s", e.Src, e.Dst) |
| 60 | }), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 61 | NumNni:nni, |
| 62 | NumPon:pon, |
| 63 | NumOnuPerPon:onuPerPon, |
| 64 | Pons: []PonPort{}, |
| 65 | Nnis: []NniPort{}, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 66 | channel: make(chan Message), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | // OLT State machine |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 70 | // NOTE do we need 2 state machines for the OLT? (InternalState and OperState) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 71 | olt.InternalState = fsm.NewFSM( |
| 72 | "created", |
| 73 | fsm.Events{ |
| 74 | {Name: "enable", Src: []string{"created"}, Dst: "enabled"}, |
| 75 | {Name: "disable", Src: []string{"enabled"}, Dst: "disabled"}, |
| 76 | }, |
| 77 | fsm.Callbacks{ |
| 78 | "enter_state": func(e *fsm.Event) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 79 | oltLogger.Debugf("Changing OLT InternalState from %s to %s", e.Src, e.Dst) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 80 | }, |
| 81 | }, |
| 82 | ) |
| 83 | |
| 84 | // create NNI Port |
| 85 | nniPort := NniPort{ |
| 86 | ID: uint32(0), |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 87 | OperState: getOperStateFSM(func(e *fsm.Event) { |
| 88 | oltLogger.Debugf("Changing NNI OperState from %s to %s", e.Src, e.Dst) |
| 89 | }), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 90 | Type: "nni", |
| 91 | } |
| 92 | olt.Nnis = append(olt.Nnis, nniPort) |
| 93 | |
| 94 | // create PON ports |
Matteo Scandolo | da9cbe2 | 2019-08-19 16:05:10 -0700 | [diff] [blame] | 95 | onuId := 1 |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 96 | for i := 0; i < pon; i++ { |
| 97 | p := PonPort{ |
| 98 | NumOnu: olt.NumOnuPerPon, |
| 99 | ID: uint32(i), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 100 | Type: "pon", |
| 101 | } |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 102 | p.OperState = getOperStateFSM(func(e *fsm.Event) { |
| 103 | oltLogger.WithFields(log.Fields{ |
| 104 | "ID": p.ID, |
| 105 | }).Debugf("Changing PON Port OperState from %s to %s", e.Src, e.Dst) |
| 106 | }) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 107 | |
| 108 | // create ONU devices |
| 109 | for j := 0; j < onuPerPon; j++ { |
Matteo Scandolo | da9cbe2 | 2019-08-19 16:05:10 -0700 | [diff] [blame] | 110 | o := CreateONU(olt, p, uint32(onuId)) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 111 | p.Onus = append(p.Onus, o) |
Matteo Scandolo | da9cbe2 | 2019-08-19 16:05:10 -0700 | [diff] [blame] | 112 | onuId = onuId + 1 |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | olt.Pons = append(olt.Pons, p) |
| 116 | } |
| 117 | |
| 118 | wg := sync.WaitGroup{} |
| 119 | |
| 120 | wg.Add(1) |
| 121 | go newOltServer(olt) |
| 122 | wg.Wait() |
| 123 | return olt |
| 124 | } |
| 125 | |
| 126 | func newOltServer(o OltDevice) error { |
| 127 | // TODO make configurable |
| 128 | address := "0.0.0.0:50060" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 129 | lis, err := net.Listen("tcp", address) |
| 130 | if err != nil { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 131 | oltLogger.Fatalf("OLT failed to listen: %v", err) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 132 | } |
| 133 | grpcServer := grpc.NewServer() |
| 134 | openolt.RegisterOpenoltServer(grpcServer, o) |
| 135 | |
| 136 | go grpcServer.Serve(lis) |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 137 | oltLogger.Debugf("OLT Listening on: %v", address) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 138 | |
| 139 | return nil |
| 140 | } |
| 141 | |
| 142 | // Device Methods |
| 143 | |
| 144 | func (o OltDevice) Enable (stream openolt.Openolt_EnableIndicationServer) error { |
| 145 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 146 | oltLogger.Debug("Enable OLT called") |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 147 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 148 | wg := sync.WaitGroup{} |
| 149 | wg.Add(1) |
| 150 | |
| 151 | // create a channel for all the OLT events |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 152 | go o.processOltMessages(stream) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 153 | |
| 154 | // enable the OLT |
| 155 | olt_msg := Message{ |
| 156 | Type: OltIndication, |
| 157 | Data: OltIndicationMessage{ |
| 158 | OperState: UP, |
| 159 | }, |
| 160 | } |
| 161 | o.channel <- olt_msg |
| 162 | |
| 163 | // send NNI Port Indications |
| 164 | for _, nni := range o.Nnis { |
| 165 | msg := Message{ |
| 166 | Type: NniIndication, |
| 167 | Data: NniIndicationMessage{ |
| 168 | OperState: UP, |
| 169 | NniPortID: nni.ID, |
| 170 | }, |
| 171 | } |
| 172 | o.channel <- msg |
| 173 | } |
| 174 | |
| 175 | // send PON Port indications |
| 176 | for _, pon := range o.Pons { |
| 177 | msg := Message{ |
| 178 | Type: PonIndication, |
| 179 | Data: PonIndicationMessage{ |
| 180 | OperState: UP, |
| 181 | PonPortID: pon.ID, |
| 182 | }, |
| 183 | } |
| 184 | o.channel <- msg |
| 185 | |
| 186 | for _, onu := range pon.Onus { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 187 | go onu.processOnuMessages(stream) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 188 | msg := Message{ |
| 189 | Type: OnuDiscIndication, |
| 190 | Data: OnuDiscIndicationMessage{ |
| 191 | Onu: onu, |
| 192 | OperState: UP, |
| 193 | }, |
| 194 | } |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 195 | onu.channel <- msg |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 196 | } |
| 197 | } |
| 198 | |
| 199 | wg.Wait() |
| 200 | return nil |
| 201 | } |
| 202 | |
| 203 | // Helpers method |
| 204 | |
| 205 | func (o OltDevice) getPonById(id uint32) (*PonPort, error) { |
| 206 | for _, pon := range o.Pons { |
| 207 | if pon.ID == id { |
| 208 | return &pon, nil |
| 209 | } |
| 210 | } |
| 211 | return nil, errors.New(fmt.Sprintf("Cannot find PonPort with id %d in OLT %d", id, o.ID)) |
| 212 | } |
| 213 | |
| 214 | func (o OltDevice) getNniById(id uint32) (*NniPort, error) { |
| 215 | for _, nni := range o.Nnis { |
| 216 | if nni.ID == id { |
| 217 | return &nni, nil |
| 218 | } |
| 219 | } |
| 220 | return nil, errors.New(fmt.Sprintf("Cannot find NniPort with id %d in OLT %d", id, o.ID)) |
| 221 | } |
| 222 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 223 | func (o OltDevice) sendOltIndication(msg OltIndicationMessage, stream openolt.Openolt_EnableIndicationServer) { |
| 224 | data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: msg.OperState.String()}} |
| 225 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame^] | 226 | oltLogger.Errorf("Failed to send Indication_OltInd: %v", err) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 229 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 230 | "OperState": msg.OperState, |
| 231 | }).Debug("Sent Indication_OltInd") |
| 232 | } |
| 233 | |
| 234 | func (o OltDevice) sendNniIndication(msg NniIndicationMessage, stream openolt.Openolt_EnableIndicationServer) { |
| 235 | nni, _ := o.getNniById(msg.NniPortID) |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 236 | nni.OperState.Event("enable") |
| 237 | // NOTE Operstate may need to be an integer |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 238 | operData := &openolt.Indication_IntfOperInd{IntfOperInd: &openolt.IntfOperIndication{ |
| 239 | Type: nni.Type, |
| 240 | IntfId: nni.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 241 | OperState: nni.OperState.Current(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 242 | }} |
| 243 | |
| 244 | if err := stream.Send(&openolt.Indication{Data: operData}); err != nil { |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame^] | 245 | oltLogger.Errorf("Failed to send Indication_IntfOperInd for NNI: %v", err) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 248 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 249 | "Type": nni.Type, |
| 250 | "IntfId": nni.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 251 | "OperState": nni.OperState.Current(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 252 | }).Debug("Sent Indication_IntfOperInd for NNI") |
| 253 | } |
| 254 | |
| 255 | func (o OltDevice) sendPonIndication(msg PonIndicationMessage, stream openolt.Openolt_EnableIndicationServer) { |
| 256 | pon, _ := o.getPonById(msg.PonPortID) |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 257 | pon.OperState.Event("enable") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 258 | discoverData := &openolt.Indication_IntfInd{IntfInd: &openolt.IntfIndication{ |
| 259 | IntfId: pon.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 260 | OperState: pon.OperState.Current(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 261 | }} |
| 262 | |
| 263 | if err := stream.Send(&openolt.Indication{Data: discoverData}); err != nil { |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame^] | 264 | oltLogger.Errorf("Failed to send Indication_IntfInd: %v", err) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 267 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 268 | "IntfId": pon.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 269 | "OperState": pon.OperState.Current(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 270 | }).Debug("Sent Indication_IntfInd") |
| 271 | |
| 272 | operData := &openolt.Indication_IntfOperInd{IntfOperInd: &openolt.IntfOperIndication{ |
| 273 | Type: pon.Type, |
| 274 | IntfId: pon.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 275 | OperState: pon.OperState.Current(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 276 | }} |
| 277 | |
| 278 | if err := stream.Send(&openolt.Indication{Data: operData}); err != nil { |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame^] | 279 | oltLogger.Errorf("Failed to send Indication_IntfOperInd for PON: %v", err) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 282 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 283 | "Type": pon.Type, |
| 284 | "IntfId": pon.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 285 | "OperState": pon.OperState.Current(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 286 | }).Debug("Sent Indication_IntfOperInd for PON") |
| 287 | } |
| 288 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 289 | func (o OltDevice) processOltMessages(stream openolt.Openolt_EnableIndicationServer) { |
| 290 | oltLogger.Debug("Started OLT Indication Channel") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 291 | for message := range o.channel { |
| 292 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 293 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 294 | oltLogger.WithFields(log.Fields{ |
| 295 | "oltId": o.ID, |
| 296 | "messageType": message.Type, |
| 297 | }).Trace("Received message") |
| 298 | |
| 299 | switch message.Type { |
| 300 | case OltIndication: |
| 301 | msg, _ := message.Data.(OltIndicationMessage) |
| 302 | if msg.OperState == UP { |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 303 | o.InternalState.Event("enable") |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 304 | o.OperState.Event("enable") |
| 305 | } else if msg.OperState == DOWN { |
| 306 | o.InternalState.Event("disable") |
| 307 | o.OperState.Event("disable") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 308 | } |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 309 | o.sendOltIndication(msg, stream) |
| 310 | case NniIndication: |
| 311 | msg, _ := message.Data.(NniIndicationMessage) |
| 312 | o.sendNniIndication(msg, stream) |
| 313 | case PonIndication: |
| 314 | msg, _ := message.Data.(PonIndicationMessage) |
| 315 | o.sendPonIndication(msg, stream) |
| 316 | default: |
| 317 | oltLogger.Warnf("Received unknown message data %v for type %v in OLT channel", message.Data, message.Type) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | // GRPC Endpoints |
| 324 | |
| 325 | func (o OltDevice) ActivateOnu(context context.Context, onu *openolt.Onu) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 326 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 327 | "onuSerialNumber": onu.SerialNumber, |
| 328 | }).Info("Received ActivateOnu call from VOLTHA") |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 329 | |
| 330 | pon, _ := o.getPonById(onu.IntfId) |
| 331 | _onu, _ := pon.getOnuBySn(onu.SerialNumber) |
| 332 | |
| 333 | // NOTE we need to immediately activate the ONU or the OMCI state machine won't start |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 334 | msg := Message{ |
| 335 | Type: OnuIndication, |
| 336 | Data: OnuIndicationMessage{ |
| 337 | OnuSN: onu.SerialNumber, |
| 338 | PonPortID: onu.IntfId, |
| 339 | OperState: UP, |
| 340 | }, |
| 341 | } |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 342 | _onu.channel <- msg |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 343 | return new(openolt.Empty) , nil |
| 344 | } |
| 345 | |
| 346 | func (o OltDevice) DeactivateOnu(context.Context, *openolt.Onu) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 347 | oltLogger.Error("DeactivateOnu not implemented") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 348 | return new(openolt.Empty) , nil |
| 349 | } |
| 350 | |
| 351 | func (o OltDevice) DeleteOnu(context.Context, *openolt.Onu) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 352 | oltLogger.Error("DeleteOnu not implemented") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 353 | return new(openolt.Empty) , nil |
| 354 | } |
| 355 | |
| 356 | func (o OltDevice) DisableOlt(context.Context, *openolt.Empty) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 357 | // NOTE when we disable the OLT should we disable NNI, PONs and ONUs altogether? |
| 358 | olt_msg := Message{ |
| 359 | Type: OltIndication, |
| 360 | Data: OltIndicationMessage{ |
| 361 | OperState: DOWN, |
| 362 | }, |
| 363 | } |
| 364 | o.channel <- olt_msg |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 365 | return new(openolt.Empty) , nil |
| 366 | } |
| 367 | |
| 368 | func (o OltDevice) DisablePonIf(context.Context, *openolt.Interface) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 369 | oltLogger.Error("DisablePonIf not implemented") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 370 | return new(openolt.Empty) , nil |
| 371 | } |
| 372 | |
| 373 | func (o OltDevice) EnableIndication(_ *openolt.Empty, stream openolt.Openolt_EnableIndicationServer) error { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 374 | oltLogger.WithField("oltId", o.ID).Info("OLT receives EnableIndication call from VOLTHA") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 375 | o.Enable(stream) |
| 376 | return nil |
| 377 | } |
| 378 | |
| 379 | func (o OltDevice) EnablePonIf(context.Context, *openolt.Interface) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 380 | oltLogger.Error("EnablePonIf not implemented") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 381 | return new(openolt.Empty) , nil |
| 382 | } |
| 383 | |
| 384 | func (o OltDevice) FlowAdd(context.Context, *openolt.Flow) (*openolt.Empty, error) { |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 385 | oltLogger.Info("received FlowAdd") |
| 386 | // TODO store flows somewhere |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 387 | return new(openolt.Empty) , nil |
| 388 | } |
| 389 | |
| 390 | func (o OltDevice) FlowRemove(context.Context, *openolt.Flow) (*openolt.Empty, error) { |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 391 | oltLogger.Info("received FlowRemove") |
| 392 | // TODO store flows somewhere |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 393 | return new(openolt.Empty) , nil |
| 394 | } |
| 395 | |
| 396 | func (o OltDevice) HeartbeatCheck(context.Context, *openolt.Empty) (*openolt.Heartbeat, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 397 | oltLogger.Error("HeartbeatCheck not implemented") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 398 | return new(openolt.Heartbeat) , nil |
| 399 | } |
| 400 | |
| 401 | func (o OltDevice) GetDeviceInfo(context.Context, *openolt.Empty) (*openolt.DeviceInfo, error) { |
| 402 | |
Matteo Scandolo | da9cbe2 | 2019-08-19 16:05:10 -0700 | [diff] [blame] | 403 | oltLogger.WithFields(log.Fields{ |
| 404 | "oltId": o.ID, |
| 405 | "PonPorts": o.NumPon, |
| 406 | }).Info("OLT receives GetDeviceInfo call from VOLTHA") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 407 | devinfo := new(openolt.DeviceInfo) |
| 408 | devinfo.Vendor = "BBSim" |
| 409 | devinfo.Model = "asfvolt16" |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 410 | devinfo.HardwareVersion = "emulated" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 411 | devinfo.FirmwareVersion = "" |
| 412 | devinfo.Technology = "xgspon" |
Matteo Scandolo | da9cbe2 | 2019-08-19 16:05:10 -0700 | [diff] [blame] | 413 | devinfo.PonPorts = uint32(o.NumPon) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 414 | devinfo.OnuIdStart = 1 |
| 415 | devinfo.OnuIdEnd = 255 |
| 416 | devinfo.AllocIdStart = 1024 |
| 417 | devinfo.AllocIdEnd = 16383 |
| 418 | devinfo.GemportIdStart = 1024 |
| 419 | devinfo.GemportIdEnd = 65535 |
| 420 | devinfo.FlowIdStart = 1 |
| 421 | devinfo.FlowIdEnd = 16383 |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 422 | devinfo.DeviceSerialNumber = fmt.Sprintf("BBSIM_OLT_%d", o.ID) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 423 | |
| 424 | return devinfo, nil |
| 425 | } |
| 426 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 427 | func (o OltDevice) OmciMsgOut(ctx context.Context, omci_msg *openolt.OmciMsg) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 428 | pon, _ := o.getPonById(omci_msg.IntfId) |
| 429 | onu, _ := pon.getOnuById(omci_msg.OnuId) |
| 430 | msg := Message{ |
| 431 | Type: OMCI, |
| 432 | Data: OmciMessage{ |
| 433 | OnuSN: onu.SerialNumber, |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 434 | OnuID: onu.ID, |
| 435 | omciMsg: omci_msg, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 436 | }, |
| 437 | } |
| 438 | onu.channel <- msg |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 439 | return new(openolt.Empty) , nil |
| 440 | } |
| 441 | |
| 442 | func (o OltDevice) OnuPacketOut(context.Context, *openolt.OnuPacket) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 443 | oltLogger.Error("OnuPacketOut not implemented") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 444 | return new(openolt.Empty) , nil |
| 445 | } |
| 446 | |
| 447 | func (o OltDevice) Reboot(context.Context, *openolt.Empty) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 448 | oltLogger.Info("Shutting Down, hope you're running in K8s...") |
| 449 | os.Exit(0) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 450 | return new(openolt.Empty) , nil |
| 451 | } |
| 452 | |
| 453 | func (o OltDevice) ReenableOlt(context.Context, *openolt.Empty) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 454 | oltLogger.Error("ReenableOlt not implemented") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 455 | return new(openolt.Empty) , nil |
| 456 | } |
| 457 | |
| 458 | func (o OltDevice) UplinkPacketOut(context context.Context, packet *openolt.UplinkPacket) (*openolt.Empty, error) { |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 459 | oltLogger.Warn("UplinkPacketOut not implemented") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 460 | return new(openolt.Empty) , nil |
| 461 | } |
| 462 | |
| 463 | func (o OltDevice) CollectStatistics(context.Context, *openolt.Empty) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 464 | oltLogger.Error("CollectStatistics not implemented") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 465 | return new(openolt.Empty) , nil |
| 466 | } |
| 467 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 468 | func (o OltDevice) GetOnuInfo(context context.Context, packet *openolt.Onu) (*openolt.OnuIndication, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 469 | oltLogger.Error("GetOnuInfo not implemented") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 470 | return new(openolt.OnuIndication) , nil |
| 471 | } |
| 472 | |
| 473 | func (o OltDevice) GetPonIf(context context.Context, packet *openolt.Interface) (*openolt.IntfIndication, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 474 | oltLogger.Error("GetPonIf not implemented") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 475 | return new(openolt.IntfIndication) , nil |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | func (s OltDevice) CreateTrafficQueues(context.Context, *tech_profile.TrafficQueues) (*openolt.Empty, error) { |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 479 | oltLogger.Info("received CreateTrafficQueues") |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 480 | return new(openolt.Empty), nil |
| 481 | } |
| 482 | |
| 483 | func (s OltDevice) RemoveTrafficQueues(context.Context, *tech_profile.TrafficQueues) (*openolt.Empty, error) { |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 484 | oltLogger.Info("received RemoveTrafficQueues") |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 485 | return new(openolt.Empty), nil |
| 486 | } |
| 487 | |
| 488 | func (s OltDevice) CreateTrafficSchedulers(context.Context, *tech_profile.TrafficSchedulers) (*openolt.Empty, error) { |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 489 | oltLogger.Info("received CreateTrafficSchedulers") |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 490 | return new(openolt.Empty), nil |
| 491 | } |
| 492 | |
| 493 | func (s OltDevice) RemoveTrafficSchedulers(context.Context, *tech_profile.TrafficSchedulers) (*openolt.Empty, error) { |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 494 | oltLogger.Info("received RemoveTrafficSchedulers") |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 495 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 496 | } |