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