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 | "github.com/google/gopacket" |
| 24 | "github.com/google/gopacket/layers" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 25 | "github.com/looplab/fsm" |
Matteo Scandolo | f6f3a7f | 2019-10-11 11:19:29 -0700 | [diff] [blame] | 26 | "github.com/opencord/bbsim/internal/bbsim/packetHandlers" |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 27 | bbsim "github.com/opencord/bbsim/internal/bbsim/types" |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 28 | "github.com/opencord/voltha-protos/go/openolt" |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 29 | "github.com/opencord/voltha-protos/go/tech_profile" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 30 | log "github.com/sirupsen/logrus" |
| 31 | "google.golang.org/grpc" |
| 32 | "net" |
| 33 | "sync" |
| 34 | ) |
| 35 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 36 | var oltLogger = log.WithFields(log.Fields{ |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 37 | "module": "OLT", |
| 38 | }) |
| 39 | |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 40 | type OltDevice struct { |
| 41 | // BBSIM Internals |
| 42 | ID int |
| 43 | SerialNumber string |
| 44 | NumNni int |
| 45 | NumPon int |
| 46 | NumOnuPerPon int |
| 47 | InternalState *fsm.FSM |
| 48 | channel chan Message |
| 49 | oltDoneChannel *chan bool |
| 50 | apiDoneChannel *chan bool |
| 51 | nniPktInChannel chan *bbsim.PacketMsg |
| 52 | |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame^] | 53 | Pons []*PonPort |
| 54 | Nnis []*NniPort |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 55 | |
| 56 | // OLT Attributes |
| 57 | OperState *fsm.FSM |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame^] | 60 | var olt OltDevice |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 61 | |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame^] | 62 | func GetOLT() *OltDevice { |
| 63 | return &olt |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 66 | func CreateOLT(seq int, nni int, pon int, onuPerPon int, sTag int, cTagInit int, oltDoneChannel *chan bool, apiDoneChannel *chan bool, group *sync.WaitGroup) OltDevice { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 67 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 68 | "ID": seq, |
| 69 | "NumNni": nni, |
| 70 | "NumPon": pon, |
| 71 | "NumOnuPerPon": onuPerPon, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 72 | }).Debug("CreateOLT") |
| 73 | |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 74 | olt = OltDevice{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 75 | ID: seq, |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 76 | SerialNumber: fmt.Sprintf("BBSIM_OLT_%d", seq), |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 77 | OperState: getOperStateFSM(func(e *fsm.Event) { |
| 78 | oltLogger.Debugf("Changing OLT OperState from %s to %s", e.Src, e.Dst) |
| 79 | }), |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 80 | NumNni: nni, |
| 81 | NumPon: pon, |
| 82 | NumOnuPerPon: onuPerPon, |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame^] | 83 | Pons: []*PonPort{}, |
| 84 | Nnis: []*NniPort{}, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 85 | channel: make(chan Message), |
| 86 | oltDoneChannel: oltDoneChannel, |
| 87 | apiDoneChannel: apiDoneChannel, |
| 88 | nniPktInChannel: make(chan *bbsim.PacketMsg, 1024), // packets coming in from the NNI and going to VOLTHA |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | // OLT State machine |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 92 | // 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] | 93 | olt.InternalState = fsm.NewFSM( |
| 94 | "created", |
| 95 | fsm.Events{ |
| 96 | {Name: "enable", Src: []string{"created"}, Dst: "enabled"}, |
| 97 | {Name: "disable", Src: []string{"enabled"}, Dst: "disabled"}, |
| 98 | }, |
| 99 | fsm.Callbacks{ |
| 100 | "enter_state": func(e *fsm.Event) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 101 | 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] | 102 | }, |
| 103 | }, |
| 104 | ) |
| 105 | |
| 106 | // create NNI Port |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 107 | nniPort, err := CreateNNI(&olt) |
| 108 | |
| 109 | if err != nil { |
| 110 | oltLogger.Fatalf("Couldn't create NNI Port: %v", err) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 111 | } |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 112 | |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame^] | 113 | olt.Nnis = append(olt.Nnis, &nniPort) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 114 | |
| 115 | // create PON ports |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 116 | availableCTag := cTagInit |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 117 | for i := 0; i < pon; i++ { |
| 118 | p := PonPort{ |
| 119 | NumOnu: olt.NumOnuPerPon, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 120 | ID: uint32(i), |
| 121 | Type: "pon", |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 122 | Olt: olt, |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame^] | 123 | Onus: []*Onu{}, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 124 | } |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 125 | p.OperState = getOperStateFSM(func(e *fsm.Event) { |
| 126 | oltLogger.WithFields(log.Fields{ |
| 127 | "ID": p.ID, |
| 128 | }).Debugf("Changing PON Port OperState from %s to %s", e.Src, e.Dst) |
| 129 | }) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 130 | |
| 131 | // create ONU devices |
| 132 | for j := 0; j < onuPerPon; j++ { |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 133 | o := CreateONU(olt, p, uint32(j+1), sTag, availableCTag) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 134 | p.Onus = append(p.Onus, o) |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 135 | availableCTag = availableCTag + 1 |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame^] | 138 | olt.Pons = append(olt.Pons, &p) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 141 | newOltServer(olt) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 142 | |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 143 | group.Done() |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 144 | return olt |
| 145 | } |
| 146 | |
| 147 | func newOltServer(o OltDevice) error { |
| 148 | // TODO make configurable |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 149 | address := "0.0.0.0:50060" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 150 | lis, err := net.Listen("tcp", address) |
| 151 | if err != nil { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 152 | oltLogger.Fatalf("OLT failed to listen: %v", err) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 153 | } |
| 154 | grpcServer := grpc.NewServer() |
| 155 | openolt.RegisterOpenoltServer(grpcServer, o) |
| 156 | |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 157 | wg := sync.WaitGroup{} |
| 158 | wg.Add(1) |
| 159 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 160 | go grpcServer.Serve(lis) |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 161 | oltLogger.Debugf("OLT Listening on: %v", address) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 162 | |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 163 | for { |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 164 | _, ok := <-*o.oltDoneChannel |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 165 | if !ok { |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 166 | // if the olt Channel is closed, stop the gRPC server |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 167 | log.Warnf("Stopping OLT gRPC server") |
| 168 | grpcServer.Stop() |
| 169 | wg.Done() |
| 170 | break |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | wg.Wait() |
| 175 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 176 | return nil |
| 177 | } |
| 178 | |
| 179 | // Device Methods |
| 180 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 181 | func (o OltDevice) Enable(stream openolt.Openolt_EnableIndicationServer) error { |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 182 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 183 | oltLogger.Debug("Enable OLT called") |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 184 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 185 | wg := sync.WaitGroup{} |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 186 | wg.Add(2) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 187 | |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 188 | // create a Channel for all the OLT events |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 189 | go o.processOltMessages(stream) |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 190 | go o.processNniPacketIns(stream) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 191 | |
| 192 | // enable the OLT |
| 193 | olt_msg := Message{ |
| 194 | Type: OltIndication, |
| 195 | Data: OltIndicationMessage{ |
| 196 | OperState: UP, |
| 197 | }, |
| 198 | } |
| 199 | o.channel <- olt_msg |
| 200 | |
| 201 | // send NNI Port Indications |
| 202 | for _, nni := range o.Nnis { |
| 203 | msg := Message{ |
| 204 | Type: NniIndication, |
| 205 | Data: NniIndicationMessage{ |
| 206 | OperState: UP, |
| 207 | NniPortID: nni.ID, |
| 208 | }, |
| 209 | } |
| 210 | o.channel <- msg |
| 211 | } |
| 212 | |
| 213 | // send PON Port indications |
| 214 | for _, pon := range o.Pons { |
| 215 | msg := Message{ |
| 216 | Type: PonIndication, |
| 217 | Data: PonIndicationMessage{ |
| 218 | OperState: UP, |
| 219 | PonPortID: pon.ID, |
| 220 | }, |
| 221 | } |
| 222 | o.channel <- msg |
| 223 | |
| 224 | for _, onu := range pon.Onus { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 225 | go onu.processOnuMessages(stream) |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 226 | go onu.processOmciMessages(stream) |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 227 | // FIXME move the message generation in the state transition |
| 228 | // from here only invoke the state transition |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 229 | msg := Message{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 230 | Type: OnuDiscIndication, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 231 | Data: OnuDiscIndicationMessage{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 232 | Onu: onu, |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 233 | OperState: UP, |
| 234 | }, |
| 235 | } |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 236 | onu.Channel <- msg |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 237 | } |
| 238 | } |
| 239 | |
| 240 | wg.Wait() |
| 241 | return nil |
| 242 | } |
| 243 | |
| 244 | // Helpers method |
| 245 | |
| 246 | func (o OltDevice) getPonById(id uint32) (*PonPort, error) { |
| 247 | for _, pon := range o.Pons { |
| 248 | if pon.ID == id { |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame^] | 249 | return pon, nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 250 | } |
| 251 | } |
| 252 | return nil, errors.New(fmt.Sprintf("Cannot find PonPort with id %d in OLT %d", id, o.ID)) |
| 253 | } |
| 254 | |
| 255 | func (o OltDevice) getNniById(id uint32) (*NniPort, error) { |
| 256 | for _, nni := range o.Nnis { |
| 257 | if nni.ID == id { |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame^] | 258 | return nni, nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | return nil, errors.New(fmt.Sprintf("Cannot find NniPort with id %d in OLT %d", id, o.ID)) |
| 262 | } |
| 263 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 264 | func (o OltDevice) sendOltIndication(msg OltIndicationMessage, stream openolt.Openolt_EnableIndicationServer) { |
| 265 | data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: msg.OperState.String()}} |
| 266 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 267 | oltLogger.Errorf("Failed to send Indication_OltInd: %v", err) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 270 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 271 | "OperState": msg.OperState, |
| 272 | }).Debug("Sent Indication_OltInd") |
| 273 | } |
| 274 | |
| 275 | func (o OltDevice) sendNniIndication(msg NniIndicationMessage, stream openolt.Openolt_EnableIndicationServer) { |
| 276 | nni, _ := o.getNniById(msg.NniPortID) |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 277 | nni.OperState.Event("enable") |
| 278 | // NOTE Operstate may need to be an integer |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 279 | operData := &openolt.Indication_IntfOperInd{IntfOperInd: &openolt.IntfOperIndication{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 280 | Type: nni.Type, |
| 281 | IntfId: nni.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 282 | OperState: nni.OperState.Current(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 283 | }} |
| 284 | |
| 285 | if err := stream.Send(&openolt.Indication{Data: operData}); err != nil { |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 286 | oltLogger.Errorf("Failed to send Indication_IntfOperInd for NNI: %v", err) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 289 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 290 | "Type": nni.Type, |
| 291 | "IntfId": nni.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 292 | "OperState": nni.OperState.Current(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 293 | }).Debug("Sent Indication_IntfOperInd for NNI") |
| 294 | } |
| 295 | |
| 296 | func (o OltDevice) sendPonIndication(msg PonIndicationMessage, stream openolt.Openolt_EnableIndicationServer) { |
| 297 | pon, _ := o.getPonById(msg.PonPortID) |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 298 | pon.OperState.Event("enable") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 299 | discoverData := &openolt.Indication_IntfInd{IntfInd: &openolt.IntfIndication{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 300 | IntfId: pon.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 301 | OperState: pon.OperState.Current(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 302 | }} |
| 303 | |
| 304 | if err := stream.Send(&openolt.Indication{Data: discoverData}); err != nil { |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 305 | oltLogger.Errorf("Failed to send Indication_IntfInd: %v", err) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 306 | } |
| 307 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 308 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 309 | "IntfId": pon.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 310 | "OperState": pon.OperState.Current(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 311 | }).Debug("Sent Indication_IntfInd") |
| 312 | |
| 313 | operData := &openolt.Indication_IntfOperInd{IntfOperInd: &openolt.IntfOperIndication{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 314 | Type: pon.Type, |
| 315 | IntfId: pon.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 316 | OperState: pon.OperState.Current(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 317 | }} |
| 318 | |
| 319 | if err := stream.Send(&openolt.Indication{Data: operData}); err != nil { |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 320 | oltLogger.Errorf("Failed to send Indication_IntfOperInd for PON: %v", err) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 323 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 324 | "Type": pon.Type, |
| 325 | "IntfId": pon.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 326 | "OperState": pon.OperState.Current(), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 327 | }).Debug("Sent Indication_IntfOperInd for PON") |
| 328 | } |
| 329 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 330 | func (o OltDevice) processOltMessages(stream openolt.Openolt_EnableIndicationServer) { |
| 331 | oltLogger.Debug("Started OLT Indication Channel") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 332 | for message := range o.channel { |
| 333 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 334 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 335 | "oltId": o.ID, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 336 | "messageType": message.Type, |
| 337 | }).Trace("Received message") |
| 338 | |
| 339 | switch message.Type { |
| 340 | case OltIndication: |
| 341 | msg, _ := message.Data.(OltIndicationMessage) |
| 342 | if msg.OperState == UP { |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 343 | o.InternalState.Event("enable") |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 344 | o.OperState.Event("enable") |
| 345 | } else if msg.OperState == DOWN { |
| 346 | o.InternalState.Event("disable") |
| 347 | o.OperState.Event("disable") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 348 | } |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 349 | o.sendOltIndication(msg, stream) |
| 350 | case NniIndication: |
| 351 | msg, _ := message.Data.(NniIndicationMessage) |
| 352 | o.sendNniIndication(msg, stream) |
| 353 | case PonIndication: |
| 354 | msg, _ := message.Data.(PonIndicationMessage) |
| 355 | o.sendPonIndication(msg, stream) |
| 356 | default: |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 357 | 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] | 358 | } |
| 359 | |
| 360 | } |
| 361 | } |
| 362 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 363 | func (o OltDevice) processNniPacketIns(stream openolt.Openolt_EnableIndicationServer) { |
| 364 | oltLogger.WithFields(log.Fields{ |
| 365 | "nniChannel": o.nniPktInChannel, |
| 366 | }).Debug("Started NNI Channel") |
| 367 | nniId := o.Nnis[0].ID // FIXME we are assuming we have only one NNI |
| 368 | for message := range o.nniPktInChannel { |
Matteo Scandolo | f6f3a7f | 2019-10-11 11:19:29 -0700 | [diff] [blame] | 369 | oltLogger.Tracef("Received packets on NNI Channel") |
| 370 | |
| 371 | onuMac, err := packetHandlers.GetDstMacAddressFromPacket(message.Pkt) |
| 372 | |
| 373 | if err != nil { |
| 374 | log.WithFields(log.Fields{ |
| 375 | "IntfType": "nni", |
| 376 | "IntfId": nniId, |
| 377 | "Pkt": message.Pkt.Data(), |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame^] | 378 | }).Error("Can't find Dst MacAddress in packet") |
Matteo Scandolo | f6f3a7f | 2019-10-11 11:19:29 -0700 | [diff] [blame] | 379 | return |
| 380 | } |
| 381 | |
| 382 | onu, err := o.FindOnuByMacAddress(onuMac) |
| 383 | if err != nil { |
| 384 | log.WithFields(log.Fields{ |
| 385 | "IntfType": "nni", |
| 386 | "IntfId": nniId, |
| 387 | "Pkt": message.Pkt.Data(), |
| 388 | "MacAddress": onuMac.String(), |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame^] | 389 | }).Error("Can't find ONU with MacAddress") |
Matteo Scandolo | f6f3a7f | 2019-10-11 11:19:29 -0700 | [diff] [blame] | 390 | return |
| 391 | } |
| 392 | |
| 393 | doubleTaggedPkt, err := packetHandlers.PushDoubleTag(onu.STag, onu.CTag, message.Pkt) |
| 394 | if err != nil { |
| 395 | log.Error("Fail to add double tag to packet") |
| 396 | } |
| 397 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 398 | data := &openolt.Indication_PktInd{PktInd: &openolt.PacketIndication{ |
| 399 | IntfType: "nni", |
| 400 | IntfId: nniId, |
Matteo Scandolo | f6f3a7f | 2019-10-11 11:19:29 -0700 | [diff] [blame] | 401 | Pkt: doubleTaggedPkt.Data()}} |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 402 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
| 403 | oltLogger.WithFields(log.Fields{ |
| 404 | "IntfType": data.PktInd.IntfType, |
| 405 | "IntfId": nniId, |
Matteo Scandolo | f6f3a7f | 2019-10-11 11:19:29 -0700 | [diff] [blame] | 406 | "Pkt": doubleTaggedPkt.Data(), |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 407 | }).Errorf("Fail to send PktInd indication: %v", err) |
| 408 | } |
Matteo Scandolo | f6f3a7f | 2019-10-11 11:19:29 -0700 | [diff] [blame] | 409 | oltLogger.WithFields(log.Fields{ |
| 410 | "IntfType": data.PktInd.IntfType, |
| 411 | "IntfId": nniId, |
| 412 | "Pkt": doubleTaggedPkt.Data(), |
| 413 | }).Tracef("Sent PktInd indication") |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 414 | } |
| 415 | } |
| 416 | |
Matteo Scandolo | f6f3a7f | 2019-10-11 11:19:29 -0700 | [diff] [blame] | 417 | // returns an ONU with a given Serial Number |
| 418 | func (o OltDevice) FindOnuBySn(serialNumber string) (*Onu, error) { |
| 419 | // TODO this function can be a perfoormance bottlenec when we have many ONUs, |
| 420 | // memoizing it will remove the bottleneck |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 421 | for _, pon := range o.Pons { |
| 422 | for _, onu := range pon.Onus { |
| 423 | if onu.Sn() == serialNumber { |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame^] | 424 | return onu, nil |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 425 | } |
| 426 | } |
| 427 | } |
| 428 | |
Matteo Scandolo | f6f3a7f | 2019-10-11 11:19:29 -0700 | [diff] [blame] | 429 | return &Onu{}, errors.New(fmt.Sprintf("cannot-find-onu-by-serial-number-%s", serialNumber)) |
| 430 | } |
| 431 | |
| 432 | // returns an ONU with a given Mac Address |
| 433 | func (o OltDevice) FindOnuByMacAddress(mac net.HardwareAddr) (*Onu, error) { |
| 434 | // TODO this function can be a perfoormance bottlenec when we have many ONUs, |
| 435 | // memoizing it will remove the bottleneck |
| 436 | for _, pon := range o.Pons { |
| 437 | for _, onu := range pon.Onus { |
| 438 | if onu.HwAddress.String() == mac.String() { |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame^] | 439 | return onu, nil |
Matteo Scandolo | f6f3a7f | 2019-10-11 11:19:29 -0700 | [diff] [blame] | 440 | } |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | return &Onu{}, errors.New(fmt.Sprintf("cannot-find-onu-by-mac-address-%s", mac)) |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 445 | } |
| 446 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 447 | // GRPC Endpoints |
| 448 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 449 | 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] | 450 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 451 | "OnuSn": onuSnToString(onu.SerialNumber), |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 452 | }).Info("Received ActivateOnu call from VOLTHA") |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 453 | |
| 454 | pon, _ := o.getPonById(onu.IntfId) |
| 455 | _onu, _ := pon.getOnuBySn(onu.SerialNumber) |
| 456 | |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 457 | if err := _onu.OperState.Event("enable"); err != nil { |
| 458 | oltLogger.WithFields(log.Fields{ |
| 459 | "IntfId": _onu.PonPortID, |
| 460 | "OnuSn": _onu.Sn(), |
| 461 | "OnuId": _onu.ID, |
| 462 | }).Infof("Failed to transition ONU.OperState to enabled state: %s", err.Error()) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 463 | } |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 464 | if err := _onu.InternalState.Event("enable"); err != nil { |
| 465 | oltLogger.WithFields(log.Fields{ |
| 466 | "IntfId": _onu.PonPortID, |
| 467 | "OnuSn": _onu.Sn(), |
| 468 | "OnuId": _onu.ID, |
| 469 | }).Infof("Failed to transition ONU to enabled state: %s", err.Error()) |
| 470 | } |
| 471 | |
| 472 | // NOTE we need to immediately activate the ONU or the OMCI state machine won't start |
| 473 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 474 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 475 | } |
| 476 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 477 | func (o OltDevice) DeactivateOnu(context.Context, *openolt.Onu) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 478 | oltLogger.Error("DeactivateOnu not implemented") |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 479 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 480 | } |
| 481 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 482 | func (o OltDevice) DeleteOnu(context.Context, *openolt.Onu) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 483 | oltLogger.Error("DeleteOnu not implemented") |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 484 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 485 | } |
| 486 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 487 | func (o OltDevice) DisableOlt(context.Context, *openolt.Empty) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 488 | // NOTE when we disable the OLT should we disable NNI, PONs and ONUs altogether? |
| 489 | olt_msg := Message{ |
| 490 | Type: OltIndication, |
| 491 | Data: OltIndicationMessage{ |
| 492 | OperState: DOWN, |
| 493 | }, |
| 494 | } |
| 495 | o.channel <- olt_msg |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 496 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 497 | } |
| 498 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 499 | func (o OltDevice) DisablePonIf(context.Context, *openolt.Interface) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 500 | oltLogger.Error("DisablePonIf not implemented") |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 501 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 502 | } |
| 503 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 504 | func (o OltDevice) EnableIndication(_ *openolt.Empty, stream openolt.Openolt_EnableIndicationServer) error { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 505 | oltLogger.WithField("oltId", o.ID).Info("OLT receives EnableIndication call from VOLTHA") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 506 | o.Enable(stream) |
| 507 | return nil |
| 508 | } |
| 509 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 510 | func (o OltDevice) EnablePonIf(context.Context, *openolt.Interface) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 511 | oltLogger.Error("EnablePonIf not implemented") |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 512 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 513 | } |
| 514 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 515 | func (o OltDevice) FlowAdd(ctx context.Context, flow *openolt.Flow) (*openolt.Empty, error) { |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 516 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 517 | "IntfId": flow.AccessIntfId, |
| 518 | "OnuId": flow.OnuId, |
| 519 | "EthType": fmt.Sprintf("%x", flow.Classifier.EthType), |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 520 | "InnerVlan": flow.Classifier.IVid, |
| 521 | "OuterVlan": flow.Classifier.OVid, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 522 | "FlowType": flow.FlowType, |
| 523 | "FlowId": flow.FlowId, |
| 524 | "UniID": flow.UniId, |
| 525 | "PortNo": flow.PortNo, |
| 526 | }).Tracef("OLT receives Flow") |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 527 | // TODO optionally store flows somewhere |
| 528 | |
| 529 | if flow.AccessIntfId == -1 { |
| 530 | oltLogger.WithFields(log.Fields{ |
| 531 | "FlowId": flow.FlowId, |
| 532 | }).Debugf("This is an OLT flow") |
| 533 | } else { |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame^] | 534 | pon, err := o.getPonById(uint32(flow.AccessIntfId)) |
| 535 | if err != nil { |
| 536 | oltLogger.WithFields(log.Fields{ |
| 537 | "OnuId": flow.OnuId, |
| 538 | "IntfId": flow.AccessIntfId, |
| 539 | "err": err, |
| 540 | }).Error("Can't find PonPort") |
| 541 | } |
| 542 | onu, err := pon.getOnuById(uint32(flow.OnuId)) |
| 543 | if err != nil { |
| 544 | oltLogger.WithFields(log.Fields{ |
| 545 | "OnuId": flow.OnuId, |
| 546 | "IntfId": flow.AccessIntfId, |
| 547 | "err": err, |
| 548 | }).Error("Can't find Onu") |
| 549 | } |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 550 | |
| 551 | msg := Message{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 552 | Type: FlowUpdate, |
| 553 | Data: OnuFlowUpdateMessage{ |
| 554 | PonPortID: pon.ID, |
| 555 | OnuID: onu.ID, |
| 556 | Flow: flow, |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 557 | }, |
| 558 | } |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 559 | onu.Channel <- msg |
Matteo Scandolo | 3bc7374 | 2019-08-20 14:04:04 -0700 | [diff] [blame] | 560 | } |
| 561 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 562 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 563 | } |
| 564 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 565 | func (o OltDevice) FlowRemove(context.Context, *openolt.Flow) (*openolt.Empty, error) { |
| 566 | oltLogger.Tracef("received FlowRemove") |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 567 | // TODO store flows somewhere |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 568 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 569 | } |
| 570 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 571 | func (o OltDevice) HeartbeatCheck(context.Context, *openolt.Empty) (*openolt.Heartbeat, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 572 | oltLogger.Error("HeartbeatCheck not implemented") |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 573 | return new(openolt.Heartbeat), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 574 | } |
| 575 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 576 | func (o OltDevice) GetDeviceInfo(context.Context, *openolt.Empty) (*openolt.DeviceInfo, error) { |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 577 | |
Matteo Scandolo | da9cbe2 | 2019-08-19 16:05:10 -0700 | [diff] [blame] | 578 | oltLogger.WithFields(log.Fields{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 579 | "oltId": o.ID, |
Matteo Scandolo | da9cbe2 | 2019-08-19 16:05:10 -0700 | [diff] [blame] | 580 | "PonPorts": o.NumPon, |
| 581 | }).Info("OLT receives GetDeviceInfo call from VOLTHA") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 582 | devinfo := new(openolt.DeviceInfo) |
| 583 | devinfo.Vendor = "BBSim" |
| 584 | devinfo.Model = "asfvolt16" |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 585 | devinfo.HardwareVersion = "emulated" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 586 | devinfo.FirmwareVersion = "" |
| 587 | devinfo.Technology = "xgspon" |
Matteo Scandolo | da9cbe2 | 2019-08-19 16:05:10 -0700 | [diff] [blame] | 588 | devinfo.PonPorts = uint32(o.NumPon) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 589 | devinfo.OnuIdStart = 1 |
| 590 | devinfo.OnuIdEnd = 255 |
| 591 | devinfo.AllocIdStart = 1024 |
| 592 | devinfo.AllocIdEnd = 16383 |
| 593 | devinfo.GemportIdStart = 1024 |
| 594 | devinfo.GemportIdEnd = 65535 |
| 595 | devinfo.FlowIdStart = 1 |
| 596 | devinfo.FlowIdEnd = 16383 |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 597 | devinfo.DeviceSerialNumber = o.SerialNumber |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 598 | |
| 599 | return devinfo, nil |
| 600 | } |
| 601 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 602 | 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] | 603 | pon, _ := o.getPonById(omci_msg.IntfId) |
| 604 | onu, _ := pon.getOnuById(omci_msg.OnuId) |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 605 | oltLogger.WithFields(log.Fields{ |
| 606 | "IntfId": onu.PonPortID, |
| 607 | "OnuId": onu.ID, |
| 608 | "OnuSn": onu.Sn(), |
| 609 | }).Tracef("Received OmciMsgOut") |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 610 | msg := Message{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 611 | Type: OMCI, |
| 612 | Data: OmciMessage{ |
| 613 | OnuSN: onu.SerialNumber, |
| 614 | OnuID: onu.ID, |
| 615 | omciMsg: omci_msg, |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 616 | }, |
| 617 | } |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 618 | onu.Channel <- msg |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 619 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 620 | } |
| 621 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 622 | func (o OltDevice) OnuPacketOut(ctx context.Context, onuPkt *openolt.OnuPacket) (*openolt.Empty, error) { |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame^] | 623 | pon, err := o.getPonById(onuPkt.IntfId) |
| 624 | if err != nil { |
| 625 | oltLogger.WithFields(log.Fields{ |
| 626 | "OnuId": onuPkt.OnuId, |
| 627 | "IntfId": onuPkt.IntfId, |
| 628 | "err": err, |
| 629 | }).Error("Can't find PonPort") |
| 630 | } |
| 631 | onu, err := pon.getOnuById(onuPkt.OnuId) |
| 632 | if err != nil { |
| 633 | oltLogger.WithFields(log.Fields{ |
| 634 | "OnuId": onuPkt.OnuId, |
| 635 | "IntfId": onuPkt.IntfId, |
| 636 | "err": err, |
| 637 | }).Error("Can't find Onu") |
| 638 | } |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 639 | |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 640 | oltLogger.WithFields(log.Fields{ |
| 641 | "IntfId": onu.PonPortID, |
| 642 | "OnuId": onu.ID, |
| 643 | "OnuSn": onu.Sn(), |
| 644 | }).Tracef("Received OnuPacketOut") |
| 645 | |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 646 | rawpkt := gopacket.NewPacket(onuPkt.Pkt, layers.LayerTypeEthernet, gopacket.Default) |
| 647 | |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 648 | msg := Message{ |
| 649 | Type: OnuPacketOut, |
| 650 | Data: OnuPacketOutMessage{ |
| 651 | IntfId: onuPkt.IntfId, |
| 652 | OnuId: onuPkt.OnuId, |
| 653 | Packet: rawpkt, |
| 654 | }, |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 655 | } |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 656 | onu.Channel <- msg |
| 657 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 658 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 659 | } |
| 660 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 661 | func (o OltDevice) Reboot(context.Context, *openolt.Empty) (*openolt.Empty, error) { |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 662 | oltLogger.Info("Shutting Down") |
| 663 | close(*o.oltDoneChannel) |
| 664 | close(*o.apiDoneChannel) |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 665 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | func (o OltDevice) ReenableOlt(context.Context, *openolt.Empty) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 669 | oltLogger.Error("ReenableOlt not implemented") |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 670 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | func (o OltDevice) UplinkPacketOut(context context.Context, packet *openolt.UplinkPacket) (*openolt.Empty, error) { |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 674 | pkt := gopacket.NewPacket(packet.Pkt, layers.LayerTypeEthernet, gopacket.Default) |
| 675 | |
| 676 | sendNniPacket(pkt) |
| 677 | // NOTE should we return an error if sendNniPakcet fails? |
| 678 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 679 | } |
| 680 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 681 | func (o OltDevice) CollectStatistics(context.Context, *openolt.Empty) (*openolt.Empty, error) { |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 682 | oltLogger.Error("CollectStatistics not implemented") |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 683 | return new(openolt.Empty), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 684 | } |
| 685 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 686 | 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] | 687 | oltLogger.Error("GetOnuInfo not implemented") |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 688 | return new(openolt.OnuIndication), nil |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | 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] | 692 | oltLogger.Error("GetPonIf not implemented") |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 693 | return new(openolt.IntfIndication), nil |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | func (s OltDevice) CreateTrafficQueues(context.Context, *tech_profile.TrafficQueues) (*openolt.Empty, error) { |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 697 | oltLogger.Info("received CreateTrafficQueues") |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 698 | return new(openolt.Empty), nil |
| 699 | } |
| 700 | |
| 701 | func (s OltDevice) RemoveTrafficQueues(context.Context, *tech_profile.TrafficQueues) (*openolt.Empty, error) { |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 702 | oltLogger.Info("received RemoveTrafficQueues") |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 703 | return new(openolt.Empty), nil |
| 704 | } |
| 705 | |
| 706 | func (s OltDevice) CreateTrafficSchedulers(context.Context, *tech_profile.TrafficSchedulers) (*openolt.Empty, error) { |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 707 | oltLogger.Info("received CreateTrafficSchedulers") |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 708 | return new(openolt.Empty), nil |
| 709 | } |
| 710 | |
| 711 | func (s OltDevice) RemoveTrafficSchedulers(context.Context, *tech_profile.TrafficSchedulers) (*openolt.Empty, error) { |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 712 | oltLogger.Info("received RemoveTrafficSchedulers") |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 713 | return new(openolt.Empty), nil |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 714 | } |