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