blob: e1ceea697a1eb23e5c7f599c211cb4a2e6ad8b6b [file] [log] [blame]
Dimitrios Mavrommatis0774a592017-12-21 14:57:52 -08001#!/usr/bin/python
2#coding: utf8
3#Copyright © 2016 - 2017 Copyright (c) Sprint, Inc. and others. All rights
4#reserved.
5#
6#This program and the accompanying materials are made available under the
7#terms of the Eclipse Public License v1.0 which accompanies this distribution,
8#and is available at http://www.eclipse.org/legal/epl-v10.html
9#
10############################################################################
11# File : pcc_rules.py
12#
13# Comments :
14# Read PCC Rules config file from './config/' and get parameters
15# values as per the PCC Rule Table.
16# As per PCC Rule table, formed a structure and parse values in structure,
17# and finally pack a structure and send over the zmq(PUB/SUB) socket to DP.
18#
19# Reference : message_sdn_dp.docx
20# Section : Table No.12 PCC Rule
21############################################################################
22
23import sys
24import os
25import time
26import struct
27import socket
28
29from configparser import ConfigParser
30
31parser = ConfigParser()
32
33def parse_pcc_values(pub_socket,topicId):
34 # TBD: Need to handle exception
35 parser.read('./config/pcc_rules.cfg')
36 print "\n ---> Reading Values from PCC config file <--- \n"
37 print "\n ---> Sending PCC Rules <---"
38 MSG_TYPE = 18
39 RULE_ID = 0
40
41 # Create a struture for PCC rule and parse the values in that.
42 for val in parser.sections():
43 if val != 'GLOBAL':
44 # TBD: Need to handle exception
45 #RULE_ID = int(parser.get(val, 'RULE_ID'))
46 RULE_ID += 1
47 RULE_NAME = str(parser.get(val, 'RULE_NAME'))
48 RATING_GROUP = int(parser.get(val, 'RATING_GROUP'))
49 SERVICE_ID = int(parser.get(val, 'SERVICE_ID'))
50 RULE_STATUS = int(parser.get(val, 'RULE_STATUS'))
51 GATE_STATUS = int(parser.get(val, 'GATE_STATUS'))
52 SESSION_CONT = int(parser.get(val, 'SESSION_CONT'))
53 REPORT_LEVEL = int(parser.get(val, 'REPORT_LEVEL'))
54 CHARGING_MODE = int(parser.get(val, 'CHARGING_MODE'))
55 METERING_METHOD = int(parser.get(val, 'METERING_METHOD'))
56 MUTE_NOTIFY = int(parser.get(val, 'MUTE_NOTIFY'))
57 MONITORING_KEY = int(parser.get(val, 'MONITORING_KEY'))
58 SPONSOR_ID = str(parser.get(val, 'SPONSOR_ID'))
59 REDIRECT_INFO = int(parser.get(val, 'REDIRECT_INFO'))
60 PRECEDENCE = int(parser.get(val, 'PRECEDENCE'))
61 DROP_PKT_COUNT = int(parser.get(val, 'DROP_PKT_COUNT'))
62 UL_MBR_MTR_PROFILE_IDX = int(parser.get(val, \
63 'UL_MBR_MTR_PROFILE_IDX'))
64 DL_MBR_MTR_PROFILE_IDX = int(parser.get(val, \
65 'DL_MBR_MTR_PROFILE_IDX'))
66
67 var = struct.Struct('!BBBBHBBBLLBBQHHBI'+str(\
68 len(RULE_NAME))+'sI'\
69 +str(len(SPONSOR_ID))+'s')
70
71 values = (topicId, MSG_TYPE, METERING_METHOD, \
72 CHARGING_MODE, RATING_GROUP, \
73 RULE_STATUS, GATE_STATUS, SESSION_CONT,\
74 MONITORING_KEY, PRECEDENCE, \
75 REPORT_LEVEL, MUTE_NOTIFY, \
76 DROP_PKT_COUNT, \
77 UL_MBR_MTR_PROFILE_IDX, \
78 DL_MBR_MTR_PROFILE_IDX, \
79 REDIRECT_INFO,\
80 len(RULE_NAME), RULE_NAME, \
81 len(SPONSOR_ID), SPONSOR_ID)
82
83 # TBD: Need to handle exception
84 # Pack the structure and send over the zmq socket to dp
85
86 pub_socket.send("%s" % (var.pack(*values)))
87 time.sleep(1)
88
89 print "\nPCC Rule Values for %s ::\nRULE_ID :%s \
90 \nRULE_NAME :%s\nRATING_GROUP :%s\
91 \nSERVICE_ID :%s\nRULE_STATUS :%s\
92 \nGATE_STATUS :%s\nSESSION_CONT :%s\
93 \nREPORT_LEVEL :%s \nCHARGING_MODE :%s\
94 \nMETERING_METHOD :%s\nMUTE_NOTIFY :%s\
95 \nMONITORING_KEY :%s\nSPONSOR_ID :%s\
96 \nREDIRECT_INFO :%s\nPRECEDENCE :%s\
97 \nDROP_PKT_COUNT :%s\
98 \nul_mbr_DROP_PKT_COUNT :%s\
99 \ndl_mbr_DROP_PKT_COUNT :%s\n\n" % \
100 (val, RULE_ID, RULE_NAME, RATING_GROUP,\
101 SERVICE_ID, RULE_STATUS, GATE_STATUS, \
102 SESSION_CONT, REPORT_LEVEL, \
103 CHARGING_MODE, METERING_METHOD, \
104 MUTE_NOTIFY, MONITORING_KEY, \
105 SPONSOR_ID, REDIRECT_INFO, PRECEDENCE,\
106 DROP_PKT_COUNT, UL_MBR_MTR_PROFILE_IDX,\
107 DL_MBR_MTR_PROFILE_IDX)
108
109 print '\n ---># PCC Rule Successfully sent..#<---\n'
110 parser.clear()