blob: 33c24fe757603462c1efbca67d8d0c6df4fb85c0 [file] [log] [blame]
Daniele Moro134b8d62020-01-14 11:32:05 -08001# Copyright 2020-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import json
16from xossynchronizer.event_steps.eventstep import EventStep
17from helpers import DtHelpers
18
19
20class SubscriberPppoeEventStep(EventStep):
21 topics = ["bng.pppoe"]
22 technology = "kafka"
23
24 to_pppoe = {
25 "SESSION_INIT": "INITIATED",
26 "SESSION_CONFIRMATION": "CONNECTED",
27 "SESSION_TERMINATION": "DISCONNECTED"
28 }
29 to_ipcp = {
30 "IPCP_CONF_ACK": "CONF_ACK",
31 "IPCP_CONF_REQ": "CONF_REQUEST"
32 }
33
34 to_auth = {
35 "AUTH_REQ": "STARTED",
36 "AUTH_SUCCESS": "APPROVED",
37 "AUTH_FAILED": "DENIED"
38 }
39
40 def __init__(self, *args, **kwargs):
41 super(SubscriberPppoeEventStep, self).__init__(*args, **kwargs)
42
43 def process_event(self, event):
44 value = json.loads(event.value)
45 self.log.info("bng.pppoe: Got event for subscriber", event_value=value)
46
47 si = DtHelpers.find_or_create_dt_si(self.model_accessor, self.log, value)
48 self.log.debug("bng.pppoe: Updating service instance", si=si)
49 # Map messageType to the different SI states
50 messageType = value["eventType"]
51 if messageType in self.to_pppoe.keys():
52 si.pppoe_state = self.to_pppoe[messageType]
53 if messageType in self.to_ipcp.keys():
54 si.ipcp_state = self.to_ipcp[messageType]
55 if messageType in self.to_auth.keys():
56 si.authentication_state = self.to_auth[messageType]
57 si.ip_address = value["ipAddress"]
58 si.mac_address = value["macAddress"]
59 si.pppoe_session_id = value["sessionId"]
60 si.save_changed_fields(always_update_timestamp=True)