Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 1 | # |
Shad Ansari | e8cbc6f | 2019-02-14 15:50:54 -0800 | [diff] [blame] | 2 | # Copyright 2019 the original author or authors. |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 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 | # |
Shad Ansari | 548f94d | 2019-04-24 13:42:52 -0700 | [diff] [blame] | 16 | |
Shad Ansari | 94250fc | 2018-07-04 06:52:11 +0000 | [diff] [blame] | 17 | import binascii |
Shad Ansari | 94250fc | 2018-07-04 06:52:11 +0000 | [diff] [blame] | 18 | import structlog |
Shad Ansari | 0601938 | 2019-02-07 22:56:16 -0800 | [diff] [blame] | 19 | import time |
Shad Ansari | 548f94d | 2019-04-24 13:42:52 -0700 | [diff] [blame] | 20 | import subprocess |
Shad Ansari | d1652de | 2019-04-24 10:15:20 -0700 | [diff] [blame] | 21 | import grpc |
Shad Ansari | 0346f0d | 2018-04-26 06:54:09 +0000 | [diff] [blame] | 22 | from scapy.layers.l2 import Ether, Dot1Q |
Shad Ansari | 3cd9bf2 | 2018-07-25 19:29:39 +0000 | [diff] [blame] | 23 | from transitions import Machine |
Shad Ansari | 3fbf1c0 | 2019-04-11 15:12:54 -0700 | [diff] [blame] | 24 | from twisted.internet import reactor |
Shad Ansari | 15928d1 | 2018-04-17 02:42:13 +0000 | [diff] [blame] | 25 | |
Shad Ansari | 548f94d | 2019-04-24 13:42:52 -0700 | [diff] [blame] | 26 | from voltha.registry import registry |
Shad Ansari | d557797 | 2019-02-22 09:35:03 -0800 | [diff] [blame] | 27 | from voltha.protos.device_pb2 import Port |
Shad Ansari | d1652de | 2019-04-24 10:15:20 -0700 | [diff] [blame] | 28 | from voltha.adapters.openolt.protos import openolt_pb2, openolt_pb2_grpc |
Shad Ansari | e8cbc6f | 2019-02-14 15:50:54 -0800 | [diff] [blame] | 29 | from voltha.adapters.openolt.openolt_utils import OpenoltUtils |
Shad Ansari | e969afc | 2019-04-05 15:16:41 -0700 | [diff] [blame] | 30 | from voltha.adapters.openolt.openolt_indications import OpenoltIndications |
Shad Ansari | 42392a7 | 2019-04-09 22:44:18 -0700 | [diff] [blame] | 31 | from voltha.adapters.openolt.openolt_packet import OpenoltPacket |
Shad Ansari | 995ca63 | 2019-04-08 19:43:46 -0700 | [diff] [blame] | 32 | from voltha.adapters.openolt.openolt_kafka_admin import KAdmin |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 33 | |
| 34 | |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 35 | class OpenoltDevice(object): |
Shad Ansari | 94250fc | 2018-07-04 06:52:11 +0000 | [diff] [blame] | 36 | """ |
| 37 | OpenoltDevice state machine: |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 38 | |
Shad Ansari | 94250fc | 2018-07-04 06:52:11 +0000 | [diff] [blame] | 39 | null ----> init ------> connected -----> up -----> down |
| 40 | ^ ^ | ^ | | |
| 41 | | | | | | | |
| 42 | | +-------------+ +---------+ | |
| 43 | | | |
| 44 | +-----------------------------------------+ |
| 45 | """ |
| 46 | # pylint: disable=too-many-instance-attributes |
| 47 | # pylint: disable=R0904 |
| 48 | states = [ |
| 49 | 'state_null', |
| 50 | 'state_init', |
| 51 | 'state_connected', |
| 52 | 'state_up', |
| 53 | 'state_down'] |
| 54 | |
Shad Ansari | 22efe83 | 2018-05-19 05:37:03 +0000 | [diff] [blame] | 55 | transitions = [ |
Shad Ansari | 0e7ad96 | 2018-09-28 01:42:26 +0000 | [diff] [blame] | 56 | {'trigger': 'go_state_init', |
| 57 | 'source': ['state_null', 'state_connected', 'state_down'], |
| 58 | 'dest': 'state_init', |
| 59 | 'before': 'do_state_init', |
| 60 | 'after': 'post_init'}, |
| 61 | {'trigger': 'go_state_connected', |
| 62 | 'source': 'state_init', |
| 63 | 'dest': 'state_connected', |
Shad Ansari | 72462c8 | 2019-04-17 01:36:01 -0700 | [diff] [blame] | 64 | 'before': 'do_state_connected', |
| 65 | 'after': 'post_connected'}, |
Shad Ansari | 0e7ad96 | 2018-09-28 01:42:26 +0000 | [diff] [blame] | 66 | {'trigger': 'go_state_up', |
| 67 | 'source': ['state_connected', 'state_down'], |
| 68 | 'dest': 'state_up', |
| 69 | 'before': 'do_state_up'}, |
| 70 | {'trigger': 'go_state_down', |
| 71 | 'source': ['state_up'], |
| 72 | 'dest': 'state_down', |
| 73 | 'before': 'do_state_down', |
| 74 | 'after': 'post_down'}] |
Shad Ansari | 22efe83 | 2018-05-19 05:37:03 +0000 | [diff] [blame] | 75 | |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 76 | def __init__(self, **kwargs): |
| 77 | super(OpenoltDevice, self).__init__() |
| 78 | |
Shad Ansari | 7c73c1a | 2019-02-04 15:39:47 -0800 | [diff] [blame] | 79 | self.admin_state = "up" |
| 80 | |
Shad Ansari | 8d06864 | 2019-02-28 23:09:03 -0800 | [diff] [blame] | 81 | adapter_agent = kwargs['adapter_agent'] |
Shad Ansari | 4f9a973 | 2019-03-08 16:47:08 -0800 | [diff] [blame] | 82 | self.device_id = kwargs['device_id'] |
Shad Ansari | cd20a6d | 2018-10-02 14:36:33 +0000 | [diff] [blame] | 83 | |
Shad Ansari | d557797 | 2019-02-22 09:35:03 -0800 | [diff] [blame] | 84 | self.data_model_class = kwargs['support_classes']['data_model'] |
Shad Ansari | cd20a6d | 2018-10-02 14:36:33 +0000 | [diff] [blame] | 85 | self.platform_class = kwargs['support_classes']['platform'] |
Shad Ansari | d557797 | 2019-02-22 09:35:03 -0800 | [diff] [blame] | 86 | self.platform = self.platform_class() |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 87 | self.resource_mgr_class = kwargs['support_classes']['resource_mgr'] |
Shad Ansari | cd20a6d | 2018-10-02 14:36:33 +0000 | [diff] [blame] | 88 | self.flow_mgr_class = kwargs['support_classes']['flow_mgr'] |
| 89 | self.alarm_mgr_class = kwargs['support_classes']['alarm_mgr'] |
| 90 | self.stats_mgr_class = kwargs['support_classes']['stats_mgr'] |
Shad Ansari | cd20a6d | 2018-10-02 14:36:33 +0000 | [diff] [blame] | 91 | |
Nicolas Palpacuer | 253461f | 2018-06-01 12:01:45 -0400 | [diff] [blame] | 92 | is_reconciliation = kwargs.get('reconciliation', False) |
Shad Ansari | 4f9a973 | 2019-03-08 16:47:08 -0800 | [diff] [blame] | 93 | self.host_and_port = kwargs['host_and_port'] |
| 94 | self.extra_args = kwargs['extra_args'] |
Shad Ansari | 8d06864 | 2019-02-28 23:09:03 -0800 | [diff] [blame] | 95 | self.log = structlog.get_logger(ip=self.host_and_port) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 96 | |
Matteo Scandolo | bf5ae0c | 2018-11-15 18:12:54 -0800 | [diff] [blame] | 97 | self.log.info('openolt-device-init') |
| 98 | |
Shad Ansari | 4f9a973 | 2019-03-08 16:47:08 -0800 | [diff] [blame] | 99 | self.data_model = self.data_model_class(self.device_id, adapter_agent, |
Shad Ansari | 8d06864 | 2019-02-28 23:09:03 -0800 | [diff] [blame] | 100 | self.platform) |
| 101 | if is_reconciliation: |
Shad Ansari | d557797 | 2019-02-22 09:35:03 -0800 | [diff] [blame] | 102 | self.log.info('reconcile data model') |
Shad Ansari | d557797 | 2019-02-22 09:35:03 -0800 | [diff] [blame] | 103 | self.data_model.reconcile() |
Nicolas Palpacuer | 28cc266 | 2018-06-22 16:30:18 -0400 | [diff] [blame] | 104 | |
Shad Ansari | 94250fc | 2018-07-04 06:52:11 +0000 | [diff] [blame] | 105 | # Initialize the OLT state machine |
| 106 | self.machine = Machine(model=self, states=OpenoltDevice.states, |
| 107 | transitions=OpenoltDevice.transitions, |
| 108 | send_event=True, initial='state_null') |
Shad Ansari | c4085df | 2019-02-13 16:47:07 -0800 | [diff] [blame] | 109 | |
| 110 | self.device_info = None |
| 111 | |
Shad Ansari | 995ca63 | 2019-04-08 19:43:46 -0700 | [diff] [blame] | 112 | self._kadmin = KAdmin() |
Shad Ansari | a3bcfe1 | 2019-04-13 11:46:28 -0700 | [diff] [blame] | 113 | self._kadmin.delete_topics([ |
| 114 | 'openolt.ind-{}'.format(self.host_and_port.split(':')[0])]) |
Shad Ansari | d1652de | 2019-04-24 10:15:20 -0700 | [diff] [blame] | 115 | |
Shad Ansari | 548f94d | 2019-04-24 13:42:52 -0700 | [diff] [blame] | 116 | self.broker = registry('openolt_kafka_proxy').kafka_endpoint |
Shad Ansari | d1652de | 2019-04-24 10:15:20 -0700 | [diff] [blame] | 117 | channel = grpc.insecure_channel(self.host_and_port) |
| 118 | self.stub = openolt_pb2_grpc.OpenoltStub(channel) |
| 119 | |
Shad Ansari | 0cc9230 | 2019-04-03 11:34:49 -0700 | [diff] [blame] | 120 | self._grpc = None |
Shad Ansari | 94250fc | 2018-07-04 06:52:11 +0000 | [diff] [blame] | 121 | self.go_state_init() |
| 122 | |
| 123 | def do_state_init(self, event): |
Shad Ansari | 0cc9230 | 2019-04-03 11:34:49 -0700 | [diff] [blame] | 124 | self.log.debug('init') |
Shad Ansari | e969afc | 2019-04-05 15:16:41 -0700 | [diff] [blame] | 125 | self._indications = OpenoltIndications(self) |
| 126 | self._indications.start() |
Nicolas Palpacuer | 7183a3b | 2018-09-10 17:16:49 -0400 | [diff] [blame] | 127 | |
| 128 | def post_init(self, event): |
| 129 | self.log.debug('post_init') |
Shad Ansari | 72462c8 | 2019-04-17 01:36:01 -0700 | [diff] [blame] | 130 | |
| 131 | # FIXME |
Shad Ansari | e969afc | 2019-04-05 15:16:41 -0700 | [diff] [blame] | 132 | time.sleep(10) |
Shad Ansari | 72462c8 | 2019-04-17 01:36:01 -0700 | [diff] [blame] | 133 | |
Shad Ansari | 72462c8 | 2019-04-17 01:36:01 -0700 | [diff] [blame] | 134 | reactor.callInThread(self.get_device_info) |
Shad Ansari | 94250fc | 2018-07-04 06:52:11 +0000 | [diff] [blame] | 135 | |
| 136 | def do_state_connected(self, event): |
Nicolas Palpacuer | 324dcae | 2018-08-02 11:12:22 -0400 | [diff] [blame] | 137 | self.log.debug("do_state_connected") |
| 138 | |
Shad Ansari | f34da59 | 2019-02-13 23:05:35 -0800 | [diff] [blame] | 139 | # Check that device_info was successfully retrieved |
| 140 | assert(self.device_info is not None |
| 141 | and self.device_info.device_serial_number is not None |
| 142 | and self.device_info.device_serial_number != '') |
| 143 | |
Shad Ansari | d557797 | 2019-02-22 09:35:03 -0800 | [diff] [blame] | 144 | self.data_model.olt_create(self.device_info) |
Craig Lutgen | 109d407 | 2018-12-11 17:01:16 -0600 | [diff] [blame] | 145 | |
Shad Ansari | 12acc9a | 2019-05-20 21:46:28 +0000 | [diff] [blame] | 146 | # FIXME |
Shad Ansari | 1ed6f7d | 2019-05-18 00:01:54 +0000 | [diff] [blame] | 147 | self._kadmin.delete_topics([ |
| 148 | 'voltha.pktout-{}'.format(self.data_model.logical_device_id)]) |
Shad Ansari | 12acc9a | 2019-05-20 21:46:28 +0000 | [diff] [blame] | 149 | self._kadmin.delete_topics(['openolt.pktin-{}'.format( |
| 150 | self.host_and_port.split(':')[0])]) |
Shad Ansari | 1ed6f7d | 2019-05-18 00:01:54 +0000 | [diff] [blame] | 151 | |
Shad Ansari | a3bcfe1 | 2019-04-13 11:46:28 -0700 | [diff] [blame] | 152 | self._packet = OpenoltPacket(self) |
| 153 | self._packet.start() |
| 154 | |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 155 | self.resource_mgr = self.resource_mgr_class(self.device_id, |
Shad Ansari | 78de2be | 2018-10-12 22:13:54 +0000 | [diff] [blame] | 156 | self.host_and_port, |
| 157 | self.extra_args, |
Shad Ansari | c4085df | 2019-02-13 16:47:07 -0800 | [diff] [blame] | 158 | self.device_info) |
Shad Ansari | d1652de | 2019-04-24 10:15:20 -0700 | [diff] [blame] | 159 | self.flow_mgr = self.flow_mgr_class(self.log, self.stub, |
Shad Ansari | f9b9b89 | 2019-02-27 17:10:27 -0800 | [diff] [blame] | 160 | self.device_id, |
Shad Ansari | d557797 | 2019-02-22 09:35:03 -0800 | [diff] [blame] | 161 | self.data_model.logical_device_id, |
Shad Ansari | f9b9b89 | 2019-02-27 17:10:27 -0800 | [diff] [blame] | 162 | self.platform, self.resource_mgr, |
| 163 | self.data_model) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 164 | |
Shad Ansari | 8d06864 | 2019-02-28 23:09:03 -0800 | [diff] [blame] | 165 | self.alarm_mgr = self.alarm_mgr_class(self.log, self.platform, |
| 166 | self.data_model) |
| 167 | self.stats_mgr = self.stats_mgr_class(self, self.log, self.platform, |
| 168 | self.data_model) |
Shad Ansari | cd20a6d | 2018-10-02 14:36:33 +0000 | [diff] [blame] | 169 | |
Shad Ansari | 72462c8 | 2019-04-17 01:36:01 -0700 | [diff] [blame] | 170 | def post_connected(self, event): |
Shad Ansari | 548f94d | 2019-04-24 13:42:52 -0700 | [diff] [blame] | 171 | # FIXME - better way that avoids absolute paths? |
| 172 | self._grpc = subprocess.Popen( |
| 173 | ['python', |
Shad Ansari | a03b133 | 2019-04-24 23:31:36 -0700 | [diff] [blame] | 174 | 'openolt_grpc.py', |
Shad Ansari | 548f94d | 2019-04-24 13:42:52 -0700 | [diff] [blame] | 175 | self.broker, |
| 176 | self.host_and_port], |
Shad Ansari | a03b133 | 2019-04-24 23:31:36 -0700 | [diff] [blame] | 177 | env={'PYTHONPATH': '/voltha:/voltha/voltha/protos/third_party'}, |
| 178 | cwd='/voltha/voltha/adapters/openolt/grpc', |
| 179 | ) |
Shad Ansari | 72462c8 | 2019-04-17 01:36:01 -0700 | [diff] [blame] | 180 | |
Shad Ansari | 94250fc | 2018-07-04 06:52:11 +0000 | [diff] [blame] | 181 | def do_state_up(self, event): |
Nicolas Palpacuer | 324dcae | 2018-08-02 11:12:22 -0400 | [diff] [blame] | 182 | self.log.debug("do_state_up") |
Shad Ansari | d557797 | 2019-02-22 09:35:03 -0800 | [diff] [blame] | 183 | self.data_model.olt_oper_up() |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 184 | |
Shad Ansari | 94250fc | 2018-07-04 06:52:11 +0000 | [diff] [blame] | 185 | def do_state_down(self, event): |
| 186 | self.log.debug("do_state_down") |
Shad Ansari | d557797 | 2019-02-22 09:35:03 -0800 | [diff] [blame] | 187 | self.data_model.olt_oper_down() |
Nicolas Palpacuer | 4114135 | 2018-08-31 14:11:38 -0400 | [diff] [blame] | 188 | |
Nicolas Palpacuer | 4114135 | 2018-08-31 14:11:38 -0400 | [diff] [blame] | 189 | def post_down(self, event): |
| 190 | self.log.debug('post_down') |
| 191 | self.flow_mgr.reset_flows() |
Shad Ansari | fc3c4e1 | 2019-04-19 16:54:01 -0700 | [diff] [blame] | 192 | self.go_state_init() |
Nicolas Palpacuer | 4114135 | 2018-08-31 14:11:38 -0400 | [diff] [blame] | 193 | |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 194 | def olt_indication(self, olt_indication): |
Shad Ansari | 22efe83 | 2018-05-19 05:37:03 +0000 | [diff] [blame] | 195 | if olt_indication.oper_state == "up": |
Shad Ansari | 94250fc | 2018-07-04 06:52:11 +0000 | [diff] [blame] | 196 | self.go_state_up() |
Shad Ansari | 22efe83 | 2018-05-19 05:37:03 +0000 | [diff] [blame] | 197 | elif olt_indication.oper_state == "down": |
Shad Ansari | 94250fc | 2018-07-04 06:52:11 +0000 | [diff] [blame] | 198 | self.go_state_down() |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 199 | |
| 200 | def intf_indication(self, intf_indication): |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 201 | self.log.debug("intf indication", intf_id=intf_indication.intf_id, |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 202 | oper_state=intf_indication.oper_state) |
Shad Ansari | ef2029b | 2019-02-25 09:45:54 -0800 | [diff] [blame] | 203 | # NOTE - BAL only sends interface indications for PON ports, |
| 204 | # not for NNI ports. |
| 205 | self.data_model.olt_port_add_update(intf_indication.intf_id, |
| 206 | "pon", |
| 207 | intf_indication.oper_state) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 208 | |
| 209 | def intf_oper_indication(self, intf_oper_indication): |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 210 | self.log.debug("Received interface oper state change indication", |
| 211 | intf_id=intf_oper_indication.intf_id, |
| 212 | type=intf_oper_indication.type, |
| 213 | oper_state=intf_oper_indication.oper_state) |
Shad Ansari | ef2029b | 2019-02-25 09:45:54 -0800 | [diff] [blame] | 214 | self.data_model.olt_port_add_update(intf_oper_indication.intf_id, |
| 215 | intf_oper_indication.type, |
| 216 | intf_oper_indication.oper_state) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 217 | |
| 218 | def onu_discovery_indication(self, onu_disc_indication): |
Shad Ansari | 803900a | 2018-05-02 06:26:00 +0000 | [diff] [blame] | 219 | intf_id = onu_disc_indication.intf_id |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 220 | serial_number = onu_disc_indication.serial_number |
Shad Ansari | e8cbc6f | 2019-02-14 15:50:54 -0800 | [diff] [blame] | 221 | serial_number_str = OpenoltUtils.stringify_serial_number(serial_number) |
Shad Ansari | 803900a | 2018-05-02 06:26:00 +0000 | [diff] [blame] | 222 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 223 | self.log.debug("onu discovery indication", intf_id=intf_id, |
| 224 | serial_number=serial_number_str) |
Nicolas Palpacuer | 36a9344 | 2018-05-23 17:38:57 -0400 | [diff] [blame] | 225 | |
Shad Ansari | f935829 | 2019-03-07 12:31:53 -0800 | [diff] [blame] | 226 | try: |
Shad Ansari | 4f9a973 | 2019-03-08 16:47:08 -0800 | [diff] [blame] | 227 | onu_id = self.data_model.onu_id(serial_number=serial_number_str) |
Shad Ansari | f935829 | 2019-03-07 12:31:53 -0800 | [diff] [blame] | 228 | except ValueError: |
| 229 | # FIXME - resource_mgr.get_onu_id() should raise exception |
Shad Ansari | d557797 | 2019-02-22 09:35:03 -0800 | [diff] [blame] | 230 | onu_id = self.resource_mgr.get_onu_id(intf_id) |
| 231 | if onu_id is None: |
| 232 | raise Exception("onu-id-unavailable") |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 233 | |
Shad Ansari | 2f8a90d | 2019-04-19 01:44:24 -0700 | [diff] [blame] | 234 | try: |
| 235 | self.data_model.onu_create(intf_id, onu_id, serial_number_str) |
| 236 | except ValueError: |
| 237 | pass |
| 238 | else: |
| 239 | self.activate_onu(intf_id, onu_id, serial_number, |
| 240 | serial_number_str) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 241 | |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 242 | def onu_indication(self, onu_indication): |
Shad Ansari | a0b3789 | 2018-06-12 21:34:30 +0000 | [diff] [blame] | 243 | self.log.debug("onu indication", intf_id=onu_indication.intf_id, |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 244 | onu_id=onu_indication.onu_id, |
| 245 | serial_number=onu_indication.serial_number, |
| 246 | oper_state=onu_indication.oper_state, |
| 247 | admin_state=onu_indication.admin_state) |
Shad Ansari | 94250fc | 2018-07-04 06:52:11 +0000 | [diff] [blame] | 248 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 249 | # Admin state |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 250 | if onu_indication.admin_state == 'down': |
| 251 | if onu_indication.oper_state != 'down': |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 252 | self.log.error('ONU-admin-state-down-and-oper-status-not-down', |
| 253 | oper_state=onu_indication.oper_state) |
| 254 | # Forcing the oper state change code to execute |
| 255 | onu_indication.oper_state = 'down' |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 256 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 257 | # Port and logical port update is taken care of by oper state block |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 258 | |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 259 | self.log.debug('admin-state-dealt-with') |
| 260 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 261 | # Operating state |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 262 | if onu_indication.oper_state == 'down': |
Shad Ansari | ef2029b | 2019-02-25 09:45:54 -0800 | [diff] [blame] | 263 | self.data_model.onu_oper_down(onu_indication.intf_id, |
| 264 | onu_indication.onu_id) |
Matt Jeanneret | 12cd5d0 | 2018-08-07 15:30:19 -0400 | [diff] [blame] | 265 | |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 266 | elif onu_indication.oper_state == 'up': |
Shad Ansari | ef2029b | 2019-02-25 09:45:54 -0800 | [diff] [blame] | 267 | self.data_model.onu_oper_up(onu_indication.intf_id, |
| 268 | onu_indication.onu_id) |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 269 | |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 270 | def omci_indication(self, omci_indication): |
| 271 | |
| 272 | self.log.debug("omci indication", intf_id=omci_indication.intf_id, |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 273 | onu_id=omci_indication.onu_id) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 274 | |
Shad Ansari | 8d06864 | 2019-02-28 23:09:03 -0800 | [diff] [blame] | 275 | self.data_model.onu_omci_rx(omci_indication.intf_id, |
| 276 | omci_indication.onu_id, |
| 277 | omci_indication.pkt) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 278 | |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 279 | def send_proxied_message(self, proxy_address, msg): |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 280 | omci = openolt_pb2.OmciMsg(intf_id=proxy_address.channel_id, |
| 281 | onu_id=proxy_address.onu_id, pkt=str(msg)) |
Shad Ansari | d1652de | 2019-04-24 10:15:20 -0700 | [diff] [blame] | 282 | reactor.callInThread(self.stub.OmciMsgOut, omci) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 283 | |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 284 | def update_flow_table(self, flows): |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 285 | self.log.debug('No updates here now, all is done in logical flows ' |
| 286 | 'update') |
Shad Ansari | 5df91f6 | 2018-07-25 23:59:46 +0000 | [diff] [blame] | 287 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 288 | def update_logical_flows(self, flows_to_add, flows_to_remove, |
| 289 | device_rules_map): |
Nicolas Palpacuer | 3d0878d | 2018-08-17 11:29:42 -0400 | [diff] [blame] | 290 | if not self.is_state_up(): |
| 291 | self.log.info('The OLT is not up, we cannot update flows', |
| 292 | flows_to_add=[f.id for f in flows_to_add], |
| 293 | flows_to_remove=[f.id for f in flows_to_remove]) |
| 294 | return |
| 295 | |
Shad Ansari | 4f9a973 | 2019-03-08 16:47:08 -0800 | [diff] [blame] | 296 | self.flow_mgr.update_logical_flows(flows_to_add, flows_to_remove, |
| 297 | device_rules_map) |
Nicolas Palpacuer | 4114135 | 2018-08-31 14:11:38 -0400 | [diff] [blame] | 298 | |
Jonathan Davis | 0f917a2 | 2018-05-30 14:39:45 -0400 | [diff] [blame] | 299 | def disable(self): |
Shad Ansari | 8d06864 | 2019-02-28 23:09:03 -0800 | [diff] [blame] | 300 | self.log.debug('sending-deactivate-olt-message') |
Jonathan Davis | 0f917a2 | 2018-05-30 14:39:45 -0400 | [diff] [blame] | 301 | |
Nicolas Palpacuer | 62dbb9c | 2018-08-02 15:03:35 -0400 | [diff] [blame] | 302 | try: |
| 303 | # Send grpc call |
Shad Ansari | d1652de | 2019-04-24 10:15:20 -0700 | [diff] [blame] | 304 | self.stub.DisableOlt(openolt_pb2.Empty()) |
Shad Ansari | 7c73c1a | 2019-02-04 15:39:47 -0800 | [diff] [blame] | 305 | self.admin_state = "down" |
Nicolas Palpacuer | 62dbb9c | 2018-08-02 15:03:35 -0400 | [diff] [blame] | 306 | self.log.info('openolt device disabled') |
| 307 | except Exception as e: |
| 308 | self.log.error('Failure to disable openolt device', error=e) |
Jonathan Davis | 0f917a2 | 2018-05-30 14:39:45 -0400 | [diff] [blame] | 309 | |
Jonathan Davis | 0f917a2 | 2018-05-30 14:39:45 -0400 | [diff] [blame] | 310 | def delete(self): |
Shad Ansari | 8d06864 | 2019-02-28 23:09:03 -0800 | [diff] [blame] | 311 | self.log.info('deleting-olt') |
Nicolas Palpacuer | 0d44e68 | 2018-08-06 10:30:26 -0400 | [diff] [blame] | 312 | |
Shad Ansari | 18094d6 | 2019-04-25 10:00:34 -0700 | [diff] [blame] | 313 | # Terminate the grpc subprocess |
| 314 | self._grpc.terminate() |
| 315 | |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 316 | # Clears up the data from the resource manager KV store |
| 317 | # for the device |
| 318 | del self.resource_mgr |
| 319 | |
Nicolas Palpacuer | 0d44e68 | 2018-08-06 10:30:26 -0400 | [diff] [blame] | 320 | try: |
| 321 | # Rebooting to reset the state |
| 322 | self.reboot() |
Shad Ansari | ef2029b | 2019-02-25 09:45:54 -0800 | [diff] [blame] | 323 | self.data_model.olt_delete() |
Nicolas Palpacuer | 0d44e68 | 2018-08-06 10:30:26 -0400 | [diff] [blame] | 324 | except Exception as e: |
| 325 | self.log.error('Failure to delete openolt device', error=e) |
| 326 | raise e |
| 327 | else: |
Shad Ansari | 8d06864 | 2019-02-28 23:09:03 -0800 | [diff] [blame] | 328 | self.log.info('successfully-deleted-olt') |
Jonathan Davis | 0f917a2 | 2018-05-30 14:39:45 -0400 | [diff] [blame] | 329 | |
Jonathan Davis | 0f917a2 | 2018-05-30 14:39:45 -0400 | [diff] [blame] | 330 | def reenable(self): |
Shad Ansari | 8d06864 | 2019-02-28 23:09:03 -0800 | [diff] [blame] | 331 | self.log.debug('reenabling-olt') |
Jonathan Davis | 0f917a2 | 2018-05-30 14:39:45 -0400 | [diff] [blame] | 332 | |
Nicolas Palpacuer | 62dbb9c | 2018-08-02 15:03:35 -0400 | [diff] [blame] | 333 | try: |
Shad Ansari | d1652de | 2019-04-24 10:15:20 -0700 | [diff] [blame] | 334 | self.stub.ReenableOlt(openolt_pb2.Empty()) |
Nicolas Palpacuer | 62dbb9c | 2018-08-02 15:03:35 -0400 | [diff] [blame] | 335 | except Exception as e: |
| 336 | self.log.error('Failure to reenable openolt device', error=e) |
Nicolas Palpacuer | 324dcae | 2018-08-02 11:12:22 -0400 | [diff] [blame] | 337 | else: |
| 338 | self.log.info('openolt device reenabled') |
Shad Ansari | 7c73c1a | 2019-02-04 15:39:47 -0800 | [diff] [blame] | 339 | self.admin_state = "up" |
Nicolas Palpacuer | 324dcae | 2018-08-02 11:12:22 -0400 | [diff] [blame] | 340 | |
Nicolas Palpacuer | 131790b | 2018-08-20 09:59:34 -0400 | [diff] [blame] | 341 | def activate_onu(self, intf_id, onu_id, serial_number, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 342 | serial_number_str): |
Nicolas Palpacuer | 131790b | 2018-08-20 09:59:34 -0400 | [diff] [blame] | 343 | self.log.debug("activating-onu", intf_id=intf_id, onu_id=onu_id, |
Shad Ansari | f9521ad | 2018-09-08 10:46:43 +0000 | [diff] [blame] | 344 | serial_number_str=serial_number_str, |
Shad Ansari | 8d06864 | 2019-02-28 23:09:03 -0800 | [diff] [blame] | 345 | serial_number=serial_number) |
Nicolas Palpacuer | 131790b | 2018-08-20 09:59:34 -0400 | [diff] [blame] | 346 | onu = openolt_pb2.Onu(intf_id=intf_id, onu_id=onu_id, |
Shad Ansari | 8d06864 | 2019-02-28 23:09:03 -0800 | [diff] [blame] | 347 | serial_number=serial_number) |
Shad Ansari | 3fbf1c0 | 2019-04-11 15:12:54 -0700 | [diff] [blame] | 348 | |
| 349 | self.log.info('activating onu', serial_number=serial_number_str) |
Shad Ansari | d1652de | 2019-04-24 10:15:20 -0700 | [diff] [blame] | 350 | reactor.callInThread(self.stub.ActivateOnu, onu) |
Nicolas Palpacuer | 62dbb9c | 2018-08-02 15:03:35 -0400 | [diff] [blame] | 351 | |
Shad Ansari | ef2029b | 2019-02-25 09:45:54 -0800 | [diff] [blame] | 352 | # FIXME - instead of passing child_device around, delete_child_device |
| 353 | # needs to change to use serial_number. |
Jonathan Davis | b45bb37 | 2018-07-19 15:05:15 -0400 | [diff] [blame] | 354 | def delete_child_device(self, child_device): |
| 355 | self.log.debug('sending-deactivate-onu', |
Jonathan Davis | b45bb37 | 2018-07-19 15:05:15 -0400 | [diff] [blame] | 356 | onu_device=child_device, |
| 357 | onu_serial_number=child_device.serial_number) |
Thiyagarajan Subramani | 353af12 | 2019-02-20 23:14:24 -0800 | [diff] [blame] | 358 | |
Shad Ansari | ef2029b | 2019-02-25 09:45:54 -0800 | [diff] [blame] | 359 | self.data_model.onu_delete(child_device.serial_number) |
Thiyagarajan Subramani | 353af12 | 2019-02-20 23:14:24 -0800 | [diff] [blame] | 360 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 361 | # TODO FIXME - For each uni. |
| 362 | # TODO FIXME - Flows are not deleted |
| 363 | uni_id = 0 # FIXME |
Thiyagarajan Subramani | 353af12 | 2019-02-20 23:14:24 -0800 | [diff] [blame] | 364 | try: |
| 365 | self.flow_mgr.delete_tech_profile_instance( |
| 366 | child_device.proxy_address.channel_id, |
| 367 | child_device.proxy_address.onu_id, |
Shad Ansari | ef2029b | 2019-02-25 09:45:54 -0800 | [diff] [blame] | 368 | uni_id, None) |
Thiyagarajan Subramani | 353af12 | 2019-02-20 23:14:24 -0800 | [diff] [blame] | 369 | except Exception as e: |
| 370 | self.log.exception("error-removing-tp-instance") |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 371 | |
Thiyagarajan Subramani | 353af12 | 2019-02-20 23:14:24 -0800 | [diff] [blame] | 372 | try: |
| 373 | pon_intf_id_onu_id = (child_device.proxy_address.channel_id, |
| 374 | child_device.proxy_address.onu_id, |
| 375 | uni_id) |
| 376 | # Free any PON resources that were reserved for the ONU |
| 377 | self.resource_mgr.free_pon_resources_for_onu(pon_intf_id_onu_id) |
| 378 | except Exception as e: |
| 379 | self.log.exception("error-removing-pon-resources-for-onu") |
| 380 | |
Shad Ansari | ef2029b | 2019-02-25 09:45:54 -0800 | [diff] [blame] | 381 | serial_number = OpenoltUtils.destringify_serial_number( |
| 382 | child_device.serial_number) |
Thiyagarajan Subramani | 353af12 | 2019-02-20 23:14:24 -0800 | [diff] [blame] | 383 | try: |
Shad Ansari | d557797 | 2019-02-22 09:35:03 -0800 | [diff] [blame] | 384 | onu = openolt_pb2.Onu( |
| 385 | intf_id=child_device.proxy_address.channel_id, |
| 386 | onu_id=child_device.proxy_address.onu_id, |
| 387 | serial_number=serial_number) |
Shad Ansari | d1652de | 2019-04-24 10:15:20 -0700 | [diff] [blame] | 388 | self.stub.DeleteOnu(onu) |
Thiyagarajan Subramani | 353af12 | 2019-02-20 23:14:24 -0800 | [diff] [blame] | 389 | except Exception as e: |
Shad Ansari | 242aac6 | 2019-04-19 18:32:56 -0700 | [diff] [blame] | 390 | self.log.warn("error-deleting-the-onu-on-olt-device", error=e) |
Nicolas Palpacuer | fd365ac | 2018-08-02 11:37:37 -0400 | [diff] [blame] | 391 | |
| 392 | def reboot(self): |
Shad Ansari | 8d06864 | 2019-02-28 23:09:03 -0800 | [diff] [blame] | 393 | self.log.debug('rebooting openolt device') |
Nicolas Palpacuer | fd365ac | 2018-08-02 11:37:37 -0400 | [diff] [blame] | 394 | try: |
Shad Ansari | d1652de | 2019-04-24 10:15:20 -0700 | [diff] [blame] | 395 | self.stub.Reboot(openolt_pb2.Empty()) |
Nicolas Palpacuer | fd365ac | 2018-08-02 11:37:37 -0400 | [diff] [blame] | 396 | except Exception as e: |
| 397 | self.log.error('something went wrong with the reboot', error=e) |
| 398 | else: |
| 399 | self.log.info('device rebooted') |
| 400 | |
Nicolas Palpacuer | 30027f4 | 2018-09-06 15:55:54 -0400 | [diff] [blame] | 401 | def trigger_statistics_collection(self): |
| 402 | try: |
Shad Ansari | d1652de | 2019-04-24 10:15:20 -0700 | [diff] [blame] | 403 | self.stub.CollectStatistics(openolt_pb2.Empty()) |
Nicolas Palpacuer | 30027f4 | 2018-09-06 15:55:54 -0400 | [diff] [blame] | 404 | except Exception as e: |
| 405 | self.log.error('Error while triggering statistics collection', |
| 406 | error=e) |
| 407 | else: |
| 408 | self.log.info('statistics requested') |
Scott Baker | d319095 | 2018-09-04 15:47:28 -0700 | [diff] [blame] | 409 | |
| 410 | def simulate_alarm(self, alarm): |
| 411 | self.alarm_mgr.simulate_alarm(alarm) |
Shad Ansari | 72462c8 | 2019-04-17 01:36:01 -0700 | [diff] [blame] | 412 | |
| 413 | def get_device_info(self): |
| 414 | self.log.debug('get_device_info') |
| 415 | timeout = 60*60 |
| 416 | delay = 1 |
| 417 | exponential_back_off = False |
| 418 | while True: |
| 419 | try: |
| 420 | self.device_info \ |
Shad Ansari | d1652de | 2019-04-24 10:15:20 -0700 | [diff] [blame] | 421 | = self.stub.GetDeviceInfo(openolt_pb2.Empty()) |
Shad Ansari | 72462c8 | 2019-04-17 01:36:01 -0700 | [diff] [blame] | 422 | break |
| 423 | except Exception as e: |
| 424 | if delay > timeout: |
| 425 | self.log.error("openolt grpc timed out connecting to olt") |
| 426 | return |
| 427 | else: |
| 428 | self.log.warn( |
| 429 | "openolt grpc retry connecting to olt in %ds: %s" |
| 430 | % (delay, repr(e))) |
| 431 | time.sleep(delay) |
| 432 | if exponential_back_off: |
| 433 | delay += delay |
| 434 | else: |
| 435 | delay += 1 |
| 436 | |
| 437 | self.log.info('openolt grpc connected to olt', |
| 438 | device_info=self.device_info) |
| 439 | |
| 440 | self.go_state_connected() |