blob: a5bc3e5167510e99be44cf16bd203c2cd75a860a [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")
48 return new(openolt.DeviceInfo), nil
49}
50
51func (s *Server) ActivateOnu(c context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
52 log.Printf("OLT receives ActivateONU()\n")
53 result := device.ValidateONU(*onu, s.Onumap)
54
55 if result == true {
56 matched, error := s.getOnuBySN(onu.SerialNumber)
57 if error != nil {
58 log.Fatalf("%s\n", error)
59 }
60 onuid := onu.OnuId
61 matched.OnuID = onuid
62 matched.InternalState = device.ONU_ACTIVATED
63 log.Printf("ONU IntfID: %d OnuID: %d activated succesufully.\n", onu.IntfId, onu.OnuId)
64 }
65 return new(openolt.Empty), nil
66}
67
68func (s *Server) DeactivateOnu(c context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
69 log.Printf("OLT receives DeactivateONU()\n")
70 return new(openolt.Empty), nil
71}
72
73func (s *Server) DeleteOnu(c context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
74 log.Printf("OLT receives DeleteONU()\n")
75 return new(openolt.Empty), nil
76}
77
78func (s *Server) OmciMsgOut(c context.Context, msg *openolt.OmciMsg) (*openolt.Empty, error) {
79 log.Printf("OLT %d receives OmciMsgOut to IF %v (ONU-ID: %v) pkt:%x.\n", s.Olt.ID, msg.IntfId, msg.OnuId, msg.Pkt)
80 //s.olt.Queue = append(s.olt.Queue, *msg)
81 return new(openolt.Empty), nil
82}
83
84func (s *Server) OnuPacketOut(c context.Context, packet *openolt.OnuPacket) (*openolt.Empty, error) {
85 log.Printf("OLT %d receives OnuPacketOut () to IF-ID:%d ONU-ID %d.\n", s.Olt.ID, packet.IntfId, packet.OnuId)
86 onuid := packet.OnuId
87 intfid := packet.IntfId
88 rawpkt := gopacket.NewPacket(packet.Pkt, layers.LayerTypeEthernet, gopacket.Default)
89 if err := s.onuPacketOut(intfid, onuid, rawpkt); err != nil {
90 return new(openolt.Empty), err
91 }
92 return new(openolt.Empty), nil
93}
94
95func (s *Server) UplinkPacketOut(c context.Context, packet *openolt.UplinkPacket) (*openolt.Empty, error) {
96 log.Printf("OLT %d receives UplinkPacketOut().\n", s.Olt.ID)
97 rawpkt := gopacket.NewPacket(packet.Pkt, layers.LayerTypeEthernet, gopacket.Default)
98 if err := s.uplinkPacketOut(rawpkt); err != nil {
99 return new(openolt.Empty), err
100 }
101 return new(openolt.Empty), nil
102}
103
104func (s *Server) FlowAdd(c context.Context, flow *openolt.Flow) (*openolt.Empty, error) {
105 log.Printf("OLT %d receives FlowAdd().\n", s.Olt.ID)
106 return new(openolt.Empty), nil
107}
108
109func (s *Server) FlowRemove(c context.Context, flow *openolt.Flow) (*openolt.Empty, error) {
110 log.Printf("OLT %d receives FlowRemove().\n", s.Olt.ID)
111 return new(openolt.Empty), nil
112}
113
114func (s *Server) HeartbeatCheck(c context.Context, empty *openolt.Empty) (*openolt.Heartbeat, error) {
115 log.Printf("OLT %d receives HeartbeatCheck().\n", s.Olt.ID)
116 signature := new(openolt.Heartbeat)
117 signature.HeartbeatSignature = s.Olt.HeartbeatSignature
118 return signature, nil
119}
120
121func (s *Server) EnablePonIf(c context.Context, intf *openolt.Interface) (*openolt.Empty, error) {
122 log.Printf("OLT %d receives EnablePonIf().\n", s.Olt.ID)
123 return new(openolt.Empty), nil
124}
125
126func (s *Server) DisablePonIf(c context.Context, intf *openolt.Interface) (*openolt.Empty, error) {
127 log.Printf("OLT %d receives DisablePonIf().\n", s.Olt.ID)
128 return new(openolt.Empty), nil
129}
130
131func (s *Server) Reboot(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) {
132 log.Printf("OLT %d receives Reboot ().\n", s.Olt.ID)
133 return new(openolt.Empty), nil
134}
135
136func (s *Server) EnableIndication(empty *openolt.Empty, stream openolt.Openolt_EnableIndicationServer) error {
137 defer func() {
138 s.gRPCserver.Stop()
139 }()
140 log.Printf("OLT receives EnableInd.\n")
141 if err := s.activateOLT(stream); err != nil {
142 log.Printf("Failed to activate OLT: %v\n", err)
143 return err
144 }
145 log.Println("Core server down.")
146 return nil
147}
148
149func CreateGrpcServer(oltid uint32, npon uint32, nonus uint32, addrport string) (l net.Listener, g *grpc.Server, e error) {
150 log.Printf("Listening %s ...", addrport)
151 g = grpc.NewServer()
152 l, e = net.Listen("tcp", addrport)
153 return
154}