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