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