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 | "gerrit.opencord.org/voltha-bbsim/common" |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 21 | "gerrit.opencord.org/voltha-bbsim/device" |
| 22 | "gerrit.opencord.org/voltha-bbsim/protos" |
| 23 | "github.com/google/gopacket" |
| 24 | "github.com/google/gopacket/layers" |
| 25 | "golang.org/x/net/context" |
| 26 | "google.golang.org/grpc" |
| 27 | "log" |
| 28 | "net" |
| 29 | ) |
| 30 | |
| 31 | // gRPC Service |
| 32 | func (s *Server) DisableOlt(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 33 | logger.Info("OLT receives DisableOLT()\n") |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 34 | if s.EnableServer != nil { |
| 35 | if err := sendOltIndDown(*s.EnableServer); err != nil { |
| 36 | return new(openolt.Empty), err |
| 37 | } |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 38 | logger.Info("Successfuly sent OLT DOWN indication") |
Keita NISHIMOTO | 9c6f6f1 | 2018-10-18 04:56:34 +0900 | [diff] [blame] | 39 | } |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 40 | return new(openolt.Empty), nil |
| 41 | } |
| 42 | |
| 43 | func (s *Server) ReenableOlt(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 44 | logger.Info("OLT receives Reenable()\n") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 45 | return new(openolt.Empty), nil |
| 46 | } |
| 47 | |
| 48 | func (s *Server) CollectStatistics(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 49 | logger.Info("OLT receives CollectStatistics()\n") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 50 | return new(openolt.Empty), nil |
| 51 | } |
| 52 | |
| 53 | func (s *Server) GetDeviceInfo(c context.Context, empty *openolt.Empty) (*openolt.DeviceInfo, error) { |
Shad Ansari | 010c194 | 2018-11-08 09:32:24 -0800 | [diff] [blame^] | 54 | logger.Info("OLT receives GetDeviceInfo()\n") |
| 55 | devinfo := new(openolt.DeviceInfo) |
| 56 | devinfo.Vendor = "EdgeCore" |
| 57 | devinfo.Model = "asfvolt16" |
| 58 | devinfo.HardwareVersion = "" |
| 59 | devinfo.FirmwareVersion = "" |
| 60 | devinfo.Technology = "xgspon" |
| 61 | devinfo.PonPorts = 1 |
| 62 | devinfo.OnuIdStart = 1 |
| 63 | devinfo.OnuIdEnd = 255 |
| 64 | devinfo.AllocIdStart = 1024 |
| 65 | devinfo.AllocIdEnd = 16383 |
| 66 | devinfo.GemportIdStart = 1024 |
| 67 | devinfo.GemportIdEnd = 65535 |
| 68 | devinfo.FlowIdStart = 1 |
| 69 | devinfo.FlowIdEnd = 16383 |
| 70 | |
| 71 | /* |
| 72 | for intf_id := 0; intf_id < 16; intf_id++ { |
| 73 | r := new(openolt.DeviceInfo_DeviceResourceRanges) |
| 74 | |
| 75 | r.IntfIds = append(r.IntfIds, uint32(intf_id)) |
| 76 | |
| 77 | r.Technology = "xgspon" |
| 78 | |
| 79 | p := new(openolt.DeviceInfo_DeviceResourceRanges_Pool) |
| 80 | p.Type = openolt.DeviceInfo_DeviceResourceRanges_Pool_ONU_ID |
| 81 | p.Sharing = openolt.DeviceInfo_DeviceResourceRanges_Pool_DEDICATED_PER_INTF |
| 82 | p.Start = 1 |
| 83 | p.End = 255 |
| 84 | r.Pools = append(r.Pools, p) |
| 85 | |
| 86 | p = new(openolt.DeviceInfo_DeviceResourceRanges_Pool) |
| 87 | p.Type = openolt.DeviceInfo_DeviceResourceRanges_Pool_ALLOC_ID |
| 88 | p.Sharing = openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_SAME_TECH |
| 89 | p.Start = 1024 |
| 90 | p.End = 16383 |
| 91 | r.Pools = append(r.Pools, p) |
| 92 | |
| 93 | p = new(openolt.DeviceInfo_DeviceResourceRanges_Pool) |
| 94 | p.Type = openolt.DeviceInfo_DeviceResourceRanges_Pool_GEMPORT_ID |
| 95 | p.Sharing = openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH |
| 96 | p.Start = 1024 |
| 97 | p.End = 65535 |
| 98 | r.Pools = append(r.Pools, p) |
| 99 | |
| 100 | p = new(openolt.DeviceInfo_DeviceResourceRanges_Pool) |
| 101 | p.Type = openolt.DeviceInfo_DeviceResourceRanges_Pool_FLOW_ID |
| 102 | p.Sharing = openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH |
| 103 | p.Start = 1 |
| 104 | p.End = 16383 |
| 105 | r.Pools = append(r.Pools, p) |
| 106 | |
| 107 | devinfo.Ranges = append(devinfo.Ranges, r) |
| 108 | } |
| 109 | */ |
| 110 | |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 111 | return devinfo, nil |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | func (s *Server) ActivateOnu(c context.Context, onu *openolt.Onu) (*openolt.Empty, error) { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 115 | logger.Info("OLT receives ActivateONU()\n") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 116 | result := device.ValidateONU(*onu, s.Onumap) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 117 | if result == true { |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 118 | matched, error := getOnuBySN(s.Onumap, onu.SerialNumber) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 119 | if error != nil { |
| 120 | log.Fatalf("%s\n", error) |
| 121 | } |
| 122 | onuid := onu.OnuId |
| 123 | matched.OnuID = onuid |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 124 | matched.UpdateIntStatus(device.ONU_ACTIVATED) |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 125 | logger.Info("ONU IntfID: %d OnuID: %d activated succesufully.\n", onu.IntfId, onu.OnuId) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 126 | } |
| 127 | return new(openolt.Empty), nil |
| 128 | } |
| 129 | |
| 130 | func (s *Server) DeactivateOnu(c context.Context, onu *openolt.Onu) (*openolt.Empty, error) { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 131 | logger.Info("OLT receives DeactivateONU()\n") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 132 | return new(openolt.Empty), nil |
| 133 | } |
| 134 | |
| 135 | func (s *Server) DeleteOnu(c context.Context, onu *openolt.Onu) (*openolt.Empty, error) { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 136 | logger.Info("OLT receives DeleteONU()\n") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 137 | return new(openolt.Empty), nil |
| 138 | } |
| 139 | |
| 140 | func (s *Server) OmciMsgOut(c context.Context, msg *openolt.OmciMsg) (*openolt.Empty, error) { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 141 | logger.Info("OLT %d receives OmciMsgOut to IF %v (ONU-ID: %v) pkt:%x.\n", s.Olt.ID, msg.IntfId, msg.OnuId, msg.Pkt) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 142 | //s.olt.Queue = append(s.olt.Queue, *msg) |
| 143 | return new(openolt.Empty), nil |
| 144 | } |
| 145 | |
| 146 | func (s *Server) OnuPacketOut(c context.Context, packet *openolt.OnuPacket) (*openolt.Empty, error) { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 147 | logger.Info("OLT %d receives OnuPacketOut () to IF-ID:%d ONU-ID %d.\n", s.Olt.ID, packet.IntfId, packet.OnuId) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 148 | onuid := packet.OnuId |
| 149 | intfid := packet.IntfId |
| 150 | rawpkt := gopacket.NewPacket(packet.Pkt, layers.LayerTypeEthernet, gopacket.Default) |
| 151 | if err := s.onuPacketOut(intfid, onuid, rawpkt); err != nil { |
| 152 | return new(openolt.Empty), err |
| 153 | } |
| 154 | return new(openolt.Empty), nil |
| 155 | } |
| 156 | |
| 157 | func (s *Server) UplinkPacketOut(c context.Context, packet *openolt.UplinkPacket) (*openolt.Empty, error) { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 158 | logger.Info("OLT %d receives UplinkPacketOut().\n", s.Olt.ID) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 159 | rawpkt := gopacket.NewPacket(packet.Pkt, layers.LayerTypeEthernet, gopacket.Default) |
| 160 | if err := s.uplinkPacketOut(rawpkt); err != nil { |
| 161 | return new(openolt.Empty), err |
| 162 | } |
| 163 | return new(openolt.Empty), nil |
| 164 | } |
| 165 | |
| 166 | func (s *Server) FlowAdd(c context.Context, flow *openolt.Flow) (*openolt.Empty, error) { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 167 | logger.Info("OLT %d receives FlowAdd().\n", s.Olt.ID) |
| 168 | logger.Debug("Flow's ONU-ID: %d, CTAG: %d\n", flow.OnuId, flow.Action.IVid) |
Keita NISHIMOTO | b841749 | 2018-10-19 17:37:38 +0900 | [diff] [blame] | 169 | //onuid := uint32(flow.OnuId) |
| 170 | //ctag := flow.Action.IVid |
| 171 | //s.CtagMap[onuid] = ctag |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 172 | return new(openolt.Empty), nil |
| 173 | } |
| 174 | |
| 175 | func (s *Server) FlowRemove(c context.Context, flow *openolt.Flow) (*openolt.Empty, error) { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 176 | logger.Info("OLT %d receives FlowRemove().\n", s.Olt.ID) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 177 | return new(openolt.Empty), nil |
| 178 | } |
| 179 | |
| 180 | func (s *Server) HeartbeatCheck(c context.Context, empty *openolt.Empty) (*openolt.Heartbeat, error) { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 181 | logger.Info("OLT %d receives HeartbeatCheck().\n", s.Olt.ID) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 182 | signature := new(openolt.Heartbeat) |
| 183 | signature.HeartbeatSignature = s.Olt.HeartbeatSignature |
| 184 | return signature, nil |
| 185 | } |
| 186 | |
| 187 | func (s *Server) EnablePonIf(c context.Context, intf *openolt.Interface) (*openolt.Empty, error) { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 188 | logger.Info("OLT %d receives EnablePonIf().\n", s.Olt.ID) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 189 | return new(openolt.Empty), nil |
| 190 | } |
| 191 | |
| 192 | func (s *Server) DisablePonIf(c context.Context, intf *openolt.Interface) (*openolt.Empty, error) { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 193 | logger.Info("OLT %d receives DisablePonIf().\n", s.Olt.ID) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 194 | return new(openolt.Empty), nil |
| 195 | } |
| 196 | |
| 197 | func (s *Server) Reboot(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 198 | logger.Info("OLT %d receives Reboot ().\n", s.Olt.ID) |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 199 | // Initialize OLT & Env |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 200 | logger.Debug("Initialized by Reboot") |
| 201 | s.Disable() |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 202 | return new(openolt.Empty), nil |
| 203 | } |
| 204 | |
| 205 | func (s *Server) EnableIndication(empty *openolt.Empty, stream openolt.Openolt_EnableIndicationServer) error { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 206 | logger.Info("OLT receives EnableInd.\n") |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 207 | defer func() { |
| 208 | logger.Debug("grpc EnableIndication Done") |
| 209 | }() |
| 210 | if err := s.Enable(&stream); err != nil { |
| 211 | logger.Error("Failed to Enable Core: %v\n", err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 212 | return err |
| 213 | } |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 214 | return nil |
| 215 | } |
| 216 | |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 217 | func NewGrpcServer(addrport string) (l net.Listener, g *grpc.Server, e error) { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 218 | logger.Info("Listening %s ...", addrport) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 219 | g = grpc.NewServer() |
| 220 | l, e = net.Listen("tcp", addrport) |
| 221 | return |
| 222 | } |