blob: 41da7f08107de39bafc111baffe19693ccc9ba22 [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) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +090054 logger.Info("OLT receives GetDeviceInfo()\n")
Keita NISHIMOTOca4da5f2018-10-15 22:48:52 +090055 devinfo := new(openolt.DeviceInfo)
56 devinfo.Vendor = "CORD"
57 devinfo.OnuIdStart = 0
58 devinfo.OnuIdEnd = 3
59 devinfo.PonPorts = 4
60 return devinfo, nil
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090061}
62
63func (s *Server) ActivateOnu(c context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +090064 logger.Info("OLT receives ActivateONU()\n")
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090065 result := device.ValidateONU(*onu, s.Onumap)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090066 if result == true {
Keita NISHIMOTO9708e042018-10-27 09:24:44 +090067 matched, error := getOnuBySN(s.Onumap, onu.SerialNumber)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090068 if error != nil {
69 log.Fatalf("%s\n", error)
70 }
71 onuid := onu.OnuId
72 matched.OnuID = onuid
Keita NISHIMOTOb8417492018-10-19 17:37:38 +090073 matched.UpdateIntStatus(device.ONU_ACTIVATED)
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +090074 logger.Info("ONU IntfID: %d OnuID: %d activated succesufully.\n", onu.IntfId, onu.OnuId)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090075 }
76 return new(openolt.Empty), nil
77}
78
79func (s *Server) DeactivateOnu(c context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +090080 logger.Info("OLT receives DeactivateONU()\n")
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090081 return new(openolt.Empty), nil
82}
83
84func (s *Server) DeleteOnu(c context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +090085 logger.Info("OLT receives DeleteONU()\n")
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090086 return new(openolt.Empty), nil
87}
88
89func (s *Server) OmciMsgOut(c context.Context, msg *openolt.OmciMsg) (*openolt.Empty, error) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +090090 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 +090091 //s.olt.Queue = append(s.olt.Queue, *msg)
92 return new(openolt.Empty), nil
93}
94
95func (s *Server) OnuPacketOut(c context.Context, packet *openolt.OnuPacket) (*openolt.Empty, error) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +090096 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 +090097 onuid := packet.OnuId
98 intfid := packet.IntfId
99 rawpkt := gopacket.NewPacket(packet.Pkt, layers.LayerTypeEthernet, gopacket.Default)
100 if err := s.onuPacketOut(intfid, onuid, rawpkt); err != nil {
101 return new(openolt.Empty), err
102 }
103 return new(openolt.Empty), nil
104}
105
106func (s *Server) UplinkPacketOut(c context.Context, packet *openolt.UplinkPacket) (*openolt.Empty, error) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +0900107 logger.Info("OLT %d receives UplinkPacketOut().\n", s.Olt.ID)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900108 rawpkt := gopacket.NewPacket(packet.Pkt, layers.LayerTypeEthernet, gopacket.Default)
109 if err := s.uplinkPacketOut(rawpkt); err != nil {
110 return new(openolt.Empty), err
111 }
112 return new(openolt.Empty), nil
113}
114
115func (s *Server) FlowAdd(c context.Context, flow *openolt.Flow) (*openolt.Empty, error) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +0900116 logger.Info("OLT %d receives FlowAdd().\n", s.Olt.ID)
117 logger.Debug("Flow's ONU-ID: %d, CTAG: %d\n", flow.OnuId, flow.Action.IVid)
Keita NISHIMOTOb8417492018-10-19 17:37:38 +0900118 //onuid := uint32(flow.OnuId)
119 //ctag := flow.Action.IVid
120 //s.CtagMap[onuid] = ctag
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900121 return new(openolt.Empty), nil
122}
123
124func (s *Server) FlowRemove(c context.Context, flow *openolt.Flow) (*openolt.Empty, error) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +0900125 logger.Info("OLT %d receives FlowRemove().\n", s.Olt.ID)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900126 return new(openolt.Empty), nil
127}
128
129func (s *Server) HeartbeatCheck(c context.Context, empty *openolt.Empty) (*openolt.Heartbeat, error) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +0900130 logger.Info("OLT %d receives HeartbeatCheck().\n", s.Olt.ID)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900131 signature := new(openolt.Heartbeat)
132 signature.HeartbeatSignature = s.Olt.HeartbeatSignature
133 return signature, nil
134}
135
136func (s *Server) EnablePonIf(c context.Context, intf *openolt.Interface) (*openolt.Empty, error) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +0900137 logger.Info("OLT %d receives EnablePonIf().\n", s.Olt.ID)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900138 return new(openolt.Empty), nil
139}
140
141func (s *Server) DisablePonIf(c context.Context, intf *openolt.Interface) (*openolt.Empty, error) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +0900142 logger.Info("OLT %d receives DisablePonIf().\n", s.Olt.ID)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900143 return new(openolt.Empty), nil
144}
145
146func (s *Server) Reboot(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +0900147 logger.Info("OLT %d receives Reboot ().\n", s.Olt.ID)
Keita NISHIMOTOca4da5f2018-10-15 22:48:52 +0900148 // Initialize OLT & Env
Keita NISHIMOTO9708e042018-10-27 09:24:44 +0900149 logger.Debug("Initialized by Reboot")
150 s.Disable()
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900151 return new(openolt.Empty), nil
152}
153
154func (s *Server) EnableIndication(empty *openolt.Empty, stream openolt.Openolt_EnableIndicationServer) error {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +0900155 logger.Info("OLT receives EnableInd.\n")
Keita NISHIMOTO9708e042018-10-27 09:24:44 +0900156 defer func() {
157 logger.Debug("grpc EnableIndication Done")
158 }()
159 if err := s.Enable(&stream); err != nil {
160 logger.Error("Failed to Enable Core: %v\n", err)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900161 return err
162 }
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900163 return nil
164}
165
Keita NISHIMOTO9708e042018-10-27 09:24:44 +0900166func NewGrpcServer(addrport string) (l net.Listener, g *grpc.Server, e error) {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +0900167 logger.Info("Listening %s ...", addrport)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900168 g = grpc.NewServer()
169 l, e = net.Listen("tcp", addrport)
170 return
171}