added test rules
diff --git a/scripts/test_rules/adc_rules.py b/scripts/test_rules/adc_rules.py
new file mode 100755
index 0000000..f5031e2
--- /dev/null
+++ b/scripts/test_rules/adc_rules.py
@@ -0,0 +1,152 @@
+#!/usr/bin/python
+#coding: utf8
+#Copyright © 2016 - 2017 Copyright (c) Sprint, Inc. and others. All rights
+#reserved.
+#
+#This program and the accompanying materials are made available under the
+#terms of the Eclipse Public License v1.0 which accompanies this distribution,
+#and is available at http://www.eclipse.org/legal/epl-v10.html
+#
+############################################################################
+# File : adc_rules.py
+#
+# Comments :
+# Read ADC Rules config file from './config/' and get parameters
+# values as per the ADC Rule Table.
+# As per ADC Rule table, formed a structure and parse values in struct,
+# and finally pack a struct and send over the zmq(PUB/SUB) socket to DP.
+#
+# Reference : message_sdn_dp.docx
+# Section : Table No.11 ADC Rule
+##############################################################################
+import sys
+import os
+import time
+import struct
+import socket
+
+from configparser import ConfigParser
+
+parser = ConfigParser()
+
+# Covert the string into num and stored into usigned 32 bit integer.
+def name_to_num(name):
+ num = 0
+ for ch in name[::-1]:
+ num = (num << 4) | (ord(ch) - ord('a'))
+ return num & 0xffffffff
+
+def parse_adc_values(pub_socket,topicId):
+ parser.read('./config/adc_rules.cfg')
+ print "\n ---> Reading Values from ADC rules file <---"
+ print "\n ---> Sending ADC rules <---"
+ MSG_TYPE = 17
+
+ # Create a structure for ADC rule and parse values in that.
+ for val in parser.sections():
+ if val != 'GLOBAL':
+ # TBD: Need to handle exception
+ ADC_TYPE = int(parser.get(val, 'ADC_TYPE'))
+ if ADC_TYPE == 0:
+ DOMAIN = str(parser.get(val, 'DOMAIN'))
+ if ADC_TYPE == 1:
+ IP = struct.unpack('!L', \
+ socket.inet_aton(str(parser.get(val, \
+ 'IP'))))
+ if ADC_TYPE == 2:
+ IP = struct.unpack('!L', \
+ socket.inet_aton(str(parser.get(val, \
+ 'IP'))))
+ PREFIX = int(parser.get(val, 'PREFIX'))
+
+ GATE_STATUS = int(parser.get(val, 'GATE_STATUS'))
+ RATING_GROUP = name_to_num(str(parser.get(val, \
+ 'RATING_GROUP')))
+ SERVICE_ID = name_to_num(str(parser.get(val, \
+ 'SERVICE_ID')))
+ PRECEDENCE = int(parser.get(val, 'PRECEDENCE'))
+ MTR_PROFILE_INDEX = int(parser.get(val, \
+ 'MTR_PROFILE_INDEX'))
+ SPONSOR = str(parser.get(val, 'SPONSOR'))
+
+ #TBD:: Need to handle exception
+ # Pack the structure and send over the zmq socket to DP
+ time.sleep(1)
+ if ADC_TYPE == 0:
+ pub_socket.send("%s" % (struct.pack('!BBBB'+ \
+ str(len(DOMAIN))+'sBLLLHB'+\
+ str(len(SPONSOR))+'s', \
+ topicId, MSG_TYPE, ADC_TYPE, \
+ len(DOMAIN), DOMAIN, \
+ GATE_STATUS, RATING_GROUP, \
+ SERVICE_ID, PRECEDENCE, \
+ MTR_PROFILE_INDEX, \
+ len(SPONSOR), SPONSOR)))
+ time.sleep(1)
+
+ print "\nADC Rule Values for ::\
+ \nADC_TYPE :%s \nDOMAIN :%s\
+ \nGATE_STATUS :%s\
+ \nrating group :%s \
+ \nSERVICE_ID :%s \
+ \nPRECEDENCE :%s \
+ \nMTR_PROFILE_INDEX :%s\
+ \nSPONSOR_LEN :%s\
+ \nSPONSOR :%s" % \
+ (ADC_TYPE, DOMAIN, GATE_STATUS,\
+ RATING_GROUP, SERVICE_ID, \
+ PRECEDENCE, MTR_PROFILE_INDEX, \
+ len(SPONSOR), SPONSOR)
+
+ if ADC_TYPE == 1:
+ pub_socket.send("%s" % (struct.pack('!BBBLBLLLHB'+\
+ str(len(SPONSOR))+'s',topicId, \
+ MSG_TYPE, ADC_TYPE, IP[0], \
+ GATE_STATUS, RATING_GROUP, \
+ SERVICE_ID, PRECEDENCE, \
+ MTR_PROFILE_INDEX, \
+ len(SPONSOR), SPONSOR)))
+
+ print "\nADC Rule Values for ::\
+ \nADC_TYPE :%s \nIP :%s \
+ \nGATE_STATUS :%s\
+ \nRATING_GROUP :%s\
+ \nSERVICE_ID :%s\
+ \nPRECEDENCE :%s\
+ \nMTR_PROFILE_INDEX :%s\
+ \nSPONSOR_LEN :%s \
+ \nSPONSOR :%s" % \
+ (ADC_TYPE, IP[0], GATE_STATUS,\
+ RATING_GROUP, SERVICE_ID, \
+ PRECEDENCE, MTR_PROFILE_INDEX, \
+ len(SPONSOR), SPONSOR)
+
+ if ADC_TYPE == 2:
+ pub_socket.send("%s" % (struct.pack('!BBBLHBL\
+ LLHB'+str(len(SPONSOR))+'s', \
+ topicId, MSG_TYPE, ADC_TYPE, \
+ IP[0], PREFIX, GATE_STATUS, \
+ RATING_GROUP, SERVICE_ID, \
+ PRECEDENCE, MTR_PROFILE_INDEX, \
+ len(SPONSOR), SPONSOR)))
+
+ print "\nADC Rule Values for ::\
+ \nADC_TYPE :%s \nIP :%s \
+ \nPREFIX :%s\nGATE_STATUS :%s \
+ \nRATING_GROUP:%s \
+ \nSERVICE_ID :%s\
+ \nPRECEDENCE :%s \
+ \nMTR_PROFILE_INDEX :%s\
+ \nSPONSOR_LEN :%s\
+ \nSPONSOR :%s"\
+ % (ADC_TYPE, IP[0], \
+ PREFIX, GATE_STATUS, \
+ RATING_GROUP, SERVICE_ID, \
+ PRECEDENCE, MTR_PROFILE_INDEX, \
+ len(SPONSOR), SPONSOR)
+
+
+ time.sleep(1)
+ print '\n ---># ADC Rule Successfully sent...#<---\n'
+ parser.clear()
+
diff --git a/scripts/test_rules/config/adc_rules.cfg b/scripts/test_rules/config/adc_rules.cfg
new file mode 100644
index 0000000..c7c2472
--- /dev/null
+++ b/scripts/test_rules/config/adc_rules.cfg
@@ -0,0 +1,85 @@
+[GLOBAL]
+NUM_ADC_RULES = 5
+
+;FORMAT ::
+;ADC_TYPE : [ DOMAIN = 0 | IP = 1 | IP PREFIX =2 ]
+;
+;if ADC_TYPE = 0
+; DOMAIN
+;elseif ADC_TYPE = 1
+; IP
+;elseif ADC_TYPE = 2
+; IP
+; PREFIX
+;else
+; NONE
+;
+;GATE_STATUS : DROP [ 0 if DROP, 1 otherwise ]
+;RATING_GROUP
+;SERVICE_ID
+;PRECEDENCE = 0x1ffffffe(536870910) - default value
+;MTR_PROFILE_INDEX
+;SPONSOR_ID
+;TARIFF_GROUP
+;TARIFF_TIME
+;
+;NOTE :
+;Rules defined first have a higher priority, unless DROP is specified
+;(i.e. multiple rules for the same IP).
+;
+;Set Meter profile index to 0 to skip the metering.
+;
+;When specifying DROP with an IP address, use a prefix of 32 to prevent DNS
+;results from overwriting rule.
+
+[ADC_RULE_0]
+ADC_TYPE = 1
+IP = 13.1.1.111
+GATE_STATUS = 1
+RATING_GROUP = Zero-Rate
+SERVICE_ID = Internet
+PRECEDENCE = 536870910
+MTR_PROFILE_INDEX = 7
+SPONSOR = Example
+
+[ADC_RULE_1]
+ADC_TYPE = 2
+IP = 13.1.1.112
+PREFIX = 24
+GATE_STATUS = 1
+RATING_GROUP = Zero-Rate
+SERVICE_ID = Management
+PRECEDENCE = 536870910
+MTR_PROFILE_INDEX = 7
+SPONSOR = Example
+
+[ADC_RULE_2]
+ADC_TYPE = 1
+IP = 13.1.1.113
+GATE_STATUS = 1
+RATING_GROUP = Zero-Rate
+SERVICE_ID = Provisioning
+PRECEDENCE = 536870910
+MTR_PROFILE_INDEX = 7
+SPONSOR = Example
+
+[ADC_RULE_3]
+ADC_TYPE = 0
+DOMAIN = www.example.gov
+GATE_STATUS = 1
+RATING_GROUP = Zero-Rate
+SERVICE_ID = Internet
+PRECEDENCE = 536870910
+MTR_PROFILE_INDEX = 7
+SPONSOR = Example
+
+[ADC_RULE_4]
+ADC_TYPE = 0
+DOMAIN = www.drop_example.com
+GATE_STATUS = 0
+RATING_GROUP = 0
+SERVICE_ID = CIPA
+PRECEDENCE = 536870910
+MTR_PROFILE_INDEX = 0
+SPONSOR = Example
+
diff --git a/scripts/test_rules/config/meter_profile.cfg b/scripts/test_rules/config/meter_profile.cfg
new file mode 100644
index 0000000..e38f9b2
--- /dev/null
+++ b/scripts/test_rules/config/meter_profile.cfg
@@ -0,0 +1,58 @@
+[GLOBAL]
+NUM_OF_IDX = 7
+
+[ENTRY_1]
+;Committed Information Rate (CIR). Measured in bytes per second.
+;MBR is mapped into CIR, convert MBR from bits to Bytes and set CIR.
+CIR = 2342400
+;Committed Burst Size unit = Bytes
+CBS = 5856
+;Excess Burst Size unit = Bytes
+EBS = 11712
+;Meter profile index. Refer this index in static_pcc.cfg to set AMBR/MBR
+MTR_PROFILE_IDX = 3
+
+[ENTRY_2]
+;1200 = 1756800
+;1400 = 2049600
+;1600 = 2342400
+CIR = 2342400
+CBS = 5856
+EBS = 11712
+MTR_PROFILE_IDX = 4
+
+[ENTRY_3]
+; QCI5,QCI7 15.571kbps = 1947 B
+CIR = 2342400
+CBS = 5856
+EBS = 11712
+MTR_PROFILE_IDX = 5
+
+[ENTRY_4]
+; QCI1, 44kbps = 5500 B
+CIR = 2342400
+CBS = 5856
+EBS = 11712
+MTR_PROFILE_IDX = 6
+
+[ENTRY_5]
+; QCI9, 31.143kbps = 3893 B
+CIR = 2342400
+CBS = 5856
+EBS = 11712
+MTR_PROFILE_IDX = 7
+
+[ENTRY_6]
+; 128B, 7pps
+CIR = 2342400
+CBS = 512
+EBS = 1024
+MTR_PROFILE_IDX = 8
+
+[ENTRY_7]
+; 128B, 2pps
+CIR = 2342400
+CBS = 512
+EBS = 1024
+MTR_PROFILE_IDX = 9
+
diff --git a/scripts/test_rules/config/pcc_rules.cfg b/scripts/test_rules/config/pcc_rules.cfg
new file mode 100644
index 0000000..e2f5564
--- /dev/null
+++ b/scripts/test_rules/config/pcc_rules.cfg
@@ -0,0 +1,84 @@
+[GLOBAL]
+NUM_PCC_FILTERS = 3
+;To config AMBR/MBR values refer meter_profile.cfg. specify only the
+;meter profile index to be set here.
+UL_AMBR_MTR_PROFILE_IDX = 3
+DL_AMBR_MTR_PROFILE_IDX = 4
+
+;default filter - must be first for now (until DP doesn't install any filters)
+[PCC_FILTER_0]
+RULE_NAME = SimuRule
+RATING_GROUP = 9
+SERVICE_ID = 0
+RULE_STATUS = 0
+GATE_STATUS = 1
+SESSION_CONT = 0
+REPORT_LEVEL = 0
+CHARGING_MODE = 0
+METERING_METHOD = 0
+MUTE_NOTIFY = 0
+MONITORING_KEY = 0
+SPONSOR_ID = 0
+REDIRECT_INFO = 0
+PRECEDENCE = 0
+DROP_PKT_COUNT = 0
+;Specify the meter profile index from meter_profile.cfg
+UL_MBR_MTR_PROFILE_IDX = 7
+DL_MBR_MTR_PROFILE_IDX = 7
+
+[PCC_FILTER_1]
+RULE_NAME = SimuRule
+RATING_GROUP = 5
+SERVICE_ID = 0
+RULE_STATUS = 0
+GATE_STATUS = 1
+SESSION_CONT = 0
+REPORT_LEVEL = 0
+CHARGING_MODE = 0
+METERING_METHOD = 0
+MUTE_NOTIFY = 0
+MONITORING_KEY = 0
+SPONSOR_ID = 0
+REDIRECT_INFO = 0
+PRECEDENCE = 255
+DROP_PKT_COUNT = 0
+UL_MBR_MTR_PROFILE_IDX = 5
+DL_MBR_MTR_PROFILE_IDX = 5
+
+[PCC_FILTER_2]
+RULE_NAME = SimuRule
+RATING_GROUP = 1
+SERVICE_ID = 0
+RULE_STATUS = 0
+GATE_STATUS = 1
+SESSION_CONT = 0
+REPORT_LEVEL = 0
+CHARGING_MODE = 0
+METERING_METHOD = 0
+MUTE_NOTIFY = 0
+MONITORING_KEY = 0
+SPONSOR_ID = 0
+REDIRECT_INFO = 0
+PRECEDENCE = 255
+DROP_PKT_COUNT = 0
+UL_MBR_MTR_PROFILE_IDX = 6
+DL_MBR_MTR_PROFILE_IDX = 6
+
+[PCC_FILTER_3]
+RULE_NAME = SimuRule
+RATING_GROUP = 7
+SERVICE_ID = 0
+RULE_STATUS = 0
+GATE_STATUS = 1
+SESSION_CONT = 0
+REPORT_LEVEL = 0
+CHARGING_MODE = 0
+METERING_METHOD = 0
+MUTE_NOTIFY = 0
+MONITORING_KEY = 0
+SPONSOR_ID = 0
+REDIRECT_INFO = 0
+PRECEDENCE = 255
+DROP_PKT_COUNT = 0
+UL_MBR_MTR_PROFILE_IDX = 5
+DL_MBR_MTR_PROFILE_IDX = 5
diff --git a/scripts/test_rules/config/sdf_rules.cfg b/scripts/test_rules/config/sdf_rules.cfg
new file mode 100644
index 0000000..4e86910
--- /dev/null
+++ b/scripts/test_rules/config/sdf_rules.cfg
@@ -0,0 +1,36 @@
+[GLOBAL]
+NUM_SDF_FILTERS = 3
+;To config AMBR/MBR values refer meter_profile.cfg. specify only the
+
+;default filter - must be first for now (until DP doesn't install any filters)
+[SDF_FILTER_0]
+RATING_GROUP = 9
+
+[SDF_FILTER_1]
+RATING_GROUP = 5
+DIRECTION = bidirectional
+PRECEDENCE = 255
+IPV4_REMOTE = 13.1.0.0
+IPV4_REMOTE_MASK = 255.255.0.0
+PROTOCOL = 17
+REMOTE_LOW_LIMIT_PORT = 5060
+REMOTE_HIGH_LIMIT_PORT = 5060
+
+[SDF_FILTER_2]
+RATING_GROUP = 1
+DIRECTION = bidirectional
+PRECEDENCE = 255
+IPV4_REMOTE = 13.1.0.0
+IPV4_REMOTE_MASK = 255.255.0.0
+PROTOCOL = 17
+LOCAL_LOW_LIMIT_PORT = 17000
+LOCAL_HIGH_LIMIT_PORT = 17010
+
+[SDF_FILTER_3]
+RATING_GROUP = 7
+DIRECTION = bidirectional
+PRECEDENCE = 255
+IPV4_REMOTE = 13.1.0.0
+PROTOCOL = 17
+LOCAL_LOW_LIMIT_PORT = 8000
+LOCAL_HIGH_LIMIT_PORT = 8080
diff --git a/scripts/test_rules/mtr_rules.py b/scripts/test_rules/mtr_rules.py
new file mode 100755
index 0000000..bad8533
--- /dev/null
+++ b/scripts/test_rules/mtr_rules.py
@@ -0,0 +1,70 @@
+#!/usr/bin/python
+#coding: utf8
+#Copyright © 2016 - 2017 Copyright (c) Sprint, Inc. and others. All rights
+#reserved.
+#
+#This program and the accompanying materials are made available under the
+#terms of the Eclipse Public License v1.0 which accompanies this distribution,
+#and is available at http://www.eclipse.org/legal/epl-v10.html
+#
+##############################################################################
+#
+# File : mtr_rules.py
+#
+# Comments :
+# Read METER Rules config file from './config/' and get parameters
+# values as per the METER Rule Table.
+# As per METER Rule table, formed a structure and parse values in structure,
+# and finally pack a structure and send over the zmq(PUB/SUB) socket to DP.
+#
+# Reference : message_sdn_dp.docx
+# Section : Table No.13 METER Rule
+##############################################################################
+
+import sys
+import os
+import time
+import struct
+import socket
+
+from configparser import ConfigParser
+
+parser = ConfigParser()
+
+def parse_mtr_values(pub_socket,topicId):
+ # TBD: Need to handle exception
+ parser.read('./config/meter_profile.cfg')
+ print "\n ---> Reading Values from Meter profile file <--- "
+ print "\n ---> Sending Meter Rules <---"
+ MSG_TYPE = 19
+ RULE_ID = 0
+
+ # Create struct for meter rule and parse values in that.
+ for val in parser.sections():
+ if val != 'GLOBAL':
+ RULE_ID += 1
+ # TBD: Need to handle exception
+ CIR = int(parser.get(val, 'CIR'))
+ CBS = int(parser.get(val, 'CBS'))
+ EBS = int(parser.get(val, 'EBS'))
+ MTR_PROFILE_IDX = int(parser.get(val, \
+ 'MTR_PROFILE_IDX'))
+
+ METERING_METHOD = 0
+
+ # Pack the struct and send over the zmq socket to dp.
+ pub_socket.send("%s" % (struct.pack('!BBHQQQH',topicId,\
+ MSG_TYPE, MTR_PROFILE_IDX, CIR, CBS, EBS, \
+ METERING_METHOD)))
+
+ print "\nMETER Rule Values for %s ::\nRULE_ID :%s\
+ \nMSG_TYPE :%s \nCIR :%s \nCBS :%s \
+ \nEBS :%s \nMTR_PROFILE_IDX :%s\
+ \nMETERING_METHOD :%s\n " % \
+ (val, RULE_ID, MSG_TYPE, CIR, \
+ CBS, EBS, MTR_PROFILE_IDX, \
+ METERING_METHOD)
+ time.sleep(1)
+
+ print '\n ---># Meter Rule Successfully sent..#<---\n'
+ parser.clear()
diff --git a/scripts/test_rules/pcc_rules.py b/scripts/test_rules/pcc_rules.py
new file mode 100755
index 0000000..e1ceea6
--- /dev/null
+++ b/scripts/test_rules/pcc_rules.py
@@ -0,0 +1,110 @@
+#!/usr/bin/python
+#coding: utf8
+#Copyright © 2016 - 2017 Copyright (c) Sprint, Inc. and others. All rights
+#reserved.
+#
+#This program and the accompanying materials are made available under the
+#terms of the Eclipse Public License v1.0 which accompanies this distribution,
+#and is available at http://www.eclipse.org/legal/epl-v10.html
+#
+############################################################################
+# File : pcc_rules.py
+#
+# Comments :
+# Read PCC Rules config file from './config/' and get parameters
+# values as per the PCC Rule Table.
+# As per PCC Rule table, formed a structure and parse values in structure,
+# and finally pack a structure and send over the zmq(PUB/SUB) socket to DP.
+#
+# Reference : message_sdn_dp.docx
+# Section : Table No.12 PCC Rule
+############################################################################
+
+import sys
+import os
+import time
+import struct
+import socket
+
+from configparser import ConfigParser
+
+parser = ConfigParser()
+
+def parse_pcc_values(pub_socket,topicId):
+ # TBD: Need to handle exception
+ parser.read('./config/pcc_rules.cfg')
+ print "\n ---> Reading Values from PCC config file <--- \n"
+ print "\n ---> Sending PCC Rules <---"
+ MSG_TYPE = 18
+ RULE_ID = 0
+
+ # Create a struture for PCC rule and parse the values in that.
+ for val in parser.sections():
+ if val != 'GLOBAL':
+ # TBD: Need to handle exception
+ #RULE_ID = int(parser.get(val, 'RULE_ID'))
+ RULE_ID += 1
+ RULE_NAME = str(parser.get(val, 'RULE_NAME'))
+ RATING_GROUP = int(parser.get(val, 'RATING_GROUP'))
+ SERVICE_ID = int(parser.get(val, 'SERVICE_ID'))
+ RULE_STATUS = int(parser.get(val, 'RULE_STATUS'))
+ GATE_STATUS = int(parser.get(val, 'GATE_STATUS'))
+ SESSION_CONT = int(parser.get(val, 'SESSION_CONT'))
+ REPORT_LEVEL = int(parser.get(val, 'REPORT_LEVEL'))
+ CHARGING_MODE = int(parser.get(val, 'CHARGING_MODE'))
+ METERING_METHOD = int(parser.get(val, 'METERING_METHOD'))
+ MUTE_NOTIFY = int(parser.get(val, 'MUTE_NOTIFY'))
+ MONITORING_KEY = int(parser.get(val, 'MONITORING_KEY'))
+ SPONSOR_ID = str(parser.get(val, 'SPONSOR_ID'))
+ REDIRECT_INFO = int(parser.get(val, 'REDIRECT_INFO'))
+ PRECEDENCE = int(parser.get(val, 'PRECEDENCE'))
+ DROP_PKT_COUNT = int(parser.get(val, 'DROP_PKT_COUNT'))
+ UL_MBR_MTR_PROFILE_IDX = int(parser.get(val, \
+ 'UL_MBR_MTR_PROFILE_IDX'))
+ DL_MBR_MTR_PROFILE_IDX = int(parser.get(val, \
+ 'DL_MBR_MTR_PROFILE_IDX'))
+
+ var = struct.Struct('!BBBBHBBBLLBBQHHBI'+str(\
+ len(RULE_NAME))+'sI'\
+ +str(len(SPONSOR_ID))+'s')
+
+ values = (topicId, MSG_TYPE, METERING_METHOD, \
+ CHARGING_MODE, RATING_GROUP, \
+ RULE_STATUS, GATE_STATUS, SESSION_CONT,\
+ MONITORING_KEY, PRECEDENCE, \
+ REPORT_LEVEL, MUTE_NOTIFY, \
+ DROP_PKT_COUNT, \
+ UL_MBR_MTR_PROFILE_IDX, \
+ DL_MBR_MTR_PROFILE_IDX, \
+ REDIRECT_INFO,\
+ len(RULE_NAME), RULE_NAME, \
+ len(SPONSOR_ID), SPONSOR_ID)
+
+ # TBD: Need to handle exception
+ # Pack the structure and send over the zmq socket to dp
+
+ pub_socket.send("%s" % (var.pack(*values)))
+ time.sleep(1)
+
+ print "\nPCC Rule Values for %s ::\nRULE_ID :%s \
+ \nRULE_NAME :%s\nRATING_GROUP :%s\
+ \nSERVICE_ID :%s\nRULE_STATUS :%s\
+ \nGATE_STATUS :%s\nSESSION_CONT :%s\
+ \nREPORT_LEVEL :%s \nCHARGING_MODE :%s\
+ \nMETERING_METHOD :%s\nMUTE_NOTIFY :%s\
+ \nMONITORING_KEY :%s\nSPONSOR_ID :%s\
+ \nREDIRECT_INFO :%s\nPRECEDENCE :%s\
+ \nDROP_PKT_COUNT :%s\
+ \nul_mbr_DROP_PKT_COUNT :%s\
+ \ndl_mbr_DROP_PKT_COUNT :%s\n\n" % \
+ (val, RULE_ID, RULE_NAME, RATING_GROUP,\
+ SERVICE_ID, RULE_STATUS, GATE_STATUS, \
+ SESSION_CONT, REPORT_LEVEL, \
+ CHARGING_MODE, METERING_METHOD, \
+ MUTE_NOTIFY, MONITORING_KEY, \
+ SPONSOR_ID, REDIRECT_INFO, PRECEDENCE,\
+ DROP_PKT_COUNT, UL_MBR_MTR_PROFILE_IDX,\
+ DL_MBR_MTR_PROFILE_IDX)
+
+ print '\n ---># PCC Rule Successfully sent..#<---\n'
+ parser.clear()
diff --git a/scripts/test_rules/readme.md b/scripts/test_rules/readme.md
new file mode 100644
index 0000000..2a3e964
--- /dev/null
+++ b/scripts/test_rules/readme.md
@@ -0,0 +1,60 @@
+# Prerequisite
+ - python is installed
+ - Configparser is installed
+ - ZeroMQ is installed
+ - netaddr is installed
+ - Python Binding of ZeroMQ is installed
+
+# Run FPC Agent
+Following is the sequence of operations to do for launching test_rule.
+
+1. Start the ZeroMQ service for DPN communication.
+
+```
+> ~/fpc/zmqforwarder/python forwarder_device.py
+```
+
+2. Start the service counts ZMQ messages on the SB, Displays message types.
+
+```
+> ~/fpc/zmqforwarder/python jc.forwarder_subscriber.py --quiet
+```
+
+3. Start up OpenDaylight.
+
+```
+> cd ~/fpc/karaf/target/assembly/bin
+```
+* To run the agent in the foreground with an interactive shell:
+
+```
+> ./karaf
+```
+
+Above steps will start FPC. Once FPC is running then use following to start
+test_rule program.
+
+# Run Rule Push Script
+Start script to push ADC, PCC, MTR and SDF rules to DP over ZMQ
+
+* Go to following folder
+
+```
+> cd ~/fpc/zmqforwarder/test_rules
+```
+* Start script to push ADC, PCC, MTR and SDF rules to DP over ZMQ.
+* To run the publisher with an interactive shell:
+
+```
+> ./rules_pub.py
+```
+This script listens for DP to come online and then push rules.
+
+#Run DP
+Start up DP
+
+```
+Note: This script waits for single DP to come up, push rules on the DP and exit.
+To push rules on another DP need to restart the script.
+
+```
diff --git a/scripts/test_rules/rules_pub.py b/scripts/test_rules/rules_pub.py
new file mode 100755
index 0000000..a658945
--- /dev/null
+++ b/scripts/test_rules/rules_pub.py
@@ -0,0 +1,87 @@
+#!/usr/bin/python
+#coding: utf8
+#Copyright © 2016 - 2017 Copyright (c) Sprint, Inc. and others. All rights
+#reserved.
+#
+#This program and the accompanying materials are made available under the
+#terms of the Eclipse Public License v1.0 which accompanies this distribution,
+#and is available at http://www.eclipse.org/legal/epl-v10.html
+#
+############################################################################
+# File : rules_test.py
+#
+# Comments :
+# Establish the channel with DP (Script(PUB) -> Forwarder -> DP(SUB)),
+# And listen and push the message over socket.
+############################################################################
+
+import signal
+import sys
+import zmq
+import struct
+import socket as socketlib
+import datetime
+import time
+
+from adc_rules import *
+from pcc_rules import *
+from mtr_rules import *
+from sdf_rules import *
+
+conflict = False
+topicId = None
+
+# TBD: Needs to handle exception
+# TBD: Needs to handle keyboard intrrupts
+
+#ZMQ ports
+rec_port = "5556"
+send_port = "5555"
+# Socket to talk to server
+context = zmq.Context()
+socket = context.socket(zmq.SUB)
+pub_socket = context.socket(zmq.PUB)
+# As of not test script runs from FPC-SDN only
+socket.connect ("tcp://192.168.105.14:%s" % rec_port)
+pub_socket.connect("tcp://192.168.105.14:%s" % send_port)
+topicfilter = ""
+controller_topic= 252
+socket.setsockopt(zmq.SUBSCRIBE, topicfilter)
+print "Listening to port ", rec_port
+print "Publisher on port ", send_port
+print "Ready to receive messages. Press Ctrl+C when ready to exit."
+
+for update_nbr in range(900000):
+ # TBD: Needs to handle exception
+ string = socket.recv()
+ ts = time.time()
+ st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
+
+ topic, msgnum, ID = struct.unpack('!BBB', string[:3])
+ print"\n topic,msg,ID:%s,%s,%s" % (topic, msgnum, ID)
+
+ #Listen to topic
+ if topic == 1 and msgnum == 10:#Assign_Id
+ top, msg, topId = struct.unpack('!BBB', string[:3])
+ print "\n topId :", topId
+ topicId = topId
+
+ #Listen to ack
+ if topic == 2 and msgnum == 12:
+ top, msg, topId_t = struct.unpack('!BBB', string[:3])
+
+ if topicId == topId_t:
+ # TBD: Needs to handle exception
+
+ parse_adc_values(pub_socket, topicId)
+ time.sleep(1)
+ parse_mtr_values(pub_socket, topicId)
+ time.sleep(1)
+ parse_pcc_values(pub_socket, topicId)
+ time.sleep(1)
+ parse_sdf_values(pub_socket, topicId)
+ time.sleep(1)
+ socket.close()
+ pub_socket.close()
+ sys.exit(0)
+
diff --git a/scripts/test_rules/sdf_rules.py b/scripts/test_rules/sdf_rules.py
new file mode 100755
index 0000000..a76ac2e
--- /dev/null
+++ b/scripts/test_rules/sdf_rules.py
@@ -0,0 +1,170 @@
+#!/usr/bin/python
+#coding: utf8
+#Copyright © 2016 - 2017 Copyright (c) Sprint, Inc. and others. All rights
+#reserved.
+#
+#This program and the accompanying materials are made available under the
+#terms of the Eclipse Public License v1.0 which accompanies this distribution,
+#and is available at http://www.eclipse.org/legal/epl-v10.html
+#
+############################################################################
+# File : sdf_rules.py
+#
+# Comments :
+# Read SDF Rules config file from './config/' and get parameters
+# values as per the SDF Rule Table.
+# As per SDF Rule table, formed a structure and parse values in structure,
+# and finally pack a structure and send over the zmq socket to DP.
+#
+# Reference : message_sdn_dp.docx
+# Section : Table No.14 SDF Rule
+############################################################################
+
+import sys
+import os
+import time
+import struct
+import socket
+
+from netaddr import IPAddress
+from configparser import ConfigParser
+
+parser = ConfigParser()
+
+def parse_sdf_values(pub_socket,topicId):
+ # TBD: Need to handle exception
+ parser.read('./config/sdf_rules.cfg')
+ print "\n ---> Reading Values from SDF rules file <--- "
+ print "\n ---> Sending SDF Rules <---"
+
+ MSG_TYPE = 20
+ # Initilize the parameters
+ # Rule type set 0 if Rule String and 1 Five tuple
+ RULE_TYPE = 0
+ PCC_RULE_ID = 0
+ DIRECTION = 'bidirectional'
+ LOCAL_IP = '0.0.0.0'
+ LOCAL_IP_MASK = 0
+ IPV4_REMOTE = '0.0.0.0'
+ IPV4_REMOTE_MASK = 0
+ LOCAL_LOW_LIMIT_PORT = 0
+ LOCAL_HIGH_LIMIT_PORT = 65535
+ REMOTE_LOW_LIMIT_PORT = 0
+ REMOTE_HIGH_LIMIT_PORT = 65535
+ PRECEDENCE = 0
+ PROTOCOL = hex(0)
+ PROTOCOL_MASK = hex(0)
+
+ # Create the structure for SDF rule and parse the values in that.
+ for val in parser.sections():
+ if val != 'GLOBAL':
+ # TBD: Need to handle exception
+ PCC_RULE_ID += 1
+ if PCC_RULE_ID > 1:
+ PROTOCOL_MASK = '0xff'
+
+ if parser.has_option(val, 'RULE_TYPE'):
+ RULE_TYPE = int(parser.get(val, \
+ 'RULE_TYPE'))
+
+ if parser.has_option(val, 'RATING_GROUP'):
+ RATING_GROUP = int(parser.get(val, \
+ 'RATING_GROUP'))
+
+ if parser.has_option(val, 'DIRECTION'):
+ DIRECTION = str(parser.get(val, \
+ 'DIRECTION'))
+
+ if parser.has_option(val, 'PRECEDENCE'):
+ PRECEDENCE = int(parser.get(val, \
+ 'PRECEDENCE'))
+
+ if parser.has_option(val, 'LOCAL_IP'):
+ LOCAL_IP = str(parser.get(val, \
+ 'LOCAL_IP'))
+
+ if parser.has_option(val, 'LOCAL_IP_MASK'):
+ LOCAL_IP_MASK = str(parser.get(val, \
+ 'LOCAL_IP_MASK'))
+
+ if parser.has_option(val, 'IPV4_REMOTE'):
+ IPV4_REMOTE = str(parser.get(val, \
+ 'IPV4_REMOTE'))
+
+ if parser.has_option(val, 'IPV4_REMOTE_MASK'):
+ IPV4_REMOTE_MASK = \
+ IPAddress(struct.unpack('!L', \
+ socket.inet_aton(\
+ str(parser.get(val, \
+ 'IPV4_REMOTE_MASK'))))\
+ [0]).netmask_bits()
+
+ if parser.has_option(val, 'PROTOCOL'):
+ PROTOCOL = hex(int(parser.get(val, \
+ 'PROTOCOL')))
+
+ if parser.has_option(val, 'PROTOCOL_MASK'):
+ PROTOCOL_MASK = int(parser.get(val, \
+ 'PROTOCOL_MASK'))
+
+ if parser.has_option(val, 'LOCAL_LOW_LIMIT_PORT'):
+ LOCAL_LOW_LIMIT_PORT = int(parser.get(val, \
+ 'LOCAL_LOW_LIMIT_PORT'))
+
+ if parser.has_option(val, 'LOCAL_HIGH_LIMIT_PORT'):
+ LOCAL_HIGH_LIMIT_PORT = int(parser.get(val, \
+ 'LOCAL_HIGH_LIMIT_PORT'))
+
+ if parser.has_option(val, 'REMOTE_LOW_LIMIT_PORT'):
+ REMOTE_LOW_LIMIT_PORT = int(parser.get(val, \
+ 'REMOTE_LOW_LIMIT_PORT'))
+
+ if parser.has_option(val, 'REMOTE_HIGH_LIMIT_PORT'):
+ REMOTE_HIGH_LIMIT_PORT = int(parser.get(val, \
+ 'REMOTE_HIGH_LIMIT_PORT'))
+
+ if DIRECTION == 'bidirectional':
+ RULE_STRING = \
+ str("%s/%s %s/%s %s : %s %s : %s %s/%s") % \
+ (IPV4_REMOTE, IPV4_REMOTE_MASK, \
+ LOCAL_IP, LOCAL_IP_MASK, \
+ REMOTE_LOW_LIMIT_PORT, \
+ REMOTE_HIGH_LIMIT_PORT, \
+ LOCAL_LOW_LIMIT_PORT, \
+ LOCAL_HIGH_LIMIT_PORT, \
+ PROTOCOL, PROTOCOL_MASK)
+
+ elif DIRECTION == 'uplink_only':
+ RULE_STRING = \
+ str("%s/%s %s/%s %s : %s %s : %s %s/%s") % \
+ (LOCAL_IP, LOCAL_IP_MASK, \
+ IPV4_REMOTE, IPV4_REMOTE_MASK, \
+ LOCAL_LOW_LIMIT_PORT, \
+ LOCAL_HIGH_LIMIT_PORT, \
+ REMOTE_LOW_LIMIT_PORT, \
+ REMOTE_HIGH_LIMIT_PORT, \
+ PROTOCOL, PROTOCOL_MASK)
+
+ elif DIRECTION == 'downlink_only':
+ RULE_STRING = \
+ str("%s/%s %s/%s %s : %s %s : %s 0x%s/0x%s") % \
+ (IPV4_REMOTE, IPV4_REMOTE_MASK, \
+ LOCAL_IP, LOCAL_IP_MASK, \
+ REMOTE_LOW_LIMIT_PORT, \
+ REMOTE_HIGH_LIMIT_PORT, \
+ LOCAL_LOW_LIMIT_PORT, \
+ LOCAL_HIGH_LIMIT_PORT, \
+ PROTOCOL, PROTOCOL_MASK)
+
+ # TBD: Need to handle exception
+ # Pack the structure and send over the zmq socket to DP
+ pub_socket.send("%s" % (struct.pack('!BBLLBI'+\
+ str(len(RULE_STRING))+'s',topicId, MSG_TYPE,\
+ PCC_RULE_ID, PRECEDENCE, RULE_TYPE, \
+ len(RULE_STRING), RULE_STRING)))
+ time.sleep(1)
+ print "\nSDF Rule Values for %s :: \nPCC_RULE_ID :%s \
+ \nPRECEDENCE :%s \nRULE_TYPE :%s \nRULE_STRING :%s"\
+ % (val, PCC_RULE_ID, PRECEDENCE, RULE_TYPE, RULE_STRING)
+ print '\n ---># SDF Rule Successfully sent.. #<---\n'
+ parser.clear()