Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [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 | |
| 17 | package core |
| 18 | |
| 19 | import ( |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 20 | "context" |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 21 | "errors" |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame] | 22 | "strconv" |
| 23 | "sync" |
| 24 | |
| 25 | "gerrit.opencord.org/voltha-bbsim/common/logger" |
| 26 | "gerrit.opencord.org/voltha-bbsim/common/utils" |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 27 | "gerrit.opencord.org/voltha-bbsim/device" |
| 28 | "gerrit.opencord.org/voltha-bbsim/protos" |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 29 | "github.com/google/gopacket" |
| 30 | "github.com/google/gopacket/layers" |
| 31 | "github.com/google/gopacket/pcap" |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame] | 32 | log "github.com/sirupsen/logrus" |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 33 | "google.golang.org/grpc" |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 34 | ) |
| 35 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 36 | const ( |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 37 | UNI_VETH_UP_PFX = "sim_uu" |
| 38 | UNI_VETH_DW_PFX = "sim_ud" |
| 39 | NNI_VETH_UP_PFX = "sim_nu" |
| 40 | NNI_VETH_DW_PFX = "sim_nd" |
| 41 | MAX_ONUS_PER_PON = 64 // This value should be the same with the value in AdapterPlatrorm class |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 42 | ) |
| 43 | |
| 44 | type Server struct { |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 45 | wg *sync.WaitGroup |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 46 | Olt *device.Olt |
| 47 | Onumap map[uint32][]*device.Onu |
| 48 | Ioinfos []*Ioinfo |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 49 | gRPCserver *grpc.Server |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 50 | gRPCAddress string |
| 51 | gRPCPort uint32 |
| 52 | Vethnames []string |
| 53 | IndInterval int |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 54 | Processes []string |
Keita NISHIMOTO | 9c6f6f1 | 2018-10-18 04:56:34 +0900 | [diff] [blame] | 55 | EnableServer *openolt.Openolt_EnableIndicationServer |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 56 | CtagMap map[string]uint32 |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 57 | cancel context.CancelFunc |
| 58 | state coreState |
| 59 | stateChan chan coreState |
Shad Ansari | 70aafb0 | 2018-11-14 22:28:17 -0800 | [diff] [blame] | 60 | omciIn chan OmciMsg |
| 61 | omciOut chan OmciMsg |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | type Packet struct { |
| 65 | Info *Ioinfo |
| 66 | Pkt gopacket.Packet |
| 67 | } |
| 68 | |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 69 | type coreState int |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 70 | |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 71 | const ( |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame] | 72 | INACTIVE = iota // OLT/ONUs are not instantiated |
| 73 | PRE_ACTIVE // Before PacketInDaemon Running |
| 74 | ACTIVE // After PacketInDaemon Running |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 75 | ) |
| 76 | |
| 77 | /* coreState |
| 78 | INACTIVE -> PRE_ACTIVE -> ACTIVE |
| 79 | (ActivateOLT) (Enable) |
| 80 | <- <- |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame] | 81 | */ |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 82 | |
Shad Ansari | 70aafb0 | 2018-11-14 22:28:17 -0800 | [diff] [blame] | 83 | func NewCore(opt *option, omciOut chan OmciMsg, omciIn chan OmciMsg) *Server { |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 84 | // TODO: make it decent |
| 85 | oltid := opt.oltid |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame] | 86 | npon := opt.npon |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 87 | nonus := opt.nonus |
| 88 | s := Server{ |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame] | 89 | Olt: device.NewOlt(oltid, npon, 1), |
| 90 | Onumap: make(map[uint32][]*device.Onu), |
| 91 | Ioinfos: []*Ioinfo{}, |
| 92 | gRPCAddress: opt.address, |
| 93 | gRPCPort: opt.port, |
| 94 | Vethnames: []string{}, |
| 95 | IndInterval: opt.intvl, |
| 96 | Processes: []string{}, |
Shad Ansari | 704c6f2 | 2018-11-13 14:57:53 -0800 | [diff] [blame] | 97 | EnableServer: nil, |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame] | 98 | state: INACTIVE, |
| 99 | stateChan: make(chan coreState, 8), |
Shad Ansari | 70aafb0 | 2018-11-14 22:28:17 -0800 | [diff] [blame] | 100 | omciIn: omciIn, |
| 101 | omciOut: omciOut, |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 102 | } |
| 103 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 104 | nnni := s.Olt.NumNniIntf |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 105 | logger.Info("OLT ID: %d was retrieved.", s.Olt.ID) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 106 | for intfid := nnni; intfid < npon+nnni; intfid++ { |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 107 | s.Onumap[intfid] = device.NewOnus(oltid, intfid, nonus, nnni) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 108 | } |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 109 | |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 110 | //TODO: To be fixed because it is hardcoded |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 111 | s.CtagMap = make(map[string]uint32) |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 112 | for i := 0; i < MAX_ONUS_PER_PON; i++ { |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 113 | oltid := s.Olt.ID |
| 114 | intfid := uint32(1) |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 115 | sn := convB2S(device.NewSN(oltid, intfid, uint32(i))) |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 116 | s.CtagMap[sn] = uint32(900 + i) // This is hard coded for BBWF |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 117 | } |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 118 | return &s |
| 119 | } |
| 120 | |
| 121 | //Blocking |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame] | 122 | func (s *Server) Start() error { |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 123 | s.wg = &sync.WaitGroup{} |
| 124 | logger.Debug("Start() Start") |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame] | 125 | defer func() { |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 126 | close(s.stateChan) |
| 127 | logger.Debug("Start() Done") |
| 128 | }() |
| 129 | addressport := s.gRPCAddress + ":" + strconv.Itoa(int(s.gRPCPort)) |
| 130 | listener, gserver, err := NewGrpcServer(addressport) |
| 131 | if err != nil { |
| 132 | logger.Error("Failed to create gRPC server", err) |
| 133 | return err |
| 134 | } |
| 135 | s.gRPCserver = gserver |
| 136 | openolt.RegisterOpenoltServer(gserver, s) |
| 137 | if err := gserver.Serve(listener); err != nil { |
| 138 | logger.Error("Failed to run gRPC server", err) |
| 139 | return err |
| 140 | } |
| 141 | s.wg.Wait() |
| 142 | return nil |
| 143 | } |
| 144 | |
| 145 | //Non-Blocking |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame] | 146 | func (s *Server) Stop() { |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 147 | logger.Debug("Stop() Start") |
| 148 | defer logger.Debug("Stop() Done") |
| 149 | if s.gRPCserver != nil { |
| 150 | s.gRPCserver.Stop() |
| 151 | logger.Debug("gRPCserver.Stop()") |
| 152 | } |
| 153 | s.StopPktInDaemon() |
| 154 | return |
| 155 | } |
| 156 | |
| 157 | // Blocking |
| 158 | func (s *Server) Enable(sv *openolt.Openolt_EnableIndicationServer) error { |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame] | 159 | defer func() { |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 160 | olt := s.Olt |
| 161 | olt.InitializeStatus() |
| 162 | for intfid, _ := range s.Onumap { |
| 163 | for _, onu := range s.Onumap[intfid] { |
| 164 | onu.InitializeStatus() |
| 165 | } |
| 166 | } |
| 167 | s.updateState(INACTIVE) |
| 168 | logger.Debug("Enable() Done") |
| 169 | }() |
| 170 | logger.Debug("Enable() Start") |
| 171 | s.EnableServer = sv |
| 172 | if err := s.activateOLT(*sv); err != nil { |
| 173 | return err |
| 174 | } |
| 175 | s.updateState(PRE_ACTIVE) |
| 176 | |
| 177 | coreCtx := context.Background() |
| 178 | coreCtx, corecancel := context.WithCancel(coreCtx) |
| 179 | s.cancel = corecancel |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame] | 180 | if err := s.StartPktInDaemon(coreCtx, *sv); err != nil { |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 181 | return err |
| 182 | } |
| 183 | return nil |
| 184 | } |
| 185 | |
| 186 | //Non-Blocking |
| 187 | func (s *Server) Disable() { |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame] | 188 | defer func() { |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 189 | logger.Debug("Disable() Done") |
| 190 | }() |
| 191 | logger.Debug("Disable() Start") |
| 192 | s.StopPktInDaemon() |
| 193 | } |
| 194 | |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame] | 195 | func (s *Server) updateState(state coreState) { |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 196 | s.state = state |
| 197 | s.stateChan <- state |
| 198 | logger.Debug("State updated to:%d", state) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | func (s *Server) activateOLT(stream openolt.Openolt_EnableIndicationServer) error { |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 202 | defer logger.Debug("activateOLT() Done") |
| 203 | logger.Debug("activateOLT() Start") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 204 | // Activate OLT |
| 205 | olt := s.Olt |
Keita NISHIMOTO | 9c6f6f1 | 2018-10-18 04:56:34 +0900 | [diff] [blame] | 206 | if err := sendOltIndUp(stream, olt); err != nil { |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 207 | return err |
| 208 | } |
| 209 | olt.OperState = "up" |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 210 | *olt.InternalState = device.OLT_UP |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 211 | logger.Info("OLT %s sent OltInd.", olt.Name) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 212 | |
| 213 | // OLT sends Interface Indication to Adapter |
| 214 | if err := sendIntfInd(stream, olt); err != nil { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 215 | logger.Error("Fail to sendIntfInd: %v", err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 216 | return err |
| 217 | } |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 218 | logger.Info("OLT %s sent IntfInd.", olt.Name) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 219 | |
| 220 | // OLT sends Operation Indication to Adapter after activating each interface |
| 221 | //time.Sleep(IF_UP_TIME * time.Second) |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 222 | *olt.InternalState = device.PONIF_UP |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 223 | if err := sendOperInd(stream, olt); err != nil { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 224 | logger.Error("Fail to sendOperInd: %v", err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 225 | return err |
| 226 | } |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 227 | logger.Info("OLT %s sent OperInd.", olt.Name) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 228 | |
| 229 | // OLT sends ONU Discover Indication to Adapter after ONU discovery |
| 230 | for intfid, _ := range s.Onumap { |
| 231 | device.UpdateOnusOpStatus(intfid, s.Onumap[intfid], "up") |
| 232 | } |
| 233 | |
| 234 | for intfid, _ := range s.Onumap { |
| 235 | sendOnuDiscInd(stream, s.Onumap[intfid]) |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 236 | logger.Info("OLT id:%d sent ONUDiscInd.", olt.ID) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | // OLT Sends OnuInd after waiting all of those ONUs up |
| 240 | for { |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 241 | if IsAllOnuActive(s.Onumap) { |
| 242 | logger.Debug("All the Onus are Activated.") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 243 | break |
| 244 | } |
| 245 | } |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 246 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 247 | for intfid, _ := range s.Onumap { |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 248 | sendOnuInd(stream, s.Onumap[intfid], s.IndInterval) |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 249 | logger.Info("OLT id:%d sent ONUInd.", olt.ID) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 250 | } |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 251 | return nil |
| 252 | } |
| 253 | |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 254 | // Blocking |
| 255 | func (s *Server) StartPktInDaemon(ctx context.Context, stream openolt.Openolt_EnableIndicationServer) error { |
| 256 | logger.Debug("StartPktInDaemon() Start") |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame] | 257 | defer func() { |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 258 | RemoveVeths(s.Vethnames) |
| 259 | s.Vethnames = []string{} |
| 260 | s.Ioinfos = []*Ioinfo{} |
| 261 | s.wg.Done() |
| 262 | s.updateState(PRE_ACTIVE) |
| 263 | logger.Debug("StartPktInDaemon() Done") |
| 264 | }() |
| 265 | s.wg.Add(1) |
| 266 | ioinfos, veths, err := createIoinfos(s.Olt.ID, s.Vethnames, s.Onumap) |
| 267 | if err != nil { |
Shad Ansari | 6a93ee2 | 2018-11-16 13:26:47 -0800 | [diff] [blame^] | 268 | logger.Error("createIoinfos failed.", err) |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 269 | return err |
| 270 | } |
| 271 | s.Ioinfos = ioinfos |
| 272 | s.Vethnames = veths |
| 273 | logger.Debug("Created vethnames:%v", s.Vethnames) |
| 274 | |
| 275 | parent := ctx |
| 276 | child, cancel := context.WithCancel(parent) |
| 277 | s.cancel = cancel |
| 278 | |
| 279 | if err = s.runPacketInDaemon(child, stream); err != nil { |
Shad Ansari | 6a93ee2 | 2018-11-16 13:26:47 -0800 | [diff] [blame^] | 280 | logger.Error("runPacketInDaemon failed.", err) |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 281 | return err |
| 282 | } |
| 283 | return nil |
| 284 | } |
| 285 | |
| 286 | //Non-Blocking |
| 287 | func (s *Server) StopPktInDaemon() { |
| 288 | if s.cancel != nil { |
| 289 | cancel := s.cancel |
| 290 | cancel() |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | func createIoinfos(oltid uint32, Vethnames []string, onumap map[uint32][]*device.Onu) ([]*Ioinfo, []string, error) { |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 295 | ioinfos := []*Ioinfo{} |
| 296 | var err error |
| 297 | for intfid, _ := range onumap { |
| 298 | for i := 0; i < len(onumap[intfid]); i++ { |
| 299 | var handler *pcap.Handle |
| 300 | onuid := onumap[intfid][i].OnuID |
| 301 | uniup, unidw := makeUniName(oltid, intfid, onuid) |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 302 | if handler, Vethnames, err = setupVethHandler(uniup, unidw, Vethnames); err != nil { |
Shad Ansari | 6a93ee2 | 2018-11-16 13:26:47 -0800 | [diff] [blame^] | 303 | logger.Error("setupVethHandler failed (onuid: %d)", onuid, err) |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 304 | return ioinfos, Vethnames, err |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 305 | } |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 306 | iinfo := Ioinfo{Name: uniup, iotype: "uni", ioloc: "inside", intfid: intfid, onuid: onuid, handler: handler} |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 307 | ioinfos = append(ioinfos, &iinfo) |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 308 | oinfo := Ioinfo{Name: unidw, iotype: "uni", ioloc: "outside", intfid: intfid, onuid: onuid, handler: nil} |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 309 | ioinfos = append(ioinfos, &oinfo) |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | var handler *pcap.Handle |
| 314 | nniup, nnidw := makeNniName(oltid) |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 315 | if handler, Vethnames, err = setupVethHandler(nniup, nnidw, Vethnames); err != nil { |
Shad Ansari | 6a93ee2 | 2018-11-16 13:26:47 -0800 | [diff] [blame^] | 316 | logger.Error("setupVethHandler failed for nni", err) |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 317 | return ioinfos, Vethnames, err |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 318 | } |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 319 | |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 320 | iinfo := Ioinfo{Name: nnidw, iotype: "nni", ioloc: "inside", intfid: 1, handler: handler} |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 321 | ioinfos = append(ioinfos, &iinfo) |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 322 | oinfo := Ioinfo{Name: nniup, iotype: "nni", ioloc: "outside", intfid: 1, handler: nil} |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 323 | ioinfos = append(ioinfos, &oinfo) |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 324 | return ioinfos, Vethnames, nil |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 325 | } |
| 326 | |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 327 | //Blocking |
| 328 | func (s *Server) runPacketInDaemon(ctx context.Context, stream openolt.Openolt_EnableIndicationServer) error { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 329 | logger.Debug("runPacketInDaemon Start") |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 330 | defer logger.Debug("runPacketInDaemon Done") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 331 | unichannel := make(chan Packet, 2048) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 332 | |
| 333 | for intfid, _ := range s.Onumap { |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 334 | for _, onu := range s.Onumap[intfid] { |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 335 | onuid := onu.OnuID |
| 336 | ioinfo, err := s.identifyUniIoinfo("inside", intfid, onuid) |
| 337 | if err != nil { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 338 | utils.LoggerWithOnu(onu).Error("Fail to identifyUniIoinfo (onuid: %d): %v", onuid, err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 339 | return err |
| 340 | } |
| 341 | uhandler := ioinfo.handler |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 342 | go RecvWorker(ioinfo, uhandler, unichannel) |
| 343 | } |
| 344 | } |
| 345 | |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 346 | ioinfo, err := s.IdentifyNniIoinfo("inside") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 347 | if err != nil { |
| 348 | return err |
| 349 | } |
| 350 | nhandler := ioinfo.handler |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 351 | nnichannel := make(chan Packet, 32) |
| 352 | go RecvWorker(ioinfo, nhandler, nnichannel) |
| 353 | |
| 354 | data := &openolt.Indication_PktInd{} |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 355 | s.updateState(ACTIVE) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 356 | for { |
| 357 | select { |
Shad Ansari | 70aafb0 | 2018-11-14 22:28:17 -0800 | [diff] [blame] | 358 | case msg := <-s.omciIn: |
Shad Ansari | ef43627 | 2018-11-14 15:58:20 -0800 | [diff] [blame] | 359 | logger.Debug("OLT %d send omci indication, IF %v (ONU-ID: %v) pkt:%x.", s.Olt.ID, msg.IntfId, msg.OnuId, msg.Pkt) |
| 360 | omci := &openolt.Indication_OmciInd{OmciInd: &openolt.OmciIndication{IntfId: msg.IntfId, OnuId: msg.OnuId, Pkt: msg.Pkt}} |
| 361 | if err := stream.Send(&openolt.Indication{Data: omci}); err != nil { |
| 362 | logger.Error("send omci indication failed.", err) |
| 363 | continue |
| 364 | } |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 365 | case unipkt := <-unichannel: |
Matteo Scandolo | 2a65914 | 2018-11-15 11:23:45 -0800 | [diff] [blame] | 366 | logger.Debug("Received packet from UNI in grpc Server") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 367 | if unipkt.Info == nil || unipkt.Info.iotype != "uni" { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 368 | logger.Debug("WARNING: This packet does not come from UNI ") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 369 | continue |
| 370 | } |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 371 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 372 | intfid := unipkt.Info.intfid |
| 373 | onuid := unipkt.Info.onuid |
| 374 | gemid, _ := getGemPortID(intfid, onuid) |
| 375 | pkt := unipkt.Pkt |
| 376 | layerEth := pkt.Layer(layers.LayerTypeEthernet) |
| 377 | le, _ := layerEth.(*layers.Ethernet) |
| 378 | ethtype := le.EthernetType |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 379 | onu, _ := s.GetOnuByID(onuid) |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 380 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 381 | if ethtype == 0x888e { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 382 | utils.LoggerWithOnu(onu).WithFields(log.Fields{ |
| 383 | "gemId": gemid, |
| 384 | }).Info("Received upstream packet is EAPOL.") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 385 | } else if layerDHCP := pkt.Layer(layers.LayerTypeDHCPv4); layerDHCP != nil { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 386 | utils.LoggerWithOnu(onu).WithFields(log.Fields{ |
| 387 | "gemId": gemid, |
| 388 | }).Info("Received upstream packet is DHCP.") |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 389 | |
| 390 | //C-TAG |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 391 | sn := convB2S(onu.SerialNumber.VendorSpecific) |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 392 | if ctag, ok := s.CtagMap[sn]; ok == true { |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 393 | tagpkt, err := PushVLAN(pkt, uint16(ctag)) |
| 394 | if err != nil { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 395 | utils.LoggerWithOnu(onu).WithFields(log.Fields{ |
| 396 | "gemId": gemid, |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame] | 397 | }).Error("Fail to tag C-tag") |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 398 | } else { |
| 399 | pkt = tagpkt |
| 400 | } |
| 401 | } else { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 402 | utils.LoggerWithOnu(onu).WithFields(log.Fields{ |
| 403 | "gemId": gemid, |
| 404 | "cTagMap": s.CtagMap, |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame] | 405 | }).Error("Could not find onuid in CtagMap", onuid, sn, s.CtagMap) |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 406 | } |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 407 | } else { |
Matteo Scandolo | 2a65914 | 2018-11-15 11:23:45 -0800 | [diff] [blame] | 408 | utils.LoggerWithOnu(onu).WithFields(log.Fields{ |
| 409 | "gemId": gemid, |
| 410 | }).Info("Received upstream packet is of unknow type, skipping.") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 411 | continue |
| 412 | } |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 413 | |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 414 | utils.LoggerWithOnu(onu).Info("sendPktInd - UNI Packet") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 415 | data = &openolt.Indication_PktInd{PktInd: &openolt.PacketIndication{IntfType: "pon", IntfId: intfid, GemportId: gemid, Pkt: pkt.Data()}} |
| 416 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame] | 417 | logger.Error("Fail to send PktInd indication.", err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 418 | return err |
| 419 | } |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 420 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 421 | case nnipkt := <-nnichannel: |
| 422 | if nnipkt.Info == nil || nnipkt.Info.iotype != "nni" { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 423 | logger.Debug("WARNING: This packet does not come from NNI ") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 424 | continue |
| 425 | } |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame] | 426 | onuid := nnipkt.Info.onuid |
Matteo Scandolo | 2a65914 | 2018-11-15 11:23:45 -0800 | [diff] [blame] | 427 | onu, _ := s.GetOnuByID(onuid) |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 428 | |
Matteo Scandolo | 2a65914 | 2018-11-15 11:23:45 -0800 | [diff] [blame] | 429 | utils.LoggerWithOnu(onu).Info("Received packet from NNI in grpc Server.") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 430 | intfid := nnipkt.Info.intfid |
| 431 | pkt := nnipkt.Pkt |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 432 | utils.LoggerWithOnu(onu).Info("sendPktInd - NNI Packet") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 433 | data = &openolt.Indication_PktInd{PktInd: &openolt.PacketIndication{IntfType: "nni", IntfId: intfid, Pkt: pkt.Data()}} |
| 434 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame] | 435 | logger.Error("Fail to send PktInd indication.", err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 436 | return err |
| 437 | } |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 438 | |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 439 | case <-ctx.Done(): |
| 440 | logger.Debug("PacketInDaemon thread receives close ") |
| 441 | close(unichannel) |
| 442 | logger.Debug("Closed unichannel ") |
| 443 | close(nnichannel) |
| 444 | logger.Debug("Closed nnichannel ") |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 445 | return nil |
Keita NISHIMOTO | c864da2 | 2018-10-15 22:41:42 +0900 | [diff] [blame] | 446 | } |
| 447 | } |
Keita NISHIMOTO | c864da2 | 2018-10-15 22:41:42 +0900 | [diff] [blame] | 448 | return nil |
| 449 | } |
| 450 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 451 | func (s *Server) onuPacketOut(intfid uint32, onuid uint32, rawpkt gopacket.Packet) error { |
| 452 | layerEth := rawpkt.Layer(layers.LayerTypeEthernet) |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 453 | onu, _ := s.GetOnuByID(onuid) |
| 454 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 455 | if layerEth != nil { |
| 456 | pkt, _ := layerEth.(*layers.Ethernet) |
| 457 | ethtype := pkt.EthernetType |
| 458 | if ethtype == 0x888e { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 459 | utils.LoggerWithOnu(onu).Info("Received downstream packet is EAPOL.") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 460 | } else if layerDHCP := rawpkt.Layer(layers.LayerTypeDHCPv4); layerDHCP != nil { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 461 | utils.LoggerWithOnu(onu).Info("Received downstream packet is DHCP.") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 462 | rawpkt, _, _ = PopVLAN(rawpkt) |
| 463 | rawpkt, _, _ = PopVLAN(rawpkt) |
| 464 | } else { |
| 465 | return nil |
| 466 | } |
| 467 | ioinfo, err := s.identifyUniIoinfo("inside", intfid, onuid) |
| 468 | if err != nil { |
| 469 | return err |
| 470 | } |
| 471 | handle := ioinfo.handler |
| 472 | SendUni(handle, rawpkt) |
| 473 | return nil |
| 474 | } |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 475 | logger.Info("WARNING: Received packet is not supported") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 476 | return nil |
| 477 | } |
| 478 | |
| 479 | func (s *Server) uplinkPacketOut(rawpkt gopacket.Packet) error { |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 480 | poppkt, _, err := PopVLAN(rawpkt) |
| 481 | poppkt, _, err = PopVLAN(poppkt) |
| 482 | if err != nil { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 483 | logger.Error("%s", err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 484 | return err |
| 485 | } |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 486 | ioinfo, err := s.IdentifyNniIoinfo("inside") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 487 | if err != nil { |
| 488 | return err |
| 489 | } |
| 490 | handle := ioinfo.handler |
| 491 | SendNni(handle, poppkt) |
| 492 | return nil |
| 493 | } |
| 494 | |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 495 | func IsAllOnuActive(onumap map[uint32][]*device.Onu) bool { |
| 496 | for _, onus := range onumap { |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 497 | for _, onu := range onus { |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 498 | if onu.GetIntStatus() != device.ONU_ACTIVATED { |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 499 | return false |
| 500 | } |
| 501 | } |
| 502 | } |
| 503 | return true |
| 504 | } |
| 505 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 506 | func getGemPortID(intfid uint32, onuid uint32) (uint32, error) { |
| 507 | idx := uint32(0) |
| 508 | return 1024 + (((MAX_ONUS_PER_PON*intfid + onuid - 1) * 7) + idx), nil |
| 509 | //return uint32(1032 + 8 * (vid - 1)), nil |
| 510 | } |
| 511 | |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 512 | func getOnuBySN(onumap map[uint32][]*device.Onu, sn *openolt.SerialNumber) (*device.Onu, error) { |
| 513 | for _, onus := range onumap { |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 514 | for _, onu := range onus { |
| 515 | if device.ValidateSN(*sn, *onu.SerialNumber) { |
| 516 | return onu, nil |
| 517 | } |
| 518 | } |
| 519 | } |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 520 | err := errors.New("No mathced SN is found ") |
| 521 | logger.Error("%s", err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 522 | return nil, err |
| 523 | } |
| 524 | |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 525 | func (s *Server) GetOnuByID(onuid uint32) (*device.Onu, error) { |
| 526 | return getOnuByID(s.Onumap, onuid) |
| 527 | } |
| 528 | |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 529 | func getOnuByID(onumap map[uint32][]*device.Onu, onuid uint32) (*device.Onu, error) { |
| 530 | for _, onus := range onumap { |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 531 | for _, onu := range onus { |
| 532 | if onu.OnuID == onuid { |
| 533 | return onu, nil |
| 534 | } |
| 535 | } |
| 536 | } |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 537 | err := errors.New("No matched OnuID is found ") |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 538 | logger.WithFields(log.Fields{ |
| 539 | "onumap": onumap, |
| 540 | "onuid": onuid, |
| 541 | }).Error(err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 542 | return nil, err |
| 543 | } |
| 544 | |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 545 | func convB2S(b []byte) string { |
| 546 | s := "" |
| 547 | for _, i := range b { |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 548 | s = s + strconv.FormatInt(int64(i/16), 16) + strconv.FormatInt(int64(i%16), 16) |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 549 | } |
| 550 | return s |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 551 | } |