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