blob: e647c9d5bfbfe16fd45c0acf3323e02b49e668a6 [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 (
20 "gerrit.opencord.org/voltha-bbsim/device"
21 "gerrit.opencord.org/voltha-bbsim/protos"
22 "github.com/google/gopacket"
23 "github.com/google/gopacket/layers"
24 "golang.org/x/net/context"
25 "google.golang.org/grpc"
26 "log"
27 "net"
28)
29
30// gRPC Service
31func (s *Server) DisableOlt(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) {
32 log.Printf("OLT receives DisableOLT()\n")
33 return new(openolt.Empty), nil
34}
35
36func (s *Server) ReenableOlt(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) {
37 log.Printf("OLT receives Reenable()\n")
38 return new(openolt.Empty), nil
39}
40
41func (s *Server) CollectStatistics(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) {
42 log.Printf("OLT receives CollectStatistics()\n")
43 return new(openolt.Empty), nil
44}
45
46func (s *Server) GetDeviceInfo(c context.Context, empty *openolt.Empty) (*openolt.DeviceInfo, error) {
47 log.Printf("OLT receives GetDeviceInfo()\n")
Keita NISHIMOTOca4da5f2018-10-15 22:48:52 +090048 devinfo := new(openolt.DeviceInfo)
49 devinfo.Vendor = "CORD"
50 devinfo.OnuIdStart = 0
51 devinfo.OnuIdEnd = 3
52 devinfo.PonPorts = 4
53 return devinfo, nil
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090054}
55
56func (s *Server) ActivateOnu(c context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
57 log.Printf("OLT receives ActivateONU()\n")
58 result := device.ValidateONU(*onu, s.Onumap)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090059 if result == true {
60 matched, error := s.getOnuBySN(onu.SerialNumber)
61 if error != nil {
62 log.Fatalf("%s\n", error)
63 }
64 onuid := onu.OnuId
65 matched.OnuID = onuid
Keita NISHIMOTOca4da5f2018-10-15 22:48:52 +090066 *matched.InternalState = device.ONU_ACTIVATED
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090067 log.Printf("ONU IntfID: %d OnuID: %d activated succesufully.\n", onu.IntfId, onu.OnuId)
68 }
69 return new(openolt.Empty), nil
70}
71
72func (s *Server) DeactivateOnu(c context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
73 log.Printf("OLT receives DeactivateONU()\n")
74 return new(openolt.Empty), nil
75}
76
77func (s *Server) DeleteOnu(c context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
78 log.Printf("OLT receives DeleteONU()\n")
79 return new(openolt.Empty), nil
80}
81
82func (s *Server) OmciMsgOut(c context.Context, msg *openolt.OmciMsg) (*openolt.Empty, error) {
83 log.Printf("OLT %d receives OmciMsgOut to IF %v (ONU-ID: %v) pkt:%x.\n", s.Olt.ID, msg.IntfId, msg.OnuId, msg.Pkt)
84 //s.olt.Queue = append(s.olt.Queue, *msg)
85 return new(openolt.Empty), nil
86}
87
88func (s *Server) OnuPacketOut(c context.Context, packet *openolt.OnuPacket) (*openolt.Empty, error) {
89 log.Printf("OLT %d receives OnuPacketOut () to IF-ID:%d ONU-ID %d.\n", s.Olt.ID, packet.IntfId, packet.OnuId)
90 onuid := packet.OnuId
91 intfid := packet.IntfId
92 rawpkt := gopacket.NewPacket(packet.Pkt, layers.LayerTypeEthernet, gopacket.Default)
93 if err := s.onuPacketOut(intfid, onuid, rawpkt); err != nil {
94 return new(openolt.Empty), err
95 }
96 return new(openolt.Empty), nil
97}
98
99func (s *Server) UplinkPacketOut(c context.Context, packet *openolt.UplinkPacket) (*openolt.Empty, error) {
100 log.Printf("OLT %d receives UplinkPacketOut().\n", s.Olt.ID)
101 rawpkt := gopacket.NewPacket(packet.Pkt, layers.LayerTypeEthernet, gopacket.Default)
102 if err := s.uplinkPacketOut(rawpkt); err != nil {
103 return new(openolt.Empty), err
104 }
105 return new(openolt.Empty), nil
106}
107
108func (s *Server) FlowAdd(c context.Context, flow *openolt.Flow) (*openolt.Empty, error) {
109 log.Printf("OLT %d receives FlowAdd().\n", s.Olt.ID)
110 return new(openolt.Empty), nil
111}
112
113func (s *Server) FlowRemove(c context.Context, flow *openolt.Flow) (*openolt.Empty, error) {
114 log.Printf("OLT %d receives FlowRemove().\n", s.Olt.ID)
115 return new(openolt.Empty), nil
116}
117
118func (s *Server) HeartbeatCheck(c context.Context, empty *openolt.Empty) (*openolt.Heartbeat, error) {
119 log.Printf("OLT %d receives HeartbeatCheck().\n", s.Olt.ID)
120 signature := new(openolt.Heartbeat)
121 signature.HeartbeatSignature = s.Olt.HeartbeatSignature
122 return signature, nil
123}
124
125func (s *Server) EnablePonIf(c context.Context, intf *openolt.Interface) (*openolt.Empty, error) {
126 log.Printf("OLT %d receives EnablePonIf().\n", s.Olt.ID)
127 return new(openolt.Empty), nil
128}
129
130func (s *Server) DisablePonIf(c context.Context, intf *openolt.Interface) (*openolt.Empty, error) {
131 log.Printf("OLT %d receives DisablePonIf().\n", s.Olt.ID)
132 return new(openolt.Empty), nil
133}
134
135func (s *Server) Reboot(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) {
136 log.Printf("OLT %d receives Reboot ().\n", s.Olt.ID)
Keita NISHIMOTOca4da5f2018-10-15 22:48:52 +0900137 log.Printf("pointer@Reboot %p", s)
138 // Initialize OLT & Env
139 if s.TestFlag == true{
140 log.Println("Initialize by Reboot")
141 cleanUpVeths(s.VethEnv)
142 close(s.Endchan)
143 processes := s.Processes
144 log.Println("processes:", processes)
145 killProcesses(processes)
146 s.Initialize()
147 }
148 olt := s.Olt
149 olt.InitializeStatus()
150 for intfid, _ := range s.Onumap{
151 for _, onu := range s.Onumap[intfid] {
152 onu.InitializeStatus()
153 }
154 }
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900155 return new(openolt.Empty), nil
156}
157
158func (s *Server) EnableIndication(empty *openolt.Empty, stream openolt.Openolt_EnableIndicationServer) error {
159 defer func() {
160 s.gRPCserver.Stop()
161 }()
162 log.Printf("OLT receives EnableInd.\n")
163 if err := s.activateOLT(stream); err != nil {
164 log.Printf("Failed to activate OLT: %v\n", err)
165 return err
166 }
167 log.Println("Core server down.")
168 return nil
169}
170
171func CreateGrpcServer(oltid uint32, npon uint32, nonus uint32, addrport string) (l net.Listener, g *grpc.Server, e error) {
172 log.Printf("Listening %s ...", addrport)
173 g = grpc.NewServer()
174 l, e = net.Listen("tcp", addrport)
175 return
176}