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 | 3bc7374 | 2019-08-20 14:04:04 -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 | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame^] | 110 | //o := CreateONU(olt, p, uint32(onuId)) |
| 111 | o := CreateONU(olt, p, uint32(j + 1)) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 112 | p.Onus = append(p.Onus, o) |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame^] | 113 | //onuId = onuId + 1 |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | olt.Pons = append(olt.Pons, p) |
| 117 | } |
| 118 | |
| 119 | wg := sync.WaitGroup{} |
| 120 | |
| 121 | wg.Add(1) |
| 122 | go newOltServer(olt) |
| 123 | wg.Wait() |
| 124 | return olt |
| 125 | } |
| 126 | |
| 127 | func newOltServer(o OltDevice) error { |
| 128 | // TODO make configurable |
| 129 | address := "0.0.0.0:50060" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 130 | lis, err := net.Listen("tcp", address) |
| 131 | if err != nil { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 132 | oltLogger.Fatalf("OLT failed to listen: %v", err) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 133 | } |
| 134 | grpcServer := grpc.NewServer() |
| 135 | openolt.RegisterOpenoltServer(grpcServer, o) |
| 136 | |
| 137 | go grpcServer.Serve(lis) |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 138 | oltLogger.Debugf("OLT Listening on: %v", address) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 139 | |
| 140 | return nil |
| 141 | } |
| 142 | |
| 143 | // Device Methods |
| 144 | |
| 145 | func (o OltDevice) Enable (stream openolt.Openolt_EnableIndicationServer) error { |
| 146 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 147 | oltLogger.Debug("Enable OLT called") |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 148 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 149 | wg := sync.WaitGroup{} |
| 150 | wg.Add(1) |
| 151 | |
| 152 | // create a channel for all the OLT events |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 153 | go o.processOltMessages(stream) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 154 | |
| 155 | // enable the OLT |
| 156 | olt_msg := Message{ |
| 157 | Type: OltIndication, |
| 158 | Data: OltIndicationMessage{ |
| 159 | OperState: UP, |
| 160 | }, |
| 161 | } |
| 162 | o.channel <- olt_msg |
| 163 | |
| 164 | // send NNI Port Indications |
| 165 | for _, nni := range o.Nnis { |
| 166 | msg := Message{ |
| 167 | Type: NniIndication, |
| 168 | Data: NniIndicationMessage{ |
| 169 | OperState: UP, |
| 170 | NniPortID: nni.ID, |
| 171 | }, |
| 172 | } |
| 173 | o.channel <- msg |
| 174 | } |
| 175 | |
| 176 | // send PON Port indications |
| 177 | for _, pon := range o.Pons { |
| 178 | msg := Message{ |
| 179 | Type: PonIndication, |
| 180 | Data: PonIndicationMessage{ |
| 181 | OperState: UP, |
| 182 | PonPortID: pon.ID, |
| 183 | }, |
| 184 | } |
| 185 | o.channel <- msg |
| 186 | |
| 187 | for _, onu := range pon.Onus { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 188 | go onu.processOnuMessages(stream) |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame^] | 189 | go onu.processOmciMessages(stream) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 190 | msg := Message{ |
| 191 | Type: OnuDiscIndication, |
| 192 | Data: OnuDiscIndicationMessage{ |
| 193 | Onu: onu, |
| 194 | OperState: UP, |
| 195 | }, |
| 196 | } |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 197 | onu.channel <- msg |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 198 | } |
| 199 | } |
| 200 | |
| 201 | wg.Wait() |
| 202 | return nil |
| 203 | } |
| 204 | |
| 205 | // Helpers method |
| 206 | |
| 207 | func (o OltDevice) getPonById(id uint32) (*PonPort, error) { |
| 208 | for _, pon := range o.Pons { |
| 209 | if pon.ID == id { |
| 210 | return &pon, nil |
| 211 | } |
| 212 | } |
| 213 | return nil, errors.New(fmt.Sprintf("Cannot find PonPort with id %d in OLT %d", id, o.ID)) |
| 214 | } |
| 215 | |
| 216 | func (o OltDevice) getNniById(id uint32) (*NniPort, error) { |
| 217 | for _, nni := range o.Nnis { |
| 218 | if nni.ID == id { |
| 219 | return &nni, nil |
| 220 | } |
| 221 | } |
| 222 | return nil, errors.New(fmt.Sprintf("Cannot find NniPort with id %d in OLT %d", id, o.ID)) |
| 223 | } |
| 224 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 225 | func (o OltDevice) sendOltIndication(msg OltIndicationMessage, stream openolt.Openolt_EnableIndicationServer) { |
| 226 | data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: msg.OperState.String()}} |
| 227 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 228 | oltLogger.Errorf("Failed to send Indication_OltInd: %v", err) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 231 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 232 | "OperState": msg.OperState, |
| 233 | }).Debug("Sent Indication_OltInd") |
| 234 | } |
| 235 | |
| 236 | func (o OltDevice) sendNniIndication(msg NniIndicationMessage, stream openolt.Openolt_EnableIndicationServer) { |
| 237 | nni, _ := o.getNniById(msg.NniPortID) |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 238 | nni.OperState.Event("enable") |
| 239 | // NOTE Operstate may need to be an integer |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 240 | operData := &openolt.Indication_IntfOperInd{IntfOperInd: &openolt.IntfOperIndication{ |
| 241 | Type: nni.Type, |
| 242 | IntfId: nni.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 243 | OperState: nni.OperState.Current(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 244 | }} |
| 245 | |
| 246 | if err := stream.Send(&openolt.Indication{Data: operData}); err != nil { |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 247 | oltLogger.Errorf("Failed to send Indication_IntfOperInd for NNI: %v", err) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 248 | } |
| 249 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 250 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 251 | "Type": nni.Type, |
| 252 | "IntfId": nni.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 253 | "OperState": nni.OperState.Current(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 254 | }).Debug("Sent Indication_IntfOperInd for NNI") |
| 255 | } |
| 256 | |
| 257 | func (o OltDevice) sendPonIndication(msg PonIndicationMessage, stream openolt.Openolt_EnableIndicationServer) { |
| 258 | pon, _ := o.getPonById(msg.PonPortID) |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 259 | pon.OperState.Event("enable") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 260 | discoverData := &openolt.Indication_IntfInd{IntfInd: &openolt.IntfIndication{ |
| 261 | IntfId: pon.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 262 | OperState: pon.OperState.Current(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 263 | }} |
| 264 | |
| 265 | if err := stream.Send(&openolt.Indication{Data: discoverData}); err != nil { |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 266 | oltLogger.Errorf("Failed to send Indication_IntfInd: %v", err) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 269 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 270 | "IntfId": pon.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 271 | "OperState": pon.OperState.Current(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 272 | }).Debug("Sent Indication_IntfInd") |
| 273 | |
| 274 | operData := &openolt.Indication_IntfOperInd{IntfOperInd: &openolt.IntfOperIndication{ |
| 275 | Type: pon.Type, |
| 276 | IntfId: pon.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 277 | OperState: pon.OperState.Current(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 278 | }} |
| 279 | |
| 280 | if err := stream.Send(&openolt.Indication{Data: operData}); err != nil { |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 281 | oltLogger.Errorf("Failed to send Indication_IntfOperInd for PON: %v", err) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 284 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 285 | "Type": pon.Type, |
| 286 | "IntfId": pon.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 287 | "OperState": pon.OperState.Current(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 288 | }).Debug("Sent Indication_IntfOperInd for PON") |
| 289 | } |
| 290 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 291 | func (o OltDevice) processOltMessages(stream openolt.Openolt_EnableIndicationServer) { |
| 292 | oltLogger.Debug("Started OLT Indication Channel") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 293 | for message := range o.channel { |
| 294 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 295 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 296 | oltLogger.WithFields(log.Fields{ |
| 297 | "oltId": o.ID, |
| 298 | "messageType": message.Type, |
| 299 | }).Trace("Received message") |
| 300 | |
| 301 | switch message.Type { |
| 302 | case OltIndication: |
| 303 | msg, _ := message.Data.(OltIndicationMessage) |
| 304 | if msg.OperState == UP { |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 305 | o.InternalState.Event("enable") |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 306 | o.OperState.Event("enable") |
| 307 | } else if msg.OperState == DOWN { |
| 308 | o.InternalState.Event("disable") |
| 309 | o.OperState.Event("disable") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 310 | } |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 311 | o.sendOltIndication(msg, stream) |
| 312 | case NniIndication: |
| 313 | msg, _ := message.Data.(NniIndicationMessage) |
| 314 | o.sendNniIndication(msg, stream) |
| 315 | case PonIndication: |
| 316 | msg, _ := message.Data.(PonIndicationMessage) |
| 317 | o.sendPonIndication(msg, stream) |
| 318 | default: |
| 319 | 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] | 320 | } |
| 321 | |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | // GRPC Endpoints |
| 326 | |
| 327 | 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] | 328 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 329 | "onuSerialNumber": onu.SerialNumber, |
| 330 | }).Info("Received ActivateOnu call from VOLTHA") |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 331 | |
| 332 | pon, _ := o.getPonById(onu.IntfId) |
| 333 | _onu, _ := pon.getOnuBySn(onu.SerialNumber) |
| 334 | |
| 335 | // 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] | 336 | msg := Message{ |
| 337 | Type: OnuIndication, |
| 338 | Data: OnuIndicationMessage{ |
| 339 | OnuSN: onu.SerialNumber, |
| 340 | PonPortID: onu.IntfId, |
| 341 | OperState: UP, |
| 342 | }, |
| 343 | } |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 344 | _onu.channel <- msg |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 345 | return new(openolt.Empty) , nil |
| 346 | } |
| 347 | |
| 348 | func (o OltDevice) DeactivateOnu(context.Context, *openolt.Onu) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 349 | oltLogger.Error("DeactivateOnu not implemented") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 350 | return new(openolt.Empty) , nil |
| 351 | } |
| 352 | |
| 353 | func (o OltDevice) DeleteOnu(context.Context, *openolt.Onu) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 354 | oltLogger.Error("DeleteOnu not implemented") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 355 | return new(openolt.Empty) , nil |
| 356 | } |
| 357 | |
| 358 | func (o OltDevice) DisableOlt(context.Context, *openolt.Empty) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 359 | // NOTE when we disable the OLT should we disable NNI, PONs and ONUs altogether? |
| 360 | olt_msg := Message{ |
| 361 | Type: OltIndication, |
| 362 | Data: OltIndicationMessage{ |
| 363 | OperState: DOWN, |
| 364 | }, |
| 365 | } |
| 366 | o.channel <- olt_msg |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 367 | return new(openolt.Empty) , nil |
| 368 | } |
| 369 | |
| 370 | func (o OltDevice) DisablePonIf(context.Context, *openolt.Interface) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 371 | oltLogger.Error("DisablePonIf not implemented") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 372 | return new(openolt.Empty) , nil |
| 373 | } |
| 374 | |
| 375 | func (o OltDevice) EnableIndication(_ *openolt.Empty, stream openolt.Openolt_EnableIndicationServer) error { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 376 | oltLogger.WithField("oltId", o.ID).Info("OLT receives EnableIndication call from VOLTHA") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 377 | o.Enable(stream) |
| 378 | return nil |
| 379 | } |
| 380 | |
| 381 | func (o OltDevice) EnablePonIf(context.Context, *openolt.Interface) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 382 | oltLogger.Error("EnablePonIf not implemented") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 383 | return new(openolt.Empty) , nil |
| 384 | } |
| 385 | |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame^] | 386 | func (o OltDevice) FlowAdd(ctx context.Context, flow *openolt.Flow) (*openolt.Empty, error) { |
| 387 | oltLogger.WithFields(log.Fields{ |
| 388 | "IntfId": flow.AccessIntfId, |
| 389 | "OnuId": flow.OnuId, |
| 390 | "EthType": fmt.Sprintf("%x", flow.Classifier.EthType), |
| 391 | "InnerVlan": flow.Classifier.IVid, |
| 392 | "OuterVlan": flow.Classifier.OVid, |
| 393 | "FlowType": flow.FlowType, |
| 394 | "FlowId": flow.FlowId, |
| 395 | "UniID": flow.UniId, |
| 396 | "PortNo": flow.PortNo, |
| 397 | }).Infof("OLT receives Flow") |
| 398 | // TODO optionally store flows somewhere |
| 399 | |
| 400 | if flow.AccessIntfId == -1 { |
| 401 | oltLogger.WithFields(log.Fields{ |
| 402 | "FlowId": flow.FlowId, |
| 403 | }).Debugf("This is an OLT flow") |
| 404 | } else { |
| 405 | pon, _ := o.getPonById(uint32(flow.AccessIntfId)) |
| 406 | onu, _ := pon.getOnuById(uint32(flow.OnuId)) |
| 407 | |
| 408 | msg := Message{ |
| 409 | Type: FlowUpdate, |
| 410 | Data: OnuFlowUpdateMessage{ |
| 411 | PonPortID: pon.ID, |
| 412 | OnuID: onu.ID, |
| 413 | Flow: flow, |
| 414 | }, |
| 415 | } |
| 416 | onu.channel <- msg |
| 417 | } |
| 418 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 419 | return new(openolt.Empty) , nil |
| 420 | } |
| 421 | |
| 422 | func (o OltDevice) FlowRemove(context.Context, *openolt.Flow) (*openolt.Empty, error) { |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 423 | oltLogger.Info("received FlowRemove") |
| 424 | // TODO store flows somewhere |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 425 | return new(openolt.Empty) , nil |
| 426 | } |
| 427 | |
| 428 | func (o OltDevice) HeartbeatCheck(context.Context, *openolt.Empty) (*openolt.Heartbeat, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 429 | oltLogger.Error("HeartbeatCheck not implemented") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 430 | return new(openolt.Heartbeat) , nil |
| 431 | } |
| 432 | |
| 433 | func (o OltDevice) GetDeviceInfo(context.Context, *openolt.Empty) (*openolt.DeviceInfo, error) { |
| 434 | |
Matteo Scandolo | da9cbe2 | 2019-08-19 16:05:10 -0700 | [diff] [blame] | 435 | oltLogger.WithFields(log.Fields{ |
| 436 | "oltId": o.ID, |
| 437 | "PonPorts": o.NumPon, |
| 438 | }).Info("OLT receives GetDeviceInfo call from VOLTHA") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 439 | devinfo := new(openolt.DeviceInfo) |
| 440 | devinfo.Vendor = "BBSim" |
| 441 | devinfo.Model = "asfvolt16" |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 442 | devinfo.HardwareVersion = "emulated" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 443 | devinfo.FirmwareVersion = "" |
| 444 | devinfo.Technology = "xgspon" |
Matteo Scandolo | da9cbe2 | 2019-08-19 16:05:10 -0700 | [diff] [blame] | 445 | devinfo.PonPorts = uint32(o.NumPon) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 446 | devinfo.OnuIdStart = 1 |
| 447 | devinfo.OnuIdEnd = 255 |
| 448 | devinfo.AllocIdStart = 1024 |
| 449 | devinfo.AllocIdEnd = 16383 |
| 450 | devinfo.GemportIdStart = 1024 |
| 451 | devinfo.GemportIdEnd = 65535 |
| 452 | devinfo.FlowIdStart = 1 |
| 453 | devinfo.FlowIdEnd = 16383 |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 454 | devinfo.DeviceSerialNumber = fmt.Sprintf("BBSIM_OLT_%d", o.ID) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 455 | |
| 456 | return devinfo, nil |
| 457 | } |
| 458 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 459 | 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] | 460 | pon, _ := o.getPonById(omci_msg.IntfId) |
| 461 | onu, _ := pon.getOnuById(omci_msg.OnuId) |
| 462 | msg := Message{ |
| 463 | Type: OMCI, |
| 464 | Data: OmciMessage{ |
| 465 | OnuSN: onu.SerialNumber, |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 466 | OnuID: onu.ID, |
| 467 | omciMsg: omci_msg, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 468 | }, |
| 469 | } |
| 470 | onu.channel <- msg |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 471 | return new(openolt.Empty) , nil |
| 472 | } |
| 473 | |
| 474 | func (o OltDevice) OnuPacketOut(context.Context, *openolt.OnuPacket) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 475 | oltLogger.Error("OnuPacketOut not implemented") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 476 | return new(openolt.Empty) , nil |
| 477 | } |
| 478 | |
| 479 | func (o OltDevice) Reboot(context.Context, *openolt.Empty) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 480 | oltLogger.Info("Shutting Down, hope you're running in K8s...") |
| 481 | os.Exit(0) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 482 | return new(openolt.Empty) , nil |
| 483 | } |
| 484 | |
| 485 | func (o OltDevice) ReenableOlt(context.Context, *openolt.Empty) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 486 | oltLogger.Error("ReenableOlt not implemented") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 487 | return new(openolt.Empty) , nil |
| 488 | } |
| 489 | |
| 490 | 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] | 491 | oltLogger.Warn("UplinkPacketOut not implemented") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 492 | return new(openolt.Empty) , nil |
| 493 | } |
| 494 | |
| 495 | func (o OltDevice) CollectStatistics(context.Context, *openolt.Empty) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 496 | oltLogger.Error("CollectStatistics not implemented") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 497 | return new(openolt.Empty) , nil |
| 498 | } |
| 499 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 500 | 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] | 501 | oltLogger.Error("GetOnuInfo not implemented") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 502 | return new(openolt.OnuIndication) , nil |
| 503 | } |
| 504 | |
| 505 | 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] | 506 | oltLogger.Error("GetPonIf not implemented") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 507 | return new(openolt.IntfIndication) , nil |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | func (s OltDevice) CreateTrafficQueues(context.Context, *tech_profile.TrafficQueues) (*openolt.Empty, error) { |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 511 | oltLogger.Info("received CreateTrafficQueues") |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 512 | return new(openolt.Empty), nil |
| 513 | } |
| 514 | |
| 515 | func (s OltDevice) RemoveTrafficQueues(context.Context, *tech_profile.TrafficQueues) (*openolt.Empty, error) { |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 516 | oltLogger.Info("received RemoveTrafficQueues") |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 517 | return new(openolt.Empty), nil |
| 518 | } |
| 519 | |
| 520 | func (s OltDevice) CreateTrafficSchedulers(context.Context, *tech_profile.TrafficSchedulers) (*openolt.Empty, error) { |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 521 | oltLogger.Info("received CreateTrafficSchedulers") |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 522 | return new(openolt.Empty), nil |
| 523 | } |
| 524 | |
| 525 | func (s OltDevice) RemoveTrafficSchedulers(context.Context, *tech_profile.TrafficSchedulers) (*openolt.Empty, error) { |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 526 | oltLogger.Info("received RemoveTrafficSchedulers") |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 527 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 528 | } |