blob: e1866b8e1ea82495e79477e18bcd78116ca33897 [file] [log] [blame]
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +09001/*
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
17package core
18
19import (
Keita NISHIMOTO9708e042018-10-27 09:24:44 +090020 "gerrit.opencord.org/voltha-bbsim/common"
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090021 "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
32func (s *Server) DisableOlt(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +090033 logger.Info("OLT receives DisableOLT()\n")
Keita NISHIMOTOb8417492018-10-19 17:37:38 +090034 if s.EnableServer != nil {
35 if err := sendOltIndDown(*s.EnableServer); err != nil {
36 return new(openolt.Empty), err
37 }
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +090038 logger.Info("Successfuly sent OLT DOWN indication")
Keita NISHIMOTO9c6f6f12018-10-18 04:56:34 +090039 }
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090040 return new(openolt.Empty), nil
41}
42
43func (s *Server) ReenableOlt(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +090044 logger.Info("OLT receives Reenable()\n")
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090045 return new(openolt.Empty), nil
46}
47
48func (s *Server) CollectStatistics(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +090049 logger.Info("OLT receives CollectStatistics()\n")
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090050 return new(openolt.Empty), nil
51}
52
53func (s *Server) GetDeviceInfo(c context.Context, empty *openolt.Empty) (*openolt.DeviceInfo, error) {
Shad Ansari010c1942018-11-08 09:32:24 -080054 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 NISHIMOTOca4da5f2018-10-15 22:48:52 +0900111 return devinfo, nil
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900112}
113
114func (s *Server) ActivateOnu(c context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +0900115 logger.Info("OLT receives ActivateONU()\n")
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900116 result := device.ValidateONU(*onu, s.Onumap)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900117 if result == true {
Keita NISHIMOTO9708e042018-10-27 09:24:44 +0900118 matched, error := getOnuBySN(s.Onumap, onu.SerialNumber)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900119 if error != nil {
120 log.Fatalf("%s\n", error)
121 }
122 onuid := onu.OnuId
123 matched.OnuID = onuid
Keita NISHIMOTOb8417492018-10-19 17:37:38 +0900124 matched.UpdateIntStatus(device.ONU_ACTIVATED)
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +0900125 logger.Info("ONU IntfID: %d OnuID: %d activated succesufully.\n", onu.IntfId, onu.OnuId)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900126 }
127 return new(openolt.Empty), nil
128}
129
130func (s *Server) DeactivateOnu(c context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +0900131 logger.Info("OLT receives DeactivateONU()\n")
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900132 return new(openolt.Empty), nil
133}
134
135func (s *Server) DeleteOnu(c context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +0900136 logger.Info("OLT receives DeleteONU()\n")
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900137 return new(openolt.Empty), nil
138}
139
140func (s *Server) OmciMsgOut(c context.Context, msg *openolt.OmciMsg) (*openolt.Empty, error) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +0900141 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 NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900142 //s.olt.Queue = append(s.olt.Queue, *msg)
143 return new(openolt.Empty), nil
144}
145
146func (s *Server) OnuPacketOut(c context.Context, packet *openolt.OnuPacket) (*openolt.Empty, error) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +0900147 logger.Info("OLT %d receives OnuPacketOut () to IF-ID:%d ONU-ID %d.\n", s.Olt.ID, packet.IntfId, packet.OnuId)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900148 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
157func (s *Server) UplinkPacketOut(c context.Context, packet *openolt.UplinkPacket) (*openolt.Empty, error) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +0900158 logger.Info("OLT %d receives UplinkPacketOut().\n", s.Olt.ID)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900159 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
166func (s *Server) FlowAdd(c context.Context, flow *openolt.Flow) (*openolt.Empty, error) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +0900167 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 NISHIMOTOb8417492018-10-19 17:37:38 +0900169 //onuid := uint32(flow.OnuId)
170 //ctag := flow.Action.IVid
171 //s.CtagMap[onuid] = ctag
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900172 return new(openolt.Empty), nil
173}
174
175func (s *Server) FlowRemove(c context.Context, flow *openolt.Flow) (*openolt.Empty, error) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +0900176 logger.Info("OLT %d receives FlowRemove().\n", s.Olt.ID)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900177 return new(openolt.Empty), nil
178}
179
180func (s *Server) HeartbeatCheck(c context.Context, empty *openolt.Empty) (*openolt.Heartbeat, error) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +0900181 logger.Info("OLT %d receives HeartbeatCheck().\n", s.Olt.ID)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900182 signature := new(openolt.Heartbeat)
183 signature.HeartbeatSignature = s.Olt.HeartbeatSignature
184 return signature, nil
185}
186
187func (s *Server) EnablePonIf(c context.Context, intf *openolt.Interface) (*openolt.Empty, error) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +0900188 logger.Info("OLT %d receives EnablePonIf().\n", s.Olt.ID)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900189 return new(openolt.Empty), nil
190}
191
192func (s *Server) DisablePonIf(c context.Context, intf *openolt.Interface) (*openolt.Empty, error) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +0900193 logger.Info("OLT %d receives DisablePonIf().\n", s.Olt.ID)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900194 return new(openolt.Empty), nil
195}
196
197func (s *Server) Reboot(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +0900198 logger.Info("OLT %d receives Reboot ().\n", s.Olt.ID)
Keita NISHIMOTOca4da5f2018-10-15 22:48:52 +0900199 // Initialize OLT & Env
Keita NISHIMOTO9708e042018-10-27 09:24:44 +0900200 logger.Debug("Initialized by Reboot")
201 s.Disable()
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900202 return new(openolt.Empty), nil
203}
204
205func (s *Server) EnableIndication(empty *openolt.Empty, stream openolt.Openolt_EnableIndicationServer) error {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +0900206 logger.Info("OLT receives EnableInd.\n")
Keita NISHIMOTO9708e042018-10-27 09:24:44 +0900207 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 NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900212 return err
213 }
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900214 return nil
215}
216
Keita NISHIMOTO9708e042018-10-27 09:24:44 +0900217func NewGrpcServer(addrport string) (l net.Listener, g *grpc.Server, e error) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +0900218 logger.Info("Listening %s ...", addrport)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900219 g = grpc.NewServer()
220 l, e = net.Listen("tcp", addrport)
221 return
222}