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