blob: 16d0c0c97c91bc5eff6cb238df24a4f9f9c7962d [file] [log] [blame]
Daniele Moro134b8d62020-01-14 11:32:05 -08001
2# Copyright 2020-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
17import json
18from xossynchronizer.event_steps.eventstep import EventStep
19from helpers import DtHelpers
20
21
22class ONUEventStep(EventStep):
23 topics = ["onu.events"]
24 technology = "kafka"
25
26 max_onu_retry = 50
27
28 def __init__(self, *args, **kwargs):
29 super(ONUEventStep, self).__init__(*args, **kwargs)
30
31 def process_event(self, event):
32 value = json.loads(event.value)
33 self.log.info("onu.events: received event", value=value)
Daniele Morof2a7f8e2020-02-19 17:37:34 -080034 # This is needed to be compatible with both Voltha 1.7 and Voltha 2.x
35 # It supposes to have only 1 subscriber per ONU and the subscriber is connected to the first port
36 if "-" in value["serialNumber"] and not value["serialNumber"].endswith("-1"):
37 self.log.info("Skip event, only consider [serialNumber]-1 events")
38 return
Daniele Moro134b8d62020-01-14 11:32:05 -080039
40 dt_si = DtHelpers.find_or_create_dt_si(self.model_accessor, self.log, value)
41 if value["status"] == "activated":
42 self.log.info("onu.events: activated onu", value=value)
43 dt_si.no_sync = False
44 dt_si.uni_port_id = long(value["portNumber"])
45 dt_si.of_dpid = value["deviceId"]
46 dt_si.oper_onu_status = "ENABLED"
47 dt_si.save_changed_fields(always_update_timestamp=True)
48 elif value["status"] == "disabled":
49 self.log.info("onu.events: disabled onu, resetting the subscriber", value=value)
50 dt_si.oper_onu_status = "DISABLED"
51 dt_si.save_changed_fields(always_update_timestamp=True)
52 return
53 else:
54 self.log.warn("onu.events: Unknown status value: %s" % value["status"], value=value)
55 return