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