blob: bad8533f6202a7abe8cbac4b7b80f5aa64e2bc56 [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#
12# File : mtr_rules.py
13#
14# Comments :
15# Read METER Rules config file from './config/' and get parameters
16# values as per the METER Rule Table.
17# As per METER Rule table, formed a structure and parse values in structure,
18# and finally pack a structure and send over the zmq(PUB/SUB) socket to DP.
19#
20# Reference : message_sdn_dp.docx
21# Section : Table No.13 METER Rule
22##############################################################################
23
24import sys
25import os
26import time
27import struct
28import socket
29
30from configparser import ConfigParser
31
32parser = ConfigParser()
33
34def parse_mtr_values(pub_socket,topicId):
35 # TBD: Need to handle exception
36 parser.read('./config/meter_profile.cfg')
37 print "\n ---> Reading Values from Meter profile file <--- "
38 print "\n ---> Sending Meter Rules <---"
39 MSG_TYPE = 19
40 RULE_ID = 0
41
42 # Create struct for meter rule and parse values in that.
43 for val in parser.sections():
44 if val != 'GLOBAL':
45 RULE_ID += 1
46 # TBD: Need to handle exception
47 CIR = int(parser.get(val, 'CIR'))
48 CBS = int(parser.get(val, 'CBS'))
49 EBS = int(parser.get(val, 'EBS'))
50 MTR_PROFILE_IDX = int(parser.get(val, \
51 'MTR_PROFILE_IDX'))
52
53 METERING_METHOD = 0
54
55 # Pack the struct and send over the zmq socket to dp.
56 pub_socket.send("%s" % (struct.pack('!BBHQQQH',topicId,\
57 MSG_TYPE, MTR_PROFILE_IDX, CIR, CBS, EBS, \
58 METERING_METHOD)))
59
60 print "\nMETER Rule Values for %s ::\nRULE_ID :%s\
61 \nMSG_TYPE :%s \nCIR :%s \nCBS :%s \
62 \nEBS :%s \nMTR_PROFILE_IDX :%s\
63 \nMETERING_METHOD :%s\n " % \
64 (val, RULE_ID, MSG_TYPE, CIR, \
65 CBS, EBS, MTR_PROFILE_IDX, \
66 METERING_METHOD)
67 time.sleep(1)
68
69 print '\n ---># Meter Rule Successfully sent..#<---\n'
70 parser.clear()